@ember-data/model 4.8.0-beta.0 → 4.8.0
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.
- package/LICENSE.md +3 -1
- package/addon/-private/belongs-to.js +59 -48
- package/addon/-private/debug/assert-polymorphic-type.js +71 -0
- package/addon/-private/deprecated-promise-proxy.ts +29 -7
- package/addon/-private/has-many.js +53 -47
- package/addon/-private/legacy-data-fetch.js +36 -33
- package/addon/-private/legacy-relationships-support.ts +31 -27
- package/addon/-private/many-array.ts +23 -21
- package/addon/-private/model.js +75 -68
- package/addon/-private/promise-many-array.ts +6 -6
- package/addon/-private/record-state.ts +6 -7
- package/addon/-private/references/belongs-to.ts +39 -27
- package/addon/-private/references/has-many.ts +37 -20
- package/addon/-private/relationship-meta.ts +4 -2
- package/addon/index.ts +0 -1
- package/blueprints/model-test/mocha-files/__root__/__path__/__test__.js +4 -3
- package/blueprints/model-test/mocha-rfc-232-files/__root__/__path__/__test__.js +3 -2
- package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +3 -2
- package/index.js +1 -1
- package/package.json +34 -47
- package/config/environment.js +0 -5
package/addon/-private/model.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { assert, deprecate, warn } from '@ember/debug';
|
|
6
|
-
import EmberError from '@ember/error';
|
|
7
6
|
import EmberObject from '@ember/object';
|
|
8
7
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
9
8
|
import { run } from '@ember/runloop';
|
|
@@ -125,10 +124,12 @@ class Model extends EmberObject {
|
|
|
125
124
|
___private_notifications;
|
|
126
125
|
|
|
127
126
|
init(options = {}) {
|
|
128
|
-
if (DEBUG
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
if (DEBUG) {
|
|
128
|
+
if (!options._secretInit && !options._createProps) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
'You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.'
|
|
131
|
+
);
|
|
132
|
+
}
|
|
132
133
|
}
|
|
133
134
|
const createProps = options._createProps;
|
|
134
135
|
const _secretInit = options._secretInit;
|
|
@@ -521,8 +522,10 @@ class Model extends EmberObject {
|
|
|
521
522
|
// when using legacy/classic ember classes. Basically: lazy in prod and eager in dev.
|
|
522
523
|
// so we do this to try to steer folks to the nicer "dont user currentState"
|
|
523
524
|
// error.
|
|
524
|
-
if (!DEBUG
|
|
525
|
-
this.___recordState
|
|
525
|
+
if (!DEBUG) {
|
|
526
|
+
if (!this.___recordState) {
|
|
527
|
+
this.___recordState = new RecordState(this);
|
|
528
|
+
}
|
|
526
529
|
}
|
|
527
530
|
return this.___recordState;
|
|
528
531
|
}
|
|
@@ -1279,7 +1282,7 @@ class Model extends EmberObject {
|
|
|
1279
1282
|
id: 'ember-data:deprecate-early-static',
|
|
1280
1283
|
for: 'ember-data',
|
|
1281
1284
|
until: '5.0',
|
|
1282
|
-
since: { available: '4.
|
|
1285
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1283
1286
|
}
|
|
1284
1287
|
);
|
|
1285
1288
|
} else {
|
|
@@ -1302,7 +1305,7 @@ class Model extends EmberObject {
|
|
|
1302
1305
|
id: 'ember-data:deprecate-early-static',
|
|
1303
1306
|
for: 'ember-data',
|
|
1304
1307
|
until: '5.0',
|
|
1305
|
-
since: { available: '4.
|
|
1308
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1306
1309
|
}
|
|
1307
1310
|
);
|
|
1308
1311
|
} else {
|
|
@@ -1356,7 +1359,7 @@ class Model extends EmberObject {
|
|
|
1356
1359
|
id: 'ember-data:deprecate-early-static',
|
|
1357
1360
|
for: 'ember-data',
|
|
1358
1361
|
until: '5.0',
|
|
1359
|
-
since: { available: '4.
|
|
1362
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1360
1363
|
}
|
|
1361
1364
|
);
|
|
1362
1365
|
} else {
|
|
@@ -1385,7 +1388,7 @@ class Model extends EmberObject {
|
|
|
1385
1388
|
id: 'ember-data:deprecate-early-static',
|
|
1386
1389
|
for: 'ember-data',
|
|
1387
1390
|
until: '5.0',
|
|
1388
|
-
since: { available: '4.
|
|
1391
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1389
1392
|
}
|
|
1390
1393
|
);
|
|
1391
1394
|
} else {
|
|
@@ -1489,56 +1492,60 @@ class Model extends EmberObject {
|
|
|
1489
1492
|
}
|
|
1490
1493
|
|
|
1491
1494
|
// ensure inverse is properly configured
|
|
1492
|
-
if (DEBUG
|
|
1493
|
-
if (
|
|
1494
|
-
if (
|
|
1495
|
-
|
|
1495
|
+
if (DEBUG) {
|
|
1496
|
+
if (isPolymorphic) {
|
|
1497
|
+
if (DEPRECATE_NON_EXPLICIT_POLYMORPHISM) {
|
|
1498
|
+
if (!inverseOptions.as) {
|
|
1499
|
+
deprecate(
|
|
1500
|
+
`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${fieldOnInverse}' on type '${inverseSchema.modelName}' is misconfigured.`,
|
|
1501
|
+
false,
|
|
1502
|
+
{
|
|
1503
|
+
id: 'ember-data:non-explicit-relationships',
|
|
1504
|
+
since: { enabled: '4.7', available: '4.7' },
|
|
1505
|
+
until: '5.0',
|
|
1506
|
+
for: 'ember-data',
|
|
1507
|
+
}
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
} else {
|
|
1511
|
+
assert(
|
|
1496
1512
|
`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${fieldOnInverse}' on type '${inverseSchema.modelName}' is misconfigured.`,
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
for: 'ember-data',
|
|
1503
|
-
}
|
|
1513
|
+
inverseOptions.as
|
|
1514
|
+
);
|
|
1515
|
+
assert(
|
|
1516
|
+
`options.as should match the expected type of the polymorphic relationship. Expected field '${fieldOnInverse}' on type '${inverseSchema.modelName}' to specify '${relationship.type}' but found '${inverseOptions.as}'`,
|
|
1517
|
+
!!inverseOptions.as && relationship.type === inverseOptions.as
|
|
1504
1518
|
);
|
|
1505
1519
|
}
|
|
1506
|
-
} else {
|
|
1507
|
-
assert(
|
|
1508
|
-
`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${fieldOnInverse}' on type '${inverseSchema.modelName}' is misconfigured.`,
|
|
1509
|
-
inverseOptions.as
|
|
1510
|
-
);
|
|
1511
|
-
assert(
|
|
1512
|
-
`options.as should match the expected type of the polymorphic relationship. Expected field '${fieldOnInverse}' on type '${inverseSchema.modelName}' to specify '${relationship.type}' but found '${inverseOptions.as}'`,
|
|
1513
|
-
!!inverseOptions.as && relationship.type === inverseOptions.as
|
|
1514
|
-
);
|
|
1515
1520
|
}
|
|
1516
1521
|
}
|
|
1517
1522
|
|
|
1518
1523
|
// ensure we are properly configured
|
|
1519
|
-
if (DEBUG
|
|
1520
|
-
if (
|
|
1521
|
-
if (
|
|
1522
|
-
|
|
1524
|
+
if (DEBUG) {
|
|
1525
|
+
if (inverseOptions.polymorphic) {
|
|
1526
|
+
if (DEPRECATE_NON_EXPLICIT_POLYMORPHISM) {
|
|
1527
|
+
if (!options.as) {
|
|
1528
|
+
deprecate(
|
|
1529
|
+
`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${name}' on type '${this.modelName}' is misconfigured.`,
|
|
1530
|
+
false,
|
|
1531
|
+
{
|
|
1532
|
+
id: 'ember-data:non-explicit-relationships',
|
|
1533
|
+
since: { enabled: '4.7', available: '4.7' },
|
|
1534
|
+
until: '5.0',
|
|
1535
|
+
for: 'ember-data',
|
|
1536
|
+
}
|
|
1537
|
+
);
|
|
1538
|
+
}
|
|
1539
|
+
} else {
|
|
1540
|
+
assert(
|
|
1523
1541
|
`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${name}' on type '${this.modelName}' is misconfigured.`,
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
for: 'ember-data',
|
|
1530
|
-
}
|
|
1542
|
+
options.as
|
|
1543
|
+
);
|
|
1544
|
+
assert(
|
|
1545
|
+
`options.as should match the expected type of the polymorphic relationship. Expected field '${name}' on type '${this.modelName}' to specify '${inverseRelationship.type}' but found '${options.as}'`,
|
|
1546
|
+
!!options.as && inverseRelationship.type === options.as
|
|
1531
1547
|
);
|
|
1532
1548
|
}
|
|
1533
|
-
} else {
|
|
1534
|
-
assert(
|
|
1535
|
-
`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${name}' on type '${this.modelName}' is misconfigured.`,
|
|
1536
|
-
options.as
|
|
1537
|
-
);
|
|
1538
|
-
assert(
|
|
1539
|
-
`options.as should match the expected type of the polymorphic relationship. Expected field '${name}' on type '${this.modelName}' to specify '${inverseRelationship.type}' but found '${options.as}'`,
|
|
1540
|
-
!!options.as && inverseRelationship.type === options.as
|
|
1541
|
-
);
|
|
1542
1549
|
}
|
|
1543
1550
|
}
|
|
1544
1551
|
|
|
@@ -1607,7 +1614,7 @@ class Model extends EmberObject {
|
|
|
1607
1614
|
id: 'ember-data:deprecate-early-static',
|
|
1608
1615
|
for: 'ember-data',
|
|
1609
1616
|
until: '5.0',
|
|
1610
|
-
since: { available: '4.
|
|
1617
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1611
1618
|
}
|
|
1612
1619
|
);
|
|
1613
1620
|
} else {
|
|
@@ -1678,7 +1685,7 @@ class Model extends EmberObject {
|
|
|
1678
1685
|
id: 'ember-data:deprecate-early-static',
|
|
1679
1686
|
for: 'ember-data',
|
|
1680
1687
|
until: '5.0',
|
|
1681
|
-
since: { available: '4.
|
|
1688
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1682
1689
|
}
|
|
1683
1690
|
);
|
|
1684
1691
|
} else {
|
|
@@ -1745,7 +1752,7 @@ class Model extends EmberObject {
|
|
|
1745
1752
|
id: 'ember-data:deprecate-early-static',
|
|
1746
1753
|
for: 'ember-data',
|
|
1747
1754
|
until: '5.0',
|
|
1748
|
-
since: { available: '4.
|
|
1755
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1749
1756
|
}
|
|
1750
1757
|
);
|
|
1751
1758
|
} else {
|
|
@@ -1821,7 +1828,7 @@ class Model extends EmberObject {
|
|
|
1821
1828
|
id: 'ember-data:deprecate-early-static',
|
|
1822
1829
|
for: 'ember-data',
|
|
1823
1830
|
until: '5.0',
|
|
1824
|
-
since: { available: '4.
|
|
1831
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1825
1832
|
}
|
|
1826
1833
|
);
|
|
1827
1834
|
} else {
|
|
@@ -1854,7 +1861,7 @@ class Model extends EmberObject {
|
|
|
1854
1861
|
id: 'ember-data:deprecate-early-static',
|
|
1855
1862
|
for: 'ember-data',
|
|
1856
1863
|
until: '5.0',
|
|
1857
|
-
since: { available: '4.
|
|
1864
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1858
1865
|
}
|
|
1859
1866
|
);
|
|
1860
1867
|
} else {
|
|
@@ -1928,7 +1935,7 @@ class Model extends EmberObject {
|
|
|
1928
1935
|
id: 'ember-data:deprecate-early-static',
|
|
1929
1936
|
for: 'ember-data',
|
|
1930
1937
|
until: '5.0',
|
|
1931
|
-
since: { available: '4.
|
|
1938
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1932
1939
|
}
|
|
1933
1940
|
);
|
|
1934
1941
|
} else {
|
|
@@ -1971,7 +1978,7 @@ class Model extends EmberObject {
|
|
|
1971
1978
|
id: 'ember-data:deprecate-early-static',
|
|
1972
1979
|
for: 'ember-data',
|
|
1973
1980
|
until: '5.0',
|
|
1974
|
-
since: { available: '4.
|
|
1981
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
1975
1982
|
}
|
|
1976
1983
|
);
|
|
1977
1984
|
} else {
|
|
@@ -2006,7 +2013,7 @@ class Model extends EmberObject {
|
|
|
2006
2013
|
id: 'ember-data:deprecate-early-static',
|
|
2007
2014
|
for: 'ember-data',
|
|
2008
2015
|
until: '5.0',
|
|
2009
|
-
since: { available: '4.
|
|
2016
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2010
2017
|
}
|
|
2011
2018
|
);
|
|
2012
2019
|
} else {
|
|
@@ -2032,7 +2039,7 @@ class Model extends EmberObject {
|
|
|
2032
2039
|
id: 'ember-data:deprecate-early-static',
|
|
2033
2040
|
for: 'ember-data',
|
|
2034
2041
|
until: '5.0',
|
|
2035
|
-
since: { available: '4.
|
|
2042
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2036
2043
|
}
|
|
2037
2044
|
);
|
|
2038
2045
|
} else {
|
|
@@ -2110,7 +2117,7 @@ class Model extends EmberObject {
|
|
|
2110
2117
|
id: 'ember-data:deprecate-early-static',
|
|
2111
2118
|
for: 'ember-data',
|
|
2112
2119
|
until: '5.0',
|
|
2113
|
-
since: { available: '4.
|
|
2120
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2114
2121
|
}
|
|
2115
2122
|
);
|
|
2116
2123
|
} else {
|
|
@@ -2186,7 +2193,7 @@ class Model extends EmberObject {
|
|
|
2186
2193
|
id: 'ember-data:deprecate-early-static',
|
|
2187
2194
|
for: 'ember-data',
|
|
2188
2195
|
until: '5.0',
|
|
2189
|
-
since: { available: '4.
|
|
2196
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2190
2197
|
}
|
|
2191
2198
|
);
|
|
2192
2199
|
} else {
|
|
@@ -2259,7 +2266,7 @@ class Model extends EmberObject {
|
|
|
2259
2266
|
id: 'ember-data:deprecate-early-static',
|
|
2260
2267
|
for: 'ember-data',
|
|
2261
2268
|
until: '5.0',
|
|
2262
|
-
since: { available: '4.
|
|
2269
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2263
2270
|
}
|
|
2264
2271
|
);
|
|
2265
2272
|
} else {
|
|
@@ -2327,7 +2334,7 @@ class Model extends EmberObject {
|
|
|
2327
2334
|
id: 'ember-data:deprecate-early-static',
|
|
2328
2335
|
for: 'ember-data',
|
|
2329
2336
|
until: '5.0',
|
|
2330
|
-
since: { available: '4.
|
|
2337
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2331
2338
|
}
|
|
2332
2339
|
);
|
|
2333
2340
|
} else {
|
|
@@ -2357,7 +2364,7 @@ class Model extends EmberObject {
|
|
|
2357
2364
|
id: 'ember-data:deprecate-early-static',
|
|
2358
2365
|
for: 'ember-data',
|
|
2359
2366
|
until: '5.0',
|
|
2360
|
-
since: { available: '4.
|
|
2367
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2361
2368
|
}
|
|
2362
2369
|
);
|
|
2363
2370
|
} else {
|
|
@@ -2469,7 +2476,7 @@ if (DEBUG) {
|
|
|
2469
2476
|
let idDesc = lookupDescriptor(this, 'id');
|
|
2470
2477
|
|
|
2471
2478
|
if (idDesc.get !== ID_DESCRIPTOR.get) {
|
|
2472
|
-
throw new
|
|
2479
|
+
throw new Error(
|
|
2473
2480
|
`You may not set 'id' as an attribute on your model. Please remove any lines that look like: \`id: attr('<type>')\` from ${this.constructor.toString()}`
|
|
2474
2481
|
);
|
|
2475
2482
|
}
|
|
@@ -2485,7 +2492,7 @@ if (DEBUG) {
|
|
|
2485
2492
|
id: 'ember-data:deprecate-model-reopen',
|
|
2486
2493
|
for: 'ember-data',
|
|
2487
2494
|
until: '5.0',
|
|
2488
|
-
since: { available: '4.
|
|
2495
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2489
2496
|
});
|
|
2490
2497
|
return originalReopen.call(this, ...arguments);
|
|
2491
2498
|
};
|
|
@@ -2498,7 +2505,7 @@ if (DEBUG) {
|
|
|
2498
2505
|
id: 'ember-data:deprecate-model-reopenclass',
|
|
2499
2506
|
for: 'ember-data',
|
|
2500
2507
|
until: '5.0',
|
|
2501
|
-
since: { available: '4.
|
|
2508
|
+
since: { available: '4.7', enabled: '4.7' },
|
|
2502
2509
|
}
|
|
2503
2510
|
);
|
|
2504
2511
|
return originalReopenClass.call(this, ...arguments);
|
|
@@ -64,7 +64,7 @@ export default class PromiseManyArray {
|
|
|
64
64
|
deprecate(`Do not use A() on an EmberData PromiseManyArray`, false, {
|
|
65
65
|
id: 'ember-data:no-a-with-array-like',
|
|
66
66
|
until: '5.0',
|
|
67
|
-
since: { enabled: '4.
|
|
67
|
+
since: { enabled: '4.7', available: '4.7' },
|
|
68
68
|
for: 'ember-data',
|
|
69
69
|
});
|
|
70
70
|
// @ts-expect-error ArrayMixin is more than a type
|
|
@@ -261,7 +261,7 @@ if (DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS) {
|
|
|
261
261
|
{
|
|
262
262
|
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
263
263
|
until: '5.0',
|
|
264
|
-
since: { enabled: '4.
|
|
264
|
+
since: { enabled: '4.7', available: '4.7' },
|
|
265
265
|
for: 'ember-data',
|
|
266
266
|
}
|
|
267
267
|
);
|
|
@@ -277,7 +277,7 @@ if (DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS) {
|
|
|
277
277
|
{
|
|
278
278
|
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
279
279
|
until: '5.0',
|
|
280
|
-
since: { enabled: '4.
|
|
280
|
+
since: { enabled: '4.7', available: '4.7' },
|
|
281
281
|
for: 'ember-data',
|
|
282
282
|
}
|
|
283
283
|
);
|
|
@@ -293,7 +293,7 @@ if (DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS) {
|
|
|
293
293
|
{
|
|
294
294
|
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
295
295
|
until: '5.0',
|
|
296
|
-
since: { enabled: '4.
|
|
296
|
+
since: { enabled: '4.7', available: '4.7' },
|
|
297
297
|
for: 'ember-data',
|
|
298
298
|
}
|
|
299
299
|
);
|
|
@@ -347,7 +347,7 @@ if (DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS) {
|
|
|
347
347
|
{
|
|
348
348
|
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
349
349
|
until: '5.0',
|
|
350
|
-
since: { enabled: '4.
|
|
350
|
+
since: { enabled: '4.7', available: '4.7' },
|
|
351
351
|
for: 'ember-data',
|
|
352
352
|
}
|
|
353
353
|
);
|
|
@@ -414,7 +414,7 @@ if (DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS) {
|
|
|
414
414
|
{
|
|
415
415
|
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
416
416
|
until: '5.0',
|
|
417
|
-
since: { enabled: '4.
|
|
417
|
+
since: { enabled: '4.7', available: '4.7' },
|
|
418
418
|
for: 'ember-data',
|
|
419
419
|
}
|
|
420
420
|
);
|
|
@@ -8,6 +8,7 @@ import { storeFor } from '@ember-data/store';
|
|
|
8
8
|
import { recordIdentifierFor } from '@ember-data/store/-private';
|
|
9
9
|
import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
|
|
10
10
|
import type RequestCache from '@ember-data/store/-private/network/request-cache';
|
|
11
|
+
import { addToTransaction, subscribe } from '@ember-data/tracking/-private';
|
|
11
12
|
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
12
13
|
import type { RecordData } from '@ember-data/types/q/record-data';
|
|
13
14
|
|
|
@@ -35,21 +36,19 @@ class Tag {
|
|
|
35
36
|
declare rev: number;
|
|
36
37
|
declare isDirty: boolean;
|
|
37
38
|
declare value: any;
|
|
39
|
+
declare t: boolean;
|
|
38
40
|
|
|
39
41
|
constructor() {
|
|
40
42
|
this.rev = 1;
|
|
41
43
|
this.isDirty = true;
|
|
42
44
|
this.value = undefined;
|
|
45
|
+
this.t = false;
|
|
43
46
|
}
|
|
44
|
-
@tracked
|
|
45
|
-
|
|
46
|
-
subscribe() {
|
|
47
|
-
this._tracking;
|
|
48
|
-
}
|
|
47
|
+
@tracked ref = null;
|
|
49
48
|
|
|
50
49
|
notify() {
|
|
51
50
|
this.isDirty = true;
|
|
52
|
-
this
|
|
51
|
+
addToTransaction(this);
|
|
53
52
|
this.rev++;
|
|
54
53
|
}
|
|
55
54
|
consume(v) {
|
|
@@ -86,7 +85,7 @@ export function tagged(_target, key, desc) {
|
|
|
86
85
|
const setter = desc.set;
|
|
87
86
|
desc.get = function () {
|
|
88
87
|
let tag = getTag(this, key);
|
|
89
|
-
|
|
88
|
+
subscribe(tag);
|
|
90
89
|
|
|
91
90
|
if (tag.isDirty) {
|
|
92
91
|
tag.consume(getter.call(this));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { deprecate } from '@ember/debug';
|
|
2
2
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
3
|
+
import { DEBUG } from '@glimmer/env';
|
|
3
4
|
import { cached, tracked } from '@glimmer/tracking';
|
|
4
5
|
|
|
5
6
|
import type { Object as JSONObject, Value as JSONValue } from 'json-typescript';
|
|
@@ -9,7 +10,6 @@ import { DEPRECATE_PROMISE_PROXIES } from '@ember-data/private-build-infra/depre
|
|
|
9
10
|
import type { Graph } from '@ember-data/record-data/-private/graph/graph';
|
|
10
11
|
import type BelongsToRelationship from '@ember-data/record-data/-private/relationships/state/belongs-to';
|
|
11
12
|
import type Store from '@ember-data/store';
|
|
12
|
-
import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
13
13
|
import { recordIdentifierFor } from '@ember-data/store/-private';
|
|
14
14
|
import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
|
|
15
15
|
import type {
|
|
@@ -22,6 +22,7 @@ import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
|
22
22
|
import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
23
23
|
import type { Dict } from '@ember-data/types/q/utils';
|
|
24
24
|
|
|
25
|
+
import { assertPolymorphicType } from '../debug/assert-polymorphic-type';
|
|
25
26
|
import type { LegacySupport } from '../legacy-relationships-support';
|
|
26
27
|
import { LEGACY_SUPPORT } from '../model';
|
|
27
28
|
|
|
@@ -101,9 +102,16 @@ export default class BelongsToReference {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The identifier of the record that this reference refers to.
|
|
107
|
+
* `null` if no related record is known.
|
|
108
|
+
*
|
|
109
|
+
* @property {StableRecordIdentifier | null} identifier
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
104
112
|
@cached
|
|
105
113
|
@dependentKeyCompat
|
|
106
|
-
get
|
|
114
|
+
get identifier(): StableRecordIdentifier | null {
|
|
107
115
|
this._ref; // consume the tracked prop
|
|
108
116
|
if (this.___relatedToken) {
|
|
109
117
|
this.store._notificationManager.unsubscribe(this.___relatedToken);
|
|
@@ -165,11 +173,11 @@ export default class BelongsToReference {
|
|
|
165
173
|
```
|
|
166
174
|
|
|
167
175
|
@method id
|
|
168
|
-
|
|
176
|
+
@public
|
|
169
177
|
@return {String} The id of the record in this belongsTo relationship.
|
|
170
178
|
*/
|
|
171
179
|
id(): string | null {
|
|
172
|
-
return this.
|
|
180
|
+
return this.identifier?.id || null;
|
|
173
181
|
}
|
|
174
182
|
|
|
175
183
|
/**
|
|
@@ -388,33 +396,37 @@ export default class BelongsToReference {
|
|
|
388
396
|
*/
|
|
389
397
|
async push(data: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<RecordInstance> {
|
|
390
398
|
let jsonApiDoc: SingleResourceDocument = data as SingleResourceDocument;
|
|
391
|
-
if (DEPRECATE_PROMISE_PROXIES
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
399
|
+
if (DEPRECATE_PROMISE_PROXIES) {
|
|
400
|
+
if ((data as { then: unknown }).then) {
|
|
401
|
+
jsonApiDoc = await resolve(data);
|
|
402
|
+
if (jsonApiDoc !== data) {
|
|
403
|
+
deprecate(
|
|
404
|
+
`You passed in a Promise to a Reference API that now expects a resolved value. await the value before setting it.`,
|
|
405
|
+
false,
|
|
406
|
+
{
|
|
407
|
+
id: 'ember-data:deprecate-promise-proxies',
|
|
408
|
+
until: '5.0',
|
|
409
|
+
since: {
|
|
410
|
+
enabled: '4.7',
|
|
411
|
+
available: '4.7',
|
|
412
|
+
},
|
|
413
|
+
for: 'ember-data',
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
}
|
|
407
417
|
}
|
|
408
418
|
}
|
|
409
419
|
let record = this.store.push(jsonApiDoc);
|
|
410
420
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
421
|
+
if (DEBUG) {
|
|
422
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
423
|
+
assertPolymorphicType(
|
|
424
|
+
this.belongsToRelationship.identifier,
|
|
425
|
+
this.belongsToRelationship.definition,
|
|
426
|
+
recordIdentifierFor(record),
|
|
427
|
+
this.store
|
|
428
|
+
);
|
|
429
|
+
}
|
|
418
430
|
|
|
419
431
|
const { identifier } = this.belongsToRelationship;
|
|
420
432
|
this.store._join(() => {
|
|
@@ -13,7 +13,6 @@ import type { Graph } from '@ember-data/record-data/-private/graph/graph';
|
|
|
13
13
|
import type ManyRelationship from '@ember-data/record-data/-private/relationships/state/has-many';
|
|
14
14
|
import type Store from '@ember-data/store';
|
|
15
15
|
import { recordIdentifierFor } from '@ember-data/store';
|
|
16
|
-
import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
17
16
|
import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
|
|
18
17
|
import type {
|
|
19
18
|
CollectionResourceDocument,
|
|
@@ -28,6 +27,7 @@ import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
|
28
27
|
import type { FindOptions } from '@ember-data/types/q/store';
|
|
29
28
|
import type { Dict } from '@ember-data/types/q/utils';
|
|
30
29
|
|
|
30
|
+
import { assertPolymorphicType } from '../debug/assert-polymorphic-type';
|
|
31
31
|
import type { LegacySupport } from '../legacy-relationships-support';
|
|
32
32
|
import { LEGACY_SUPPORT } from '../model';
|
|
33
33
|
|
|
@@ -102,9 +102,15 @@ export default class HasManyReference {
|
|
|
102
102
|
this.___relatedTokenMap.clear();
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* An array of identifiers for the records that this reference refers to.
|
|
107
|
+
*
|
|
108
|
+
* @property {StableRecordIdentifier[]} identifiers
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
105
111
|
@cached
|
|
106
112
|
@dependentKeyCompat
|
|
107
|
-
get
|
|
113
|
+
get identifiers(): StableRecordIdentifier[] {
|
|
108
114
|
this._ref; // consume the tracked prop
|
|
109
115
|
|
|
110
116
|
let resource = this._resource();
|
|
@@ -236,7 +242,7 @@ export default class HasManyReference {
|
|
|
236
242
|
@return {Array} The ids in this has-many relationship
|
|
237
243
|
*/
|
|
238
244
|
ids(): Array<string | null> {
|
|
239
|
-
return this.
|
|
245
|
+
return this.identifiers.map((identifier) => identifier.id);
|
|
240
246
|
}
|
|
241
247
|
|
|
242
248
|
/**
|
|
@@ -400,22 +406,24 @@ export default class HasManyReference {
|
|
|
400
406
|
objectOrPromise: ExistingResourceObject[] | CollectionResourceDocument | { data: SingleResourceDocument[] }
|
|
401
407
|
): Promise<ManyArray> {
|
|
402
408
|
let payload = objectOrPromise;
|
|
403
|
-
if (DEPRECATE_PROMISE_PROXIES
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
409
|
+
if (DEPRECATE_PROMISE_PROXIES) {
|
|
410
|
+
if ((objectOrPromise as unknown as { then: unknown }).then) {
|
|
411
|
+
payload = await resolve(objectOrPromise);
|
|
412
|
+
if (payload !== objectOrPromise) {
|
|
413
|
+
deprecate(
|
|
414
|
+
`You passed in a Promise to a Reference API that now expects a resolved value. await the value before setting it.`,
|
|
415
|
+
false,
|
|
416
|
+
{
|
|
417
|
+
id: 'ember-data:deprecate-promise-proxies',
|
|
418
|
+
until: '5.0',
|
|
419
|
+
since: {
|
|
420
|
+
enabled: '4.7',
|
|
421
|
+
available: '4.7',
|
|
422
|
+
},
|
|
423
|
+
for: 'ember-data',
|
|
424
|
+
}
|
|
425
|
+
);
|
|
426
|
+
}
|
|
419
427
|
}
|
|
420
428
|
}
|
|
421
429
|
let array: Array<ExistingResourceObject | SingleResourceDocument>;
|
|
@@ -519,7 +527,16 @@ export default class HasManyReference {
|
|
|
519
527
|
this.___identifier
|
|
520
528
|
)!;
|
|
521
529
|
|
|
522
|
-
|
|
530
|
+
const loaded = this._isLoaded();
|
|
531
|
+
|
|
532
|
+
if (!loaded) {
|
|
533
|
+
// subscribe to changes
|
|
534
|
+
// for when we are not loaded yet
|
|
535
|
+
this._ref;
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
return support.getManyArray(this.key);
|
|
523
540
|
}
|
|
524
541
|
|
|
525
542
|
/**
|
|
@@ -77,8 +77,10 @@ class RelationshipDefinition implements RelationshipSchema {
|
|
|
77
77
|
inverse = modelClass.inverseFor(this.key, store);
|
|
78
78
|
}
|
|
79
79
|
// TODO make this error again for the non-polymorphic case
|
|
80
|
-
if (DEBUG
|
|
81
|
-
|
|
80
|
+
if (DEBUG) {
|
|
81
|
+
if (!this.options.polymorphic) {
|
|
82
|
+
modelClass.typeForRelationship(this.key, store);
|
|
83
|
+
}
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
if (inverse) {
|