@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
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-use-before-define */
2
- import { Grammars } from 'ebnf';
2
+ import { Grammars } from "ebnf";
3
3
  import type {
4
4
  Parser,
5
5
  AnyNode,
@@ -8,14 +8,14 @@ import type {
8
8
  ConcatenatedNode,
9
9
  QueryNode,
10
10
  ExpressionNode,
11
- } from '../ast';
11
+ } from "../ast";
12
12
  import {
13
13
  toValue,
14
14
  toQuery,
15
15
  toPath,
16
16
  toConcatenatedNode,
17
17
  toExpression,
18
- } from '../ast';
18
+ } from "../ast";
19
19
  import type {
20
20
  ValueToken,
21
21
  ModelRefToken,
@@ -26,7 +26,7 @@ import type {
26
26
  QueryToken,
27
27
  QuotedValueToken,
28
28
  ExpressionToken,
29
- } from './types';
29
+ } from "./types";
30
30
 
31
31
  const parser = new Grammars.W3C.Parser(`
32
32
  value ::= segment_and_bracket (SEGMENT_SEPARATOR segment_and_bracket)*
@@ -66,20 +66,20 @@ function convertExpressionToken(token: ExpressionToken): ExpressionNode {
66
66
 
67
67
  /** map a concatenated token to a node */
68
68
  function convertConcatenatedToken(
69
- token: ConcatenatedToken
69
+ token: ConcatenatedToken,
70
70
  ): ConcatenatedNode | ValueNode | PathNode | ExpressionNode {
71
71
  return toConcatenatedNode(
72
72
  token.children.map((child) => {
73
- if (child.type === 'identifier') {
73
+ if (child.type === "identifier") {
74
74
  return convertIdentifierToken(child);
75
75
  }
76
76
 
77
- if (child.type === 'expression') {
77
+ if (child.type === "expression") {
78
78
  return convertExpressionToken(child);
79
79
  }
80
80
 
81
81
  return convertModelRefToken(child);
82
- })
82
+ }),
83
83
  );
84
84
  }
85
85
 
@@ -90,15 +90,15 @@ function convertQuotedValueToken(token: QuotedValueToken): ValueNode {
90
90
 
91
91
  /** map a quoted value token to a value node */
92
92
  function convertOptionallyQuotedToken(
93
- token: OptionallyQuotedSegment
93
+ token: OptionallyQuotedSegment,
94
94
  ): ValueNode | ConcatenatedNode | PathNode | ExpressionNode {
95
95
  const child = token.children[0];
96
- if (child.type === 'quoted_value') {
96
+ if (child.type === "quoted_value") {
97
97
  return convertQuotedValueToken(child);
98
98
  }
99
99
 
100
100
  const grandChild = child.children[0];
101
- if (grandChild.type === 'identifier') {
101
+ if (grandChild.type === "identifier") {
102
102
  return convertIdentifierToken(grandChild);
103
103
  }
104
104
 
@@ -109,7 +109,7 @@ function convertOptionallyQuotedToken(
109
109
  function convertQueryToken(token: QueryToken): QueryNode {
110
110
  return toQuery(
111
111
  convertOptionallyQuotedToken(token.children[0]),
112
- convertOptionallyQuotedToken(token.children[1])
112
+ convertOptionallyQuotedToken(token.children[1]),
113
113
  );
114
114
  }
115
115
 
@@ -120,22 +120,22 @@ function convertValueToken(binding: ValueToken): PathNode {
120
120
  /** Expand a token into it's path refs */
121
121
  function expandPath(token: Token) {
122
122
  switch (token.type) {
123
- case 'modelRef':
123
+ case "modelRef":
124
124
  path.push(convertModelRefToken(token));
125
125
  break;
126
- case 'identifier':
126
+ case "identifier":
127
127
  path.push(convertIdentifierToken(token));
128
128
  break;
129
- case 'quoted_value':
129
+ case "quoted_value":
130
130
  path.push(convertQuotedValueToken(token));
131
131
  break;
132
- case 'expression':
132
+ case "expression":
133
133
  path.push(convertExpressionToken(token));
134
134
  break;
135
- case 'query':
135
+ case "query":
136
136
  path.push(convertQueryToken(token));
137
137
  break;
138
- case 'concatenated':
138
+ case "concatenated":
139
139
  path.push(convertConcatenatedToken(token));
140
140
  break;
141
141
  default:
@@ -155,7 +155,7 @@ function convertModelRefToken(token: ModelRefToken): PathNode {
155
155
 
156
156
  /** Parse a binding using ebnf */
157
157
  export const parse: Parser = (path) => {
158
- if (path === '') {
158
+ if (path === "") {
159
159
  return {
160
160
  status: true,
161
161
  path: toPath([]),
@@ -167,12 +167,11 @@ export const parse: Parser = (path) => {
167
167
  if (!ast) {
168
168
  return {
169
169
  status: false,
170
- error: 'Unable to parse binding',
170
+ error: "Unable to parse binding",
171
171
  };
172
172
  }
173
173
 
174
174
  if (ast.errors.length > 0) {
175
- // console.log(ast.errors);
176
175
  return {
177
176
  status: false,
178
177
  error: ast.errors[0].message,
@@ -1,8 +1,8 @@
1
- import type { IToken } from 'ebnf';
1
+ import type { IToken } from "ebnf";
2
2
 
3
3
  export interface ValueToken extends IToken {
4
4
  /** A value type */
5
- type: 'value';
5
+ type: "value";
6
6
 
7
7
  /** Any children of the value */
8
8
  children: Array<SegmentAndBracketToken>;
@@ -10,7 +10,7 @@ export interface ValueToken extends IToken {
10
10
 
11
11
  export interface SegmentAndBracketToken extends IToken {
12
12
  /** A token for a segment + brackets */
13
- type: 'segment_and_bracket';
13
+ type: "segment_and_bracket";
14
14
 
15
15
  /** The segment + brackets */
16
16
  children: [SegmentToken, ...Array<BracketToken>];
@@ -18,7 +18,7 @@ export interface SegmentAndBracketToken extends IToken {
18
18
 
19
19
  export interface SegmentToken extends IToken {
20
20
  /** A segment token */
21
- type: 'segment';
21
+ type: "segment";
22
22
 
23
23
  /** Any children of the token */
24
24
  children: [ConcatenatedToken | IdentifierToken];
@@ -26,14 +26,14 @@ export interface SegmentToken extends IToken {
26
26
 
27
27
  export interface BracketToken extends IToken {
28
28
  /** A bracket token */
29
- type: 'bracket';
29
+ type: "bracket";
30
30
  /** Any children of the token */
31
31
  children: [OptionallyQuotedSegment | QueryToken];
32
32
  }
33
33
 
34
34
  export interface ExpressionValueToken extends IToken {
35
35
  /** Expression value token */
36
- type: 'expression_value';
36
+ type: "expression_value";
37
37
 
38
38
  /** No children here */
39
39
  children: [];
@@ -41,7 +41,7 @@ export interface ExpressionValueToken extends IToken {
41
41
 
42
42
  export interface ExpressionToken extends IToken {
43
43
  /** Expression token */
44
- type: 'expression';
44
+ type: "expression";
45
45
 
46
46
  /** Children is the expression value */
47
47
  children: [ExpressionValueToken];
@@ -49,42 +49,42 @@ export interface ExpressionToken extends IToken {
49
49
 
50
50
  export interface QuotedValueToken extends IToken {
51
51
  /** A quoted value */
52
- type: 'quoted_value';
52
+ type: "quoted_value";
53
53
  /** Any children of the token */
54
54
  children: [];
55
55
  }
56
56
 
57
57
  export interface IdentifierToken extends IToken {
58
58
  /** Any identifier */
59
- type: 'identifier';
59
+ type: "identifier";
60
60
  /** Any children of the token */
61
61
  children: [];
62
62
  }
63
63
 
64
64
  export interface ConcatenatedToken extends IToken {
65
65
  /** A node of more than 1 identifier */
66
- type: 'concatenated';
66
+ type: "concatenated";
67
67
  /** Any children of the token */
68
68
  children: Array<IdentifierToken | ModelRefToken | ExpressionToken>;
69
69
  }
70
70
 
71
71
  export interface ModelRefToken extends IToken {
72
72
  /** A nested model reference */
73
- type: 'modelRef';
73
+ type: "modelRef";
74
74
  /** Any children of the token */
75
75
  children: [ValueToken];
76
76
  }
77
77
 
78
78
  export interface OptionallyQuotedSegment extends IToken {
79
79
  /** Any optionally quoted segment */
80
- type: 'optionally_quoted_segment';
80
+ type: "optionally_quoted_segment";
81
81
  /** Any children of the token */
82
82
  children: [QuotedValueToken | SegmentToken];
83
83
  }
84
84
 
85
85
  export interface QueryToken extends IToken {
86
86
  /** A query */
87
- type: 'query';
87
+ type: "query";
88
88
  /** Any children of the token */
89
89
  children: [OptionallyQuotedSegment, OptionallyQuotedSegment];
90
90
  }
@@ -1,4 +1,4 @@
1
- export * from './ast';
2
- export { parse as parseParsimmon } from './parsimmon';
3
- export { parse as parseEBNF } from './ebnf';
4
- export { parse as parseCustom } from './custom';
1
+ export * from "./ast";
2
+ export { parse as parseParsimmon } from "./parsimmon";
3
+ export { parse as parseEBNF } from "./ebnf";
4
+ export { parse as parseCustom } from "./custom";
@@ -1,21 +1,21 @@
1
- import flatten from 'arr-flatten';
2
- import type { Parser } from 'parsimmon';
3
- import P from 'parsimmon';
4
- import type { Parser as BindingParser } from '../ast';
1
+ import flatten from "arr-flatten";
2
+ import type { Parser } from "parsimmon";
3
+ import P from "parsimmon";
4
+ import type { Parser as BindingParser } from "../ast";
5
5
  import {
6
6
  toValue,
7
7
  toConcatenatedNode,
8
8
  toQuery,
9
9
  toPath,
10
10
  toExpression,
11
- } from '../ast';
11
+ } from "../ast";
12
12
 
13
13
  const doubleQuote = P.string('"');
14
14
  const singleQuote = P.string("'");
15
- const backTick = P.string('`');
15
+ const backTick = P.string("`");
16
16
 
17
17
  const identifier = P.regex(/[\w\-@]+/)
18
- .desc('identifier')
18
+ .desc("identifier")
19
19
  .map(toValue);
20
20
 
21
21
  // eslint-disable-next-line prefer-const
@@ -24,7 +24,7 @@ let path: Parser<any>;
24
24
  const futurePath = P.lazy(() => path);
25
25
  const nestedPath = futurePath
26
26
  .trim(P.optWhitespace)
27
- .wrap(P.string('{{'), P.string('}}'))
27
+ .wrap(P.string("{{"), P.string("}}"))
28
28
  .map(toPath);
29
29
 
30
30
  const nestedExpression = P.regex(/[^`]*/)
@@ -39,23 +39,23 @@ const segment = P.alt(identifier, nestedPath, nestedExpression)
39
39
  const optionallyQuotedSegment = P.alt(
40
40
  P.regex(/[^"]*/).wrap(doubleQuote, doubleQuote).map(toValue),
41
41
  P.regex(/[^']*/).wrap(singleQuote, singleQuote).map(toValue),
42
- segment
42
+ segment,
43
43
  );
44
44
 
45
45
  const query = P.seq(
46
46
  optionallyQuotedSegment,
47
- P.string('=').times(1, 3).trim(P.optWhitespace),
48
- optionallyQuotedSegment
47
+ P.string("=").times(1, 3).trim(P.optWhitespace),
48
+ optionallyQuotedSegment,
49
49
  ).map(([key, , value]) => toQuery(key as any, value as any));
50
50
 
51
51
  const brackets = P.alt(query, optionallyQuotedSegment)
52
52
  .trim(P.optWhitespace)
53
- .wrap(P.string('['), P.string(']'))
53
+ .wrap(P.string("["), P.string("]"))
54
54
  .many();
55
55
 
56
56
  const segmentAndBrackets = P.seqMap(segment, brackets, (s, bs) => [s, ...bs]);
57
57
 
58
- path = P.sepBy(segmentAndBrackets, P.string('.')).map(flatten);
58
+ path = P.sepBy(segmentAndBrackets, P.string(".")).map(flatten);
59
59
 
60
60
  /** Parse a binding using parsimmon */
61
61
  export const parse: BindingParser = (binding) => {
@@ -65,7 +65,7 @@ export const parse: BindingParser = (binding) => {
65
65
  return {
66
66
  status: true,
67
67
  path: {
68
- name: 'PathNode',
68
+ name: "PathNode",
69
69
  path: result.value,
70
70
  },
71
71
  };
@@ -0,0 +1,106 @@
1
+ import { test, expect } from "vitest";
2
+ import { ConstantsController } from "..";
3
+
4
+ test("basic get/set functionality", () => {
5
+ const controller = new ConstantsController();
6
+
7
+ // Basic get/set tests
8
+ const data = {
9
+ firstname: "john",
10
+ lastname: "doe",
11
+ favorite: {
12
+ color: "red",
13
+ },
14
+ };
15
+ controller.addConstants(data, "constants");
16
+
17
+ const firstname = controller.getConstants("firstname", "constants");
18
+ const middleName = controller.getConstants("middlename", "constants");
19
+ const middleNameSafe = controller.getConstants(
20
+ "middlename",
21
+ "constants",
22
+ "A",
23
+ );
24
+ const favoriteColor = controller.getConstants("favorite.color", "constants");
25
+ const nonExistantNamespace = controller.getConstants("test", "foo");
26
+ const nonExistantNamespaceWithFallback = controller.getConstants(
27
+ "test",
28
+ "foo",
29
+ "bar",
30
+ );
31
+
32
+ expect(firstname).toStrictEqual(data.firstname);
33
+ expect(middleName).toBe(undefined);
34
+ expect(middleNameSafe).toStrictEqual("A");
35
+ expect(favoriteColor).toStrictEqual(data.favorite.color);
36
+ expect(favoriteColor).toStrictEqual(data.favorite.color);
37
+ expect(nonExistantNamespace).toBe(undefined);
38
+ expect(nonExistantNamespaceWithFallback).toBe("bar");
39
+
40
+ // Test and make sure keys override properly
41
+ const newData = {
42
+ favorite: {
43
+ color: "blue",
44
+ },
45
+ };
46
+
47
+ controller.addConstants(newData, "constants");
48
+ const newFavoriteColor = controller.getConstants(
49
+ "favorite.color",
50
+ "constants",
51
+ );
52
+ expect(newFavoriteColor).toStrictEqual(newData.favorite.color);
53
+ });
54
+
55
+ test("temp override functionality", () => {
56
+ const controller = new ConstantsController();
57
+
58
+ // Basic Temp tests
59
+ const data = {
60
+ firstname: "john",
61
+ lastname: "doe",
62
+ favorite: {
63
+ color: "red",
64
+ },
65
+ };
66
+
67
+ const temp = {
68
+ middlename: "A",
69
+ favorite: {
70
+ color: "green",
71
+ },
72
+ };
73
+ controller.addConstants(data, "constants");
74
+ controller.setTemporaryValues(temp, "constants");
75
+
76
+ const tempMiddleName = controller.getConstants("middlename", "constants");
77
+ const tempFavoriteColor = controller.getConstants(
78
+ "favorite.color",
79
+ "constants",
80
+ );
81
+
82
+ expect(tempMiddleName).toStrictEqual(temp.middlename);
83
+ expect(tempFavoriteColor).toStrictEqual(temp.favorite.color);
84
+
85
+ // Test overriding temp with new temp
86
+ const newTemp = {
87
+ favorite: {
88
+ color: "orange",
89
+ },
90
+ };
91
+ controller.setTemporaryValues(newTemp, "constants");
92
+ const newtempFavoriteColor = controller.getConstants(
93
+ "favorite.color",
94
+ "constants",
95
+ );
96
+ expect(newtempFavoriteColor).toStrictEqual(newTemp.favorite.color);
97
+
98
+ // Reset temp and values should be the same as the original data
99
+ controller.clearTemporaryValues();
100
+
101
+ const middleName = controller.getConstants("middlename", "constants");
102
+ const favoriteColor = controller.getConstants("favorite.color", "constants");
103
+
104
+ expect(middleName).toBe(undefined);
105
+ expect(favoriteColor).toStrictEqual(data.favorite.color);
106
+ });
@@ -1,6 +1,6 @@
1
- import { LocalModel } from '../../data';
2
- import { BindingInstance } from '../../binding';
3
- import { objectToBatchSet } from './utils';
1
+ import { LocalModel } from "../../data";
2
+ import { BindingInstance } from "../../binding";
3
+ import { objectToBatchSet } from "./utils";
4
4
 
5
5
  export interface ConstantsProvider {
6
6
  /**
@@ -1,7 +1,7 @@
1
- import { BindingInstance } from '../../binding';
1
+ import { BindingInstance } from "../../binding";
2
2
 
3
3
  /** Recursively flattens a nested object to be an object of depth 1 with keys being the full path in the orginal object */
4
- export function flatten(obj: any, roots: [string][] = [], sep = '.'): any {
4
+ export function flatten(obj: any, roots: [string][] = [], sep = "."): any {
5
5
  return (
6
6
  Object
7
7
  // find props of given object
@@ -13,13 +13,13 @@ export function flatten(obj: any, roots: [string][] = [], sep = '.'): any {
13
13
 
14
14
  // include previously returned object
15
15
  ...memo,
16
- ...(Object.prototype.toString.call(obj[prop]) === '[object Object]'
16
+ ...(Object.prototype.toString.call(obj[prop]) === "[object Object]"
17
17
  ? // keep working if value is an object
18
18
  flatten(obj[prop], roots.concat([prop]))
19
19
  : // include current prop and value and prefix prop with the roots
20
20
  { [roots.concat([prop]).join(sep)]: obj[prop] }),
21
21
  }),
22
- {}
22
+ {},
23
23
  )
24
24
  );
25
25
  }
@@ -1,8 +1,8 @@
1
- import { SyncHook, SyncWaterfallHook, SyncBailHook } from 'tapable-ts';
2
- import { dequal } from 'dequal';
3
- import type { Logger } from '../../logger';
4
- import type { BindingParser, BindingLike } from '../../binding';
5
- import { BindingInstance } from '../../binding';
1
+ import { SyncHook, SyncWaterfallHook, SyncBailHook } from "tapable-ts";
2
+ import { dequal } from "dequal";
3
+ import type { Logger } from "../../logger";
4
+ import type { BindingParser, BindingLike } from "../../binding";
5
+ import { BindingInstance } from "../../binding";
6
6
  import type {
7
7
  BatchSetTransaction,
8
8
  Updates,
@@ -10,10 +10,10 @@ import type {
10
10
  DataModelWithParser,
11
11
  DataPipeline,
12
12
  DataModelMiddleware,
13
- } from '../../data';
14
- import { PipelinedDataModel, LocalModel } from '../../data';
15
- import type { RawSetTransaction } from '../../types';
16
- import { ReadOnlyDataController } from './utils';
13
+ } from "../../data";
14
+ import { PipelinedDataModel, LocalModel } from "../../data";
15
+ import type { RawSetTransaction } from "../../types";
16
+ import { ReadOnlyDataController } from "./utils";
17
17
 
18
18
  /** The orchestrator for player data */
19
19
  export class DataController implements DataModelWithParser<DataModelOptions> {
@@ -56,7 +56,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
56
56
 
57
57
  /** A logger to use */
58
58
  logger?: Logger;
59
- }
59
+ },
60
60
  ) {
61
61
  this.logger = options.logger;
62
62
  const middleware = options.middleware || [];
@@ -80,7 +80,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
80
80
  private resolveDataValue(
81
81
  binding: BindingInstance,
82
82
  value: any,
83
- deformat: boolean
83
+ deformat: boolean,
84
84
  ) {
85
85
  if (deformat) {
86
86
  return this.hooks.deformat.call(value, binding);
@@ -91,7 +91,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
91
91
 
92
92
  public set(
93
93
  transaction: RawSetTransaction,
94
- options?: DataModelOptions
94
+ options?: DataModelOptions,
95
95
  ): Updates {
96
96
  let normalizedTransaction: BatchSetTransaction = [];
97
97
 
@@ -114,7 +114,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
114
114
  parsed,
115
115
  this.resolveDataValue(parsed, val, Boolean(options?.formatted)),
116
116
  ];
117
- }
117
+ },
118
118
  ) as BatchSetTransaction;
119
119
  }
120
120
 
@@ -131,19 +131,19 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
131
131
 
132
132
  if (dequal(oldVal, newVal)) {
133
133
  this.logger?.debug(
134
- `Skipping update for path: ${binding.asString()}. Value was unchanged: ${oldVal}`
134
+ `Skipping update for path: ${binding.asString()}. Value was unchanged: ${oldVal}`,
135
135
  );
136
136
  } else {
137
137
  updates.push(update);
138
138
 
139
139
  this.logger?.debug(
140
- `Setting path: ${binding.asString()} from: ${oldVal} to: ${newVal}`
140
+ `Setting path: ${binding.asString()} from: ${oldVal} to: ${newVal}`,
141
141
  );
142
142
  }
143
143
 
144
144
  return updates;
145
145
  },
146
- []
146
+ [],
147
147
  );
148
148
 
149
149
  // Get the applied update
@@ -159,7 +159,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
159
159
  this.logger?.debug(
160
160
  `Path: ${tr.binding.asString()} was changed from: ${
161
161
  tr.oldValue
162
- } to: ${tr.newValue}`
162
+ } to: ${tr.newValue}`,
163
163
  );
164
164
  setUpdates.push(tr);
165
165
  }
@@ -175,7 +175,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
175
175
  }
176
176
 
177
177
  private resolve(binding: BindingLike, readOnly: boolean): BindingInstance {
178
- return Array.isArray(binding) || typeof binding === 'string'
178
+ return Array.isArray(binding) || typeof binding === "string"
179
179
  ? this.pathResolver.parse(binding, { readOnly })
180
180
  : binding;
181
181
  }
@@ -208,11 +208,11 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
208
208
 
209
209
  public delete(binding: BindingLike, options?: DataModelOptions) {
210
210
  if (
211
- typeof binding !== 'string' &&
211
+ typeof binding !== "string" &&
212
212
  !Array.isArray(binding) &&
213
213
  !(binding instanceof BindingInstance)
214
214
  ) {
215
- throw new Error('Invalid arguments: delete expects a data path (string)');
215
+ throw new Error("Invalid arguments: delete expects a data path (string)");
216
216
  }
217
217
 
218
218
  const resolved =
@@ -225,7 +225,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
225
225
  const parentValue = this.get(parentBinding);
226
226
 
227
227
  const existedBeforeDelete =
228
- typeof parentValue === 'object' &&
228
+ typeof parentValue === "object" &&
229
229
  parentValue !== null &&
230
230
  Object.prototype.hasOwnProperty.call(parentValue, property);
231
231
 
@@ -239,7 +239,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
239
239
  }
240
240
 
241
241
  public serialize(): object {
242
- return this.hooks.serialize.call(this.get(''));
242
+ return this.hooks.serialize.call(this.get(""));
243
243
  }
244
244
 
245
245
  public makeReadOnly(): ReadOnlyDataController {
@@ -1 +1 @@
1
- export * from './controller';
1
+ export * from "./controller";
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import type { DataController } from '.';
3
- import type { Logger } from '../../logger';
4
- import type { BindingLike } from '../../binding';
2
+ import type { DataController } from ".";
3
+ import type { Logger } from "../../logger";
4
+ import type { BindingLike } from "../../binding";
5
5
  import type {
6
6
  DataModelWithParser,
7
7
  DataModelOptions,
8
8
  Updates,
9
- } from '../../data';
9
+ } from "../../data";
10
10
 
11
11
  /** Wrapper for the Data Controller Class that prevents writes */
12
12
  export class ReadOnlyDataController
@@ -26,17 +26,17 @@ export class ReadOnlyDataController
26
26
 
27
27
  set(
28
28
  transaction: [BindingLike, any][],
29
- options?: DataModelOptions | undefined
29
+ options?: DataModelOptions | undefined,
30
30
  ): Updates {
31
31
  this.logger?.error(
32
- 'Error: Tried to set in a read only instance of the DataController'
32
+ "Error: Tried to set in a read only instance of the DataController",
33
33
  );
34
34
  return [];
35
35
  }
36
36
 
37
37
  delete(binding: BindingLike, options?: DataModelOptions | undefined): void {
38
38
  this.logger?.error(
39
- 'Error: Tried to delete in a read only instance of the DataController'
39
+ "Error: Tried to delete in a read only instance of the DataController",
40
40
  );
41
41
  }
42
42
  }