react-native-divkit 0.1.0-alpha.1 → 0.1.0-alpha.2
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/README.md +135 -137
- package/dist/DivKit.d.ts.map +1 -1
- package/dist/DivKit.js +24 -7
- package/dist/DivKit.js.map +1 -1
- package/dist/actions/array.d.ts.map +1 -1
- package/dist/actions/array.js +1 -1
- package/dist/actions/array.js.map +1 -1
- package/dist/actions/copyToClipboard.d.ts.map +1 -1
- package/dist/actions/copyToClipboard.js +2 -1
- package/dist/actions/copyToClipboard.js.map +1 -1
- package/dist/actions/dict.d.ts.map +1 -1
- package/dist/actions/dict.js.map +1 -1
- package/dist/actions/updateStructure.d.ts.map +1 -1
- package/dist/actions/updateStructure.js.map +1 -1
- package/dist/components/container/DivContainer.d.ts.map +1 -1
- package/dist/components/container/DivContainer.js +3 -5
- package/dist/components/container/DivContainer.js.map +1 -1
- package/dist/components/image/DivImage.d.ts.map +1 -1
- package/dist/components/image/DivImage.js +1 -6
- package/dist/components/image/DivImage.js.map +1 -1
- package/dist/components/state/DivState.d.ts.map +1 -1
- package/dist/components/state/DivState.js +3 -5
- package/dist/components/state/DivState.js.map +1 -1
- package/dist/components/text/DivText.d.ts.map +1 -1
- package/dist/components/text/DivText.js +4 -4
- package/dist/components/text/DivText.js.map +1 -1
- package/dist/components/utilities/Outer.d.ts.map +1 -1
- package/dist/components/utilities/Outer.js +6 -5
- package/dist/components/utilities/Outer.js.map +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/expressions/eval.d.ts.map +1 -1
- package/dist/expressions/eval.js +19 -11
- package/dist/expressions/eval.js.map +1 -1
- package/dist/expressions/funcs/array.d.ts.map +1 -1
- package/dist/expressions/funcs/array.js +72 -168
- package/dist/expressions/funcs/array.js.map +1 -1
- package/dist/expressions/funcs/colors.d.ts.map +1 -1
- package/dist/expressions/funcs/colors.js.map +1 -1
- package/dist/expressions/funcs/customFuncs.d.ts.map +1 -1
- package/dist/expressions/funcs/customFuncs.js +6 -4
- package/dist/expressions/funcs/customFuncs.js.map +1 -1
- package/dist/expressions/funcs/datetime.d.ts.map +1 -1
- package/dist/expressions/funcs/datetime.js +1 -1
- package/dist/expressions/funcs/datetime.js.map +1 -1
- package/dist/expressions/funcs/dict.d.ts.map +1 -1
- package/dist/expressions/funcs/dict.js.map +1 -1
- package/dist/expressions/funcs/funcs.d.ts.map +1 -1
- package/dist/expressions/funcs/funcs.js +21 -13
- package/dist/expressions/funcs/funcs.js.map +1 -1
- package/dist/expressions/funcs/math.d.ts.map +1 -1
- package/dist/expressions/funcs/math.js +40 -20
- package/dist/expressions/funcs/math.js.map +1 -1
- package/dist/expressions/funcs/std.d.ts.map +1 -1
- package/dist/expressions/funcs/std.js +4 -4
- package/dist/expressions/funcs/std.js.map +1 -1
- package/dist/expressions/funcs/strings.d.ts.map +1 -1
- package/dist/expressions/funcs/strings.js +1 -2
- package/dist/expressions/funcs/strings.js.map +1 -1
- package/dist/expressions/funcs/trigonometry.js +2 -2
- package/dist/expressions/funcs/trigonometry.js.map +1 -1
- package/dist/expressions/json.d.ts +2 -2
- package/dist/expressions/json.d.ts.map +1 -1
- package/dist/expressions/json.js +6 -4
- package/dist/expressions/json.js.map +1 -1
- package/dist/expressions/utils.d.ts.map +1 -1
- package/dist/expressions/utils.js +9 -10
- package/dist/expressions/utils.js.map +1 -1
- package/dist/expressions/variable.d.ts.map +1 -1
- package/dist/expressions/variable.js +3 -7
- package/dist/expressions/variable.js.map +1 -1
- package/dist/expressions/walk.d.ts.map +1 -1
- package/dist/expressions/walk.js.map +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useAction.d.ts.map +1 -1
- package/dist/hooks/useAction.js.map +1 -1
- package/dist/hooks/useDerivedFromVars.d.ts.map +1 -1
- package/dist/hooks/useDerivedFromVars.js.map +1 -1
- package/dist/hooks/useVariable.d.ts.map +1 -1
- package/dist/hooks/useVariable.js +4 -4
- package/dist/hooks/useVariable.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/stores/createObservable.d.ts.map +1 -1
- package/dist/stores/createObservable.js.map +1 -1
- package/dist/utils/applyTemplate.d.ts +2 -2
- package/dist/utils/applyTemplate.d.ts.map +1 -1
- package/dist/utils/applyTemplate.js +13 -13
- package/dist/utils/applyTemplate.js.map +1 -1
- package/dist/utils/correctColor.d.ts.map +1 -1
- package/dist/utils/correctColor.js +8 -6
- package/dist/utils/correctColor.js.map +1 -1
- package/dist/utils/formatDate.d.ts.map +1 -1
- package/dist/utils/formatDate.js +7 -10
- package/dist/utils/formatDate.js.map +1 -1
- package/dist/utils/wrapError.d.ts.map +1 -1
- package/dist/utils/wrapError.js.map +1 -1
- package/package.json +2 -2
- package/src/DivKit.tsx +258 -220
- package/src/actions/array.ts +91 -64
- package/src/actions/copyToClipboard.ts +28 -19
- package/src/actions/dict.ts +36 -26
- package/src/actions/updateStructure.ts +86 -61
- package/src/components/README.md +38 -18
- package/src/components/container/DivContainer.tsx +4 -14
- package/src/components/image/DivImage.tsx +1 -11
- package/src/components/state/DivState.tsx +3 -9
- package/src/components/text/DivText.tsx +8 -20
- package/src/components/utilities/Outer.tsx +9 -19
- package/src/components/utilities/README.md +33 -29
- package/src/context/index.ts +2 -11
- package/src/expressions/ast.d.ts +16 -9
- package/src/expressions/eval.ts +82 -37
- package/src/expressions/funcs/array.ts +129 -209
- package/src/expressions/funcs/colors.ts +1 -3
- package/src/expressions/funcs/customFuncs.ts +6 -4
- package/src/expressions/funcs/datetime.ts +10 -3
- package/src/expressions/funcs/dict.ts +16 -2
- package/src/expressions/funcs/funcs.ts +75 -89
- package/src/expressions/funcs/math.ts +103 -43
- package/src/expressions/funcs/std.ts +4 -7
- package/src/expressions/funcs/strings.ts +9 -25
- package/src/expressions/funcs/trigonometry.ts +2 -2
- package/src/expressions/json.ts +60 -53
- package/src/expressions/utils.ts +24 -22
- package/src/expressions/variable.ts +5 -21
- package/src/expressions/walk.ts +6 -3
- package/src/hooks/README.md +61 -53
- package/src/hooks/index.ts +3 -18
- package/src/hooks/useAction.ts +1 -3
- package/src/hooks/useDerivedFromVars.ts +3 -13
- package/src/hooks/useVariable.ts +7 -17
- package/src/index.ts +10 -48
- package/src/stores/createObservable.ts +35 -35
- package/src/types/alignment.d.ts +15 -6
- package/src/types/background.d.ts +6 -2
- package/src/types/base.d.ts +41 -9
- package/src/types/componentContext.d.ts +27 -22
- package/src/types/container.d.ts +1 -4
- package/src/types/text.d.ts +1 -1
- package/src/utils/applyTemplate.ts +103 -109
- package/src/utils/correctColor.ts +9 -8
- package/src/utils/formatDate.ts +175 -86
- package/src/utils/wrapError.ts +7 -4
package/src/actions/array.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ActionArrayInsertValue,
|
|
3
|
+
ActionArrayRemoveValue,
|
|
4
|
+
ActionArraySetValue,
|
|
5
|
+
WrappedError
|
|
6
|
+
} from '../../typings/common';
|
|
2
7
|
import type { ArrayVariable, Variable } from '../../typings/variables';
|
|
3
8
|
import type { MaybeMissing } from '../expressions/json';
|
|
4
9
|
import { convertTypedValue } from '../expressions/utils';
|
|
@@ -13,31 +18,37 @@ export function arrayInsert(
|
|
|
13
18
|
): void {
|
|
14
19
|
const { variable_name: name, index, value } = actionTyped;
|
|
15
20
|
|
|
16
|
-
if (!value || typeof index !== 'number' && index !== undefined) {
|
|
17
|
-
logError(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (!value || (typeof index !== 'number' && index !== undefined)) {
|
|
22
|
+
logError(
|
|
23
|
+
wrapError(new Error('Incorrect array_insert_value action'), {
|
|
24
|
+
additional: {
|
|
25
|
+
name
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
);
|
|
22
29
|
return;
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
26
33
|
const list = variableInstance.getValue();
|
|
27
34
|
if (typeof index === 'number' && (index < 0 || index > list.length)) {
|
|
28
|
-
logError(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
logError(
|
|
36
|
+
wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
37
|
+
additional: {
|
|
38
|
+
name,
|
|
39
|
+
index,
|
|
40
|
+
length: list.length
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
);
|
|
35
44
|
} else if (!value.type) {
|
|
36
|
-
logError(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
logError(
|
|
46
|
+
wrapError(new Error('Incorrect value type'), {
|
|
47
|
+
additional: {
|
|
48
|
+
name
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
);
|
|
41
52
|
} else {
|
|
42
53
|
const newList = list.slice();
|
|
43
54
|
const val = convertTypedValue(value);
|
|
@@ -60,24 +71,28 @@ export function arrayRemove(
|
|
|
60
71
|
const { variable_name: name, index } = actionTyped;
|
|
61
72
|
|
|
62
73
|
if (typeof index !== 'number') {
|
|
63
|
-
logError(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
logError(
|
|
75
|
+
wrapError(new Error('Incorrect array_remove_value action'), {
|
|
76
|
+
additional: {
|
|
77
|
+
name
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
);
|
|
68
81
|
return;
|
|
69
82
|
}
|
|
70
83
|
|
|
71
84
|
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
72
85
|
const list = variableInstance.getValue();
|
|
73
86
|
if (typeof index === 'number' && (index < 0 || index >= list.length)) {
|
|
74
|
-
logError(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
logError(
|
|
88
|
+
wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
89
|
+
additional: {
|
|
90
|
+
name,
|
|
91
|
+
index,
|
|
92
|
+
length: list.length
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
);
|
|
81
96
|
} else {
|
|
82
97
|
const newList = list.slice();
|
|
83
98
|
newList.splice(index, 1);
|
|
@@ -95,30 +110,36 @@ export function arraySet(
|
|
|
95
110
|
const { variable_name: name, index, value } = actionTyped;
|
|
96
111
|
|
|
97
112
|
if (!value || typeof index !== 'number') {
|
|
98
|
-
logError(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
logError(
|
|
114
|
+
wrapError(new Error('Incorrect array_set_value action'), {
|
|
115
|
+
additional: {
|
|
116
|
+
name
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
);
|
|
103
120
|
return;
|
|
104
121
|
}
|
|
105
122
|
|
|
106
123
|
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
107
124
|
const list = variableInstance.getValue();
|
|
108
125
|
if (typeof index === 'number' && (index < 0 || index >= list.length)) {
|
|
109
|
-
logError(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
logError(
|
|
127
|
+
wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
128
|
+
additional: {
|
|
129
|
+
name,
|
|
130
|
+
index,
|
|
131
|
+
length: list.length
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
);
|
|
116
135
|
} else if (!value.type) {
|
|
117
|
-
logError(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
logError(
|
|
137
|
+
wrapError(new Error('Incorrect value type'), {
|
|
138
|
+
additional: {
|
|
139
|
+
name
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
);
|
|
122
143
|
} else {
|
|
123
144
|
const newList = list.slice();
|
|
124
145
|
newList[index] = convertTypedValue(value);
|
|
@@ -137,22 +158,26 @@ function handle(
|
|
|
137
158
|
const { variable_name: name } = actionTyped;
|
|
138
159
|
|
|
139
160
|
if (!name) {
|
|
140
|
-
logError(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
161
|
+
logError(
|
|
162
|
+
wrapError(new Error(`Incorrect ${actionTyped.type} action`), {
|
|
163
|
+
additional: {
|
|
164
|
+
name
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
);
|
|
145
168
|
return;
|
|
146
169
|
}
|
|
147
170
|
|
|
148
171
|
const variableInstance = componentContext?.getVariable(name) || variables.get(name);
|
|
149
172
|
|
|
150
173
|
if (!variableInstance) {
|
|
151
|
-
logError(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
174
|
+
logError(
|
|
175
|
+
wrapError(new Error('Cannot find variable'), {
|
|
176
|
+
additional: {
|
|
177
|
+
name
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
);
|
|
156
181
|
return;
|
|
157
182
|
}
|
|
158
183
|
|
|
@@ -160,11 +185,13 @@ function handle(
|
|
|
160
185
|
if (type === 'array') {
|
|
161
186
|
cb(variableInstance as ArrayVariable);
|
|
162
187
|
} else {
|
|
163
|
-
logError(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
logError(
|
|
189
|
+
wrapError(new Error('Trying to insert value into the non-array'), {
|
|
190
|
+
additional: {
|
|
191
|
+
name,
|
|
192
|
+
type
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
);
|
|
169
196
|
}
|
|
170
197
|
}
|
|
@@ -44,15 +44,20 @@ export function copyToClipboard(
|
|
|
44
44
|
logError: (error: WrappedError) => void,
|
|
45
45
|
actionTyped: MaybeMissing<ActionCopyToClipboard>
|
|
46
46
|
): void {
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
if (
|
|
48
|
+
!(
|
|
49
|
+
actionTyped.content &&
|
|
50
|
+
(actionTyped.content.type === 'text' || actionTyped.content.type === 'url') &&
|
|
51
|
+
typeof actionTyped.content.value === 'string'
|
|
52
|
+
)
|
|
53
|
+
) {
|
|
54
|
+
logError(
|
|
55
|
+
wrapError(new Error('Incorrect action'), {
|
|
56
|
+
additional: {
|
|
57
|
+
action: actionTyped
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
);
|
|
56
61
|
return;
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -62,21 +67,25 @@ export function copyToClipboard(
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
if (!Clipboard) {
|
|
65
|
-
logError(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
logError(
|
|
71
|
+
wrapError(new Error('Clipboard is unavailable. Install @react-native-clipboard/clipboard'), {
|
|
72
|
+
additional: {
|
|
73
|
+
action: actionTyped
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
);
|
|
70
77
|
return;
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
try {
|
|
74
81
|
Clipboard.setString(actionTyped.content.value);
|
|
75
82
|
} catch (err) {
|
|
76
|
-
logError(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
logError(
|
|
84
|
+
wrapError(new Error('Failed to copy to the clipboard'), {
|
|
85
|
+
additional: {
|
|
86
|
+
originalError: String(err)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
);
|
|
81
90
|
}
|
|
82
91
|
}
|
package/src/actions/dict.ts
CHANGED
|
@@ -14,39 +14,47 @@ export function dictSetValue(
|
|
|
14
14
|
const { variable_name: name, key, value } = actionTyped;
|
|
15
15
|
|
|
16
16
|
if (typeof key !== 'string') {
|
|
17
|
-
logError(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
logError(
|
|
18
|
+
wrapError(new Error('Incorrect dict_set_value action'), {
|
|
19
|
+
additional: {
|
|
20
|
+
name
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
);
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
if (!name) {
|
|
26
|
-
logError(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
logError(
|
|
29
|
+
wrapError(new Error(`Incorrect ${actionTyped.type} action`), {
|
|
30
|
+
additional: {
|
|
31
|
+
name
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
);
|
|
31
35
|
return;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
if (value && !value.type) {
|
|
35
|
-
logError(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
logError(
|
|
40
|
+
wrapError(new Error('Incorrect value type'), {
|
|
41
|
+
additional: {
|
|
42
|
+
name
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
);
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
const variableInstance = componentContext?.getVariable(name) || variables.get(name);
|
|
43
49
|
|
|
44
50
|
if (!variableInstance) {
|
|
45
|
-
logError(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
logError(
|
|
52
|
+
wrapError(new Error('Cannot find variable'), {
|
|
53
|
+
additional: {
|
|
54
|
+
name
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
);
|
|
50
58
|
return;
|
|
51
59
|
}
|
|
52
60
|
|
|
@@ -61,11 +69,13 @@ export function dictSetValue(
|
|
|
61
69
|
}
|
|
62
70
|
variableInstance.setValue(newDict);
|
|
63
71
|
} else {
|
|
64
|
-
logError(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
logError(
|
|
73
|
+
wrapError(new Error('Trying to set value into the non-dict'), {
|
|
74
|
+
additional: {
|
|
75
|
+
name,
|
|
76
|
+
type
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
);
|
|
70
80
|
}
|
|
71
81
|
}
|
|
@@ -14,40 +14,48 @@ export function updateStructure(
|
|
|
14
14
|
const { variable_name: name, path, value } = actionTyped;
|
|
15
15
|
|
|
16
16
|
if (!value?.value) {
|
|
17
|
-
logError(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
logError(
|
|
18
|
+
wrapError(new Error('Missing value for an action'), {
|
|
19
|
+
additional: {
|
|
20
|
+
name
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
);
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
if (typeof path !== 'string' || !path || path.charAt(0) === '/' || path.charAt(path.length - 1) === '/') {
|
|
26
|
-
logError(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
logError(
|
|
29
|
+
wrapError(new Error(`Value '${path}' for key 'path' is not valid`), {
|
|
30
|
+
additional: {
|
|
31
|
+
name
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
);
|
|
31
35
|
return;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
if (!name) {
|
|
35
|
-
logError(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
logError(
|
|
40
|
+
wrapError(new Error(`Incorrect ${actionTyped.type} action`), {
|
|
41
|
+
additional: {
|
|
42
|
+
name
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
);
|
|
40
46
|
return;
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
const variableInstance = componentContext?.getVariable(name) || variables.get(name);
|
|
44
50
|
|
|
45
51
|
if (!variableInstance) {
|
|
46
|
-
logError(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
logError(
|
|
53
|
+
wrapError(new Error('Cannot find variable'), {
|
|
54
|
+
additional: {
|
|
55
|
+
name
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
);
|
|
51
59
|
return;
|
|
52
60
|
}
|
|
53
61
|
|
|
@@ -56,13 +64,15 @@ export function updateStructure(
|
|
|
56
64
|
const obj = variableInstance.getValue() as Record<string, unknown>;
|
|
57
65
|
const processed = path.replace(/\/+/g, '/');
|
|
58
66
|
if (processed === '/') {
|
|
59
|
-
logError(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
logError(
|
|
68
|
+
wrapError(new Error(`Value '${path}' for key 'path' is not valid`), {
|
|
69
|
+
additional: {
|
|
70
|
+
name,
|
|
71
|
+
type,
|
|
72
|
+
path
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
);
|
|
66
76
|
return;
|
|
67
77
|
}
|
|
68
78
|
const parts = processed.split('/');
|
|
@@ -72,46 +82,59 @@ export function updateStructure(
|
|
|
72
82
|
const part = parts[i];
|
|
73
83
|
|
|
74
84
|
if (!part) {
|
|
75
|
-
logError(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
logError(
|
|
86
|
+
wrapError(new Error('Path is empty'), {
|
|
87
|
+
additional: {
|
|
88
|
+
name,
|
|
89
|
+
type,
|
|
90
|
+
path
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
);
|
|
82
94
|
return;
|
|
83
95
|
}
|
|
84
96
|
|
|
85
97
|
if (!temp || typeof temp !== 'object') {
|
|
86
|
-
logError(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
logError(
|
|
99
|
+
wrapError(
|
|
100
|
+
new Error(
|
|
101
|
+
`Element with path '${parts.slice(0, i).join('/')}' is not ${temp === undefined ? 'found' : 'a structure'}`
|
|
102
|
+
),
|
|
103
|
+
{
|
|
104
|
+
additional: {
|
|
105
|
+
name,
|
|
106
|
+
type,
|
|
107
|
+
path
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
);
|
|
93
112
|
return;
|
|
94
113
|
}
|
|
95
114
|
if (Array.isArray(temp)) {
|
|
96
115
|
const int = Number(part);
|
|
97
116
|
if (Number.isNaN(int)) {
|
|
98
|
-
logError(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
117
|
+
logError(
|
|
118
|
+
wrapError(new Error(`Unable to use '${part}' as array index`), {
|
|
119
|
+
additional: {
|
|
120
|
+
name,
|
|
121
|
+
type,
|
|
122
|
+
path
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
);
|
|
105
126
|
return;
|
|
106
127
|
}
|
|
107
128
|
if (i + 1 === parts.length && (int < 0 || int > temp.length)) {
|
|
108
|
-
logError(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
129
|
+
logError(
|
|
130
|
+
wrapError(new Error(`Position '${int}' is out of array bounds`), {
|
|
131
|
+
additional: {
|
|
132
|
+
name,
|
|
133
|
+
type,
|
|
134
|
+
path
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
);
|
|
115
138
|
return;
|
|
116
139
|
}
|
|
117
140
|
}
|
|
@@ -124,11 +147,13 @@ export function updateStructure(
|
|
|
124
147
|
temp[parts[parts.length - 1]] = convertTypedValue(value);
|
|
125
148
|
variableInstance.setValue(newObj);
|
|
126
149
|
} else {
|
|
127
|
-
logError(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
150
|
+
logError(
|
|
151
|
+
wrapError(new Error('Action requires array or dictionary variable'), {
|
|
152
|
+
additional: {
|
|
153
|
+
name,
|
|
154
|
+
type
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
);
|
|
133
158
|
}
|
|
134
159
|
}
|