lib/record-patch-builder.js
function validatePatchOperationFrom(opType, opInd, pathPtr, fromPtr, forMove) {

	const invalidFrom = msg => new common.X2SyntaxError(
		`Invalid "from" pointer in patch operation #${opInd + 1} (${opType}):` +
			` ${msg}`);

	if (forMove && pathPtr.isChildOf(fromPtr))
		throw invalidFrom('may not move location into one of its children.');

	const fromPropDesc = fromPtr.propDesc;
	const toPropDesc = pathPtr.propDesc;

	if (fromPropDesc.scalarValueType !== toPropDesc.scalarValueType)
		throw invalidFrom('incompatible property value types.');
	if (toPropDesc.isRef() && (fromPropDesc.refTarget !== toPropDesc.refTarget))
		throw invalidFrom('incompatible reference property targets.');
	if ((toPropDesc.scalarValueType === 'object') &&
		!isCompatibleObjects(fromPropDesc, toPropDesc))
		throw invalidFrom('incompatible nested objects.');

	if (toPropDesc.isArray() && !pathPtr.collectionElement) {
		if (!fromPropDesc.isArray() || fromPropDesc.collectionElement)
			throw invalidFrom('not an array.');
	} else if (toPropDesc.isMap() && !pathPtr.collectionElement) {
		if (!fromPropDesc.isMap() || fromPropDesc.collectionElement)
			throw invalidFrom('not a map.');
	} else {
		if (!fromPropDesc.isScalar() && !fromPtr.collectionElement)
			throw invalidFrom('not a scalar.');
	}

	return fromPtr;
}
function validatePatchOperationFrom(opType, opInd, pathPtr, fromPtr, forMove) {

	const invalidFrom = msg => new common.X2SyntaxError(
		`Invalid "from" pointer in patch operation #${opInd + 1} (${opType}):` +
			` ${msg}`);

	if (forMove && pathPtr.isChildOf(fromPtr))
		throw invalidFrom('may not move location into one of its children.');

	const fromPropDesc = fromPtr.propDesc;
	const toPropDesc = pathPtr.propDesc;

	if (fromPropDesc.scalarValueType !== toPropDesc.scalarValueType)
		throw invalidFrom('incompatible property value types.');
	if (toPropDesc.isRef() && (fromPropDesc.refTarget !== toPropDesc.refTarget))
		throw invalidFrom('incompatible reference property targets.');
	if ((toPropDesc.scalarValueType === 'object') &&
		!isCompatibleObjects(fromPropDesc, toPropDesc))
		throw invalidFrom('incompatible nested objects.');

	if (toPropDesc.isArray() && !pathPtr.collectionElement) {
		if (!fromPropDesc.isArray() || fromPropDesc.collectionElement)
			throw invalidFrom('not an array.');
	} else if (toPropDesc.isMap() && !pathPtr.collectionElement) {
		if (!fromPropDesc.isMap() || fromPropDesc.collectionElement)
			throw invalidFrom('not a map.');
	} else {
		if (!fromPropDesc.isScalar() && !fromPtr.collectionElement)
			throw invalidFrom('not a scalar.');
	}

	return fromPtr;
}
function validatePatchOperationFrom ( opType , opInd , pathPtr , fromPtr , forMove ) { const invalidFrom = msg => new common . X2SyntaxError ( ` ${ opInd + 1 } ${ opType } ` + ` ${ msg } ` ) ; if ( forMove && pathPtr . isChildOf ( fromPtr ) ) throw invalidFrom ( 'may not move location into one of its children.' ) ; const fromPropDesc = fromPtr . propDesc ; const toPropDesc = pathPtr . propDesc ; if ( fromPropDesc . scalarValueType !== toPropDesc . scalarValueType ) throw invalidFrom ( 'incompatible property value types.' ) ; if ( toPropDesc . isRef ( ) && ( fromPropDesc . refTarget !== toPropDesc . refTarget ) ) throw invalidFrom ( 'incompatible reference property targets.' ) ; if ( ( toPropDesc . scalarValueType === 'object' ) && ! isCompatibleObjects ( fromPropDesc , toPropDesc ) ) throw invalidFrom ( 'incompatible nested objects.' ) ; if ( toPropDesc . isArray ( ) && ! pathPtr . collectionElement ) { if ( ! fromPropDesc . isArray ( ) || fromPropDesc . collectionElement ) throw invalidFrom ( 'not an array.' ) ; } else if ( toPropDesc . isMap ( ) && ! pathPtr . collectionElement ) { if ( ! fromPropDesc . isMap ( ) || fromPropDesc . collectionElement ) throw invalidFrom ( 'not a map.' ) ; } else { if ( ! fromPropDesc . isScalar ( ) && ! fromPtr . collectionElement ) throw invalidFrom ( 'not a scalar.' ) ; } return fromPtr ; }
Validate "from" property provided with a patch operation.

@private
@param {string} opType Patch operation type.
@param {number} opInd Index of the patch operation in the list of operations.
@param {module:x2node-pointers~RecordElementPointer} pathPtr Information
object for the property path where the "from" property is supposed to be
placed.
@param {module:x2node-pointers~RecordElementPointer} fromPtr Information
object for the "from" property.
@param {boolean} forMove <code>true</code> if moving, <code>false</code> if
copying.
@returns {module:x2node-pointers~RecordElementPointer} The pointer passed in
as the <code>fromPtr</code>.
@throws {module:x2node-common.X2SyntaxError} If the "from" is incompatible.
Validate from property provided with a patch operation .