@ember-data/store 4.4.0-alpha.9 → 4.4.1
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 +147 -134
- package/addon/-private/system/ds-model-store.ts +10 -1
- package/addon/-private/system/fetch-manager.ts +21 -48
- package/addon/-private/system/model/internal-model.ts +192 -263
- package/addon/-private/system/model/states.js +41 -5
- package/addon/-private/system/{promise-proxies.ts → promise-proxies.js} +21 -31
- package/addon/-private/system/{record-array-manager.ts → record-array-manager.js} +60 -87
- package/addon/-private/system/record-arrays/adapter-populated-record-array.js +95 -0
- package/addon/-private/system/record-arrays/{record-array.ts → record-array.js} +75 -96
- package/addon/-private/system/record-data-for.ts +0 -2
- package/addon/-private/system/references/belongs-to.ts +2 -3
- package/addon/-private/system/references/has-many.ts +2 -4
- package/addon/-private/system/schema-definition-service.ts +2 -2
- package/addon/-private/system/snapshot-record-array.ts +11 -12
- package/addon/-private/system/snapshot.ts +7 -24
- package/addon/-private/system/store/common.js +1 -24
- package/addon/-private/system/store/finders.js +5 -53
- package/addon/-private/system/store/internal-model-factory.ts +7 -8
- package/addon/-private/system/store/record-data-store-wrapper.ts +2 -7
- package/addon/-private/system/store/serializer-response.js +71 -0
- package/addon/-private/ts-interfaces/ds-model.ts +7 -15
- package/addon/-private/ts-interfaces/ember-data-json-api.ts +0 -3
- package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +20 -19
- package/addon/-private/ts-interfaces/minimum-serializer-interface.ts +6 -27
- package/addon/-private/ts-interfaces/record-data.ts +1 -4
- package/addon/-private/ts-interfaces/record-instance.ts +1 -3
- package/addon/-private/ts-interfaces/store.ts +0 -1
- package/addon/-private/utils/promise-record.ts +3 -3
- package/index.js +0 -3
- package/package.json +6 -7
- package/addon/-private/system/promise-proxy-base.js +0 -7
- package/addon/-private/system/record-arrays/adapter-populated-record-array.ts +0 -129
- package/addon/-private/system/store/serializer-response.ts +0 -85
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { A } from '@ember/array';
|
|
2
|
+
import { get } from '@ember/object';
|
|
3
|
+
|
|
4
|
+
import RecordArray from './record-array';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
@module @ember-data/store
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
Represents an ordered list of records whose order and membership is
|
|
12
|
+
determined by the adapter. For example, a query sent to the adapter
|
|
13
|
+
may trigger a search on the server, whose results would be loaded
|
|
14
|
+
into an instance of the `AdapterPopulatedRecordArray`.
|
|
15
|
+
|
|
16
|
+
This class should not be imported and instantiated by consuming applications.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
If you want to update the array and get the latest records from the
|
|
21
|
+
adapter, you can invoke [`update()`](AdapterPopulatedRecordArray/methods/update?anchor=update):
|
|
22
|
+
|
|
23
|
+
Example
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
// GET /users?isAdmin=true
|
|
27
|
+
store.query('user', { isAdmin: true }).then(function(admins) {
|
|
28
|
+
|
|
29
|
+
admins.then(function() {
|
|
30
|
+
console.log(admins.get("length")); // 42
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// somewhere later in the app code, when new admins have been created
|
|
34
|
+
// in the meantime
|
|
35
|
+
//
|
|
36
|
+
// GET /users?isAdmin=true
|
|
37
|
+
admins.update().then(function() {
|
|
38
|
+
admins.get('isUpdating'); // false
|
|
39
|
+
console.log(admins.get("length")); // 123
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
admins.get('isUpdating'); // true
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
@class AdapterPopulatedRecordArray
|
|
47
|
+
@public
|
|
48
|
+
@extends RecordArray
|
|
49
|
+
*/
|
|
50
|
+
export default RecordArray.extend({
|
|
51
|
+
init() {
|
|
52
|
+
this.set('content', this.get('content') || A());
|
|
53
|
+
|
|
54
|
+
this._super(...arguments);
|
|
55
|
+
this.query = this.query || null;
|
|
56
|
+
this.links = this.links || null;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
replace() {
|
|
60
|
+
throw new Error(`The result of a server query (on ${this.modelName}) is immutable.`);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
_update() {
|
|
64
|
+
let store = get(this, 'store');
|
|
65
|
+
let query = get(this, 'query');
|
|
66
|
+
|
|
67
|
+
return store._query(this.modelName, query, this);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
_setObjects(identifiersOrInternalModels, payload) {
|
|
71
|
+
// TODO: initial load should not cause change events at all, only
|
|
72
|
+
// subsequent. This requires changing the public api of adapter.query, but
|
|
73
|
+
// hopefully we can do that soon.
|
|
74
|
+
this.get('content').setObjects(identifiersOrInternalModels);
|
|
75
|
+
|
|
76
|
+
this.setProperties({
|
|
77
|
+
isLoaded: true,
|
|
78
|
+
isUpdating: false,
|
|
79
|
+
meta: { ...payload.meta },
|
|
80
|
+
links: { ...payload.links },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
this.manager._associateWithRecordArray(identifiersOrInternalModels, this);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
@method _setIdentifiers
|
|
88
|
+
@param {StableRecordIdentifier[]} identifiers
|
|
89
|
+
@param {Object} payload normalized payload
|
|
90
|
+
@private
|
|
91
|
+
*/
|
|
92
|
+
_setIdentifiers(identifiers, payload) {
|
|
93
|
+
this._setObjects(identifiers, payload);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
@@ -1,37 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@module @ember-data/store
|
|
3
3
|
*/
|
|
4
|
-
import type NativeArray from '@ember/array/-private/native-array';
|
|
5
4
|
import ArrayProxy from '@ember/array/proxy';
|
|
6
|
-
import { assert } from '@ember/debug';
|
|
7
5
|
import { computed, get, set } from '@ember/object';
|
|
8
|
-
import { tracked } from '@glimmer/tracking';
|
|
9
6
|
|
|
10
7
|
import { Promise } from 'rsvp';
|
|
11
8
|
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
import type { StableRecordIdentifier } from '../../ts-interfaces/identifier';
|
|
15
|
-
import type { RecordInstance } from '../../ts-interfaces/record-instance';
|
|
16
|
-
import type { FindOptions } from '../../ts-interfaces/store';
|
|
17
|
-
import type CoreStore from '../core-store';
|
|
18
|
-
import type { PromiseArray } from '../promise-proxies';
|
|
19
|
-
import { promiseArray } from '../promise-proxies';
|
|
9
|
+
import { PromiseArray } from '../promise-proxies';
|
|
20
10
|
import SnapshotRecordArray from '../snapshot-record-array';
|
|
21
11
|
import { internalModelFactoryFor } from '../store/internal-model-factory';
|
|
22
12
|
|
|
23
|
-
function recordForIdentifier(store
|
|
13
|
+
function recordForIdentifier(store, identifier) {
|
|
24
14
|
return internalModelFactoryFor(store).lookup(identifier).getRecord();
|
|
25
15
|
}
|
|
26
16
|
|
|
27
|
-
export interface RecordArrayCreateArgs {
|
|
28
|
-
modelName: string;
|
|
29
|
-
store: CoreStore;
|
|
30
|
-
manager: RecordArrayManager;
|
|
31
|
-
content: NativeArray<StableRecordIdentifier>;
|
|
32
|
-
isLoaded: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
17
|
/**
|
|
36
18
|
A record array is an array that contains records of a certain modelName. The record
|
|
37
19
|
array materializes records as needed when they are retrieved for the first
|
|
@@ -45,21 +27,24 @@ export interface RecordArrayCreateArgs {
|
|
|
45
27
|
@public
|
|
46
28
|
@extends Ember.ArrayProxy
|
|
47
29
|
*/
|
|
48
|
-
export default class RecordArray extends ArrayProxy<StableRecordIdentifier, RecordInstance> {
|
|
49
|
-
/**
|
|
50
|
-
The array of client ids backing the record array. When a
|
|
51
|
-
record is requested from the record array, the record
|
|
52
|
-
for the client id at the same index is materialized, if
|
|
53
|
-
necessary, by the store.
|
|
54
30
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
31
|
+
let RecordArray = ArrayProxy.extend({
|
|
32
|
+
init(args) {
|
|
33
|
+
this._super(args);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
The array of client ids backing the record array. When a
|
|
37
|
+
record is requested from the record array, the record
|
|
38
|
+
for the client id at the same index is materialized, if
|
|
39
|
+
necessary, by the store.
|
|
40
|
+
|
|
41
|
+
@property content
|
|
42
|
+
@private
|
|
43
|
+
@type Ember.Array
|
|
44
|
+
*/
|
|
45
|
+
this.set('content', this.content || null);
|
|
46
|
+
|
|
47
|
+
/**
|
|
63
48
|
The flag to signal a `RecordArray` is finished loading data.
|
|
64
49
|
|
|
65
50
|
Example
|
|
@@ -72,49 +57,42 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
72
57
|
@property isLoaded
|
|
73
58
|
@public
|
|
74
59
|
@type Boolean
|
|
75
|
-
*/
|
|
76
|
-
declare isLoaded: boolean;
|
|
77
|
-
/**
|
|
78
|
-
The store that created this record array.
|
|
79
|
-
|
|
80
|
-
@property store
|
|
81
|
-
@private
|
|
82
|
-
@type Store
|
|
83
60
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
declare manager: RecordArrayManager;
|
|
87
|
-
|
|
88
|
-
/**
|
|
61
|
+
this.isLoaded = this.isLoaded || false;
|
|
62
|
+
/**
|
|
89
63
|
The flag to signal a `RecordArray` is currently loading data.
|
|
64
|
+
|
|
90
65
|
Example
|
|
66
|
+
|
|
91
67
|
```javascript
|
|
92
68
|
let people = store.peekAll('person');
|
|
93
69
|
people.get('isUpdating'); // false
|
|
94
70
|
people.update();
|
|
95
71
|
people.get('isUpdating'); // true
|
|
96
72
|
```
|
|
73
|
+
|
|
97
74
|
@property isUpdating
|
|
98
75
|
@public
|
|
99
76
|
@type Boolean
|
|
100
|
-
|
|
101
|
-
|
|
77
|
+
*/
|
|
78
|
+
this.isUpdating = false;
|
|
102
79
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
assert(`Cannot initialize RecordArray with isUpdating`, !props || !('_updatingPromise' in props));
|
|
106
|
-
super.init();
|
|
80
|
+
/**
|
|
81
|
+
The store that created this record array.
|
|
107
82
|
|
|
108
|
-
|
|
109
|
-
|
|
83
|
+
@property store
|
|
84
|
+
@private
|
|
85
|
+
@type Store
|
|
86
|
+
*/
|
|
87
|
+
this.store = this.store || null;
|
|
110
88
|
this._updatingPromise = null;
|
|
111
|
-
}
|
|
89
|
+
},
|
|
112
90
|
|
|
113
91
|
replace() {
|
|
114
92
|
throw new Error(
|
|
115
93
|
`The result of a server query (for all ${this.modelName} types) is immutable. To modify contents, use toArray()`
|
|
116
94
|
);
|
|
117
|
-
}
|
|
95
|
+
},
|
|
118
96
|
|
|
119
97
|
/**
|
|
120
98
|
The modelClass represented by this record array.
|
|
@@ -123,13 +101,12 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
123
101
|
@public
|
|
124
102
|
@type {subclass of Model}
|
|
125
103
|
*/
|
|
126
|
-
|
|
127
|
-
get type() {
|
|
104
|
+
type: computed('modelName', function () {
|
|
128
105
|
if (!this.modelName) {
|
|
129
106
|
return null;
|
|
130
107
|
}
|
|
131
108
|
return this.store.modelFor(this.modelName);
|
|
132
|
-
}
|
|
109
|
+
}).readOnly(),
|
|
133
110
|
|
|
134
111
|
/**
|
|
135
112
|
Retrieves an object from the content by index.
|
|
@@ -139,10 +116,10 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
139
116
|
@param {Number} index
|
|
140
117
|
@return {Model} record
|
|
141
118
|
*/
|
|
142
|
-
objectAtContent(index
|
|
119
|
+
objectAtContent(index) {
|
|
143
120
|
let identifier = get(this, 'content').objectAt(index);
|
|
144
121
|
return identifier ? recordForIdentifier(this.store, identifier) : undefined;
|
|
145
|
-
}
|
|
122
|
+
},
|
|
146
123
|
|
|
147
124
|
/**
|
|
148
125
|
Used to get the latest version of all of the records in this array
|
|
@@ -164,34 +141,33 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
164
141
|
@method update
|
|
165
142
|
@public
|
|
166
143
|
*/
|
|
167
|
-
update()
|
|
168
|
-
if (this
|
|
169
|
-
return this._updatingPromise
|
|
144
|
+
update() {
|
|
145
|
+
if (get(this, 'isUpdating')) {
|
|
146
|
+
return this._updatingPromise;
|
|
170
147
|
}
|
|
171
148
|
|
|
172
|
-
this.isUpdating
|
|
149
|
+
this.set('isUpdating', true);
|
|
173
150
|
|
|
174
|
-
let updatingPromise = this._update()
|
|
175
|
-
updatingPromise.finally(() => {
|
|
151
|
+
let updatingPromise = this._update().finally(() => {
|
|
176
152
|
this._updatingPromise = null;
|
|
177
|
-
if (this.isDestroying || this.isDestroyed) {
|
|
153
|
+
if (this.get('isDestroying') || this.get('isDestroyed')) {
|
|
178
154
|
return;
|
|
179
155
|
}
|
|
180
|
-
this.isUpdating
|
|
156
|
+
this.set('isUpdating', false);
|
|
181
157
|
});
|
|
182
158
|
|
|
183
159
|
this._updatingPromise = updatingPromise;
|
|
184
160
|
|
|
185
161
|
return updatingPromise;
|
|
186
|
-
}
|
|
162
|
+
},
|
|
187
163
|
|
|
188
164
|
/*
|
|
189
165
|
Update this RecordArray and return a promise which resolves once the update
|
|
190
166
|
is finished.
|
|
191
167
|
*/
|
|
192
|
-
_update()
|
|
168
|
+
_update() {
|
|
193
169
|
return this.store.findAll(this.modelName, { reload: true });
|
|
194
|
-
}
|
|
170
|
+
},
|
|
195
171
|
|
|
196
172
|
/**
|
|
197
173
|
Saves all of the records in the `RecordArray`.
|
|
@@ -210,7 +186,7 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
210
186
|
@public
|
|
211
187
|
@return {PromiseArray} promise
|
|
212
188
|
*/
|
|
213
|
-
save()
|
|
189
|
+
save() {
|
|
214
190
|
let promiseLabel = `DS: RecordArray#save ${this.modelName}`;
|
|
215
191
|
let promise = Promise.all(this.invoke('save'), promiseLabel).then(
|
|
216
192
|
() => this,
|
|
@@ -218,8 +194,8 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
218
194
|
'DS: RecordArray#save return RecordArray'
|
|
219
195
|
);
|
|
220
196
|
|
|
221
|
-
return
|
|
222
|
-
}
|
|
197
|
+
return PromiseArray.create({ promise });
|
|
198
|
+
},
|
|
223
199
|
|
|
224
200
|
/**
|
|
225
201
|
@method _unregisterFromManager
|
|
@@ -227,7 +203,7 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
227
203
|
*/
|
|
228
204
|
_unregisterFromManager() {
|
|
229
205
|
this.manager.unregisterRecordArray(this);
|
|
230
|
-
}
|
|
206
|
+
},
|
|
231
207
|
|
|
232
208
|
willDestroy() {
|
|
233
209
|
this._unregisterFromManager();
|
|
@@ -239,34 +215,33 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
239
215
|
// * the exception being: if an dominator has a reference to this object,
|
|
240
216
|
// and must be informed to release e.g. e.g. removing itself from th
|
|
241
217
|
// recordArrayMananger
|
|
242
|
-
set(this, 'content', null
|
|
218
|
+
set(this, 'content', null);
|
|
243
219
|
set(this, 'length', 0);
|
|
244
|
-
|
|
245
|
-
}
|
|
220
|
+
this._super(...arguments);
|
|
221
|
+
},
|
|
246
222
|
|
|
247
223
|
/**
|
|
248
224
|
@method _createSnapshot
|
|
249
225
|
@private
|
|
250
226
|
*/
|
|
251
|
-
_createSnapshot(options
|
|
227
|
+
_createSnapshot(options) {
|
|
252
228
|
// this is private for users, but public for ember-data internals
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
229
|
+
return new SnapshotRecordArray(this, this.get('meta'), options);
|
|
230
|
+
},
|
|
256
231
|
|
|
257
232
|
/**
|
|
258
233
|
@method _dissociateFromOwnRecords
|
|
259
234
|
@internal
|
|
260
235
|
*/
|
|
261
236
|
_dissociateFromOwnRecords() {
|
|
262
|
-
this.content.forEach((identifier) => {
|
|
237
|
+
this.get('content').forEach((identifier) => {
|
|
263
238
|
let recordArrays = this.manager.getRecordArraysForIdentifier(identifier);
|
|
264
239
|
|
|
265
240
|
if (recordArrays) {
|
|
266
241
|
recordArrays.delete(this);
|
|
267
242
|
}
|
|
268
243
|
});
|
|
269
|
-
}
|
|
244
|
+
},
|
|
270
245
|
|
|
271
246
|
/**
|
|
272
247
|
Adds identifiers to the `RecordArray` without duplicates
|
|
@@ -275,9 +250,9 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
275
250
|
@internal
|
|
276
251
|
@param {StableRecordIdentifier[]} identifiers
|
|
277
252
|
*/
|
|
278
|
-
_pushIdentifiers(identifiers
|
|
279
|
-
this
|
|
280
|
-
}
|
|
253
|
+
_pushIdentifiers(identifiers) {
|
|
254
|
+
get(this, 'content').pushObjects(identifiers);
|
|
255
|
+
},
|
|
281
256
|
|
|
282
257
|
/**
|
|
283
258
|
Removes identifiers from the `RecordArray`.
|
|
@@ -286,15 +261,19 @@ export default class RecordArray extends ArrayProxy<StableRecordIdentifier, Reco
|
|
|
286
261
|
@internal
|
|
287
262
|
@param {StableRecordIdentifier[]} identifiers
|
|
288
263
|
*/
|
|
289
|
-
_removeIdentifiers(identifiers
|
|
290
|
-
this
|
|
291
|
-
}
|
|
264
|
+
_removeIdentifiers(identifiers) {
|
|
265
|
+
get(this, 'content').removeObjects(identifiers);
|
|
266
|
+
},
|
|
292
267
|
|
|
293
268
|
/**
|
|
294
269
|
@method _takeSnapshot
|
|
295
270
|
@internal
|
|
296
271
|
*/
|
|
297
|
-
_takeSnapshot()
|
|
298
|
-
return this
|
|
299
|
-
|
|
300
|
-
|
|
272
|
+
_takeSnapshot() {
|
|
273
|
+
return get(this, 'content').map((identifier) =>
|
|
274
|
+
internalModelFactoryFor(this.store).lookup(identifier).createSnapshot()
|
|
275
|
+
);
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
export default RecordArray;
|
|
@@ -3,7 +3,6 @@ import { DEBUG } from '@glimmer/env';
|
|
|
3
3
|
|
|
4
4
|
import type { StableRecordIdentifier } from '../ts-interfaces/identifier';
|
|
5
5
|
import type { RecordData } from '../ts-interfaces/record-data';
|
|
6
|
-
import type { RecordInstance } from '../ts-interfaces/record-instance';
|
|
7
6
|
import WeakCache from './weak-cache';
|
|
8
7
|
|
|
9
8
|
/*
|
|
@@ -41,7 +40,6 @@ export function removeRecordDataFor(identifier: StableRecordIdentifier): void {
|
|
|
41
40
|
|
|
42
41
|
export default function recordDataFor(instance: StableRecordIdentifier): RecordData | null;
|
|
43
42
|
export default function recordDataFor(instance: Instance): RecordData;
|
|
44
|
-
export default function recordDataFor(instance: RecordInstance): RecordData;
|
|
45
43
|
export default function recordDataFor(instance: object): null;
|
|
46
44
|
export default function recordDataFor(instance: Instance | object): RecordData | null {
|
|
47
45
|
if (RecordDataForIdentifierCache.has(instance as StableRecordIdentifier)) {
|
|
@@ -8,7 +8,6 @@ import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
|
8
8
|
|
|
9
9
|
import { SingleResourceDocument } from '../../ts-interfaces/ember-data-json-api';
|
|
10
10
|
import { StableRecordIdentifier } from '../../ts-interfaces/identifier';
|
|
11
|
-
import { RecordInstance } from '../../ts-interfaces/record-instance';
|
|
12
11
|
import CoreStore from '../core-store';
|
|
13
12
|
import { NotificationType, unsubscribe } from '../record-notification-manager';
|
|
14
13
|
import { internalModelFactoryFor, recordIdentifierFor } from '../store/internal-model-factory';
|
|
@@ -194,7 +193,7 @@ export default class BelongsToReference extends Reference {
|
|
|
194
193
|
@param {Object|Promise} objectOrPromise a promise that resolves to a JSONAPI document object describing the new value of this relationship.
|
|
195
194
|
@return {Promise<record>} A promise that resolves with the new value in this belongs-to relationship.
|
|
196
195
|
*/
|
|
197
|
-
async push(data: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<
|
|
196
|
+
async push(data: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<Object> {
|
|
198
197
|
const jsonApiDoc = await resolve(data);
|
|
199
198
|
let record = this.store.push(jsonApiDoc);
|
|
200
199
|
|
|
@@ -268,7 +267,7 @@ export default class BelongsToReference extends Reference {
|
|
|
268
267
|
@public
|
|
269
268
|
@return {Model} the record in this relationship
|
|
270
269
|
*/
|
|
271
|
-
value():
|
|
270
|
+
value(): Object | null {
|
|
272
271
|
let resource = this._resource();
|
|
273
272
|
if (resource && resource.data) {
|
|
274
273
|
let inverseInternalModel = this.store._internalModelForResource(resource.data);
|
|
@@ -4,8 +4,6 @@ import { cached, tracked } from '@glimmer/tracking';
|
|
|
4
4
|
|
|
5
5
|
import { resolve } from 'rsvp';
|
|
6
6
|
|
|
7
|
-
import { ManyArray } from 'ember-data/-private';
|
|
8
|
-
|
|
9
7
|
import type { ManyRelationship } from '@ember-data/record-data/-private';
|
|
10
8
|
import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
11
9
|
|
|
@@ -252,7 +250,7 @@ export default class HasManyReference extends Reference {
|
|
|
252
250
|
*/
|
|
253
251
|
async push(
|
|
254
252
|
objectOrPromise: ExistingResourceObject[] | CollectionResourceDocument | { data: SingleResourceDocument[] }
|
|
255
|
-
): Promise<
|
|
253
|
+
): Promise<any> {
|
|
256
254
|
const payload = await resolve(objectOrPromise);
|
|
257
255
|
let array: Array<ExistingResourceObject | SingleResourceDocument>;
|
|
258
256
|
|
|
@@ -293,7 +291,7 @@ export default class HasManyReference extends Reference {
|
|
|
293
291
|
});
|
|
294
292
|
|
|
295
293
|
// TODO IGOR it seems wrong that we were returning the many array here
|
|
296
|
-
return internalModel.getHasMany(this.key)
|
|
294
|
+
return internalModel.getHasMany(this.key);
|
|
297
295
|
}
|
|
298
296
|
|
|
299
297
|
_isLoaded() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getOwner } from '@ember/application';
|
|
2
2
|
import { get } from '@ember/object';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import require from 'require';
|
|
5
5
|
|
|
6
6
|
import type Model from '@ember-data/model';
|
|
7
7
|
import { HAS_MODEL_PACKAGE } from '@ember-data/private-build-infra';
|
|
@@ -18,7 +18,7 @@ if (HAS_MODEL_PACKAGE) {
|
|
|
18
18
|
let _found;
|
|
19
19
|
_modelForMixin = function () {
|
|
20
20
|
if (!_found) {
|
|
21
|
-
_found = (
|
|
21
|
+
_found = require('@ember-data/model/-private')._modelForMixin;
|
|
22
22
|
}
|
|
23
23
|
return _found(...arguments);
|
|
24
24
|
};
|
|
@@ -3,41 +3,40 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { ModelSchema } from '../ts-interfaces/ds-model';
|
|
6
|
-
import { FindOptions } from '../ts-interfaces/store';
|
|
7
6
|
import type { Dict } from '../ts-interfaces/utils';
|
|
8
7
|
import type RecordArray from './record-arrays/record-array';
|
|
9
8
|
import type Snapshot from './snapshot';
|
|
10
9
|
/**
|
|
11
10
|
SnapshotRecordArray is not directly instantiable.
|
|
12
11
|
Instances are provided to consuming application's
|
|
13
|
-
adapters for certain requests.
|
|
12
|
+
adapters for certain requests.
|
|
14
13
|
|
|
15
14
|
@class SnapshotRecordArray
|
|
16
15
|
@public
|
|
17
16
|
*/
|
|
18
17
|
export default class SnapshotRecordArray {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
private _snapshots: Snapshot[] | null;
|
|
19
|
+
private _recordArray: RecordArray | null;
|
|
20
|
+
private _type: ModelSchema | null;
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
public length: number;
|
|
23
|
+
public meta?: Dict<any>;
|
|
24
|
+
public adapterOptions: Dict<any>;
|
|
25
|
+
public include?: string;
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
SnapshotRecordArray is not directly instantiable.
|
|
30
29
|
Instances are provided to consuming application's
|
|
31
|
-
adapters and serializers for certain requests.
|
|
30
|
+
adapters and serializers for certain requests.
|
|
32
31
|
|
|
33
32
|
@method constructor
|
|
34
33
|
@private
|
|
35
34
|
@constructor
|
|
36
35
|
@param {RecordArray} recordArray
|
|
37
36
|
@param {Object} meta
|
|
38
|
-
@param options
|
|
37
|
+
@param options
|
|
39
38
|
*/
|
|
40
|
-
constructor(recordArray: RecordArray, meta
|
|
39
|
+
constructor(recordArray: RecordArray, meta?: Dict<any>, options: Dict<any> = {}) {
|
|
41
40
|
/**
|
|
42
41
|
An array of snapshots
|
|
43
42
|
@private
|
|
@@ -4,19 +4,10 @@
|
|
|
4
4
|
import { assert } from '@ember/debug';
|
|
5
5
|
import { get } from '@ember/object';
|
|
6
6
|
|
|
7
|
-
import { importSync } from '@embroider/macros';
|
|
8
|
-
|
|
9
7
|
import { HAS_RECORD_DATA_PACKAGE } from '@ember-data/private-build-infra';
|
|
10
|
-
import type BelongsToRelationship from '@ember-data/record-data/addon/-private/relationships/state/belongs-to';
|
|
11
|
-
import type ManyRelationship from '@ember-data/record-data/addon/-private/relationships/state/has-many';
|
|
12
|
-
import type {
|
|
13
|
-
ExistingResourceIdentifierObject,
|
|
14
|
-
NewResourceIdentifierObject,
|
|
15
|
-
} from '@ember-data/store/-private/ts-interfaces/ember-data-json-api';
|
|
16
8
|
|
|
17
9
|
import type { DSModel, DSModelSchema, ModelSchema } from '../ts-interfaces/ds-model';
|
|
18
10
|
import type { StableRecordIdentifier } from '../ts-interfaces/identifier';
|
|
19
|
-
import { OptionsHash } from '../ts-interfaces/minimum-serializer-interface';
|
|
20
11
|
import type { ChangedAttributesHash } from '../ts-interfaces/record-data';
|
|
21
12
|
import type { AttributeSchema, RelationshipSchema } from '../ts-interfaces/record-data-schemas';
|
|
22
13
|
import type { RecordInstance } from '../ts-interfaces/record-instance';
|
|
@@ -331,11 +322,9 @@ export default class Snapshot implements Snapshot {
|
|
|
331
322
|
assert(`snapshot.belongsTo only supported when using the package @ember-data/record-data`);
|
|
332
323
|
}
|
|
333
324
|
|
|
334
|
-
const graphFor = (
|
|
335
|
-
importSync('@ember-data/record-data/-private') as typeof import('@ember-data/record-data/-private')
|
|
336
|
-
).graphFor;
|
|
325
|
+
const graphFor = require('@ember-data/record-data/-private').graphFor;
|
|
337
326
|
const { identifier } = this;
|
|
338
|
-
const relationship = graphFor(this._store._storeWrapper).get(identifier, keyName)
|
|
327
|
+
const relationship = graphFor(this._store._storeWrapper).get(identifier, keyName);
|
|
339
328
|
|
|
340
329
|
assert(
|
|
341
330
|
`You looked up the ${keyName} belongsTo relationship for { type: ${identifier.type}, id: ${identifier.id}, lid: ${identifier.lid} but no such relationship was found.`,
|
|
@@ -432,11 +421,9 @@ export default class Snapshot implements Snapshot {
|
|
|
432
421
|
assert(`snapshot.hasMany only supported when using the package @ember-data/record-data`);
|
|
433
422
|
}
|
|
434
423
|
|
|
435
|
-
const graphFor = (
|
|
436
|
-
importSync('@ember-data/record-data/-private') as typeof import('@ember-data/record-data/-private')
|
|
437
|
-
).graphFor;
|
|
424
|
+
const graphFor = require('@ember-data/record-data/-private').graphFor;
|
|
438
425
|
const { identifier } = this;
|
|
439
|
-
const relationship = graphFor(this._store._storeWrapper).get(identifier, keyName)
|
|
426
|
+
const relationship = graphFor(this._store._storeWrapper).get(identifier, keyName);
|
|
440
427
|
assert(
|
|
441
428
|
`You looked up the ${keyName} hasMany relationship for { type: ${identifier.type}, id: ${identifier.id}, lid: ${identifier.lid} but no such relationship was found.`,
|
|
442
429
|
relationship
|
|
@@ -454,9 +441,7 @@ export default class Snapshot implements Snapshot {
|
|
|
454
441
|
let internalModel = store._internalModelForResource(member);
|
|
455
442
|
if (!internalModel.isDeleted()) {
|
|
456
443
|
if (returnModeIsIds) {
|
|
457
|
-
(results as RecordId[]).push(
|
|
458
|
-
(member as ExistingResourceIdentifierObject | NewResourceIdentifierObject).id || null
|
|
459
|
-
);
|
|
444
|
+
(results as RecordId[]).push(member.id || null);
|
|
460
445
|
} else {
|
|
461
446
|
(results as Snapshot[]).push(internalModel.createSnapshot());
|
|
462
447
|
}
|
|
@@ -549,9 +534,7 @@ export default class Snapshot implements Snapshot {
|
|
|
549
534
|
@return {Object} an object whose values are primitive JSON values only
|
|
550
535
|
@public
|
|
551
536
|
*/
|
|
552
|
-
serialize(options
|
|
553
|
-
|
|
554
|
-
assert(`Cannot serialize record, no serializer found`, serializer);
|
|
555
|
-
return serializer.serialize(this, options);
|
|
537
|
+
serialize(options: unknown): unknown {
|
|
538
|
+
return this._store.serializerFor(this.modelName).serialize(this, options);
|
|
556
539
|
}
|
|
557
540
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { deprecate } from '@ember/debug';
|
|
2
1
|
import { get } from '@ember/object';
|
|
3
2
|
import { DEBUG } from '@glimmer/env';
|
|
4
3
|
|
|
5
4
|
import { resolve } from 'rsvp';
|
|
6
5
|
|
|
7
|
-
import { DEPRECATE_RSVP_PROMISE } from '@ember-data/private-build-infra/deprecations';
|
|
8
|
-
|
|
9
6
|
/**
|
|
10
7
|
@module @ember-data/store
|
|
11
8
|
*/
|
|
@@ -35,27 +32,7 @@ export function guardDestroyedStore(promise, store, label) {
|
|
|
35
32
|
if (DEBUG) {
|
|
36
33
|
token = store._trackAsyncRequestStart(label);
|
|
37
34
|
}
|
|
38
|
-
let wrapperPromise = resolve(promise, label).then((
|
|
39
|
-
if (!_objectIsAlive(store)) {
|
|
40
|
-
if (DEPRECATE_RSVP_PROMISE) {
|
|
41
|
-
deprecate(
|
|
42
|
-
`A Promise did not resolve by the time the store was destroyed. This will error in a future release.`,
|
|
43
|
-
false,
|
|
44
|
-
{
|
|
45
|
-
id: 'ember-data:rsvp-unresolved-async',
|
|
46
|
-
until: '5.0',
|
|
47
|
-
for: '@ember-data/store',
|
|
48
|
-
since: {
|
|
49
|
-
available: '4.5',
|
|
50
|
-
enabled: '4.5',
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return promise;
|
|
58
|
-
});
|
|
35
|
+
let wrapperPromise = resolve(promise, label).then((v) => promise);
|
|
59
36
|
|
|
60
37
|
return _guard(wrapperPromise, () => {
|
|
61
38
|
if (DEBUG) {
|