@player-ui/player 0.8.0--canary.307.9621 → 0.8.0-next.0

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 (214) hide show
  1. package/dist/Player.native.js +11630 -0
  2. package/dist/Player.native.js.map +1 -0
  3. package/dist/cjs/index.cjs +5626 -0
  4. package/dist/cjs/index.cjs.map +1 -0
  5. package/dist/{index.esm.js → index.legacy-esm.js} +2044 -1667
  6. package/dist/{index.cjs.js → index.mjs} +2052 -1761
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +29 -63
  9. package/src/__tests__/data.test.ts +498 -0
  10. package/src/__tests__/flow.test.ts +312 -0
  11. package/src/__tests__/helpers/action-exp.plugin.ts +22 -0
  12. package/src/__tests__/helpers/actions.flow.ts +67 -0
  13. package/src/__tests__/helpers/binding.plugin.ts +125 -0
  14. package/src/__tests__/helpers/expression.plugin.ts +88 -0
  15. package/src/__tests__/helpers/transform-plugin.ts +19 -0
  16. package/src/__tests__/helpers/validation.flow.ts +56 -0
  17. package/src/__tests__/player.test.ts +597 -0
  18. package/src/__tests__/string-resolver.test.ts +186 -0
  19. package/src/__tests__/validation.test.ts +3555 -0
  20. package/src/__tests__/view.test.ts +715 -0
  21. package/src/binding/__tests__/binding.test.ts +113 -0
  22. package/src/binding/__tests__/index.test.ts +208 -0
  23. package/src/binding/__tests__/resolver.test.ts +83 -0
  24. package/src/binding/binding.ts +6 -6
  25. package/src/binding/index.ts +34 -34
  26. package/src/binding/resolver.ts +19 -19
  27. package/src/binding/utils.ts +7 -7
  28. package/src/binding-grammar/__tests__/parser.test.ts +64 -0
  29. package/src/binding-grammar/__tests__/test-utils/ast-cases.ts +198 -0
  30. package/src/binding-grammar/__tests__/test-utils/perf-test.ts +66 -0
  31. package/src/binding-grammar/ast.ts +11 -11
  32. package/src/binding-grammar/custom/index.ts +19 -22
  33. package/src/binding-grammar/ebnf/index.ts +20 -21
  34. package/src/binding-grammar/ebnf/types.ts +13 -13
  35. package/src/binding-grammar/index.ts +4 -4
  36. package/src/binding-grammar/parsimmon/index.ts +14 -14
  37. package/src/controllers/constants/__tests__/index.test.ts +106 -0
  38. package/src/controllers/constants/index.ts +3 -3
  39. package/src/controllers/constants/utils.ts +4 -4
  40. package/src/controllers/data/controller.ts +22 -22
  41. package/src/controllers/data/index.ts +1 -1
  42. package/src/controllers/data/utils.ts +7 -7
  43. package/src/controllers/flow/__tests__/controller.test.ts +195 -0
  44. package/src/controllers/flow/__tests__/flow.test.ts +381 -0
  45. package/src/controllers/flow/controller.ts +13 -13
  46. package/src/controllers/flow/flow.ts +23 -23
  47. package/src/controllers/flow/index.ts +2 -2
  48. package/src/controllers/index.ts +5 -5
  49. package/src/controllers/validation/binding-tracker.ts +71 -59
  50. package/src/controllers/validation/controller.ts +104 -104
  51. package/src/controllers/validation/index.ts +2 -2
  52. package/src/controllers/view/asset-transform.ts +20 -20
  53. package/src/controllers/view/controller.ts +27 -27
  54. package/src/controllers/view/index.ts +4 -4
  55. package/src/controllers/view/store.ts +3 -3
  56. package/src/controllers/view/types.ts +7 -7
  57. package/src/data/__tests__/__snapshots__/dependency-tracker.test.ts.snap +64 -0
  58. package/src/data/__tests__/dependency-tracker.test.ts +146 -0
  59. package/src/data/__tests__/local-model.test.ts +46 -0
  60. package/src/data/__tests__/model.test.ts +78 -0
  61. package/src/data/dependency-tracker.ts +16 -16
  62. package/src/data/index.ts +4 -4
  63. package/src/data/local-model.ts +6 -6
  64. package/src/data/model.ts +17 -17
  65. package/src/data/noop-model.ts +1 -1
  66. package/src/expressions/__tests__/__snapshots__/parser.test.ts.snap +854 -0
  67. package/src/expressions/__tests__/evaluator-functions.test.ts +47 -0
  68. package/src/expressions/__tests__/evaluator.test.ts +410 -0
  69. package/src/expressions/__tests__/parser.test.ts +115 -0
  70. package/src/expressions/__tests__/utils.test.ts +44 -0
  71. package/src/expressions/evaluator-functions.ts +6 -6
  72. package/src/expressions/evaluator.ts +71 -67
  73. package/src/expressions/index.ts +4 -4
  74. package/src/expressions/parser.ts +102 -105
  75. package/src/expressions/types.ts +29 -21
  76. package/src/expressions/utils.ts +32 -21
  77. package/src/index.ts +13 -13
  78. package/src/logger/__tests__/consoleLogger.test.ts +46 -0
  79. package/src/logger/__tests__/noopLogger.test.ts +13 -0
  80. package/src/logger/__tests__/proxyLogger.test.ts +31 -0
  81. package/src/logger/__tests__/tapableLogger.test.ts +41 -0
  82. package/src/logger/consoleLogger.ts +9 -9
  83. package/src/logger/index.ts +5 -5
  84. package/src/logger/noopLogger.ts +1 -1
  85. package/src/logger/proxyLogger.ts +6 -6
  86. package/src/logger/tapableLogger.ts +7 -7
  87. package/src/logger/types.ts +2 -2
  88. package/src/player.ts +60 -58
  89. package/src/plugins/default-exp-plugin.ts +10 -10
  90. package/src/plugins/default-view-plugin.ts +29 -0
  91. package/src/plugins/flow-exp-plugin.ts +6 -6
  92. package/src/schema/__tests__/schema.test.ts +243 -0
  93. package/src/schema/index.ts +2 -2
  94. package/src/schema/schema.ts +24 -24
  95. package/src/schema/types.ts +4 -4
  96. package/src/string-resolver/__tests__/index.test.ts +361 -0
  97. package/src/string-resolver/index.ts +17 -17
  98. package/src/types.ts +17 -17
  99. package/src/utils/__tests__/replaceParams.test.ts +33 -0
  100. package/src/utils/index.ts +1 -1
  101. package/src/utils/replaceParams.ts +1 -1
  102. package/src/validator/__tests__/binding-map-splice.test.ts +53 -0
  103. package/src/validator/__tests__/validation-middleware.test.ts +127 -0
  104. package/src/validator/binding-map-splice.ts +5 -5
  105. package/src/validator/index.ts +4 -4
  106. package/src/validator/registry.ts +1 -1
  107. package/src/validator/types.ts +13 -13
  108. package/src/validator/validation-middleware.ts +15 -15
  109. package/src/view/__tests__/view.immutable.test.ts +269 -0
  110. package/src/view/__tests__/view.test.ts +959 -0
  111. package/src/view/builder/index.test.ts +69 -0
  112. package/src/view/builder/index.ts +3 -3
  113. package/src/view/index.ts +5 -5
  114. package/src/view/parser/__tests__/__snapshots__/parser.test.ts.snap +394 -0
  115. package/src/view/parser/__tests__/parser.test.ts +264 -0
  116. package/src/view/parser/index.ts +43 -33
  117. package/src/view/parser/types.ts +11 -11
  118. package/src/view/parser/utils.ts +5 -5
  119. package/src/view/plugins/__tests__/__snapshots__/template.test.ts.snap +278 -0
  120. package/src/view/plugins/__tests__/applicability.test.ts +265 -0
  121. package/src/view/plugins/__tests__/string.test.ts +122 -0
  122. package/src/view/plugins/__tests__/template.test.ts +724 -0
  123. package/src/view/plugins/applicability.ts +19 -19
  124. package/src/view/plugins/index.ts +4 -5
  125. package/src/view/plugins/options.ts +1 -1
  126. package/src/view/plugins/string-resolver.ts +22 -22
  127. package/src/view/plugins/switch.ts +22 -23
  128. package/src/view/plugins/template-plugin.ts +26 -27
  129. package/src/view/resolver/__tests__/dependencies.test.ts +321 -0
  130. package/src/view/resolver/__tests__/edgecases.test.ts +626 -0
  131. package/src/view/resolver/index.ts +42 -42
  132. package/src/view/resolver/types.ts +21 -20
  133. package/src/view/resolver/utils.ts +9 -9
  134. package/src/view/view.ts +32 -22
  135. package/types/binding/binding.d.ts +50 -0
  136. package/types/binding/index.d.ts +29 -0
  137. package/types/binding/resolver.d.ts +26 -0
  138. package/types/binding/utils.d.ts +12 -0
  139. package/types/binding-grammar/ast.d.ts +67 -0
  140. package/types/binding-grammar/custom/index.d.ts +4 -0
  141. package/types/binding-grammar/ebnf/index.d.ts +4 -0
  142. package/types/binding-grammar/ebnf/types.d.ts +75 -0
  143. package/types/binding-grammar/index.d.ts +5 -0
  144. package/types/binding-grammar/parsimmon/index.d.ts +4 -0
  145. package/types/controllers/constants/index.d.ts +45 -0
  146. package/types/controllers/constants/utils.d.ts +6 -0
  147. package/types/controllers/data/controller.d.ts +45 -0
  148. package/types/controllers/data/index.d.ts +2 -0
  149. package/types/controllers/data/utils.d.ts +14 -0
  150. package/types/controllers/flow/controller.d.ts +25 -0
  151. package/types/controllers/flow/flow.d.ts +50 -0
  152. package/types/controllers/flow/index.d.ts +3 -0
  153. package/types/controllers/index.d.ts +6 -0
  154. package/types/controllers/validation/binding-tracker.d.ts +32 -0
  155. package/types/controllers/validation/controller.d.ts +151 -0
  156. package/types/controllers/validation/index.d.ts +3 -0
  157. package/types/controllers/view/asset-transform.d.ts +19 -0
  158. package/types/controllers/view/controller.d.ts +37 -0
  159. package/types/controllers/view/index.d.ts +5 -0
  160. package/types/controllers/view/store.d.ts +20 -0
  161. package/types/controllers/view/types.d.ts +16 -0
  162. package/types/data/dependency-tracker.d.ts +49 -0
  163. package/types/data/index.d.ts +5 -0
  164. package/types/data/local-model.d.ts +16 -0
  165. package/types/data/model.d.ts +86 -0
  166. package/types/data/noop-model.d.ts +13 -0
  167. package/types/expressions/evaluator-functions.d.ts +15 -0
  168. package/types/expressions/evaluator.d.ts +52 -0
  169. package/types/expressions/index.d.ts +5 -0
  170. package/types/expressions/parser.d.ts +10 -0
  171. package/types/expressions/types.d.ts +144 -0
  172. package/types/expressions/utils.d.ts +12 -0
  173. package/types/index.d.ts +14 -0
  174. package/types/logger/consoleLogger.d.ts +17 -0
  175. package/types/logger/index.d.ts +6 -0
  176. package/types/logger/noopLogger.d.ts +10 -0
  177. package/types/logger/proxyLogger.d.ts +15 -0
  178. package/types/logger/tapableLogger.d.ts +23 -0
  179. package/types/logger/types.d.ts +6 -0
  180. package/types/player.d.ts +101 -0
  181. package/types/plugins/default-exp-plugin.d.ts +9 -0
  182. package/types/plugins/default-view-plugin.d.ts +9 -0
  183. package/types/plugins/flow-exp-plugin.d.ts +11 -0
  184. package/types/schema/index.d.ts +3 -0
  185. package/types/schema/schema.d.ts +36 -0
  186. package/types/schema/types.d.ts +38 -0
  187. package/types/string-resolver/index.d.ts +30 -0
  188. package/types/types.d.ts +73 -0
  189. package/types/utils/index.d.ts +2 -0
  190. package/types/utils/replaceParams.d.ts +9 -0
  191. package/types/validator/binding-map-splice.d.ts +10 -0
  192. package/types/validator/index.d.ts +5 -0
  193. package/types/validator/registry.d.ts +11 -0
  194. package/types/validator/types.d.ts +53 -0
  195. package/types/validator/validation-middleware.d.ts +36 -0
  196. package/types/view/builder/index.d.ts +35 -0
  197. package/types/view/index.d.ts +6 -0
  198. package/types/view/parser/index.d.ts +52 -0
  199. package/types/view/parser/types.d.ts +109 -0
  200. package/types/view/parser/utils.d.ts +6 -0
  201. package/types/view/plugins/applicability.d.ts +10 -0
  202. package/types/view/plugins/index.d.ts +5 -0
  203. package/types/view/plugins/options.d.ts +4 -0
  204. package/types/view/plugins/string-resolver.d.ts +13 -0
  205. package/types/view/plugins/switch.d.ts +14 -0
  206. package/types/view/plugins/template-plugin.d.ts +33 -0
  207. package/types/view/resolver/index.d.ts +73 -0
  208. package/types/view/resolver/types.d.ts +129 -0
  209. package/types/view/resolver/utils.d.ts +11 -0
  210. package/types/view/view.d.ts +37 -0
  211. package/dist/index.d.ts +0 -1814
  212. package/dist/player.dev.js +0 -11472
  213. package/dist/player.prod.js +0 -2
  214. package/src/view/plugins/plugin.ts +0 -21
@@ -0,0 +1,9 @@
1
+ import type { Player, PlayerPlugin } from "../player";
2
+ /**
3
+ * A plugin that provides the out-of-the-box expressions for player
4
+ */
5
+ export declare class DefaultViewPlugin implements PlayerPlugin {
6
+ name: string;
7
+ apply(player: Player): void;
8
+ }
9
+ //# sourceMappingURL=default-view-plugin.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { Player, PlayerPlugin } from "../player";
2
+ /**
3
+ * A plugin that taps into the flow controller to evaluate available expressions
4
+ * Expressions can be exposed via lifecycle "hooks" in flow/state nodes
5
+ * e.g: onStart, onEnd
6
+ */
7
+ export declare class FlowExpPlugin implements PlayerPlugin {
8
+ name: string;
9
+ apply(player: Player): void;
10
+ }
11
+ //# sourceMappingURL=flow-exp-plugin.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./schema";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,36 @@
1
+ import { SyncWaterfallHook } from "tapable-ts";
2
+ import type { Schema as SchemaType, Formatting } from "@player-ui/types";
3
+ import type { BindingInstance } from "../binding";
4
+ import type { ValidationProvider, ValidationObject } from "../validator";
5
+ import type { FormatDefinition, FormatOptions, FormatType } from "./types";
6
+ /** Expand the authored schema into a set of paths -> DataTypes */
7
+ export declare function parse(schema: SchemaType.Schema): Map<string, SchemaType.DataTypes>;
8
+ /**
9
+ * The Schema is the central hub for all data invariants, and metaData associated with the data-model itself
10
+ * Outside of the types defined in the JSON payload, it doesn't manage or keep any state.
11
+ * It simply servers as an orchestrator for other modules to interface w/ the schema.
12
+ */
13
+ export declare class SchemaController implements ValidationProvider {
14
+ private formatters;
15
+ private types;
16
+ readonly schema: Map<string, SchemaType.DataTypes>;
17
+ private bindingSchemaNormalizedCache;
18
+ readonly hooks: {
19
+ resolveTypeForBinding: SyncWaterfallHook<[SchemaType.DataTypes | undefined, BindingInstance], Record<string, any>>;
20
+ };
21
+ constructor(schema?: SchemaType.Schema);
22
+ addFormatters(fns: Array<FormatType<any, any, FormatOptions>>): void;
23
+ addDataTypes(types: Array<SchemaType.DataType<any>>): void;
24
+ getValidationsForBinding(binding: BindingInstance): Array<ValidationObject> | undefined;
25
+ private normalizeBinding;
26
+ getType(binding: BindingInstance): SchemaType.DataTypes | undefined;
27
+ getApparentType(binding: BindingInstance): SchemaType.DataTypes | undefined;
28
+ getTypeDefinition(dataType: string): SchemaType.DataType<any> | undefined;
29
+ getFormatterForType(formatReference: Formatting.Reference): FormatDefinition<unknown, unknown> | undefined;
30
+ /**
31
+ * Given a binding, fetch a function that's responsible for formatting, and/or de-formatting the data
32
+ * If no formatter is registered, it will return undefined
33
+ */
34
+ getFormatter(binding: BindingInstance): FormatDefinition<unknown, unknown> | undefined;
35
+ }
36
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1,38 @@
1
+ import type { Formatting } from "@player-ui/types";
2
+ export type FormatOptions = Omit<Formatting.Reference, "type">;
3
+ /**
4
+ * The return types for the schema don't include options.
5
+ * These are already sent to the generic formatter function for that type
6
+ */
7
+ export type FormatFunction<From, To = From, Options = unknown> = (val: From, options?: Options) => To | undefined;
8
+ export type FormatHandler<From, To = From> = (val: From) => To;
9
+ export interface FormatDefinition<DataModelType, UserDisplayType> {
10
+ /**
11
+ * A function to format data (from the data-model to the user).
12
+ * Defaults to the identify function
13
+ */
14
+ format: FormatHandler<DataModelType, UserDisplayType>;
15
+ /**
16
+ * A function to invert the formatting (from the user to the data-model)
17
+ * Defaults to the identify function.
18
+ */
19
+ deformat: FormatHandler<UserDisplayType, DataModelType>;
20
+ }
21
+ export interface FormatType<DataModelType, UserDisplayType = DataModelType, Options = undefined> {
22
+ /**
23
+ * The name of the formatter.
24
+ * This corresponds to the 'type' format property when creating a DataType
25
+ */
26
+ name: string;
27
+ /**
28
+ * An optional function to format data for display to the user.
29
+ * This goes from dataModel -> UI display
30
+ */
31
+ format?: FormatFunction<DataModelType | UserDisplayType, UserDisplayType, Options>;
32
+ /**
33
+ * An optional function for undo the action of a format function for storage.
34
+ * This goes from UI -> dataModel
35
+ */
36
+ deformat?: FormatFunction<UserDisplayType | DataModelType, DataModelType, Options>;
37
+ }
38
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,30 @@
1
+ import type { Expression } from "@player-ui/types";
2
+ import type { DataModelWithParser } from "../data";
3
+ export interface Options {
4
+ /**
5
+ * The model to use when resolving refs
6
+ * Passing `false` will skip trying to resolve any direct model refs ({{foo}})
7
+ */
8
+ model: false | DataModelWithParser;
9
+ /**
10
+ * A function to evaluate an expression
11
+ * Passing `false` will skip trying to evaluate any expressions (@[ foo() ]@)
12
+ */
13
+ evaluate: false | ((exp: Expression) => any);
14
+ /**
15
+ * Optionaly resolve binding without formatting in case Type format applies
16
+ */
17
+ formatted?: boolean;
18
+ }
19
+ /** Search the given string for the coordinates of the next expression to resolve */
20
+ export declare function findNextExp(str: string): {
21
+ start: number;
22
+ end: number;
23
+ } | undefined;
24
+ /** Finds any subset of the string wrapped in @[]@ and evaluates it as an expression */
25
+ export declare function resolveExpressionsInString(val: string, { evaluate }: Options): string;
26
+ /** Return a string with all data model references resolved */
27
+ export declare function resolveDataRefsInString(val: string, options: Options): string;
28
+ /** Recursively resolve all model refs in whatever you pass in */
29
+ export declare function resolveDataRefs<T>(val: T, options: Options): T;
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,73 @@
1
+ import type { Flow, FlowResult } from "@player-ui/types";
2
+ import type { BindingParser, BindingLike } from "./binding";
3
+ import type { SchemaController } from "./schema";
4
+ import type { ExpressionEvaluator } from "./expressions";
5
+ import type { Logger } from "./logger";
6
+ import type { ViewController, DataController, ValidationController, FlowController } from "./controllers";
7
+ import type { ReadOnlyDataController } from "./controllers/data/utils";
8
+ /** The status for a flow's execution state */
9
+ export type PlayerFlowStatus = "not-started" | "in-progress" | "completed" | "error";
10
+ /** Common interface for the state of Player's flow execution */
11
+ export interface BaseFlowState<T extends PlayerFlowStatus> {
12
+ /** A unique reference for the life-cycle of a flow */
13
+ ref: symbol;
14
+ /** The status of the given flow */
15
+ status: T;
16
+ }
17
+ /** The beginning state of Player, before it's seen a flow */
18
+ export type NotStartedState = BaseFlowState<"not-started">;
19
+ export declare const NOT_STARTED_STATE: NotStartedState;
20
+ /** Shared properties for a flow in any state of execution (in-progress, completed successfully, or errored out) */
21
+ export interface PlayerFlowExecutionData {
22
+ /** The currently executing flow */
23
+ flow: Flow;
24
+ }
25
+ export interface ControllerState {
26
+ /** The manager for data for a flow */
27
+ data: DataController;
28
+ /** The view manager for a flow */
29
+ view: ViewController;
30
+ /** The schema manager for a flow */
31
+ schema: SchemaController;
32
+ /** The validation manager for a flow */
33
+ validation: ValidationController;
34
+ /** The expression evaluator for a flow */
35
+ expression: ExpressionEvaluator;
36
+ /** The manager for parsing and resolving bindings */
37
+ binding: BindingParser;
38
+ /** the manager for the flow state machine */
39
+ flow: FlowController;
40
+ }
41
+ /** A flow is currently executing */
42
+ export type InProgressState = BaseFlowState<"in-progress"> & PlayerFlowExecutionData & {
43
+ /** A promise that resolves when the flow is completed */
44
+ flowResult: Promise<FlowResult>;
45
+ /** The underlying state controllers for the current flow */
46
+ controllers: ControllerState;
47
+ /** Allow other platforms to abort the current flow with an error */
48
+ fail: (error: Error) => void;
49
+ /**
50
+ * The Logger for the current player instance
51
+ */
52
+ logger: Logger;
53
+ };
54
+ /** The flow completed properly */
55
+ export type CompletedState = BaseFlowState<"completed"> & PlayerFlowExecutionData & FlowResult & {
56
+ /** Readonly Player controllers to provide Player functionality after the flow has ended */
57
+ controllers: {
58
+ /** A read only instance of the Data Controller */
59
+ data: ReadOnlyDataController;
60
+ };
61
+ };
62
+ /** The flow finished but not successfully */
63
+ export type ErrorState = BaseFlowState<"error"> & {
64
+ /** The currently executing flow */
65
+ flow: Flow;
66
+ /** The error associated with the failed flow */
67
+ error: Error;
68
+ };
69
+ /** Any Player state */
70
+ export type PlayerFlowState = NotStartedState | InProgressState | CompletedState | ErrorState;
71
+ export type RawSetType = [BindingLike, any];
72
+ export type RawSetTransaction = Record<string, any> | RawSetType[];
73
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "./replaceParams";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Replaces %num in message with the provided parameters in order.
3
+ *
4
+ * @param message - Parameterized string like "This is a %1"
5
+ * @param params - Parameters to replace in message E.g. ['tax2021.amount']
6
+ * @returns A message with the parameters replaced.
7
+ */
8
+ export declare function replaceParams(message: string, params: Record<string, any>): string;
9
+ //# sourceMappingURL=replaceParams.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { BindingInstance } from "../binding";
2
+ /**
3
+ * Remove a binding, and any children from from the map
4
+ * If the binding is an array-item, then it will be spliced from the array and the others will be shifted down
5
+ *
6
+ * @param sourceMap - A map of bindings to values
7
+ * @param binding - The binding to remove from the map
8
+ */
9
+ export declare function removeBindingAndChildrenFromMap<T>(sourceMap: Map<BindingInstance, T>, binding: BindingInstance): Map<BindingInstance, T>;
10
+ //# sourceMappingURL=binding-map-splice.d.ts.map
@@ -0,0 +1,5 @@
1
+ export * from "./validation-middleware";
2
+ export * from "./types";
3
+ export * from "./registry";
4
+ export * from "./binding-map-splice";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { ValidatorFunction } from "./types";
2
+ /** A registry that tracks validators */
3
+ export declare class ValidatorRegistry {
4
+ private registry;
5
+ constructor();
6
+ /** Use the given validator name to fetch the handler */
7
+ get(name: string): ValidatorFunction | undefined;
8
+ /** Register a new validator */
9
+ register<T>(name: string, handler: ValidatorFunction<T>): void;
10
+ }
11
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1,53 @@
1
+ import type { Schema, Validation } from "@player-ui/types";
2
+ import type { BindingInstance, BindingFactory } from "../binding";
3
+ import type { DataModelWithParser } from "../data";
4
+ import type { ExpressionEvaluatorFunction } from "../expressions";
5
+ import type { Logger } from "../logger";
6
+ import type { ConstantsProvider } from "../controllers";
7
+ interface BaseValidationResponse<T = Validation.Severity> {
8
+ /** The validation message to show to the user */
9
+ message: string;
10
+ /** List of parameters associated with a validation. These can be replaced into a templatized message string. */
11
+ parameters?: Record<string, any>;
12
+ /** How serious is this violation */
13
+ severity: T;
14
+ /** Where this validation should be displayed */
15
+ displayTarget?: Validation.DisplayTarget;
16
+ /** The blocking state of this validation */
17
+ blocking?: boolean | "once";
18
+ }
19
+ export interface WarningValidationResponse extends BaseValidationResponse<"warning"> {
20
+ /** Warning validations can be dismissed without correcting the error */
21
+ dismiss?: () => void;
22
+ }
23
+ export type ErrorValidationResponse = BaseValidationResponse<"error">;
24
+ export type ValidationResponse = ErrorValidationResponse | WarningValidationResponse;
25
+ type RequiredValidationKeys = "severity" | "trigger";
26
+ export type ValidationObject = Validation.Reference & Required<Pick<Validation.Reference, RequiredValidationKeys>>;
27
+ export type ValidationObjectWithHandler = ValidationObject & {
28
+ /** A predefined handler for this validation object */
29
+ handler?: ValidatorFunction;
30
+ };
31
+ export interface ValidationProvider {
32
+ getValidationsForBinding?(binding: BindingInstance): Array<ValidationObjectWithHandler> | undefined;
33
+ getValidationsForView?(): Array<ValidationObjectWithHandler> | undefined;
34
+ }
35
+ export interface ValidatorContext {
36
+ /** The data to set or get data from */
37
+ model: DataModelWithParser;
38
+ /** A means of parsing a binding */
39
+ parseBinding: BindingFactory;
40
+ /** Execute the expression and return it's result */
41
+ evaluate: ExpressionEvaluatorFunction;
42
+ /** Logger instance to use */
43
+ logger: Logger;
44
+ /** The validation object that triggered this function */
45
+ validation: ValidationObject;
46
+ /** The constants for messages */
47
+ constants: ConstantsProvider;
48
+ /** The type in the schema that triggered the validation if there is one */
49
+ schemaType: Schema.DataType | undefined;
50
+ }
51
+ export type ValidatorFunction<Options = unknown> = (context: ValidatorContext, value: any, options?: Options) => Omit<BaseValidationResponse, "severity"> | undefined;
52
+ export {};
53
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,36 @@
1
+ import type { BindingInstance } from "../binding";
2
+ import type { BatchSetTransaction, DataModelImpl, DataModelOptions, DataModelMiddleware, Updates } from "../data";
3
+ import type { Logger } from "../logger";
4
+ import type { ValidationResponse } from "./types";
5
+ /**
6
+ * A BindingInstance with an indicator of whether or not it's a strong binding
7
+ */
8
+ export type StrongOrWeakBinding = {
9
+ /** BindingInstance in question */
10
+ binding: BindingInstance;
11
+ /** Boolean indicating whether the relevant BindingInstance is a strong binding */
12
+ isStrong: boolean;
13
+ };
14
+ /**
15
+ * Returns a validation object if the data is invalid or an set of BindingsInstances if the binding itself is a weak ref of another invalid validation
16
+ */
17
+ export type MiddlewareChecker = (binding: BindingInstance, model: DataModelImpl) => ValidationResponse | Set<StrongOrWeakBinding> | undefined;
18
+ /**
19
+ * Middleware for the data-model that caches the results of invalid data
20
+ */
21
+ export declare class ValidationMiddleware implements DataModelMiddleware {
22
+ validator: MiddlewareChecker;
23
+ shadowModelPaths: Map<BindingInstance, any>;
24
+ private logger?;
25
+ private shouldIncludeInvalid?;
26
+ constructor(validator: MiddlewareChecker, options?: {
27
+ /** A logger instance */
28
+ logger?: Logger;
29
+ /** Optional function to include data staged in shadowModel */
30
+ shouldIncludeInvalid?: (options?: DataModelOptions) => boolean;
31
+ });
32
+ set(transaction: BatchSetTransaction, options?: DataModelOptions, next?: DataModelImpl): Updates;
33
+ get(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): any;
34
+ delete(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): void | undefined;
35
+ }
36
+ //# sourceMappingURL=validation-middleware.d.ts.map
@@ -0,0 +1,35 @@
1
+ import type { Node, AnyAssetType } from "../parser";
2
+ import { NodeType } from "../parser";
3
+ /**
4
+ * Functions for building AST nodes (relatively) easily
5
+ */
6
+ export declare class Builder {
7
+ /**
8
+ * Creates an asset node
9
+ *
10
+ * @param value - the value to put in the asset node
11
+ */
12
+ static asset<T extends AnyAssetType>(value: T): Node.Asset<T>;
13
+ /**
14
+ * Creates a value node
15
+ *
16
+ * @param v - The object to put in the value node
17
+ */
18
+ static value(v?: object): Node.Value;
19
+ /**
20
+ * Creates a multiNode and associates the multiNode as the parent
21
+ * of all the value nodes
22
+ *
23
+ * @param values - the value or applicability nodes to put in the multinode
24
+ */
25
+ static multiNode(...values: (Node.Value | Node.Applicability)[]): Node.MultiNode;
26
+ /**
27
+ * Adds a child node to a node
28
+ *
29
+ * @param node - The node to add a child to
30
+ * @param path - The path at which to add the child
31
+ * @param child - The child node
32
+ */
33
+ static addChild<N extends Node.BaseWithChildren<NT>, NT extends NodeType>(node: N, path: Node.PathSegment | Node.PathSegment[], child: Node.Node): N;
34
+ }
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,6 @@
1
+ export * from "./view";
2
+ export * from "./resolver";
3
+ export * from "./parser";
4
+ export * from "./builder";
5
+ export * from "./plugins";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { SyncBailHook, SyncWaterfallHook } from "tapable-ts";
2
+ import type { AnyAssetType, Node } from "./types";
3
+ import { NodeType } from "./types";
4
+ export * from "./types";
5
+ export * from "./utils";
6
+ export declare const EMPTY_NODE: Node.Empty;
7
+ export interface ParseObjectOptions {
8
+ /** how nested the templated is */
9
+ templateDepth?: number;
10
+ }
11
+ /**
12
+ * The Parser is the way to take an incoming view from the user and parse it into an AST.
13
+ * It provides a few ways to interact with the parsing, including mutating an object before and after creation of an AST node
14
+ */
15
+ export declare class Parser {
16
+ readonly hooks: {
17
+ /**
18
+ * A hook to interact with an object _before_ parsing it into an AST
19
+ *
20
+ * @param value - The object we're are about to parse
21
+ * @returns - A new value to parse.
22
+ * If undefined, the original value is used.
23
+ * If null, we stop parsing this node.
24
+ */
25
+ onParseObject: SyncWaterfallHook<[object, NodeType], Record<string, any>>;
26
+ /**
27
+ * A callback to interact with an AST _after_ we parse it into the AST
28
+ *
29
+ * @param value - The object we parsed
30
+ * @param node - The AST node we generated
31
+ * @returns - A new AST node to use
32
+ * If undefined, the original value is used.
33
+ * If null, we ignore this node all together
34
+ */
35
+ onCreateASTNode: SyncWaterfallHook<[Node.Node | null | undefined, object], Record<string, any>>;
36
+ determineNodeType: SyncBailHook<[string | object], NodeType, Record<string, any>>;
37
+ parseNode: SyncBailHook<[obj: object, nodeType: Node.ChildrenTypes, parseOptions: ParseObjectOptions, determinedNodeType: NodeType | null], Node.Node, Record<string, any>>;
38
+ };
39
+ parseView(value: AnyAssetType): Node.View;
40
+ private parseAsync;
41
+ createASTNode(node: Node.Node | null, value: any): Node.Node | null;
42
+ /**
43
+ * Checks if there are templated values in the object
44
+ *
45
+ * @param obj - The Parsed Object to check to see if we have a template array type for
46
+ * @param localKey - The key being checked
47
+ */
48
+ private hasTemplateValues;
49
+ private hasSwitchKey;
50
+ parseObject(obj: object, type?: Node.ChildrenTypes, options?: ParseObjectOptions): Node.Node | null;
51
+ }
52
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,109 @@
1
+ import type { Asset as AssetType, Expression, Binding } from "@player-ui/types";
2
+ export type AnyAssetType = AssetType<string>;
3
+ export declare enum NodeType {
4
+ Asset = "asset",
5
+ View = "view",
6
+ Applicability = "applicability",
7
+ Template = "template",
8
+ Value = "value",
9
+ MultiNode = "multi-node",
10
+ Switch = "switch",
11
+ Async = "async",
12
+ Unknown = "unknown",
13
+ Empty = "empty"
14
+ }
15
+ export declare namespace Node {
16
+ type ChildrenTypes = NodeType.Asset | NodeType.Value | NodeType.View;
17
+ interface Base<T extends NodeType> {
18
+ /** Every node contains a type to distinguish it from other nodes */
19
+ type: T;
20
+ /** Every node (outside of the root) contains a reference to it's parent */
21
+ parent?: Node;
22
+ }
23
+ type PathSegment = string | number;
24
+ interface Child {
25
+ /** The path of the child relative to the parent */
26
+ path: PathSegment[];
27
+ /** If true, the path points to an array, and the value will be appended to it result */
28
+ array?: boolean;
29
+ /** The child node */
30
+ value: Node;
31
+ }
32
+ interface BaseWithChildren<T extends NodeType> extends Base<T> {
33
+ /** Any node that contains a list of children underneath it */
34
+ children?: Child[];
35
+ }
36
+ interface Asset<T extends AnyAssetType = AnyAssetType> extends BaseWithChildren<NodeType.Asset>, PluginOptions {
37
+ /** Any asset nested within a view */
38
+ value: T;
39
+ }
40
+ interface View<T extends AnyAssetType = AnyAssetType> extends BaseWithChildren<NodeType.View>, PluginOptions {
41
+ /** The root of the parsed view */
42
+ value: T;
43
+ }
44
+ interface Applicability extends Base<NodeType.Applicability> {
45
+ /** The expression to execute that determines applicability of the target node */
46
+ expression: Expression;
47
+ /** The node to use if the expression is truthy */
48
+ value: Node;
49
+ }
50
+ interface Template extends Base<NodeType.Template> {
51
+ /** The location of an array in the model */
52
+ data: Binding;
53
+ /** The template to use when mapping over the data */
54
+ template: unknown;
55
+ /** The number of nested templates so far */
56
+ depth: number;
57
+ /** should the template recomputed when data changes */
58
+ dynamic?: boolean;
59
+ }
60
+ interface Value extends BaseWithChildren<NodeType.Value>, PluginOptions {
61
+ /** A simple node representing a value */
62
+ value: any;
63
+ }
64
+ interface MultiNode extends Base<NodeType.MultiNode> {
65
+ /**
66
+ * Should this list override the target node if they overlap?
67
+ * If not amend the existing list
68
+ */
69
+ override?: boolean;
70
+ /** A list of values that comprise this node */
71
+ values: Array<Node>;
72
+ }
73
+ interface Switch extends Base<NodeType.Switch> {
74
+ /** Should this list be re-computed when data changes */
75
+ dynamic?: boolean;
76
+ /** A list of cases to evaluate in order */
77
+ cases: SwitchCase[];
78
+ }
79
+ interface SwitchCase {
80
+ /** The expression to evaluate for a single case statement */
81
+ case: Expression | true;
82
+ /** The value to use if this case is true */
83
+ value: Value;
84
+ }
85
+ interface Async extends Base<NodeType.Async> {
86
+ /** The unique id of the node */
87
+ id: string;
88
+ /** The value representing the node */
89
+ value: Node;
90
+ }
91
+ interface PluginOptions {
92
+ /** A list of plugins */
93
+ plugins?: {
94
+ /** StringResolverPlugin options */
95
+ stringResolver?: {
96
+ /**
97
+ * An optional array of node properties to skip during string resolution
98
+ * Specified in the AssetTransformPlugin
99
+ */
100
+ propertiesToSkip?: string[];
101
+ };
102
+ };
103
+ }
104
+ type Unknown = Base<NodeType.Unknown>;
105
+ type Empty = Base<NodeType.Empty>;
106
+ type ViewOrAsset = View | Asset;
107
+ type Node = Asset | Applicability | Template | Value | View | MultiNode | Switch | Async | Unknown | Empty;
108
+ }
109
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,6 @@
1
+ import type { Node } from "./types";
2
+ /** Check to see if the object contains async */
3
+ export declare function hasAsync(obj: object): boolean;
4
+ /** Get the ID of the Node if there is one */
5
+ export declare function getNodeID(node?: Node.Node | null): string | undefined;
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { Resolver } from "../resolver";
2
+ import type { Parser } from "../parser";
3
+ import { ViewInstance, ViewPlugin } from "../view";
4
+ /** A view plugin to remove inapplicable assets from the tree */
5
+ export default class ApplicabilityPlugin implements ViewPlugin {
6
+ applyResolver(resolver: Resolver): void;
7
+ applyParser(parser: Parser): void;
8
+ apply(view: ViewInstance): void;
9
+ }
10
+ //# sourceMappingURL=applicability.d.ts.map
@@ -0,0 +1,5 @@
1
+ export { default as TemplatePlugin } from "./template-plugin";
2
+ export { default as StringResolverPlugin } from "./string-resolver";
3
+ export { default as ApplicabilityPlugin } from "./applicability";
4
+ export { default as SwitchPlugin } from "./switch";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ import type { Resolve } from "../resolver";
2
+ /** Config options that are required to resolve/update a view */
3
+ export type Options = Resolve.NodeResolveOptions;
4
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { Options } from "./options";
2
+ import type { Resolver } from "../resolver";
3
+ import { ViewInstance, ViewPlugin } from "../view";
4
+ /** Recursively resolve all string references in an object or array */
5
+ export declare function resolveAllRefs(node: any, resolveOptions: Options, propertiesToSkip: Set<string | number>): any;
6
+ /** A plugin that resolves all string references for each node */
7
+ export default class StringResolverPlugin implements ViewPlugin {
8
+ private propertiesToSkipCache;
9
+ constructor();
10
+ applyResolver(resolver: Resolver): void;
11
+ apply(view: ViewInstance): void;
12
+ }
13
+ //# sourceMappingURL=string-resolver.d.ts.map
@@ -0,0 +1,14 @@
1
+ import type { Options } from "./options";
2
+ import type { Parser } from "../parser";
3
+ import type { Resolver } from "../resolver";
4
+ import { ViewInstance, ViewPlugin } from "../view";
5
+ /** A view plugin to resolve switches */
6
+ export default class SwitchPlugin implements ViewPlugin {
7
+ private readonly options;
8
+ constructor(options: Options);
9
+ private resolveSwitch;
10
+ applyParser(parser: Parser): void;
11
+ applyResolver(resolver: Resolver): void;
12
+ apply(view: ViewInstance): void;
13
+ }
14
+ //# sourceMappingURL=switch.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { SyncWaterfallHook } from "tapable-ts";
2
+ import type { Parser } from "../parser";
3
+ import type { Options } from "./options";
4
+ import type { Resolver } from "../resolver";
5
+ import { ViewInstance, ViewPlugin } from "../view";
6
+ export interface TemplateItemInfo {
7
+ /** The index of the data for the current iteration of the template */
8
+ index: number;
9
+ /** The data for the current iteration of the template */
10
+ data: any;
11
+ /** The depth of the template node */
12
+ depth: number;
13
+ }
14
+ export interface TemplateSubstitution {
15
+ /** Regular expression to find and replace. The global flag will be always be added to this expression. */
16
+ expression: string | RegExp;
17
+ /** The value to replace matches with. */
18
+ value: string;
19
+ }
20
+ export type TemplateSubstitutionsFunc = (baseSubstitutions: TemplateSubstitution[], templateItemInfo: TemplateItemInfo) => TemplateSubstitution[];
21
+ /** A view plugin to resolve/manage templates */
22
+ export default class TemplatePlugin implements ViewPlugin {
23
+ private readonly options;
24
+ hooks: {
25
+ resolveTemplateSubstitutions: SyncWaterfallHook<[TemplateSubstitution[], TemplateItemInfo], Record<string, any>>;
26
+ };
27
+ constructor(options: Options);
28
+ private parseTemplate;
29
+ applyParser(parser: Parser): void;
30
+ applyResolverHooks(resolver: Resolver): void;
31
+ apply(view: ViewInstance): void;
32
+ }
33
+ //# sourceMappingURL=template-plugin.d.ts.map