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

99.17% Statements 838/845
96.12% Branches 124/129
100% Functions 45/45
99.17% Lines 838/845

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 846103x 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 449x 449x 449x 449x 449x 449x 449x 449x 449x 449x 449x 259x 259x 259x 259x 259x 259x 259x 259x 259x 259x 259x 259x 259x 259x 259x 259x 18x 18x 241x 241x 241x 241x 241x 241x 241x 241x 241x 259x 6x 3x 3x 3x 3x 3x 3x 4x 1x 1x 1x 1x 1x 1x 1x 1x 2x 4x 1x 1x 1x 1x 1x 1x 1x 1x 6x 236x 236x 236x 259x 2x 2x 234x 234x 259x 19x 259x 62x 259x 4x 259x 4x 259x 31x 259x 8x 259x 7x 259x 15x 259x 7x 259x 14x 259x 1x 259x 5x 259x 2x 259x 4x 259x 6x 259x 3x 259x 3x 259x 259x 259x 259x 259x 5x 259x 259x 259x 259x 14x 259x 20x 20x 259x 449x 449x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 312x 312x 312x 312x 312x 312x 312x 20x 20x 20x 20x 20x 20x 16x 16x 16x 16x 21x 21x 21x 21x               21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 16x 16x 20x 312x 312x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 311x 311x 311x 311x 14x 14x 14x 14x 14x 14x 13x 13x 13x 13x 13x 13x 13x 14x 311x 311x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 288x 288x 288x 288x 288x 288x 288x 288x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 288x 288x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 305x 305x 305x 305x 305x 305x 305x 305x 8x 8x 8x 8x 8x 8x 7x 9x 7x 7x 8x 305x 305x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 301x 301x 301x 301x 301x 301x 301x 301x 4x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 4x 301x 301x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 357x 357x 357x 357x 357x 357x 357x 62x 2x 2x 2x 2x 62x 357x 357x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 332x 332x 332x 332x 332x 332x 332x 37x 37x 37x 37x 37x 332x 332x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 299x 299x 299x 299x 299x 299x 299x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 299x 299x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 301x 301x 301x 301x 301x 301x 301x 4x 4x 4x 4x 4x 301x 301x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 298x 298x 298x 298x 1x 1x 1x 1x 1x 298x 298x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 304x 304x 304x 304x 304x 304x 304x 7x 7x 7x 7x 7x 304x 304x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 312x 312x 312x 312x 312x 312x 312x 15x 15x 15x 15x 15x 312x 312x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 302x 302x 302x 302x 5x 5x 5x 5x 5x 5x 302x 302x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 299x 299x 299x 299x 299x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 304x 304x 304x 304x 7x 7x 7x 7x 7x 7x 7x 7x 7x 304x 304x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 301x 301x 301x 301x 4x 4x 4x 4x 4x 4x 4x 301x 301x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 303x 303x 303x 303x 303x 303x 303x 6x 6x 6x 6x 6x 303x 303x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 300x 300x 300x 300x 300x 300x 300x 300x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 300x 300x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 300x 300x 300x 300x 300x 300x 300x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 300x 300x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 302x 302x 302x 302x 302x 302x 302x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 302x 302x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 311x 14x 14x 14x 14x 14x 14x 311x 311x 311x 103x 103x 103x 103x  
/*!
 * WikiLambda Pinia store to interact with the store to create new ZObjects by their type.
 *
 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
 * @license MIT
 */
'use strict';
 
const Constants = require( '../../Constants.js' );
const { getParameterByName } = require( '../../utils/urlUtils.js' );
const {
	getScaffolding,
	initializePayloadForType,
	isGenericType,
	isTruthyOrEqual
} = require( '../../utils/typeUtils.js' );
 
module.exports = {
	state: {},
 
	getters: {
		/**
		 * Return a blank object for a given type, and initialize its
		 * values if the payload contains the required initialization data.
		 *
		 * @return {Function}
		 */
		createObjectByType: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.type the type of the new object to add
			 * @param {Object} payload.value initialization values
			 * @param {boolean} payload.append whether to append the new zobject to a list
			 * @param {boolean} payload.literal force create a literal object: on root initialization and
			 * mode selector explicit request
			 * @param {Array} keyList a list of types that have been seen so far
			 * @return {Object}
			 */
			const generateObjectByType = ( payload, keyList = [] ) => {
				// If payload.literal is true, we are forcing creating a literal
				// object for those types that are generally persisted and linked.
				// We force literal when:
				// * initializing a new root ZObject
				// * the mode selector explicitly requests literal
				// * it has a builtin component even if it's an enum
				// We default to references for LINKED_TYPES and Enums when:
				// * initializing function arguments
				// * initializing key values
				// * adding new items to a list
				const isRecursiveType = keyList.includes( payload.type );
				const isLinkedOrCustomEnum = Constants.LINKED_TYPES.includes( payload.type ) ||
				this.isCustomEnum( payload.type );
				const shouldReturnReference = isRecursiveType || ( !payload.literal && isLinkedOrCustomEnum );
 
				if ( shouldReturnReference ) {
					return this.createZReference( payload );
				}
 
				// Unset payload.literal for recursive calls
				delete payload.literal;
 
				keyList.push( payload.type );
 
				// If payload.type is an object, we are looking at a generic type,
				// so a type returned by a function call. Transform the payload for
				// the special cases: List, Pair and Map
				if ( isGenericType( payload.type ) ) {
					if ( payload.type[ Constants.Z_FUNCTION_CALL_FUNCTION ] === Constants.Z_TYPED_LIST ) {
						const newPayload = Object.assign( {}, payload );
						newPayload.type = Constants.Z_TYPED_LIST;
						newPayload.value = payload.type[ Constants.Z_TYPED_LIST_TYPE ];
						return this.createObjectByType( newPayload, keyList );
					}
 
					if ( payload.type[ Constants.Z_FUNCTION_CALL_FUNCTION ] === Constants.Z_TYPED_PAIR ) {
						const newPayload = Object.assign( {}, payload );
						newPayload.type = Constants.Z_TYPED_PAIR;
						newPayload.values = [
							payload.type[ Constants.Z_TYPED_PAIR_TYPE1 ],
							payload.type[ Constants.Z_TYPED_PAIR_TYPE2 ]
						];
						return this.createObjectByType( newPayload, keyList );
					}
 
					if ( payload.type[ Constants.Z_FUNCTION_CALL_FUNCTION ] === Constants.Z_TYPED_MAP ) {
						const newPayload = Object.assign( {}, payload );
						newPayload.type = Constants.Z_TYPED_MAP;
						newPayload.values = [
							payload.type[ Constants.Z_TYPED_MAP_TYPE1 ],
							payload.type[ Constants.Z_TYPED_MAP_TYPE2 ]
						];
						return this.createObjectByType( newPayload, keyList );
					}
				}
 
				// If payload.type is a Wikidata enum, we need to create a
				// Wikidata enum object, which is a special case.
				if ( this.isWikidataEnum( payload.type ) ) {
					return this.createZWikidataEnum( payload );
				}
 
				switch ( payload.type ) {
					case Constants.Z_REFERENCE:
						return this.createZReference( payload );
					case Constants.Z_STRING:
						return this.createZString( payload );
					case Constants.Z_BOOLEAN:
						return this.createZBoolean( payload );
					case Constants.Z_MULTILINGUALSTRING:
						return this.createZMultilingualString( payload );
					case Constants.Z_MONOLINGUALSTRING:
						return this.createZMonolingualString( payload );
					case Constants.Z_MONOLINGUALSTRINGSET:
						return this.createZMonolingualStringSet( payload );
					case Constants.Z_ARGUMENT:
						return this.createZArgument( payload );
					case Constants.Z_FUNCTION_CALL:
						return this.createZFunctionCall( payload );
					case Constants.Z_FUNCTION:
						return this.createZFunction( payload );
					case Constants.Z_PERSISTENTOBJECT:
						return this.createZPersistentObject( payload );
					case Constants.Z_TYPE:
						return this.createZType( payload );
					case Constants.Z_IMPLEMENTATION:
						return this.createZImplementation( payload );
					case Constants.Z_CODE:
						return this.createZCode( payload );
					case Constants.Z_TESTER:
						return this.createZTester( payload );
					case Constants.Z_TYPED_LIST:
						return this.createZTypedList( payload );
					case Constants.Z_TYPED_PAIR:
						return this.createZTypedPair( payload );
					case Constants.Z_TYPED_MAP:
						return this.createZTypedMap( payload );
					case Constants.Z_WIKIDATA_ITEM:
					case Constants.Z_WIKIDATA_LEXEME:
					case Constants.Z_WIKIDATA_LEXEME_FORM:
					case Constants.Z_WIKIDATA_LEXEME_SENSE:
					case Constants.Z_WIKIDATA_PROPERTY:
						return this.createWikidataEntity( payload );
					case Constants.Z_WIKIDATA_REFERENCE_ITEM:
					case Constants.Z_WIKIDATA_REFERENCE_LEXEME:
					case Constants.Z_WIKIDATA_REFERENCE_LEXEME_FORM:
					case Constants.Z_WIKIDATA_REFERENCE_PROPERTY:
						return this.createWikidataReference( payload );
					default:
						// Explore and create new ZObject keys
						return this.createGenericObject( payload, keyList );
				}
			};
			return generateObjectByType;
		},
 
		/**
		 * Return a blank generic object for a given type. If the
		 * type is a reference and the persisted object is known,
		 * initialize all its keys. Else simply return the type field.
		 * The entry will result in a json representation equal to:
		 * {
		 *  Z1K1: 'Zx'
		 *  ZxK1: ''
		 * }
		 *
		 * @return {Function}
		 */
		createGenericObject: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.type
			 * @param {Array} keyList a list of types that have been seen so far
			 * @return {Object}
			 */
			const generateGenericObject = ( payload, keyList = [] ) => {
				const persisted = this.getStoredObject( payload.type );
				const value = {
					[ Constants.Z_OBJECT_TYPE ]: payload.type
				};
				keyList.push( payload.type );
				if ( persisted ) {
					const zobject = persisted[ Constants.Z_PERSISTENTOBJECT_VALUE ];
					if ( zobject[ Constants.Z_OBJECT_TYPE ] === Constants.Z_TYPE ) {
						const keys = zobject[ Constants.Z_TYPE_KEYS ];
						for ( let i = 1; i < keys.length; i++ ) {
							const key = keys[ i ];
 
							// Create a reference to self it the key is the identity key of the root object
							const isIdentityKey = !payload.isRoot ? false : (
								isTruthyOrEqual( key, [
									Constants.Z_KEY_IS_IDENTITY
								], Constants.Z_BOOLEAN_TRUE ) ||
								isTruthyOrEqual( key, [
									Constants.Z_KEY_IS_IDENTITY,
									Constants.Z_BOOLEAN_IDENTITY
								], Constants.Z_BOOLEAN_TRUE )
							);
							const keyPayload = isIdentityKey ?
								{ type: Constants.Z_REFERENCE, value: this.getCurrentZObjectId } :
								initializePayloadForType( key[ Constants.Z_KEY_TYPE ] );
 
							// We must pass keyList array by value in here, so that the types found in an argument
							// branch don't affect another branch, it should only restrict repetition in depth.
							const blankValue = this.createObjectByType( keyPayload, keyList.slice() );
							value[ key[ Constants.Z_KEY_ID ] ] = blankValue;
						}
					}
				}
				return value;
			};
			return generateGenericObject;
		},
 
		/**
		 * Return a blank and initialized zPersistentObject.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: { Z1K1: 'Z9', Z9K1: 'Z2' },
		 *  Z2K1: { Z1K1: 'Z9', Z9K1: 'Z0' },
		 *  Z2K2: {
		 *   Z1K1: { Z1K1: 'Z9', Z9K1: '' }
		 *  },
		 *  Z2K3: {
		 *   Z1K1: { Z1K1: 'Z9', Z9K1: 'Z12' }
		 *   Z12K1: [ Z11 ]
		 *  },
		 *  Z2K4: {
		 *   Z1K1: { Z1K1: 'Z9', Z9K1: 'Z32' }
		 *   Z32K1: [ Z31 ]
		 *  }
		 * }
		 *
		 * @return {Function}
		 */
		createZPersistentObject: function () {
			/**
			 * @return {Object}
			 */
			const generateZPersistentObject = () => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_PERSISTENTOBJECT );
				// Initialize persistent zid and blank label
				const zid = this.getCurrentZObjectId || Constants.NEW_ZID_PLACEHOLDER;
				value[ Constants.Z_PERSISTENTOBJECT_ID ][ Constants.Z_STRING_VALUE ] = zid;
				if ( this.getUserLangZid ) {
					const mono = this.createObjectByType( {
						type: Constants.Z_MONOLINGUALSTRING,
						lang: this.getUserLangZid
					} );
					value[ Constants.Z_PERSISTENTOBJECT_LABEL ][
						Constants.Z_MULTILINGUALSTRING_VALUE ].push( mono );
				}
				return value;
			};
			return generateZPersistentObject;
		},
 
		/**
		 * Return a blank and initialized zMonolingualString.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: Z11,
		 *  Z11K1: { Z1K1: Z9, Z9K1: payload.lang },
		 *  Z11K2: { Z1K1: Z6, Z6K1: '' }
		 * }
		 *
		 * @return {Function}
		 */
		createZMonolingualString: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.value string value of the monolingual string
			 * @param {string} payload.lang zid of the language for the monolingual string
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZMonolingualString = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_MONOLINGUALSTRING );
				// Initialize monolingual string
				const lang = payload.lang || '';
				value[ Constants.Z_MONOLINGUALSTRING_VALUE ] = this.createObjectByType( {
					type: Constants.Z_STRING,
					value: payload.value
				} );
				value[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ][ Constants.Z_REFERENCE_ID ] = lang;
				return value;
			};
			return generateZMonolingualString;
		},
 
		/**
		 * Return a blank and initialized zMonolingualStringSet.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: Z31,
		 *  Z31K1: { Z1K1: Z9, Z9K1: payload.lang },
		 *  Z31K2: [ 'Z6', { Z1K1: Z6, Z6K1: payload.value } ]
		 * }
		 *
		 * @return {Function}
		 */
		createZMonolingualStringSet: function () {
			/**
			 * @param {Object} payload
			 * @param {Array} payload.value Array list of strings for the list
			 * @param {string} payload.lang zid of the language for the first monolingual string
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZMonolingualStringSet = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_MONOLINGUALSTRINGSET );
				// Initialize language and first string
				const lang = payload.lang || '';
				value[ Constants.Z_MONOLINGUALSTRINGSET_LANGUAGE ][ Constants.Z_REFERENCE_ID ] = lang;
				if ( payload.value ) {
					payload.value.forEach( ( stringValue ) => {
						value[ Constants.Z_MONOLINGUALSTRINGSET_VALUE ].push( stringValue );
					} );
				}
				return value;
			};
			return generateZMonolingualStringSet;
		},
 
		/**
		 * Return a blank and initialized zMultilingualString.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: Z12,
		 *  Z12K1: [
		 *   Z11,
		 *   { Z1K1: Z11, Z11K1: '', Z11K2: '' }
		 *  ]
		 * }
		 *
		 * @return {Function}
		 */
		createZMultilingualString: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.value string value of the first monolingual string
			 * @param {string} payload.lang zid of the language for the first monolingual string
			 * @param {number} payload.append
			 * @return {Object}
			 */
			const generateZMultilingualString = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_MULTILINGUALSTRING );
 
				// Initialize first monolingual string if there's any lang or value
				if ( ( 'lang' in payload ) || ( 'value' in payload ) ) {
					const mono = this.createObjectByType( {
						type: Constants.Z_MONOLINGUALSTRING,
						lang: payload.lang || this.getUserLangZid,
						value: payload.value || ''
					} );
					value[ Constants.Z_MULTILINGUALSTRING_VALUE ].push( mono );
				}
				return value;
			};
			return generateZMultilingualString;
		},
 
		/**
		 * Return a blank and initialized zString
		 * The value will result in a json representation equal to:
		 * * If payload.value is a canonical reference (matches Zn format):
		 *   return { Z1K1: Z6, Z6K1: payload.value }
		 * * If payload.value is a canonical string:
		 *   return payload.value
		 *
		 * @return {Function}
		 */
		createZString: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.value
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZString = ( payload ) => {
				if ( payload.value && payload.value.match( /^Z\d+$/ ) ) {
					const normalString = getScaffolding( Constants.Z_STRING );
					normalString[ Constants.Z_STRING_VALUE ] = payload.value;
					return normalString;
				}
				return payload.value || '';
			};
			return generateZString;
		},
 
		/**
		 * Return a blank and initialized zReference.
		 * The value will result in a json representation equal to:
		 * { Z1K1: Z9, Z9K1: payload.value }
		 *
		 * @return {Function}
		 */
		createZReference: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.value
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZReference = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_REFERENCE );
				// Initialize values, if any
				value[ Constants.Z_REFERENCE_ID ] = payload.value || '';
				return value;
			};
			return generateZReference;
		},
 
		/**
		 * Return an initialized zWikidataEnum.
		 * The value will result in a json representation equal to:
		 * {
		 *   "Z1K1": "Zxxxxx",
		 *   "ZxxxxxK1": {
		 *     "Z1K1": "Z609x",
		 *     "Z609xK1": payload.value ||''
		 *   }
		 * }
		 *
		 * @return {Function}
		 */
		createZWikidataEnum: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.type the type of the new object to add
			 * @param {Object} payload.value initialization values
			 * @return {Object}
			 */
			const generateZWikidataEnum = ( payload ) => {
				const enumType = this.getTypeOfWikidataEnum( payload.type );
				const enumValue = getScaffolding( enumType );
 
				// Initialize the enum reference with the provided value
				enumValue[ `${ enumType }K1` ] = payload.value || '';
 
				return {
					[ Constants.Z_OBJECT_TYPE ]: payload.type,
					[ `${ payload.type }K1` ]: enumValue
				};
			};
			return generateZWikidataEnum;
		},
 
		/**
		 * Return a blank and initialized zBoolean.
		 * The value will result in a json representation equal to:
		 * {
		 *   Z1K1: Z40,
		 *   Z40K1: { Z1K1: Z9, Z9K1: payload.value }
		 * }
		 *
		 * @return {Function}
		 */
		createZBoolean: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.value
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZBoolean = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_BOOLEAN );
				// Initialize value with the boolean Zid, if any
				value[ Constants.Z_BOOLEAN_IDENTITY ][ Constants.Z_REFERENCE_ID ] = payload.value || '';
				return value;
			};
			return generateZBoolean;
		},
 
		/**
		 * Return a blank and initialized zType.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: 'Z4',
		 *  Z4K1: { Z1K1: 'Z9', Z9K1: 'Z0' },
		 *  Z4K2: [ 'Z3' ]
		 *  Z4K3: { Z1K1: 'Z9', Z9K1: 'Z101' }
		 * }
		 *
		 * @return {Function}
		 */
		createZType: function () {
			/**
			 * @return {Object}
			 */
			const generateZType = () => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_TYPE );
				// Initialize validator function
				value[ Constants.Z_TYPE_VALIDATOR ][ Constants.Z_REFERENCE_ID ] = Constants.Z_VALIDATE_OBJECT;
				return value;
			};
			return generateZType;
		},
		/**
		 * Return a blank and initialized zArgument.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: 'Z17',
		 *  Z17K1: { Z1K1: 'Z9', Z9K1: '' },
		 *  Z17K2: { Z1K1: 'Z6', Z6K1: 'Z0K1' },
		 *  Z17K3: { Z1K1: 'Z12', Z12K1: [ Z11 ] }
		 * }
		 *
		 * @return {Function}
		 */
		createZArgument: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.value
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZArgument = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_ARGUMENT );
				// Initialize argument key
				value[ Constants.Z_ARGUMENT_KEY ] = payload.value || this.getNextKey;
				return value;
			};
			return generateZArgument;
		},
 
		/**
		 * Return a blank and initialized zFunctionCall.
		 * The value will result in a json representation equal to:
		 * { Z1K1: Z7, Z7K1: '' }
		 *
		 * @return {Function}
		 */
		createZFunctionCall: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.value Zid of the function to call
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZFunctionCall = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_FUNCTION_CALL );
				// Initialize function zid
				value[ Constants.Z_FUNCTION_CALL_FUNCTION ][ Constants.Z_REFERENCE_ID ] = payload.value || '';
				return value;
			};
			return generateZFunctionCall;
		},
 
		/**
		 * Return a blank and initialized zImplementation.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: 'Z14',
		 *  Z14K1: { Z1K1: 'Z9', Z9K1: '' },
		 *  Z14K2: { Z1K1: 'Z7', Z7K1: '' },
		 * }
		 *
		 * @return {Function}
		 */
		createZImplementation: function () {
			/**
			 * @return {Object}
			 */
			const generateZImplementation = () => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_IMPLEMENTATION );
				// Initialize function zid from the url parameters
				const functionZid = getParameterByName( Constants.Z_IMPLEMENTATION_FUNCTION ) || '';
				value[ Constants.Z_IMPLEMENTATION_FUNCTION ][ Constants.Z_REFERENCE_ID ] = functionZid;
				return value;
			};
			return generateZImplementation;
		},
 
		/**
		 * Return a blank and initialized zCode.
		 * The value will result in a json representation equal to:
		 *
		 * {
		 *  Z1K1: 'Z16'
		 *  Z16K1: { Z1K1: 'Z9', Z9K1: '' },
		 *  Z16K2: ''
		 * }
		 *
		 * @return {Function}
		 */
		createZCode: function () {
			/**
			 * @return {Object}
			 */
			const generateZCode = () => getScaffolding( Constants.Z_CODE );
			return generateZCode;
		},
 
		/**
		 * Return a blank and initialized zFunction.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: 'Z8',
		 *  Z8K1: [ 'Z17' ],
		 *  Z8K2: { Z1K1: 'Z9', Z9K1: '' },
		 *  Z8K3: [ 'Z20' ],
		 *  Z8K4: [ 'Z14' ],
		 *  Z8K5: { Z1K1: 'Z9', Z9K1: '' },
		 * }
		 *
		 * @return {Function}
		 */
		createZFunction: function () {
			/**
			 * @return {Object}
			 */
			const generateZFunction = () => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_FUNCTION );
				const arg = getScaffolding( Constants.Z_ARGUMENT );
				// Initialize function identity and one empty argument
				const functionZid = this.getCurrentZObjectId || Constants.NEW_ZID_PLACEHOLDER;
				value[ Constants.Z_FUNCTION_IDENTITY ][ Constants.Z_REFERENCE_ID ] = functionZid;
				arg[ Constants.Z_ARGUMENT_KEY ] = `${ functionZid }K1`;
				value[ Constants.Z_FUNCTION_ARGUMENTS ].push( arg );
				return value;
			};
			return generateZFunction;
		},
 
		/**
		 * Return a blank and initialized zTester.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: 'Z20',
		 *  Z20K1: { Z1K1: 'Z9', Z9K1: '' }
		 *  Z20K2: {
		 *   Z1K1: 'Z7',
		 *   Z7K1: { Z1K1: 'Z9', Z9K1: '' }
		 *  },
		 *  Z20K3: {
		 *   Z1K1: 'Z7',
		 *   Z7K1: { Z1K1: 'Z9', Z9K1: '' }
		 *  }
		 * }
		 *
		 * @return {Function}
		 */
		createZTester: function () {
			/**
			 * @return {Object}
			 */
			const generateZTester = () => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_TESTER );
 
				// Initialize function zid from the url parameters
				const functionZid = getParameterByName( Constants.Z_TESTER_FUNCTION ) || '';
				value[ Constants.Z_TESTER_FUNCTION ][ Constants.Z_REFERENCE_ID ] = functionZid;
				return value;
			};
			return generateZTester;
		},
 
		/**
		 * Return a blank and initialized zTypedList.
		 * The value will result in a json representation equal to:
		 * [ 'Z1' ]
		 *
		 * @return {Function}
		 */
		createZTypedList: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.value
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZTypedList = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_TYPED_LIST );
				// Initialize function zid from the url parameters
				value[ 0 ][ Constants.Z_REFERENCE_ID ] = payload.value || Constants.Z_OBJECT;
				return value;
			};
			return generateZTypedList;
		},
 
		/**
		 * Return a blank and initialized zTypedPair.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: {
		 *   Z1K1: Z7,
		 *   Z7K1: Z882,
		 *   Z882K1: { Z1K1: Z9, Z9K1: '' }
		 *   Z882K2: { Z1K1: Z9, Z9K1: '' }
		 *  },
		 *  K1: {}
		 *  K2: {}
		 * }
		 *
		 * @return {Function}
		 */
		createZTypedPair: function () {
			/**
			 * @param {Object} payload
			 * @param {Object} payload.values
			 * @param {boolean} payload.isDeclaration This is used know if the values need to be initialized or not
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZTypedPair = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_TYPED_PAIR );
 
				// Initialize typed pair type
				const type1 = payload.values ? payload.values[ 0 ] : '';
				const type2 = payload.values ? payload.values[ 1 ] : '';
				value[ Constants.Z_OBJECT_TYPE ][ Constants.Z_TYPED_PAIR_TYPE1 ][ Constants.Z_REFERENCE_ID ] = type1;
				value[ Constants.Z_OBJECT_TYPE ][ Constants.Z_TYPED_PAIR_TYPE2 ][ Constants.Z_REFERENCE_ID ] = type2;
 
				// K1 contains initialized object ot type1
				// K2 contains initialized object ot type2
				const value1 = type1 ? this.createObjectByType( { type: type1 } ) : {};
				const value2 = type2 ? this.createObjectByType( { type: type2 } ) : {};
				value[ Constants.Z_TYPED_OBJECT_ELEMENT_1 ] = value1;
				value[ Constants.Z_TYPED_OBJECT_ELEMENT_2 ] = value2;
 
				return value;
 
			};
			return generateZTypedPair;
		},
 
		/**
		 * Return a blank and initialized zTypedMap.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: {
		 *   Z1K1: Z7,
		 *   Z7K1: Z883,
		 *   Z883K1: { Z1K1: Z9, Z9K1: '' }
		 *   Z883K2: { Z1K1: Z9, Z9K1: '' }
		 *  }
		 * }
		 *
		 * @return {Function}
		 */
		createZTypedMap: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.values
			 * @param {boolean} payload.append
			 * @return {Object}
			 */
			const generateZTypedMap = ( payload ) => {
				// Get scaffolding
				const value = getScaffolding( Constants.Z_TYPED_MAP );
 
				// Initialize typed map type
				const type1 = payload.values ? payload.values[ 0 ] : '';
				const type2 = payload.values ? payload.values[ 1 ] : '';
				value[ Constants.Z_OBJECT_TYPE ][ Constants.Z_TYPED_MAP_TYPE1 ][ Constants.Z_REFERENCE_ID ] = type1;
				value[ Constants.Z_OBJECT_TYPE ][ Constants.Z_TYPED_MAP_TYPE2 ][ Constants.Z_REFERENCE_ID ] = type2;
 
				// K1 contains a typed list of pairs ( type1, type2 )
				const benjamin = value[ Constants.Z_TYPED_OBJECT_ELEMENT_1 ][ 0 ];
				benjamin[ Constants.Z_TYPED_PAIR_TYPE1 ][ Constants.Z_REFERENCE_ID ] = type1;
				benjamin[ Constants.Z_TYPED_PAIR_TYPE2 ][ Constants.Z_REFERENCE_ID ] = type2;
 
				return value;
			};
			return generateZTypedMap;
		},
 
		/**
		 * Return a blank and initialized Wikidata Entity Fetch function call.
		 * The value will result in a json representation equal to:
		 * {
		 *  Z1K1: {
		 *   Z1K1: Z7,
		 *   Z7K1: <Wikidata Fetch Function>,
		 *   <Wikidata Fetch Function Id>: {
		 *     Z1K1: <Wikidata Reference Type>,
		 *     <Wikidata Reference Type Id>: { Z1K1: Z6, Z6K1: '' }
		 *    }
		 *  }
		 * }
		 *
		 * If payload.value is provided, it will be used to initialize the reference value.
		 *
		 * @return {Function}
		 */
		createWikidataEntity: function () {
			/**
			 * @param {Object} payload
			 * @param {string} payload.type
			 * @param {string|Object} [payload.value] Optional initialization value for the reference
			 * @return {Object}
			 */
			const generateWikidataEntity = ( payload ) => {
				const value = getScaffolding( Constants.Z_FUNCTION_CALL );
				const refType = Constants.WIKIDATA_REFERENCE_TYPES[ payload.type ];
				const fetchFunction = Constants.WIKIDATA_FETCH_FUNCTIONS[ payload.type ];
				const fetchFunctionId = fetchFunction ? `${ fetchFunction }K1` : null;
 
				if ( refType && fetchFunction && fetchFunctionId ) {
					const wdRef = this.createObjectByType( { type: refType, value: payload.value } );
					value[ Constants.Z_FUNCTION_CALL_FUNCTION ] = fetchFunction;
					value[ fetchFunctionId ] = wdRef;
				}
				return value;
			};
			return generateWikidataEntity;
		},
 
		/**
		 * Creates a Wikidata reference object for the given type and value.
		 *
		 * @param {Object} payload
		 * @param {string} payload.type - The Wikidata reference type ZID
		 * @param {string} payload.value - The entity ID (e.g., Q42, L2, etc.)
		 * @return {Object}
		 */
		createWikidataReference: function () {
			const generateWikidataReference = ( payload ) => {
				const idKey = `${ payload.type }K1`;
				const value = {
					[ Constants.Z_OBJECT_TYPE ]: payload.type,
					[ idKey ]: payload.value || ''
				};
				return value;
			};
			return generateWikidataReference;
		}
	},
 
	actions: {}
};