@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.
- package/dist/Player.native.js +11630 -0
- package/dist/Player.native.js.map +1 -0
- package/dist/cjs/index.cjs +5626 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{index.esm.js → index.legacy-esm.js} +2044 -1667
- package/dist/{index.cjs.js → index.mjs} +2052 -1761
- package/dist/index.mjs.map +1 -0
- package/package.json +29 -63
- package/src/__tests__/data.test.ts +498 -0
- package/src/__tests__/flow.test.ts +312 -0
- package/src/__tests__/helpers/action-exp.plugin.ts +22 -0
- package/src/__tests__/helpers/actions.flow.ts +67 -0
- package/src/__tests__/helpers/binding.plugin.ts +125 -0
- package/src/__tests__/helpers/expression.plugin.ts +88 -0
- package/src/__tests__/helpers/transform-plugin.ts +19 -0
- package/src/__tests__/helpers/validation.flow.ts +56 -0
- package/src/__tests__/player.test.ts +597 -0
- package/src/__tests__/string-resolver.test.ts +186 -0
- package/src/__tests__/validation.test.ts +3555 -0
- package/src/__tests__/view.test.ts +715 -0
- package/src/binding/__tests__/binding.test.ts +113 -0
- package/src/binding/__tests__/index.test.ts +208 -0
- package/src/binding/__tests__/resolver.test.ts +83 -0
- package/src/binding/binding.ts +6 -6
- package/src/binding/index.ts +34 -34
- package/src/binding/resolver.ts +19 -19
- package/src/binding/utils.ts +7 -7
- package/src/binding-grammar/__tests__/parser.test.ts +64 -0
- package/src/binding-grammar/__tests__/test-utils/ast-cases.ts +198 -0
- package/src/binding-grammar/__tests__/test-utils/perf-test.ts +66 -0
- package/src/binding-grammar/ast.ts +11 -11
- package/src/binding-grammar/custom/index.ts +19 -22
- package/src/binding-grammar/ebnf/index.ts +20 -21
- package/src/binding-grammar/ebnf/types.ts +13 -13
- package/src/binding-grammar/index.ts +4 -4
- package/src/binding-grammar/parsimmon/index.ts +14 -14
- package/src/controllers/constants/__tests__/index.test.ts +106 -0
- package/src/controllers/constants/index.ts +3 -3
- package/src/controllers/constants/utils.ts +4 -4
- package/src/controllers/data/controller.ts +22 -22
- package/src/controllers/data/index.ts +1 -1
- package/src/controllers/data/utils.ts +7 -7
- package/src/controllers/flow/__tests__/controller.test.ts +195 -0
- package/src/controllers/flow/__tests__/flow.test.ts +381 -0
- package/src/controllers/flow/controller.ts +13 -13
- package/src/controllers/flow/flow.ts +23 -23
- package/src/controllers/flow/index.ts +2 -2
- package/src/controllers/index.ts +5 -5
- package/src/controllers/validation/binding-tracker.ts +71 -59
- package/src/controllers/validation/controller.ts +104 -104
- package/src/controllers/validation/index.ts +2 -2
- package/src/controllers/view/asset-transform.ts +20 -20
- package/src/controllers/view/controller.ts +27 -27
- package/src/controllers/view/index.ts +4 -4
- package/src/controllers/view/store.ts +3 -3
- package/src/controllers/view/types.ts +7 -7
- package/src/data/__tests__/__snapshots__/dependency-tracker.test.ts.snap +64 -0
- package/src/data/__tests__/dependency-tracker.test.ts +146 -0
- package/src/data/__tests__/local-model.test.ts +46 -0
- package/src/data/__tests__/model.test.ts +78 -0
- package/src/data/dependency-tracker.ts +16 -16
- package/src/data/index.ts +4 -4
- package/src/data/local-model.ts +6 -6
- package/src/data/model.ts +17 -17
- package/src/data/noop-model.ts +1 -1
- package/src/expressions/__tests__/__snapshots__/parser.test.ts.snap +854 -0
- package/src/expressions/__tests__/evaluator-functions.test.ts +47 -0
- package/src/expressions/__tests__/evaluator.test.ts +410 -0
- package/src/expressions/__tests__/parser.test.ts +115 -0
- package/src/expressions/__tests__/utils.test.ts +44 -0
- package/src/expressions/evaluator-functions.ts +6 -6
- package/src/expressions/evaluator.ts +71 -67
- package/src/expressions/index.ts +4 -4
- package/src/expressions/parser.ts +102 -105
- package/src/expressions/types.ts +29 -21
- package/src/expressions/utils.ts +32 -21
- package/src/index.ts +13 -13
- package/src/logger/__tests__/consoleLogger.test.ts +46 -0
- package/src/logger/__tests__/noopLogger.test.ts +13 -0
- package/src/logger/__tests__/proxyLogger.test.ts +31 -0
- package/src/logger/__tests__/tapableLogger.test.ts +41 -0
- package/src/logger/consoleLogger.ts +9 -9
- package/src/logger/index.ts +5 -5
- package/src/logger/noopLogger.ts +1 -1
- package/src/logger/proxyLogger.ts +6 -6
- package/src/logger/tapableLogger.ts +7 -7
- package/src/logger/types.ts +2 -2
- package/src/player.ts +60 -58
- package/src/plugins/default-exp-plugin.ts +10 -10
- package/src/plugins/default-view-plugin.ts +29 -0
- package/src/plugins/flow-exp-plugin.ts +6 -6
- package/src/schema/__tests__/schema.test.ts +243 -0
- package/src/schema/index.ts +2 -2
- package/src/schema/schema.ts +24 -24
- package/src/schema/types.ts +4 -4
- package/src/string-resolver/__tests__/index.test.ts +361 -0
- package/src/string-resolver/index.ts +17 -17
- package/src/types.ts +17 -17
- package/src/utils/__tests__/replaceParams.test.ts +33 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/replaceParams.ts +1 -1
- package/src/validator/__tests__/binding-map-splice.test.ts +53 -0
- package/src/validator/__tests__/validation-middleware.test.ts +127 -0
- package/src/validator/binding-map-splice.ts +5 -5
- package/src/validator/index.ts +4 -4
- package/src/validator/registry.ts +1 -1
- package/src/validator/types.ts +13 -13
- package/src/validator/validation-middleware.ts +15 -15
- package/src/view/__tests__/view.immutable.test.ts +269 -0
- package/src/view/__tests__/view.test.ts +959 -0
- package/src/view/builder/index.test.ts +69 -0
- package/src/view/builder/index.ts +3 -3
- package/src/view/index.ts +5 -5
- package/src/view/parser/__tests__/__snapshots__/parser.test.ts.snap +394 -0
- package/src/view/parser/__tests__/parser.test.ts +264 -0
- package/src/view/parser/index.ts +43 -33
- package/src/view/parser/types.ts +11 -11
- package/src/view/parser/utils.ts +5 -5
- package/src/view/plugins/__tests__/__snapshots__/template.test.ts.snap +278 -0
- package/src/view/plugins/__tests__/applicability.test.ts +265 -0
- package/src/view/plugins/__tests__/string.test.ts +122 -0
- package/src/view/plugins/__tests__/template.test.ts +724 -0
- package/src/view/plugins/applicability.ts +19 -19
- package/src/view/plugins/index.ts +4 -5
- package/src/view/plugins/options.ts +1 -1
- package/src/view/plugins/string-resolver.ts +22 -22
- package/src/view/plugins/switch.ts +22 -23
- package/src/view/plugins/template-plugin.ts +26 -27
- package/src/view/resolver/__tests__/dependencies.test.ts +321 -0
- package/src/view/resolver/__tests__/edgecases.test.ts +626 -0
- package/src/view/resolver/index.ts +42 -42
- package/src/view/resolver/types.ts +21 -20
- package/src/view/resolver/utils.ts +9 -9
- package/src/view/view.ts +32 -22
- package/types/binding/binding.d.ts +50 -0
- package/types/binding/index.d.ts +29 -0
- package/types/binding/resolver.d.ts +26 -0
- package/types/binding/utils.d.ts +12 -0
- package/types/binding-grammar/ast.d.ts +67 -0
- package/types/binding-grammar/custom/index.d.ts +4 -0
- package/types/binding-grammar/ebnf/index.d.ts +4 -0
- package/types/binding-grammar/ebnf/types.d.ts +75 -0
- package/types/binding-grammar/index.d.ts +5 -0
- package/types/binding-grammar/parsimmon/index.d.ts +4 -0
- package/types/controllers/constants/index.d.ts +45 -0
- package/types/controllers/constants/utils.d.ts +6 -0
- package/types/controllers/data/controller.d.ts +45 -0
- package/types/controllers/data/index.d.ts +2 -0
- package/types/controllers/data/utils.d.ts +14 -0
- package/types/controllers/flow/controller.d.ts +25 -0
- package/types/controllers/flow/flow.d.ts +50 -0
- package/types/controllers/flow/index.d.ts +3 -0
- package/types/controllers/index.d.ts +6 -0
- package/types/controllers/validation/binding-tracker.d.ts +32 -0
- package/types/controllers/validation/controller.d.ts +151 -0
- package/types/controllers/validation/index.d.ts +3 -0
- package/types/controllers/view/asset-transform.d.ts +19 -0
- package/types/controllers/view/controller.d.ts +37 -0
- package/types/controllers/view/index.d.ts +5 -0
- package/types/controllers/view/store.d.ts +20 -0
- package/types/controllers/view/types.d.ts +16 -0
- package/types/data/dependency-tracker.d.ts +49 -0
- package/types/data/index.d.ts +5 -0
- package/types/data/local-model.d.ts +16 -0
- package/types/data/model.d.ts +86 -0
- package/types/data/noop-model.d.ts +13 -0
- package/types/expressions/evaluator-functions.d.ts +15 -0
- package/types/expressions/evaluator.d.ts +52 -0
- package/types/expressions/index.d.ts +5 -0
- package/types/expressions/parser.d.ts +10 -0
- package/types/expressions/types.d.ts +144 -0
- package/types/expressions/utils.d.ts +12 -0
- package/types/index.d.ts +14 -0
- package/types/logger/consoleLogger.d.ts +17 -0
- package/types/logger/index.d.ts +6 -0
- package/types/logger/noopLogger.d.ts +10 -0
- package/types/logger/proxyLogger.d.ts +15 -0
- package/types/logger/tapableLogger.d.ts +23 -0
- package/types/logger/types.d.ts +6 -0
- package/types/player.d.ts +101 -0
- package/types/plugins/default-exp-plugin.d.ts +9 -0
- package/types/plugins/default-view-plugin.d.ts +9 -0
- package/types/plugins/flow-exp-plugin.d.ts +11 -0
- package/types/schema/index.d.ts +3 -0
- package/types/schema/schema.d.ts +36 -0
- package/types/schema/types.d.ts +38 -0
- package/types/string-resolver/index.d.ts +30 -0
- package/types/types.d.ts +73 -0
- package/types/utils/index.d.ts +2 -0
- package/types/utils/replaceParams.d.ts +9 -0
- package/types/validator/binding-map-splice.d.ts +10 -0
- package/types/validator/index.d.ts +5 -0
- package/types/validator/registry.d.ts +11 -0
- package/types/validator/types.d.ts +53 -0
- package/types/validator/validation-middleware.d.ts +36 -0
- package/types/view/builder/index.d.ts +35 -0
- package/types/view/index.d.ts +6 -0
- package/types/view/parser/index.d.ts +52 -0
- package/types/view/parser/types.d.ts +109 -0
- package/types/view/parser/utils.d.ts +6 -0
- package/types/view/plugins/applicability.d.ts +10 -0
- package/types/view/plugins/index.d.ts +5 -0
- package/types/view/plugins/options.d.ts +4 -0
- package/types/view/plugins/string-resolver.d.ts +13 -0
- package/types/view/plugins/switch.d.ts +14 -0
- package/types/view/plugins/template-plugin.d.ts +33 -0
- package/types/view/resolver/index.d.ts +73 -0
- package/types/view/resolver/types.d.ts +129 -0
- package/types/view/resolver/utils.d.ts +11 -0
- package/types/view/view.d.ts +37 -0
- package/dist/index.d.ts +0 -1814
- package/dist/player.dev.js +0 -11472
- package/dist/player.prod.js +0 -2
- package/src/view/plugins/plugin.ts +0 -21
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`dynamic templates > Works with template items plus value items > Should show template item first when coming before values on lexical order 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"asset": {
|
|
6
|
+
"id": "overviewItem3",
|
|
7
|
+
"label": {
|
|
8
|
+
"asset": {
|
|
9
|
+
"id": "overviewItem3-label",
|
|
10
|
+
"type": "text",
|
|
11
|
+
"value": "1099-A",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
"type": "overviewItem",
|
|
15
|
+
"values": [
|
|
16
|
+
{
|
|
17
|
+
"asset": {
|
|
18
|
+
"id": "overviewItem3-year",
|
|
19
|
+
"type": "text",
|
|
20
|
+
"value": "Desciption of concept 1099 1",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"asset": {
|
|
25
|
+
"id": "loverviewItem3-cy",
|
|
26
|
+
"type": "text",
|
|
27
|
+
"value": "4000",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
exports[`dynamic templates > Works with template items plus value items > Should show template item last when coming after values on lexical order 1`] = `
|
|
36
|
+
{
|
|
37
|
+
"asset": {
|
|
38
|
+
"id": "overviewItem1",
|
|
39
|
+
"label": {
|
|
40
|
+
"asset": {
|
|
41
|
+
"id": "overviewItem1-label",
|
|
42
|
+
"type": "text",
|
|
43
|
+
"value": "First Summary",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
"type": "overviewItem",
|
|
47
|
+
"values": [
|
|
48
|
+
{
|
|
49
|
+
"asset": {
|
|
50
|
+
"id": "overviewItem1-year",
|
|
51
|
+
"type": "text",
|
|
52
|
+
"value": "Desciption of year summary 1",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"asset": {
|
|
57
|
+
"id": "loverviewItem1-cy",
|
|
58
|
+
"type": "text",
|
|
59
|
+
"value": "14000",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
exports[`templates > works with nested templates 1`] = `
|
|
68
|
+
{
|
|
69
|
+
"children": [
|
|
70
|
+
{
|
|
71
|
+
"path": [
|
|
72
|
+
"values",
|
|
73
|
+
],
|
|
74
|
+
"value": {
|
|
75
|
+
"override": false,
|
|
76
|
+
"parent": [Circular],
|
|
77
|
+
"type": "multi-node",
|
|
78
|
+
"values": [
|
|
79
|
+
{
|
|
80
|
+
"children": [
|
|
81
|
+
{
|
|
82
|
+
"path": [
|
|
83
|
+
"asset",
|
|
84
|
+
],
|
|
85
|
+
"value": {
|
|
86
|
+
"children": [
|
|
87
|
+
{
|
|
88
|
+
"path": [
|
|
89
|
+
"values",
|
|
90
|
+
],
|
|
91
|
+
"value": {
|
|
92
|
+
"override": false,
|
|
93
|
+
"parent": [Circular],
|
|
94
|
+
"type": "multi-node",
|
|
95
|
+
"values": [
|
|
96
|
+
{
|
|
97
|
+
"parent": [Circular],
|
|
98
|
+
"type": "value",
|
|
99
|
+
"value": {
|
|
100
|
+
"text": "{{foo.pets.0}} + {{foo.people.0}}",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"parent": [Circular],
|
|
105
|
+
"type": "value",
|
|
106
|
+
"value": {
|
|
107
|
+
"text": "{{foo.pets.0}} + {{foo.people.1}}",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
"parent": [Circular],
|
|
115
|
+
"type": "asset",
|
|
116
|
+
"value": {
|
|
117
|
+
"id": "outer-collection-0",
|
|
118
|
+
"type": "collection",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
"parent": [Circular],
|
|
124
|
+
"type": "value",
|
|
125
|
+
"value": undefined,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"children": [
|
|
129
|
+
{
|
|
130
|
+
"path": [
|
|
131
|
+
"asset",
|
|
132
|
+
],
|
|
133
|
+
"value": {
|
|
134
|
+
"children": [
|
|
135
|
+
{
|
|
136
|
+
"path": [
|
|
137
|
+
"values",
|
|
138
|
+
],
|
|
139
|
+
"value": {
|
|
140
|
+
"override": false,
|
|
141
|
+
"parent": [Circular],
|
|
142
|
+
"type": "multi-node",
|
|
143
|
+
"values": [
|
|
144
|
+
{
|
|
145
|
+
"parent": [Circular],
|
|
146
|
+
"type": "value",
|
|
147
|
+
"value": {
|
|
148
|
+
"text": "{{foo.pets.1}} + {{foo.people.0}}",
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"parent": [Circular],
|
|
153
|
+
"type": "value",
|
|
154
|
+
"value": {
|
|
155
|
+
"text": "{{foo.pets.1}} + {{foo.people.1}}",
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
"parent": [Circular],
|
|
163
|
+
"type": "asset",
|
|
164
|
+
"value": {
|
|
165
|
+
"id": "outer-collection-1",
|
|
166
|
+
"type": "collection",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
"parent": [Circular],
|
|
172
|
+
"type": "value",
|
|
173
|
+
"value": undefined,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"children": [
|
|
177
|
+
{
|
|
178
|
+
"path": [
|
|
179
|
+
"asset",
|
|
180
|
+
],
|
|
181
|
+
"value": {
|
|
182
|
+
"children": [
|
|
183
|
+
{
|
|
184
|
+
"path": [
|
|
185
|
+
"values",
|
|
186
|
+
],
|
|
187
|
+
"value": {
|
|
188
|
+
"override": false,
|
|
189
|
+
"parent": [Circular],
|
|
190
|
+
"type": "multi-node",
|
|
191
|
+
"values": [
|
|
192
|
+
{
|
|
193
|
+
"parent": [Circular],
|
|
194
|
+
"type": "value",
|
|
195
|
+
"value": {
|
|
196
|
+
"text": "{{foo.pets.2}} + {{foo.people.0}}",
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"parent": [Circular],
|
|
201
|
+
"type": "value",
|
|
202
|
+
"value": {
|
|
203
|
+
"text": "{{foo.pets.2}} + {{foo.people.1}}",
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
"parent": [Circular],
|
|
211
|
+
"type": "asset",
|
|
212
|
+
"value": {
|
|
213
|
+
"id": "outer-collection-2",
|
|
214
|
+
"type": "collection",
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
"parent": [Circular],
|
|
220
|
+
"type": "value",
|
|
221
|
+
"value": undefined,
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
"type": "value",
|
|
228
|
+
"value": {
|
|
229
|
+
"id": "foo",
|
|
230
|
+
"type": "collection",
|
|
231
|
+
},
|
|
232
|
+
}
|
|
233
|
+
`;
|
|
234
|
+
|
|
235
|
+
exports[`templates > works with simple ones 1`] = `
|
|
236
|
+
{
|
|
237
|
+
"children": [
|
|
238
|
+
{
|
|
239
|
+
"path": [
|
|
240
|
+
"values",
|
|
241
|
+
],
|
|
242
|
+
"value": {
|
|
243
|
+
"override": false,
|
|
244
|
+
"parent": [Circular],
|
|
245
|
+
"type": "multi-node",
|
|
246
|
+
"values": [
|
|
247
|
+
{
|
|
248
|
+
"parent": [Circular],
|
|
249
|
+
"type": "value",
|
|
250
|
+
"value": {
|
|
251
|
+
"value": "{{foo.bar.0}}",
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"parent": [Circular],
|
|
256
|
+
"type": "value",
|
|
257
|
+
"value": {
|
|
258
|
+
"value": "{{foo.bar.1}}",
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"parent": [Circular],
|
|
263
|
+
"type": "value",
|
|
264
|
+
"value": {
|
|
265
|
+
"value": "{{foo.bar.2}}",
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
"type": "value",
|
|
273
|
+
"value": {
|
|
274
|
+
"id": "foo",
|
|
275
|
+
"type": "collection",
|
|
276
|
+
},
|
|
277
|
+
}
|
|
278
|
+
`;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { BindingParser } from "../../../binding";
|
|
3
|
+
import type { DataModelWithParser } from "../../../data";
|
|
4
|
+
import { LocalModel, withParser } from "../../../data";
|
|
5
|
+
import { ExpressionEvaluator } from "../../../expressions";
|
|
6
|
+
import { SchemaController } from "../../../schema";
|
|
7
|
+
import type { Resolve } from "../../resolver";
|
|
8
|
+
import { Resolver } from "../../resolver";
|
|
9
|
+
import type { Node } from "../../parser";
|
|
10
|
+
import { Parser } from "../../parser";
|
|
11
|
+
import { ApplicabilityPlugin, StringResolverPlugin } from "..";
|
|
12
|
+
|
|
13
|
+
const parseBinding = new BindingParser().parse;
|
|
14
|
+
|
|
15
|
+
describe("applicability", () => {
|
|
16
|
+
let model: DataModelWithParser;
|
|
17
|
+
let expressionEvaluator: ExpressionEvaluator;
|
|
18
|
+
let resolverOptions: Resolve.ResolverOptions;
|
|
19
|
+
let parser: Parser;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
model = withParser(new LocalModel(), parseBinding);
|
|
23
|
+
expressionEvaluator = new ExpressionEvaluator({
|
|
24
|
+
model,
|
|
25
|
+
});
|
|
26
|
+
parser = new Parser();
|
|
27
|
+
|
|
28
|
+
resolverOptions = {
|
|
29
|
+
evaluator: expressionEvaluator,
|
|
30
|
+
parseBinding,
|
|
31
|
+
model,
|
|
32
|
+
parseNode: parser.parseObject.bind(parser),
|
|
33
|
+
schema: new SchemaController(),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("undefined does not remove asset", () => {
|
|
38
|
+
const aP = new ApplicabilityPlugin();
|
|
39
|
+
const sP = new StringResolverPlugin();
|
|
40
|
+
|
|
41
|
+
aP.applyParser(parser);
|
|
42
|
+
|
|
43
|
+
const root = parser.parseObject({
|
|
44
|
+
asset: {
|
|
45
|
+
values: [
|
|
46
|
+
{
|
|
47
|
+
applicability: "{{foo}}",
|
|
48
|
+
value: "foo",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
value: "bar",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const resolver = new Resolver(root as Node.Node, resolverOptions);
|
|
58
|
+
|
|
59
|
+
aP.applyResolver(resolver);
|
|
60
|
+
sP.applyResolver(resolver);
|
|
61
|
+
|
|
62
|
+
expect(resolver.update()).toStrictEqual({
|
|
63
|
+
asset: { values: [{ value: "foo" }, { value: "bar" }] },
|
|
64
|
+
});
|
|
65
|
+
model.set([["foo", false]]);
|
|
66
|
+
expect(resolver.update()).toStrictEqual({
|
|
67
|
+
asset: { values: [{ value: "bar" }] },
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("removes empty objects", () => {
|
|
72
|
+
new ApplicabilityPlugin().applyParser(parser);
|
|
73
|
+
const root = parser.parseObject({
|
|
74
|
+
asset: {
|
|
75
|
+
values: [
|
|
76
|
+
{
|
|
77
|
+
applicability: "{{foo}}",
|
|
78
|
+
value: "foo",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: "bar",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
model.set([["foo", true]]);
|
|
87
|
+
const resolver = new Resolver(root as Node.Node, resolverOptions);
|
|
88
|
+
|
|
89
|
+
new ApplicabilityPlugin().applyResolver(resolver);
|
|
90
|
+
new StringResolverPlugin().applyResolver(resolver);
|
|
91
|
+
|
|
92
|
+
expect(resolver.update()).toStrictEqual({
|
|
93
|
+
asset: { values: [{ value: "foo" }, { value: "bar" }] },
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
model.set([["foo", false]]);
|
|
97
|
+
expect(resolver.update()).toStrictEqual({
|
|
98
|
+
asset: { values: [{ value: "bar" }] },
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("removes asset wrappers", () => {
|
|
103
|
+
new ApplicabilityPlugin().applyParser(parser);
|
|
104
|
+
const root = parser.parseObject({
|
|
105
|
+
asset: {
|
|
106
|
+
title: {
|
|
107
|
+
applicability: "{{foo}}",
|
|
108
|
+
asset: {
|
|
109
|
+
value: "foo",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
value: "Hello World",
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
model.set([["foo", true]]);
|
|
116
|
+
const resolver = new Resolver(root as Node.Node, resolverOptions);
|
|
117
|
+
|
|
118
|
+
new ApplicabilityPlugin().applyResolver(resolver);
|
|
119
|
+
new StringResolverPlugin().applyResolver(resolver);
|
|
120
|
+
|
|
121
|
+
expect(resolver.update()).toStrictEqual({
|
|
122
|
+
asset: { title: { asset: { value: "foo" } }, value: "Hello World" },
|
|
123
|
+
});
|
|
124
|
+
model.set([["foo", false]]);
|
|
125
|
+
expect(resolver.update()).toStrictEqual({
|
|
126
|
+
asset: { value: "Hello World" },
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("handles empty models", () => {
|
|
131
|
+
new ApplicabilityPlugin().applyParser(parser);
|
|
132
|
+
const root = parser.parseObject({
|
|
133
|
+
asset: {
|
|
134
|
+
values: [
|
|
135
|
+
{
|
|
136
|
+
asset: {
|
|
137
|
+
id: "some-asset-1",
|
|
138
|
+
type: "text",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
asset: {
|
|
143
|
+
id: "some-asset-2",
|
|
144
|
+
type: "text",
|
|
145
|
+
applicability: "{{foo}} == true",
|
|
146
|
+
value: "foo",
|
|
147
|
+
label: {
|
|
148
|
+
asset: {
|
|
149
|
+
applicability: "{{bar}} == true",
|
|
150
|
+
value: "bar",
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
const fooBinding = parseBinding("foo");
|
|
159
|
+
const barBinding = parseBinding("bar");
|
|
160
|
+
|
|
161
|
+
model.set([
|
|
162
|
+
[fooBinding, true],
|
|
163
|
+
[barBinding, true],
|
|
164
|
+
]);
|
|
165
|
+
const resolver = new Resolver(root as Node.Node, resolverOptions);
|
|
166
|
+
|
|
167
|
+
new ApplicabilityPlugin().applyResolver(resolver);
|
|
168
|
+
new StringResolverPlugin().applyResolver(resolver);
|
|
169
|
+
|
|
170
|
+
expect(resolver.update()).toStrictEqual({
|
|
171
|
+
asset: {
|
|
172
|
+
values: [
|
|
173
|
+
{
|
|
174
|
+
asset: {
|
|
175
|
+
id: "some-asset-1",
|
|
176
|
+
type: "text",
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
asset: {
|
|
181
|
+
id: "some-asset-2",
|
|
182
|
+
type: "text",
|
|
183
|
+
value: "foo",
|
|
184
|
+
label: { asset: { value: "bar" } },
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
model.set([[fooBinding, false]]);
|
|
191
|
+
expect(resolver.update(new Set([fooBinding]))).toStrictEqual({
|
|
192
|
+
asset: {
|
|
193
|
+
values: [
|
|
194
|
+
{
|
|
195
|
+
asset: {
|
|
196
|
+
id: "some-asset-1",
|
|
197
|
+
type: "text",
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
model.set([[fooBinding, true]]);
|
|
205
|
+
expect(resolver.update(new Set([fooBinding]))).toStrictEqual({
|
|
206
|
+
asset: {
|
|
207
|
+
values: [
|
|
208
|
+
{
|
|
209
|
+
asset: {
|
|
210
|
+
id: "some-asset-1",
|
|
211
|
+
type: "text",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
asset: {
|
|
216
|
+
id: "some-asset-2",
|
|
217
|
+
type: "text",
|
|
218
|
+
value: "foo",
|
|
219
|
+
label: { asset: { value: "bar" } },
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
model.set([[barBinding, false]]);
|
|
227
|
+
expect(resolver.update(new Set([barBinding]))).toStrictEqual({
|
|
228
|
+
asset: {
|
|
229
|
+
values: [
|
|
230
|
+
{
|
|
231
|
+
asset: {
|
|
232
|
+
id: "some-asset-1",
|
|
233
|
+
type: "text",
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
asset: {
|
|
238
|
+
id: "some-asset-2",
|
|
239
|
+
type: "text",
|
|
240
|
+
value: "foo",
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("determines if nodeType is applicability", () => {
|
|
249
|
+
new ApplicabilityPlugin().applyParser(parser);
|
|
250
|
+
const nodeTest = {
|
|
251
|
+
applicability: "{{bar}} == true",
|
|
252
|
+
};
|
|
253
|
+
const nodeType = parser.hooks.determineNodeType.call(nodeTest);
|
|
254
|
+
expect(nodeType).toStrictEqual("applicability");
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("Does not return a nodeType", () => {
|
|
258
|
+
new ApplicabilityPlugin().applyParser(parser);
|
|
259
|
+
const nodeTest = {
|
|
260
|
+
value: "foo",
|
|
261
|
+
};
|
|
262
|
+
const nodeType = parser.hooks.determineNodeType.call(nodeTest);
|
|
263
|
+
expect(nodeType).toBe(undefined);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { describe, expect, beforeEach, test } from "vitest";
|
|
2
|
+
import { BindingParser } from "../../../binding";
|
|
3
|
+
import type { DataModelImpl } from "../../../data";
|
|
4
|
+
import { LocalModel, withParser } from "../../../data";
|
|
5
|
+
import { ExpressionEvaluator } from "../../../expressions";
|
|
6
|
+
import { SchemaController } from "../../../schema";
|
|
7
|
+
import type { Resolve } from "../../resolver";
|
|
8
|
+
import { Resolver } from "../../resolver";
|
|
9
|
+
import { NodeType, Parser } from "../../parser";
|
|
10
|
+
import { StringResolverPlugin } from "..";
|
|
11
|
+
|
|
12
|
+
describe("string-resolver", () => {
|
|
13
|
+
let model: DataModelImpl;
|
|
14
|
+
let expressionEvaluator: ExpressionEvaluator;
|
|
15
|
+
let resolverOptions: Resolve.ResolverOptions;
|
|
16
|
+
let parser: Parser;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
const localModel = new LocalModel({
|
|
20
|
+
name: "Adam",
|
|
21
|
+
age: 27,
|
|
22
|
+
city: "San Diego",
|
|
23
|
+
nested: "Name: {{name}} age: {{age}}",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const bindingParser = new BindingParser({
|
|
27
|
+
set: localModel.set,
|
|
28
|
+
get: localModel.get,
|
|
29
|
+
});
|
|
30
|
+
model = withParser(localModel, bindingParser.parse);
|
|
31
|
+
|
|
32
|
+
expressionEvaluator = new ExpressionEvaluator({
|
|
33
|
+
model,
|
|
34
|
+
});
|
|
35
|
+
parser = new Parser();
|
|
36
|
+
|
|
37
|
+
resolverOptions = {
|
|
38
|
+
evaluator: expressionEvaluator,
|
|
39
|
+
model,
|
|
40
|
+
parseBinding: bindingParser.parse,
|
|
41
|
+
parseNode: parser.parseObject.bind(parser),
|
|
42
|
+
schema: new SchemaController(),
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("resolves basic objects", () => {
|
|
47
|
+
const root = parser.parseObject({
|
|
48
|
+
asset: {
|
|
49
|
+
type: "bar",
|
|
50
|
+
name: "My name is {{name}}",
|
|
51
|
+
age: "{{age}}",
|
|
52
|
+
alt: "{{nested}}",
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const resolver = new Resolver(root!, resolverOptions);
|
|
56
|
+
new StringResolverPlugin().applyResolver(resolver);
|
|
57
|
+
expect(resolver.update()).toStrictEqual({
|
|
58
|
+
asset: {
|
|
59
|
+
type: "bar",
|
|
60
|
+
name: "My name is Adam",
|
|
61
|
+
age: 27,
|
|
62
|
+
alt: "Name: Adam age: 27",
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("skips exp prop when configured", () => {
|
|
68
|
+
const root = parser.parseObject({
|
|
69
|
+
asset: {
|
|
70
|
+
type: "bar",
|
|
71
|
+
name: "My name is {{name}}",
|
|
72
|
+
age: "{{age}}",
|
|
73
|
+
alt: "{{nested}}",
|
|
74
|
+
exp: {
|
|
75
|
+
onStart: '{{name}} = "test"',
|
|
76
|
+
},
|
|
77
|
+
label: {
|
|
78
|
+
asset: {
|
|
79
|
+
id: "foo",
|
|
80
|
+
type: "bar",
|
|
81
|
+
exp: '{{name}} = "other"',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const resolver = new Resolver(root!, resolverOptions);
|
|
88
|
+
|
|
89
|
+
resolver.hooks.beforeResolve.tap("test", (n) => {
|
|
90
|
+
if (n?.type === NodeType.Asset || n?.type === NodeType.View) {
|
|
91
|
+
return {
|
|
92
|
+
...n,
|
|
93
|
+
plugins: {
|
|
94
|
+
stringResolver: {
|
|
95
|
+
propertiesToSkip: ["exp"],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
new StringResolverPlugin().applyResolver(resolver);
|
|
103
|
+
expect(resolver.update()).toStrictEqual({
|
|
104
|
+
asset: {
|
|
105
|
+
type: "bar",
|
|
106
|
+
name: "My name is Adam",
|
|
107
|
+
age: 27,
|
|
108
|
+
alt: "Name: Adam age: 27",
|
|
109
|
+
exp: {
|
|
110
|
+
onStart: '{{name}} = "test"',
|
|
111
|
+
},
|
|
112
|
+
label: {
|
|
113
|
+
asset: {
|
|
114
|
+
id: "foo",
|
|
115
|
+
type: "bar",
|
|
116
|
+
exp: '{{name}} = "other"',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|