All files / ext.wikilambda.app/store/stores library.js

98.35% Statements 1198/1218
95.87% Branches 209/218
96.55% Functions 56/58
98.35% Lines 1198/1218

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 261x 261x 261x 261x 261x 906x 906x 896x 896x 895x 895x 896x 11x 261x 261x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 277x 277x 277x 277x 277x 257x 257x 257x 18x 18x 239x 239x 239x 257x 277x 277x 103x 103x 103x 103x 103x 103x 103x 103x 103x 151x 151x 151x 151x 151x 249x 249x 249x 1x 1x 248x 249x 224x 224x 224x 224x 142x 142x 142x 142x 142x 142x 86x 86x 86x 142x 142x 142x 55x 55x 55x 55x 55x     142x 142x 142x 1x 142x 142x 224x 106x 106x 106x 151x 151x 151x 103x 103x 103x 103x 103x 103x 103x 103x 103x 209x 209x 209x 209x 209x 174x 1x 1x 173x 174x 87x 87x 86x 86x 86x 93x 1x 1x 85x 85x 93x 40x 40x 45x 45x 93x 1x 1x 44x 44x 50x 41x 41x 3x 3x 10x 2x 174x 209x 209x 103x 103x 103x 103x 103x 103x 103x 103x 348x 348x 348x 348x 348x 273x 273x 273x 273x 273x 273x 205x 273x 87x 87x 186x 186x 186x 186x 273x 3x 3x 183x 183x 263x 283x 283x 3x 1x 283x 3x 3x 283x 180x 348x 348x 103x 103x 103x 103x 103x 103x 103x 103x 342x 342x 342x 342x 342x 409x 409x 409x 409x 409x 408x 409x 169x 169x 240x 240x 240x 240x 409x 1x 409x 342x 342x 103x 103x 103x 103x 103x 103x 103x 103x 103x 301x 301x 301x 301x 301x 4x 4x 4x 3x 4x 2x 2x 2x 301x 301x 103x 103x 103x 103x 103x 103x 103x 103x 103x 300x 300x 300x 300x 300x 3x 3x 3x 2x 3x 2x 2x 1x 300x 300x 103x 103x 103x 103x 103x 103x 103x 103x 299x 299x 299x 299x 299x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 299x 299x 299x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 391x 391x 391x 391x 391x 391x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 362x 362x 362x 362x 362x 2200x 2200x 362x 362x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 281x 281x 281x 281x 281x     281x 281x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 61x 61x 61x 61x 61x 928x 928x 1x 1x 927x 927x 927x 928x 49x 49x 878x 878x 878x 878x 61x 61x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 310x 310x 310x 310x 310x 310x 29x 29x 16x 16x 16x 13x 310x 310x 103x 103x 103x 103x 103x 103x 103x 103x 103x 300x 300x 300x 300x 300x 3x 3x 3x 3x 300x 300x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 306x 306x 306x 306x 306x 55x 55x 1x 1x 54x 55x 26x 26x 55x     29x 27x 27x 1x 306x 306x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 304x 304x 304x 304x 304x 27x 27x     27x 27x 27x 27x 27x 27x 27x 27x 27x 27x         27x 27x 27x   304x 304x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 289x 289x 289x 289x 289x 39x 39x 1x 1x 38x 39x 1x 1x 37x 37x 289x 289x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 297x 297x 297x 297x 297x 297x 6x 6x 6x 6x 6x 6x 4x 4x 3x 3x 3x 3x 1x 1x 2x 2x 2x 2x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 3x 3x 297x 297x 103x 103x 103x 103x 103x 103x 103x 103x 103x 297x 297x 297x 297x 297x 297x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 300x 300x 300x 300x 300x 3x 3x 1x 1x 1x 2x 3x 1x 1x 1x 3x       1x 1x 1x 1x 1x 1x 1x 1x 1x 300x 300x 103x 103x 103x 103x 103x 103x 103x 103x 103x 300x 300x 300x 300x 300x 3x 3x 1x 1x 2x 3x 1x 1x 1x 300x 300x 300x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 1270x 635x 635x 635x 635x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 525x 525x 501x 501x 103x 103x 103x 103x 103x 103x 103x 103x 103x 1287x 103x 103x 103x 103x 103x 103x 103x 103x 103x 3x 3x 3x 3x 3x 3x 1x 1x 1x 2x 2x 3x 1x 1x 2x 2x 2x 2x 103x 103x 103x 103x 103x 103x 103x 103x 129x 103x 103x 103x 103x 103x 103x 5x 5x 5x 5x 5x 5x 5x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 27x 27x 27x 27x 27x 26x 27x 27x 27x 27x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 2x 2x 2x 2x 1x 1x 1x 2x   2x 2x 2x 1x 1x 1x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 2x 4x 2x 2x 4x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 744x 744x 744x 744x 744x 744x 744x 1904x 1904x 1904x 1904x 1904x 1904x 1904x 983x 1904x 680x 680x 1904x 1904x 1904x 519x 519x 744x 744x 744x 744x 744x 744x 744x 744x 91x 91x 744x 744x 744x 91x 91x 91x 635x 91x 91x 91x 91x 635x 91x 91x 91x 91x 744x 744x 744x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 89x 89x 89x 89x 89x 89x 89x 89x 89x 89x 89x 526x 526x 526x 526x 526x 526x 526x 526x 526x 526x 526x 526x     526x 526x 526x 526x 526x 526x 526x 526x 526x 526x 526x 523x 523x 523x 523x 523x 523x 523x 523x 526x 526x 526x 526x 526x 526x 526x 526x 526x 526x 526x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 526x 526x 295x 295x 295x 295x 295x 719x 719x 719x 719x 719x 719x 719x 719x 719x 719x 719x 719x 719x 295x 295x 295x 295x 295x 2x 2x 2x 2x 295x 2x 2x 2x 2x 295x 526x 526x 38x 38x 38x 38x 38x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 38x 38x 526x 526x 129x 129x 129x 129x 129x 129x 129x 526x 526x 526x 526x 526x 526x 526x 89x 89x 89x 89x 89x   89x 89x 103x 103x 103x 103x 103x 103x 103x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 103x 103x  
/*!
 * WikiLambda Vue editor: Pinia store: fetch, store and
 * provide auxiliary data from other ZObjects (labels, keys, etc.).
 * It also contains other helper getters to retrieve details of other
 * stored auxiliary objects such as functions, languages, etc.
 *
 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
 * @license MIT
 */
'use strict';
 
const Constants = require( '../../Constants.js' );
const { searchLabels, searchFunctions, fetchZObjects } = require( '../../utils/apiUtils.js' );
const LabelData = require( '../classes/LabelData.js' );
const { getZObjectType } = require( '../../utils/zobjectUtils.js' );
const {
	isGlobalKey,
	getZidOfGlobalKey,
	getKeyFromKeyList,
	getArgFromArgList,
	isTruthyOrEqual
} = require( '../../utils/typeUtils.js' );
const { hybridToCanonical } = require( '../../utils/schemata.js' );
 
const DEBOUNCE_ZOBJECT_LOOKUP_TIMEOUT = 300;
let debounceZObjectLookup = null;
 
module.exports = {
	state: {
		/**
		 * Collection of ZPersistent objects fetched
		 * and indexed by their ZID.
		 */
		objects: {},
		/**
		 * Collection of LabelData object indexed by the identifier of
		 * the ZKey, ZPersistentObject or ZArgumentDeclaration.
		 */
		labels: {},
		/**
		 * Collection of the requested zids and the resolving promises
		 * zid: promise
		 */
		requests: {},
		/**
		 * Collection of enum types with all their selectable values
		 */
		enums: {},
		/**
		 * Map of the available language zids in the store indexed by language code
		 */
		languages: {}
	},
 
	getters: {
		/**
		 * Returns the string value of the language Iso code if the object
		 * has been fetched and is stored in the state.
		 * If not available, returns the input zid.
		 *
		 * @return {Function}
		 */
		getLanguageIsoCodeOfZLang: function () {
			/**
			 * @param {string} zid
			 * @return {string}
			 */
			const findLanguageIsoCode = ( zid ) => {
				const storedObject = this.getStoredObject( zid );
				if ( storedObject ) {
					const zobject = storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ];
					if ( zobject[ Constants.Z_OBJECT_TYPE ] === Constants.Z_NATURAL_LANGUAGE ) {
						return zobject[ Constants.Z_NATURAL_LANGUAGE_ISO_CODE ];
					}
				}
				return zid;
			};
			return findLanguageIsoCode;
		},
 
		/**
		 * Returns the language zid given a language Iso code if the
		 * object has been fetched and is stored in the state.
		 * If not available, falls back to server-side language mapping.
		 *
		 * @param {Object} state
		 * @return {Function}
		 */
		getLanguageZidOfCode: function ( state ) {
			/**
			 * @param {string} code
			 * @return {string|undefined}
			 */
			const findLanguageZid = ( code ) => {
				// First try to get from store
				const existingZid = state.languages[ code ];
				if ( existingZid ) {
					return existingZid;
				}
 
				// Fall back to server-side language mapping
				const langMap = mw.config.get( 'wgWikiLambdaLangs', {} );
				return langMap && langMap[ code ];
			};
			return findLanguageZid;
		},
 
		/**
		 * Given a global ZKey (ZnKm) it returns a string that reflects
		 * its expected value type (if any). Else it returns Z1.
		 *
		 * @return {Function}
		 */
		getExpectedTypeOfKey: function () {
			/**
			 * @param {string|undefined} key
			 * @return {string}
			 */
			const findExpectedType = ( key ) => {
				// If the key is undefined, then this is the root object,
				// the expected type is always Z2/Persistent object type
				if ( key === undefined ) {
					return Constants.Z_PERSISTENTOBJECT;
				}
 
				if ( isGlobalKey( key ) ) {
					const zid = getZidOfGlobalKey( key );
					const storedObject = this.getStoredObject( zid );
 
					if ( storedObject ) {
						const zobject = storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ];
						const ztype = zobject[ Constants.Z_OBJECT_TYPE ];
 
						switch ( ztype ) {
							// Return the key value type if zid belongs to a type
							case Constants.Z_TYPE: {
								const zkey = getKeyFromKeyList( key, zobject[ Constants.Z_TYPE_KEYS ] );
								return zkey ? zkey[ Constants.Z_KEY_TYPE ] : Constants.Z_OBJECT;
							}
 
							// Return the argument type if the zid belongs to a function
							case Constants.Z_FUNCTION: {
								const zarg = getArgFromArgList( key, zobject[ Constants.Z_FUNCTION_ARGUMENTS ] );
								if ( zarg ) {
									const type = zarg[ Constants.Z_ARGUMENT_TYPE ];
									return type;
								}
								return Constants.Z_OBJECT;
							}
 
							// If not found, return Z1/ZObject (any) type
							default:
								return Constants.Z_OBJECT;
						}
					}
				}
 
				// If key is not found, a list index, or a local key, return Z1/Object (any) type
				return Constants.Z_OBJECT;
			};
 
			return findExpectedType;
		},
 
		/**
		 * Given a key, returns whether it is set to be an identity key
		 * (Z3K4 field is set to true/Z41)
		 *
		 * @return {Function}
		 */
		isIdentityKey: function () {
			/**
			 * @param {string|undefined} key
			 * @return {boolean}
			 */
			const checkIdentityKey = ( key ) => {
				if ( key === undefined ) {
					return false;
				}
 
				if ( !isGlobalKey( key ) ) {
					return false;
				}
 
				const zid = getZidOfGlobalKey( key );
				const storedObject = this.getStoredObject( zid );
				if ( !storedObject ) {
					return false;
				}
 
				const zobject = storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ];
				if ( zobject[ Constants.Z_OBJECT_TYPE ] !== Constants.Z_TYPE ) {
					return false;
				}
 
				const zkey = getKeyFromKeyList( key, zobject[ Constants.Z_TYPE_KEYS ] );
				if ( !zkey ) {
					return false;
				}
 
				const isIdentity = zkey[ Constants.Z_KEY_IS_IDENTITY ];
				if ( !isIdentity ) {
					return false;
				}
 
				return (
					( isIdentity === Constants.Z_BOOLEAN_TRUE ) ||
					( isIdentity[ Constants.Z_BOOLEAN_IDENTITY ] === Constants.Z_BOOLEAN_TRUE )
				);
			};
			return checkIdentityKey;
		},
 
		/**
		 * Given a type zid, returns whether it has an identity key
		 *
		 * @return {Function}
		 */
		isEnumType: function () {
			/**
			 * @param {string} zid
			 * @return {boolean}
			 */
			const checkEnumType = ( zid ) => {
				const storedObject = this.getStoredObject( zid );
				// If the zid is undefined, excluded from enums or the object is not found,
				// return false
				if (
					( zid === undefined ) ||
					( Constants.EXCLUDE_FROM_ENUMS.includes( zid ) ) ||
					( !storedObject )
				) {
					return false;
				}
 
				const zobject = storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ];
 
				// If the zObject is not a type, return false
				if ( !zobject || zobject[ Constants.Z_OBJECT_TYPE ] !== Constants.Z_TYPE ) {
					return false;
				}
 
				const keys = zobject[ Constants.Z_TYPE_KEYS ].slice( 1 );
				for ( const key of keys ) {
					const isIdentity = key[ Constants.Z_KEY_IS_IDENTITY ];
					if ( isIdentity && (
						( isIdentity === Constants.Z_BOOLEAN_TRUE ) ||
						( isIdentity[ Constants.Z_BOOLEAN_IDENTITY ] === Constants.Z_BOOLEAN_TRUE )
					) ) {
						return true;
					}
				}
				return false;
			};
			return checkEnumType;
		},
 
		/**
		 * Given a type zid, returns whether it is an instance of a Wikidata enum/Z6884
		 *
		 * @return {Function}
		 */
		isWikidataEnum: function () {
			/**
			 * @param {string} zid
			 * @return {boolean}
			 */
			const checkWikidataEnumType = ( zid ) => {
				const storedObject = this.getStoredObject( zid );
				// If the zid is undefined or the object is not found,
				// return false
				if (
					( zid === undefined ) ||
					( !storedObject )
				) {
					return false;
				}
				const zobject = storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ];
				// If the zObject is a function call and it is a Wikidata enum/Z6884, return true
				return (
					zobject &&
					zobject[ Constants.Z_OBJECT_TYPE ] === Constants.Z_FUNCTION_CALL &&
					zobject[ Constants.Z_FUNCTION_CALL_FUNCTION ] === Constants.Z_WIKIDATA_ENUM
				);
			};
			return checkWikidataEnumType;
		},
 
		/**
		 * Returns the values of  an instance of a Wikidata enum/Z6884 given its Zid.
		 * The values are extracted from the references of the enum object.
		 *
		 * @return {Function}
		 */
		getReferencesOfWikidataEnum: function () {
			/**
			 * @param {string} zid - The Zid of the Wikidata enum.
			 * @return {Array|undefined} - An array of values or undefined if not found.
			 */
			const findReferencesOfWikidataEnum = ( zid ) => {
				const storedObject = this.getStoredObject( zid );
				if (
					zid === undefined ||
					!storedObject
				) {
					return undefined;
				}
				return storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_WIKIDATA_ENUM_REFERENCES ];
			};
			return findReferencesOfWikidataEnum;
		},
 
		/**
		 * Returns the type of an instance of a Wikidata enum/Z6884 given its Zid.
		 * The type is determined based on the first value in the enum's references.
		 *
		 * @return {Function}
		 */
		getTypeOfWikidataEnum: function () {
			/**
			 * @param {string} zid - The Zid of the Wikidata enum.
			 * @return {string|undefined} - The type of the Wikidata enum or undefined if not found.
			 */
			const findTypeOfWikidataEnum = ( zid ) => {
				const storedObject = this.getStoredObject( zid );
				if (
					zid === undefined ||
					!storedObject
				) {
					return undefined;
				}
				return storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_WIKIDATA_ENUM_TYPE ];
			};
			return findTypeOfWikidataEnum;
		},
 
		/**
		 * Given a type zid, returns the list of items in an instance of a Wikidata enum/Z6884
		 *
		 * @return {Function}
		 */
		getReferencesIdsOfWikidataEnum: function () {
			/**
			 * @param {string} zid
			 * @return {Array}
			 */
			const findReferencesIdsOfWikidataEnum = ( zid ) => {
				const values = this.getReferencesOfWikidataEnum( zid );
				if ( !values ) {
					return [];
				}
				const type = values[ 0 ];
				return values
					.slice( 1 )
					.map( ( row ) => row[ `${ type }K1` ] )
					.filter( ( id ) => !!id );
 
			};
			return findReferencesIdsOfWikidataEnum;
 
		},
 
		/**
		 * Given a type zid, returns whether it has an identity key,
		 * excluding the builtin enum types (Boolean/Z40), as they
		 * have builtin components that require special cases.
		 *
		 * @return {Function}
		 */
		isCustomEnum: function () {
			/**
			 * @param {string} zid
			 * @return {boolean}
			 */
			const checkCustomEnum = ( zid ) => this.isEnumType( zid ) && !Constants.BUILTIN_ENUMS.includes( zid );
			return checkCustomEnum;
		},
		/**
		 * Returns the persisted object for a given ZID if that was successfully
		 * fetched from the DB and saved in the state. Else returns undefined.
		 *
		 * If the function Zid returned an error (e.g. Zid not found), the
		 * error was stored, but this getter will return undefined.
		 *
		 * @param {Object} state
		 * @return {Function}
		 */
		getStoredObject: function ( state ) {
			/**
			 * @param {string} zid of the ZPersistentObject
			 * @return {Object|undefined} persisted ZObject
			 */
			const findStoredObject = ( zid ) => {
				const objectData = state.objects[ zid ];
				return ( !objectData || !objectData.success ) ? undefined : objectData.data;
			};
			return findStoredObject;
		},
		/**
		 * Returns the object for a given ZID that was fetched using fetchZids.
		 * If the object was not fetched, returns undefined.
		 * If the object was fetched but returned an error (e.g. Zid not found),
		 * returns the error object.
		 *
		 * This getter is specially designed to be used from Visual Editor,
		 * as we need to use the returned error data.
		 *
		 * @param {Object} state
		 * @return {Function}
		 */
		getFetchedObject: function ( state ) {
			/**
			 * @param {string} zid of the ZPersistentObject
			 * @return {Object|undefined} persisted ZObject
			 */
			const findFetchedObject = ( zid ) => {
				const objectData = state.objects[ zid ];
				return objectData || undefined;
			};
			return findFetchedObject;
		},
		/**
		 * Returns the LabelData of the ID of a ZKey, ZPersistentObject or ZArgumentDeclaration.
		 * The label is in the user selected language, if available, or else in the closest fallback.
		 * If not available, returns a new LabelData object with the input zid as the label.
		 *
		 * This getter must make sure that there's always a LabelData object return, so that the
		 * caller components can safely access the LabelData properties.
		 *
		 * @param {Object} state
		 * @return {Function}
		 */
		getLabelData: function ( state ) {
			/**
			 * @param {string} id
			 * @return {LabelData}
			 */
			const findLabelData = ( id ) => {
				// If the requested language is 'qqx', return (zid) as the label
				if ( this.getUserRequestedLang === 'qqx' && id ) {
					return new LabelData( id, `(${ id })`, this.getUserLangZid, this.getUserLangCode );
				}
 
				// If label data is still not present in the library, return zid as the label
				const labelData = state.labels[ id ];
				if ( !labelData ) {
					return new LabelData( id, id, this.getUserLangZid, this.getUserLangCode );
				}
 
				// Enrich label data with language code and directionality
				labelData.setLangCode( this.getLanguageIsoCodeOfZLang( labelData.lang ) );
				return labelData;
			};
			return findLabelData;
		},
 
		/**
		 * Returns the array of implementations or tests connected to a persisted
		 * Function stored in the library, given the Function Zid and the key
		 * identifying the object list (tests or implementations)
		 *
		 * @return {Function}
		 */
		getConnectedObjects: function () {
			/**
			 * @param {string} zid
			 * @param {string} key
			 * @return {Array}
			 */
			const findConnectedObjects = ( zid, key ) => {
				const func = this.getStoredObject( zid );
				if ( func ) {
					const imps = func[ Constants.Z_PERSISTENTOBJECT_VALUE ][ key ];
					return imps ? imps.slice( 1 ) : [];
				}
				return [];
			};
			return findConnectedObjects;
		},
 
		/**
		 * Returns the function zid given an implementation zid
		 * by returning the value in its Z14K1 field
		 *
		 * @return {Function}
		 */
		getFunctionZidOfImplementation: function () {
			/**
			 * @param {string} zid
			 * @return {string|undefined}
			 */
			const findFunctionZid = ( zid ) => {
				const implementation = this.getStoredObject( zid );
				return implementation ?
					implementation[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_IMPLEMENTATION_FUNCTION ] :
					undefined;
			};
			return findFunctionZid;
		},
 
		/**
		 * Returns the type of an implementation stored in the
		 * global state, given its Zid. The type will be
		 * composition/Z14K2, built-in/Z14K4, or code/Z14K3.
		 * If the implementation Zid is unknown returns undefined.
		 *
		 * @return {Function}
		 */
		getTypeOfImplementation: function () {
			/**
			 * @param {string} zid
			 * @return {string | undefined}
			 */
			const findTypeOfImplementation = ( zid ) => {
				const storedObject = this.getStoredObject( zid );
				if ( !storedObject ) {
					return undefined;
				}
				const implementation = storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ];
				if ( Constants.Z_IMPLEMENTATION_COMPOSITION in implementation ) {
					return Constants.Z_IMPLEMENTATION_COMPOSITION;
				}
				if ( Constants.Z_IMPLEMENTATION_BUILT_IN in implementation ) {
					return Constants.Z_IMPLEMENTATION_BUILT_IN;
				}
				if ( Constants.Z_IMPLEMENTATION_CODE in implementation ) {
					return Constants.Z_IMPLEMENTATION_CODE;
				}
				return undefined;
			};
			return findTypeOfImplementation;
		},
 
		/**
		 * Returns the language code of an implementation stored
		 * in the global state, given its Zid. If the implementation
		 * is not of type code (but composition or built-in) returns
		 * undefined.
		 *
		 * @return {Function}
		 */
		getLanguageOfImplementation: function () {
			/**
			 * @param {string} zid
			 * @return {string | undefined}
			 */
			const findLanguageOfImplementation = ( zid ) => {
				const storedObject = this.getStoredObject( zid );
				if ( !storedObject ) {
					return undefined;
				}
				const implementation = storedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ];
				if ( Constants.Z_IMPLEMENTATION_CODE in implementation ) {
					// If code is literal: return literal
					if (
						isTruthyOrEqual( implementation, [
							Constants.Z_IMPLEMENTATION_CODE,
							Constants.Z_CODE_LANGUAGE,
							Constants.Z_PROGRAMMING_LANGUAGE_CODE
						] )
					) {
						return implementation[ Constants.Z_IMPLEMENTATION_CODE ][
							Constants.Z_CODE_LANGUAGE
						][ Constants.Z_PROGRAMMING_LANGUAGE_CODE ];
					}
					// Else, code is reference: return zid
					return implementation[ Constants.Z_IMPLEMENTATION_CODE ][ Constants.Z_CODE_LANGUAGE ];
				}
				return undefined;
			};
			return findLanguageOfImplementation;
		},
 
		/**
		 * Given a function Zid, it inspects its function definition
		 * stored in the state and returns an array of its arguments.
		 * It returns undefined if the function is not available or the
		 * zid does not belong to a valid function.
		 *
		 * @return {Function}
		 */
		getInputsOfFunctionZid: function () {
			/**
			 * @param {string} zid
			 * @return {Array}
			 */
			const findInputsOfFunction = ( zid ) => {
				const func = this.getStoredObject( zid );
				if ( !func ) {
					return [];
				}
				const obj = func[ Constants.Z_PERSISTENTOBJECT_VALUE ];
				if ( obj[ Constants.Z_OBJECT_TYPE ] !== Constants.Z_FUNCTION ) {
					return [];
				}
				// Remove benjamin type item
				return obj[ Constants.Z_FUNCTION_ARGUMENTS ].slice( 1 );
			};
			return findInputsOfFunction;
		},
 
		/**
		 * Returns the values of an enum with a given ZID.
		 * If the request includes a selected Id, check that it appears
		 * in the returned collection, and if not, manually include it
		 * (only if it's the zid of a valid instance of the enum type)
		 *
		 * @param {Object} state
		 * @return {Function}
		 */
		getEnumValues: function ( state ) {
			/**
			 * @param {string} zid
			 * @param {string|undefined} selected
			 * @return {Array}
			 */
			const findEnumValues = ( zid, selected = undefined ) => {
				const enumObj = state.enums[ zid ];
				const enums = enumObj && enumObj.data instanceof Array ? enumObj.data : [];
 
				// If there's a selected item and it is not in the initial enum collection:
				// get the object from the store, check that it's valid, and if so, add to list
				if ( selected ) {
					const selectedIndex = enums.findIndex( ( item ) => item.page_title === selected );
					if ( selectedIndex < 0 ) {
						// Get the object from the store: it will already be fetched
						// If selected zid does not exist: do nothing
						const selectedObject = this.getStoredObject( selected );
						if ( !selectedObject || !( Constants.Z_PERSISTENTOBJECT_VALUE in selectedObject ) ) {
							return enums;
						}
 
						// Get the selected object type.
						// If selected zid is not a valid instance of this enum: do nothing
						const selectedType = getZObjectType( selectedObject[ Constants.Z_PERSISTENTOBJECT_VALUE ] );
						if ( selectedType !== zid ) {
							return enums;
						}
 
						const selectedItem = {
							page_title: selected,
							label: this.getLabelData( selected ).label
						};
						return [ selectedItem, ...enums ];
					}
				}
 
				return enums;
			};
			return findEnumValues;
		},
 
		/**
		 * Returns the enum of a given ZID
		 *
		 * @param {Object} state
		 * @return {Function}
		 */
		getEnum: function ( state ) {
			/**
			 * @param {string} zid
			 * @return {Array}
			 */
			const findEnum = ( zid ) => state.enums[ zid ];
			return findEnum;
		},
 
		/**
		 * Returns the object with the selected description and its language
		 * information. Returns undefined if:
		 * * no stored object with this zid
		 * * stored object has no description
		 *
		 * @return {Function}
		 */
		getDescription: function () {
			/**
			 * @param {string} zid
			 * @return {LabelData|undefined}
			 */
			const findDescription = ( zid ) => {
				const persistentObject = this.getStoredObject( zid );
				if ( !persistentObject ) {
					// No stored object
					return undefined;
				}
				const multiStr = persistentObject[ Constants.Z_PERSISTENTOBJECT_DESCRIPTION ];
				if ( !multiStr ) {
					// No description key
					return undefined;
				}
				if ( multiStr[ Constants.Z_MULTILINGUALSTRING_VALUE ].length <= 1 ) {
					// No description items
					return undefined;
				}
 
				// First monolingual string is the userlang, fallback or first added lang:
				const description = multiStr[ Constants.Z_MULTILINGUALSTRING_VALUE ][ 1 ];
				return new LabelData(
					zid,
					description[ Constants.Z_MONOLINGUALSTRING_VALUE ],
					description[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ],
					this.getLanguageIsoCodeOfZLang( description[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ] )
				);
			};
			return findDescription;
		},
 
		/**
		 * Returns the output type of a function given its Zid.
		 * If the object is not a function or not available, returns undefined.
		 *
		 * @return {Function}
		 */
		getOutputTypeOfFunctionZid: function () {
			/**
			 * @param {string} zid
			 * @return {string|undefined}
			 */
			const findOutputTypeOfFunctionZid = ( zid ) => {
				const func = this.getStoredObject( zid );
				if ( !func ) {
					return;
				}
				const obj = func[ Constants.Z_PERSISTENTOBJECT_VALUE ];
				if ( obj[ Constants.Z_OBJECT_TYPE ] !== Constants.Z_FUNCTION ) {
					return;
				}
				return obj[ Constants.Z_FUNCTION_RETURN_TYPE ];
			};
			return findOutputTypeOfFunctionZid;
		}
	},
 
	actions: {
		/**
		 * Set request state for each zid
		 *
		 * @param {Object} payload
		 * @param {string} payload.zid
		 * @param {Promise} payload.request
		 */
		setZidRequest: function ( payload ) {
			if ( payload.request ) {
				this.requests[ payload.zid ] = payload.request;
			} else {
				delete this.requests[ payload.zid ];
			}
		},
 
		/**
		 * Add zid info to the state
		 *
		 * @param {Object} payload
		 * @param {string} payload.zid
		 * @param {Object} payload.data
		 * @param {boolean|undefined} payload.success
		 * @param {boolean|undefined} payload.forceUpdate
		 */
		setStoredObject: function ( payload ) {
			const { zid, data, success = true, forceUpdate = false } = payload;
			if ( !( zid in this.objects ) || forceUpdate ) {
				this.objects[ zid ] = { success, data };
			}
		},
 
		/**
		 * Save the LabelData object for a given ID
		 * of a ZPersistentObject, ZKey or ZArgumentDeclaration.
		 *
		 * @param {LabelData} labelData
		 */
		setLabel: function ( labelData ) {
			this.labels[ labelData.zid ] = labelData;
		},
 
		/**
		 * @param {Object} payload
		 * @param {string} payload.zid
		 * @param {Array | Promise} payload.data
		 * @param {number | undefined} payload.searchContinue
		 */
		setEnumData: function ( payload ) {
			const zid = payload.zid;
			const data = payload.data;
			const searchContinue = payload.searchContinue;
 
			// Initialize the enum object if it does not exist with a Promise or Array
			if ( !this.enums[ zid ] ) {
				this.enums[ zid ] = { data };
				return;
			}
 
			// Ensure data is an array before concatenation
			if ( !Array.isArray( this.enums[ zid ].data ) ) {
				this.enums[ zid ].data = [];
			}
 
			// Append new data and update continuation value
			this.enums[ zid ].data = this.enums[ zid ].data.concat( data );
			this.enums[ zid ].searchContinue = searchContinue;
		},
 
		/**
		 * @param {Object} payload
		 * @param {string} payload.code
		 * @param {string} payload.zid
		 */
		setLanguageCode: function ( payload ) {
			this.languages[ payload.code ] = payload.zid;
		},
 
		/**
		 * Updates the stored object in the Library with the current ZObject
		 */
		updateStoredObject: function () {
			const zobject = hybridToCanonical( this.getJsonObject( Constants.STORED_OBJECTS.MAIN ) );
			const zid = this.getCurrentZObjectId;
			this.setStoredObject( {
				zid,
				data: zobject,
				forceUpdate: true
			} );
		},
 
		/**
		 * Performs a Lookup call to the database to retrieve all
		 * ZObject references that match a given input and type.
		 * This is used in selectors such as ZObjectSelector or the
		 * language selector of the About widget.
		 *
		 * @param {Object} payload
		 * @return {Promise}
		 * @property {Array<Object>} labels - The search results
		 * @property {number|null} searchContinue - The token to continue the search or null if no more results
		 */
		lookupZObjectLabels: function ( payload ) {
			payload.language = this.getUserLangCode;
			return new Promise( ( resolve, reject ) => {
				clearTimeout( debounceZObjectLookup );
				debounceZObjectLookup = setTimeout(
					() => searchLabels( payload )
						.then( ( data ) => resolve( data ) )
						.catch( ( error ) => reject( error ) ),
					DEBOUNCE_ZOBJECT_LOOKUP_TIMEOUT
				);
			} );
		},
 
		/**
		 * Performs a Lookup call to the database to retrieve all
		 * Functions that match a given input and type.
		 * This is used in the function selector for VisualEditor
		 *
		 * @param {Object} payload
		 * @param {string} payload.search
		 * @param {boolean} payload.renderable
		 * @return {Promise}
		 * @property {Array<Object>} labels - The search results
		 * @property {number|null} searchContinue - The token to continue the search or null if no more results
		 */
		lookupFunctions: function ( payload ) {
			payload.language = this.getUserLangCode;
			return new Promise( ( resolve, reject ) => {
				clearTimeout( debounceZObjectLookup );
				debounceZObjectLookup = setTimeout(
					() => searchFunctions( payload )
						.then( ( data ) => resolve( data ) )
						.catch( ( error ) => reject( error ) ),
					DEBOUNCE_ZOBJECT_LOOKUP_TIMEOUT
				);
			} );
		},
 
		/**
		 * Fetches all values stored of a given enum type.
		 *
		 * @param {Object} payload
		 * @param {string} payload.type - The ZID of the enum type
		 * @param {number} payload.limit - The amount of enums to fetch
		 * @return {Promise} - Promise resolving to:
		 * @property {Array<Object>} labels - The search results
		 * @property {number|null} searchContinue - The token to continue the search or null if no more results
		 */
		fetchEnumValues: function ( payload ) {
			const enumObject = this.getEnum( payload.type );
			const searchContinue = enumObject ? enumObject.searchContinue : undefined;
 
			// If no continuation token and the enum is already fetched, do nothing
			if ( enumObject && !searchContinue ) {
				return Promise.resolve();
			}
			const promise = searchLabels( {
				input: '',
				types: [ payload.type ],
				limit: payload.limit || Constants.API_ENUMS_APPEND_LIMIT,
				language: this.getUserLangCode,
				searchContinue
			} ).then( ( data ) => {
				// Set values when the request is completed
				this.setEnumData( { zid: payload.type, data: data.labels, searchContinue: data.searchContinue } );
				return data;
			} ).catch( () => {
				this.setEnumData( { zid: payload.type, data: [] } );
			} );
 
			if ( !searchContinue ) {
				this.setEnumData( { zid: payload.type, data: promise } );
			}
			return promise;
		},
 
		/**
		 * Fetches a given language code using the labels API and
		 * if found it stores locally the correspondance of language
		 * code and language zid.
		 *
		 * @param {string} langCode
		 * @return {Promise}
		 */
		fetchLanguageCode: function ( langCode ) {
			const payload = {
				language: this.getUserLangCode,
				limit: 1,
				exact: true,
				types: [ Constants.Z_NATURAL_LANGUAGE ],
				input: langCode
			};
 
			return searchLabels( payload ).then( ( data ) => {
				// Make sure the returned data matches the language code:
				// match rate is 1.0, with the matched langCode as an alias.
				if (
					( data.labels.length > 0 ) &&
					( data.labels[ 0 ].match_rate === 1 ) &&
					( data.labels[ 0 ].match_label === langCode ) &&
					( data.labels[ 0 ].match_is_primary === '0' )
				) {
					this.setLanguageCode( { code: langCode, zid: data.labels[ 0 ].page_title } );
				}
			} );
		},
 
		/**
		 * Orchestrates the calls to wikilambdaload_zobject api to fetch
		 * a given set of ZIDs. This method takes care of the following requirements:
		 *
		 * * Zids are requested in batches of max 50 items.
		 * * Zids are only requested once.
		 * * Every zid is stored along with their request while it's being fetched.
		 * * Once it's fetched, the request is cleared.
		 * * The returning promise only resolves when all of the batches have returned.
		 *
		 * @param {Object} payload
		 * @param {Array} payload.zids array of zids to fetch
		 * @return {Promise}
		 */
		fetchZids: function ( payload ) {
			let requestZids = [];
			const allPromises = [];
			const {
				zids = []
			} = payload;
 
			zids.forEach( ( zid ) => {
				// Ignore if:
				// * Zid is Z0
				// * Zid has already been fetched (success or failure)
				if (
					zid &&
					zid !== Constants.NEW_ZID_PLACEHOLDER &&
					!( zid in this.objects ) &&
					!( zid in this.requests )
				) {
					requestZids.push( zid );
				}
				// Capture pending promise to await if:
				// * Zid is waiting to be fetched
				if ( zid in this.requests ) {
					allPromises.push( this.requests[ zid ] );
				}
			} );
 
			// Keep only unique values
			requestZids = [ ...new Set( requestZids ) ];
 
			// Batch zids in groups of max 50 items
			const batches = [];
			for ( let i = 0; i < requestZids.length; i += Constants.API_REQUEST_ITEMS_LIMIT ) {
				batches.push( requestZids.slice( i, i + Constants.API_REQUEST_ITEMS_LIMIT ) );
			}
 
			// For each batch, generate a Promise
			for ( const batch of batches ) {
				const batchPromise = this.performFetchZids( { zids: batch } ).then( () => {
					// Once it's back, unset active request
					batch.forEach( ( zid ) => {
						this.setZidRequest( { zid, request: null } );
					} );
				} );
				// Set active request
				batch.forEach( ( zid ) => {
					this.setZidRequest( { zid, request: batchPromise } );
				} );
				// Collect batch promises
				allPromises.push( batchPromise );
			}
 
			// Return pending and new promises for all the requested zids
			return Promise.all( allPromises );
		},
 
		/**
		 * Calls the api wikilambdaload_zobjects with a set of Zids and
		 * with or without language property. The language will always be
		 * requested so that the backend takes care of the language ballback
		 * logic. The only moment in wich we will not specify a language
		 * property is when requesting the root ZObject on initialization
		 *
		 * Once received the response, stores the full object in the objects
		 * array and the labels for the Zids, ZKey and ZArgument ids in the
		 * labels store object. The labels returned are already in the
		 * preferred language (or closest fallback available).
		 *
		 * @param {Object} payload
		 * @return {Promise}
		 */
		performFetchZids: function ( payload ) {
			return new Promise( ( resolve, reject ) => {
				fetchZObjects( {
					zids: payload.zids.join( '|' ),
					language: this.getUserLangCode,
					dependencies: true
				} ).then( ( response ) => {
					const requestedZids = payload.zids;
					const returnedZids = Object.keys( response );
					const dependentZids = [];
 
					returnedZids.forEach( ( zid ) => {
						// success is true or false, we normalize it to boolean in case it is undefined somehow
						const { data, success } = response[ zid ];
						// 1. State mutation:
						// Add zObject or error data to the state objects array
						this.setStoredObject( {
							zid,
							data,
							success: !!success
						} );
 
						// If the requested zid returned error, exit
						if ( !success ) {
							return;
						}
 
						// 2. State mutation:
						// Add zObject label in user's selected language
						const multiStr = data[
							Constants.Z_PERSISTENTOBJECT_LABEL
						][ Constants.Z_MULTILINGUALSTRING_VALUE ].slice( 1 );
 
						// The returned multilingual strings will only contain one monolingual string
						// (or none) as they have already been filtered by the back-end to the given
						// language or any of its available fallbacks.
						if ( multiStr.length === 1 ) {
							const labelData = new LabelData(
								zid,
								multiStr[ 0 ][ Constants.Z_MONOLINGUALSTRING_VALUE ],
								multiStr[ 0 ][ Constants.Z_MONOLINGUALSTRING_LANGUAGE ]
							);
							dependentZids.push( multiStr[ 0 ][ Constants.Z_MONOLINGUALSTRING_LANGUAGE ] );
							this.setLabel( labelData );
						}
 
						// 3. State mutation:
						// Add the key or argument labels from the selected language to the store
						let objects;
						const objectValue = data[ Constants.Z_PERSISTENTOBJECT_VALUE ];
						const zType = ( typeof objectValue === 'object' ) ?
							objectValue[ Constants.Z_OBJECT_TYPE ] :
							undefined;
 
						switch ( zType ) {
							case Constants.Z_ERRORTYPE:
								// If the zObject is an error type, get all key labels
								// and commit to the store
								objects = objectValue[ Constants.Z_ERRORTYPE_KEYS ].slice( 1 );
 
								objects.forEach( ( key ) => {
									const keyLabels = key[
										Constants.Z_KEY_LABEL
									][ Constants.Z_MULTILINGUALSTRING_VALUE ].slice( 1 );
 
									if ( keyLabels.length === 1 ) {
										const labelData = new LabelData(
											key[ Constants.Z_KEY_ID ],
											keyLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_VALUE ],
											keyLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_LANGUAGE ]
										);
										dependentZids.push( keyLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_LANGUAGE ] );
										this.setLabel( labelData );
									}
								} );
								break;
 
							case Constants.Z_TYPE:
								// If the zObject is a type, get all key labels
								// and commit to the store
								objects = objectValue[ Constants.Z_TYPE_KEYS ].slice( 1 );
 
								objects.forEach( ( key ) => {
									const keyLabels = key[
										Constants.Z_KEY_LABEL
									][ Constants.Z_MULTILINGUALSTRING_VALUE ].slice( 1 );
 
									if ( keyLabels.length === 1 ) {
										const labelData = new LabelData(
											key[ Constants.Z_KEY_ID ],
											keyLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_VALUE ],
											keyLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_LANGUAGE ]
										);
										dependentZids.push( keyLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_LANGUAGE ] );
										this.setLabel( labelData );
									}
								} );
 
								// If the zObject is a type, get all parser and renderer functions
								// and commit to the store
								if ( Constants.Z_TYPE_RENDERER in objectValue ) {
									const renderer = objectValue[ Constants.Z_TYPE_RENDERER ];
									dependentZids.push( renderer );
									this.setRenderer( { type: zid, renderer } );
								}
								if ( Constants.Z_TYPE_PARSER in objectValue ) {
									const parser = objectValue[ Constants.Z_TYPE_PARSER ];
									dependentZids.push( parser );
									this.setParser( { type: zid, parser } );
								}
								break;
 
							case Constants.Z_FUNCTION:
								// If the zObject is a function, get all argument
								// declaration labels and commit to the store
								objects = objectValue[ Constants.Z_FUNCTION_ARGUMENTS ].slice( 1 );
 
								objects.forEach( ( arg ) => {
									const argLabels = arg[
										Constants.Z_ARGUMENT_LABEL
									][ Constants.Z_MULTILINGUALSTRING_VALUE ].slice( 1 );
 
									if ( argLabels.length === 1 ) {
 
										const labelData = new LabelData(
											arg[ Constants.Z_ARGUMENT_KEY ],
											argLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_VALUE ],
											argLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_LANGUAGE ]
										);
										dependentZids.push( argLabels[ 0 ][ Constants.Z_MONOLINGUALSTRING_LANGUAGE ] );
										this.setLabel( labelData );
									}
								} );
								break;
 
							case Constants.Z_NATURAL_LANGUAGE:
								// If the zObject is a natural langugae, save the
								// code and the zid in the store for easy access
								this.setLanguageCode( {
									code: objectValue[ Constants.Z_NATURAL_LANGUAGE_ISO_CODE ],
									zid
								} );
								break;
 
							default:
							// Do nothing
						}
 
						// Make sure that we fetch all languages stored in the labels library
						this.fetchZids( { zids: [ ...new Set( dependentZids ) ] } );
					} );
 
					// performFetch must resolve to the list of requested zids
					resolve( requestedZids );
				} ).catch( ( error ) => {
					reject( error );
				} );
			} );
		},
		/**
		 * Pre-fetch information of the Zids most commonly used within the UI
		 *
		 * @return {Promise}
		 */
		prefetchZids: function () {
			const zids = [
				Constants.Z_OBJECT,
				Constants.Z_PERSISTENTOBJECT,
				Constants.Z_MULTILINGUALSTRING,
				Constants.Z_MONOLINGUALSTRING,
				Constants.Z_KEY,
				Constants.Z_TYPE,
				Constants.Z_STRING,
				Constants.Z_FUNCTION,
				Constants.Z_FUNCTION_CALL,
				Constants.Z_REFERENCE,
				Constants.Z_BOOLEAN,
				Constants.Z_BOOLEAN_TRUE,
				Constants.Z_BOOLEAN_FALSE,
				Constants.Z_IMPLEMENTATION,
				this.getUserLangZid,
				Constants.Z_TYPED_LIST,
				Constants.Z_ARGUMENT_REFERENCE,
				Constants.Z_NATURAL_LANGUAGE,
				... Constants.SUGGESTIONS.LANGUAGES,
				... Constants.SUGGESTIONS.TYPES
			];
			return this.fetchZids( { zids } );
		}
	}
};