@ember-data/store 4.2.0-alpha.8 → 4.2.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/addon/-private/system/core-store.ts +466 -140
- package/addon/-private/system/ds-model-store.ts +63 -12
- package/addon/-private/system/fetch-manager.ts +4 -9
- package/addon/-private/system/model/internal-model.ts +342 -90
- package/addon/-private/system/model/states.js +14 -2
- package/addon/-private/system/record-array-manager.js +30 -3
- package/addon/-private/system/references/belongs-to.ts +26 -11
- package/addon/-private/system/references/has-many.ts +33 -14
- package/addon/-private/system/references/record.ts +23 -9
- package/addon/-private/system/snapshot.ts +48 -22
- package/addon/-private/system/store/finders.js +58 -2
- package/addon/-private/system/store/record-data-store-wrapper.ts +24 -17
- package/addon/-private/ts-interfaces/fetch-manager.ts +0 -4
- package/package.json +10 -10
|
@@ -7,6 +7,8 @@ import { assert } from '@ember/debug';
|
|
|
7
7
|
import { get, set } from '@ember/object';
|
|
8
8
|
import { _backburner as emberBackburner } from '@ember/runloop';
|
|
9
9
|
|
|
10
|
+
import { REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT } from '@ember-data/canary-features';
|
|
11
|
+
|
|
10
12
|
import isStableIdentifier from '../identifiers/is-stable-identifier';
|
|
11
13
|
import { AdapterPopulatedRecordArray, RecordArray } from './record-arrays';
|
|
12
14
|
import { internalModelFactoryFor } from './store/internal-model-factory';
|
|
@@ -25,10 +27,11 @@ export function recordArraysForIdentifier(identifierOrInternalModel) {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
const pendingForIdentifier = new Set([]);
|
|
30
|
+
const IMDematerializing = new WeakMap();
|
|
28
31
|
|
|
29
32
|
const getIdentifier = function getIdentifier(identifierOrInternalModel) {
|
|
30
33
|
let i = identifierOrInternalModel;
|
|
31
|
-
if (!isStableIdentifier(identifierOrInternalModel)) {
|
|
34
|
+
if (!REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT && !isStableIdentifier(identifierOrInternalModel)) {
|
|
32
35
|
// identifier may actually be an internalModel
|
|
33
36
|
// but during materialization we will get an identifier that
|
|
34
37
|
// has already been removed from the identifiers cache yet
|
|
@@ -39,7 +42,18 @@ const getIdentifier = function getIdentifier(identifierOrInternalModel) {
|
|
|
39
42
|
return i;
|
|
40
43
|
};
|
|
41
44
|
|
|
45
|
+
// REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT only
|
|
42
46
|
const peekIMCache = function peekIMCache(cache, identifier) {
|
|
47
|
+
if (!REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT) {
|
|
48
|
+
let im = IMDematerializing.get(identifier);
|
|
49
|
+
if (im === undefined) {
|
|
50
|
+
// if not im._isDematerializing
|
|
51
|
+
im = cache.peek(identifier);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return im;
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
return cache.peek(identifier);
|
|
44
58
|
};
|
|
45
59
|
|
|
@@ -337,6 +351,14 @@ class RecordArrayManager {
|
|
|
337
351
|
let modelName = identifier.type;
|
|
338
352
|
identifier = getIdentifier(identifier);
|
|
339
353
|
|
|
354
|
+
if (!REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT) {
|
|
355
|
+
const cache = internalModelFactoryFor(this.store);
|
|
356
|
+
const im = peekIMCache(cache, identifier);
|
|
357
|
+
if (im && im._isDematerializing) {
|
|
358
|
+
IMDematerializing.set(identifier, im);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
340
362
|
if (pendingForIdentifier.has(identifier)) {
|
|
341
363
|
return;
|
|
342
364
|
}
|
|
@@ -406,10 +428,15 @@ const updateLiveRecordArray = function updateLiveRecordArray(store, recordArray,
|
|
|
406
428
|
};
|
|
407
429
|
|
|
408
430
|
const pushIdentifiers = function pushIdentifiers(recordArray, identifiers, cache) {
|
|
409
|
-
recordArray._pushIdentifiers
|
|
431
|
+
if (!REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT && !recordArray._pushIdentifiers) {
|
|
432
|
+
// deprecate('not allowed to use this intimate api any more');
|
|
433
|
+
recordArray._pushInternalModels(identifiers.map((i) => peekIMCache(cache, i)));
|
|
434
|
+
} else {
|
|
435
|
+
recordArray._pushIdentifiers(identifiers);
|
|
436
|
+
}
|
|
410
437
|
};
|
|
411
438
|
const removeIdentifiers = function removeIdentifiers(recordArray, identifiers, cache) {
|
|
412
|
-
if (!recordArray._removeIdentifiers) {
|
|
439
|
+
if (!REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT && !recordArray._removeIdentifiers) {
|
|
413
440
|
// deprecate('not allowed to use this intimate api any more');
|
|
414
441
|
recordArray._removeInternalModels(identifiers.map((i) => peekIMCache(cache, i)));
|
|
415
442
|
} else {
|
|
@@ -4,6 +4,7 @@ import { cached, tracked } from '@glimmer/tracking';
|
|
|
4
4
|
|
|
5
5
|
import { resolve } from 'rsvp';
|
|
6
6
|
|
|
7
|
+
import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
|
|
7
8
|
import { DEPRECATE_BELONGS_TO_REFERENCE_PUSH } from '@ember-data/private-build-infra/deprecations';
|
|
8
9
|
import type { BelongsToRelationship } from '@ember-data/record-data/-private';
|
|
9
10
|
import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
@@ -56,22 +57,26 @@ export default class BelongsToReference extends Reference {
|
|
|
56
57
|
this.parent = parent!.recordReference;
|
|
57
58
|
this.parentIdentifier = parentIdentifier;
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
61
|
+
this.#token = store._notificationManager.subscribe(
|
|
62
|
+
parentIdentifier,
|
|
63
|
+
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
64
|
+
if ((bucket === 'relationships' || bucket === 'property') && notifiedKey === key) {
|
|
65
|
+
this._ref++;
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
);
|
|
69
|
+
}
|
|
67
70
|
|
|
68
71
|
// TODO inverse
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
destroy() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
76
|
+
unsubscribe(this.#token);
|
|
77
|
+
if (this.#relatedToken) {
|
|
78
|
+
unsubscribe(this.#relatedToken);
|
|
79
|
+
}
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
82
|
|
|
@@ -142,7 +147,17 @@ export default class BelongsToReference extends Reference {
|
|
|
142
147
|
@return {String} The id of the record in this belongsTo relationship.
|
|
143
148
|
*/
|
|
144
149
|
id(): string | null {
|
|
145
|
-
|
|
150
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
151
|
+
return this._relatedIdentifier?.id || null;
|
|
152
|
+
}
|
|
153
|
+
let resource = this._resource();
|
|
154
|
+
if (resource && resource.data) {
|
|
155
|
+
const identifier = this.store.identifierCache.getOrCreateRecordIdentifier(resource.data);
|
|
156
|
+
|
|
157
|
+
return identifier.id;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return null;
|
|
146
161
|
}
|
|
147
162
|
|
|
148
163
|
_resource() {
|
|
@@ -4,6 +4,7 @@ import { cached, tracked } from '@glimmer/tracking';
|
|
|
4
4
|
|
|
5
5
|
import { resolve } from 'rsvp';
|
|
6
6
|
|
|
7
|
+
import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
|
|
7
8
|
import type { ManyRelationship } from '@ember-data/record-data/-private';
|
|
8
9
|
import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
9
10
|
|
|
@@ -57,24 +58,28 @@ export default class HasManyReference extends Reference {
|
|
|
57
58
|
|
|
58
59
|
this.parent = internalModelFactoryFor(store).peek(parentIdentifier)!.recordReference;
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
62
|
+
this.#token = store._notificationManager.subscribe(
|
|
63
|
+
parentIdentifier,
|
|
64
|
+
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
65
|
+
if ((bucket === 'relationships' || bucket === 'property') && notifiedKey === key) {
|
|
66
|
+
this._ref++;
|
|
67
|
+
}
|
|
65
68
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
);
|
|
70
|
+
this.#relatedTokenMap = new Map();
|
|
71
|
+
}
|
|
69
72
|
// TODO inverse
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
destroy() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
77
|
+
unsubscribe(this.#token);
|
|
78
|
+
this.#relatedTokenMap.forEach((token) => {
|
|
79
|
+
unsubscribe(token);
|
|
80
|
+
});
|
|
81
|
+
this.#relatedTokenMap.clear();
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
@cached
|
|
@@ -201,7 +206,21 @@ export default class HasManyReference extends Reference {
|
|
|
201
206
|
@return {Array} The ids in this has-many relationship
|
|
202
207
|
*/
|
|
203
208
|
ids(): Array<string | null> {
|
|
204
|
-
|
|
209
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
210
|
+
return this._relatedIdentifiers.map((identifier) => identifier.id);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let resource = this._resource();
|
|
214
|
+
|
|
215
|
+
if (resource && resource.data) {
|
|
216
|
+
return resource.data.map((resourceIdentifier) => {
|
|
217
|
+
const identifier = this.store.identifierCache.getOrCreateRecordIdentifier(resourceIdentifier);
|
|
218
|
+
|
|
219
|
+
return identifier.id;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return [];
|
|
205
224
|
}
|
|
206
225
|
|
|
207
226
|
/**
|
|
@@ -3,6 +3,8 @@ import { cached, tracked } from '@glimmer/tracking';
|
|
|
3
3
|
|
|
4
4
|
import RSVP, { resolve } from 'rsvp';
|
|
5
5
|
|
|
6
|
+
import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
|
|
7
|
+
|
|
6
8
|
import type { SingleResourceDocument } from '../../ts-interfaces/ember-data-json-api';
|
|
7
9
|
import type { StableRecordIdentifier } from '../../ts-interfaces/identifier';
|
|
8
10
|
import type { RecordInstance } from '../../ts-interfaces/record-instance';
|
|
@@ -30,18 +32,22 @@ export default class RecordReference extends Reference {
|
|
|
30
32
|
|
|
31
33
|
constructor(public store: CoreStore, identifier: StableRecordIdentifier) {
|
|
32
34
|
super(store, identifier);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
36
|
+
this.#token = store._notificationManager.subscribe(
|
|
37
|
+
identifier,
|
|
38
|
+
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
39
|
+
if (bucket === 'identity' || ((bucket === 'attributes' || bucket === 'property') && notifiedKey === 'id')) {
|
|
40
|
+
this._ref++;
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
);
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
destroy() {
|
|
44
|
-
|
|
48
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
49
|
+
unsubscribe(this.#token);
|
|
50
|
+
}
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
public get type(): string {
|
|
@@ -79,7 +85,15 @@ export default class RecordReference extends Reference {
|
|
|
79
85
|
@return {String} The id of the record.
|
|
80
86
|
*/
|
|
81
87
|
id() {
|
|
82
|
-
|
|
88
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
89
|
+
return this._id;
|
|
90
|
+
}
|
|
91
|
+
let identifier = this.identifier();
|
|
92
|
+
if (identifier) {
|
|
93
|
+
return identifier.id;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return null;
|
|
83
97
|
}
|
|
84
98
|
|
|
85
99
|
/**
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { assert } from '@ember/debug';
|
|
5
5
|
import { get } from '@ember/object';
|
|
6
6
|
|
|
7
|
+
import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
|
|
7
8
|
import { HAS_RECORD_DATA_PACKAGE } from '@ember-data/private-build-infra';
|
|
8
9
|
|
|
9
10
|
import type { DSModel, DSModelSchema, ModelSchema } from '../ts-interfaces/ds-model';
|
|
@@ -64,9 +65,10 @@ export default class Snapshot implements Snapshot {
|
|
|
64
65
|
let internalModel = (this._internalModel = _store._internalModelForResource(identifier));
|
|
65
66
|
this.modelName = identifier.type;
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
69
|
+
// TODO add public docs once this FF is on
|
|
70
|
+
this.identifier = identifier;
|
|
71
|
+
}
|
|
70
72
|
/*
|
|
71
73
|
If the internalModel does not yet have a record, then we are
|
|
72
74
|
likely a snapshot being provided to a find request, so we
|
|
@@ -149,15 +151,26 @@ export default class Snapshot implements Snapshot {
|
|
|
149
151
|
}
|
|
150
152
|
let record = this.record;
|
|
151
153
|
let attributes = (this.__attributes = Object.create(null));
|
|
152
|
-
let attrs
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
let attrs: string[];
|
|
155
|
+
|
|
156
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
157
|
+
attrs = Object.keys(this._store._attributesDefinitionFor(this.modelName, this.identifier));
|
|
158
|
+
} else {
|
|
159
|
+
attrs = Object.keys(this._store._attributesDefinitionFor(this.modelName));
|
|
160
|
+
}
|
|
161
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
162
|
+
attrs.forEach((keyName) => {
|
|
163
|
+
if (schemaIsDSModel(this.type)) {
|
|
164
|
+
// if the schema is for a DSModel then the instance is too
|
|
165
|
+
attributes[keyName] = get(record as DSModel, keyName);
|
|
166
|
+
} else {
|
|
167
|
+
attributes[keyName] = recordDataFor(this._internalModel).getAttr(keyName);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
} else {
|
|
171
|
+
// When CUSTOM_MODEL_CLASS is false `record` must be DSModel
|
|
172
|
+
(record as DSModel).eachAttribute((keyName) => (attributes[keyName] = get(record as DSModel, keyName)));
|
|
173
|
+
}
|
|
161
174
|
|
|
162
175
|
return attributes;
|
|
163
176
|
}
|
|
@@ -174,6 +187,9 @@ export default class Snapshot implements Snapshot {
|
|
|
174
187
|
}
|
|
175
188
|
|
|
176
189
|
get isNew(): boolean {
|
|
190
|
+
if (!CUSTOM_MODEL_CLASS) {
|
|
191
|
+
throw new Error('isNew is only available when custom model class ff is on');
|
|
192
|
+
}
|
|
177
193
|
return this._internalModel.isNew();
|
|
178
194
|
}
|
|
179
195
|
|
|
@@ -317,7 +333,7 @@ export default class Snapshot implements Snapshot {
|
|
|
317
333
|
}
|
|
318
334
|
|
|
319
335
|
const graphFor = require('@ember-data/record-data/-private').graphFor;
|
|
320
|
-
const { identifier } = this;
|
|
336
|
+
const { identifier } = CUSTOM_MODEL_CLASS ? this : this._internalModel;
|
|
321
337
|
const relationship = graphFor(this._store._storeWrapper).get(identifier, keyName);
|
|
322
338
|
|
|
323
339
|
assert(
|
|
@@ -416,7 +432,7 @@ export default class Snapshot implements Snapshot {
|
|
|
416
432
|
}
|
|
417
433
|
|
|
418
434
|
const graphFor = require('@ember-data/record-data/-private').graphFor;
|
|
419
|
-
const { identifier } = this;
|
|
435
|
+
const { identifier } = CUSTOM_MODEL_CLASS ? this : this._internalModel;
|
|
420
436
|
const relationship = graphFor(this._store._storeWrapper).get(identifier, keyName);
|
|
421
437
|
assert(
|
|
422
438
|
`You looked up the ${keyName} hasMany relationship for { type: ${identifier.type}, id: ${identifier.id}, lid: ${identifier.lid} but no such relationship was found.`,
|
|
@@ -472,10 +488,15 @@ export default class Snapshot implements Snapshot {
|
|
|
472
488
|
@public
|
|
473
489
|
*/
|
|
474
490
|
eachAttribute(callback: (key: string, meta: AttributeSchema) => void, binding?: unknown): void {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
491
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
492
|
+
let attrDefs = this._store._attributesDefinitionFor(this.modelName, this.identifier);
|
|
493
|
+
Object.keys(attrDefs).forEach((key) => {
|
|
494
|
+
callback.call(binding, key, attrDefs[key] as AttributeSchema);
|
|
495
|
+
});
|
|
496
|
+
} else {
|
|
497
|
+
// in the non CUSTOM_MODEL_CLASS world we only have DSModel instances
|
|
498
|
+
(this.record as DSModel).eachAttribute(callback, binding);
|
|
499
|
+
}
|
|
479
500
|
}
|
|
480
501
|
|
|
481
502
|
/**
|
|
@@ -496,10 +517,15 @@ export default class Snapshot implements Snapshot {
|
|
|
496
517
|
@public
|
|
497
518
|
*/
|
|
498
519
|
eachRelationship(callback: (key: string, meta: RelationshipSchema) => void, binding?: unknown): void {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
520
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
521
|
+
let relationshipDefs = this._store._relationshipsDefinitionFor(this.modelName, this.identifier);
|
|
522
|
+
Object.keys(relationshipDefs).forEach((key) => {
|
|
523
|
+
callback.call(binding, key, relationshipDefs[key] as RelationshipSchema);
|
|
524
|
+
});
|
|
525
|
+
} else {
|
|
526
|
+
// in the non CUSTOM_MODEL_CLASS world we only have DSModel instances
|
|
527
|
+
(this.record as DSModel).eachRelationship(callback, binding);
|
|
528
|
+
}
|
|
503
529
|
}
|
|
504
530
|
|
|
505
531
|
/**
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { assert, deprecate } from '@ember/debug';
|
|
1
|
+
import { assert, deprecate, warn } from '@ember/debug';
|
|
2
2
|
import { DEBUG } from '@glimmer/env';
|
|
3
3
|
|
|
4
4
|
import { Promise } from 'rsvp';
|
|
5
5
|
|
|
6
|
+
import { REQUEST_SERVICE } from '@ember-data/canary-features';
|
|
7
|
+
|
|
8
|
+
import coerceId from '../coerce-id';
|
|
6
9
|
import { _bind, _guard, _objectIsAlive, guardDestroyedStore } from './common';
|
|
7
10
|
import { normalizeResponseHelper } from './serializer-response';
|
|
8
11
|
|
|
@@ -18,7 +21,60 @@ function payloadIsNotBlank(adapterPayload) {
|
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
export function _find() {
|
|
24
|
+
export function _find(adapter, store, modelClass, id, internalModel, options) {
|
|
25
|
+
if (REQUEST_SERVICE) {
|
|
26
|
+
assert(`Requests made when REQUEST_SERVICE=true should not use the legacy finders`);
|
|
27
|
+
}
|
|
28
|
+
let snapshot = internalModel.createSnapshot(options);
|
|
29
|
+
let { modelName } = internalModel;
|
|
30
|
+
let promise = Promise.resolve().then(() => {
|
|
31
|
+
return adapter.findRecord(store, modelClass, id, snapshot);
|
|
32
|
+
});
|
|
33
|
+
let label = `DS: Handle Adapter#findRecord of '${modelName}' with id: '${id}'`;
|
|
34
|
+
const { identifier } = internalModel;
|
|
35
|
+
|
|
36
|
+
promise = guardDestroyedStore(promise, store, label);
|
|
37
|
+
|
|
38
|
+
return promise.then(
|
|
39
|
+
(adapterPayload) => {
|
|
40
|
+
assert(
|
|
41
|
+
`You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`,
|
|
42
|
+
payloadIsNotBlank(adapterPayload)
|
|
43
|
+
);
|
|
44
|
+
let serializer = store.serializerFor(modelName);
|
|
45
|
+
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, id, 'findRecord');
|
|
46
|
+
assert(
|
|
47
|
+
`Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`,
|
|
48
|
+
!Array.isArray(payload.data)
|
|
49
|
+
);
|
|
50
|
+
assert(
|
|
51
|
+
`The 'findRecord' request for ${modelName}:${id} resolved indicating success but contained no primary data. To indicate a 404 not found you should either reject the promise returned by the adapter's findRecord method or throw a NotFoundError.`,
|
|
52
|
+
'data' in payload && payload.data !== null && typeof payload.data === 'object'
|
|
53
|
+
);
|
|
54
|
+
warn(
|
|
55
|
+
`You requested a record of type '${modelName}' with id '${id}' but the adapter returned a payload with primary data having an id of '${payload.data.id}'. Use 'store.findRecord()' when the requested id is the same as the one returned by the adapter. In other cases use 'store.queryRecord()' instead.`,
|
|
56
|
+
coerceId(payload.data.id) === coerceId(id),
|
|
57
|
+
{
|
|
58
|
+
id: 'ds.store.findRecord.id-mismatch',
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// ensure that regardless of id returned we assign to the correct record
|
|
63
|
+
payload.data.lid = identifier.lid;
|
|
64
|
+
|
|
65
|
+
return store._push(payload);
|
|
66
|
+
},
|
|
67
|
+
(error) => {
|
|
68
|
+
internalModel.send('notFound');
|
|
69
|
+
if (internalModel.currentState.isEmpty) {
|
|
70
|
+
internalModel.unloadRecord();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
throw error;
|
|
74
|
+
},
|
|
75
|
+
`DS: Extract payload of '${modelName}'`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
22
78
|
|
|
23
79
|
export function _findMany(adapter, store, modelName, ids, internalModels, optionsMap) {
|
|
24
80
|
let snapshots = internalModels.map((internalModel) => internalModel.createSnapshot(optionsMap.get(internalModel)));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
|
|
1
2
|
import type { RelationshipDefinition } from '@ember-data/model/-private/system/relationships/relationship-meta';
|
|
2
3
|
import { HAS_RECORD_DATA_PACKAGE } from '@ember-data/private-build-infra';
|
|
3
4
|
|
|
@@ -117,13 +118,16 @@ export default class RecordDataStoreWrapper implements StoreWrapper {
|
|
|
117
118
|
if (!definition) {
|
|
118
119
|
return null;
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
122
|
+
if (metaIsRelationshipDefinition(definition)) {
|
|
123
|
+
return definition._inverseKey(this._store, modelClass);
|
|
124
|
+
} else if (definition.options && definition.options.inverse !== undefined) {
|
|
125
|
+
return definition.options.inverse;
|
|
126
|
+
} else {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
125
129
|
} else {
|
|
126
|
-
return
|
|
130
|
+
return (definition as RelationshipDefinition)._inverseKey(this._store, modelClass);
|
|
127
131
|
}
|
|
128
132
|
}
|
|
129
133
|
|
|
@@ -133,18 +137,21 @@ export default class RecordDataStoreWrapper implements StoreWrapper {
|
|
|
133
137
|
if (!definition) {
|
|
134
138
|
return false;
|
|
135
139
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
141
|
+
if (definition.options && definition.options.inverse === null) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if ((definition as unknown as { inverseIsAsync?: boolean }).inverseIsAsync !== undefined) {
|
|
145
|
+
// TODO do we need to amend the RFC for this prop?
|
|
146
|
+
// else we should add it to the TS interface and document.
|
|
147
|
+
return !!(definition as unknown as { inverseIsAsync: boolean }).inverseIsAsync;
|
|
148
|
+
} else if (metaIsRelationshipDefinition(definition)) {
|
|
149
|
+
return definition._inverseIsAsync(this._store, modelClass);
|
|
150
|
+
} else {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
146
153
|
} else {
|
|
147
|
-
return
|
|
154
|
+
return (definition as RelationshipDefinition)._inverseIsAsync(this._store, modelClass);
|
|
148
155
|
}
|
|
149
156
|
}
|
|
150
157
|
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { Dict } from '@ember-data/store/-private/ts-interfaces/utils';
|
|
2
|
-
|
|
3
1
|
import type { RecordIdentifier } from './identifier';
|
|
4
2
|
|
|
5
3
|
export interface Operation {
|
|
6
4
|
op: string;
|
|
7
|
-
options: Dict<unknown> | undefined;
|
|
8
|
-
recordIdentifier: RecordIdentifier;
|
|
9
5
|
}
|
|
10
6
|
|
|
11
7
|
export interface FindRecordQuery extends Operation {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/store",
|
|
3
|
-
"version": "4.2.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "The default blueprint for ember-cli addons.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"start": "ember serve"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ember-data/canary-features": "4.2.0
|
|
21
|
-
"@ember-data/private-build-infra": "4.2.0
|
|
20
|
+
"@ember-data/canary-features": "4.2.0",
|
|
21
|
+
"@ember-data/private-build-infra": "4.2.0",
|
|
22
22
|
"@ember/string": "^3.0.0",
|
|
23
23
|
"@glimmer/tracking": "^1.0.4",
|
|
24
24
|
"ember-auto-import": "^2.2.4",
|
|
@@ -28,30 +28,30 @@
|
|
|
28
28
|
"ember-cli-typescript": "^4.1.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@ember-data/unpublished-test-infra": "4.2.0
|
|
31
|
+
"@ember-data/unpublished-test-infra": "4.2.0",
|
|
32
32
|
"@ember/optional-features": "^2.0.0",
|
|
33
33
|
"@ember/test-helpers": "^2.6.0",
|
|
34
34
|
"@types/ember": "^3.16.5",
|
|
35
35
|
"@types/rsvp": "^4.0.3",
|
|
36
36
|
"broccoli-asset-rev": "^3.0.0",
|
|
37
|
-
"ember-cli": "~
|
|
37
|
+
"ember-cli": "~3.26.1",
|
|
38
38
|
"ember-cli-dependency-checker": "^3.2.0",
|
|
39
|
-
"ember-cli-htmlbars": "^
|
|
39
|
+
"ember-cli-htmlbars": "^5.1.2",
|
|
40
40
|
"ember-cli-inject-live-reload": "^2.0.2",
|
|
41
41
|
"ember-cli-sri": "^2.1.1",
|
|
42
42
|
"ember-cli-terser": "~4.0.1",
|
|
43
43
|
"ember-disable-prototype-extensions": "^1.1.3",
|
|
44
44
|
"ember-export-application-global": "^2.0.1",
|
|
45
45
|
"ember-load-initializers": "^2.1.1",
|
|
46
|
-
"ember-maybe-import-regenerator": "^1.
|
|
46
|
+
"ember-maybe-import-regenerator": "^0.1.6",
|
|
47
47
|
"ember-qunit": "^5.1.5",
|
|
48
|
-
"ember-resolver": "^8.0.
|
|
49
|
-
"ember-source": "~
|
|
48
|
+
"ember-resolver": "^8.0.0",
|
|
49
|
+
"ember-source": "~3.28.6",
|
|
50
50
|
"ember-source-channel-url": "^3.0.0",
|
|
51
51
|
"ember-try": "^1.4.0",
|
|
52
52
|
"loader.js": "^4.7.0",
|
|
53
53
|
"qunit": "^2.15.0",
|
|
54
|
-
"qunit-dom": "^
|
|
54
|
+
"qunit-dom": "^1.6.0",
|
|
55
55
|
"webpack": "^5.37.1"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|