@ember-data/store 4.8.0-alpha.3 → 4.8.0-alpha.6
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/identifier-cache.ts +65 -66
- package/addon/-private/caches/instance-cache.ts +173 -236
- package/addon/-private/caches/record-data-for.ts +1 -6
- package/addon/-private/index.ts +13 -10
- package/addon/-private/legacy-model-support/record-reference.ts +12 -10
- package/addon/-private/legacy-model-support/schema-definition-service.ts +9 -4
- package/addon/-private/legacy-model-support/shim-model-class.ts +17 -10
- package/addon/-private/managers/record-array-manager.ts +282 -321
- package/addon/-private/managers/record-data-manager.ts +822 -0
- package/addon/-private/managers/record-data-store-wrapper.ts +295 -91
- package/addon/-private/managers/record-notification-manager.ts +45 -32
- package/addon/-private/network/fetch-manager.ts +292 -300
- package/addon/-private/network/finders.js +11 -6
- package/addon/-private/network/request-cache.ts +20 -17
- package/addon/-private/network/snapshot-record-array.ts +12 -29
- package/addon/-private/network/snapshot.ts +25 -27
- package/addon/-private/proxies/promise-proxies.ts +72 -11
- package/addon/-private/record-arrays/identifier-array.ts +924 -0
- package/addon/-private/store-service.ts +380 -114
- package/addon/-private/utils/is-non-empty-string.ts +1 -1
- package/addon/-private/utils/promise-record.ts +2 -3
- package/addon/-private/utils/uuid-polyfill.ts +71 -0
- package/package.json +11 -7
- package/addon/-private/backburner.js +0 -25
- package/addon/-private/record-arrays/adapter-populated-record-array.ts +0 -128
- package/addon/-private/record-arrays/record-array.ts +0 -320
- package/addon/-private/utils/weak-cache.ts +0 -125
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import { assert } from '@ember/debug';
|
|
2
|
-
import { DEBUG } from '@glimmer/env';
|
|
3
2
|
|
|
4
3
|
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
5
4
|
import type { RecordData } from '@ember-data/types/q/record-data';
|
|
6
5
|
import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
7
6
|
|
|
8
|
-
import WeakCache from '../utils/weak-cache';
|
|
9
|
-
|
|
10
7
|
/*
|
|
11
8
|
* Returns the RecordData instance associated with a given
|
|
12
9
|
* Model or Identifier
|
|
13
10
|
*/
|
|
14
11
|
|
|
15
|
-
const RecordDataForIdentifierCache = new
|
|
16
|
-
DEBUG ? 'recordData' : ''
|
|
17
|
-
);
|
|
12
|
+
const RecordDataForIdentifierCache = new Map<StableRecordIdentifier | RecordInstance, RecordData>();
|
|
18
13
|
|
|
19
14
|
export function setRecordDataFor(identifier: StableRecordIdentifier | RecordInstance, recordData: RecordData): void {
|
|
20
15
|
assert(
|
package/addon/-private/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ export {
|
|
|
18
18
|
setIdentifierUpdateMethod,
|
|
19
19
|
setIdentifierForgetMethod,
|
|
20
20
|
setIdentifierResetMethod,
|
|
21
|
+
isStableIdentifier,
|
|
21
22
|
} from './caches/identifier-cache';
|
|
22
23
|
|
|
23
24
|
export function normalizeModelName(modelName: string) {
|
|
@@ -37,20 +38,22 @@ export function normalizeModelName(modelName: string) {
|
|
|
37
38
|
assert(`normalizeModelName support has been removed`);
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
// TODO this should be a deprecated helper but we have so much usage of it
|
|
42
|
+
// to also eliminate
|
|
40
43
|
export { default as coerceId } from './utils/coerce-id';
|
|
41
44
|
|
|
42
|
-
export {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
export {
|
|
46
|
+
default as RecordArray,
|
|
47
|
+
default as IdentifierArray,
|
|
48
|
+
Collection as AdapterPopulatedRecordArray,
|
|
49
|
+
SOURCE,
|
|
50
|
+
MUTATE,
|
|
51
|
+
IDENTIFIER_ARRAY_TAG,
|
|
52
|
+
} from './record-arrays/identifier-array';
|
|
53
|
+
export { default as RecordArrayManager, fastPush } from './managers/record-array-manager';
|
|
48
54
|
|
|
49
55
|
// // Used by tests
|
|
50
56
|
export { default as SnapshotRecordArray } from './network/snapshot-record-array';
|
|
51
57
|
|
|
52
|
-
//
|
|
58
|
+
// leaked for private use / test use, should investigate removing
|
|
53
59
|
export { default as recordDataFor, removeRecordDataFor } from './caches/record-data-for';
|
|
54
|
-
export { default as RecordDataStoreWrapper } from './managers/record-data-store-wrapper';
|
|
55
|
-
|
|
56
|
-
export { default as WeakCache } from './utils/weak-cache';
|
|
@@ -27,18 +27,20 @@ import type Store from '../store-service';
|
|
|
27
27
|
@extends Reference
|
|
28
28
|
*/
|
|
29
29
|
export default class RecordReference {
|
|
30
|
+
declare store: Store;
|
|
30
31
|
// unsubscribe token given to us by the notification manager
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
___token!: Object;
|
|
33
|
+
___identifier: StableRecordIdentifier;
|
|
33
34
|
|
|
34
35
|
@tracked _ref = 0;
|
|
35
36
|
|
|
36
|
-
constructor(
|
|
37
|
-
this
|
|
38
|
-
this
|
|
37
|
+
constructor(store: Store, identifier: StableRecordIdentifier) {
|
|
38
|
+
this.store = store;
|
|
39
|
+
this.___identifier = identifier;
|
|
40
|
+
this.___token = store._notificationManager.subscribe(
|
|
39
41
|
identifier,
|
|
40
42
|
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
41
|
-
if (bucket === 'identity' || (
|
|
43
|
+
if (bucket === 'identity' || (bucket === 'attributes' && notifiedKey === 'id')) {
|
|
42
44
|
this._ref++;
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -46,7 +48,7 @@ export default class RecordReference {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
destroy() {
|
|
49
|
-
unsubscribe(this
|
|
51
|
+
unsubscribe(this.___token);
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
get type(): string {
|
|
@@ -73,7 +75,7 @@ export default class RecordReference {
|
|
|
73
75
|
*/
|
|
74
76
|
id() {
|
|
75
77
|
this._ref; // consume the tracked prop
|
|
76
|
-
return this
|
|
78
|
+
return this.___identifier.id;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
/**
|
|
@@ -95,7 +97,7 @@ export default class RecordReference {
|
|
|
95
97
|
@return {String} The identifier of the record.
|
|
96
98
|
*/
|
|
97
99
|
identifier(): StableRecordIdentifier {
|
|
98
|
-
return this
|
|
100
|
+
return this.___identifier;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
/**
|
|
@@ -183,7 +185,7 @@ export default class RecordReference {
|
|
|
183
185
|
@return {Model} the record for this RecordReference
|
|
184
186
|
*/
|
|
185
187
|
value(): RecordInstance | null {
|
|
186
|
-
return this.store.peekRecord(this
|
|
188
|
+
return this.store.peekRecord(this.___identifier);
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
/**
|
|
@@ -26,10 +26,15 @@ if (HAS_MODEL_PACKAGE) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export class DSModelSchemaDefinitionService {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
declare store: Store;
|
|
30
|
+
declare _relationshipsDefCache;
|
|
31
|
+
declare _attributesDefCache;
|
|
32
|
+
|
|
33
|
+
constructor(store: Store) {
|
|
34
|
+
this.store = store;
|
|
35
|
+
this._relationshipsDefCache = Object.create(null);
|
|
36
|
+
this._attributesDefCache = Object.create(null);
|
|
37
|
+
}
|
|
33
38
|
|
|
34
39
|
// Following the existing RD implementation
|
|
35
40
|
attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { DEBUG } from '@glimmer/env';
|
|
2
|
-
|
|
3
1
|
import type { ModelSchema } from '@ember-data/types/q/ds-model';
|
|
4
2
|
import type { AttributeSchema, RelationshipSchema } from '@ember-data/types/q/record-data-schemas';
|
|
5
3
|
import type { Dict } from '@ember-data/types/q/utils';
|
|
6
4
|
|
|
7
5
|
import type Store from '../store-service';
|
|
8
|
-
import WeakCache from '../utils/weak-cache';
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
// if modelFor turns out to be a bottleneck we should replace with a Map
|
|
8
|
+
// and clear it during store teardown.
|
|
9
|
+
const AvailableShims = new WeakMap<Store, Dict<ShimModelClass>>();
|
|
10
|
+
|
|
14
11
|
export function getShimClass(store: Store, modelName: string): ShimModelClass {
|
|
15
|
-
let shims = AvailableShims.
|
|
12
|
+
let shims = AvailableShims.get(store);
|
|
13
|
+
|
|
14
|
+
if (!shims) {
|
|
15
|
+
shims = Object.create(null) as Dict<ShimModelClass>;
|
|
16
|
+
AvailableShims.set(store, shims);
|
|
17
|
+
}
|
|
18
|
+
|
|
16
19
|
let shim = shims[modelName];
|
|
17
20
|
if (shim === undefined) {
|
|
18
21
|
shim = shims[modelName] = new ShimModelClass(store, modelName);
|
|
@@ -33,8 +36,12 @@ function mapFromHash<T>(hash: Dict<T>): Map<string, T> {
|
|
|
33
36
|
|
|
34
37
|
// Mimics the static apis of DSModel
|
|
35
38
|
export default class ShimModelClass implements ModelSchema {
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
declare __store: Store;
|
|
40
|
+
declare modelName: string;
|
|
41
|
+
constructor(store: Store, modelName: string) {
|
|
42
|
+
this.__store = store;
|
|
43
|
+
this.modelName = modelName;
|
|
44
|
+
}
|
|
38
45
|
|
|
39
46
|
get fields(): Map<string, 'attribute' | 'belongsTo' | 'hasMany'> {
|
|
40
47
|
let attrs = this.__store.getSchemaDefinitionService().attributesDefinitionFor({ type: this.modelName });
|