@ember-data/store 4.4.0-alpha.8 → 4.4.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 +119 -130
- 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 +160 -264
- 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
|
@@ -7,8 +7,9 @@ import { DEBUG } from '@glimmer/env';
|
|
|
7
7
|
import type DSModelClass from '@ember-data/model';
|
|
8
8
|
|
|
9
9
|
import type { DSModel } from '../ts-interfaces/ds-model';
|
|
10
|
-
import type { StableRecordIdentifier } from '../ts-interfaces/identifier';
|
|
10
|
+
import type { RecordIdentifier, StableRecordIdentifier } from '../ts-interfaces/identifier';
|
|
11
11
|
import type { RecordDataRecordWrapper } from '../ts-interfaces/record-data-record-wrapper';
|
|
12
|
+
import type { RelationshipsSchema } from '../ts-interfaces/record-data-schemas';
|
|
12
13
|
import type { SchemaDefinitionService } from '../ts-interfaces/schema-definition-service';
|
|
13
14
|
import CoreStore from './core-store';
|
|
14
15
|
import type ShimModelClass from './model/shim-model-class';
|
|
@@ -107,6 +108,14 @@ class Store extends CoreStore {
|
|
|
107
108
|
return this._relationshipsDefinitionFor({ type: modelName })[key];
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
_attributesDefinitionFor(identifier: RecordIdentifier | { type: string }) {
|
|
112
|
+
return this.getSchemaDefinitionService().attributesDefinitionFor(identifier);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {
|
|
116
|
+
return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier);
|
|
117
|
+
}
|
|
118
|
+
|
|
110
119
|
getSchemaDefinitionService(): SchemaDefinitionService {
|
|
111
120
|
if (!this._schemaDefinitionService) {
|
|
112
121
|
this._schemaDefinitionService = new DSModelSchemaDefinitionService(this);
|
|
@@ -2,24 +2,19 @@
|
|
|
2
2
|
* @module @ember-data/store
|
|
3
3
|
*/
|
|
4
4
|
import { A } from '@ember/array';
|
|
5
|
-
import { assert,
|
|
5
|
+
import { assert, warn } from '@ember/debug';
|
|
6
6
|
import { _backburner as emberBackburner } from '@ember/runloop';
|
|
7
7
|
import { DEBUG } from '@glimmer/env';
|
|
8
8
|
|
|
9
|
-
import { default as RSVP,
|
|
10
|
-
|
|
11
|
-
import { DEPRECATE_RSVP_PROMISE } from '@ember-data/private-build-infra/deprecations';
|
|
9
|
+
import { default as RSVP, Promise } from 'rsvp';
|
|
12
10
|
|
|
13
11
|
import type { CollectionResourceDocument, SingleResourceDocument } from '../ts-interfaces/ember-data-json-api';
|
|
14
12
|
import type { FindRecordQuery, Request, SaveRecordMutation } from '../ts-interfaces/fetch-manager';
|
|
15
13
|
import type { ExistingRecordIdentifier, RecordIdentifier, StableRecordIdentifier } from '../ts-interfaces/identifier';
|
|
16
|
-
import type { MinimumSerializerInterface } from '../ts-interfaces/minimum-serializer-interface';
|
|
17
|
-
import { FindOptions } from '../ts-interfaces/store';
|
|
18
14
|
import type { Dict } from '../ts-interfaces/utils';
|
|
19
15
|
import coerceId from './coerce-id';
|
|
20
16
|
import type CoreStore from './core-store';
|
|
21
17
|
import { errorsArrayToHash } from './errors-utils';
|
|
22
|
-
import ShimModelClass from './model/shim-model-class';
|
|
23
18
|
import RequestCache, { RequestPromise } from './request-cache';
|
|
24
19
|
import type { PrivateSnapshot } from './snapshot';
|
|
25
20
|
import Snapshot from './snapshot';
|
|
@@ -35,15 +30,8 @@ function payloadIsNotBlank(adapterPayload): boolean {
|
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
type AdapterErrors = Error & { errors?: string[]; isAdapterError?: true };
|
|
39
|
-
type SerializerWithParseErrors = MinimumSerializerInterface & {
|
|
40
|
-
extractErrors?(store: CoreStore, modelClass: ShimModelClass, error: AdapterErrors, recordId: string | null): any;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
33
|
export const SaveOp: unique symbol = Symbol('SaveOp');
|
|
44
34
|
|
|
45
|
-
export type FetchMutationOptions = FindOptions & { [SaveOp]: 'createRecord' | 'deleteRecord' | 'updateRecord' };
|
|
46
|
-
|
|
47
35
|
interface PendingFetchItem {
|
|
48
36
|
identifier: ExistingRecordIdentifier;
|
|
49
37
|
queryRequest: Request;
|
|
@@ -56,7 +44,7 @@ interface PendingSaveItem {
|
|
|
56
44
|
resolver: RSVP.Deferred<any>;
|
|
57
45
|
snapshot: Snapshot;
|
|
58
46
|
identifier: RecordIdentifier;
|
|
59
|
-
options:
|
|
47
|
+
options: { [k: string]: unknown; [SaveOp]: 'createRecord' | 'saveRecord' | 'updateRecord' };
|
|
60
48
|
queryRequest: Request;
|
|
61
49
|
}
|
|
62
50
|
|
|
@@ -90,7 +78,7 @@ export default class FetchManager {
|
|
|
90
78
|
|
|
91
79
|
@internal
|
|
92
80
|
*/
|
|
93
|
-
scheduleSave(identifier: RecordIdentifier, options:
|
|
81
|
+
scheduleSave(identifier: RecordIdentifier, options: any = {}): RSVP.Promise<null | SingleResourceDocument> {
|
|
94
82
|
let promiseLabel = 'DS: Model#save ' + this;
|
|
95
83
|
let resolver = RSVP.defer<null | SingleResourceDocument>(promiseLabel);
|
|
96
84
|
let query: SaveRecordMutation = {
|
|
@@ -137,8 +125,8 @@ export default class FetchManager {
|
|
|
137
125
|
typeof adapter[operation] === 'function'
|
|
138
126
|
);
|
|
139
127
|
|
|
140
|
-
let promise = resolve().then(() => adapter[operation](store, modelClass, snapshot));
|
|
141
|
-
let serializer
|
|
128
|
+
let promise = Promise.resolve().then(() => adapter[operation](store, modelClass, snapshot));
|
|
129
|
+
let serializer = store.serializerFor(modelName);
|
|
142
130
|
let label = `DS: Extract and notify about ${operation} completion of ${internalModel}`;
|
|
143
131
|
|
|
144
132
|
assert(
|
|
@@ -146,26 +134,11 @@ export default class FetchManager {
|
|
|
146
134
|
promise !== undefined
|
|
147
135
|
);
|
|
148
136
|
|
|
149
|
-
promise =
|
|
150
|
-
|
|
151
|
-
if (!_objectIsAlive(internalModel)) {
|
|
152
|
-
if (DEPRECATE_RSVP_PROMISE) {
|
|
153
|
-
deprecate(
|
|
154
|
-
`A Promise while saving ${modelName} did not resolve by the time your model was destroyed. This will error in a future release.`,
|
|
155
|
-
false,
|
|
156
|
-
{
|
|
157
|
-
id: 'ember-data:rsvp-unresolved-async',
|
|
158
|
-
until: '5.0',
|
|
159
|
-
for: '@ember-data/store',
|
|
160
|
-
since: {
|
|
161
|
-
available: '4.5',
|
|
162
|
-
enabled: '4.5',
|
|
163
|
-
},
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
137
|
+
promise = guardDestroyedStore(promise, store, label);
|
|
138
|
+
promise = _guard(promise, _bind(_objectIsAlive, internalModel));
|
|
168
139
|
|
|
140
|
+
promise = promise.then(
|
|
141
|
+
(adapterPayload) => {
|
|
169
142
|
if (adapterPayload) {
|
|
170
143
|
return normalizeResponseHelper(serializer, store, modelClass, adapterPayload, snapshot.id, operation);
|
|
171
144
|
}
|
|
@@ -174,8 +147,7 @@ export default class FetchManager {
|
|
|
174
147
|
if (error && error.isAdapterError === true && error.code === 'InvalidError') {
|
|
175
148
|
let parsedErrors = error.errors;
|
|
176
149
|
|
|
177
|
-
|
|
178
|
-
if (serializer && typeof serializer.extractErrors === 'function') {
|
|
150
|
+
if (typeof serializer.extractErrors === 'function') {
|
|
179
151
|
parsedErrors = serializer.extractErrors(store, modelClass, error, snapshot.id);
|
|
180
152
|
} else {
|
|
181
153
|
parsedErrors = errorsArrayToHash(error.errors);
|
|
@@ -207,7 +179,7 @@ export default class FetchManager {
|
|
|
207
179
|
}
|
|
208
180
|
}
|
|
209
181
|
|
|
210
|
-
scheduleFetch(identifier: ExistingRecordIdentifier, options: any, shouldTrace: boolean): Promise<any> {
|
|
182
|
+
scheduleFetch(identifier: ExistingRecordIdentifier, options: any, shouldTrace: boolean): RSVP.Promise<any> {
|
|
211
183
|
// TODO Probably the store should pass in the query object
|
|
212
184
|
|
|
213
185
|
let query: FindRecordQuery = {
|
|
@@ -290,16 +262,17 @@ export default class FetchManager {
|
|
|
290
262
|
|
|
291
263
|
let snapshot = new Snapshot(fetchItem.options, identifier, this._store);
|
|
292
264
|
let klass = this._store.modelFor(identifier.type);
|
|
265
|
+
|
|
266
|
+
let promise = Promise.resolve().then(() => {
|
|
267
|
+
return adapter.findRecord(this._store, klass, identifier.id, snapshot);
|
|
268
|
+
});
|
|
269
|
+
|
|
293
270
|
let id = identifier.id;
|
|
271
|
+
|
|
294
272
|
let label = `DS: Handle Adapter#findRecord of '${modelName}' with id: '${id}'`;
|
|
295
273
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return adapter.findRecord(this._store, klass, identifier.id, snapshot);
|
|
299
|
-
}),
|
|
300
|
-
this._store,
|
|
301
|
-
label
|
|
302
|
-
).then(
|
|
274
|
+
promise = guardDestroyedStore(promise, this._store, label);
|
|
275
|
+
promise = promise.then(
|
|
303
276
|
(adapterPayload) => {
|
|
304
277
|
assert(
|
|
305
278
|
`You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`,
|
|
@@ -514,7 +487,7 @@ export default class FetchManager {
|
|
|
514
487
|
|
|
515
488
|
let groups: Snapshot[][];
|
|
516
489
|
if (adapter.groupRecordsForFindMany) {
|
|
517
|
-
groups = adapter.groupRecordsForFindMany(this
|
|
490
|
+
groups = adapter.groupRecordsForFindMany(this, snapshots);
|
|
518
491
|
} else {
|
|
519
492
|
groups = [snapshots];
|
|
520
493
|
}
|