@ember-data/store 4.10.0-beta.3 → 4.11.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/caches/instance-cache.ts +8 -7
- package/addon/-private/legacy-model-support/shim-model-class.ts +10 -5
- package/addon/-private/managers/record-array-manager.ts +1 -4
- package/addon/-private/managers/record-data-manager.ts +1 -1
- package/addon/-private/record-arrays/identifier-array.ts +12 -57
- package/addon/-private/store-service.ts +7 -15
- package/index.js +0 -1
- package/package.json +9 -9
|
@@ -423,21 +423,16 @@ export class InstanceCache {
|
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
let removeFromRecordArray = true;
|
|
427
426
|
if (recordData) {
|
|
428
|
-
removeFromRecordArray = !recordData.isDeletionCommitted(identifier);
|
|
429
427
|
recordData.unloadRecord(identifier);
|
|
430
428
|
this.__instances.recordData.delete(identifier);
|
|
431
429
|
removeRecordDataFor(identifier);
|
|
432
430
|
} else {
|
|
433
|
-
removeFromRecordArray = false;
|
|
434
431
|
this.disconnect(identifier);
|
|
435
432
|
}
|
|
436
433
|
|
|
437
434
|
this.store._fetchManager.clearEntries(identifier);
|
|
438
|
-
|
|
439
|
-
this.store.recordArrayManager.identifierRemoved(identifier);
|
|
440
|
-
}
|
|
435
|
+
this.store.recordArrayManager.identifierRemoved(identifier);
|
|
441
436
|
if (LOG_INSTANCE_CACHE) {
|
|
442
437
|
// eslint-disable-next-line no-console
|
|
443
438
|
console.log(`InstanceCache: unloaded RecordData for ${String(identifier)}`);
|
|
@@ -476,6 +471,12 @@ export class InstanceCache {
|
|
|
476
471
|
const isEmpty = _isEmpty(this, identifier);
|
|
477
472
|
const isLoading = _isLoading(this, identifier);
|
|
478
473
|
|
|
474
|
+
if (options.preload) {
|
|
475
|
+
this.store._join(() => {
|
|
476
|
+
preloadData(this.store, identifier, options.preload!);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
479
480
|
let promise: Promise<StableRecordIdentifier>;
|
|
480
481
|
if (isEmpty) {
|
|
481
482
|
assertIdentifierHasId(identifier);
|
|
@@ -611,7 +612,7 @@ export function recordDataIsFullyDeleted(cache: InstanceCache, identifier: Stabl
|
|
|
611
612
|
models.
|
|
612
613
|
*/
|
|
613
614
|
type PreloadRelationshipValue = RecordInstance | string;
|
|
614
|
-
|
|
615
|
+
function preloadData(store: Store, identifier: StableRecordIdentifier, preload: Dict<unknown>) {
|
|
615
616
|
let jsonPayload: JsonApiResource = {};
|
|
616
617
|
//TODO(Igor) consider the polymorphic case
|
|
617
618
|
const schemas = store.getSchemaDefinitionService();
|
|
@@ -81,11 +81,16 @@ export default class ShimModelClass implements ModelSchema {
|
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
eachTransformedAttribute<T>(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
eachTransformedAttribute<T>(
|
|
85
|
+
callback: (this: T | undefined, key: string, relationship: RelationshipSchema) => void,
|
|
86
|
+
binding?: T
|
|
87
|
+
) {
|
|
88
|
+
let relationshipDefs = this.__store
|
|
89
|
+
.getSchemaDefinitionService()
|
|
90
|
+
.relationshipsDefinitionFor({ type: this.modelName });
|
|
91
|
+
Object.keys(relationshipDefs).forEach((key) => {
|
|
92
|
+
if (relationshipDefs[key]!.type) {
|
|
93
|
+
callback.call(binding, key, relationshipDefs[key] as RelationshipSchema);
|
|
89
94
|
}
|
|
90
95
|
});
|
|
91
96
|
}
|
|
@@ -357,10 +357,7 @@ function sync(array: IdentifierArray, changes: Map<StableRecordIdentifier, 'add'
|
|
|
357
357
|
// state = array[SOURCE] = [];
|
|
358
358
|
} else {
|
|
359
359
|
removes.forEach((i) => {
|
|
360
|
-
|
|
361
|
-
if (index !== -1) {
|
|
362
|
-
state.splice(index, 1);
|
|
363
|
-
}
|
|
360
|
+
state.splice(state.indexOf(i), 1);
|
|
364
361
|
});
|
|
365
362
|
}
|
|
366
363
|
}
|
|
@@ -119,7 +119,7 @@ export class NonSingletonRecordDataManager implements RecordData {
|
|
|
119
119
|
// called by something V1
|
|
120
120
|
if (!isStableIdentifier(identifier)) {
|
|
121
121
|
data = identifier as JsonApiResource;
|
|
122
|
-
hasRecord = data as
|
|
122
|
+
hasRecord = data as boolean;
|
|
123
123
|
identifier = this.#identifier;
|
|
124
124
|
}
|
|
125
125
|
if (this.#isDeprecated(recordData)) {
|
|
@@ -114,33 +114,6 @@ interface PrivateState {
|
|
|
114
114
|
links: Links | PaginationLinks | null;
|
|
115
115
|
meta: Dict<unknown> | null;
|
|
116
116
|
}
|
|
117
|
-
type ForEachCB = (record: RecordInstance, index: number, context: IdentifierArray) => void;
|
|
118
|
-
function safeForEach(
|
|
119
|
-
instance: IdentifierArray,
|
|
120
|
-
arr: StableRecordIdentifier[],
|
|
121
|
-
store: Store,
|
|
122
|
-
callback: ForEachCB,
|
|
123
|
-
target: unknown
|
|
124
|
-
) {
|
|
125
|
-
if (target === undefined) {
|
|
126
|
-
target = null;
|
|
127
|
-
}
|
|
128
|
-
// clone to prevent mutation
|
|
129
|
-
arr = arr.slice();
|
|
130
|
-
assert('`forEach` expects a function as first argument.', typeof callback === 'function');
|
|
131
|
-
|
|
132
|
-
// because we retrieveLatest above we need not worry if array is mutated during iteration
|
|
133
|
-
// by unloadRecord/rollbackAttributes
|
|
134
|
-
// push/add/removeObject may still be problematic
|
|
135
|
-
// but this is a more traditionally expected forEach bug.
|
|
136
|
-
const length = arr.length; // we need to access length to ensure we are consumed
|
|
137
|
-
|
|
138
|
-
for (let index = 0; index < length; index++) {
|
|
139
|
-
callback.call(target, store._instanceCache.getRecord(arr[index]), index, instance);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return instance;
|
|
143
|
-
}
|
|
144
117
|
|
|
145
118
|
/**
|
|
146
119
|
A record array is an array that contains records of a certain type (or modelName).
|
|
@@ -268,25 +241,15 @@ class IdentifierArray {
|
|
|
268
241
|
let fn = boundFns.get(prop);
|
|
269
242
|
|
|
270
243
|
if (fn === undefined) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
fn = function () {
|
|
281
|
-
subscribe(_TAG);
|
|
282
|
-
// array functions must run through Reflect to work properly
|
|
283
|
-
// binding via other means will not work.
|
|
284
|
-
transaction = true;
|
|
285
|
-
let result = Reflect.apply(target[prop] as ProxiedMethod, receiver, arguments) as unknown;
|
|
286
|
-
transaction = false;
|
|
287
|
-
return result;
|
|
288
|
-
};
|
|
289
|
-
}
|
|
244
|
+
fn = function () {
|
|
245
|
+
subscribe(_TAG);
|
|
246
|
+
// array functions must run through Reflect to work properly
|
|
247
|
+
// binding via other means will not work.
|
|
248
|
+
transaction = true;
|
|
249
|
+
let result = Reflect.apply(target[prop] as ProxiedMethod, receiver, arguments) as unknown;
|
|
250
|
+
transaction = false;
|
|
251
|
+
return result;
|
|
252
|
+
};
|
|
290
253
|
|
|
291
254
|
boundFns.set(prop, fn);
|
|
292
255
|
}
|
|
@@ -308,7 +271,7 @@ class IdentifierArray {
|
|
|
308
271
|
const args: unknown[] = Array.prototype.slice.call(arguments);
|
|
309
272
|
assert(`Cannot start a new array transaction while a previous transaction is underway`, !transaction);
|
|
310
273
|
transaction = true;
|
|
311
|
-
let result
|
|
274
|
+
let result = Reflect.apply(target[prop] as ProxiedMethod, receiver, args) as unknown;
|
|
312
275
|
self[MUTATE]!(prop as string, args, result);
|
|
313
276
|
addToTransaction(_TAG);
|
|
314
277
|
// TODO handle cache updates
|
|
@@ -695,21 +658,13 @@ if (DEPRECATE_ARRAY_LIKE) {
|
|
|
695
658
|
|
|
696
659
|
IdentifierArray.prototype.removeObject = function (obj: RecordInstance) {
|
|
697
660
|
deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'removeObject', 'splice');
|
|
698
|
-
|
|
699
|
-
if (index !== -1) {
|
|
700
|
-
this.splice(index, 1);
|
|
701
|
-
}
|
|
661
|
+
this.splice(this.indexOf(obj), 1);
|
|
702
662
|
return this;
|
|
703
663
|
};
|
|
704
664
|
|
|
705
665
|
IdentifierArray.prototype.removeObjects = function (objs: RecordInstance[]) {
|
|
706
666
|
deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'removeObjects', 'splice');
|
|
707
|
-
objs.forEach((obj) =>
|
|
708
|
-
const index = this.indexOf(obj);
|
|
709
|
-
if (index !== -1) {
|
|
710
|
-
this.splice(index, 1);
|
|
711
|
-
}
|
|
712
|
-
});
|
|
667
|
+
objs.forEach((obj) => this.splice(this.indexOf(obj), 1));
|
|
713
668
|
return this;
|
|
714
669
|
};
|
|
715
670
|
|
|
@@ -45,7 +45,6 @@ import { IdentifierCache } from './caches/identifier-cache';
|
|
|
45
45
|
import {
|
|
46
46
|
InstanceCache,
|
|
47
47
|
peekRecordIdentifier,
|
|
48
|
-
preloadData,
|
|
49
48
|
recordDataIsFullyDeleted,
|
|
50
49
|
recordIdentifierFor,
|
|
51
50
|
setRecordIdentifier,
|
|
@@ -483,7 +482,6 @@ class Store extends Service {
|
|
|
483
482
|
@return {subclass of Model | ShimModelClass}
|
|
484
483
|
*/
|
|
485
484
|
// TODO @deprecate in favor of schema APIs, requires adapter/serializer overhaul or replacement
|
|
486
|
-
declare _forceShim: boolean;
|
|
487
485
|
modelFor(modelName: string): ShimModelClass | DSModelClass {
|
|
488
486
|
if (DEBUG) {
|
|
489
487
|
assertDestroyedStoreOnly(this, 'modelFor');
|
|
@@ -499,7 +497,7 @@ class Store extends Service {
|
|
|
499
497
|
|
|
500
498
|
// for factorFor factory/class split
|
|
501
499
|
let klass = maybeFactory && maybeFactory.class ? maybeFactory.class : maybeFactory;
|
|
502
|
-
if (!klass || !klass.isModel
|
|
500
|
+
if (!klass || !klass.isModel) {
|
|
503
501
|
assert(
|
|
504
502
|
`No model was found for '${modelName}' and no schema handles the type`,
|
|
505
503
|
this.getSchemaDefinitionService().doesTypeExist(modelName)
|
|
@@ -1129,12 +1127,6 @@ class Store extends Service {
|
|
|
1129
1127
|
let promise;
|
|
1130
1128
|
options = options || {};
|
|
1131
1129
|
|
|
1132
|
-
if (options.preload) {
|
|
1133
|
-
this._join(() => {
|
|
1134
|
-
preloadData(this, identifier, options!.preload!);
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
1130
|
// if not loaded start loading
|
|
1139
1131
|
if (!this._instanceCache.recordIsLoaded(identifier)) {
|
|
1140
1132
|
promise = this._instanceCache._fetchDataIfNeededForIdentifier(identifier, options);
|
|
@@ -1142,7 +1134,6 @@ class Store extends Service {
|
|
|
1142
1134
|
// Refetch if the reload option is passed
|
|
1143
1135
|
} else if (options.reload) {
|
|
1144
1136
|
assertIdentifierHasId(identifier);
|
|
1145
|
-
|
|
1146
1137
|
promise = this._fetchManager.scheduleFetch(identifier, options);
|
|
1147
1138
|
} else {
|
|
1148
1139
|
let snapshot: Snapshot | null = null;
|
|
@@ -2319,8 +2310,8 @@ class Store extends Service {
|
|
|
2319
2310
|
|
|
2320
2311
|
const saveOptions = Object.assign({ [SaveOp]: operation }, options);
|
|
2321
2312
|
let fetchManagerPromise = this._fetchManager.scheduleSave(identifier, saveOptions);
|
|
2322
|
-
return fetchManagerPromise
|
|
2323
|
-
|
|
2313
|
+
return fetchManagerPromise.then(
|
|
2314
|
+
(payload) => {
|
|
2324
2315
|
if (LOG_PAYLOADS) {
|
|
2325
2316
|
try {
|
|
2326
2317
|
let data = payload ? JSON.parse(JSON.stringify(payload)) : payload;
|
|
@@ -2375,8 +2366,8 @@ class Store extends Service {
|
|
|
2375
2366
|
}
|
|
2376
2367
|
});
|
|
2377
2368
|
return record;
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2369
|
+
},
|
|
2370
|
+
(e) => {
|
|
2380
2371
|
let err = e;
|
|
2381
2372
|
if (!e) {
|
|
2382
2373
|
err = new Error(`Unknown Error Occurred During Request`);
|
|
@@ -2385,7 +2376,8 @@ class Store extends Service {
|
|
|
2385
2376
|
}
|
|
2386
2377
|
adapterDidInvalidate(this, identifier, err);
|
|
2387
2378
|
throw err;
|
|
2388
|
-
}
|
|
2379
|
+
}
|
|
2380
|
+
);
|
|
2389
2381
|
}
|
|
2390
2382
|
|
|
2391
2383
|
/**
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/store",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"description": "The core of EmberData. Provides the Store service which coordinates the cache with the network and presentation layers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"author": "",
|
|
15
15
|
"directories": {},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@ember-data/model": "4.
|
|
18
|
-
"@ember-data/record-data": "4.
|
|
19
|
-
"@ember-data/tracking": "4.
|
|
20
|
-
"@ember/string": "^3.0.
|
|
17
|
+
"@ember-data/model": "4.11.0",
|
|
18
|
+
"@ember-data/record-data": "4.11.0",
|
|
19
|
+
"@ember-data/tracking": "4.11.0",
|
|
20
|
+
"@ember/string": "^3.0.1",
|
|
21
21
|
"@glimmer/tracking": "^1.1.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependenciesMeta": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@ember-data/canary-features": "4.
|
|
41
|
-
"@ember-data/private-build-infra": "4.
|
|
40
|
+
"@ember-data/canary-features": "4.11.0",
|
|
41
|
+
"@ember-data/private-build-infra": "4.11.0",
|
|
42
42
|
"@embroider/macros": "^1.10.0",
|
|
43
|
-
"ember-auto-import": "^2.
|
|
43
|
+
"ember-auto-import": "^2.4.3",
|
|
44
44
|
"ember-cached-decorator-polyfill": "^1.0.1",
|
|
45
45
|
"ember-cli-babel": "^7.26.11"
|
|
46
46
|
},
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"volta": {
|
|
58
58
|
"extends": "../../package.json"
|
|
59
59
|
},
|
|
60
|
-
"packageManager": "pnpm@7.
|
|
60
|
+
"packageManager": "pnpm@7.15.0"
|
|
61
61
|
}
|