@routevn/creator-model 1.3.7 → 1.4.1
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/package.json +1 -1
- package/src/index.js +1 -0
- package/src/model.js +450 -20
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/model.js
CHANGED
|
@@ -45,6 +45,7 @@ const createEmptyCollectionState = () => ({
|
|
|
45
45
|
items: {},
|
|
46
46
|
tree: [],
|
|
47
47
|
});
|
|
48
|
+
const VALID_VARIABLE_ITEM_TYPES = new Set(["folder", "variable"]);
|
|
48
49
|
const TAG_SCOPE_BASE_KEYS = [
|
|
49
50
|
"images",
|
|
50
51
|
"sounds",
|
|
@@ -113,6 +114,123 @@ const normalizeTagsState = (tags) => {
|
|
|
113
114
|
return nextTags;
|
|
114
115
|
};
|
|
115
116
|
|
|
117
|
+
const filterVariableTreeNodes = ({ nodes, unsupportedItemIds }) => {
|
|
118
|
+
if (!Array.isArray(nodes)) {
|
|
119
|
+
return {
|
|
120
|
+
nodes,
|
|
121
|
+
changed: false,
|
|
122
|
+
removedIds: new Set(),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const filteredNodes = [];
|
|
127
|
+
const removedIds = new Set();
|
|
128
|
+
let changed = false;
|
|
129
|
+
|
|
130
|
+
for (const node of nodes) {
|
|
131
|
+
if (!isPlainObject(node)) {
|
|
132
|
+
filteredNodes.push(node);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (unsupportedItemIds.has(node.id)) {
|
|
137
|
+
changed = true;
|
|
138
|
+
collectVariableTreeIds([node], removedIds);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const childrenResult = filterVariableTreeNodes({
|
|
143
|
+
nodes: node.children,
|
|
144
|
+
unsupportedItemIds,
|
|
145
|
+
});
|
|
146
|
+
for (const removedId of childrenResult.removedIds) {
|
|
147
|
+
removedIds.add(removedId);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (childrenResult.changed) {
|
|
151
|
+
changed = true;
|
|
152
|
+
filteredNodes.push({
|
|
153
|
+
...node,
|
|
154
|
+
children: childrenResult.nodes,
|
|
155
|
+
});
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
filteredNodes.push(node);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (filteredNodes.length !== nodes.length) {
|
|
163
|
+
changed = true;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
nodes: changed ? filteredNodes : nodes,
|
|
168
|
+
changed,
|
|
169
|
+
removedIds,
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const collectVariableTreeIds = (nodes, ids = new Set()) => {
|
|
174
|
+
if (!Array.isArray(nodes)) {
|
|
175
|
+
return ids;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
for (const node of nodes) {
|
|
179
|
+
if (!isPlainObject(node) || !isNonEmptyString(node.id)) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
ids.add(node.id);
|
|
184
|
+
collectVariableTreeIds(node.children, ids);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return ids;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const normalizeVariablesCollection = (variables) => {
|
|
191
|
+
if (!isPlainObject(variables) || !isPlainObject(variables.items)) {
|
|
192
|
+
return variables;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const unsupportedItemIds = new Set();
|
|
196
|
+
const nextItems = {};
|
|
197
|
+
let didFilterItems = false;
|
|
198
|
+
|
|
199
|
+
for (const [itemId, item] of Object.entries(variables.items)) {
|
|
200
|
+
if (!VALID_VARIABLE_ITEM_TYPES.has(item?.type)) {
|
|
201
|
+
unsupportedItemIds.add(itemId);
|
|
202
|
+
didFilterItems = true;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
nextItems[itemId] = item;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const treeResult = filterVariableTreeNodes({
|
|
210
|
+
nodes: variables.tree,
|
|
211
|
+
unsupportedItemIds,
|
|
212
|
+
});
|
|
213
|
+
const nextTree = treeResult.nodes;
|
|
214
|
+
const didFilterTree = treeResult.changed;
|
|
215
|
+
|
|
216
|
+
for (const removedId of treeResult.removedIds) {
|
|
217
|
+
if (Object.hasOwn(nextItems, removedId)) {
|
|
218
|
+
delete nextItems[removedId];
|
|
219
|
+
didFilterItems = true;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!didFilterItems && !didFilterTree) {
|
|
224
|
+
return variables;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
...variables,
|
|
229
|
+
items: nextItems,
|
|
230
|
+
tree: nextTree,
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
|
|
116
234
|
const normalizeStateCollections = (state) => {
|
|
117
235
|
if (!isPlainObject(state)) {
|
|
118
236
|
return state;
|
|
@@ -125,8 +243,14 @@ const normalizeStateCollections = (state) => {
|
|
|
125
243
|
].filter((key) => state[key] === undefined);
|
|
126
244
|
const normalizedTags = normalizeTagsState(state.tags);
|
|
127
245
|
const hasNormalizedTags = normalizedTags !== state.tags;
|
|
246
|
+
const normalizedVariables = normalizeVariablesCollection(state.variables);
|
|
247
|
+
const hasNormalizedVariables = normalizedVariables !== state.variables;
|
|
128
248
|
|
|
129
|
-
if (
|
|
249
|
+
if (
|
|
250
|
+
missingCollectionKeys.length === 0 &&
|
|
251
|
+
!hasNormalizedTags &&
|
|
252
|
+
!hasNormalizedVariables
|
|
253
|
+
) {
|
|
130
254
|
return state;
|
|
131
255
|
}
|
|
132
256
|
|
|
@@ -141,6 +265,9 @@ const normalizeStateCollections = (state) => {
|
|
|
141
265
|
if (hasNormalizedTags) {
|
|
142
266
|
nextState.tags = normalizedTags;
|
|
143
267
|
}
|
|
268
|
+
if (hasNormalizedVariables) {
|
|
269
|
+
nextState.variables = normalizedVariables;
|
|
270
|
+
}
|
|
144
271
|
|
|
145
272
|
return nextState;
|
|
146
273
|
};
|
|
@@ -249,7 +376,7 @@ const LAYOUT_ELEMENT_BASE_TYPES = [
|
|
|
249
376
|
"container-ref-confirm-dialog-ok",
|
|
250
377
|
"container-ref-confirm-dialog-cancel",
|
|
251
378
|
];
|
|
252
|
-
export const SCHEMA_VERSION =
|
|
379
|
+
export const SCHEMA_VERSION = 4;
|
|
253
380
|
const LAYOUT_CONTAINER_ELEMENT_TYPES = [
|
|
254
381
|
"folder",
|
|
255
382
|
"container",
|
|
@@ -2313,6 +2440,9 @@ const validateTransformItems = ({ items, path, errorFactory }) => {
|
|
|
2313
2440
|
"anchorX",
|
|
2314
2441
|
"anchorY",
|
|
2315
2442
|
"rotation",
|
|
2443
|
+
"thumbnailFileId",
|
|
2444
|
+
"previewFileId",
|
|
2445
|
+
"preview",
|
|
2316
2446
|
],
|
|
2317
2447
|
path: itemPath,
|
|
2318
2448
|
errorFactory,
|
|
@@ -2351,6 +2481,27 @@ const validateTransformItems = ({ items, path, errorFactory }) => {
|
|
|
2351
2481
|
}
|
|
2352
2482
|
|
|
2353
2483
|
if (item.type === "transform") {
|
|
2484
|
+
for (const fieldName of ["thumbnailFileId", "previewFileId"]) {
|
|
2485
|
+
const fileId = item[fieldName];
|
|
2486
|
+
if (fileId !== undefined && !isNonEmptyString(fileId)) {
|
|
2487
|
+
return invalidFromErrorFactory(
|
|
2488
|
+
errorFactory,
|
|
2489
|
+
`${itemPath}.${fieldName} must be a non-empty string when provided`,
|
|
2490
|
+
);
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
{
|
|
2495
|
+
const result = validateTransformPreviewObject({
|
|
2496
|
+
value: item.preview,
|
|
2497
|
+
path: `${itemPath}.preview`,
|
|
2498
|
+
errorFactory,
|
|
2499
|
+
});
|
|
2500
|
+
if (result?.valid === false) {
|
|
2501
|
+
return result;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2354
2505
|
{
|
|
2355
2506
|
const result = validateOptionalUniqueIdArray({
|
|
2356
2507
|
value: item.tagIds,
|
|
@@ -2646,15 +2797,13 @@ const validateVariableEnumMetadata = ({
|
|
|
2646
2797
|
const validateVariableItems = ({ items, path, errorFactory }) => {
|
|
2647
2798
|
for (const [itemId, item] of Object.entries(items)) {
|
|
2648
2799
|
const itemPath = `${path}.${itemId}`;
|
|
2649
|
-
const
|
|
2800
|
+
const itemType = item?.type;
|
|
2801
|
+
const variableType = item?.variableType;
|
|
2650
2802
|
|
|
2651
|
-
if (
|
|
2652
|
-
variableType !== "folder" &&
|
|
2653
|
-
!VARIABLE_TYPE_KEYS.includes(variableType)
|
|
2654
|
-
) {
|
|
2803
|
+
if (itemType !== "folder" && itemType !== "variable") {
|
|
2655
2804
|
return invalidFromErrorFactory(
|
|
2656
2805
|
errorFactory,
|
|
2657
|
-
`${itemPath}.type must be 'folder'
|
|
2806
|
+
`${itemPath}.type must be 'folder' or 'variable'`,
|
|
2658
2807
|
);
|
|
2659
2808
|
}
|
|
2660
2809
|
|
|
@@ -2662,11 +2811,12 @@ const validateVariableItems = ({ items, path, errorFactory }) => {
|
|
|
2662
2811
|
const result = validateAllowedKeys({
|
|
2663
2812
|
value: item,
|
|
2664
2813
|
allowedKeys:
|
|
2665
|
-
|
|
2814
|
+
itemType === "folder"
|
|
2666
2815
|
? ["id", "type", "name", "description"]
|
|
2667
2816
|
: [
|
|
2668
2817
|
"id",
|
|
2669
2818
|
"type",
|
|
2819
|
+
"variableType",
|
|
2670
2820
|
"name",
|
|
2671
2821
|
"description",
|
|
2672
2822
|
"tagIds",
|
|
@@ -2712,7 +2862,14 @@ const validateVariableItems = ({ items, path, errorFactory }) => {
|
|
|
2712
2862
|
);
|
|
2713
2863
|
}
|
|
2714
2864
|
|
|
2715
|
-
if (
|
|
2865
|
+
if (itemType === "variable") {
|
|
2866
|
+
if (!VARIABLE_TYPE_KEYS.includes(variableType)) {
|
|
2867
|
+
return invalidFromErrorFactory(
|
|
2868
|
+
errorFactory,
|
|
2869
|
+
`${itemPath}.variableType must be 'string', 'number', or 'boolean'`,
|
|
2870
|
+
);
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2716
2873
|
{
|
|
2717
2874
|
const result = validateOptionalUniqueIdArray({
|
|
2718
2875
|
value: item.tagIds,
|
|
@@ -4398,7 +4555,7 @@ const applyVariableEnumMetadata = ({ item, data }) => {
|
|
|
4398
4555
|
}
|
|
4399
4556
|
|
|
4400
4557
|
const enumEnabled =
|
|
4401
|
-
item.
|
|
4558
|
+
item.variableType === "string" &&
|
|
4402
4559
|
data.isEnum !== false &&
|
|
4403
4560
|
(data.isEnum === true ||
|
|
4404
4561
|
data.enumValues !== undefined ||
|
|
@@ -4714,6 +4871,78 @@ const validatePreviewObject = ({ value, path, errorFactory }) => {
|
|
|
4714
4871
|
return VALID_RESULT;
|
|
4715
4872
|
};
|
|
4716
4873
|
|
|
4874
|
+
const validateTransformPreviewSlot = ({ value, path, errorFactory }) => {
|
|
4875
|
+
if (value === undefined) {
|
|
4876
|
+
return VALID_RESULT;
|
|
4877
|
+
}
|
|
4878
|
+
|
|
4879
|
+
if (!isPlainObject(value)) {
|
|
4880
|
+
return invalidFromErrorFactory(
|
|
4881
|
+
errorFactory,
|
|
4882
|
+
`${path} must be an object when provided`,
|
|
4883
|
+
);
|
|
4884
|
+
}
|
|
4885
|
+
|
|
4886
|
+
{
|
|
4887
|
+
const result = validateAllowedKeys({
|
|
4888
|
+
value,
|
|
4889
|
+
allowedKeys: ["imageId"],
|
|
4890
|
+
path,
|
|
4891
|
+
errorFactory,
|
|
4892
|
+
});
|
|
4893
|
+
if (result?.valid === false) {
|
|
4894
|
+
return result;
|
|
4895
|
+
}
|
|
4896
|
+
}
|
|
4897
|
+
|
|
4898
|
+
if (value.imageId !== undefined && !isNonEmptyString(value.imageId)) {
|
|
4899
|
+
return invalidFromErrorFactory(
|
|
4900
|
+
errorFactory,
|
|
4901
|
+
`${path}.imageId must be a non-empty string when provided`,
|
|
4902
|
+
);
|
|
4903
|
+
}
|
|
4904
|
+
|
|
4905
|
+
return VALID_RESULT;
|
|
4906
|
+
};
|
|
4907
|
+
|
|
4908
|
+
const validateTransformPreviewObject = ({ value, path, errorFactory }) => {
|
|
4909
|
+
if (value === undefined) {
|
|
4910
|
+
return VALID_RESULT;
|
|
4911
|
+
}
|
|
4912
|
+
|
|
4913
|
+
if (!isPlainObject(value)) {
|
|
4914
|
+
return invalidFromErrorFactory(
|
|
4915
|
+
errorFactory,
|
|
4916
|
+
`${path} must be an object when provided`,
|
|
4917
|
+
);
|
|
4918
|
+
}
|
|
4919
|
+
|
|
4920
|
+
{
|
|
4921
|
+
const result = validateAllowedKeys({
|
|
4922
|
+
value,
|
|
4923
|
+
allowedKeys: ["background", "target"],
|
|
4924
|
+
path,
|
|
4925
|
+
errorFactory,
|
|
4926
|
+
});
|
|
4927
|
+
if (result?.valid === false) {
|
|
4928
|
+
return result;
|
|
4929
|
+
}
|
|
4930
|
+
}
|
|
4931
|
+
|
|
4932
|
+
for (const key of ["background", "target"]) {
|
|
4933
|
+
const result = validateTransformPreviewSlot({
|
|
4934
|
+
value: value[key],
|
|
4935
|
+
path: `${path}.${key}`,
|
|
4936
|
+
errorFactory,
|
|
4937
|
+
});
|
|
4938
|
+
if (result?.valid === false) {
|
|
4939
|
+
return result;
|
|
4940
|
+
}
|
|
4941
|
+
}
|
|
4942
|
+
|
|
4943
|
+
return VALID_RESULT;
|
|
4944
|
+
};
|
|
4945
|
+
|
|
4717
4946
|
const validateLayoutItems = ({ items, path, errorFactory }) => {
|
|
4718
4947
|
for (const [itemId, item] of Object.entries(items)) {
|
|
4719
4948
|
const itemPath = `${path}.${itemId}`;
|
|
@@ -5892,6 +6121,38 @@ const validateAnimationMaskImageReferences = ({
|
|
|
5892
6121
|
return VALID_RESULT;
|
|
5893
6122
|
};
|
|
5894
6123
|
|
|
6124
|
+
const validateTransformPreviewImageReferences = ({
|
|
6125
|
+
state,
|
|
6126
|
+
preview,
|
|
6127
|
+
path,
|
|
6128
|
+
details = {},
|
|
6129
|
+
errorFactory = createPreconditionValidationError,
|
|
6130
|
+
}) => {
|
|
6131
|
+
if (!isPlainObject(preview)) {
|
|
6132
|
+
return VALID_RESULT;
|
|
6133
|
+
}
|
|
6134
|
+
|
|
6135
|
+
for (const slotKey of ["background", "target"]) {
|
|
6136
|
+
const imageId = preview[slotKey]?.imageId;
|
|
6137
|
+
const result = validateImageReference({
|
|
6138
|
+
state,
|
|
6139
|
+
imageId,
|
|
6140
|
+
path: `${path}.${slotKey}.imageId`,
|
|
6141
|
+
details: {
|
|
6142
|
+
...details,
|
|
6143
|
+
slot: slotKey,
|
|
6144
|
+
imageId,
|
|
6145
|
+
},
|
|
6146
|
+
errorFactory,
|
|
6147
|
+
});
|
|
6148
|
+
if (!result.valid) {
|
|
6149
|
+
return result;
|
|
6150
|
+
}
|
|
6151
|
+
}
|
|
6152
|
+
|
|
6153
|
+
return VALID_RESULT;
|
|
6154
|
+
};
|
|
6155
|
+
|
|
5895
6156
|
export const assertInvariants = ({ state }) => {
|
|
5896
6157
|
if (!isPlainObject(state)) {
|
|
5897
6158
|
return invalidInvariant("state must be an object");
|
|
@@ -6401,6 +6662,42 @@ export const assertInvariants = ({ state }) => {
|
|
|
6401
6662
|
continue;
|
|
6402
6663
|
}
|
|
6403
6664
|
|
|
6665
|
+
for (const fieldName of ["thumbnailFileId", "previewFileId"]) {
|
|
6666
|
+
const fileId = transform[fieldName];
|
|
6667
|
+
if (fileId === undefined) {
|
|
6668
|
+
continue;
|
|
6669
|
+
}
|
|
6670
|
+
|
|
6671
|
+
const fileResult = validateFileReference({
|
|
6672
|
+
state,
|
|
6673
|
+
fileId,
|
|
6674
|
+
path: `transform.${fieldName}`,
|
|
6675
|
+
details: {
|
|
6676
|
+
transformId,
|
|
6677
|
+
[fieldName]: fileId,
|
|
6678
|
+
},
|
|
6679
|
+
errorFactory: createInvariantValidationError,
|
|
6680
|
+
});
|
|
6681
|
+
if (!fileResult.valid) {
|
|
6682
|
+
return fileResult;
|
|
6683
|
+
}
|
|
6684
|
+
}
|
|
6685
|
+
|
|
6686
|
+
{
|
|
6687
|
+
const previewResult = validateTransformPreviewImageReferences({
|
|
6688
|
+
state,
|
|
6689
|
+
preview: transform.preview,
|
|
6690
|
+
path: "transform.preview",
|
|
6691
|
+
details: {
|
|
6692
|
+
transformId,
|
|
6693
|
+
},
|
|
6694
|
+
errorFactory: createInvariantValidationError,
|
|
6695
|
+
});
|
|
6696
|
+
if (!previewResult.valid) {
|
|
6697
|
+
return previewResult;
|
|
6698
|
+
}
|
|
6699
|
+
}
|
|
6700
|
+
|
|
6404
6701
|
{
|
|
6405
6702
|
const result = validateTagIdsAgainstScope({
|
|
6406
6703
|
state,
|
|
@@ -7106,6 +7403,8 @@ const runValidateState = ({ state }) => {
|
|
|
7106
7403
|
|
|
7107
7404
|
export const validateState = ({ state }) => runValidateState({ state });
|
|
7108
7405
|
|
|
7406
|
+
export const normalizeState = ({ state }) => normalizeStateCollections(state);
|
|
7407
|
+
|
|
7109
7408
|
const validatePlacementFields = ({ payload, errorFactory }) => {
|
|
7110
7409
|
if (
|
|
7111
7410
|
payload.index !== undefined &&
|
|
@@ -8973,6 +9272,9 @@ const validateTransformCreateData = ({ data, errorFactory }) => {
|
|
|
8973
9272
|
"anchorX",
|
|
8974
9273
|
"anchorY",
|
|
8975
9274
|
"rotation",
|
|
9275
|
+
"thumbnailFileId",
|
|
9276
|
+
"previewFileId",
|
|
9277
|
+
"preview",
|
|
8976
9278
|
],
|
|
8977
9279
|
path: "payload.data",
|
|
8978
9280
|
errorFactory,
|
|
@@ -8997,6 +9299,27 @@ const validateTransformCreateData = ({ data, errorFactory }) => {
|
|
|
8997
9299
|
}
|
|
8998
9300
|
|
|
8999
9301
|
if (data.type === "transform") {
|
|
9302
|
+
for (const fieldName of ["thumbnailFileId", "previewFileId"]) {
|
|
9303
|
+
const fileId = data[fieldName];
|
|
9304
|
+
if (fileId !== undefined && !isNonEmptyString(fileId)) {
|
|
9305
|
+
return invalidFromErrorFactory(
|
|
9306
|
+
errorFactory,
|
|
9307
|
+
`payload.data.${fieldName} must be a non-empty string when provided`,
|
|
9308
|
+
);
|
|
9309
|
+
}
|
|
9310
|
+
}
|
|
9311
|
+
|
|
9312
|
+
{
|
|
9313
|
+
const result = validateTransformPreviewObject({
|
|
9314
|
+
value: data.preview,
|
|
9315
|
+
path: "payload.data.preview",
|
|
9316
|
+
errorFactory,
|
|
9317
|
+
});
|
|
9318
|
+
if (result?.valid === false) {
|
|
9319
|
+
return result;
|
|
9320
|
+
}
|
|
9321
|
+
}
|
|
9322
|
+
|
|
9000
9323
|
{
|
|
9001
9324
|
const result = validateOptionalUniqueIdArray({
|
|
9002
9325
|
value: data.tagIds,
|
|
@@ -9267,6 +9590,9 @@ const validateTransformUpdateData = ({ data, errorFactory }) => {
|
|
|
9267
9590
|
"anchorX",
|
|
9268
9591
|
"anchorY",
|
|
9269
9592
|
"rotation",
|
|
9593
|
+
"thumbnailFileId",
|
|
9594
|
+
"previewFileId",
|
|
9595
|
+
"preview",
|
|
9270
9596
|
],
|
|
9271
9597
|
path: "payload.data",
|
|
9272
9598
|
errorFactory,
|
|
@@ -9297,6 +9623,27 @@ const validateTransformUpdateData = ({ data, errorFactory }) => {
|
|
|
9297
9623
|
);
|
|
9298
9624
|
}
|
|
9299
9625
|
|
|
9626
|
+
for (const fieldName of ["thumbnailFileId", "previewFileId"]) {
|
|
9627
|
+
const fileId = data[fieldName];
|
|
9628
|
+
if (fileId !== undefined && !isNonEmptyString(fileId)) {
|
|
9629
|
+
return invalidFromErrorFactory(
|
|
9630
|
+
errorFactory,
|
|
9631
|
+
`payload.data.${fieldName} must be a non-empty string when provided`,
|
|
9632
|
+
);
|
|
9633
|
+
}
|
|
9634
|
+
}
|
|
9635
|
+
|
|
9636
|
+
{
|
|
9637
|
+
const result = validateTransformPreviewObject({
|
|
9638
|
+
value: data.preview,
|
|
9639
|
+
path: "payload.data.preview",
|
|
9640
|
+
errorFactory,
|
|
9641
|
+
});
|
|
9642
|
+
if (result?.valid === false) {
|
|
9643
|
+
return result;
|
|
9644
|
+
}
|
|
9645
|
+
}
|
|
9646
|
+
|
|
9300
9647
|
{
|
|
9301
9648
|
const result = validateOptionalUniqueIdArray({
|
|
9302
9649
|
value: data.tagIds,
|
|
@@ -9334,10 +9681,10 @@ const validateVariableCreateData = ({ data, errorFactory }) => {
|
|
|
9334
9681
|
);
|
|
9335
9682
|
}
|
|
9336
9683
|
|
|
9337
|
-
if (data.type !== "folder" &&
|
|
9684
|
+
if (data.type !== "folder" && data.type !== "variable") {
|
|
9338
9685
|
return invalidFromErrorFactory(
|
|
9339
9686
|
errorFactory,
|
|
9340
|
-
"payload.data.type must be 'folder'
|
|
9687
|
+
"payload.data.type must be 'folder' or 'variable'",
|
|
9341
9688
|
);
|
|
9342
9689
|
}
|
|
9343
9690
|
|
|
@@ -9349,6 +9696,7 @@ const validateVariableCreateData = ({ data, errorFactory }) => {
|
|
|
9349
9696
|
? ["type", "name", "description"]
|
|
9350
9697
|
: [
|
|
9351
9698
|
"type",
|
|
9699
|
+
"variableType",
|
|
9352
9700
|
"name",
|
|
9353
9701
|
"description",
|
|
9354
9702
|
"tagIds",
|
|
@@ -9380,7 +9728,14 @@ const validateVariableCreateData = ({ data, errorFactory }) => {
|
|
|
9380
9728
|
);
|
|
9381
9729
|
}
|
|
9382
9730
|
|
|
9383
|
-
if (data.type
|
|
9731
|
+
if (data.type === "variable") {
|
|
9732
|
+
if (!VARIABLE_TYPE_KEYS.includes(data.variableType)) {
|
|
9733
|
+
return invalidFromErrorFactory(
|
|
9734
|
+
errorFactory,
|
|
9735
|
+
"payload.data.variableType must be 'string', 'number', or 'boolean'",
|
|
9736
|
+
);
|
|
9737
|
+
}
|
|
9738
|
+
|
|
9384
9739
|
{
|
|
9385
9740
|
const result = validateOptionalUniqueIdArray({
|
|
9386
9741
|
value: data.tagIds,
|
|
@@ -9396,7 +9751,7 @@ const validateVariableCreateData = ({ data, errorFactory }) => {
|
|
|
9396
9751
|
{
|
|
9397
9752
|
const result = validateVariableEnumMetadata({
|
|
9398
9753
|
data,
|
|
9399
|
-
variableType: data.
|
|
9754
|
+
variableType: data.variableType,
|
|
9400
9755
|
path: "payload.data",
|
|
9401
9756
|
errorFactory,
|
|
9402
9757
|
});
|
|
@@ -9415,7 +9770,7 @@ const validateVariableCreateData = ({ data, errorFactory }) => {
|
|
|
9415
9770
|
{
|
|
9416
9771
|
const result = validateVariableTypedValue({
|
|
9417
9772
|
value: data.default,
|
|
9418
|
-
variableType: data.
|
|
9773
|
+
variableType: data.variableType,
|
|
9419
9774
|
path: "payload.data.default",
|
|
9420
9775
|
errorFactory,
|
|
9421
9776
|
});
|
|
@@ -9426,7 +9781,7 @@ const validateVariableCreateData = ({ data, errorFactory }) => {
|
|
|
9426
9781
|
{
|
|
9427
9782
|
const result = validateVariableTypedValue({
|
|
9428
9783
|
value: data.value,
|
|
9429
|
-
variableType: data.
|
|
9784
|
+
variableType: data.variableType,
|
|
9430
9785
|
path: "payload.data.value",
|
|
9431
9786
|
errorFactory,
|
|
9432
9787
|
});
|
|
@@ -11610,6 +11965,24 @@ const findReferencedFileUsage = ({ state, fileId }) => {
|
|
|
11610
11965
|
}
|
|
11611
11966
|
}
|
|
11612
11967
|
|
|
11968
|
+
for (const [transformId, transform] of Object.entries(
|
|
11969
|
+
state.transforms.items,
|
|
11970
|
+
)) {
|
|
11971
|
+
if (transform.type !== "transform") {
|
|
11972
|
+
continue;
|
|
11973
|
+
}
|
|
11974
|
+
|
|
11975
|
+
for (const fieldName of ["thumbnailFileId", "previewFileId"]) {
|
|
11976
|
+
if (transform[fieldName] === fileId) {
|
|
11977
|
+
return {
|
|
11978
|
+
kind: "transform",
|
|
11979
|
+
field: fieldName,
|
|
11980
|
+
ownerId: transformId,
|
|
11981
|
+
};
|
|
11982
|
+
}
|
|
11983
|
+
}
|
|
11984
|
+
}
|
|
11985
|
+
|
|
11613
11986
|
for (const [characterId, character] of Object.entries(
|
|
11614
11987
|
state.characters.items,
|
|
11615
11988
|
)) {
|
|
@@ -15911,6 +16284,15 @@ const COMMAND_DEFINITIONS = [
|
|
|
15911
16284
|
target: item,
|
|
15912
16285
|
tagIds: payload.data.tagIds,
|
|
15913
16286
|
});
|
|
16287
|
+
if (payload.data.thumbnailFileId !== undefined) {
|
|
16288
|
+
item.thumbnailFileId = payload.data.thumbnailFileId;
|
|
16289
|
+
}
|
|
16290
|
+
if (payload.data.previewFileId !== undefined) {
|
|
16291
|
+
item.previewFileId = payload.data.previewFileId;
|
|
16292
|
+
}
|
|
16293
|
+
if (payload.data.preview !== undefined) {
|
|
16294
|
+
item.preview = structuredClone(payload.data.preview);
|
|
16295
|
+
}
|
|
15914
16296
|
|
|
15915
16297
|
return item;
|
|
15916
16298
|
},
|
|
@@ -15924,6 +16306,30 @@ const COMMAND_DEFINITIONS = [
|
|
|
15924
16306
|
return;
|
|
15925
16307
|
}
|
|
15926
16308
|
|
|
16309
|
+
const fileResult = validateReferencedFilesInData({
|
|
16310
|
+
state,
|
|
16311
|
+
data: payload.data,
|
|
16312
|
+
fields: ["thumbnailFileId", "previewFileId"],
|
|
16313
|
+
details: {
|
|
16314
|
+
transformId: payload.transformId,
|
|
16315
|
+
},
|
|
16316
|
+
});
|
|
16317
|
+
if (!fileResult.valid) {
|
|
16318
|
+
return fileResult;
|
|
16319
|
+
}
|
|
16320
|
+
|
|
16321
|
+
const previewResult = validateTransformPreviewImageReferences({
|
|
16322
|
+
state,
|
|
16323
|
+
preview: payload.data.preview,
|
|
16324
|
+
path: "payload.data.preview",
|
|
16325
|
+
details: {
|
|
16326
|
+
transformId: payload.transformId,
|
|
16327
|
+
},
|
|
16328
|
+
});
|
|
16329
|
+
if (!previewResult.valid) {
|
|
16330
|
+
return previewResult;
|
|
16331
|
+
}
|
|
16332
|
+
|
|
15927
16333
|
return validateTagIdsAgainstScope({
|
|
15928
16334
|
state,
|
|
15929
16335
|
tagIds: payload.data.tagIds,
|
|
@@ -15947,6 +16353,30 @@ const COMMAND_DEFINITIONS = [
|
|
|
15947
16353
|
}
|
|
15948
16354
|
|
|
15949
16355
|
if (currentItem.type === "transform") {
|
|
16356
|
+
const fileResult = validateReferencedFilesInData({
|
|
16357
|
+
state,
|
|
16358
|
+
data: payload.data,
|
|
16359
|
+
fields: ["thumbnailFileId", "previewFileId"],
|
|
16360
|
+
details: {
|
|
16361
|
+
transformId: payload.transformId,
|
|
16362
|
+
},
|
|
16363
|
+
});
|
|
16364
|
+
if (!fileResult.valid) {
|
|
16365
|
+
return fileResult;
|
|
16366
|
+
}
|
|
16367
|
+
|
|
16368
|
+
const previewResult = validateTransformPreviewImageReferences({
|
|
16369
|
+
state,
|
|
16370
|
+
preview: payload.data.preview,
|
|
16371
|
+
path: "payload.data.preview",
|
|
16372
|
+
details: {
|
|
16373
|
+
transformId: payload.transformId,
|
|
16374
|
+
},
|
|
16375
|
+
});
|
|
16376
|
+
if (!previewResult.valid) {
|
|
16377
|
+
return previewResult;
|
|
16378
|
+
}
|
|
16379
|
+
|
|
15950
16380
|
return validateTagIdsAgainstScope({
|
|
15951
16381
|
state,
|
|
15952
16382
|
tagIds: payload.data.tagIds,
|
|
@@ -16013,7 +16443,7 @@ const COMMAND_DEFINITIONS = [
|
|
|
16013
16443
|
}
|
|
16014
16444
|
|
|
16015
16445
|
if (
|
|
16016
|
-
currentItem.
|
|
16446
|
+
currentItem.variableType !== "string" &&
|
|
16017
16447
|
(payload.data.isEnum !== undefined ||
|
|
16018
16448
|
payload.data.enumValues !== undefined)
|
|
16019
16449
|
) {
|
|
@@ -16042,7 +16472,7 @@ const COMMAND_DEFINITIONS = [
|
|
|
16042
16472
|
{
|
|
16043
16473
|
const result = validateVariableTypedValue({
|
|
16044
16474
|
value: payload.data.default,
|
|
16045
|
-
variableType: currentItem.
|
|
16475
|
+
variableType: currentItem.variableType,
|
|
16046
16476
|
path: "payload.data.default",
|
|
16047
16477
|
errorFactory: createPreconditionValidationError,
|
|
16048
16478
|
});
|
|
@@ -16056,7 +16486,7 @@ const COMMAND_DEFINITIONS = [
|
|
|
16056
16486
|
{
|
|
16057
16487
|
const result = validateVariableTypedValue({
|
|
16058
16488
|
value: payload.data.value,
|
|
16059
|
-
variableType: currentItem.
|
|
16489
|
+
variableType: currentItem.variableType,
|
|
16060
16490
|
path: "payload.data.value",
|
|
16061
16491
|
errorFactory: createPreconditionValidationError,
|
|
16062
16492
|
});
|