@player-ui/player 0.4.0-next.4 → 0.4.0-next.6
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.
- package/dist/index.cjs.js +110 -39
- package/dist/index.d.ts +33 -10
- package/dist/index.esm.js +110 -40
- package/dist/player.dev.js +4108 -4037
- package/dist/player.prod.js +1 -1
- package/package.json +3 -3
- package/src/controllers/data.ts +0 -2
- package/src/expressions/evaluator.ts +2 -2
- package/src/expressions/index.ts +1 -0
- package/src/expressions/parser.ts +53 -27
- package/src/expressions/types.ts +6 -0
- package/src/player.ts +20 -21
- package/src/plugins/default-exp-plugin.ts +57 -0
- package/src/schema/schema.ts +28 -9
- package/src/string-resolver/index.ts +18 -7
- package/src/validator/validation-middleware.ts +4 -1
- package/src/view/parser/index.ts +7 -1
package/dist/index.cjs.js
CHANGED
|
@@ -909,7 +909,9 @@ function isIdentifierPart(ch) {
|
|
|
909
909
|
function isModelRefStart(ch0, ch1) {
|
|
910
910
|
return ch0 === OCURL_CODE && ch1 === OCURL_CODE;
|
|
911
911
|
}
|
|
912
|
-
function parseExpression(expr) {
|
|
912
|
+
function parseExpression(expr, options) {
|
|
913
|
+
var _a;
|
|
914
|
+
const strictMode = (_a = options == null ? void 0 : options.strict) != null ? _a : true;
|
|
913
915
|
const charAtFunc = expr.charAt;
|
|
914
916
|
const charCodeAtFunc = expr.charCodeAt;
|
|
915
917
|
const { length } = expr;
|
|
@@ -1303,6 +1305,9 @@ function parseExpression(expr) {
|
|
|
1303
1305
|
}
|
|
1304
1306
|
args.push(node);
|
|
1305
1307
|
}
|
|
1308
|
+
if (charIndex !== termination) {
|
|
1309
|
+
throwError(`Expected ${String.fromCharCode(termination)}`, index);
|
|
1310
|
+
}
|
|
1306
1311
|
return args;
|
|
1307
1312
|
}
|
|
1308
1313
|
function gobbleVariable() {
|
|
@@ -1373,28 +1378,41 @@ function parseExpression(expr) {
|
|
|
1373
1378
|
};
|
|
1374
1379
|
}
|
|
1375
1380
|
const nodes = [];
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
+
try {
|
|
1382
|
+
while (index < length) {
|
|
1383
|
+
const chIndex = exprICode(index);
|
|
1384
|
+
if (chIndex === SEMCOL_CODE || chIndex === COMMA_CODE) {
|
|
1385
|
+
index++;
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
const node = gobbleExpression();
|
|
1389
|
+
if (node) {
|
|
1390
|
+
nodes.push(node);
|
|
1391
|
+
} else if (index < length) {
|
|
1392
|
+
throwError(`Unexpected "${exprI(index)}"`, index);
|
|
1393
|
+
}
|
|
1381
1394
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
nodes.push(node);
|
|
1385
|
-
} else if (index < length) {
|
|
1386
|
-
throwError(`Unexpected "${exprI(index)}"`, index);
|
|
1395
|
+
if (nodes.length === 1) {
|
|
1396
|
+
return nodes[0];
|
|
1387
1397
|
}
|
|
1398
|
+
return {
|
|
1399
|
+
__id: ExpNodeOpaqueIdentifier,
|
|
1400
|
+
type: "Compound",
|
|
1401
|
+
body: nodes,
|
|
1402
|
+
location: getLocation(0)
|
|
1403
|
+
};
|
|
1404
|
+
} catch (e) {
|
|
1405
|
+
if (strictMode || !(e instanceof Error)) {
|
|
1406
|
+
throw e;
|
|
1407
|
+
}
|
|
1408
|
+
return {
|
|
1409
|
+
__id: ExpNodeOpaqueIdentifier,
|
|
1410
|
+
type: "Compound",
|
|
1411
|
+
body: nodes,
|
|
1412
|
+
location: getLocation(0),
|
|
1413
|
+
error: e
|
|
1414
|
+
};
|
|
1388
1415
|
}
|
|
1389
|
-
if (nodes.length === 1) {
|
|
1390
|
-
return nodes[0];
|
|
1391
|
-
}
|
|
1392
|
-
return {
|
|
1393
|
-
__id: ExpNodeOpaqueIdentifier,
|
|
1394
|
-
type: "Compound",
|
|
1395
|
-
body: nodes,
|
|
1396
|
-
location: getLocation(0)
|
|
1397
|
-
};
|
|
1398
1416
|
}
|
|
1399
1417
|
|
|
1400
1418
|
const setDataVal = (_context, binding, value) => {
|
|
@@ -1898,6 +1916,9 @@ function parse(schema) {
|
|
|
1898
1916
|
if (type.isArray) {
|
|
1899
1917
|
nestedPath.push("[]");
|
|
1900
1918
|
}
|
|
1919
|
+
if (type.isRecord) {
|
|
1920
|
+
nestedPath.push("{}");
|
|
1921
|
+
}
|
|
1901
1922
|
if (type.type && schema[type.type]) {
|
|
1902
1923
|
parseQueue.push({
|
|
1903
1924
|
path: nestedPath,
|
|
@@ -1946,8 +1967,20 @@ class SchemaController {
|
|
|
1946
1967
|
if (cached) {
|
|
1947
1968
|
return cached;
|
|
1948
1969
|
}
|
|
1949
|
-
|
|
1950
|
-
|
|
1970
|
+
let bindingArray = binding.asArray();
|
|
1971
|
+
let normalized = bindingArray.map((p) => typeof p === "number" ? "[]" : p).join(".");
|
|
1972
|
+
if (normalized) {
|
|
1973
|
+
this.bindingSchemaNormalizedCache.set(binding, normalized);
|
|
1974
|
+
bindingArray = normalized.split(".");
|
|
1975
|
+
}
|
|
1976
|
+
bindingArray.forEach((item) => {
|
|
1977
|
+
const recordBinding = bindingArray.map((p) => p === item ? "{}" : p).join(".");
|
|
1978
|
+
if (this.schema.get(recordBinding)) {
|
|
1979
|
+
this.bindingSchemaNormalizedCache.set(binding, recordBinding);
|
|
1980
|
+
bindingArray = recordBinding.split(".");
|
|
1981
|
+
normalized = recordBinding;
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1951
1984
|
return normalized;
|
|
1952
1985
|
}
|
|
1953
1986
|
getType(binding) {
|
|
@@ -2034,6 +2067,9 @@ function findNextExp(str) {
|
|
|
2034
2067
|
};
|
|
2035
2068
|
}
|
|
2036
2069
|
function resolveExpressionsInString(val, { evaluate }) {
|
|
2070
|
+
if (!evaluate) {
|
|
2071
|
+
return val;
|
|
2072
|
+
}
|
|
2037
2073
|
const expMatch = /@\[.*?\]@/;
|
|
2038
2074
|
let newVal = val;
|
|
2039
2075
|
let match = newVal.match(expMatch);
|
|
@@ -2053,7 +2089,7 @@ function resolveExpressionsInString(val, { evaluate }) {
|
|
|
2053
2089
|
function resolveDataRefsInString(val, options) {
|
|
2054
2090
|
const { model } = options;
|
|
2055
2091
|
let workingString = resolveExpressionsInString(val, options);
|
|
2056
|
-
if (typeof workingString !== "string" || workingString.indexOf(DOUBLE_OPEN_CURLY) === -1) {
|
|
2092
|
+
if (!model || typeof workingString !== "string" || workingString.indexOf(DOUBLE_OPEN_CURLY) === -1) {
|
|
2057
2093
|
return workingString;
|
|
2058
2094
|
}
|
|
2059
2095
|
while (workingString.indexOf(DOUBLE_OPEN_CURLY) !== -1) {
|
|
@@ -2082,9 +2118,9 @@ function traverseObject(val, options) {
|
|
|
2082
2118
|
const keys = Object.keys(val);
|
|
2083
2119
|
let newVal = val;
|
|
2084
2120
|
if (keys.length > 0) {
|
|
2085
|
-
|
|
2121
|
+
keys.forEach((key) => {
|
|
2086
2122
|
newVal = timm.setIn(newVal, [key], traverseObject(val[key], options));
|
|
2087
|
-
}
|
|
2123
|
+
});
|
|
2088
2124
|
}
|
|
2089
2125
|
return newVal;
|
|
2090
2126
|
}
|
|
@@ -2136,7 +2172,7 @@ class ValidationMiddleware {
|
|
|
2136
2172
|
} else if (validations instanceof Set) {
|
|
2137
2173
|
validations.forEach((validation) => {
|
|
2138
2174
|
invalidBindings.push(validation.binding);
|
|
2139
|
-
if (!validation.isStrong) {
|
|
2175
|
+
if (!validation.isStrong && validation.binding.asString() === binding.asString()) {
|
|
2140
2176
|
nextTransaction.push([validation.binding, value]);
|
|
2141
2177
|
}
|
|
2142
2178
|
});
|
|
@@ -2276,7 +2312,13 @@ class Parser {
|
|
|
2276
2312
|
if (!localObj) {
|
|
2277
2313
|
return currentValue;
|
|
2278
2314
|
}
|
|
2279
|
-
const objEntries = Array.isArray(localObj) ? localObj.map((v, i) => [i, v]) :
|
|
2315
|
+
const objEntries = Array.isArray(localObj) ? localObj.map((v, i) => [i, v]) : [
|
|
2316
|
+
...Object.entries(localObj),
|
|
2317
|
+
...Object.getOwnPropertySymbols(localObj).map((s) => [
|
|
2318
|
+
s,
|
|
2319
|
+
localObj[s]
|
|
2320
|
+
])
|
|
2321
|
+
];
|
|
2280
2322
|
const defaultValue = {
|
|
2281
2323
|
children: [],
|
|
2282
2324
|
value: currentValue
|
|
@@ -4218,7 +4260,6 @@ class DataController {
|
|
|
4218
4260
|
}
|
|
4219
4261
|
});
|
|
4220
4262
|
this.hooks.onSet.call(normalizedTransaction);
|
|
4221
|
-
this.hooks.onSet.call(normalizedTransaction);
|
|
4222
4263
|
if (setUpdates.length > 0) {
|
|
4223
4264
|
this.hooks.onUpdate.call(setUpdates, options);
|
|
4224
4265
|
}
|
|
@@ -4377,6 +4418,39 @@ class FlowExpPlugin {
|
|
|
4377
4418
|
}
|
|
4378
4419
|
}
|
|
4379
4420
|
|
|
4421
|
+
const createFormatFunction = (schema) => {
|
|
4422
|
+
const handler = (ctx, value, formatName) => {
|
|
4423
|
+
var _a, _b;
|
|
4424
|
+
return (_b = (_a = schema.getFormatterForType({ type: formatName })) == null ? void 0 : _a.format(value)) != null ? _b : value;
|
|
4425
|
+
};
|
|
4426
|
+
return handler;
|
|
4427
|
+
};
|
|
4428
|
+
class DefaultExpPlugin {
|
|
4429
|
+
constructor() {
|
|
4430
|
+
this.name = "flow-exp-plugin";
|
|
4431
|
+
}
|
|
4432
|
+
apply(player) {
|
|
4433
|
+
let formatFunction;
|
|
4434
|
+
player.hooks.schema.tap(this.name, (schemaController) => {
|
|
4435
|
+
formatFunction = createFormatFunction(schemaController);
|
|
4436
|
+
});
|
|
4437
|
+
player.hooks.expressionEvaluator.tap(this.name, (expEvaluator) => {
|
|
4438
|
+
if (formatFunction) {
|
|
4439
|
+
expEvaluator.addExpressionFunction("format", formatFunction);
|
|
4440
|
+
}
|
|
4441
|
+
expEvaluator.addExpressionFunction("log", (ctx, ...args) => {
|
|
4442
|
+
player.logger.info(...args);
|
|
4443
|
+
});
|
|
4444
|
+
expEvaluator.addExpressionFunction("debug", (ctx, ...args) => {
|
|
4445
|
+
player.logger.debug(...args);
|
|
4446
|
+
});
|
|
4447
|
+
expEvaluator.addExpressionFunction("eval", (ctx, ...args) => {
|
|
4448
|
+
return ctx.evaluate(...args);
|
|
4449
|
+
});
|
|
4450
|
+
});
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4380
4454
|
const NOT_STARTED_STATE = {
|
|
4381
4455
|
ref: Symbol("not-started"),
|
|
4382
4456
|
status: "not-started"
|
|
@@ -4421,8 +4495,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4421
4495
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
4422
4496
|
});
|
|
4423
4497
|
};
|
|
4424
|
-
const PLAYER_VERSION = "0.4.0-next.
|
|
4425
|
-
const COMMIT = "
|
|
4498
|
+
const PLAYER_VERSION = "0.4.0-next.6";
|
|
4499
|
+
const COMMIT = "380eb6be2e6d61675cf721c4c3e64821099e5fbe";
|
|
4426
4500
|
const _Player = class {
|
|
4427
4501
|
constructor(config) {
|
|
4428
4502
|
this.logger = new TapableLogger();
|
|
@@ -4443,14 +4517,15 @@ const _Player = class {
|
|
|
4443
4517
|
resolveFlowContent: new tapableTs.SyncWaterfallHook()
|
|
4444
4518
|
};
|
|
4445
4519
|
var _a;
|
|
4446
|
-
const initialPlugins = [];
|
|
4447
|
-
const flowExpPlugin = new FlowExpPlugin();
|
|
4448
|
-
initialPlugins.push(flowExpPlugin);
|
|
4449
4520
|
if (config == null ? void 0 : config.logger) {
|
|
4450
4521
|
this.logger.addHandler(config.logger);
|
|
4451
4522
|
}
|
|
4452
4523
|
this.config = config || {};
|
|
4453
|
-
this.config.plugins = [
|
|
4524
|
+
this.config.plugins = [
|
|
4525
|
+
new DefaultExpPlugin(),
|
|
4526
|
+
...this.config.plugins || [],
|
|
4527
|
+
new FlowExpPlugin()
|
|
4528
|
+
];
|
|
4454
4529
|
(_a = this.config.plugins) == null ? void 0 : _a.forEach((plugin) => {
|
|
4455
4530
|
plugin.apply(this);
|
|
4456
4531
|
});
|
|
@@ -4634,11 +4709,6 @@ const _Player = class {
|
|
|
4634
4709
|
this.hooks.view.call(view);
|
|
4635
4710
|
});
|
|
4636
4711
|
this.hooks.viewController.call(viewController);
|
|
4637
|
-
const formatFunction = (ctx, value, formatName) => {
|
|
4638
|
-
var _a, _b;
|
|
4639
|
-
return (_b = (_a = schema.getFormatterForType({ type: formatName })) == null ? void 0 : _a.format(value)) != null ? _b : value;
|
|
4640
|
-
};
|
|
4641
|
-
expressionEvaluator.addExpressionFunction("format", formatFunction);
|
|
4642
4712
|
return {
|
|
4643
4713
|
start: () => {
|
|
4644
4714
|
flowController.start().then((endState) => {
|
|
@@ -4769,6 +4839,7 @@ exports.isBinding = isBinding;
|
|
|
4769
4839
|
exports.isExpressionNode = isExpressionNode;
|
|
4770
4840
|
exports.maybeConvertToNum = maybeConvertToNum;
|
|
4771
4841
|
exports.parse = parse;
|
|
4842
|
+
exports.parseExpression = parseExpression;
|
|
4772
4843
|
exports.resolveDataRefs = resolveDataRefs;
|
|
4773
4844
|
exports.resolveDataRefsInString = resolveDataRefsInString;
|
|
4774
4845
|
exports.resolveExpressionsInString = resolveExpressionsInString;
|
package/dist/index.d.ts
CHANGED
|
@@ -391,6 +391,11 @@ interface BaseNode<T> {
|
|
|
391
391
|
__id: typeof ExpNodeOpaqueIdentifier;
|
|
392
392
|
/** The location of the node in the source expression string */
|
|
393
393
|
location?: NodeLocation;
|
|
394
|
+
/**
|
|
395
|
+
* The error that occurred while parsing this node
|
|
396
|
+
* This is only set if the parsing mode is set to non-strict
|
|
397
|
+
*/
|
|
398
|
+
error?: Error;
|
|
394
399
|
}
|
|
395
400
|
/** A helper interface for nodes that container left and right children */
|
|
396
401
|
interface DirectionalNode {
|
|
@@ -520,6 +525,16 @@ declare function withoutContext<T extends unknown[], Return>(fn: (...args: T) =>
|
|
|
520
525
|
/** Get the node in the expression that's closest to the desired position */
|
|
521
526
|
declare function findClosestNodeAtPosition(node: ExpressionNode, position: NodePosition): ExpressionNode | undefined;
|
|
522
527
|
|
|
528
|
+
/**
|
|
529
|
+
* An expression to AST parser based on JSEP: http://jsep.from.so/
|
|
530
|
+
*/
|
|
531
|
+
|
|
532
|
+
/** Parse out an expression from the string */
|
|
533
|
+
declare function parseExpression(expr: string, options?: {
|
|
534
|
+
/** If true (the default), will throw on invalid expressions */
|
|
535
|
+
strict?: boolean;
|
|
536
|
+
}): ExpressionNode;
|
|
537
|
+
|
|
523
538
|
declare type FormatOptions = Omit<Formatting.Reference, 'type'>;
|
|
524
539
|
/**
|
|
525
540
|
* The return types for the schema don't include options.
|
|
@@ -1489,7 +1504,7 @@ declare class ValidatorRegistry {
|
|
|
1489
1504
|
}
|
|
1490
1505
|
|
|
1491
1506
|
/** Expand the authored schema into a set of paths -> DataTypes */
|
|
1492
|
-
declare function parse(schema: Schema.Schema): Map<string, Schema.
|
|
1507
|
+
declare function parse(schema: Schema.Schema): Map<string, Schema.DataTypes>;
|
|
1493
1508
|
/**
|
|
1494
1509
|
* The Schema is the central hub for all data invariants, and metaData associated with the data-model itself
|
|
1495
1510
|
* Outside of the types defined in the JSON payload, it doesn't manage or keep any state.
|
|
@@ -1498,18 +1513,18 @@ declare function parse(schema: Schema.Schema): Map<string, Schema.DataType>;
|
|
|
1498
1513
|
declare class SchemaController implements ValidationProvider {
|
|
1499
1514
|
private formatters;
|
|
1500
1515
|
private types;
|
|
1501
|
-
readonly schema: Map<string, Schema.
|
|
1516
|
+
readonly schema: Map<string, Schema.DataTypes>;
|
|
1502
1517
|
private bindingSchemaNormalizedCache;
|
|
1503
1518
|
readonly hooks: {
|
|
1504
|
-
resolveTypeForBinding: SyncWaterfallHook<[Schema.
|
|
1519
|
+
resolveTypeForBinding: SyncWaterfallHook<[Schema.DataTypes | undefined, BindingInstance], Record<string, any>>;
|
|
1505
1520
|
};
|
|
1506
1521
|
constructor(schema?: Schema.Schema);
|
|
1507
1522
|
addFormatters(fns: Array<FormatType<any, any, FormatOptions>>): void;
|
|
1508
1523
|
addDataTypes(types: Array<Schema.DataType<any>>): void;
|
|
1509
1524
|
getValidationsForBinding(binding: BindingInstance): Array<ValidationObject> | undefined;
|
|
1510
1525
|
private normalizeBinding;
|
|
1511
|
-
getType(binding: BindingInstance): Schema.
|
|
1512
|
-
getApparentType(binding: BindingInstance): Schema.
|
|
1526
|
+
getType(binding: BindingInstance): Schema.DataTypes | undefined;
|
|
1527
|
+
getApparentType(binding: BindingInstance): Schema.DataTypes | undefined;
|
|
1513
1528
|
getTypeDefinition(dataType: string): Schema.DataType<any> | undefined;
|
|
1514
1529
|
getFormatterForType(formatReference: Formatting.Reference): FormatDefinition<unknown, unknown> | undefined;
|
|
1515
1530
|
/**
|
|
@@ -1520,10 +1535,16 @@ declare class SchemaController implements ValidationProvider {
|
|
|
1520
1535
|
}
|
|
1521
1536
|
|
|
1522
1537
|
interface Options {
|
|
1523
|
-
/**
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1538
|
+
/**
|
|
1539
|
+
* The model to use when resolving refs
|
|
1540
|
+
* Passing `false` will skip trying to resolve any direct model refs ({{foo}})
|
|
1541
|
+
*/
|
|
1542
|
+
model: false | DataModelWithParser;
|
|
1543
|
+
/**
|
|
1544
|
+
* A function to evaluate an expression
|
|
1545
|
+
* Passing `false` will skip trying to evaluate any expressions (@[ foo() ]@)
|
|
1546
|
+
*/
|
|
1547
|
+
evaluate: false | ((exp: Expression) => any);
|
|
1527
1548
|
}
|
|
1528
1549
|
/** Search the given string for the coordinates of the next expression to resolve */
|
|
1529
1550
|
declare function findNextExp(str: string): {
|
|
@@ -1550,6 +1571,8 @@ interface PlayerPlugin {
|
|
|
1550
1571
|
*/
|
|
1551
1572
|
apply: (player: Player) => void;
|
|
1552
1573
|
}
|
|
1574
|
+
interface ExtendedPlayerPlugin<Assets = void, Views = void, Expressions = void, DataTypes = void> {
|
|
1575
|
+
}
|
|
1553
1576
|
interface PlayerConfigOptions {
|
|
1554
1577
|
/** A set of plugins to load */
|
|
1555
1578
|
plugins?: PlayerPlugin[];
|
|
@@ -1636,4 +1659,4 @@ declare class FlowExpPlugin implements PlayerPlugin {
|
|
|
1636
1659
|
apply(player: Player): void;
|
|
1637
1660
|
}
|
|
1638
1661
|
|
|
1639
|
-
export { AnyAssetType, ApplicabilityPlugin, ArrayExpressionNode, AssetTransformCorePlugin, AssignmentNode, BaseFlowState, BaseNode, BatchSetTransaction, BeforeTransformFunction, BinaryNode, BinaryOperator, BinaryOperatorAdvanced, BinaryOperatorBasic, BindingFactory, BindingInstance, BindingLike, BindingParser, BindingParserOptions, BindingTracker, Builder, CallExpressionNode, CompletedState, CompoundNode, ConditionalExpressionNode, ConsoleLogger, ConstantsController, ConstantsProvider, ControllerState, DataController, DataModelImpl, DataModelMiddleware, DataModelOptions, DataModelWithParser, DataPipeline, DependencyMiddleware, DependencyModel, DependencySets, DependencyTracker, DirectionalNode, EMPTY_NODE, ErrorState, ErrorValidationResponse, ExpNodeOpaqueIdentifier, ExpressionContext, ExpressionEvaluator, ExpressionEvaluatorFunction, ExpressionEvaluatorOptions, ExpressionHandler, ExpressionLiteralType, ExpressionNode, ExpressionNodeType, ExpressionType, FlowController, FlowExpPlugin, FlowInstance, FormatDefinition, FormatFunction, FormatHandler, FormatOptions, FormatType, Getter, HookOptions, IdentifierNode, InProgressState, LiteralNode, LocalModel, LocalStateStore, LogFn, Logger, LoggerProvider, LogicalNode, MemberExpressionNode, MiddlewareChecker, ModelRefNode, ModificationNode, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NamedState, Node, NodeLocation, NodePosition, NodeType, NoopLogger, NotStartedState, ObjectNode, OperatorProcessingOptions, Options, ParseObjectOptions, Parser, PipelinedDataModel, Player, PlayerConfigOptions, PlayerFlowExecutionData, PlayerFlowState, PlayerFlowStatus, PlayerInfo, PlayerPlugin, ProxyLogger, ROOT_BINDING, RawBinding, RawBindingSegment, RawSetTransaction, RawSetType, Resolve, Resolver, SIMPLE_BINDING_REGEX, SchemaController, Severity, StatefulValidationObject, Store, StringResolverPlugin, StrongOrWeakBinding, SwitchPlugin, TapableLogger, TemplatePlugin, ThisNode, TransformFunction, TransformFunctions, TransformRegistry, TransitionFunction, TransitionOptions, UnaryNode, UnaryOperator, Updates, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidationObject, ValidationProvider, ValidationResponse, ValidatorContext, ValidatorFunction, ValidatorRegistry, ViewController, ViewControllerOptions, ViewInstance, ViewPlugin, WarningValidationResponse, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, maybeConvertToNum, parse, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
|
|
1662
|
+
export { AnyAssetType, ApplicabilityPlugin, ArrayExpressionNode, AssetTransformCorePlugin, AssignmentNode, BaseFlowState, BaseNode, BatchSetTransaction, BeforeTransformFunction, BinaryNode, BinaryOperator, BinaryOperatorAdvanced, BinaryOperatorBasic, BindingFactory, BindingInstance, BindingLike, BindingParser, BindingParserOptions, BindingTracker, Builder, CallExpressionNode, CompletedState, CompoundNode, ConditionalExpressionNode, ConsoleLogger, ConstantsController, ConstantsProvider, ControllerState, DataController, DataModelImpl, DataModelMiddleware, DataModelOptions, DataModelWithParser, DataPipeline, DependencyMiddleware, DependencyModel, DependencySets, DependencyTracker, DirectionalNode, EMPTY_NODE, ErrorState, ErrorValidationResponse, ExpNodeOpaqueIdentifier, ExpressionContext, ExpressionEvaluator, ExpressionEvaluatorFunction, ExpressionEvaluatorOptions, ExpressionHandler, ExpressionLiteralType, ExpressionNode, ExpressionNodeType, ExpressionType, ExtendedPlayerPlugin, FlowController, FlowExpPlugin, FlowInstance, FormatDefinition, FormatFunction, FormatHandler, FormatOptions, FormatType, Getter, HookOptions, IdentifierNode, InProgressState, LiteralNode, LocalModel, LocalStateStore, LogFn, Logger, LoggerProvider, LogicalNode, MemberExpressionNode, MiddlewareChecker, ModelRefNode, ModificationNode, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NamedState, Node, NodeLocation, NodePosition, NodeType, NoopLogger, NotStartedState, ObjectNode, OperatorProcessingOptions, Options, ParseObjectOptions, Parser, PipelinedDataModel, Player, PlayerConfigOptions, PlayerFlowExecutionData, PlayerFlowState, PlayerFlowStatus, PlayerInfo, PlayerPlugin, ProxyLogger, ROOT_BINDING, RawBinding, RawBindingSegment, RawSetTransaction, RawSetType, Resolve, Resolver, SIMPLE_BINDING_REGEX, SchemaController, Severity, StatefulValidationObject, Store, StringResolverPlugin, StrongOrWeakBinding, SwitchPlugin, TapableLogger, TemplatePlugin, ThisNode, TransformFunction, TransformFunctions, TransformRegistry, TransitionFunction, TransitionOptions, UnaryNode, UnaryOperator, Updates, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidationObject, ValidationProvider, ValidationResponse, ValidatorContext, ValidatorFunction, ValidatorRegistry, ViewController, ViewControllerOptions, ViewInstance, ViewPlugin, WarningValidationResponse, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, maybeConvertToNum, parse, parseExpression, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
|
package/dist/index.esm.js
CHANGED
|
@@ -896,7 +896,9 @@ function isIdentifierPart(ch) {
|
|
|
896
896
|
function isModelRefStart(ch0, ch1) {
|
|
897
897
|
return ch0 === OCURL_CODE && ch1 === OCURL_CODE;
|
|
898
898
|
}
|
|
899
|
-
function parseExpression(expr) {
|
|
899
|
+
function parseExpression(expr, options) {
|
|
900
|
+
var _a;
|
|
901
|
+
const strictMode = (_a = options == null ? void 0 : options.strict) != null ? _a : true;
|
|
900
902
|
const charAtFunc = expr.charAt;
|
|
901
903
|
const charCodeAtFunc = expr.charCodeAt;
|
|
902
904
|
const { length } = expr;
|
|
@@ -1290,6 +1292,9 @@ function parseExpression(expr) {
|
|
|
1290
1292
|
}
|
|
1291
1293
|
args.push(node);
|
|
1292
1294
|
}
|
|
1295
|
+
if (charIndex !== termination) {
|
|
1296
|
+
throwError(`Expected ${String.fromCharCode(termination)}`, index);
|
|
1297
|
+
}
|
|
1293
1298
|
return args;
|
|
1294
1299
|
}
|
|
1295
1300
|
function gobbleVariable() {
|
|
@@ -1360,28 +1365,41 @@ function parseExpression(expr) {
|
|
|
1360
1365
|
};
|
|
1361
1366
|
}
|
|
1362
1367
|
const nodes = [];
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
+
try {
|
|
1369
|
+
while (index < length) {
|
|
1370
|
+
const chIndex = exprICode(index);
|
|
1371
|
+
if (chIndex === SEMCOL_CODE || chIndex === COMMA_CODE) {
|
|
1372
|
+
index++;
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
const node = gobbleExpression();
|
|
1376
|
+
if (node) {
|
|
1377
|
+
nodes.push(node);
|
|
1378
|
+
} else if (index < length) {
|
|
1379
|
+
throwError(`Unexpected "${exprI(index)}"`, index);
|
|
1380
|
+
}
|
|
1368
1381
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
nodes.push(node);
|
|
1372
|
-
} else if (index < length) {
|
|
1373
|
-
throwError(`Unexpected "${exprI(index)}"`, index);
|
|
1382
|
+
if (nodes.length === 1) {
|
|
1383
|
+
return nodes[0];
|
|
1374
1384
|
}
|
|
1385
|
+
return {
|
|
1386
|
+
__id: ExpNodeOpaqueIdentifier,
|
|
1387
|
+
type: "Compound",
|
|
1388
|
+
body: nodes,
|
|
1389
|
+
location: getLocation(0)
|
|
1390
|
+
};
|
|
1391
|
+
} catch (e) {
|
|
1392
|
+
if (strictMode || !(e instanceof Error)) {
|
|
1393
|
+
throw e;
|
|
1394
|
+
}
|
|
1395
|
+
return {
|
|
1396
|
+
__id: ExpNodeOpaqueIdentifier,
|
|
1397
|
+
type: "Compound",
|
|
1398
|
+
body: nodes,
|
|
1399
|
+
location: getLocation(0),
|
|
1400
|
+
error: e
|
|
1401
|
+
};
|
|
1375
1402
|
}
|
|
1376
|
-
if (nodes.length === 1) {
|
|
1377
|
-
return nodes[0];
|
|
1378
|
-
}
|
|
1379
|
-
return {
|
|
1380
|
-
__id: ExpNodeOpaqueIdentifier,
|
|
1381
|
-
type: "Compound",
|
|
1382
|
-
body: nodes,
|
|
1383
|
-
location: getLocation(0)
|
|
1384
|
-
};
|
|
1385
1403
|
}
|
|
1386
1404
|
|
|
1387
1405
|
const setDataVal = (_context, binding, value) => {
|
|
@@ -1885,6 +1903,9 @@ function parse(schema) {
|
|
|
1885
1903
|
if (type.isArray) {
|
|
1886
1904
|
nestedPath.push("[]");
|
|
1887
1905
|
}
|
|
1906
|
+
if (type.isRecord) {
|
|
1907
|
+
nestedPath.push("{}");
|
|
1908
|
+
}
|
|
1888
1909
|
if (type.type && schema[type.type]) {
|
|
1889
1910
|
parseQueue.push({
|
|
1890
1911
|
path: nestedPath,
|
|
@@ -1933,8 +1954,20 @@ class SchemaController {
|
|
|
1933
1954
|
if (cached) {
|
|
1934
1955
|
return cached;
|
|
1935
1956
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1957
|
+
let bindingArray = binding.asArray();
|
|
1958
|
+
let normalized = bindingArray.map((p) => typeof p === "number" ? "[]" : p).join(".");
|
|
1959
|
+
if (normalized) {
|
|
1960
|
+
this.bindingSchemaNormalizedCache.set(binding, normalized);
|
|
1961
|
+
bindingArray = normalized.split(".");
|
|
1962
|
+
}
|
|
1963
|
+
bindingArray.forEach((item) => {
|
|
1964
|
+
const recordBinding = bindingArray.map((p) => p === item ? "{}" : p).join(".");
|
|
1965
|
+
if (this.schema.get(recordBinding)) {
|
|
1966
|
+
this.bindingSchemaNormalizedCache.set(binding, recordBinding);
|
|
1967
|
+
bindingArray = recordBinding.split(".");
|
|
1968
|
+
normalized = recordBinding;
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1938
1971
|
return normalized;
|
|
1939
1972
|
}
|
|
1940
1973
|
getType(binding) {
|
|
@@ -2021,6 +2054,9 @@ function findNextExp(str) {
|
|
|
2021
2054
|
};
|
|
2022
2055
|
}
|
|
2023
2056
|
function resolveExpressionsInString(val, { evaluate }) {
|
|
2057
|
+
if (!evaluate) {
|
|
2058
|
+
return val;
|
|
2059
|
+
}
|
|
2024
2060
|
const expMatch = /@\[.*?\]@/;
|
|
2025
2061
|
let newVal = val;
|
|
2026
2062
|
let match = newVal.match(expMatch);
|
|
@@ -2040,7 +2076,7 @@ function resolveExpressionsInString(val, { evaluate }) {
|
|
|
2040
2076
|
function resolveDataRefsInString(val, options) {
|
|
2041
2077
|
const { model } = options;
|
|
2042
2078
|
let workingString = resolveExpressionsInString(val, options);
|
|
2043
|
-
if (typeof workingString !== "string" || workingString.indexOf(DOUBLE_OPEN_CURLY) === -1) {
|
|
2079
|
+
if (!model || typeof workingString !== "string" || workingString.indexOf(DOUBLE_OPEN_CURLY) === -1) {
|
|
2044
2080
|
return workingString;
|
|
2045
2081
|
}
|
|
2046
2082
|
while (workingString.indexOf(DOUBLE_OPEN_CURLY) !== -1) {
|
|
@@ -2069,9 +2105,9 @@ function traverseObject(val, options) {
|
|
|
2069
2105
|
const keys = Object.keys(val);
|
|
2070
2106
|
let newVal = val;
|
|
2071
2107
|
if (keys.length > 0) {
|
|
2072
|
-
|
|
2108
|
+
keys.forEach((key) => {
|
|
2073
2109
|
newVal = setIn(newVal, [key], traverseObject(val[key], options));
|
|
2074
|
-
}
|
|
2110
|
+
});
|
|
2075
2111
|
}
|
|
2076
2112
|
return newVal;
|
|
2077
2113
|
}
|
|
@@ -2123,7 +2159,7 @@ class ValidationMiddleware {
|
|
|
2123
2159
|
} else if (validations instanceof Set) {
|
|
2124
2160
|
validations.forEach((validation) => {
|
|
2125
2161
|
invalidBindings.push(validation.binding);
|
|
2126
|
-
if (!validation.isStrong) {
|
|
2162
|
+
if (!validation.isStrong && validation.binding.asString() === binding.asString()) {
|
|
2127
2163
|
nextTransaction.push([validation.binding, value]);
|
|
2128
2164
|
}
|
|
2129
2165
|
});
|
|
@@ -2263,7 +2299,13 @@ class Parser {
|
|
|
2263
2299
|
if (!localObj) {
|
|
2264
2300
|
return currentValue;
|
|
2265
2301
|
}
|
|
2266
|
-
const objEntries = Array.isArray(localObj) ? localObj.map((v, i) => [i, v]) :
|
|
2302
|
+
const objEntries = Array.isArray(localObj) ? localObj.map((v, i) => [i, v]) : [
|
|
2303
|
+
...Object.entries(localObj),
|
|
2304
|
+
...Object.getOwnPropertySymbols(localObj).map((s) => [
|
|
2305
|
+
s,
|
|
2306
|
+
localObj[s]
|
|
2307
|
+
])
|
|
2308
|
+
];
|
|
2267
2309
|
const defaultValue = {
|
|
2268
2310
|
children: [],
|
|
2269
2311
|
value: currentValue
|
|
@@ -4205,7 +4247,6 @@ class DataController {
|
|
|
4205
4247
|
}
|
|
4206
4248
|
});
|
|
4207
4249
|
this.hooks.onSet.call(normalizedTransaction);
|
|
4208
|
-
this.hooks.onSet.call(normalizedTransaction);
|
|
4209
4250
|
if (setUpdates.length > 0) {
|
|
4210
4251
|
this.hooks.onUpdate.call(setUpdates, options);
|
|
4211
4252
|
}
|
|
@@ -4364,6 +4405,39 @@ class FlowExpPlugin {
|
|
|
4364
4405
|
}
|
|
4365
4406
|
}
|
|
4366
4407
|
|
|
4408
|
+
const createFormatFunction = (schema) => {
|
|
4409
|
+
const handler = (ctx, value, formatName) => {
|
|
4410
|
+
var _a, _b;
|
|
4411
|
+
return (_b = (_a = schema.getFormatterForType({ type: formatName })) == null ? void 0 : _a.format(value)) != null ? _b : value;
|
|
4412
|
+
};
|
|
4413
|
+
return handler;
|
|
4414
|
+
};
|
|
4415
|
+
class DefaultExpPlugin {
|
|
4416
|
+
constructor() {
|
|
4417
|
+
this.name = "flow-exp-plugin";
|
|
4418
|
+
}
|
|
4419
|
+
apply(player) {
|
|
4420
|
+
let formatFunction;
|
|
4421
|
+
player.hooks.schema.tap(this.name, (schemaController) => {
|
|
4422
|
+
formatFunction = createFormatFunction(schemaController);
|
|
4423
|
+
});
|
|
4424
|
+
player.hooks.expressionEvaluator.tap(this.name, (expEvaluator) => {
|
|
4425
|
+
if (formatFunction) {
|
|
4426
|
+
expEvaluator.addExpressionFunction("format", formatFunction);
|
|
4427
|
+
}
|
|
4428
|
+
expEvaluator.addExpressionFunction("log", (ctx, ...args) => {
|
|
4429
|
+
player.logger.info(...args);
|
|
4430
|
+
});
|
|
4431
|
+
expEvaluator.addExpressionFunction("debug", (ctx, ...args) => {
|
|
4432
|
+
player.logger.debug(...args);
|
|
4433
|
+
});
|
|
4434
|
+
expEvaluator.addExpressionFunction("eval", (ctx, ...args) => {
|
|
4435
|
+
return ctx.evaluate(...args);
|
|
4436
|
+
});
|
|
4437
|
+
});
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4367
4441
|
const NOT_STARTED_STATE = {
|
|
4368
4442
|
ref: Symbol("not-started"),
|
|
4369
4443
|
status: "not-started"
|
|
@@ -4408,8 +4482,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4408
4482
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
4409
4483
|
});
|
|
4410
4484
|
};
|
|
4411
|
-
const PLAYER_VERSION = "0.4.0-next.
|
|
4412
|
-
const COMMIT = "
|
|
4485
|
+
const PLAYER_VERSION = "0.4.0-next.6";
|
|
4486
|
+
const COMMIT = "380eb6be2e6d61675cf721c4c3e64821099e5fbe";
|
|
4413
4487
|
const _Player = class {
|
|
4414
4488
|
constructor(config) {
|
|
4415
4489
|
this.logger = new TapableLogger();
|
|
@@ -4430,14 +4504,15 @@ const _Player = class {
|
|
|
4430
4504
|
resolveFlowContent: new SyncWaterfallHook()
|
|
4431
4505
|
};
|
|
4432
4506
|
var _a;
|
|
4433
|
-
const initialPlugins = [];
|
|
4434
|
-
const flowExpPlugin = new FlowExpPlugin();
|
|
4435
|
-
initialPlugins.push(flowExpPlugin);
|
|
4436
4507
|
if (config == null ? void 0 : config.logger) {
|
|
4437
4508
|
this.logger.addHandler(config.logger);
|
|
4438
4509
|
}
|
|
4439
4510
|
this.config = config || {};
|
|
4440
|
-
this.config.plugins = [
|
|
4511
|
+
this.config.plugins = [
|
|
4512
|
+
new DefaultExpPlugin(),
|
|
4513
|
+
...this.config.plugins || [],
|
|
4514
|
+
new FlowExpPlugin()
|
|
4515
|
+
];
|
|
4441
4516
|
(_a = this.config.plugins) == null ? void 0 : _a.forEach((plugin) => {
|
|
4442
4517
|
plugin.apply(this);
|
|
4443
4518
|
});
|
|
@@ -4621,11 +4696,6 @@ const _Player = class {
|
|
|
4621
4696
|
this.hooks.view.call(view);
|
|
4622
4697
|
});
|
|
4623
4698
|
this.hooks.viewController.call(viewController);
|
|
4624
|
-
const formatFunction = (ctx, value, formatName) => {
|
|
4625
|
-
var _a, _b;
|
|
4626
|
-
return (_b = (_a = schema.getFormatterForType({ type: formatName })) == null ? void 0 : _a.format(value)) != null ? _b : value;
|
|
4627
|
-
};
|
|
4628
|
-
expressionEvaluator.addExpressionFunction("format", formatFunction);
|
|
4629
4699
|
return {
|
|
4630
4700
|
start: () => {
|
|
4631
4701
|
flowController.start().then((endState) => {
|
|
@@ -4705,5 +4775,5 @@ Player.info = {
|
|
|
4705
4775
|
commit: COMMIT
|
|
4706
4776
|
};
|
|
4707
4777
|
|
|
4708
|
-
export { ApplicabilityPlugin, AssetTransformCorePlugin, BindingInstance, BindingParser, Builder, ConsoleLogger, ConstantsController, DataController, DependencyMiddleware, DependencyModel, DependencyTracker, EMPTY_NODE, ExpNodeOpaqueIdentifier, ExpressionEvaluator, FlowController, FlowExpPlugin, FlowInstance, LocalModel, LocalStateStore, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NodeType, NoopLogger, Parser, PipelinedDataModel, Player, ProxyLogger, ROOT_BINDING, Resolver, SIMPLE_BINDING_REGEX, SchemaController, StringResolverPlugin, SwitchPlugin, TapableLogger, TemplatePlugin, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidatorRegistry, ViewController, ViewInstance, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, maybeConvertToNum, parse, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
|
|
4778
|
+
export { ApplicabilityPlugin, AssetTransformCorePlugin, BindingInstance, BindingParser, Builder, ConsoleLogger, ConstantsController, DataController, DependencyMiddleware, DependencyModel, DependencyTracker, EMPTY_NODE, ExpNodeOpaqueIdentifier, ExpressionEvaluator, FlowController, FlowExpPlugin, FlowInstance, LocalModel, LocalStateStore, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NodeType, NoopLogger, Parser, PipelinedDataModel, Player, ProxyLogger, ROOT_BINDING, Resolver, SIMPLE_BINDING_REGEX, SchemaController, StringResolverPlugin, SwitchPlugin, TapableLogger, TemplatePlugin, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidatorRegistry, ViewController, ViewInstance, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, maybeConvertToNum, parse, parseExpression, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
|
|
4709
4779
|
//# sourceMappingURL=index.esm.js.map
|