@routevn/creator-model 1.0.4 → 1.0.5
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/model.js +6 -85
package/package.json
CHANGED
package/src/model.js
CHANGED
|
@@ -52,33 +52,6 @@ const normalizeStateCollections = (state) => {
|
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
54
|
const isString = (value) => typeof value === "string";
|
|
55
|
-
const FILE_ITEM_TYPES = [
|
|
56
|
-
"image",
|
|
57
|
-
"image-thumbnail",
|
|
58
|
-
"audio",
|
|
59
|
-
"audio-waveform",
|
|
60
|
-
"video",
|
|
61
|
-
"video-thumbnail",
|
|
62
|
-
"font",
|
|
63
|
-
];
|
|
64
|
-
const IMAGE_FILE_REFERENCE_TYPES = {
|
|
65
|
-
fileId: ["image"],
|
|
66
|
-
thumbnailFileId: ["image-thumbnail"],
|
|
67
|
-
};
|
|
68
|
-
const SOUND_FILE_REFERENCE_TYPES = {
|
|
69
|
-
fileId: ["audio"],
|
|
70
|
-
waveformDataFileId: ["audio-waveform"],
|
|
71
|
-
};
|
|
72
|
-
const VIDEO_FILE_REFERENCE_TYPES = {
|
|
73
|
-
fileId: ["video"],
|
|
74
|
-
thumbnailFileId: ["video-thumbnail"],
|
|
75
|
-
};
|
|
76
|
-
const FONT_FILE_REFERENCE_TYPES = {
|
|
77
|
-
fileId: ["font"],
|
|
78
|
-
};
|
|
79
|
-
const CHARACTER_FILE_REFERENCE_TYPES = {
|
|
80
|
-
fileId: ["image"],
|
|
81
|
-
};
|
|
82
55
|
const isHexColor = (value) =>
|
|
83
56
|
typeof value === "string" && /^#[0-9a-fA-F]{6}$/.test(value);
|
|
84
57
|
const LIVE_TWEEN_PROPERTY_KEYS = [
|
|
@@ -581,10 +554,10 @@ const validateFileItems = ({ items, path, errorFactory }) => {
|
|
|
581
554
|
for (const [itemId, item] of Object.entries(items)) {
|
|
582
555
|
const itemPath = `${path}.${itemId}`;
|
|
583
556
|
|
|
584
|
-
if (item?.type !==
|
|
557
|
+
if (item?.type !== undefined && !isNonEmptyString(item.type)) {
|
|
585
558
|
return invalidFromErrorFactory(
|
|
586
559
|
errorFactory,
|
|
587
|
-
`${itemPath}.type must be
|
|
560
|
+
`${itemPath}.type must be a non-empty string when provided`,
|
|
588
561
|
);
|
|
589
562
|
}
|
|
590
563
|
|
|
@@ -3493,7 +3466,6 @@ const validateFileReference = ({
|
|
|
3493
3466
|
state,
|
|
3494
3467
|
fileId,
|
|
3495
3468
|
path,
|
|
3496
|
-
allowedTypes,
|
|
3497
3469
|
details = {},
|
|
3498
3470
|
errorFactory = createPreconditionValidationError,
|
|
3499
3471
|
}) => {
|
|
@@ -3501,36 +3473,10 @@ const validateFileReference = ({
|
|
|
3501
3473
|
return VALID_RESULT;
|
|
3502
3474
|
}
|
|
3503
3475
|
|
|
3504
|
-
const expectedTypeMessage =
|
|
3505
|
-
Array.isArray(allowedTypes) && allowedTypes.length > 0
|
|
3506
|
-
? `${path} must reference an existing non-folder file with type ${allowedTypes
|
|
3507
|
-
.map((type) => `'${type}'`)
|
|
3508
|
-
.join(" or ")}`
|
|
3509
|
-
: `${path} must reference an existing non-folder file`;
|
|
3476
|
+
const expectedTypeMessage = `${path} must reference an existing non-folder file`;
|
|
3510
3477
|
const file = state.files?.items?.[fileId];
|
|
3511
3478
|
if (!isPlainObject(file) || file.type === "folder") {
|
|
3512
|
-
return invalidFromErrorFactory(
|
|
3513
|
-
errorFactory,
|
|
3514
|
-
expectedTypeMessage,
|
|
3515
|
-
Array.isArray(allowedTypes) && allowedTypes.length > 0
|
|
3516
|
-
? {
|
|
3517
|
-
...details,
|
|
3518
|
-
expectedFileTypes: [...allowedTypes],
|
|
3519
|
-
}
|
|
3520
|
-
: details,
|
|
3521
|
-
);
|
|
3522
|
-
}
|
|
3523
|
-
|
|
3524
|
-
if (
|
|
3525
|
-
Array.isArray(allowedTypes) &&
|
|
3526
|
-
allowedTypes.length > 0 &&
|
|
3527
|
-
!allowedTypes.includes(file.type)
|
|
3528
|
-
) {
|
|
3529
|
-
return invalidFromErrorFactory(errorFactory, expectedTypeMessage, {
|
|
3530
|
-
...details,
|
|
3531
|
-
expectedFileTypes: [...allowedTypes],
|
|
3532
|
-
actualFileType: file.type,
|
|
3533
|
-
});
|
|
3479
|
+
return invalidFromErrorFactory(errorFactory, expectedTypeMessage, details);
|
|
3534
3480
|
}
|
|
3535
3481
|
|
|
3536
3482
|
return VALID_RESULT;
|
|
@@ -3659,7 +3605,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3659
3605
|
state,
|
|
3660
3606
|
fileId: image.fileId,
|
|
3661
3607
|
path: "image.fileId",
|
|
3662
|
-
allowedTypes: IMAGE_FILE_REFERENCE_TYPES.fileId,
|
|
3663
3608
|
details: { imageId, fileId: image.fileId },
|
|
3664
3609
|
errorFactory: createInvariantValidationError,
|
|
3665
3610
|
});
|
|
@@ -3673,7 +3618,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3673
3618
|
state,
|
|
3674
3619
|
fileId: image.thumbnailFileId,
|
|
3675
3620
|
path: "image.thumbnailFileId",
|
|
3676
|
-
allowedTypes: IMAGE_FILE_REFERENCE_TYPES.thumbnailFileId,
|
|
3677
3621
|
details: { imageId, thumbnailFileId: image.thumbnailFileId },
|
|
3678
3622
|
errorFactory: createInvariantValidationError,
|
|
3679
3623
|
});
|
|
@@ -3693,7 +3637,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3693
3637
|
state,
|
|
3694
3638
|
fileId: sound.fileId,
|
|
3695
3639
|
path: "sound.fileId",
|
|
3696
|
-
allowedTypes: SOUND_FILE_REFERENCE_TYPES.fileId,
|
|
3697
3640
|
details: { soundId, fileId: sound.fileId },
|
|
3698
3641
|
errorFactory: createInvariantValidationError,
|
|
3699
3642
|
});
|
|
@@ -3710,7 +3653,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3710
3653
|
state,
|
|
3711
3654
|
fileId: sound.waveformDataFileId,
|
|
3712
3655
|
path: "sound.waveformDataFileId",
|
|
3713
|
-
allowedTypes: SOUND_FILE_REFERENCE_TYPES.waveformDataFileId,
|
|
3714
3656
|
details: { soundId, waveformDataFileId: sound.waveformDataFileId },
|
|
3715
3657
|
errorFactory: createInvariantValidationError,
|
|
3716
3658
|
});
|
|
@@ -3730,7 +3672,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3730
3672
|
state,
|
|
3731
3673
|
fileId: video.fileId,
|
|
3732
3674
|
path: "video.fileId",
|
|
3733
|
-
allowedTypes: VIDEO_FILE_REFERENCE_TYPES.fileId,
|
|
3734
3675
|
details: { videoId, fileId: video.fileId },
|
|
3735
3676
|
errorFactory: createInvariantValidationError,
|
|
3736
3677
|
});
|
|
@@ -3744,7 +3685,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3744
3685
|
state,
|
|
3745
3686
|
fileId: video.thumbnailFileId,
|
|
3746
3687
|
path: "video.thumbnailFileId",
|
|
3747
|
-
allowedTypes: VIDEO_FILE_REFERENCE_TYPES.thumbnailFileId,
|
|
3748
3688
|
details: { videoId, thumbnailFileId: video.thumbnailFileId },
|
|
3749
3689
|
errorFactory: createInvariantValidationError,
|
|
3750
3690
|
});
|
|
@@ -3763,7 +3703,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3763
3703
|
state,
|
|
3764
3704
|
fileId: font.fileId,
|
|
3765
3705
|
path: "font.fileId",
|
|
3766
|
-
allowedTypes: FONT_FILE_REFERENCE_TYPES.fileId,
|
|
3767
3706
|
details: { fontId, fileId: font.fileId },
|
|
3768
3707
|
errorFactory: createInvariantValidationError,
|
|
3769
3708
|
});
|
|
@@ -3784,7 +3723,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3784
3723
|
state,
|
|
3785
3724
|
fileId: character.fileId,
|
|
3786
3725
|
path: "character.fileId",
|
|
3787
|
-
allowedTypes: CHARACTER_FILE_REFERENCE_TYPES.fileId,
|
|
3788
3726
|
details: { characterId, fileId: character.fileId },
|
|
3789
3727
|
errorFactory: createInvariantValidationError,
|
|
3790
3728
|
});
|
|
@@ -3804,7 +3742,6 @@ export const assertInvariants = ({ state }) => {
|
|
|
3804
3742
|
state,
|
|
3805
3743
|
fileId: sprite.fileId,
|
|
3806
3744
|
path: "character.sprite.fileId",
|
|
3807
|
-
allowedTypes: CHARACTER_FILE_REFERENCE_TYPES.fileId,
|
|
3808
3745
|
details: { characterId, spriteId, fileId: sprite.fileId },
|
|
3809
3746
|
errorFactory: createInvariantValidationError,
|
|
3810
3747
|
});
|
|
@@ -5060,10 +4997,10 @@ const validateFileCreateData = ({ data, errorFactory }) => {
|
|
|
5060
4997
|
);
|
|
5061
4998
|
}
|
|
5062
4999
|
|
|
5063
|
-
if (data.type !==
|
|
5000
|
+
if (data.type !== undefined && !isNonEmptyString(data.type)) {
|
|
5064
5001
|
return invalidFromErrorFactory(
|
|
5065
5002
|
errorFactory,
|
|
5066
|
-
"payload.data.type must be
|
|
5003
|
+
"payload.data.type must be a non-empty string when provided",
|
|
5067
5004
|
);
|
|
5068
5005
|
}
|
|
5069
5006
|
|
|
@@ -5118,7 +5055,6 @@ const validateReferencedFilesInData = ({
|
|
|
5118
5055
|
state,
|
|
5119
5056
|
data,
|
|
5120
5057
|
fields,
|
|
5121
|
-
fieldTypes = {},
|
|
5122
5058
|
nullableFields = [],
|
|
5123
5059
|
details = {},
|
|
5124
5060
|
errorFactory = createPreconditionValidationError,
|
|
@@ -5138,7 +5074,6 @@ const validateReferencedFilesInData = ({
|
|
|
5138
5074
|
state,
|
|
5139
5075
|
fileId,
|
|
5140
5076
|
path: `payload.data.${field}`,
|
|
5141
|
-
allowedTypes: fieldTypes[field],
|
|
5142
5077
|
details: {
|
|
5143
5078
|
...details,
|
|
5144
5079
|
field,
|
|
@@ -7198,7 +7133,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
7198
7133
|
}
|
|
7199
7134
|
: {
|
|
7200
7135
|
id: payload.fileId,
|
|
7201
|
-
type: payload.data.type,
|
|
7202
7136
|
mimeType: payload.data.mimeType,
|
|
7203
7137
|
size: payload.data.size,
|
|
7204
7138
|
sha256: payload.data.sha256,
|
|
@@ -8548,7 +8482,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
8548
8482
|
state,
|
|
8549
8483
|
data: payload.data,
|
|
8550
8484
|
fields: ["fileId", "thumbnailFileId"],
|
|
8551
|
-
fieldTypes: IMAGE_FILE_REFERENCE_TYPES,
|
|
8552
8485
|
details: {
|
|
8553
8486
|
imageId: payload.imageId,
|
|
8554
8487
|
},
|
|
@@ -8661,7 +8594,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
8661
8594
|
state,
|
|
8662
8595
|
data: payload.data,
|
|
8663
8596
|
fields: ["fileId", "thumbnailFileId"],
|
|
8664
|
-
fieldTypes: IMAGE_FILE_REFERENCE_TYPES,
|
|
8665
8597
|
details: {
|
|
8666
8598
|
imageId: payload.imageId,
|
|
8667
8599
|
},
|
|
@@ -8974,7 +8906,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
8974
8906
|
state,
|
|
8975
8907
|
data: payload.data,
|
|
8976
8908
|
fields: ["fileId", "waveformDataFileId"],
|
|
8977
|
-
fieldTypes: SOUND_FILE_REFERENCE_TYPES,
|
|
8978
8909
|
nullableFields: ["waveformDataFileId"],
|
|
8979
8910
|
details: {
|
|
8980
8911
|
soundId: payload.soundId,
|
|
@@ -9084,7 +9015,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
9084
9015
|
state,
|
|
9085
9016
|
data: payload.data,
|
|
9086
9017
|
fields: ["fileId", "waveformDataFileId"],
|
|
9087
|
-
fieldTypes: SOUND_FILE_REFERENCE_TYPES,
|
|
9088
9018
|
nullableFields: ["waveformDataFileId"],
|
|
9089
9019
|
details: {
|
|
9090
9020
|
soundId: payload.soundId,
|
|
@@ -9398,7 +9328,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
9398
9328
|
state,
|
|
9399
9329
|
data: payload.data,
|
|
9400
9330
|
fields: ["fileId", "thumbnailFileId"],
|
|
9401
|
-
fieldTypes: VIDEO_FILE_REFERENCE_TYPES,
|
|
9402
9331
|
details: {
|
|
9403
9332
|
videoId: payload.videoId,
|
|
9404
9333
|
},
|
|
@@ -9509,7 +9438,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
9509
9438
|
state,
|
|
9510
9439
|
data: payload.data,
|
|
9511
9440
|
fields: ["fileId", "thumbnailFileId"],
|
|
9512
|
-
fieldTypes: VIDEO_FILE_REFERENCE_TYPES,
|
|
9513
9441
|
details: {
|
|
9514
9442
|
videoId: payload.videoId,
|
|
9515
9443
|
},
|
|
@@ -10196,7 +10124,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
10196
10124
|
state,
|
|
10197
10125
|
data: payload.data,
|
|
10198
10126
|
fields: ["fileId"],
|
|
10199
|
-
fieldTypes: FONT_FILE_REFERENCE_TYPES,
|
|
10200
10127
|
details: {
|
|
10201
10128
|
fontId: payload.fontId,
|
|
10202
10129
|
},
|
|
@@ -10295,7 +10222,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
10295
10222
|
state,
|
|
10296
10223
|
data: payload.data,
|
|
10297
10224
|
fields: ["fileId"],
|
|
10298
|
-
fieldTypes: FONT_FILE_REFERENCE_TYPES,
|
|
10299
10225
|
details: {
|
|
10300
10226
|
fontId: payload.fontId,
|
|
10301
10227
|
},
|
|
@@ -11081,7 +11007,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
11081
11007
|
state,
|
|
11082
11008
|
data: payload.data,
|
|
11083
11009
|
fields: ["fileId"],
|
|
11084
|
-
fieldTypes: CHARACTER_FILE_REFERENCE_TYPES,
|
|
11085
11010
|
details: {
|
|
11086
11011
|
characterId: payload.characterId,
|
|
11087
11012
|
},
|
|
@@ -11102,7 +11027,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
11102
11027
|
state,
|
|
11103
11028
|
fileId: sprite.fileId,
|
|
11104
11029
|
path: "payload.data.sprites.items.*.fileId",
|
|
11105
|
-
allowedTypes: CHARACTER_FILE_REFERENCE_TYPES.fileId,
|
|
11106
11030
|
details: {
|
|
11107
11031
|
characterId: payload.characterId,
|
|
11108
11032
|
spriteId,
|
|
@@ -11129,7 +11053,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
11129
11053
|
state,
|
|
11130
11054
|
data: payload.data,
|
|
11131
11055
|
fields: ["fileId"],
|
|
11132
|
-
fieldTypes: CHARACTER_FILE_REFERENCE_TYPES,
|
|
11133
11056
|
details: {
|
|
11134
11057
|
characterId: payload.characterId,
|
|
11135
11058
|
},
|
|
@@ -11314,7 +11237,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
11314
11237
|
state,
|
|
11315
11238
|
data: payload.data,
|
|
11316
11239
|
fields: ["fileId"],
|
|
11317
|
-
fieldTypes: CHARACTER_FILE_REFERENCE_TYPES,
|
|
11318
11240
|
details: {
|
|
11319
11241
|
characterId: payload.characterId,
|
|
11320
11242
|
spriteId: payload.spriteId,
|
|
@@ -11418,7 +11340,6 @@ const COMMAND_DEFINITIONS = [
|
|
|
11418
11340
|
state,
|
|
11419
11341
|
data: payload.data,
|
|
11420
11342
|
fields: ["fileId"],
|
|
11421
|
-
fieldTypes: CHARACTER_FILE_REFERENCE_TYPES,
|
|
11422
11343
|
details: {
|
|
11423
11344
|
characterId: payload.characterId,
|
|
11424
11345
|
spriteId: payload.spriteId,
|