findBreakingChanges.mjs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  2. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  3. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  4. import objectValues from '../polyfills/objectValues';
  5. import keyMap from '../jsutils/keyMap';
  6. import inspect from '../jsutils/inspect';
  7. import invariant from '../jsutils/invariant';
  8. import { print } from '../language/printer';
  9. import { visit } from '../language/visitor';
  10. import { isScalarType, isObjectType, isInterfaceType, isUnionType, isEnumType, isInputObjectType, isNonNullType, isListType, isNamedType, isRequiredArgument, isRequiredInputField } from '../type/definition';
  11. import { astFromValue } from './astFromValue';
  12. export var BreakingChangeType = Object.freeze({
  13. TYPE_REMOVED: 'TYPE_REMOVED',
  14. TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND',
  15. TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION',
  16. VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM',
  17. REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED',
  18. INTERFACE_REMOVED_FROM_OBJECT: 'INTERFACE_REMOVED_FROM_OBJECT',
  19. FIELD_REMOVED: 'FIELD_REMOVED',
  20. FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND',
  21. REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED',
  22. ARG_REMOVED: 'ARG_REMOVED',
  23. ARG_CHANGED_KIND: 'ARG_CHANGED_KIND',
  24. DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED',
  25. DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED',
  26. REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED',
  27. DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED'
  28. });
  29. export var DangerousChangeType = Object.freeze({
  30. VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM',
  31. TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION',
  32. OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED',
  33. OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED',
  34. INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT',
  35. ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE'
  36. });
  37. /**
  38. * Given two schemas, returns an Array containing descriptions of all the types
  39. * of breaking changes covered by the other functions down below.
  40. */
  41. export function findBreakingChanges(oldSchema, newSchema) {
  42. var breakingChanges = findSchemaChanges(oldSchema, newSchema).filter(function (change) {
  43. return change.type in BreakingChangeType;
  44. });
  45. return breakingChanges;
  46. }
  47. /**
  48. * Given two schemas, returns an Array containing descriptions of all the types
  49. * of potentially dangerous changes covered by the other functions down below.
  50. */
  51. export function findDangerousChanges(oldSchema, newSchema) {
  52. var dangerousChanges = findSchemaChanges(oldSchema, newSchema).filter(function (change) {
  53. return change.type in DangerousChangeType;
  54. });
  55. return dangerousChanges;
  56. }
  57. function findSchemaChanges(oldSchema, newSchema) {
  58. return [].concat(findTypeChanges(oldSchema, newSchema), findDirectiveChanges(oldSchema, newSchema));
  59. }
  60. function findDirectiveChanges(oldSchema, newSchema) {
  61. var schemaChanges = [];
  62. var directivesDiff = diff(oldSchema.getDirectives(), newSchema.getDirectives());
  63. for (var _i2 = 0, _directivesDiff$remov2 = directivesDiff.removed; _i2 < _directivesDiff$remov2.length; _i2++) {
  64. var oldDirective = _directivesDiff$remov2[_i2];
  65. schemaChanges.push({
  66. type: BreakingChangeType.DIRECTIVE_REMOVED,
  67. description: "".concat(oldDirective.name, " was removed.")
  68. });
  69. }
  70. for (var _i4 = 0, _directivesDiff$persi2 = directivesDiff.persisted; _i4 < _directivesDiff$persi2.length; _i4++) {
  71. var _ref2 = _directivesDiff$persi2[_i4];
  72. var _oldDirective = _ref2[0];
  73. var newDirective = _ref2[1];
  74. var argsDiff = diff(_oldDirective.args, newDirective.args);
  75. for (var _i6 = 0, _argsDiff$added2 = argsDiff.added; _i6 < _argsDiff$added2.length; _i6++) {
  76. var newArg = _argsDiff$added2[_i6];
  77. if (isRequiredArgument(newArg)) {
  78. schemaChanges.push({
  79. type: BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
  80. description: "A required arg ".concat(newArg.name, " on directive ").concat(_oldDirective.name, " was added.")
  81. });
  82. }
  83. }
  84. for (var _i8 = 0, _argsDiff$removed2 = argsDiff.removed; _i8 < _argsDiff$removed2.length; _i8++) {
  85. var oldArg = _argsDiff$removed2[_i8];
  86. schemaChanges.push({
  87. type: BreakingChangeType.DIRECTIVE_ARG_REMOVED,
  88. description: "".concat(oldArg.name, " was removed from ").concat(_oldDirective.name, ".")
  89. });
  90. }
  91. for (var _i10 = 0, _oldDirective$locatio2 = _oldDirective.locations; _i10 < _oldDirective$locatio2.length; _i10++) {
  92. var location = _oldDirective$locatio2[_i10];
  93. if (newDirective.locations.indexOf(location) === -1) {
  94. schemaChanges.push({
  95. type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
  96. description: "".concat(location, " was removed from ").concat(_oldDirective.name, ".")
  97. });
  98. }
  99. }
  100. }
  101. return schemaChanges;
  102. }
  103. function findTypeChanges(oldSchema, newSchema) {
  104. var schemaChanges = [];
  105. var typesDiff = diff(objectValues(oldSchema.getTypeMap()), objectValues(newSchema.getTypeMap()));
  106. for (var _i12 = 0, _typesDiff$removed2 = typesDiff.removed; _i12 < _typesDiff$removed2.length; _i12++) {
  107. var oldType = _typesDiff$removed2[_i12];
  108. schemaChanges.push({
  109. type: BreakingChangeType.TYPE_REMOVED,
  110. description: "".concat(oldType.name, " was removed.")
  111. });
  112. }
  113. for (var _i14 = 0, _typesDiff$persisted2 = typesDiff.persisted; _i14 < _typesDiff$persisted2.length; _i14++) {
  114. var _ref4 = _typesDiff$persisted2[_i14];
  115. var _oldType = _ref4[0];
  116. var newType = _ref4[1];
  117. if (isEnumType(_oldType) && isEnumType(newType)) {
  118. schemaChanges.push.apply(schemaChanges, findEnumTypeChanges(_oldType, newType));
  119. } else if (isUnionType(_oldType) && isUnionType(newType)) {
  120. schemaChanges.push.apply(schemaChanges, findUnionTypeChanges(_oldType, newType));
  121. } else if (isInputObjectType(_oldType) && isInputObjectType(newType)) {
  122. schemaChanges.push.apply(schemaChanges, findInputObjectTypeChanges(_oldType, newType));
  123. } else if (isObjectType(_oldType) && isObjectType(newType)) {
  124. schemaChanges.push.apply(schemaChanges, findObjectTypeChanges(_oldType, newType));
  125. } else if (isInterfaceType(_oldType) && isInterfaceType(newType)) {
  126. schemaChanges.push.apply(schemaChanges, findFieldChanges(_oldType, newType));
  127. } else if (_oldType.constructor !== newType.constructor) {
  128. schemaChanges.push({
  129. type: BreakingChangeType.TYPE_CHANGED_KIND,
  130. description: "".concat(_oldType.name, " changed from ") + "".concat(typeKindName(_oldType), " to ").concat(typeKindName(newType), ".")
  131. });
  132. }
  133. }
  134. return schemaChanges;
  135. }
  136. function findInputObjectTypeChanges(oldType, newType) {
  137. var schemaChanges = [];
  138. var fieldsDiff = diff(objectValues(oldType.getFields()), objectValues(newType.getFields()));
  139. for (var _i16 = 0, _fieldsDiff$added2 = fieldsDiff.added; _i16 < _fieldsDiff$added2.length; _i16++) {
  140. var newField = _fieldsDiff$added2[_i16];
  141. if (isRequiredInputField(newField)) {
  142. schemaChanges.push({
  143. type: BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
  144. description: "A required field ".concat(newField.name, " on input type ").concat(oldType.name, " was added.")
  145. });
  146. } else {
  147. schemaChanges.push({
  148. type: DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
  149. description: "An optional field ".concat(newField.name, " on input type ").concat(oldType.name, " was added.")
  150. });
  151. }
  152. }
  153. for (var _i18 = 0, _fieldsDiff$removed2 = fieldsDiff.removed; _i18 < _fieldsDiff$removed2.length; _i18++) {
  154. var oldField = _fieldsDiff$removed2[_i18];
  155. schemaChanges.push({
  156. type: BreakingChangeType.FIELD_REMOVED,
  157. description: "".concat(oldType.name, ".").concat(oldField.name, " was removed.")
  158. });
  159. }
  160. for (var _i20 = 0, _fieldsDiff$persisted2 = fieldsDiff.persisted; _i20 < _fieldsDiff$persisted2.length; _i20++) {
  161. var _ref6 = _fieldsDiff$persisted2[_i20];
  162. var _oldField = _ref6[0];
  163. var _newField = _ref6[1];
  164. var isSafe = isChangeSafeForInputObjectFieldOrFieldArg(_oldField.type, _newField.type);
  165. if (!isSafe) {
  166. schemaChanges.push({
  167. type: BreakingChangeType.FIELD_CHANGED_KIND,
  168. description: "".concat(oldType.name, ".").concat(_oldField.name, " changed type from ") + "".concat(String(_oldField.type), " to ").concat(String(_newField.type), ".")
  169. });
  170. }
  171. }
  172. return schemaChanges;
  173. }
  174. function findUnionTypeChanges(oldType, newType) {
  175. var schemaChanges = [];
  176. var possibleTypesDiff = diff(oldType.getTypes(), newType.getTypes());
  177. for (var _i22 = 0, _possibleTypesDiff$ad2 = possibleTypesDiff.added; _i22 < _possibleTypesDiff$ad2.length; _i22++) {
  178. var newPossibleType = _possibleTypesDiff$ad2[_i22];
  179. schemaChanges.push({
  180. type: DangerousChangeType.TYPE_ADDED_TO_UNION,
  181. description: "".concat(newPossibleType.name, " was added to union type ").concat(oldType.name, ".")
  182. });
  183. }
  184. for (var _i24 = 0, _possibleTypesDiff$re2 = possibleTypesDiff.removed; _i24 < _possibleTypesDiff$re2.length; _i24++) {
  185. var oldPossibleType = _possibleTypesDiff$re2[_i24];
  186. schemaChanges.push({
  187. type: BreakingChangeType.TYPE_REMOVED_FROM_UNION,
  188. description: "".concat(oldPossibleType.name, " was removed from union type ").concat(oldType.name, ".")
  189. });
  190. }
  191. return schemaChanges;
  192. }
  193. function findEnumTypeChanges(oldType, newType) {
  194. var schemaChanges = [];
  195. var valuesDiff = diff(oldType.getValues(), newType.getValues());
  196. for (var _i26 = 0, _valuesDiff$added2 = valuesDiff.added; _i26 < _valuesDiff$added2.length; _i26++) {
  197. var newValue = _valuesDiff$added2[_i26];
  198. schemaChanges.push({
  199. type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
  200. description: "".concat(newValue.name, " was added to enum type ").concat(oldType.name, ".")
  201. });
  202. }
  203. for (var _i28 = 0, _valuesDiff$removed2 = valuesDiff.removed; _i28 < _valuesDiff$removed2.length; _i28++) {
  204. var oldValue = _valuesDiff$removed2[_i28];
  205. schemaChanges.push({
  206. type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
  207. description: "".concat(oldValue.name, " was removed from enum type ").concat(oldType.name, ".")
  208. });
  209. }
  210. return schemaChanges;
  211. }
  212. function findObjectTypeChanges(oldType, newType) {
  213. var schemaChanges = findFieldChanges(oldType, newType);
  214. var interfacesDiff = diff(oldType.getInterfaces(), newType.getInterfaces());
  215. for (var _i30 = 0, _interfacesDiff$added2 = interfacesDiff.added; _i30 < _interfacesDiff$added2.length; _i30++) {
  216. var newInterface = _interfacesDiff$added2[_i30];
  217. schemaChanges.push({
  218. type: DangerousChangeType.INTERFACE_ADDED_TO_OBJECT,
  219. description: "".concat(newInterface.name, " added to interfaces implemented by ").concat(oldType.name, ".")
  220. });
  221. }
  222. for (var _i32 = 0, _interfacesDiff$remov2 = interfacesDiff.removed; _i32 < _interfacesDiff$remov2.length; _i32++) {
  223. var oldInterface = _interfacesDiff$remov2[_i32];
  224. schemaChanges.push({
  225. type: BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
  226. description: "".concat(oldType.name, " no longer implements interface ").concat(oldInterface.name, ".")
  227. });
  228. }
  229. return schemaChanges;
  230. }
  231. function findFieldChanges(oldType, newType) {
  232. var schemaChanges = [];
  233. var fieldsDiff = diff(objectValues(oldType.getFields()), objectValues(newType.getFields()));
  234. for (var _i34 = 0, _fieldsDiff$removed4 = fieldsDiff.removed; _i34 < _fieldsDiff$removed4.length; _i34++) {
  235. var oldField = _fieldsDiff$removed4[_i34];
  236. schemaChanges.push({
  237. type: BreakingChangeType.FIELD_REMOVED,
  238. description: "".concat(oldType.name, ".").concat(oldField.name, " was removed.")
  239. });
  240. }
  241. for (var _i36 = 0, _fieldsDiff$persisted4 = fieldsDiff.persisted; _i36 < _fieldsDiff$persisted4.length; _i36++) {
  242. var _ref8 = _fieldsDiff$persisted4[_i36];
  243. var _oldField2 = _ref8[0];
  244. var newField = _ref8[1];
  245. schemaChanges.push.apply(schemaChanges, findArgChanges(oldType, _oldField2, newField));
  246. var isSafe = isChangeSafeForObjectOrInterfaceField(_oldField2.type, newField.type);
  247. if (!isSafe) {
  248. schemaChanges.push({
  249. type: BreakingChangeType.FIELD_CHANGED_KIND,
  250. description: "".concat(oldType.name, ".").concat(_oldField2.name, " changed type from ") + "".concat(String(_oldField2.type), " to ").concat(String(newField.type), ".")
  251. });
  252. }
  253. }
  254. return schemaChanges;
  255. }
  256. function findArgChanges(oldType, oldField, newField) {
  257. var schemaChanges = [];
  258. var argsDiff = diff(oldField.args, newField.args);
  259. for (var _i38 = 0, _argsDiff$removed4 = argsDiff.removed; _i38 < _argsDiff$removed4.length; _i38++) {
  260. var oldArg = _argsDiff$removed4[_i38];
  261. schemaChanges.push({
  262. type: BreakingChangeType.ARG_REMOVED,
  263. description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(oldArg.name, " was removed.")
  264. });
  265. }
  266. for (var _i40 = 0, _argsDiff$persisted2 = argsDiff.persisted; _i40 < _argsDiff$persisted2.length; _i40++) {
  267. var _ref10 = _argsDiff$persisted2[_i40];
  268. var _oldArg = _ref10[0];
  269. var newArg = _ref10[1];
  270. var isSafe = isChangeSafeForInputObjectFieldOrFieldArg(_oldArg.type, newArg.type);
  271. if (!isSafe) {
  272. schemaChanges.push({
  273. type: BreakingChangeType.ARG_CHANGED_KIND,
  274. description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " has changed type from ") + "".concat(String(_oldArg.type), " to ").concat(String(newArg.type), ".")
  275. });
  276. } else if (_oldArg.defaultValue !== undefined) {
  277. if (newArg.defaultValue === undefined) {
  278. schemaChanges.push({
  279. type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
  280. description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " defaultValue was removed.")
  281. });
  282. } else {
  283. // Since we looking only for client's observable changes we should
  284. // compare default values in the same representation as they are
  285. // represented inside introspection.
  286. var oldValueStr = stringifyValue(_oldArg.defaultValue, _oldArg.type);
  287. var newValueStr = stringifyValue(newArg.defaultValue, newArg.type);
  288. if (oldValueStr !== newValueStr) {
  289. schemaChanges.push({
  290. type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
  291. description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " has changed defaultValue from ").concat(oldValueStr, " to ").concat(newValueStr, ".")
  292. });
  293. }
  294. }
  295. }
  296. }
  297. for (var _i42 = 0, _argsDiff$added4 = argsDiff.added; _i42 < _argsDiff$added4.length; _i42++) {
  298. var _newArg = _argsDiff$added4[_i42];
  299. if (isRequiredArgument(_newArg)) {
  300. schemaChanges.push({
  301. type: BreakingChangeType.REQUIRED_ARG_ADDED,
  302. description: "A required arg ".concat(_newArg.name, " on ").concat(oldType.name, ".").concat(oldField.name, " was added.")
  303. });
  304. } else {
  305. schemaChanges.push({
  306. type: DangerousChangeType.OPTIONAL_ARG_ADDED,
  307. description: "An optional arg ".concat(_newArg.name, " on ").concat(oldType.name, ".").concat(oldField.name, " was added.")
  308. });
  309. }
  310. }
  311. return schemaChanges;
  312. }
  313. function isChangeSafeForObjectOrInterfaceField(oldType, newType) {
  314. if (isListType(oldType)) {
  315. return (// if they're both lists, make sure the underlying types are compatible
  316. isListType(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType) || // moving from nullable to non-null of the same underlying type is safe
  317. isNonNullType(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)
  318. );
  319. }
  320. if (isNonNullType(oldType)) {
  321. // if they're both non-null, make sure the underlying types are compatible
  322. return isNonNullType(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType);
  323. }
  324. return (// if they're both named types, see if their names are equivalent
  325. isNamedType(newType) && oldType.name === newType.name || // moving from nullable to non-null of the same underlying type is safe
  326. isNonNullType(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)
  327. );
  328. }
  329. function isChangeSafeForInputObjectFieldOrFieldArg(oldType, newType) {
  330. if (isListType(oldType)) {
  331. // if they're both lists, make sure the underlying types are compatible
  332. return isListType(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType);
  333. }
  334. if (isNonNullType(oldType)) {
  335. return (// if they're both non-null, make sure the underlying types are
  336. // compatible
  337. isNonNullType(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType) || // moving from non-null to nullable of the same underlying type is safe
  338. !isNonNullType(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType)
  339. );
  340. } // if they're both named types, see if their names are equivalent
  341. return isNamedType(newType) && oldType.name === newType.name;
  342. }
  343. function typeKindName(type) {
  344. if (isScalarType(type)) {
  345. return 'a Scalar type';
  346. }
  347. if (isObjectType(type)) {
  348. return 'an Object type';
  349. }
  350. if (isInterfaceType(type)) {
  351. return 'an Interface type';
  352. }
  353. if (isUnionType(type)) {
  354. return 'a Union type';
  355. }
  356. if (isEnumType(type)) {
  357. return 'an Enum type';
  358. }
  359. /* istanbul ignore else */
  360. if (isInputObjectType(type)) {
  361. return 'an Input type';
  362. } // Not reachable. All possible named types have been considered.
  363. /* istanbul ignore next */
  364. invariant(false, 'Unexpected type: ' + inspect(type));
  365. }
  366. function stringifyValue(value, type) {
  367. var ast = astFromValue(value, type);
  368. /* istanbul ignore next */
  369. ast != null || invariant(0);
  370. var sortedAST = visit(ast, {
  371. ObjectValue: function ObjectValue(objectNode) {
  372. var fields = [].concat(objectNode.fields).sort(function (fieldA, fieldB) {
  373. return fieldA.name.value.localeCompare(fieldB.name.value);
  374. });
  375. return _objectSpread({}, objectNode, {
  376. fields: fields
  377. });
  378. }
  379. });
  380. return print(sortedAST);
  381. }
  382. function diff(oldArray, newArray) {
  383. var added = [];
  384. var removed = [];
  385. var persisted = [];
  386. var oldMap = keyMap(oldArray, function (_ref11) {
  387. var name = _ref11.name;
  388. return name;
  389. });
  390. var newMap = keyMap(newArray, function (_ref12) {
  391. var name = _ref12.name;
  392. return name;
  393. });
  394. for (var _i44 = 0; _i44 < oldArray.length; _i44++) {
  395. var oldItem = oldArray[_i44];
  396. var newItem = newMap[oldItem.name];
  397. if (newItem === undefined) {
  398. removed.push(oldItem);
  399. } else {
  400. persisted.push([oldItem, newItem]);
  401. }
  402. }
  403. for (var _i46 = 0; _i46 < newArray.length; _i46++) {
  404. var _newItem = newArray[_i46];
  405. if (oldMap[_newItem.name] === undefined) {
  406. added.push(_newItem);
  407. }
  408. }
  409. return {
  410. added: added,
  411. persisted: persisted,
  412. removed: removed
  413. };
  414. }