"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _ParseOp = require("./ParseOp"); var _ParseObject = _interopRequireDefault(require("./ParseObject")); var _ParseQuery = _interopRequireDefault(require("./ParseQuery")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @flow */ /** * Creates a new Relation for the given parent object and key. This * constructor should rarely be used directly, but rather created by * Parse.Object.relation. * *
* A class that is used to access all of the children of a many-to-many * relationship. Each instance of Parse.Relation is associated with a * particular parent object and key. *
* @alias Parse.Relation */ class ParseRelation { /*:: parent: ?ParseObject;*/ /*:: key: ?string;*/ /*:: targetClassName: ?string;*/ /** * @param {Parse.Object} parent The parent of this relation. * @param {String} key The key for this relation on the parent. */ constructor(parent /*: ?ParseObject*/ , key /*: ?string*/ ) { this.parent = parent; this.key = key; this.targetClassName = null; } /* * Makes sure that this relation has the right parent and key. */ _ensureParentAndKey(parent /*: ParseObject*/ , key /*: string*/ ) { this.key = this.key || key; if (this.key !== key) { throw new Error('Internal Error. Relation retrieved from two different keys.'); } if (this.parent) { if (this.parent.className !== parent.className) { throw new Error('Internal Error. Relation retrieved from two different Objects.'); } if (this.parent.id) { if (this.parent.id !== parent.id) { throw new Error('Internal Error. Relation retrieved from two different Objects.'); } } else if (parent.id) { this.parent = parent; } } else { this.parent = parent; } } /** * Adds a Parse.Object or an array of Parse.Objects to the relation. * @param {} objects The item or items to add. */ add(objects /*: ParseObject | Array