@player-ui/player 0.4.0-next.0 → 0.4.0-next.10

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.
Files changed (42) hide show
  1. package/dist/index.cjs.js +730 -362
  2. package/dist/index.d.ts +220 -81
  3. package/dist/index.esm.js +726 -364
  4. package/dist/player.dev.js +12311 -0
  5. package/dist/player.prod.js +2 -0
  6. package/package.json +14 -5
  7. package/src/binding/binding.ts +8 -0
  8. package/src/binding/index.ts +1 -1
  9. package/src/controllers/constants/index.ts +9 -5
  10. package/src/controllers/data.ts +49 -54
  11. package/src/controllers/flow/controller.ts +16 -12
  12. package/src/controllers/flow/flow.ts +6 -1
  13. package/src/controllers/validation/binding-tracker.ts +42 -19
  14. package/src/controllers/validation/controller.ts +265 -85
  15. package/src/controllers/view/asset-transform.ts +4 -1
  16. package/src/controllers/view/controller.ts +19 -2
  17. package/src/data/dependency-tracker.ts +14 -0
  18. package/src/data/local-model.ts +25 -1
  19. package/src/data/model.ts +55 -8
  20. package/src/data/noop-model.ts +2 -0
  21. package/src/expressions/evaluator-functions.ts +24 -2
  22. package/src/expressions/evaluator.ts +37 -33
  23. package/src/expressions/index.ts +1 -0
  24. package/src/expressions/parser.ts +53 -27
  25. package/src/expressions/types.ts +23 -5
  26. package/src/expressions/utils.ts +19 -0
  27. package/src/player.ts +44 -48
  28. package/src/plugins/default-exp-plugin.ts +57 -0
  29. package/src/plugins/flow-exp-plugin.ts +2 -2
  30. package/src/schema/schema.ts +28 -9
  31. package/src/string-resolver/index.ts +25 -9
  32. package/src/types.ts +1 -4
  33. package/src/validator/binding-map-splice.ts +59 -0
  34. package/src/validator/index.ts +1 -0
  35. package/src/validator/types.ts +11 -3
  36. package/src/validator/validation-middleware.ts +38 -4
  37. package/src/view/parser/index.ts +51 -3
  38. package/src/view/plugins/applicability.ts +1 -1
  39. package/src/view/plugins/string-resolver.ts +8 -4
  40. package/src/view/plugins/template-plugin.ts +1 -6
  41. package/src/view/resolver/index.ts +119 -54
  42. package/src/view/resolver/types.ts +48 -7
package/dist/index.d.ts CHANGED
@@ -58,6 +58,13 @@ interface BindingParserOptions {
58
58
  * Get the result of evaluating an expression
59
59
  */
60
60
  evaluate: (exp: string) => any;
61
+ /**
62
+ * Without readOnly, if a binding such as this is used: arr[key='does not exist'],
63
+ * then an object with that key will be created.
64
+ * This is done to make assignment such as arr[key='abc'].val = 'foo' work smoothly.
65
+ * Setting readOnly to true will prevent this behavior, avoiding unintended data changes.
66
+ */
67
+ readOnly?: boolean;
61
68
  }
62
69
  declare type Getter = (path: BindingInstance) => any;
63
70
  declare type RawBindingSegment = number | string;
@@ -178,16 +185,19 @@ interface DataModelOptions {
178
185
  interface DataModelWithParser<Options = DataModelOptions> {
179
186
  get(binding: BindingLike, options?: Options): any;
180
187
  set(transaction: [BindingLike, any][], options?: Options): Updates;
188
+ delete(binding: BindingLike, options?: Options): void;
181
189
  }
182
190
  interface DataModelImpl<Options = DataModelOptions> {
183
191
  get(binding: BindingInstance, options?: Options): any;
184
192
  set(transaction: BatchSetTransaction, options?: Options): Updates;
193
+ delete(binding: BindingInstance, options?: Options): void;
185
194
  }
186
195
  interface DataModelMiddleware {
187
196
  /** The name of the middleware */
188
197
  name?: string;
189
198
  set(transaction: BatchSetTransaction, options?: DataModelOptions, next?: DataModelImpl): Updates;
190
199
  get(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): any;
200
+ delete?(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): void;
191
201
  reset?(): void;
192
202
  }
193
203
  /** Wrap the inputs of the DataModel with calls to parse raw binding inputs */
@@ -212,6 +222,7 @@ declare class PipelinedDataModel implements DataModelImpl {
212
222
  reset(model?: {}): void;
213
223
  set(transaction: BatchSetTransaction, options?: DataModelOptions): Updates;
214
224
  get(binding: BindingInstance, options?: DataModelOptions): any;
225
+ delete(binding: BindingInstance, options?: DataModelOptions): void;
215
226
  }
216
227
 
217
228
  declare type DependencySets = 'core' | 'children';
@@ -250,6 +261,7 @@ declare class DependencyMiddleware extends DependencyTracker implements DataMode
250
261
  constructor();
251
262
  set(transaction: BatchSetTransaction, options?: DataModelOptions, next?: DataModelImpl | undefined): Updates;
252
263
  get(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl | undefined): any;
264
+ delete(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl | undefined): void | undefined;
253
265
  }
254
266
  /** A data-model that tracks dependencies of read/written data */
255
267
  declare class DependencyModel<Options = DataModelOptions> extends DependencyTracker implements DataModelImpl<Options> {
@@ -257,6 +269,7 @@ declare class DependencyModel<Options = DataModelOptions> extends DependencyTrac
257
269
  constructor(rootModel: DataModelImpl<Options>);
258
270
  set(transaction: BatchSetTransaction, options?: Options): Updates;
259
271
  get(binding: BindingInstance, options?: Options): any;
272
+ delete(binding: BindingInstance, options?: Options): void;
260
273
  }
261
274
 
262
275
  /**
@@ -266,6 +279,7 @@ declare class DependencyModel<Options = DataModelOptions> extends DependencyTrac
266
279
  declare class NOOPDataModel implements DataModelImpl {
267
280
  get(): undefined;
268
281
  set(): never[];
282
+ delete(): void;
269
283
  }
270
284
  /** You only really need 1 instance of the NOOP model */
271
285
  declare const NOOP_MODEL: NOOPDataModel;
@@ -281,6 +295,7 @@ declare class LocalModel implements DataModelImpl {
281
295
  reset(model?: {}): void;
282
296
  get(binding?: BindingInstance): any;
283
297
  set(transaction: BatchSetTransaction): Updates;
298
+ delete(binding: BindingInstance): void;
284
299
  }
285
300
 
286
301
  declare type LogFn = (...args: Array<any>) => void;
@@ -349,8 +364,13 @@ declare class ProxyLogger implements Logger {
349
364
  readonly error: (...args: any[]) => void;
350
365
  }
351
366
 
367
+ declare type ExpressionObjectType = {
368
+ /** The expression to eval */
369
+ value: BasicExpressionTypes;
370
+ };
352
371
  declare type ExpressionLiteralType = string | number | boolean | undefined | null;
353
- declare type ExpressionType = object | ExpressionLiteralType | Array<ExpressionLiteralType> | ExpressionNode;
372
+ declare type BasicExpressionTypes = ExpressionLiteralType | ExpressionObjectType | Array<ExpressionLiteralType | ExpressionObjectType>;
373
+ declare type ExpressionType = BasicExpressionTypes | ExpressionNode;
354
374
  interface OperatorProcessingOptions {
355
375
  /**
356
376
  * When set to a falsy value, the arguments passed to the handler will be raw AST Nodes
@@ -391,6 +411,11 @@ interface BaseNode<T> {
391
411
  __id: typeof ExpNodeOpaqueIdentifier;
392
412
  /** The location of the node in the source expression string */
393
413
  location?: NodeLocation;
414
+ /**
415
+ * The error that occurred while parsing this node
416
+ * This is only set if the parsing mode is set to non-strict
417
+ */
418
+ error?: Error;
394
419
  }
395
420
  /** A helper interface for nodes that container left and right children */
396
421
  interface DirectionalNode {
@@ -478,6 +503,10 @@ declare type ExpressionNodeType = ExpressionNode['type'];
478
503
  interface HookOptions extends ExpressionContext {
479
504
  /** Given an expression node */
480
505
  resolveNode: (node: ExpressionNode) => any;
506
+ /** Enabling this flag skips calling the onError hook, and just throws errors back to the caller.
507
+ * The caller is responsible for handling the error.
508
+ */
509
+ throwErrors?: boolean;
481
510
  }
482
511
  declare type ExpressionEvaluatorOptions = Omit<HookOptions, 'resolveNode' | 'evaluate'>;
483
512
  declare type ExpressionEvaluatorFunction = (exp: ExpressionType, options?: ExpressionEvaluatorOptions) => any;
@@ -489,6 +518,10 @@ declare class ExpressionEvaluator {
489
518
  readonly hooks: {
490
519
  /** Resolve an AST node for an expression to a value */
491
520
  resolve: SyncWaterfallHook<[any, ExpressionNode, HookOptions], Record<string, any>>;
521
+ /** Gets the options that will be passed in calls to the resolve hook */
522
+ resolveOptions: SyncWaterfallHook<[HookOptions], Record<string, any>>;
523
+ /** Allows users to change the expression to be evaluated before processing */
524
+ beforeEvaluate: SyncWaterfallHook<[ExpressionType, HookOptions], Record<string, any>>;
492
525
  /**
493
526
  * An optional means of handling an error in the expression execution
494
527
  * Return true if handled, to stop propagation of the error
@@ -504,7 +537,7 @@ declare class ExpressionEvaluator {
504
537
  };
505
538
  reset(): void;
506
539
  constructor(defaultOptions: ExpressionEvaluatorOptions);
507
- evaluate(expression: ExpressionType, options?: ExpressionEvaluatorOptions): any;
540
+ evaluate(expr: ExpressionType, options?: ExpressionEvaluatorOptions): any;
508
541
  addExpressionFunction<T extends readonly unknown[], R>(name: string, handler: ExpressionHandler<T, R>): void;
509
542
  addBinaryOperator(operator: string, handler: BinaryOperator): void;
510
543
  addUnaryOperator(operator: string, handler: UnaryOperator): void;
@@ -519,6 +552,18 @@ declare class ExpressionEvaluator {
519
552
  declare function withoutContext<T extends unknown[], Return>(fn: (...args: T) => Return): ExpressionHandler<T, Return>;
520
553
  /** Get the node in the expression that's closest to the desired position */
521
554
  declare function findClosestNodeAtPosition(node: ExpressionNode, position: NodePosition): ExpressionNode | undefined;
555
+ /** Checks if the expression is a simple type */
556
+ declare function isObjectExpression(expr: ExpressionType): expr is ExpressionObjectType;
557
+
558
+ /**
559
+ * An expression to AST parser based on JSEP: http://jsep.from.so/
560
+ */
561
+
562
+ /** Parse out an expression from the string */
563
+ declare function parseExpression(expr: string, options?: {
564
+ /** If true (the default), will throw on invalid expressions */
565
+ strict?: boolean;
566
+ }): ExpressionNode;
522
567
 
523
568
  declare type FormatOptions = Omit<Formatting.Reference, 'type'>;
524
569
  /**
@@ -590,6 +635,8 @@ declare class FlowInstance {
590
635
  resolveTransitionNode: SyncWaterfallHook<[NavigationFlowState], Record<string, any>>;
591
636
  /** A callback when a transition from 1 state to another was made */
592
637
  transition: SyncHook<[NamedState | undefined, NamedState], Record<string, any>>;
638
+ /** A callback to run actions after a transition occurs */
639
+ afterTransition: SyncHook<[FlowInstance], Record<string, any>>;
593
640
  };
594
641
  constructor(id: string, flow: NavigationFlow, options?: {
595
642
  /** Logger instance to use */
@@ -757,24 +804,95 @@ declare class Parser {
757
804
  };
758
805
  parseView(value: AnyAssetType): Node.View;
759
806
  createASTNode(node: Node.Node | null, value: any): Node.Node | null;
807
+ /**
808
+ * Checks if there are templated values in the object
809
+ *
810
+ * @param obj - The Parsed Object to check to see if we have a template array type for
811
+ * @param localKey - The key being checked
812
+ */
813
+ private hasTemplateValues;
760
814
  parseObject(obj: object, type?: Node.ChildrenTypes, options?: ParseObjectOptions): Node.Node | null;
761
815
  }
762
816
 
817
+ interface ConstantsProvider {
818
+ /**
819
+ * Function to add constants to the providers store
820
+ * - @param data values to add to the constants store
821
+ */
822
+ addConstants(data: Record<string, any>, namespace: string): void;
823
+ /**
824
+ * Function to retrieve constants from the providers store
825
+ * - @param key Key used for the store access
826
+ * - @param namespace namespace values were loaded under (defined in the plugin)
827
+ * - @param fallback Optional - if key doesn't exist in namespace what to return (will return unknown if not provided)
828
+ */
829
+ getConstants(key: any, namespace: string, fallback?: any): any;
830
+ /**
831
+ * Function to set values to temporarily override certain keys in the perminant store
832
+ * - @param data values to override store with
833
+ * - @param namespace namespace to override
834
+ */
835
+ setTemporaryValues(data: any, namespace: string): void;
836
+ /**
837
+ * Clears any temporary values that were previously set
838
+ */
839
+ clearTemporaryValues(): void;
840
+ }
841
+ /**
842
+ * Key/Value store for constants and context for Player
843
+ */
844
+ declare class ConstantsController implements ConstantsProvider {
845
+ /**
846
+ * Data store is basically a map of namespaces to DataModels to provide some data isolation
847
+ */
848
+ private store;
849
+ /**
850
+ * Separate store for temporary flow specific overrides.
851
+ * They are kept in a separate data model to make clearing it easier between flows
852
+ * and so there is no confusion on what is static and what is temporary
853
+ */
854
+ private tempStore;
855
+ constructor();
856
+ addConstants(data: any, namespace: string): void;
857
+ getConstants(key: string, namespace: string, fallback?: any): any;
858
+ setTemporaryValues(data: any, namespace: string): void;
859
+ clearTemporaryValues(namespace?: string): void;
860
+ }
861
+
862
+ interface ValidationGetResolveOptions {
863
+ /**
864
+ * If we should ignore any non-blocking validations in the return
865
+ * @default true
866
+ */
867
+ ignoreNonBlocking?: boolean;
868
+ }
869
+ interface PlayerUtils {
870
+ findPlugin<Plugin = unknown>(symbol: symbol): Plugin | undefined;
871
+ }
763
872
  declare namespace Resolve {
764
873
  interface Validation {
765
874
  /** Fetch the data-type for the given binding */
766
875
  type(binding: BindingLike): Schema.DataType | undefined;
767
876
  /** Get all currently applicable validation errors */
768
- getAll(): Map<BindingInstance, ValidationResponse> | undefined;
877
+ getAll(options?: ValidationGetResolveOptions): Map<BindingInstance, ValidationResponse> | undefined;
769
878
  /** Internal Method to lookup if there is a validation for the given binding */
770
- _getValidationForBinding(binding: BindingLike): ValidationResponse | undefined;
879
+ _getValidationForBinding(binding: BindingLike): {
880
+ /** Get the validation for the given binding */
881
+ get: (options?: ValidationGetResolveOptions) => ValidationResponse | undefined;
882
+ /** Get all validations for the given binding */
883
+ getAll: (options?: ValidationGetResolveOptions) => Array<ValidationResponse>;
884
+ } | undefined;
771
885
  /** Get field level error for the specific binding */
772
886
  get(binding: BindingLike, options?: {
773
887
  /** If this binding should also be tracked for validations */
774
- track: boolean;
775
- }): ValidationResponse | undefined;
888
+ track?: boolean;
889
+ } & ValidationGetResolveOptions): ValidationResponse | undefined;
890
+ getValidationsForBinding(binding: BindingLike, options?: {
891
+ /** If this binding should also be tracked for validations */
892
+ track?: boolean;
893
+ } & ValidationGetResolveOptions): Array<ValidationResponse>;
776
894
  /** Get errors for all children regardless of section */
777
- getChildren(type: Validation.DisplayTarget): Array<ValidationResponse>;
895
+ getChildren(type?: Validation.DisplayTarget): Array<ValidationResponse>;
778
896
  /** Get errors for all children solely in this section */
779
897
  getValidationsForSection(): Array<ValidationResponse>;
780
898
  /** Track errors for this binding, and notify the node of changes */
@@ -788,6 +906,8 @@ declare namespace Resolve {
788
906
  interface BaseOptions {
789
907
  /** A logger to use */
790
908
  logger?: Logger;
909
+ /** Utils for various useful operations */
910
+ utils?: PlayerUtils;
791
911
  /** An optional set of validation features */
792
912
  validation?: Validation;
793
913
  /** Parse a raw valy into an AST node */
@@ -796,6 +916,8 @@ declare namespace Resolve {
796
916
  transition?: TransitionFunction;
797
917
  /** The hub for data invariants and metaData associated with the data model */
798
918
  schema: SchemaController;
919
+ /** The constants for messages */
920
+ constants?: ConstantsProvider;
799
921
  }
800
922
  interface NodeDataOptions {
801
923
  /** The data to set or get data from */
@@ -922,8 +1044,10 @@ declare class Resolver {
922
1044
  constructor(root: Node.Node, options: Resolve.ResolverOptions);
923
1045
  getSourceNode(convertedAST: Node.Node): Node.Node | undefined;
924
1046
  update(changes?: Set<BindingInstance>): any;
1047
+ getResolveCache(): Map<Node.Node, Resolve.ResolvedNode>;
925
1048
  private getNodeID;
926
1049
  private getPreviousResult;
1050
+ private cloneNode;
927
1051
  private computeTree;
928
1052
  }
929
1053
 
@@ -1056,6 +1180,8 @@ declare class Builder {
1056
1180
  interface BindingTracker {
1057
1181
  /** Get the bindings currently being tracked for validation */
1058
1182
  getBindings(): Set<BindingInstance>;
1183
+ /** Add a binding to the tracked set */
1184
+ trackBinding(binding: BindingInstance): void;
1059
1185
  }
1060
1186
  interface Options$1 {
1061
1187
  /** Parse a binding from a view */
@@ -1073,12 +1199,21 @@ declare class ValidationBindingTrackerViewPlugin implements ViewPlugin, BindingT
1073
1199
  constructor(options: Options$1);
1074
1200
  /** Fetch the tracked bindings in the current view */
1075
1201
  getBindings(): Set<BindingInstance>;
1202
+ /** Add a binding to the tracked set */
1203
+ trackBinding(binding: BindingInstance): void;
1076
1204
  /** Attach hooks to the given resolver */
1077
1205
  applyResolver(resolver: Resolver): void;
1078
1206
  apply(view: ViewInstance): void;
1079
1207
  }
1080
1208
 
1081
- declare type SimpleValidatorContext = Omit<ValidatorContext, 'validation'>;
1209
+ declare const SCHEMA_VALIDATION_PROVIDER_NAME = "schema";
1210
+ declare const VIEW_VALIDATION_PROVIDER_NAME = "view";
1211
+ declare const VALIDATION_PROVIDER_NAME_SYMBOL: unique symbol;
1212
+ declare type ValidationObjectWithSource = ValidationObjectWithHandler & {
1213
+ /** The name of the validation */
1214
+ [VALIDATION_PROVIDER_NAME_SYMBOL]: string;
1215
+ };
1216
+ declare type SimpleValidatorContext = Omit<ValidatorContext, 'validation' | 'schemaType'>;
1082
1217
  interface BaseActiveValidation<T> {
1083
1218
  /** The validation is being actively shown */
1084
1219
  state: 'active';
@@ -1097,7 +1232,9 @@ declare type StatefulWarning = {
1097
1232
  /** A common key to differentiate between errors and warnings */
1098
1233
  type: 'warning';
1099
1234
  /** The underlying validation this tracks */
1100
- value: ValidationObject;
1235
+ value: ValidationObjectWithSource;
1236
+ /** If this is currently preventing navigation from continuing */
1237
+ isBlockingNavigation: boolean;
1101
1238
  } & ({
1102
1239
  /** warnings start with no state, but can active or dismissed */
1103
1240
  state: 'none' | 'dismissed';
@@ -1107,24 +1244,29 @@ declare type StatefulError = {
1107
1244
  /** A common key to differentiate between errors and warnings */
1108
1245
  type: 'error';
1109
1246
  /** The underlying validation this tracks */
1110
- value: ValidationObject;
1247
+ value: ValidationObjectWithSource;
1248
+ /** If this is currently preventing navigation from continuing */
1249
+ isBlockingNavigation: boolean;
1111
1250
  } & ({
1112
1251
  /** Errors start with no state an can be activated */
1113
1252
  state: 'none';
1114
1253
  } | ActiveError);
1115
1254
  declare type StatefulValidationObject = StatefulWarning | StatefulError;
1116
- declare type ValidationRunner = (obj: ValidationObject) => {
1255
+ declare type ValidationRunner = (obj: ValidationObjectWithHandler) => {
1117
1256
  /** A validation message */
1118
1257
  message: string;
1119
1258
  } | undefined;
1120
1259
  /** A class that manages validating bindings across phases */
1121
1260
  declare class ValidatedBinding {
1122
- private currentPhase?;
1261
+ currentPhase?: Validation.Trigger;
1123
1262
  private applicableValidations;
1124
1263
  private validationsByState;
1264
+ get allValidations(): Array<StatefulValidationObject>;
1125
1265
  weakBindings: Set<BindingInstance>;
1126
1266
  private onDismiss?;
1127
- constructor(possibleValidations: Array<ValidationObject>, onDismiss?: () => void, log?: Logger, weakBindings?: Set<BindingInstance>);
1267
+ constructor(possibleValidations: Array<ValidationObjectWithSource>, onDismiss?: () => void, log?: Logger, weakBindings?: Set<BindingInstance>);
1268
+ private checkIfBlocking;
1269
+ getAll(): Array<ValidationResponse>;
1128
1270
  get(): ValidationResponse | undefined;
1129
1271
  private runApplicableValidations;
1130
1272
  update(phase: Validation.Trigger, canDismiss: boolean, runner: ValidationRunner): void;
@@ -1156,27 +1298,43 @@ declare class ValidationController implements BindingTracker {
1156
1298
  onAddValidation: SyncWaterfallHook<[ValidationResponse, BindingInstance], Record<string, any>>;
1157
1299
  /** The inverse of onAddValidation, this is called when a validation is removed from the list */
1158
1300
  onRemoveValidation: SyncWaterfallHook<[ValidationResponse, BindingInstance], Record<string, any>>;
1301
+ resolveValidationProviders: SyncWaterfallHook<[{
1302
+ /** The name of the provider */
1303
+ source: string;
1304
+ /** The provider itself */
1305
+ provider: ValidationProvider;
1306
+ }[]], {
1307
+ /** The view this is triggered for */
1308
+ view?: ViewInstance | undefined;
1309
+ }>;
1310
+ /** A hook called when a binding is added to the tracker */
1311
+ onTrackBinding: SyncHook<[BindingInstance], Record<string, any>>;
1159
1312
  };
1160
1313
  private tracker;
1161
1314
  private validations;
1162
1315
  private validatorRegistry?;
1163
1316
  private schema;
1164
1317
  private providers;
1318
+ private viewValidationProvider?;
1165
1319
  private options?;
1166
1320
  private weakBindingTracker;
1167
- private lastActiveBindings;
1168
1321
  constructor(schema: SchemaController, options?: SimpleValidatorContext);
1169
1322
  setOptions(options: SimpleValidatorContext): void;
1170
1323
  /** Return the middleware for the data-model to stop propagation of invalid data */
1171
1324
  getDataMiddleware(): Array<DataModelMiddleware>;
1325
+ private getValidationProviders;
1326
+ reset(): void;
1172
1327
  onView(view: ViewInstance): void;
1173
- private updateValidationsForBinding;
1174
- private validationRunner;
1328
+ updateValidationsForBinding(binding: BindingInstance, trigger: Validation.Trigger, validationContext?: SimpleValidatorContext, onDismiss?: () => void): void;
1329
+ validationRunner(validationObj: ValidationObjectWithHandler, binding: BindingInstance, context?: SimpleValidatorContext | undefined): {
1330
+ message: string;
1331
+ } | undefined;
1175
1332
  private updateValidationsForView;
1176
1333
  private setCompare;
1177
1334
  private get activeBindings();
1178
1335
  getValidator(type: string): ValidatorFunction<unknown> | undefined;
1179
1336
  getBindings(): Set<BindingInstance>;
1337
+ trackBinding(binding: BindingInstance): void;
1180
1338
  /** Executes all known validations for the tracked bindings using the given model */
1181
1339
  validateView(trigger?: Validation.Trigger): {
1182
1340
  /** Indicating if the view can proceed without error */
@@ -1184,6 +1342,7 @@ declare class ValidationController implements BindingTracker {
1184
1342
  /** the validations that are preventing the view from continuing */
1185
1343
  validations?: Map<BindingInstance, ValidationResponse>;
1186
1344
  };
1345
+ /** Get the current tracked validation for the given binding */
1187
1346
  getValidationForBinding(binding: BindingInstance): ValidatedBinding | undefined;
1188
1347
  forView(parser: BindingFactory): Resolve.Validation;
1189
1348
  }
@@ -1266,10 +1425,7 @@ declare type InProgressState = BaseFlowState<'in-progress'> & PlayerFlowExecutio
1266
1425
  logger: Logger;
1267
1426
  };
1268
1427
  /** The flow completed properly */
1269
- declare type CompletedState = BaseFlowState<'completed'> & PlayerFlowExecutionData & FlowResult & {
1270
- /** The top-level data-model for the flow */
1271
- dataModel: DataModelWithParser;
1272
- };
1428
+ declare type CompletedState = BaseFlowState<'completed'> & PlayerFlowExecutionData & FlowResult;
1273
1429
  /** The flow finished but not successfully */
1274
1430
  declare type ErrorState = BaseFlowState<'error'> & {
1275
1431
  /** The currently executing flow */
@@ -1314,10 +1470,7 @@ declare class DataController implements DataModelWithParser<DataModelOptions> {
1314
1470
  set(transaction: RawSetTransaction, options?: DataModelOptions): Updates;
1315
1471
  private resolve;
1316
1472
  get(binding: BindingLike, options?: DataModelOptions): any;
1317
- delete(binding: BindingLike): void;
1318
- getTrash(): Set<BindingInstance>;
1319
- private addToTrash;
1320
- private deleteData;
1473
+ delete(binding: BindingLike, options?: DataModelOptions): void;
1321
1474
  serialize(): object;
1322
1475
  }
1323
1476
 
@@ -1365,51 +1518,6 @@ declare class AssetTransformCorePlugin {
1365
1518
  apply(viewController: ViewController): void;
1366
1519
  }
1367
1520
 
1368
- interface ConstantsProvider {
1369
- /**
1370
- * Function to add constants to the providers store
1371
- * - @param data values to add to the constants store
1372
- */
1373
- addConstants(data: Record<string, any>, namespace: string): void;
1374
- /**
1375
- * Function to retreive constants from the providers store
1376
- * - @param key Key used for the store access
1377
- * - @param namespace namespace values were loaded under (defined in the plugin)
1378
- * - @param fallback Optional - if key doesn't exist in namespace what to return (will return unknown if not provided)
1379
- */
1380
- getConstants(key: any, namespace: string, fallback?: any): any;
1381
- /**
1382
- * Function to set values to temporarily override certain keys in the perminant store
1383
- * - @param data values to override store with
1384
- * - @param namespace namespace to override
1385
- */
1386
- setTemporaryValues(data: any, namespace: string): void;
1387
- /**
1388
- * Clears any temporary values that were previously set
1389
- */
1390
- clearTemporaryValues(): void;
1391
- }
1392
- /**
1393
- * Key/Value store for constants and context for Player
1394
- */
1395
- declare class ConstantsController implements ConstantsProvider {
1396
- /**
1397
- * Data store is basically a map of namespaces to DataModels to provide some data isolation
1398
- */
1399
- private store;
1400
- /**
1401
- * Separate store for temporary flow specific overrides.
1402
- * They are kept in a separate data model to make clearing it easier between flows
1403
- * and so there is no confusion on what is static and what is temporary
1404
- */
1405
- private tempStore;
1406
- constructor();
1407
- addConstants(data: any, namespace: string): void;
1408
- getConstants(key: string, namespace: string, fallback?: any): any;
1409
- setTemporaryValues(data: any, namespace: string): void;
1410
- clearTemporaryValues(): void;
1411
- }
1412
-
1413
1521
  interface BaseValidationResponse<T = Validation.Severity> {
1414
1522
  /** The validation message to show to the user */
1415
1523
  message: string;
@@ -1430,9 +1538,13 @@ declare type ErrorValidationResponse = BaseValidationResponse<'error'>;
1430
1538
  declare type ValidationResponse = ErrorValidationResponse | WarningValidationResponse;
1431
1539
  declare type RequiredValidationKeys = 'severity' | 'trigger';
1432
1540
  declare type ValidationObject = Validation.Reference & Required<Pick<Validation.Reference, RequiredValidationKeys>>;
1541
+ declare type ValidationObjectWithHandler = ValidationObject & {
1542
+ /** A predefined handler for this validation object */
1543
+ handler?: ValidatorFunction;
1544
+ };
1433
1545
  interface ValidationProvider {
1434
- getValidationsForBinding?(binding: BindingInstance): Array<ValidationObject> | undefined;
1435
- getValidationsForView?(): Array<ValidationObject> | undefined;
1546
+ getValidationsForBinding?(binding: BindingInstance): Array<ValidationObjectWithHandler> | undefined;
1547
+ getValidationsForView?(): Array<ValidationObjectWithHandler> | undefined;
1436
1548
  }
1437
1549
  interface ValidatorContext {
1438
1550
  /** The data to set or get data from */
@@ -1447,6 +1559,8 @@ interface ValidatorContext {
1447
1559
  validation: ValidationObject;
1448
1560
  /** The constants for messages */
1449
1561
  constants: ConstantsProvider;
1562
+ /** The type in the schema that triggered the validation if there is one */
1563
+ schemaType: Schema.DataType | undefined;
1450
1564
  }
1451
1565
  declare type ValidatorFunction<Options = unknown> = (context: ValidatorContext, value: any, options?: Options) => Omit<BaseValidationResponse, 'severity'> | undefined;
1452
1566
 
@@ -1470,12 +1584,16 @@ declare class ValidationMiddleware implements DataModelMiddleware {
1470
1584
  validator: MiddlewareChecker;
1471
1585
  shadowModelPaths: Map<BindingInstance, any>;
1472
1586
  private logger?;
1587
+ private shouldIncludeInvalid?;
1473
1588
  constructor(validator: MiddlewareChecker, options?: {
1474
1589
  /** A logger instance */
1475
1590
  logger?: Logger;
1591
+ /** Optional function to include data staged in shadowModel */
1592
+ shouldIncludeInvalid?: (options?: DataModelOptions) => boolean;
1476
1593
  });
1477
1594
  set(transaction: BatchSetTransaction, options?: DataModelOptions, next?: DataModelImpl): Updates;
1478
1595
  get(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): any;
1596
+ delete(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): void | undefined;
1479
1597
  }
1480
1598
 
1481
1599
  /** A registry that tracks validators */
@@ -1488,8 +1606,17 @@ declare class ValidatorRegistry {
1488
1606
  register<T>(name: string, handler: ValidatorFunction<T>): void;
1489
1607
  }
1490
1608
 
1609
+ /**
1610
+ * Remove a binding, and any children from from the map
1611
+ * If the binding is an array-item, then it will be spliced from the array and the others will be shifted down
1612
+ *
1613
+ * @param sourceMap - A map of bindings to values
1614
+ * @param binding - The binding to remove from the map
1615
+ */
1616
+ declare function removeBindingAndChildrenFromMap<T>(sourceMap: Map<BindingInstance, T>, binding: BindingInstance): Map<BindingInstance, T>;
1617
+
1491
1618
  /** Expand the authored schema into a set of paths -> DataTypes */
1492
- declare function parse(schema: Schema.Schema): Map<string, Schema.DataType>;
1619
+ declare function parse(schema: Schema.Schema): Map<string, Schema.DataTypes>;
1493
1620
  /**
1494
1621
  * The Schema is the central hub for all data invariants, and metaData associated with the data-model itself
1495
1622
  * Outside of the types defined in the JSON payload, it doesn't manage or keep any state.
@@ -1498,18 +1625,18 @@ declare function parse(schema: Schema.Schema): Map<string, Schema.DataType>;
1498
1625
  declare class SchemaController implements ValidationProvider {
1499
1626
  private formatters;
1500
1627
  private types;
1501
- readonly schema: Map<string, Schema.DataType>;
1628
+ readonly schema: Map<string, Schema.DataTypes>;
1502
1629
  private bindingSchemaNormalizedCache;
1503
1630
  readonly hooks: {
1504
- resolveTypeForBinding: SyncWaterfallHook<[Schema.DataType<unknown> | undefined, BindingInstance], Record<string, any>>;
1631
+ resolveTypeForBinding: SyncWaterfallHook<[Schema.DataTypes | undefined, BindingInstance], Record<string, any>>;
1505
1632
  };
1506
1633
  constructor(schema?: Schema.Schema);
1507
1634
  addFormatters(fns: Array<FormatType<any, any, FormatOptions>>): void;
1508
1635
  addDataTypes(types: Array<Schema.DataType<any>>): void;
1509
1636
  getValidationsForBinding(binding: BindingInstance): Array<ValidationObject> | undefined;
1510
1637
  private normalizeBinding;
1511
- getType(binding: BindingInstance): Schema.DataType | undefined;
1512
- getApparentType(binding: BindingInstance): Schema.DataType | undefined;
1638
+ getType(binding: BindingInstance): Schema.DataTypes | undefined;
1639
+ getApparentType(binding: BindingInstance): Schema.DataTypes | undefined;
1513
1640
  getTypeDefinition(dataType: string): Schema.DataType<any> | undefined;
1514
1641
  getFormatterForType(formatReference: Formatting.Reference): FormatDefinition<unknown, unknown> | undefined;
1515
1642
  /**
@@ -1520,10 +1647,20 @@ declare class SchemaController implements ValidationProvider {
1520
1647
  }
1521
1648
 
1522
1649
  interface Options {
1523
- /** The model to use when resolving refs */
1524
- model: DataModelWithParser;
1525
- /** A function to evaluate an expression */
1526
- evaluate: (exp: Expression) => any;
1650
+ /**
1651
+ * The model to use when resolving refs
1652
+ * Passing `false` will skip trying to resolve any direct model refs ({{foo}})
1653
+ */
1654
+ model: false | DataModelWithParser;
1655
+ /**
1656
+ * A function to evaluate an expression
1657
+ * Passing `false` will skip trying to evaluate any expressions (@[ foo() ]@)
1658
+ */
1659
+ evaluate: false | ((exp: Expression) => any);
1660
+ /**
1661
+ * Optionaly resolve binding without formatting in case Type format applies
1662
+ */
1663
+ formatted?: boolean;
1527
1664
  }
1528
1665
  /** Search the given string for the coordinates of the next expression to resolve */
1529
1666
  declare function findNextExp(str: string): {
@@ -1550,6 +1687,8 @@ interface PlayerPlugin {
1550
1687
  */
1551
1688
  apply: (player: Player) => void;
1552
1689
  }
1690
+ interface ExtendedPlayerPlugin<Assets = void, Views = void, Expressions = void, DataTypes = void> {
1691
+ }
1553
1692
  interface PlayerConfigOptions {
1554
1693
  /** A set of plugins to load */
1555
1694
  plugins?: PlayerPlugin[];
@@ -1636,4 +1775,4 @@ declare class FlowExpPlugin implements PlayerPlugin {
1636
1775
  apply(player: Player): void;
1637
1776
  }
1638
1777
 
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 };
1778
+ export { AnyAssetType, ApplicabilityPlugin, ArrayExpressionNode, AssetTransformCorePlugin, AssignmentNode, BaseFlowState, BaseNode, BasicExpressionTypes, 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, ExpressionObjectType, 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, PlayerUtils, ProxyLogger, ROOT_BINDING, RawBinding, RawBindingSegment, RawSetTransaction, RawSetType, Resolve, Resolver, SCHEMA_VALIDATION_PROVIDER_NAME, SIMPLE_BINDING_REGEX, SchemaController, Severity, StatefulValidationObject, Store, StringResolverPlugin, StrongOrWeakBinding, SwitchPlugin, TapableLogger, TemplatePlugin, ThisNode, TransformFunction, TransformFunctions, TransformRegistry, TransitionFunction, TransitionOptions, UnaryNode, UnaryOperator, Updates, VALIDATION_PROVIDER_NAME_SYMBOL, VIEW_VALIDATION_PROVIDER_NAME, ValidationBindingTrackerViewPlugin, ValidationController, ValidationGetResolveOptions, ValidationMiddleware, ValidationObject, ValidationObjectWithHandler, ValidationObjectWithSource, ValidationProvider, ValidationResponse, ValidatorContext, ValidatorFunction, ValidatorRegistry, ViewController, ViewControllerOptions, ViewInstance, ViewPlugin, WarningValidationResponse, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, isObjectExpression, maybeConvertToNum, parse, parseExpression, removeBindingAndChildrenFromMap, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };