ParseOp.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.opFromJSON = opFromJSON;
  7. exports.RelationOp = exports.RemoveOp = exports.AddUniqueOp = exports.AddOp = exports.IncrementOp = exports.UnsetOp = exports.SetOp = exports.Op = void 0;
  8. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  9. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  10. var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
  11. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  12. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  13. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  14. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  15. var _arrayContainsObject = _interopRequireDefault(require("./arrayContainsObject"));
  16. var _decode = _interopRequireDefault(require("./decode"));
  17. var _encode = _interopRequireDefault(require("./encode"));
  18. var _ParseObject = _interopRequireDefault(require("./ParseObject"));
  19. var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
  20. var _unique = _interopRequireDefault(require("./unique"));
  21. /**
  22. * Copyright (c) 2015-present, Parse, LLC.
  23. * All rights reserved.
  24. *
  25. * This source code is licensed under the BSD-style license found in the
  26. * LICENSE file in the root directory of this source tree. An additional grant
  27. * of patent rights can be found in the PATENTS file in the same directory.
  28. *
  29. * @flow
  30. */
  31. function opFromJSON(json
  32. /*: { [key: string]: any }*/
  33. )
  34. /*: ?Op*/
  35. {
  36. if (!json || !json.__op) {
  37. return null;
  38. }
  39. switch (json.__op) {
  40. case 'Delete':
  41. return new UnsetOp();
  42. case 'Increment':
  43. return new IncrementOp(json.amount);
  44. case 'Add':
  45. return new AddOp((0, _decode.default)(json.objects));
  46. case 'AddUnique':
  47. return new AddUniqueOp((0, _decode.default)(json.objects));
  48. case 'Remove':
  49. return new RemoveOp((0, _decode.default)(json.objects));
  50. case 'AddRelation':
  51. {
  52. var toAdd = (0, _decode.default)(json.objects);
  53. if (!Array.isArray(toAdd)) {
  54. return new RelationOp([], []);
  55. }
  56. return new RelationOp(toAdd, []);
  57. }
  58. case 'RemoveRelation':
  59. {
  60. var toRemove = (0, _decode.default)(json.objects);
  61. if (!Array.isArray(toRemove)) {
  62. return new RelationOp([], []);
  63. }
  64. return new RelationOp([], toRemove);
  65. }
  66. case 'Batch':
  67. {
  68. var _toAdd = [];
  69. var _toRemove = [];
  70. for (var i = 0; i < json.ops.length; i++) {
  71. if (json.ops[i].__op === 'AddRelation') {
  72. _toAdd = _toAdd.concat((0, _decode.default)(json.ops[i].objects));
  73. } else if (json.ops[i].__op === 'RemoveRelation') {
  74. _toRemove = _toRemove.concat((0, _decode.default)(json.ops[i].objects));
  75. }
  76. }
  77. return new RelationOp(_toAdd, _toRemove);
  78. }
  79. }
  80. return null;
  81. }
  82. var Op =
  83. /*#__PURE__*/
  84. function () {
  85. function Op() {
  86. (0, _classCallCheck2.default)(this, Op);
  87. }
  88. (0, _createClass2.default)(Op, [{
  89. key: "applyTo",
  90. // Empty parent class
  91. value: function ()
  92. /*: mixed*/
  93. /*: mixed*/
  94. {}
  95. /* eslint-disable-line no-unused-vars */
  96. }, {
  97. key: "mergeWith",
  98. value: function ()
  99. /*: Op*/
  100. /*: ?Op*/
  101. {}
  102. /* eslint-disable-line no-unused-vars */
  103. }, {
  104. key: "toJSON",
  105. value: function ()
  106. /*: mixed*/
  107. {}
  108. }]);
  109. return Op;
  110. }();
  111. exports.Op = Op;
  112. var SetOp =
  113. /*#__PURE__*/
  114. function (_Op) {
  115. (0, _inherits2.default)(SetOp, _Op);
  116. function SetOp(value
  117. /*: mixed*/
  118. ) {
  119. var _this;
  120. (0, _classCallCheck2.default)(this, SetOp);
  121. _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(SetOp).call(this));
  122. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_value", void 0);
  123. _this._value = value;
  124. return _this;
  125. }
  126. (0, _createClass2.default)(SetOp, [{
  127. key: "applyTo",
  128. value: function ()
  129. /*: mixed*/
  130. {
  131. return this._value;
  132. }
  133. }, {
  134. key: "mergeWith",
  135. value: function ()
  136. /*: SetOp*/
  137. {
  138. return new SetOp(this._value);
  139. }
  140. }, {
  141. key: "toJSON",
  142. value: function () {
  143. return (0, _encode.default)(this._value, false, true);
  144. }
  145. }]);
  146. return SetOp;
  147. }(Op);
  148. exports.SetOp = SetOp;
  149. var UnsetOp =
  150. /*#__PURE__*/
  151. function (_Op2) {
  152. (0, _inherits2.default)(UnsetOp, _Op2);
  153. function UnsetOp() {
  154. (0, _classCallCheck2.default)(this, UnsetOp);
  155. return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(UnsetOp).apply(this, arguments));
  156. }
  157. (0, _createClass2.default)(UnsetOp, [{
  158. key: "applyTo",
  159. value: function () {
  160. return undefined;
  161. }
  162. }, {
  163. key: "mergeWith",
  164. value: function ()
  165. /*: UnsetOp*/
  166. {
  167. return new UnsetOp();
  168. }
  169. }, {
  170. key: "toJSON",
  171. value: function ()
  172. /*: { __op: string }*/
  173. {
  174. return {
  175. __op: 'Delete'
  176. };
  177. }
  178. }]);
  179. return UnsetOp;
  180. }(Op);
  181. exports.UnsetOp = UnsetOp;
  182. var IncrementOp =
  183. /*#__PURE__*/
  184. function (_Op3) {
  185. (0, _inherits2.default)(IncrementOp, _Op3);
  186. function IncrementOp(amount
  187. /*: number*/
  188. ) {
  189. var _this2;
  190. (0, _classCallCheck2.default)(this, IncrementOp);
  191. _this2 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(IncrementOp).call(this));
  192. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "_amount", void 0);
  193. if (typeof amount !== 'number') {
  194. throw new TypeError('Increment Op must be initialized with a numeric amount.');
  195. }
  196. _this2._amount = amount;
  197. return _this2;
  198. }
  199. (0, _createClass2.default)(IncrementOp, [{
  200. key: "applyTo",
  201. value: function (value
  202. /*: ?mixed*/
  203. )
  204. /*: number*/
  205. {
  206. if (typeof value === 'undefined') {
  207. return this._amount;
  208. }
  209. if (typeof value !== 'number') {
  210. throw new TypeError('Cannot increment a non-numeric value.');
  211. }
  212. return this._amount + value;
  213. }
  214. }, {
  215. key: "mergeWith",
  216. value: function (previous
  217. /*: Op*/
  218. )
  219. /*: Op*/
  220. {
  221. if (!previous) {
  222. return this;
  223. }
  224. if (previous instanceof SetOp) {
  225. return new SetOp(this.applyTo(previous._value));
  226. }
  227. if (previous instanceof UnsetOp) {
  228. return new SetOp(this._amount);
  229. }
  230. if (previous instanceof IncrementOp) {
  231. return new IncrementOp(this.applyTo(previous._amount));
  232. }
  233. throw new Error('Cannot merge Increment Op with the previous Op');
  234. }
  235. }, {
  236. key: "toJSON",
  237. value: function ()
  238. /*: { __op: string; amount: number }*/
  239. {
  240. return {
  241. __op: 'Increment',
  242. amount: this._amount
  243. };
  244. }
  245. }]);
  246. return IncrementOp;
  247. }(Op);
  248. exports.IncrementOp = IncrementOp;
  249. var AddOp =
  250. /*#__PURE__*/
  251. function (_Op4) {
  252. (0, _inherits2.default)(AddOp, _Op4);
  253. function AddOp(value
  254. /*: mixed | Array<mixed>*/
  255. ) {
  256. var _this3;
  257. (0, _classCallCheck2.default)(this, AddOp);
  258. _this3 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(AddOp).call(this));
  259. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this3), "_value", void 0);
  260. _this3._value = Array.isArray(value) ? value : [value];
  261. return _this3;
  262. }
  263. (0, _createClass2.default)(AddOp, [{
  264. key: "applyTo",
  265. value: function (value
  266. /*: mixed*/
  267. )
  268. /*: Array<mixed>*/
  269. {
  270. if (value == null) {
  271. return this._value;
  272. }
  273. if (Array.isArray(value)) {
  274. return value.concat(this._value);
  275. }
  276. throw new Error('Cannot add elements to a non-array value');
  277. }
  278. }, {
  279. key: "mergeWith",
  280. value: function (previous
  281. /*: Op*/
  282. )
  283. /*: Op*/
  284. {
  285. if (!previous) {
  286. return this;
  287. }
  288. if (previous instanceof SetOp) {
  289. return new SetOp(this.applyTo(previous._value));
  290. }
  291. if (previous instanceof UnsetOp) {
  292. return new SetOp(this._value);
  293. }
  294. if (previous instanceof AddOp) {
  295. return new AddOp(this.applyTo(previous._value));
  296. }
  297. throw new Error('Cannot merge Add Op with the previous Op');
  298. }
  299. }, {
  300. key: "toJSON",
  301. value: function ()
  302. /*: { __op: string; objects: mixed }*/
  303. {
  304. return {
  305. __op: 'Add',
  306. objects: (0, _encode.default)(this._value, false, true)
  307. };
  308. }
  309. }]);
  310. return AddOp;
  311. }(Op);
  312. exports.AddOp = AddOp;
  313. var AddUniqueOp =
  314. /*#__PURE__*/
  315. function (_Op5) {
  316. (0, _inherits2.default)(AddUniqueOp, _Op5);
  317. function AddUniqueOp(value
  318. /*: mixed | Array<mixed>*/
  319. ) {
  320. var _this4;
  321. (0, _classCallCheck2.default)(this, AddUniqueOp);
  322. _this4 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(AddUniqueOp).call(this));
  323. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this4), "_value", void 0);
  324. _this4._value = (0, _unique.default)(Array.isArray(value) ? value : [value]);
  325. return _this4;
  326. }
  327. (0, _createClass2.default)(AddUniqueOp, [{
  328. key: "applyTo",
  329. value: function (value
  330. /*: mixed | Array<mixed>*/
  331. )
  332. /*: Array<mixed>*/
  333. {
  334. if (value == null) {
  335. return this._value || [];
  336. }
  337. if (Array.isArray(value)) {
  338. // copying value lets Flow guarantee the pointer isn't modified elsewhere
  339. var valueCopy = value;
  340. var toAdd = [];
  341. this._value.forEach(function (v) {
  342. if (v instanceof _ParseObject.default) {
  343. if (!(0, _arrayContainsObject.default)(valueCopy, v)) {
  344. toAdd.push(v);
  345. }
  346. } else {
  347. if (valueCopy.indexOf(v) < 0) {
  348. toAdd.push(v);
  349. }
  350. }
  351. });
  352. return value.concat(toAdd);
  353. }
  354. throw new Error('Cannot add elements to a non-array value');
  355. }
  356. }, {
  357. key: "mergeWith",
  358. value: function (previous
  359. /*: Op*/
  360. )
  361. /*: Op*/
  362. {
  363. if (!previous) {
  364. return this;
  365. }
  366. if (previous instanceof SetOp) {
  367. return new SetOp(this.applyTo(previous._value));
  368. }
  369. if (previous instanceof UnsetOp) {
  370. return new SetOp(this._value);
  371. }
  372. if (previous instanceof AddUniqueOp) {
  373. return new AddUniqueOp(this.applyTo(previous._value));
  374. }
  375. throw new Error('Cannot merge AddUnique Op with the previous Op');
  376. }
  377. }, {
  378. key: "toJSON",
  379. value: function ()
  380. /*: { __op: string; objects: mixed }*/
  381. {
  382. return {
  383. __op: 'AddUnique',
  384. objects: (0, _encode.default)(this._value, false, true)
  385. };
  386. }
  387. }]);
  388. return AddUniqueOp;
  389. }(Op);
  390. exports.AddUniqueOp = AddUniqueOp;
  391. var RemoveOp =
  392. /*#__PURE__*/
  393. function (_Op6) {
  394. (0, _inherits2.default)(RemoveOp, _Op6);
  395. function RemoveOp(value
  396. /*: mixed | Array<mixed>*/
  397. ) {
  398. var _this5;
  399. (0, _classCallCheck2.default)(this, RemoveOp);
  400. _this5 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(RemoveOp).call(this));
  401. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this5), "_value", void 0);
  402. _this5._value = (0, _unique.default)(Array.isArray(value) ? value : [value]);
  403. return _this5;
  404. }
  405. (0, _createClass2.default)(RemoveOp, [{
  406. key: "applyTo",
  407. value: function (value
  408. /*: mixed | Array<mixed>*/
  409. )
  410. /*: Array<mixed>*/
  411. {
  412. if (value == null) {
  413. return [];
  414. }
  415. if (Array.isArray(value)) {
  416. // var i = value.indexOf(this._value);
  417. var removed = value.concat([]);
  418. for (var i = 0; i < this._value.length; i++) {
  419. var index = removed.indexOf(this._value[i]);
  420. while (index > -1) {
  421. removed.splice(index, 1);
  422. index = removed.indexOf(this._value[i]);
  423. }
  424. if (this._value[i] instanceof _ParseObject.default && this._value[i].id) {
  425. for (var j = 0; j < removed.length; j++) {
  426. if (removed[j] instanceof _ParseObject.default && this._value[i].id === removed[j].id) {
  427. removed.splice(j, 1);
  428. j--;
  429. }
  430. }
  431. }
  432. }
  433. return removed;
  434. }
  435. throw new Error('Cannot remove elements from a non-array value');
  436. }
  437. }, {
  438. key: "mergeWith",
  439. value: function (previous
  440. /*: Op*/
  441. )
  442. /*: Op*/
  443. {
  444. if (!previous) {
  445. return this;
  446. }
  447. if (previous instanceof SetOp) {
  448. return new SetOp(this.applyTo(previous._value));
  449. }
  450. if (previous instanceof UnsetOp) {
  451. return new UnsetOp();
  452. }
  453. if (previous instanceof RemoveOp) {
  454. var uniques = previous._value.concat([]);
  455. for (var i = 0; i < this._value.length; i++) {
  456. if (this._value[i] instanceof _ParseObject.default) {
  457. if (!(0, _arrayContainsObject.default)(uniques, this._value[i])) {
  458. uniques.push(this._value[i]);
  459. }
  460. } else {
  461. if (uniques.indexOf(this._value[i]) < 0) {
  462. uniques.push(this._value[i]);
  463. }
  464. }
  465. }
  466. return new RemoveOp(uniques);
  467. }
  468. throw new Error('Cannot merge Remove Op with the previous Op');
  469. }
  470. }, {
  471. key: "toJSON",
  472. value: function ()
  473. /*: { __op: string; objects: mixed }*/
  474. {
  475. return {
  476. __op: 'Remove',
  477. objects: (0, _encode.default)(this._value, false, true)
  478. };
  479. }
  480. }]);
  481. return RemoveOp;
  482. }(Op);
  483. exports.RemoveOp = RemoveOp;
  484. var RelationOp =
  485. /*#__PURE__*/
  486. function (_Op7) {
  487. (0, _inherits2.default)(RelationOp, _Op7);
  488. function RelationOp(adds
  489. /*: Array<ParseObject | string>*/
  490. , removes
  491. /*: Array<ParseObject | string>*/
  492. ) {
  493. var _this6;
  494. (0, _classCallCheck2.default)(this, RelationOp);
  495. _this6 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(RelationOp).call(this));
  496. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this6), "_targetClassName", void 0);
  497. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this6), "relationsToAdd", void 0);
  498. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this6), "relationsToRemove", void 0);
  499. _this6._targetClassName = null;
  500. if (Array.isArray(adds)) {
  501. _this6.relationsToAdd = (0, _unique.default)(adds.map(_this6._extractId, (0, _assertThisInitialized2.default)(_this6)));
  502. }
  503. if (Array.isArray(removes)) {
  504. _this6.relationsToRemove = (0, _unique.default)(removes.map(_this6._extractId, (0, _assertThisInitialized2.default)(_this6)));
  505. }
  506. return _this6;
  507. }
  508. (0, _createClass2.default)(RelationOp, [{
  509. key: "_extractId",
  510. value: function (obj
  511. /*: string | ParseObject*/
  512. )
  513. /*: string*/
  514. {
  515. if (typeof obj === 'string') {
  516. return obj;
  517. }
  518. if (!obj.id) {
  519. throw new Error('You cannot add or remove an unsaved Parse Object from a relation');
  520. }
  521. if (!this._targetClassName) {
  522. this._targetClassName = obj.className;
  523. }
  524. if (this._targetClassName !== obj.className) {
  525. throw new Error('Tried to create a Relation with 2 different object types: ' + this._targetClassName + ' and ' + obj.className + '.');
  526. }
  527. return obj.id;
  528. }
  529. }, {
  530. key: "applyTo",
  531. value: function (value
  532. /*: mixed*/
  533. , object
  534. /*:: ?: { className: string, id: ?string }*/
  535. , key
  536. /*:: ?: string*/
  537. )
  538. /*: ?ParseRelation*/
  539. {
  540. if (!value) {
  541. if (!object || !key) {
  542. throw new Error('Cannot apply a RelationOp without either a previous value, or an object and a key');
  543. }
  544. var parent = new _ParseObject.default(object.className);
  545. if (object.id && object.id.indexOf('local') === 0) {
  546. parent._localId = object.id;
  547. } else if (object.id) {
  548. parent.id = object.id;
  549. }
  550. var relation = new _ParseRelation.default(parent, key);
  551. relation.targetClassName = this._targetClassName;
  552. return relation;
  553. }
  554. if (value instanceof _ParseRelation.default) {
  555. if (this._targetClassName) {
  556. if (value.targetClassName) {
  557. if (this._targetClassName !== value.targetClassName) {
  558. throw new Error('Related object must be a ' + value.targetClassName + ', but a ' + this._targetClassName + ' was passed in.');
  559. }
  560. } else {
  561. value.targetClassName = this._targetClassName;
  562. }
  563. }
  564. return value;
  565. } else {
  566. throw new Error('Relation cannot be applied to a non-relation field');
  567. }
  568. }
  569. }, {
  570. key: "mergeWith",
  571. value: function (previous
  572. /*: Op*/
  573. )
  574. /*: Op*/
  575. {
  576. if (!previous) {
  577. return this;
  578. } else if (previous instanceof UnsetOp) {
  579. throw new Error('You cannot modify a relation after deleting it.');
  580. } else if (previous instanceof SetOp && previous._value instanceof _ParseRelation.default) {
  581. return this;
  582. } else if (previous instanceof RelationOp) {
  583. if (previous._targetClassName && previous._targetClassName !== this._targetClassName) {
  584. throw new Error('Related object must be of class ' + previous._targetClassName + ', but ' + (this._targetClassName || 'null') + ' was passed in.');
  585. }
  586. var newAdd = previous.relationsToAdd.concat([]);
  587. this.relationsToRemove.forEach(function (r) {
  588. var index = newAdd.indexOf(r);
  589. if (index > -1) {
  590. newAdd.splice(index, 1);
  591. }
  592. });
  593. this.relationsToAdd.forEach(function (r) {
  594. var index = newAdd.indexOf(r);
  595. if (index < 0) {
  596. newAdd.push(r);
  597. }
  598. });
  599. var newRemove = previous.relationsToRemove.concat([]);
  600. this.relationsToAdd.forEach(function (r) {
  601. var index = newRemove.indexOf(r);
  602. if (index > -1) {
  603. newRemove.splice(index, 1);
  604. }
  605. });
  606. this.relationsToRemove.forEach(function (r) {
  607. var index = newRemove.indexOf(r);
  608. if (index < 0) {
  609. newRemove.push(r);
  610. }
  611. });
  612. var newRelation = new RelationOp(newAdd, newRemove);
  613. newRelation._targetClassName = this._targetClassName;
  614. return newRelation;
  615. }
  616. throw new Error('Cannot merge Relation Op with the previous Op');
  617. }
  618. }, {
  619. key: "toJSON",
  620. value: function ()
  621. /*: { __op?: string; objects?: mixed; ops?: mixed }*/
  622. {
  623. var _this7 = this;
  624. var idToPointer = function (id) {
  625. return {
  626. __type: 'Pointer',
  627. className: _this7._targetClassName,
  628. objectId: id
  629. };
  630. };
  631. var adds = null;
  632. var removes = null;
  633. var pointers = null;
  634. if (this.relationsToAdd.length > 0) {
  635. pointers = this.relationsToAdd.map(idToPointer);
  636. adds = {
  637. __op: 'AddRelation',
  638. objects: pointers
  639. };
  640. }
  641. if (this.relationsToRemove.length > 0) {
  642. pointers = this.relationsToRemove.map(idToPointer);
  643. removes = {
  644. __op: 'RemoveRelation',
  645. objects: pointers
  646. };
  647. }
  648. if (adds && removes) {
  649. return {
  650. __op: 'Batch',
  651. ops: [adds, removes]
  652. };
  653. }
  654. return adds || removes || {};
  655. }
  656. }]);
  657. return RelationOp;
  658. }(Op);
  659. exports.RelationOp = RelationOp;