@ember-data/store 4.5.0-beta.0 → 4.5.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/backburner.js → backburner.js} +0 -0
- package/addon/-private/{system/coerce-id.ts → coerce-id.ts} +0 -0
- package/addon/-private/{system/store/common.js → common.js} +0 -0
- package/addon/-private/{system/core-store.ts → core-store.ts} +467 -1253
- package/addon/-private/{system/errors-utils.js → errors-utils.js} +7 -6
- package/addon/-private/{system/fetch-manager.ts → fetch-manager.ts} +72 -42
- package/addon/-private/finders.js +107 -0
- package/addon/-private/identifer-debug-consts.ts +3 -0
- package/addon/-private/{identifiers/cache.ts → identifier-cache.ts} +26 -14
- package/addon/-private/{system/identity-map.ts → identity-map.ts} +2 -1
- package/addon/-private/index.ts +17 -17
- package/addon/-private/instance-cache.ts +387 -0
- package/addon/-private/{system/store/internal-model-factory.ts → internal-model-factory.ts} +25 -19
- package/addon/-private/{system/internal-model-map.ts → internal-model-map.ts} +9 -5
- package/addon/-private/model/internal-model.ts +602 -0
- package/addon/-private/{system/references/record.ts → model/record-reference.ts} +23 -36
- package/addon/-private/{system/model → model}/shim-model-class.ts +19 -14
- package/addon/-private/{system/normalize-model-name.ts → normalize-model-name.ts} +0 -0
- package/addon/-private/{system/promise-proxies.ts → promise-proxies.ts} +12 -5
- package/addon/-private/{system/promise-proxy-base.js → promise-proxy-base.js} +0 -0
- package/addon/-private/{system/record-array-manager.ts → record-array-manager.ts} +19 -18
- package/addon/-private/{system/record-arrays → record-arrays}/adapter-populated-record-array.ts +11 -10
- package/addon/-private/{system/record-arrays → record-arrays}/record-array.ts +37 -19
- package/addon/-private/record-data-for.ts +39 -0
- package/addon/-private/{system/store/record-data-store-wrapper.ts → record-data-store-wrapper.ts} +21 -26
- package/addon/-private/{system/record-notification-manager.ts → record-notification-manager.ts} +8 -3
- package/addon/-private/{system/request-cache.ts → request-cache.ts} +5 -6
- package/addon/-private/{system/schema-definition-service.ts → schema-definition-service.ts} +30 -14
- package/addon/-private/{system/store/serializer-response.ts → serializer-response.ts} +7 -6
- package/addon/-private/{system/snapshot-record-array.ts → snapshot-record-array.ts} +27 -8
- package/addon/-private/{system/snapshot.ts → snapshot.ts} +54 -39
- package/addon/-private/utils/construct-resource.ts +7 -3
- package/addon/-private/utils/promise-record.ts +9 -18
- package/addon/-private/{system/weak-cache.ts → weak-cache.ts} +2 -2
- package/addon/index.ts +1 -0
- package/package.json +21 -20
- package/addon/-private/identifiers/is-stable-identifier.ts +0 -18
- package/addon/-private/identifiers/utils/uuid-v4.ts +0 -80
- package/addon/-private/system/ds-model-store.ts +0 -136
- package/addon/-private/system/model/internal-model.ts +0 -1303
- package/addon/-private/system/model/states.js +0 -736
- package/addon/-private/system/record-arrays.ts +0 -8
- package/addon/-private/system/record-data-for.ts +0 -54
- package/addon/-private/system/references/belongs-to.ts +0 -406
- package/addon/-private/system/references/has-many.ts +0 -487
- package/addon/-private/system/references/reference.ts +0 -205
- package/addon/-private/system/references.js +0 -9
- package/addon/-private/system/store/finders.js +0 -412
- package/addon/-private/ts-interfaces/ds-model.ts +0 -50
- package/addon/-private/ts-interfaces/ember-data-json-api.ts +0 -145
- package/addon/-private/ts-interfaces/fetch-manager.ts +0 -44
- package/addon/-private/ts-interfaces/identifier.ts +0 -246
- package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +0 -584
- package/addon/-private/ts-interfaces/minimum-serializer-interface.ts +0 -257
- package/addon/-private/ts-interfaces/promise-proxies.ts +0 -3
- package/addon/-private/ts-interfaces/record-data-json-api.ts +0 -29
- package/addon/-private/ts-interfaces/record-data-record-wrapper.ts +0 -46
- package/addon/-private/ts-interfaces/record-data-schemas.ts +0 -45
- package/addon/-private/ts-interfaces/record-data-store-wrapper.ts +0 -56
- package/addon/-private/ts-interfaces/record-data.ts +0 -72
- package/addon/-private/ts-interfaces/record-instance.ts +0 -18
- package/addon/-private/ts-interfaces/schema-definition-service.ts +0 -12
- package/addon/-private/ts-interfaces/store.ts +0 -10
- package/addon/-private/ts-interfaces/utils.ts +0 -6
package/addon/-private/{system/record-notification-manager.ts → record-notification-manager.ts}
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DEBUG } from '@glimmer/env';
|
|
2
2
|
|
|
3
|
-
import type { RecordIdentifier, StableRecordIdentifier } from '
|
|
4
|
-
|
|
3
|
+
import type { RecordIdentifier, StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
4
|
+
|
|
5
|
+
import type Store from './core-store';
|
|
5
6
|
import WeakCache from './weak-cache';
|
|
6
7
|
|
|
7
8
|
type UnsubscribeToken = Object;
|
|
@@ -41,7 +42,7 @@ export function unsubscribe(token: UnsubscribeToken) {
|
|
|
41
42
|
Currently only support a single callback per identifier
|
|
42
43
|
*/
|
|
43
44
|
export default class NotificationManager {
|
|
44
|
-
constructor(private store:
|
|
45
|
+
constructor(private store: Store) {}
|
|
45
46
|
|
|
46
47
|
subscribe(identifier: RecordIdentifier, callback: NotificationCallback): UnsubscribeToken {
|
|
47
48
|
let stableIdentifier = this.store.identifierCache.getOrCreateRecordIdentifier(identifier);
|
|
@@ -52,6 +53,10 @@ export default class NotificationManager {
|
|
|
52
53
|
return unsubToken;
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
unsubscribe(token: UnsubscribeToken) {
|
|
57
|
+
unsubscribe(token);
|
|
58
|
+
}
|
|
59
|
+
|
|
55
60
|
notify(identifier: RecordIdentifier, value: 'attributes' | 'relationships' | 'property', key?: string): boolean;
|
|
56
61
|
notify(identifier: RecordIdentifier, value: 'errors' | 'meta' | 'identity' | 'unload' | 'state'): boolean;
|
|
57
62
|
notify(identifier: RecordIdentifier, value: NotificationType, key?: string): boolean {
|
|
@@ -4,9 +4,8 @@ import type {
|
|
|
4
4
|
Request,
|
|
5
5
|
RequestState,
|
|
6
6
|
SaveRecordMutation,
|
|
7
|
-
} from '
|
|
8
|
-
import {
|
|
9
|
-
import type { RecordIdentifier } from '../ts-interfaces/identifier';
|
|
7
|
+
} from '@ember-data/types/q/fetch-manager';
|
|
8
|
+
import type { RecordIdentifier } from '@ember-data/types/q/identifier';
|
|
10
9
|
|
|
11
10
|
const Touching: unique symbol = Symbol('touching');
|
|
12
11
|
export const RequestPromise: unique symbol = Symbol('promise');
|
|
@@ -36,7 +35,7 @@ export default class RequestCache {
|
|
|
36
35
|
this._pending[lid] = [];
|
|
37
36
|
}
|
|
38
37
|
let request: InternalRequest = {
|
|
39
|
-
state:
|
|
38
|
+
state: 'pending',
|
|
40
39
|
request: queryRequest,
|
|
41
40
|
type,
|
|
42
41
|
} as InternalRequest;
|
|
@@ -48,7 +47,7 @@ export default class RequestCache {
|
|
|
48
47
|
(result) => {
|
|
49
48
|
this._dequeue(lid, request);
|
|
50
49
|
let finalizedRequest = {
|
|
51
|
-
state:
|
|
50
|
+
state: 'fulfilled',
|
|
52
51
|
request: queryRequest,
|
|
53
52
|
type,
|
|
54
53
|
response: { data: result },
|
|
@@ -60,7 +59,7 @@ export default class RequestCache {
|
|
|
60
59
|
(error) => {
|
|
61
60
|
this._dequeue(lid, request);
|
|
62
61
|
let finalizedRequest = {
|
|
63
|
-
state:
|
|
62
|
+
state: 'rejected',
|
|
64
63
|
request: queryRequest,
|
|
65
64
|
type,
|
|
66
65
|
response: { data: error && error.error },
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { getOwner } from '@ember/application';
|
|
2
|
+
import { deprecate } from '@ember/debug';
|
|
2
3
|
import { get } from '@ember/object';
|
|
3
4
|
|
|
4
5
|
import { importSync } from '@embroider/macros';
|
|
5
6
|
|
|
6
7
|
import type Model from '@ember-data/model';
|
|
7
8
|
import { HAS_MODEL_PACKAGE } from '@ember-data/private-build-infra';
|
|
9
|
+
import { DEPRECATE_STRING_ARG_SCHEMAS } from '@ember-data/private-build-infra/deprecations';
|
|
10
|
+
import type { RecordIdentifier } from '@ember-data/types/q/identifier';
|
|
11
|
+
import type { AttributesSchema, RelationshipsSchema } from '@ember-data/types/q/record-data-schemas';
|
|
8
12
|
|
|
9
|
-
import type
|
|
10
|
-
import type { AttributesSchema, RelationshipsSchema } from '../ts-interfaces/record-data-schemas';
|
|
11
|
-
import type Store from './ds-model-store';
|
|
13
|
+
import type Store from './core-store';
|
|
12
14
|
import normalizeModelName from './normalize-model-name';
|
|
13
15
|
|
|
14
16
|
type ModelForMixin = (store: Store, normalizedModelName: string) => Model | null;
|
|
@@ -25,7 +27,6 @@ if (HAS_MODEL_PACKAGE) {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export class DSModelSchemaDefinitionService {
|
|
28
|
-
private _modelFactoryCache = Object.create(null);
|
|
29
30
|
private _relationshipsDefCache = Object.create(null);
|
|
30
31
|
private _attributesDefCache = Object.create(null);
|
|
31
32
|
|
|
@@ -34,7 +35,17 @@ export class DSModelSchemaDefinitionService {
|
|
|
34
35
|
// Following the existing RD implementation
|
|
35
36
|
attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {
|
|
36
37
|
let modelName, attributes;
|
|
37
|
-
if (typeof identifier === 'string') {
|
|
38
|
+
if (DEPRECATE_STRING_ARG_SCHEMAS && typeof identifier === 'string') {
|
|
39
|
+
deprecate(
|
|
40
|
+
`attributesDefinitionFor expects either a record identifier or an argument of shape { type: string }, received a string.`,
|
|
41
|
+
false,
|
|
42
|
+
{
|
|
43
|
+
id: 'ember-data:deprecate-string-arg-schemas',
|
|
44
|
+
for: 'ember-data',
|
|
45
|
+
until: '5.0',
|
|
46
|
+
since: { enabled: '4.5', available: '4.5' },
|
|
47
|
+
}
|
|
48
|
+
);
|
|
38
49
|
modelName = identifier;
|
|
39
50
|
} else {
|
|
40
51
|
modelName = identifier.type;
|
|
@@ -57,7 +68,17 @@ export class DSModelSchemaDefinitionService {
|
|
|
57
68
|
// Following the existing RD implementation
|
|
58
69
|
relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {
|
|
59
70
|
let modelName, relationships;
|
|
60
|
-
if (typeof identifier === 'string') {
|
|
71
|
+
if (DEPRECATE_STRING_ARG_SCHEMAS && typeof identifier === 'string') {
|
|
72
|
+
deprecate(
|
|
73
|
+
`relationshipsDefinitionFor expects either a record identifier or an argument of shape { type: string }, received a string.`,
|
|
74
|
+
false,
|
|
75
|
+
{
|
|
76
|
+
id: 'ember-data:deprecate-string-arg-schemas',
|
|
77
|
+
for: 'ember-data',
|
|
78
|
+
until: '5.0',
|
|
79
|
+
since: { enabled: '4.5', available: '4.5' },
|
|
80
|
+
}
|
|
81
|
+
);
|
|
61
82
|
modelName = identifier;
|
|
62
83
|
} else {
|
|
63
84
|
modelName = identifier.type;
|
|
@@ -76,7 +97,7 @@ export class DSModelSchemaDefinitionService {
|
|
|
76
97
|
|
|
77
98
|
doesTypeExist(modelName: string): boolean {
|
|
78
99
|
let normalizedModelName = normalizeModelName(modelName);
|
|
79
|
-
let factory = getModelFactory(this.store, this._modelFactoryCache, normalizedModelName);
|
|
100
|
+
let factory = getModelFactory(this.store, this.store._modelFactoryCache, normalizedModelName);
|
|
80
101
|
|
|
81
102
|
return factory !== null;
|
|
82
103
|
}
|
|
@@ -86,7 +107,8 @@ export function getModelFactory(store: Store, cache, normalizedModelName: string
|
|
|
86
107
|
let factory = cache[normalizedModelName];
|
|
87
108
|
|
|
88
109
|
if (!factory) {
|
|
89
|
-
|
|
110
|
+
let owner: any = getOwner(store);
|
|
111
|
+
factory = owner.factoryFor(`model:${normalizedModelName}`);
|
|
90
112
|
|
|
91
113
|
if (!factory && HAS_MODEL_PACKAGE) {
|
|
92
114
|
//Support looking up mixins as base types for polymorphic relationships
|
|
@@ -112,9 +134,3 @@ export function getModelFactory(store: Store, cache, normalizedModelName: string
|
|
|
112
134
|
|
|
113
135
|
return factory;
|
|
114
136
|
}
|
|
115
|
-
|
|
116
|
-
export function _lookupModelFactory(store: Store, normalizedModelName: string): Model | null {
|
|
117
|
-
let owner = getOwner(store);
|
|
118
|
-
|
|
119
|
-
return owner.factoryFor(`model:${normalizedModelName}`);
|
|
120
|
-
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { assert } from '@ember/debug';
|
|
2
2
|
import { DEBUG } from '@glimmer/env';
|
|
3
3
|
|
|
4
|
-
import { JsonApiDocument } from '
|
|
5
|
-
import { AdapterPayload } from '
|
|
6
|
-
import { MinimumSerializerInterface, RequestType } from '
|
|
7
|
-
|
|
8
|
-
import
|
|
4
|
+
import type { JsonApiDocument } from '@ember-data/types/q/ember-data-json-api';
|
|
5
|
+
import type { AdapterPayload } from '@ember-data/types/q/minimum-adapter-interface';
|
|
6
|
+
import type { MinimumSerializerInterface, RequestType } from '@ember-data/types/q/minimum-serializer-interface';
|
|
7
|
+
|
|
8
|
+
import type Store from './core-store';
|
|
9
|
+
import type ShimModelClass from './model/shim-model-class';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
This is a helper method that validates a JSON API top-level document
|
|
@@ -69,7 +70,7 @@ function validateDocumentStructure(doc?: AdapterPayload | JsonApiDocument): asse
|
|
|
69
70
|
|
|
70
71
|
export function normalizeResponseHelper(
|
|
71
72
|
serializer: MinimumSerializerInterface | null,
|
|
72
|
-
store:
|
|
73
|
+
store: Store,
|
|
73
74
|
modelClass: ShimModelClass,
|
|
74
75
|
payload: AdapterPayload,
|
|
75
76
|
id: string | null,
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
@module @ember-data/store
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import
|
|
5
|
+
import { deprecate } from '@ember/debug';
|
|
6
|
+
|
|
7
|
+
import { DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS } from '@ember-data/private-build-infra/deprecations';
|
|
8
|
+
import type { ModelSchema } from '@ember-data/types/q/ds-model';
|
|
9
|
+
import type { FindOptions } from '@ember-data/types/q/store';
|
|
10
|
+
import type { Dict } from '@ember-data/types/q/utils';
|
|
11
|
+
|
|
8
12
|
import type RecordArray from './record-arrays/record-array';
|
|
9
13
|
import type Snapshot from './snapshot';
|
|
10
14
|
/**
|
|
@@ -75,8 +79,6 @@ export default class SnapshotRecordArray {
|
|
|
75
79
|
*/
|
|
76
80
|
this.length = recordArray.get('length');
|
|
77
81
|
|
|
78
|
-
this._type = null;
|
|
79
|
-
|
|
80
82
|
/**
|
|
81
83
|
Meta objects for the record array.
|
|
82
84
|
|
|
@@ -151,12 +153,11 @@ export default class SnapshotRecordArray {
|
|
|
151
153
|
/**
|
|
152
154
|
The type of the underlying records for the snapshots in the array, as a Model
|
|
153
155
|
@property type
|
|
156
|
+
@deprecated
|
|
154
157
|
@public
|
|
155
158
|
@type {Model}
|
|
156
159
|
*/
|
|
157
|
-
|
|
158
|
-
return this._type || (this._type = this._recordArray.get('type'));
|
|
159
|
-
}
|
|
160
|
+
|
|
160
161
|
/**
|
|
161
162
|
The modelName of the underlying records for the snapshots in the array, as a Model
|
|
162
163
|
@property modelName
|
|
@@ -205,3 +206,21 @@ export default class SnapshotRecordArray {
|
|
|
205
206
|
return this._snapshots;
|
|
206
207
|
}
|
|
207
208
|
}
|
|
209
|
+
|
|
210
|
+
if (DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS) {
|
|
211
|
+
Object.defineProperty(SnapshotRecordArray.prototype, 'type', {
|
|
212
|
+
get() {
|
|
213
|
+
deprecate(
|
|
214
|
+
`Using SnapshotRecordArray.type to access the ModelClass for a record is deprecated. Use store.modelFor(<modelName>) instead.`,
|
|
215
|
+
false,
|
|
216
|
+
{
|
|
217
|
+
id: 'ember-data:deprecate-snapshot-model-class-access',
|
|
218
|
+
until: '5.0',
|
|
219
|
+
for: 'ember-data',
|
|
220
|
+
since: { available: '4.5.0', enabled: '4.5.0' },
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
return this._recordArray.get('type');
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@module @ember-data/store
|
|
3
3
|
*/
|
|
4
|
-
import { assert } from '@ember/debug';
|
|
4
|
+
import { assert, deprecate } from '@ember/debug';
|
|
5
5
|
import { get } from '@ember/object';
|
|
6
6
|
|
|
7
7
|
import { importSync } from '@embroider/macros';
|
|
8
8
|
|
|
9
9
|
import { HAS_RECORD_DATA_PACKAGE } from '@ember-data/private-build-infra';
|
|
10
|
+
import { DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS } from '@ember-data/private-build-infra/deprecations';
|
|
10
11
|
import type BelongsToRelationship from '@ember-data/record-data/addon/-private/relationships/state/belongs-to';
|
|
11
12
|
import type ManyRelationship from '@ember-data/record-data/addon/-private/relationships/state/has-many';
|
|
13
|
+
import type { DSModel, DSModelSchema, ModelSchema } from '@ember-data/types/q/ds-model';
|
|
12
14
|
import type {
|
|
13
15
|
ExistingResourceIdentifierObject,
|
|
14
16
|
NewResourceIdentifierObject,
|
|
15
|
-
} from '@ember-data/
|
|
16
|
-
|
|
17
|
-
import type {
|
|
18
|
-
import type {
|
|
19
|
-
import {
|
|
20
|
-
import type {
|
|
21
|
-
import type {
|
|
22
|
-
import type {
|
|
23
|
-
|
|
24
|
-
import type { Dict } from '../ts-interfaces/utils';
|
|
17
|
+
} from '@ember-data/types/q/ember-data-json-api';
|
|
18
|
+
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
19
|
+
import type { OptionsHash } from '@ember-data/types/q/minimum-serializer-interface';
|
|
20
|
+
import type { ChangedAttributesHash } from '@ember-data/types/q/record-data';
|
|
21
|
+
import type { AttributeSchema, RelationshipSchema } from '@ember-data/types/q/record-data-schemas';
|
|
22
|
+
import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
23
|
+
import type { FindOptions } from '@ember-data/types/q/store';
|
|
24
|
+
import type { Dict } from '@ember-data/types/q/utils';
|
|
25
|
+
|
|
25
26
|
import type Store from './core-store';
|
|
26
27
|
import type InternalModel from './model/internal-model';
|
|
27
|
-
import recordDataFor from './record-data-for';
|
|
28
28
|
|
|
29
29
|
type RecordId = string | null;
|
|
30
30
|
|
|
@@ -32,12 +32,6 @@ function schemaIsDSModel(schema: ModelSchema | DSModelSchema): schema is DSModel
|
|
|
32
32
|
return (schema as DSModelSchema).isModel === true;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
type ProtoExntends<T, U> = U & Omit<T, keyof U>;
|
|
36
|
-
interface _PrivateSnapshot {
|
|
37
|
-
_internalModel: InternalModel;
|
|
38
|
-
}
|
|
39
|
-
export type PrivateSnapshot = ProtoExntends<Snapshot, _PrivateSnapshot>;
|
|
40
|
-
|
|
41
35
|
/**
|
|
42
36
|
Snapshot is not directly instantiable.
|
|
43
37
|
Instances are provided to a consuming application's
|
|
@@ -70,7 +64,7 @@ export default class Snapshot implements Snapshot {
|
|
|
70
64
|
* @param _store
|
|
71
65
|
*/
|
|
72
66
|
constructor(options: FindOptions, identifier: StableRecordIdentifier, private _store: Store) {
|
|
73
|
-
let internalModel = (this._internalModel = _store._internalModelForResource(identifier));
|
|
67
|
+
let internalModel = (this._internalModel = _store._instanceCache._internalModelForResource(identifier));
|
|
74
68
|
this.modelName = identifier.type;
|
|
75
69
|
|
|
76
70
|
/**
|
|
@@ -83,7 +77,7 @@ export default class Snapshot implements Snapshot {
|
|
|
83
77
|
this.identifier = identifier;
|
|
84
78
|
|
|
85
79
|
/*
|
|
86
|
-
If the
|
|
80
|
+
If the we do not yet have a record, then we are
|
|
87
81
|
likely a snapshot being provided to a find request, so we
|
|
88
82
|
populate __attributes lazily. Else, to preserve the "moment
|
|
89
83
|
in time" in which a snapshot is created, we greedily grab
|
|
@@ -134,9 +128,9 @@ export default class Snapshot implements Snapshot {
|
|
|
134
128
|
@type {String}
|
|
135
129
|
@public
|
|
136
130
|
*/
|
|
137
|
-
this.modelName =
|
|
131
|
+
this.modelName = identifier.type;
|
|
138
132
|
if (internalModel.hasRecord) {
|
|
139
|
-
this._changedAttributes =
|
|
133
|
+
this._changedAttributes = this._store._instanceCache.getRecordData(identifier).changedAttributes();
|
|
140
134
|
}
|
|
141
135
|
}
|
|
142
136
|
|
|
@@ -155,7 +149,7 @@ export default class Snapshot implements Snapshot {
|
|
|
155
149
|
@public
|
|
156
150
|
*/
|
|
157
151
|
get record(): RecordInstance {
|
|
158
|
-
return this.
|
|
152
|
+
return this._store._instanceCache.getRecord(this.identifier);
|
|
159
153
|
}
|
|
160
154
|
|
|
161
155
|
get _attributes(): Dict<any> {
|
|
@@ -164,13 +158,14 @@ export default class Snapshot implements Snapshot {
|
|
|
164
158
|
}
|
|
165
159
|
let record = this.record;
|
|
166
160
|
let attributes = (this.__attributes = Object.create(null));
|
|
167
|
-
let attrs = Object.keys(this._store.
|
|
161
|
+
let attrs = Object.keys(this._store.getSchemaDefinitionService().attributesDefinitionFor(this.identifier));
|
|
162
|
+
let recordData = this._store._instanceCache.getRecordData(this.identifier);
|
|
168
163
|
attrs.forEach((keyName) => {
|
|
169
|
-
if (schemaIsDSModel(this.
|
|
164
|
+
if (schemaIsDSModel(this._internalModel.modelClass)) {
|
|
170
165
|
// if the schema is for a DSModel then the instance is too
|
|
171
166
|
attributes[keyName] = get(record as DSModel, keyName);
|
|
172
167
|
} else {
|
|
173
|
-
attributes[keyName] =
|
|
168
|
+
attributes[keyName] = recordData.getAttr(keyName);
|
|
174
169
|
}
|
|
175
170
|
});
|
|
176
171
|
|
|
@@ -182,11 +177,9 @@ export default class Snapshot implements Snapshot {
|
|
|
182
177
|
|
|
183
178
|
@property type
|
|
184
179
|
@public
|
|
180
|
+
@deprecated
|
|
185
181
|
@type {Model}
|
|
186
182
|
*/
|
|
187
|
-
get type(): ModelSchema {
|
|
188
|
-
return this._internalModel.modelClass;
|
|
189
|
-
}
|
|
190
183
|
|
|
191
184
|
get isNew(): boolean {
|
|
192
185
|
return this._internalModel.isNew();
|
|
@@ -316,7 +309,9 @@ export default class Snapshot implements Snapshot {
|
|
|
316
309
|
return this._belongsToRelationships[keyName];
|
|
317
310
|
}
|
|
318
311
|
|
|
319
|
-
let relationshipMeta = store.
|
|
312
|
+
let relationshipMeta = store.getSchemaDefinitionService().relationshipsDefinitionFor({ type: this.modelName })[
|
|
313
|
+
keyName
|
|
314
|
+
];
|
|
320
315
|
assert(
|
|
321
316
|
`Model '${this.identifier}' has no belongsTo relationship named '${keyName}' defined.`,
|
|
322
317
|
relationshipMeta && relationshipMeta.kind === 'belongsTo'
|
|
@@ -335,7 +330,7 @@ export default class Snapshot implements Snapshot {
|
|
|
335
330
|
importSync('@ember-data/record-data/-private') as typeof import('@ember-data/record-data/-private')
|
|
336
331
|
).graphFor;
|
|
337
332
|
const { identifier } = this;
|
|
338
|
-
const relationship = graphFor(this._store
|
|
333
|
+
const relationship = graphFor(this._store).get(identifier, keyName) as BelongsToRelationship;
|
|
339
334
|
|
|
340
335
|
assert(
|
|
341
336
|
`You looked up the ${keyName} belongsTo relationship for { type: ${identifier.type}, id: ${identifier.id}, lid: ${identifier.lid} but no such relationship was found.`,
|
|
@@ -349,14 +344,14 @@ export default class Snapshot implements Snapshot {
|
|
|
349
344
|
let value = relationship.getData();
|
|
350
345
|
let data = value && value.data;
|
|
351
346
|
|
|
352
|
-
inverseInternalModel = data ? store._internalModelForResource(data) : null;
|
|
347
|
+
inverseInternalModel = data ? store._instanceCache._internalModelForResource(data) : null;
|
|
353
348
|
|
|
354
349
|
if (value && value.data !== undefined) {
|
|
355
350
|
if (inverseInternalModel && !inverseInternalModel.isDeleted()) {
|
|
356
351
|
if (returnModeIsId) {
|
|
357
352
|
result = inverseInternalModel.id;
|
|
358
353
|
} else {
|
|
359
|
-
result =
|
|
354
|
+
result = store._instanceCache.createSnapshot(inverseInternalModel.identifier);
|
|
360
355
|
}
|
|
361
356
|
} else {
|
|
362
357
|
result = null;
|
|
@@ -417,7 +412,9 @@ export default class Snapshot implements Snapshot {
|
|
|
417
412
|
}
|
|
418
413
|
|
|
419
414
|
let store = this._internalModel.store;
|
|
420
|
-
let relationshipMeta = store.
|
|
415
|
+
let relationshipMeta = store.getSchemaDefinitionService().relationshipsDefinitionFor({ type: this.modelName })[
|
|
416
|
+
keyName
|
|
417
|
+
];
|
|
421
418
|
assert(
|
|
422
419
|
`Model '${this.identifier}' has no hasMany relationship named '${keyName}' defined.`,
|
|
423
420
|
relationshipMeta && relationshipMeta.kind === 'hasMany'
|
|
@@ -436,7 +433,7 @@ export default class Snapshot implements Snapshot {
|
|
|
436
433
|
importSync('@ember-data/record-data/-private') as typeof import('@ember-data/record-data/-private')
|
|
437
434
|
).graphFor;
|
|
438
435
|
const { identifier } = this;
|
|
439
|
-
const relationship = graphFor(this._store
|
|
436
|
+
const relationship = graphFor(this._store).get(identifier, keyName) as ManyRelationship;
|
|
440
437
|
assert(
|
|
441
438
|
`You looked up the ${keyName} hasMany relationship for { type: ${identifier.type}, id: ${identifier.id}, lid: ${identifier.lid} but no such relationship was found.`,
|
|
442
439
|
relationship
|
|
@@ -451,14 +448,14 @@ export default class Snapshot implements Snapshot {
|
|
|
451
448
|
if (value.data) {
|
|
452
449
|
results = [];
|
|
453
450
|
value.data.forEach((member) => {
|
|
454
|
-
let internalModel = store._internalModelForResource(member);
|
|
451
|
+
let internalModel = store._instanceCache._internalModelForResource(member);
|
|
455
452
|
if (!internalModel.isDeleted()) {
|
|
456
453
|
if (returnModeIsIds) {
|
|
457
454
|
(results as RecordId[]).push(
|
|
458
455
|
(member as ExistingResourceIdentifierObject | NewResourceIdentifierObject).id || null
|
|
459
456
|
);
|
|
460
457
|
} else {
|
|
461
|
-
(results as Snapshot[]).push(
|
|
458
|
+
(results as Snapshot[]).push(store._instanceCache.createSnapshot(internalModel.identifier));
|
|
462
459
|
}
|
|
463
460
|
}
|
|
464
461
|
});
|
|
@@ -493,7 +490,7 @@ export default class Snapshot implements Snapshot {
|
|
|
493
490
|
@public
|
|
494
491
|
*/
|
|
495
492
|
eachAttribute(callback: (key: string, meta: AttributeSchema) => void, binding?: unknown): void {
|
|
496
|
-
let attrDefs = this._store.
|
|
493
|
+
let attrDefs = this._store.getSchemaDefinitionService().attributesDefinitionFor(this.identifier);
|
|
497
494
|
Object.keys(attrDefs).forEach((key) => {
|
|
498
495
|
callback.call(binding, key, attrDefs[key] as AttributeSchema);
|
|
499
496
|
});
|
|
@@ -517,7 +514,7 @@ export default class Snapshot implements Snapshot {
|
|
|
517
514
|
@public
|
|
518
515
|
*/
|
|
519
516
|
eachRelationship(callback: (key: string, meta: RelationshipSchema) => void, binding?: unknown): void {
|
|
520
|
-
let relationshipDefs = this._store.
|
|
517
|
+
let relationshipDefs = this._store.getSchemaDefinitionService().relationshipsDefinitionFor(this.identifier);
|
|
521
518
|
Object.keys(relationshipDefs).forEach((key) => {
|
|
522
519
|
callback.call(binding, key, relationshipDefs[key] as RelationshipSchema);
|
|
523
520
|
});
|
|
@@ -555,3 +552,21 @@ export default class Snapshot implements Snapshot {
|
|
|
555
552
|
return serializer.serialize(this, options);
|
|
556
553
|
}
|
|
557
554
|
}
|
|
555
|
+
|
|
556
|
+
if (DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS) {
|
|
557
|
+
Object.defineProperty(Snapshot.prototype, 'type', {
|
|
558
|
+
get() {
|
|
559
|
+
deprecate(
|
|
560
|
+
`Using Snapshot.type to access the ModelClass for a record is deprecated. Use store.modelFor(<modelName>) instead.`,
|
|
561
|
+
false,
|
|
562
|
+
{
|
|
563
|
+
id: 'ember-data:deprecate-snapshot-model-class-access',
|
|
564
|
+
until: '5.0',
|
|
565
|
+
for: 'ember-data',
|
|
566
|
+
since: { available: '4.5.0', enabled: '4.5.0' },
|
|
567
|
+
}
|
|
568
|
+
);
|
|
569
|
+
return this._internalModel.modelClass;
|
|
570
|
+
},
|
|
571
|
+
});
|
|
572
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { assert } from '@ember/debug';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import type {
|
|
4
|
+
ExistingResourceIdentifierObject,
|
|
5
|
+
ResourceIdentifierObject,
|
|
6
|
+
} from '@ember-data/types/q/ember-data-json-api';
|
|
7
|
+
|
|
8
|
+
import coerceId from '../coerce-id';
|
|
9
|
+
import { isStableIdentifier } from '../identifier-cache';
|
|
6
10
|
import isNonEmptyString from './is-non-empty-string';
|
|
7
11
|
|
|
8
12
|
function constructResource(type: ResourceIdentifierObject): ResourceIdentifierObject;
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
3
|
-
import { promiseObject } from '../system/promise-proxies';
|
|
4
|
-
import type { RecordInstance } from '../ts-interfaces/record-instance';
|
|
1
|
+
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
2
|
+
import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import type Store from '../core-store';
|
|
5
|
+
import type { PromiseObject } from '../promise-proxies';
|
|
6
|
+
import { promiseObject } from '../promise-proxies';
|
|
9
7
|
|
|
10
|
-
/**
|
|
11
|
-
* Get the materialized model from the internalModel/promise
|
|
12
|
-
* that returns an internal model and return it in a promiseObject.
|
|
13
|
-
*
|
|
14
|
-
* Useful for returning from find methods
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
8
|
export default function promiseRecord(
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
store: Store,
|
|
10
|
+
promise: Promise<StableRecordIdentifier>,
|
|
11
|
+
label?: string
|
|
21
12
|
): PromiseObject<RecordInstance> {
|
|
22
|
-
let toReturn =
|
|
13
|
+
let toReturn = promise.then((identifier: StableRecordIdentifier) => store.peekRecord(identifier)!);
|
|
23
14
|
|
|
24
15
|
return promiseObject(toReturn, label);
|
|
25
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEBUG } from '@glimmer/env';
|
|
2
2
|
|
|
3
|
-
import { DEBUG_IDENTIFIER_BUCKET } from '
|
|
3
|
+
import { DEBUG_IDENTIFIER_BUCKET } from './identifer-debug-consts';
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
DEBUG only fields. Keeping this in a separate interface
|
|
@@ -98,7 +98,7 @@ class WeakCache<K extends object, V> extends WeakMap<K, V> {
|
|
|
98
98
|
|
|
99
99
|
class DebugWeakCache<K extends object, V> extends WeakCache<K, V> {
|
|
100
100
|
set(obj: K, value: V): this {
|
|
101
|
-
if (DEBUG && super.has(obj)) {
|
|
101
|
+
if (DEBUG && super.has(obj) && this.get(obj) !== value) {
|
|
102
102
|
throw new Error(`${Object.prototype.toString.call(obj)} was already assigned a value for ${this._fieldName}`);
|
|
103
103
|
}
|
|
104
104
|
if (DEBUG) {
|
package/addon/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/store",
|
|
3
|
-
"version": "4.5.0
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "The default blueprint for ember-cli addons.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -17,52 +17,53 @@
|
|
|
17
17
|
"start": "ember serve"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ember-data/canary-features": "4.5.0
|
|
21
|
-
"@ember-data/private-build-infra": "4.5.0
|
|
20
|
+
"@ember-data/canary-features": "4.5.0",
|
|
21
|
+
"@ember-data/private-build-infra": "4.5.0",
|
|
22
22
|
"@ember/string": "^3.0.0",
|
|
23
|
-
"@embroider/macros": "^1.
|
|
24
|
-
"@glimmer/tracking": "^1.
|
|
25
|
-
"ember-auto-import": "^2.2
|
|
23
|
+
"@embroider/macros": "^1.8.3",
|
|
24
|
+
"@glimmer/tracking": "^1.1.2",
|
|
25
|
+
"ember-auto-import": "^2.4.2",
|
|
26
26
|
"ember-cached-decorator-polyfill": "^0.1.4",
|
|
27
27
|
"ember-cli-babel": "^7.26.11",
|
|
28
28
|
"ember-cli-path-utils": "^1.0.0",
|
|
29
|
-
"ember-cli-typescript": "^5.
|
|
29
|
+
"ember-cli-typescript": "^5.1.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@ember-data/unpublished-test-infra": "4.5.0
|
|
32
|
+
"@ember-data/unpublished-test-infra": "4.5.0",
|
|
33
33
|
"@ember/optional-features": "^2.0.0",
|
|
34
|
-
"@ember/test-helpers": "
|
|
34
|
+
"@ember/test-helpers": "~2.7.0",
|
|
35
35
|
"@types/ember": "^4.0.0",
|
|
36
36
|
"@types/rsvp": "^4.0.4",
|
|
37
37
|
"broccoli-asset-rev": "^3.0.0",
|
|
38
|
-
"ember-cli": "~4.
|
|
38
|
+
"ember-cli": "~4.6.0",
|
|
39
39
|
"ember-cli-dependency-checker": "^3.3.1",
|
|
40
|
-
"ember-cli-htmlbars": "^6.0
|
|
41
|
-
"ember-cli-inject-live-reload": "^2.0
|
|
40
|
+
"ember-cli-htmlbars": "^6.1.0",
|
|
41
|
+
"ember-cli-inject-live-reload": "^2.1.0",
|
|
42
42
|
"ember-cli-sri": "^2.1.1",
|
|
43
|
-
"ember-cli-terser": "~4.0.
|
|
43
|
+
"ember-cli-terser": "~4.0.2",
|
|
44
44
|
"ember-disable-prototype-extensions": "^1.1.3",
|
|
45
45
|
"ember-export-application-global": "^2.0.1",
|
|
46
|
-
"ember-load-initializers": "^2.1.
|
|
46
|
+
"ember-load-initializers": "^2.1.2",
|
|
47
47
|
"ember-maybe-import-regenerator": "^1.0.0",
|
|
48
48
|
"ember-qunit": "^5.1.5",
|
|
49
49
|
"ember-resolver": "^8.0.3",
|
|
50
|
-
"ember-source": "~4.
|
|
50
|
+
"ember-source": "~4.6.0",
|
|
51
51
|
"ember-source-channel-url": "^3.0.0",
|
|
52
52
|
"ember-try": "^2.0.0",
|
|
53
53
|
"loader.js": "^4.7.0",
|
|
54
|
-
"qunit": "^2.
|
|
54
|
+
"qunit": "^2.19.1",
|
|
55
55
|
"qunit-dom": "^2.0.0",
|
|
56
|
-
"webpack": "^5.
|
|
56
|
+
"webpack": "^5.74.0"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
|
-
"node": "
|
|
59
|
+
"node": "^14.8.0 || 16.* || >= 18.*",
|
|
60
|
+
"yarn": "1.22.19"
|
|
60
61
|
},
|
|
61
62
|
"ember-addon": {
|
|
62
63
|
"configPath": "tests/dummy/config"
|
|
63
64
|
},
|
|
64
65
|
"volta": {
|
|
65
|
-
"node": "
|
|
66
|
-
"yarn": "1.22.
|
|
66
|
+
"node": "16.16.0",
|
|
67
|
+
"yarn": "1.22.19"
|
|
67
68
|
}
|
|
68
69
|
}
|