@ember-data/model 4.7.0-beta.1 → 4.8.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,10 +29,8 @@ export default function modelForMixin(store: Store, normalizedModelName: string)
29
29
  let mixin = MaybeMixin && MaybeMixin.class;
30
30
  if (mixin) {
31
31
  let ModelForMixin = Model.extend(mixin);
32
- ModelForMixin.reopenClass({
33
- __isMixin: true,
34
- __mixin: mixin,
35
- });
32
+ ModelForMixin.__isMixin = true;
33
+ ModelForMixin.__mixin = mixin;
36
34
  //Cache the class as a model
37
35
  owner.register('model:' + normalizedModelName, ModelForMixin);
38
36
  }
@@ -2,7 +2,7 @@
2
2
  @module @ember-data/model
3
3
  */
4
4
 
5
- import { assert, warn } from '@ember/debug';
5
+ import { assert, deprecate, warn } from '@ember/debug';
6
6
  import EmberError from '@ember/error';
7
7
  import EmberObject, { get } from '@ember/object';
8
8
  import { dependentKeyCompat } from '@ember/object/compat';
@@ -16,16 +16,13 @@ import Ember from 'ember';
16
16
  import { resolve } from 'rsvp';
17
17
 
18
18
  import { HAS_DEBUG_PACKAGE } from '@ember-data/private-build-infra';
19
- import { DEPRECATE_SAVE_PROMISE_ACCESS } from '@ember-data/private-build-infra/deprecations';
20
- import { recordIdentifierFor, storeFor } from '@ember-data/store';
21
19
  import {
22
- coerceId,
23
- deprecatedPromiseObject,
24
- errorsArrayToHash,
25
- InternalModel,
26
- recordDataFor,
27
- WeakCache,
28
- } from '@ember-data/store/-private';
20
+ DEPRECATE_EARLY_STATIC,
21
+ DEPRECATE_MODEL_REOPEN,
22
+ DEPRECATE_SAVE_PROMISE_ACCESS,
23
+ } from '@ember-data/private-build-infra/deprecations';
24
+ import { recordIdentifierFor, storeFor } from '@ember-data/store';
25
+ import { coerceId, deprecatedPromiseObject, InternalModel, WeakCache } from '@ember-data/store/-private';
29
26
 
30
27
  import Errors from './errors';
31
28
  import { LegacySupport } from './legacy-relationships-support';
@@ -565,22 +562,7 @@ class Model extends EmberObject {
565
562
  @computeOnce
566
563
  get errors() {
567
564
  let errors = Errors.create({ __record: this });
568
- // TODO we should unify how errors gets populated
569
- // with the code managing the update. Probably a
570
- // lazy flush similar to retrieveLatest in ManyArray
571
- let recordData = recordDataFor(this);
572
- let jsonApiErrors;
573
- if (recordData.getErrors) {
574
- jsonApiErrors = recordData.getErrors();
575
- if (jsonApiErrors) {
576
- let errorsHash = errorsArrayToHash(jsonApiErrors);
577
- let errorKeys = Object.keys(errorsHash);
578
-
579
- for (let i = 0; i < errorKeys.length; i++) {
580
- errors.add(errorKeys[i], errorsHash[errorKeys[i]]);
581
- }
582
- }
583
- }
565
+ this.currentState.updateInvalidErrors(errors);
584
566
  return errors;
585
567
  }
586
568
 
@@ -1258,12 +1240,46 @@ class Model extends EmberObject {
1258
1240
  @return {Model} the type of the relationship, or undefined
1259
1241
  */
1260
1242
  static typeForRelationship(name, store) {
1243
+ if (DEPRECATE_EARLY_STATIC) {
1244
+ deprecate(
1245
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1246
+ this.modelName,
1247
+ {
1248
+ id: 'ember-data:deprecate-early-static',
1249
+ for: 'ember-data',
1250
+ until: '5.0',
1251
+ since: { available: '4.8', enabled: '4.8' },
1252
+ }
1253
+ );
1254
+ } else {
1255
+ assert(
1256
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1257
+ this.modelName
1258
+ );
1259
+ }
1261
1260
  let relationship = this.relationshipsByName.get(name);
1262
1261
  return relationship && store.modelFor(relationship.type);
1263
1262
  }
1264
1263
 
1265
1264
  @computeOnce
1266
1265
  static get inverseMap() {
1266
+ if (DEPRECATE_EARLY_STATIC) {
1267
+ deprecate(
1268
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1269
+ this.modelName,
1270
+ {
1271
+ id: 'ember-data:deprecate-early-static',
1272
+ for: 'ember-data',
1273
+ until: '5.0',
1274
+ since: { available: '4.8', enabled: '4.8' },
1275
+ }
1276
+ );
1277
+ } else {
1278
+ assert(
1279
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1280
+ this.modelName
1281
+ );
1282
+ }
1267
1283
  return Object.create(null);
1268
1284
  }
1269
1285
 
@@ -1301,6 +1317,23 @@ class Model extends EmberObject {
1301
1317
  @return {Object} the inverse relationship, or null
1302
1318
  */
1303
1319
  static inverseFor(name, store) {
1320
+ if (DEPRECATE_EARLY_STATIC) {
1321
+ deprecate(
1322
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1323
+ this.modelName,
1324
+ {
1325
+ id: 'ember-data:deprecate-early-static',
1326
+ for: 'ember-data',
1327
+ until: '5.0',
1328
+ since: { available: '4.8', enabled: '4.8' },
1329
+ }
1330
+ );
1331
+ } else {
1332
+ assert(
1333
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1334
+ this.modelName
1335
+ );
1336
+ }
1304
1337
  let inverseMap = this.inverseMap;
1305
1338
  if (inverseMap[name]) {
1306
1339
  return inverseMap[name];
@@ -1313,6 +1346,23 @@ class Model extends EmberObject {
1313
1346
 
1314
1347
  //Calculate the inverse, ignoring the cache
1315
1348
  static _findInverseFor(name, store) {
1349
+ if (DEPRECATE_EARLY_STATIC) {
1350
+ deprecate(
1351
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1352
+ this.modelName,
1353
+ {
1354
+ id: 'ember-data:deprecate-early-static',
1355
+ for: 'ember-data',
1356
+ until: '5.0',
1357
+ since: { available: '4.8', enabled: '4.8' },
1358
+ }
1359
+ );
1360
+ } else {
1361
+ assert(
1362
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1363
+ this.modelName
1364
+ );
1365
+ }
1316
1366
  let inverseType = this.typeForRelationship(name, store);
1317
1367
  if (!inverseType) {
1318
1368
  return null;
@@ -1457,6 +1507,23 @@ class Model extends EmberObject {
1457
1507
 
1458
1508
  @computeOnce
1459
1509
  static get relationships() {
1510
+ if (DEPRECATE_EARLY_STATIC) {
1511
+ deprecate(
1512
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1513
+ this.modelName,
1514
+ {
1515
+ id: 'ember-data:deprecate-early-static',
1516
+ for: 'ember-data',
1517
+ until: '5.0',
1518
+ since: { available: '4.8', enabled: '4.8' },
1519
+ }
1520
+ );
1521
+ } else {
1522
+ assert(
1523
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1524
+ this.modelName
1525
+ );
1526
+ }
1460
1527
  let map = new Map();
1461
1528
  let relationshipsByName = this.relationshipsByName;
1462
1529
 
@@ -1511,6 +1578,23 @@ class Model extends EmberObject {
1511
1578
  */
1512
1579
  @computeOnce
1513
1580
  static get relationshipNames() {
1581
+ if (DEPRECATE_EARLY_STATIC) {
1582
+ deprecate(
1583
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1584
+ this.modelName,
1585
+ {
1586
+ id: 'ember-data:deprecate-early-static',
1587
+ for: 'ember-data',
1588
+ until: '5.0',
1589
+ since: { available: '4.8', enabled: '4.8' },
1590
+ }
1591
+ );
1592
+ } else {
1593
+ assert(
1594
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1595
+ this.modelName
1596
+ );
1597
+ }
1514
1598
  let names = {
1515
1599
  hasMany: [],
1516
1600
  belongsTo: [],
@@ -1561,6 +1645,23 @@ class Model extends EmberObject {
1561
1645
  */
1562
1646
  @computeOnce
1563
1647
  static get relatedTypes() {
1648
+ if (DEPRECATE_EARLY_STATIC) {
1649
+ deprecate(
1650
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1651
+ this.modelName,
1652
+ {
1653
+ id: 'ember-data:deprecate-early-static',
1654
+ for: 'ember-data',
1655
+ until: '5.0',
1656
+ since: { available: '4.8', enabled: '4.8' },
1657
+ }
1658
+ );
1659
+ } else {
1660
+ assert(
1661
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1662
+ this.modelName
1663
+ );
1664
+ }
1564
1665
  let types = [];
1565
1666
 
1566
1667
  let rels = this.relationshipsObject;
@@ -1620,6 +1721,23 @@ class Model extends EmberObject {
1620
1721
  */
1621
1722
  @computeOnce
1622
1723
  static get relationshipsByName() {
1724
+ if (DEPRECATE_EARLY_STATIC) {
1725
+ deprecate(
1726
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1727
+ this.modelName,
1728
+ {
1729
+ id: 'ember-data:deprecate-early-static',
1730
+ for: 'ember-data',
1731
+ until: '5.0',
1732
+ since: { available: '4.8', enabled: '4.8' },
1733
+ }
1734
+ );
1735
+ } else {
1736
+ assert(
1737
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1738
+ this.modelName
1739
+ );
1740
+ }
1623
1741
  let map = new Map();
1624
1742
  let rels = this.relationshipsObject;
1625
1743
  let relationships = Object.keys(rels);
@@ -1636,6 +1754,23 @@ class Model extends EmberObject {
1636
1754
 
1637
1755
  @computeOnce
1638
1756
  static get relationshipsObject() {
1757
+ if (DEPRECATE_EARLY_STATIC) {
1758
+ deprecate(
1759
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1760
+ this.modelName,
1761
+ {
1762
+ id: 'ember-data:deprecate-early-static',
1763
+ for: 'ember-data',
1764
+ until: '5.0',
1765
+ since: { available: '4.8', enabled: '4.8' },
1766
+ }
1767
+ );
1768
+ } else {
1769
+ assert(
1770
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1771
+ this.modelName
1772
+ );
1773
+ }
1639
1774
  let relationships = Object.create(null);
1640
1775
  let modelName = this.modelName;
1641
1776
  this.eachComputedProperty((name, meta) => {
@@ -1693,6 +1828,23 @@ class Model extends EmberObject {
1693
1828
  */
1694
1829
  @computeOnce
1695
1830
  static get fields() {
1831
+ if (DEPRECATE_EARLY_STATIC) {
1832
+ deprecate(
1833
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1834
+ this.modelName,
1835
+ {
1836
+ id: 'ember-data:deprecate-early-static',
1837
+ for: 'ember-data',
1838
+ until: '5.0',
1839
+ since: { available: '4.8', enabled: '4.8' },
1840
+ }
1841
+ );
1842
+ } else {
1843
+ assert(
1844
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1845
+ this.modelName
1846
+ );
1847
+ }
1696
1848
  let map = new Map();
1697
1849
 
1698
1850
  this.eachComputedProperty((name, meta) => {
@@ -1718,6 +1870,23 @@ class Model extends EmberObject {
1718
1870
  @param {any} binding the value to which the callback's `this` should be bound
1719
1871
  */
1720
1872
  static eachRelationship(callback, binding) {
1873
+ if (DEPRECATE_EARLY_STATIC) {
1874
+ deprecate(
1875
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1876
+ this.modelName,
1877
+ {
1878
+ id: 'ember-data:deprecate-early-static',
1879
+ for: 'ember-data',
1880
+ until: '5.0',
1881
+ since: { available: '4.8', enabled: '4.8' },
1882
+ }
1883
+ );
1884
+ } else {
1885
+ assert(
1886
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1887
+ this.modelName
1888
+ );
1889
+ }
1721
1890
  this.relationshipsByName.forEach((relationship, name) => {
1722
1891
  callback.call(binding, name, relationship);
1723
1892
  });
@@ -1736,6 +1905,23 @@ class Model extends EmberObject {
1736
1905
  @param {any} binding the value to which the callback's `this` should be bound
1737
1906
  */
1738
1907
  static eachRelatedType(callback, binding) {
1908
+ if (DEPRECATE_EARLY_STATIC) {
1909
+ deprecate(
1910
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1911
+ this.modelName,
1912
+ {
1913
+ id: 'ember-data:deprecate-early-static',
1914
+ for: 'ember-data',
1915
+ until: '5.0',
1916
+ since: { available: '4.8', enabled: '4.8' },
1917
+ }
1918
+ );
1919
+ } else {
1920
+ assert(
1921
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1922
+ this.modelName
1923
+ );
1924
+ }
1739
1925
  let relationshipTypes = this.relatedTypes;
1740
1926
 
1741
1927
  for (let i = 0; i < relationshipTypes.length; i++) {
@@ -1745,6 +1931,23 @@ class Model extends EmberObject {
1745
1931
  }
1746
1932
 
1747
1933
  static determineRelationshipType(knownSide, store) {
1934
+ if (DEPRECATE_EARLY_STATIC) {
1935
+ deprecate(
1936
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
1937
+ this.modelName,
1938
+ {
1939
+ id: 'ember-data:deprecate-early-static',
1940
+ for: 'ember-data',
1941
+ until: '5.0',
1942
+ since: { available: '4.8', enabled: '4.8' },
1943
+ }
1944
+ );
1945
+ } else {
1946
+ assert(
1947
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
1948
+ this.modelName
1949
+ );
1950
+ }
1748
1951
  let knownKey = knownSide.key;
1749
1952
  let knownKind = knownSide.kind;
1750
1953
  let inverse = this.inverseFor(knownKey, store);
@@ -1806,6 +2009,23 @@ class Model extends EmberObject {
1806
2009
  */
1807
2010
  @computeOnce
1808
2011
  static get attributes() {
2012
+ if (DEPRECATE_EARLY_STATIC) {
2013
+ deprecate(
2014
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
2015
+ this.modelName,
2016
+ {
2017
+ id: 'ember-data:deprecate-early-static',
2018
+ for: 'ember-data',
2019
+ until: '5.0',
2020
+ since: { available: '4.8', enabled: '4.8' },
2021
+ }
2022
+ );
2023
+ } else {
2024
+ assert(
2025
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
2026
+ this.modelName
2027
+ );
2028
+ }
1809
2029
  let map = new Map();
1810
2030
 
1811
2031
  this.eachComputedProperty((name, meta) => {
@@ -1865,6 +2085,23 @@ class Model extends EmberObject {
1865
2085
  */
1866
2086
  @computeOnce
1867
2087
  static get transformedAttributes() {
2088
+ if (DEPRECATE_EARLY_STATIC) {
2089
+ deprecate(
2090
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
2091
+ this.modelName,
2092
+ {
2093
+ id: 'ember-data:deprecate-early-static',
2094
+ for: 'ember-data',
2095
+ until: '5.0',
2096
+ since: { available: '4.8', enabled: '4.8' },
2097
+ }
2098
+ );
2099
+ } else {
2100
+ assert(
2101
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
2102
+ this.modelName
2103
+ );
2104
+ }
1868
2105
  let map = new Map();
1869
2106
 
1870
2107
  this.eachAttribute((key, meta) => {
@@ -1921,6 +2158,23 @@ class Model extends EmberObject {
1921
2158
  @static
1922
2159
  */
1923
2160
  static eachAttribute(callback, binding) {
2161
+ if (DEPRECATE_EARLY_STATIC) {
2162
+ deprecate(
2163
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
2164
+ this.modelName,
2165
+ {
2166
+ id: 'ember-data:deprecate-early-static',
2167
+ for: 'ember-data',
2168
+ until: '5.0',
2169
+ since: { available: '4.8', enabled: '4.8' },
2170
+ }
2171
+ );
2172
+ } else {
2173
+ assert(
2174
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
2175
+ this.modelName
2176
+ );
2177
+ }
1924
2178
  this.attributes.forEach((meta, name) => {
1925
2179
  callback.call(binding, name, meta);
1926
2180
  });
@@ -1972,6 +2226,23 @@ class Model extends EmberObject {
1972
2226
  @static
1973
2227
  */
1974
2228
  static eachTransformedAttribute(callback, binding) {
2229
+ if (DEPRECATE_EARLY_STATIC) {
2230
+ deprecate(
2231
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
2232
+ this.modelName,
2233
+ {
2234
+ id: 'ember-data:deprecate-early-static',
2235
+ for: 'ember-data',
2236
+ until: '5.0',
2237
+ since: { available: '4.8', enabled: '4.8' },
2238
+ }
2239
+ );
2240
+ } else {
2241
+ assert(
2242
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
2243
+ this.modelName
2244
+ );
2245
+ }
1975
2246
  this.transformedAttributes.forEach((type, name) => {
1976
2247
  callback.call(binding, name, type);
1977
2248
  });
@@ -1985,6 +2256,23 @@ class Model extends EmberObject {
1985
2256
  @static
1986
2257
  */
1987
2258
  static toString() {
2259
+ if (DEPRECATE_EARLY_STATIC) {
2260
+ deprecate(
2261
+ `Accessing schema information on Models without looking up the model via the store is deprecated. Use store.modelFor (or better Snapshots or the store.getSchemaDefinitionService() apis) instead.`,
2262
+ this.modelName,
2263
+ {
2264
+ id: 'ember-data:deprecate-early-static',
2265
+ for: 'ember-data',
2266
+ until: '5.0',
2267
+ since: { available: '4.8', enabled: '4.8' },
2268
+ }
2269
+ );
2270
+ } else {
2271
+ assert(
2272
+ `Accessing schema information on Models without looking up the model via the store is disallowed.`,
2273
+ this.modelName
2274
+ );
2275
+ }
1988
2276
  return `model:${get(this, 'modelName')}`;
1989
2277
  }
1990
2278
  }
@@ -2111,6 +2399,35 @@ if (DEBUG) {
2111
2399
  }
2112
2400
  },
2113
2401
  });
2402
+
2403
+ if (DEPRECATE_MODEL_REOPEN) {
2404
+ const originalReopen = Model.reopen;
2405
+ const originalReopenClass = Model.reopenClass;
2406
+
2407
+ Model.reopen = function deprecatedReopen() {
2408
+ deprecate(`Model.reopen is deprecated. Use Foo extends Model to extend your class instead.`, false, {
2409
+ id: 'ember-data:deprecate-model-reopen',
2410
+ for: 'ember-data',
2411
+ until: '5.0',
2412
+ since: { available: '4.8', enabled: '4.8' },
2413
+ });
2414
+ return originalReopen.call(this, arguments);
2415
+ };
2416
+
2417
+ Model.reopenClass = function deprecatedReopenClass() {
2418
+ deprecate(
2419
+ `Model.reopenClass is deprecated. Use Foo extends Model to add static methods and properties to your class instead.`,
2420
+ false,
2421
+ {
2422
+ id: 'ember-data:deprecate-model-reopenclass',
2423
+ for: 'ember-data',
2424
+ until: '5.0',
2425
+ since: { available: '4.8', enabled: '4.8' },
2426
+ }
2427
+ );
2428
+ return originalReopenClass.call(this, arguments);
2429
+ };
2430
+ }
2114
2431
  }
2115
2432
 
2116
2433
  export default Model;
@@ -5,7 +5,7 @@ import { cached, tracked } from '@glimmer/tracking';
5
5
 
6
6
  import type Store from '@ember-data/store';
7
7
  import { storeFor } from '@ember-data/store';
8
- import { errorsArrayToHash, recordIdentifierFor } from '@ember-data/store/-private';
8
+ import { recordIdentifierFor } from '@ember-data/store/-private';
9
9
  import type { NotificationType } from '@ember-data/store/-private/record-notification-manager';
10
10
  import type RequestCache from '@ember-data/store/-private/request-cache';
11
11
  import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
@@ -13,6 +13,9 @@ import type { RecordData } from '@ember-data/types/q/record-data';
13
13
 
14
14
  type Model = InstanceType<typeof import('./model')>;
15
15
 
16
+ const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
17
+ const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
18
+ const PRIMARY_ATTRIBUTE_KEY = 'base';
16
19
  function isInvalidError(error) {
17
20
  return error && error.isAdapterError === true && error.code === 'InvalidError';
18
21
  }
@@ -176,7 +179,6 @@ export default class RecordState {
176
179
  break;
177
180
  case 'rejected':
178
181
  this.isSaving = false;
179
-
180
182
  this._lastError = req;
181
183
  if (!(req.response && isInvalidError(req.response.data))) {
182
184
  this._errorRequests.push(req);
@@ -246,11 +248,7 @@ export default class RecordState {
246
248
  this.notify('isDeleted');
247
249
  break;
248
250
  case 'errors':
249
- // we only hit this if a foreign RecordData notifies
250
- // errors changed. Our own implementation does not
251
- // take this path currently, but we should probably
252
- // fix that.
253
- this.updateInvalidErrors();
251
+ this.updateInvalidErrors(this.record.errors);
254
252
  this.notify('isValid');
255
253
  break;
256
254
  }
@@ -261,16 +259,33 @@ export default class RecordState {
261
259
  getTag(this, key).notify();
262
260
  }
263
261
 
264
- updateInvalidErrors() {
265
- let jsonApiErrors = this.recordData.getErrors!(this.identifier);
262
+ updateInvalidErrors(errors) {
263
+ assert(
264
+ `Expected the RecordData instance for ${this.identifier} to implement getErrors(identifier)`,
265
+ typeof this.recordData.getErrors === 'function'
266
+ );
267
+ let jsonApiErrors = this.recordData.getErrors(this.identifier);
266
268
 
267
- const { errors } = this.record;
268
269
  errors.clear();
269
- let newErrors = errorsArrayToHash(jsonApiErrors);
270
- let errorKeys = Object.keys(newErrors);
271
270
 
272
- for (let i = 0; i < errorKeys.length; i++) {
273
- errors.add(errorKeys[i], newErrors[errorKeys[i]]);
271
+ for (let i = 0; i < jsonApiErrors.length; i++) {
272
+ let error = jsonApiErrors[i];
273
+
274
+ if (error.source && error.source.pointer) {
275
+ let keyMatch = error.source.pointer.match(SOURCE_POINTER_REGEXP);
276
+ let key: string | undefined;
277
+
278
+ if (keyMatch) {
279
+ key = keyMatch[2];
280
+ } else if (error.source.pointer.search(SOURCE_POINTER_PRIMARY_REGEXP) !== -1) {
281
+ key = PRIMARY_ATTRIBUTE_KEY;
282
+ }
283
+
284
+ if (key) {
285
+ let errMsg = error.detail || error.title;
286
+ errors.add(key, errMsg);
287
+ }
288
+ }
274
289
  }
275
290
  }
276
291
 
@@ -1,9 +1,9 @@
1
+ import { dasherize } from '@ember/string';
1
2
  import { DEBUG } from '@glimmer/env';
2
3
 
3
4
  import { singularize } from 'ember-inflector';
4
5
 
5
6
  import type Store from '@ember-data/store';
6
- import { normalizeModelName } from '@ember-data/store/-private';
7
7
  import type { RelationshipSchema } from '@ember-data/types/q/record-data-schemas';
8
8
 
9
9
  /**
@@ -11,7 +11,7 @@ import type { RelationshipSchema } from '@ember-data/types/q/record-data-schemas
11
11
  */
12
12
 
13
13
  function typeForRelationshipMeta(meta) {
14
- let modelName = normalizeModelName(meta.type || meta.key);
14
+ let modelName = dasherize(meta.type || meta.key);
15
15
 
16
16
  if (meta.kind === 'hasMany') {
17
17
  modelName = singularize(modelName);
package/index.js CHANGED
@@ -17,6 +17,7 @@ module.exports = Object.assign({}, addonBaseConfig, {
17
17
  '@ember-data/store/-private',
18
18
  '@ember-data/store/-debug',
19
19
  '@embroider/macros',
20
+ '@ember/string',
20
21
  '@embroider/macros/es-compat',
21
22
 
22
23
  '@ember/application',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/model",
3
- "version": "4.7.0-beta.1",
3
+ "version": "4.8.0-alpha.2",
4
4
  "description": "The default blueprint for ember-cli addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -18,9 +18,9 @@
18
18
  "test:node": "mocha"
19
19
  },
20
20
  "dependencies": {
21
- "@ember-data/canary-features": "4.7.0-beta.1",
22
- "@ember-data/private-build-infra": "4.7.0-beta.1",
23
- "@ember-data/store": "4.7.0-beta.1",
21
+ "@ember-data/canary-features": "4.8.0-alpha.2",
22
+ "@ember-data/private-build-infra": "4.8.0-alpha.2",
23
+ "@ember-data/store": "4.8.0-alpha.2",
24
24
  "@ember/edition-utils": "^1.2.0",
25
25
  "@ember/string": "^3.0.0",
26
26
  "@embroider/macros": "^1.8.3",
@@ -34,7 +34,7 @@
34
34
  "inflection": "~1.13.2"
35
35
  },
36
36
  "devDependencies": {
37
- "@ember-data/unpublished-test-infra": "4.7.0-beta.1",
37
+ "@ember-data/unpublished-test-infra": "4.8.0-alpha.2",
38
38
  "@ember/optional-features": "^2.0.0",
39
39
  "@ember/test-helpers": "~2.7.0",
40
40
  "broccoli-asset-rev": "^3.0.0",