@ember-data/model 4.8.0-alpha.1 → 4.8.0-alpha.4
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/addon/-private/attr.js +9 -24
- package/addon/-private/belongs-to.js +83 -21
- package/addon/-private/errors.ts +6 -6
- package/addon/-private/has-many.js +77 -17
- package/addon/-private/legacy-data-fetch.js +35 -13
- package/addon/-private/legacy-data-utils.ts +1 -1
- package/addon/-private/legacy-relationships-support.ts +126 -129
- package/addon/-private/many-array.ts +37 -25
- package/addon/-private/model-for-mixin.ts +2 -4
- package/addon/-private/model.js +431 -112
- package/addon/-private/notify-changes.ts +2 -2
- package/addon/-private/promise-many-array.ts +170 -112
- package/addon/-private/record-state.ts +63 -46
- package/addon/-private/references/belongs-to.ts +33 -28
- package/addon/-private/references/has-many.ts +50 -42
- package/addon/-private/relationship-meta.ts +5 -25
- package/index.js +1 -0
- package/package.json +11 -7
|
@@ -8,8 +8,8 @@ import type { BelongsToRelationship } from '@ember-data/record-data/-private';
|
|
|
8
8
|
import type Store from '@ember-data/store';
|
|
9
9
|
import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
10
10
|
import { recordIdentifierFor } from '@ember-data/store/-private';
|
|
11
|
-
import type { NotificationType } from '@ember-data/store/-private/record-notification-manager';
|
|
12
|
-
import type { DebugWeakCache } from '@ember-data/store/-private/weak-cache';
|
|
11
|
+
import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
|
|
12
|
+
import type { DebugWeakCache } from '@ember-data/store/-private/utils/weak-cache';
|
|
13
13
|
import type {
|
|
14
14
|
LinkObject,
|
|
15
15
|
Links,
|
|
@@ -52,12 +52,12 @@ export default class BelongsToReference {
|
|
|
52
52
|
declare key: string;
|
|
53
53
|
declare belongsToRelationship: BelongsToRelationship;
|
|
54
54
|
declare type: string;
|
|
55
|
-
|
|
55
|
+
___identifier: StableRecordIdentifier;
|
|
56
56
|
declare store: Store;
|
|
57
57
|
|
|
58
58
|
// unsubscribe tokens given to us by the notification manager
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
___token!: object;
|
|
60
|
+
___relatedToken: object | null = null;
|
|
61
61
|
|
|
62
62
|
@tracked _ref = 0;
|
|
63
63
|
|
|
@@ -71,12 +71,12 @@ export default class BelongsToReference {
|
|
|
71
71
|
this.belongsToRelationship = belongsToRelationship;
|
|
72
72
|
this.type = belongsToRelationship.definition.type;
|
|
73
73
|
this.store = store;
|
|
74
|
-
this
|
|
74
|
+
this.___identifier = parentIdentifier;
|
|
75
75
|
|
|
76
|
-
this
|
|
76
|
+
this.___token = store._notificationManager.subscribe(
|
|
77
77
|
parentIdentifier,
|
|
78
78
|
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
79
|
-
if (
|
|
79
|
+
if (bucket === 'relationships' && notifiedKey === key) {
|
|
80
80
|
this._ref++;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -88,9 +88,11 @@ export default class BelongsToReference {
|
|
|
88
88
|
destroy() {
|
|
89
89
|
// TODO @feature we need the notification manager often enough
|
|
90
90
|
// we should potentially just expose it fully public
|
|
91
|
-
this.store._notificationManager.unsubscribe(this
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
this.store._notificationManager.unsubscribe(this.___token);
|
|
92
|
+
this.___token = null as unknown as object;
|
|
93
|
+
if (this.___relatedToken) {
|
|
94
|
+
this.store._notificationManager.unsubscribe(this.___relatedToken);
|
|
95
|
+
this.___relatedToken = null;
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
|
|
@@ -98,17 +100,18 @@ export default class BelongsToReference {
|
|
|
98
100
|
@dependentKeyCompat
|
|
99
101
|
get _relatedIdentifier(): StableRecordIdentifier | null {
|
|
100
102
|
this._ref; // consume the tracked prop
|
|
101
|
-
if (this
|
|
102
|
-
this.store._notificationManager.unsubscribe(this
|
|
103
|
+
if (this.___relatedToken) {
|
|
104
|
+
this.store._notificationManager.unsubscribe(this.___relatedToken);
|
|
105
|
+
this.___relatedToken = null;
|
|
103
106
|
}
|
|
104
107
|
|
|
105
108
|
let resource = this._resource();
|
|
106
109
|
if (resource && resource.data) {
|
|
107
110
|
const identifier = this.store.identifierCache.getOrCreateRecordIdentifier(resource.data);
|
|
108
|
-
this
|
|
111
|
+
this.___relatedToken = this.store._notificationManager.subscribe(
|
|
109
112
|
identifier,
|
|
110
113
|
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
111
|
-
if (bucket === 'identity' || (
|
|
114
|
+
if (bucket === 'identity' || (bucket === 'attributes' && notifiedKey === 'id')) {
|
|
112
115
|
this._ref++;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
@@ -125,7 +128,7 @@ export default class BelongsToReference {
|
|
|
125
128
|
`type()` and `id()` methods form a composite key for the identity
|
|
126
129
|
map. This can be used to access the id of an async relationship
|
|
127
130
|
without triggering a fetch that would normally happen if you
|
|
128
|
-
attempted to use `record.
|
|
131
|
+
attempted to use `record.relationship.id`.
|
|
129
132
|
|
|
130
133
|
Example
|
|
131
134
|
|
|
@@ -134,7 +137,7 @@ export default class BelongsToReference {
|
|
|
134
137
|
import Model, { belongsTo } from '@ember-data/model';
|
|
135
138
|
|
|
136
139
|
export default class BlogModel extends Model {
|
|
137
|
-
@belongsTo({ async: true }) user;
|
|
140
|
+
@belongsTo('user', { async: true, inverse: null }) user;
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
let blog = store.push({
|
|
@@ -174,7 +177,7 @@ export default class BelongsToReference {
|
|
|
174
177
|
// models/blog.js
|
|
175
178
|
import Model, { belongsTo } from '@ember-data/model';
|
|
176
179
|
export default Model.extend({
|
|
177
|
-
user: belongsTo({ async: true })
|
|
180
|
+
user: belongsTo('user', { async: true, inverse: null })
|
|
178
181
|
});
|
|
179
182
|
|
|
180
183
|
let blog = store.push({
|
|
@@ -236,7 +239,7 @@ export default class BelongsToReference {
|
|
|
236
239
|
// models/blog.js
|
|
237
240
|
import Model, { belongsTo } from '@ember-data/model';
|
|
238
241
|
export default Model.extend({
|
|
239
|
-
user: belongsTo({ async: true })
|
|
242
|
+
user: belongsTo('user', { async: true, inverse: null })
|
|
240
243
|
});
|
|
241
244
|
|
|
242
245
|
let blog = store.push({
|
|
@@ -277,7 +280,9 @@ export default class BelongsToReference {
|
|
|
277
280
|
}
|
|
278
281
|
|
|
279
282
|
_resource() {
|
|
280
|
-
return this.store._instanceCache
|
|
283
|
+
return this.store._instanceCache
|
|
284
|
+
.getRecordData(this.___identifier)
|
|
285
|
+
.getRelationship(this.___identifier, this.key) as SingleResourceRelationship;
|
|
281
286
|
}
|
|
282
287
|
|
|
283
288
|
/**
|
|
@@ -291,7 +296,7 @@ export default class BelongsToReference {
|
|
|
291
296
|
import Model, { hasMany } from '@ember-data/model';
|
|
292
297
|
|
|
293
298
|
export default class PostModel extends Model {
|
|
294
|
-
@hasMany({ async: true }) comments;
|
|
299
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
295
300
|
}
|
|
296
301
|
```
|
|
297
302
|
|
|
@@ -341,7 +346,7 @@ export default class BelongsToReference {
|
|
|
341
346
|
import Model, { belongsTo } from '@ember-data/model';
|
|
342
347
|
|
|
343
348
|
export default class BlogModel extends Model {
|
|
344
|
-
@belongsTo({ async: true }) user;
|
|
349
|
+
@belongsTo('user', { async: true, inverse: null }) user;
|
|
345
350
|
}
|
|
346
351
|
|
|
347
352
|
let blog = store.push({
|
|
@@ -404,7 +409,7 @@ export default class BelongsToReference {
|
|
|
404
409
|
|
|
405
410
|
/**
|
|
406
411
|
`value()` synchronously returns the current value of the belongs-to
|
|
407
|
-
relationship. Unlike `record.
|
|
412
|
+
relationship. Unlike `record.relationshipName`, calling
|
|
408
413
|
`value()` on a reference does not trigger a fetch if the async
|
|
409
414
|
relationship is not yet loaded. If the relationship is not loaded
|
|
410
415
|
it will always return `null`.
|
|
@@ -416,7 +421,7 @@ export default class BelongsToReference {
|
|
|
416
421
|
import Model, { belongsTo } from '@ember-data/model';
|
|
417
422
|
|
|
418
423
|
export default class BlogModel extends Model {
|
|
419
|
-
@belongsTo({ async: true }) user;
|
|
424
|
+
@belongsTo('user', { async: true, inverse: null }) user;
|
|
420
425
|
}
|
|
421
426
|
|
|
422
427
|
let blog = store.push({
|
|
@@ -469,7 +474,7 @@ export default class BelongsToReference {
|
|
|
469
474
|
import Model, { belongsTo } from '@ember-data/model';
|
|
470
475
|
|
|
471
476
|
export default class BlogModel extends Model {
|
|
472
|
-
@belongsTo({ async: true }) user;
|
|
477
|
+
@belongsTo('user', { async: true, inverse: null }) user;
|
|
473
478
|
}
|
|
474
479
|
|
|
475
480
|
let blog = store.push({
|
|
@@ -522,7 +527,7 @@ export default class BelongsToReference {
|
|
|
522
527
|
load(options?: Dict<unknown>) {
|
|
523
528
|
const support: LegacySupport = (
|
|
524
529
|
LEGACY_SUPPORT as DebugWeakCache<StableRecordIdentifier, LegacySupport>
|
|
525
|
-
).getWithError(this
|
|
530
|
+
).getWithError(this.___identifier);
|
|
526
531
|
return support.getBelongsTo(this.key, options);
|
|
527
532
|
}
|
|
528
533
|
|
|
@@ -539,7 +544,7 @@ export default class BelongsToReference {
|
|
|
539
544
|
import Model, { belongsTo } from '@ember-data/model';
|
|
540
545
|
|
|
541
546
|
export default class BlogModel extends Model {
|
|
542
|
-
@belongsTo({ async: true }) user;
|
|
547
|
+
@belongsTo('user', { async: true, inverse: null }) user;
|
|
543
548
|
}
|
|
544
549
|
|
|
545
550
|
let blog = store.push({
|
|
@@ -579,7 +584,7 @@ export default class BelongsToReference {
|
|
|
579
584
|
reload(options?: Dict<unknown>) {
|
|
580
585
|
const support: LegacySupport = (
|
|
581
586
|
LEGACY_SUPPORT as DebugWeakCache<StableRecordIdentifier, LegacySupport>
|
|
582
|
-
).getWithError(this
|
|
587
|
+
).getWithError(this.___identifier);
|
|
583
588
|
return support.reloadBelongsTo(this.key, options).then(() => this.value());
|
|
584
589
|
}
|
|
585
590
|
}
|
|
@@ -11,8 +11,8 @@ import type { ManyRelationship } from '@ember-data/record-data/-private';
|
|
|
11
11
|
import type Store from '@ember-data/store';
|
|
12
12
|
import { recordIdentifierFor } from '@ember-data/store';
|
|
13
13
|
import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
14
|
-
import type { NotificationType } from '@ember-data/store/-private/record-notification-manager';
|
|
15
|
-
import type { DebugWeakCache } from '@ember-data/store/-private/weak-cache';
|
|
14
|
+
import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
|
|
15
|
+
import type { DebugWeakCache } from '@ember-data/store/-private/utils/weak-cache';
|
|
16
16
|
import type {
|
|
17
17
|
CollectionResourceDocument,
|
|
18
18
|
CollectionResourceRelationship,
|
|
@@ -59,9 +59,9 @@ export default class HasManyReference {
|
|
|
59
59
|
declare store: Store;
|
|
60
60
|
|
|
61
61
|
// unsubscribe tokens given to us by the notification manager
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
___token!: Object;
|
|
63
|
+
___identifier: StableRecordIdentifier;
|
|
64
|
+
___relatedTokenMap!: Map<StableRecordIdentifier, Object>;
|
|
65
65
|
|
|
66
66
|
@tracked _ref = 0;
|
|
67
67
|
|
|
@@ -76,25 +76,25 @@ export default class HasManyReference {
|
|
|
76
76
|
this.type = hasManyRelationship.definition.type;
|
|
77
77
|
|
|
78
78
|
this.store = store;
|
|
79
|
-
this
|
|
80
|
-
this
|
|
79
|
+
this.___identifier = parentIdentifier;
|
|
80
|
+
this.___token = store._notificationManager.subscribe(
|
|
81
81
|
parentIdentifier,
|
|
82
82
|
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
83
|
-
if (
|
|
83
|
+
if (bucket === 'relationships' && notifiedKey === key) {
|
|
84
84
|
this._ref++;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
);
|
|
88
|
-
this
|
|
88
|
+
this.___relatedTokenMap = new Map();
|
|
89
89
|
// TODO inverse
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
destroy() {
|
|
93
|
-
this.store._notificationManager.unsubscribe(this
|
|
94
|
-
this
|
|
93
|
+
this.store._notificationManager.unsubscribe(this.___token);
|
|
94
|
+
this.___relatedTokenMap.forEach((token) => {
|
|
95
95
|
this.store._notificationManager.unsubscribe(token);
|
|
96
96
|
});
|
|
97
|
-
this
|
|
97
|
+
this.___relatedTokenMap.clear();
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
@cached
|
|
@@ -104,34 +104,44 @@ export default class HasManyReference {
|
|
|
104
104
|
|
|
105
105
|
let resource = this._resource();
|
|
106
106
|
|
|
107
|
-
this
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
this.#relatedTokenMap.clear();
|
|
107
|
+
let map = this.___relatedTokenMap;
|
|
108
|
+
this.___relatedTokenMap = new Map();
|
|
111
109
|
|
|
112
110
|
if (resource && resource.data) {
|
|
113
111
|
return resource.data.map((resourceIdentifier) => {
|
|
114
112
|
const identifier = this.store.identifierCache.getOrCreateRecordIdentifier(resourceIdentifier);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
let token = map.get(identifier);
|
|
114
|
+
|
|
115
|
+
if (token) {
|
|
116
|
+
map.delete(identifier);
|
|
117
|
+
} else {
|
|
118
|
+
token = this.store._notificationManager.subscribe(
|
|
119
|
+
identifier,
|
|
120
|
+
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
121
|
+
if (bucket === 'identity' || (bucket === 'attributes' && notifiedKey === 'id')) {
|
|
122
|
+
this._ref++;
|
|
123
|
+
}
|
|
120
124
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.#relatedTokenMap.set(identifier, token);
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
this.___relatedTokenMap.set(identifier, token);
|
|
125
128
|
|
|
126
129
|
return identifier;
|
|
127
130
|
});
|
|
128
131
|
}
|
|
129
132
|
|
|
133
|
+
map.forEach((token) => {
|
|
134
|
+
this.store._notificationManager.unsubscribe(token);
|
|
135
|
+
});
|
|
136
|
+
map.clear();
|
|
137
|
+
|
|
130
138
|
return [];
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
_resource() {
|
|
134
|
-
return this.store._instanceCache
|
|
142
|
+
return this.store._instanceCache
|
|
143
|
+
.getRecordData(this.___identifier)
|
|
144
|
+
.getRelationship(this.___identifier, this.key) as CollectionResourceRelationship;
|
|
135
145
|
}
|
|
136
146
|
|
|
137
147
|
/**
|
|
@@ -145,7 +155,7 @@ export default class HasManyReference {
|
|
|
145
155
|
import Model, { hasMany } from '@ember-data/model';
|
|
146
156
|
|
|
147
157
|
export default class PostModel extends Model {
|
|
148
|
-
@hasMany({ async: true }) comments;
|
|
158
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
149
159
|
}
|
|
150
160
|
```
|
|
151
161
|
|
|
@@ -194,7 +204,7 @@ export default class HasManyReference {
|
|
|
194
204
|
import Model, { hasMany } from '@ember-data/model';
|
|
195
205
|
|
|
196
206
|
export default class PostModel extends Model {
|
|
197
|
-
@hasMany({ async: true }) comments;
|
|
207
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
198
208
|
}
|
|
199
209
|
```
|
|
200
210
|
|
|
@@ -234,7 +244,7 @@ export default class HasManyReference {
|
|
|
234
244
|
// models/blog.js
|
|
235
245
|
import Model, { belongsTo } from '@ember-data/model';
|
|
236
246
|
export default Model.extend({
|
|
237
|
-
user: belongsTo({ async: true })
|
|
247
|
+
user: belongsTo('user', { async: true, inverse: null })
|
|
238
248
|
});
|
|
239
249
|
|
|
240
250
|
let blog = store.push({
|
|
@@ -296,7 +306,7 @@ export default class HasManyReference {
|
|
|
296
306
|
// models/blog.js
|
|
297
307
|
import Model, { hasMany } from '@ember-data/model';
|
|
298
308
|
export default Model.extend({
|
|
299
|
-
users: hasMany({ async: true })
|
|
309
|
+
users: hasMany('user', { async: true, inverse: null })
|
|
300
310
|
});
|
|
301
311
|
|
|
302
312
|
let blog = store.push({
|
|
@@ -347,7 +357,7 @@ export default class HasManyReference {
|
|
|
347
357
|
import Model, { hasMany } from '@ember-data/model';
|
|
348
358
|
|
|
349
359
|
export default class PostModel extends Model {
|
|
350
|
-
@hasMany({ async: true }) comments;
|
|
360
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
351
361
|
}
|
|
352
362
|
```
|
|
353
363
|
|
|
@@ -435,16 +445,14 @@ export default class HasManyReference {
|
|
|
435
445
|
|
|
436
446
|
let members = this.hasManyRelationship.currentState;
|
|
437
447
|
|
|
438
|
-
//TODO @runspired determine isLoaded via a better means
|
|
439
448
|
return members.every((identifier) => {
|
|
440
|
-
|
|
441
|
-
return internalModel.isLoaded === true;
|
|
449
|
+
return this.store._instanceCache.recordIsLoaded(identifier, true) === true;
|
|
442
450
|
});
|
|
443
451
|
}
|
|
444
452
|
|
|
445
453
|
/**
|
|
446
454
|
`value()` synchronously returns the current value of the has-many
|
|
447
|
-
relationship. Unlike `record.
|
|
455
|
+
relationship. Unlike `record.relationshipName`, calling
|
|
448
456
|
`value()` on a reference does not trigger a fetch if the async
|
|
449
457
|
relationship is not yet loaded. If the relationship is not loaded
|
|
450
458
|
it will always return `null`.
|
|
@@ -455,7 +463,7 @@ export default class HasManyReference {
|
|
|
455
463
|
import Model, { hasMany } from '@ember-data/model';
|
|
456
464
|
|
|
457
465
|
export default class PostModel extends Model {
|
|
458
|
-
@hasMany({ async: true }) comments;
|
|
466
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
459
467
|
}
|
|
460
468
|
```
|
|
461
469
|
|
|
@@ -474,7 +482,7 @@ export default class HasManyReference {
|
|
|
474
482
|
|
|
475
483
|
let commentsRef = post.hasMany('comments');
|
|
476
484
|
|
|
477
|
-
post.
|
|
485
|
+
post.comments.then(function(comments) {
|
|
478
486
|
commentsRef.value() === comments
|
|
479
487
|
})
|
|
480
488
|
```
|
|
@@ -486,7 +494,7 @@ export default class HasManyReference {
|
|
|
486
494
|
value() {
|
|
487
495
|
const support: LegacySupport = (
|
|
488
496
|
LEGACY_SUPPORT as DebugWeakCache<StableRecordIdentifier, LegacySupport>
|
|
489
|
-
).getWithError(this
|
|
497
|
+
).getWithError(this.___identifier);
|
|
490
498
|
|
|
491
499
|
return this._isLoaded() ? support.getManyArray(this.key) : null;
|
|
492
500
|
}
|
|
@@ -503,7 +511,7 @@ export default class HasManyReference {
|
|
|
503
511
|
import Model, { hasMany } from '@ember-data/model';
|
|
504
512
|
|
|
505
513
|
export default class PostModel extends Model {
|
|
506
|
-
@hasMany({ async: true }) comments;
|
|
514
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
507
515
|
}
|
|
508
516
|
```
|
|
509
517
|
|
|
@@ -558,7 +566,7 @@ export default class HasManyReference {
|
|
|
558
566
|
async load(options?: FindOptions): Promise<ManyArray> {
|
|
559
567
|
const support: LegacySupport = (
|
|
560
568
|
LEGACY_SUPPORT as DebugWeakCache<StableRecordIdentifier, LegacySupport>
|
|
561
|
-
).getWithError(this
|
|
569
|
+
).getWithError(this.___identifier);
|
|
562
570
|
return support.getHasMany(this.key, options) as Promise<ManyArray> | ManyArray; // this cast is necessary because typescript does not work properly with custom thenables;
|
|
563
571
|
}
|
|
564
572
|
|
|
@@ -572,7 +580,7 @@ export default class HasManyReference {
|
|
|
572
580
|
import Model, { hasMany } from '@ember-data/model';
|
|
573
581
|
|
|
574
582
|
export default class PostModel extends Model {
|
|
575
|
-
@hasMany({ async: true }) comments;
|
|
583
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
576
584
|
}
|
|
577
585
|
```
|
|
578
586
|
|
|
@@ -615,7 +623,7 @@ export default class HasManyReference {
|
|
|
615
623
|
reload(options?: FindOptions) {
|
|
616
624
|
const support: LegacySupport = (
|
|
617
625
|
LEGACY_SUPPORT as DebugWeakCache<StableRecordIdentifier, LegacySupport>
|
|
618
|
-
).getWithError(this
|
|
626
|
+
).getWithError(this.___identifier);
|
|
619
627
|
return support.reloadHasMany(this.key, options);
|
|
620
628
|
}
|
|
621
629
|
}
|
|
@@ -1,17 +1,13 @@
|
|
|
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
|
-
/**
|
|
10
|
-
@module @ember-data/store
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
9
|
function typeForRelationshipMeta(meta) {
|
|
14
|
-
let modelName =
|
|
10
|
+
let modelName = dasherize(meta.type || meta.key);
|
|
15
11
|
|
|
16
12
|
if (meta.kind === 'hasMany') {
|
|
17
13
|
modelName = singularize(modelName);
|
|
@@ -25,10 +21,9 @@ function shouldFindInverse(relationshipMeta) {
|
|
|
25
21
|
return !(options && options.inverse === null);
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
class RelationshipDefinition implements RelationshipSchema {
|
|
29
25
|
declare _type: string;
|
|
30
26
|
declare __inverseKey: string;
|
|
31
|
-
declare __inverseIsAsync: boolean;
|
|
32
27
|
declare __hasCalculatedInverse: boolean;
|
|
33
28
|
declare parentModelName: string;
|
|
34
29
|
declare inverseIsAsync: string | null;
|
|
@@ -37,7 +32,6 @@ export class RelationshipDefinition implements RelationshipSchema {
|
|
|
37
32
|
constructor(meta: any) {
|
|
38
33
|
this._type = '';
|
|
39
34
|
this.__inverseKey = '';
|
|
40
|
-
this.__inverseIsAsync = true;
|
|
41
35
|
this.__hasCalculatedInverse = false;
|
|
42
36
|
this.parentModelName = meta.parentModelName;
|
|
43
37
|
this.meta = meta;
|
|
@@ -74,16 +68,9 @@ export class RelationshipDefinition implements RelationshipSchema {
|
|
|
74
68
|
return this.__inverseKey;
|
|
75
69
|
}
|
|
76
70
|
|
|
77
|
-
_inverseIsAsync(store: Store, modelClass): boolean {
|
|
78
|
-
if (this.__hasCalculatedInverse === false) {
|
|
79
|
-
this._calculateInverse(store, modelClass);
|
|
80
|
-
}
|
|
81
|
-
return this.__inverseIsAsync;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
71
|
_calculateInverse(store: Store, modelClass): void {
|
|
85
72
|
this.__hasCalculatedInverse = true;
|
|
86
|
-
let inverseKey
|
|
73
|
+
let inverseKey;
|
|
87
74
|
let inverse: any = null;
|
|
88
75
|
|
|
89
76
|
if (shouldFindInverse(this.meta)) {
|
|
@@ -94,20 +81,13 @@ export class RelationshipDefinition implements RelationshipSchema {
|
|
|
94
81
|
|
|
95
82
|
if (inverse) {
|
|
96
83
|
inverseKey = inverse.name;
|
|
97
|
-
inverseIsAsync = isRelationshipAsync(inverse);
|
|
98
84
|
} else {
|
|
99
85
|
inverseKey = null;
|
|
100
|
-
inverseIsAsync = false;
|
|
101
86
|
}
|
|
102
87
|
this.__inverseKey = inverseKey;
|
|
103
|
-
this.__inverseIsAsync = inverseIsAsync;
|
|
104
88
|
}
|
|
105
89
|
}
|
|
106
|
-
|
|
107
|
-
function isRelationshipAsync(meta: RelationshipSchema): boolean {
|
|
108
|
-
let inverseAsync = meta.options && meta.options.async;
|
|
109
|
-
return typeof inverseAsync === 'undefined' ? true : inverseAsync;
|
|
110
|
-
}
|
|
90
|
+
export type { RelationshipDefinition };
|
|
111
91
|
|
|
112
92
|
export function relationshipFromMeta(meta: RelationshipSchema): RelationshipDefinition {
|
|
113
93
|
return new RelationshipDefinition(meta);
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/model",
|
|
3
|
-
"version": "4.8.0-alpha.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.8.0-alpha.4",
|
|
4
|
+
"description": "A presentation layer for apps built with @ember-data/store",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
7
7
|
],
|
|
8
|
-
"repository":
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+ssh://git@github.com:emberjs/data.git",
|
|
11
|
+
"directory": "packages/model"
|
|
12
|
+
},
|
|
9
13
|
"license": "MIT",
|
|
10
14
|
"author": "",
|
|
11
15
|
"directories": {
|
|
@@ -18,9 +22,9 @@
|
|
|
18
22
|
"test:node": "mocha"
|
|
19
23
|
},
|
|
20
24
|
"dependencies": {
|
|
21
|
-
"@ember-data/canary-features": "4.8.0-alpha.
|
|
22
|
-
"@ember-data/private-build-infra": "4.8.0-alpha.
|
|
23
|
-
"@ember-data/store": "4.8.0-alpha.
|
|
25
|
+
"@ember-data/canary-features": "4.8.0-alpha.4",
|
|
26
|
+
"@ember-data/private-build-infra": "4.8.0-alpha.4",
|
|
27
|
+
"@ember-data/store": "4.8.0-alpha.4",
|
|
24
28
|
"@ember/edition-utils": "^1.2.0",
|
|
25
29
|
"@ember/string": "^3.0.0",
|
|
26
30
|
"@embroider/macros": "^1.8.3",
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
"inflection": "~1.13.2"
|
|
35
39
|
},
|
|
36
40
|
"devDependencies": {
|
|
37
|
-
"@ember-data/unpublished-test-infra": "4.8.0-alpha.
|
|
41
|
+
"@ember-data/unpublished-test-infra": "4.8.0-alpha.4",
|
|
38
42
|
"@ember/optional-features": "^2.0.0",
|
|
39
43
|
"@ember/test-helpers": "~2.7.0",
|
|
40
44
|
"broccoli-asset-rev": "^3.0.0",
|