@ember-data/store 4.2.0-alpha.8 → 4.2.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 +466 -140
- package/addon/-private/system/ds-model-store.ts +63 -12
- package/addon/-private/system/fetch-manager.ts +4 -9
- package/addon/-private/system/model/internal-model.ts +342 -90
- package/addon/-private/system/model/states.js +14 -2
- package/addon/-private/system/record-array-manager.js +30 -3
- package/addon/-private/system/references/belongs-to.ts +26 -11
- package/addon/-private/system/references/has-many.ts +33 -14
- package/addon/-private/system/references/record.ts +23 -9
- package/addon/-private/system/snapshot.ts +48 -22
- package/addon/-private/system/store/finders.js +58 -2
- package/addon/-private/system/store/record-data-store-wrapper.ts +24 -17
- package/addon/-private/ts-interfaces/fetch-manager.ts +0 -4
- package/package.json +10 -10
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { getOwner, setOwner } from '@ember/application';
|
|
2
2
|
import { assert, deprecate } from '@ember/debug';
|
|
3
3
|
import EmberError from '@ember/error';
|
|
4
|
+
import { get } from '@ember/object';
|
|
4
5
|
import { isPresent } from '@ember/utils';
|
|
5
6
|
import { DEBUG } from '@glimmer/env';
|
|
6
7
|
|
|
8
|
+
import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
|
|
7
9
|
import type DSModelClass from '@ember-data/model';
|
|
8
10
|
|
|
9
11
|
import type { DSModel } from '../ts-interfaces/ds-model';
|
|
@@ -67,7 +69,7 @@ class Store extends CoreStore {
|
|
|
67
69
|
// for factorFor factory/class split
|
|
68
70
|
let klass = maybeFactory && maybeFactory.class ? maybeFactory.class : maybeFactory;
|
|
69
71
|
if (!klass || !klass.isModel) {
|
|
70
|
-
if (!this.getSchemaDefinitionService().doesTypeExist(modelName)) {
|
|
72
|
+
if (!CUSTOM_MODEL_CLASS || !this.getSchemaDefinitionService().doesTypeExist(modelName)) {
|
|
71
73
|
throw new EmberError(`No model was found for '${modelName}' and no schema handles the type`);
|
|
72
74
|
}
|
|
73
75
|
return getShimClass(this, modelName);
|
|
@@ -101,34 +103,83 @@ class Store extends CoreStore {
|
|
|
101
103
|
typeof modelName === 'string'
|
|
102
104
|
);
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
107
|
+
return this.getSchemaDefinitionService().doesTypeExist(modelName);
|
|
108
|
+
} else {
|
|
109
|
+
assert(`You need to pass a model name to the store's hasModelFor method`, isPresent(modelName));
|
|
110
|
+
assert(
|
|
111
|
+
`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`,
|
|
112
|
+
typeof modelName === 'string'
|
|
113
|
+
);
|
|
114
|
+
let normalizedModelName = normalizeModelName(modelName);
|
|
115
|
+
let factory = getModelFactory(this, this._modelFactoryCache, normalizedModelName);
|
|
116
|
+
|
|
117
|
+
return factory !== null;
|
|
118
|
+
}
|
|
105
119
|
}
|
|
106
120
|
|
|
107
121
|
_relationshipMetaFor(modelName: string, id: string | null, key: string) {
|
|
108
|
-
|
|
122
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
123
|
+
return this._relationshipsDefinitionFor(modelName)[key];
|
|
124
|
+
} else {
|
|
125
|
+
let modelClass = this.modelFor(modelName);
|
|
126
|
+
let relationshipsByName = get(modelClass, 'relationshipsByName');
|
|
127
|
+
return relationshipsByName.get(key);
|
|
128
|
+
}
|
|
109
129
|
}
|
|
110
130
|
|
|
111
131
|
_attributesDefinitionFor(modelName: string, identifier?: StableRecordIdentifier) {
|
|
112
|
-
if (
|
|
113
|
-
|
|
132
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
133
|
+
if (identifier) {
|
|
134
|
+
return this.getSchemaDefinitionService().attributesDefinitionFor(identifier);
|
|
135
|
+
} else {
|
|
136
|
+
return this.getSchemaDefinitionService().attributesDefinitionFor(modelName);
|
|
137
|
+
}
|
|
114
138
|
} else {
|
|
115
|
-
|
|
139
|
+
let attributes = this._attributesDefCache[modelName];
|
|
140
|
+
|
|
141
|
+
if (attributes === undefined) {
|
|
142
|
+
let modelClass = this.modelFor(modelName);
|
|
143
|
+
let attributeMap = get(modelClass, 'attributes');
|
|
144
|
+
|
|
145
|
+
attributes = Object.create(null);
|
|
146
|
+
attributeMap.forEach((meta, name) => (attributes[name] = meta));
|
|
147
|
+
this._attributesDefCache[modelName] = attributes;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return attributes;
|
|
116
151
|
}
|
|
117
152
|
}
|
|
118
153
|
|
|
119
154
|
_relationshipsDefinitionFor(modelName: string, identifier?: StableRecordIdentifier): RelationshipsSchema {
|
|
120
|
-
if (
|
|
121
|
-
|
|
155
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
156
|
+
if (identifier) {
|
|
157
|
+
return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier);
|
|
158
|
+
} else {
|
|
159
|
+
return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName);
|
|
160
|
+
}
|
|
122
161
|
} else {
|
|
123
|
-
|
|
162
|
+
let relationships = this._relationshipsDefCache[modelName];
|
|
163
|
+
|
|
164
|
+
if (relationships === undefined) {
|
|
165
|
+
let modelClass = this.modelFor(modelName);
|
|
166
|
+
relationships = get(modelClass, 'relationshipsObject') || null;
|
|
167
|
+
this._relationshipsDefCache[modelName] = relationships;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return relationships;
|
|
124
171
|
}
|
|
125
172
|
}
|
|
126
173
|
|
|
127
174
|
getSchemaDefinitionService(): SchemaDefinitionService {
|
|
128
|
-
if (
|
|
129
|
-
this._schemaDefinitionService
|
|
175
|
+
if (CUSTOM_MODEL_CLASS) {
|
|
176
|
+
if (!this._schemaDefinitionService) {
|
|
177
|
+
this._schemaDefinitionService = new DSModelSchemaDefinitionService(this);
|
|
178
|
+
}
|
|
179
|
+
return this._schemaDefinitionService;
|
|
180
|
+
} else {
|
|
181
|
+
throw 'schema service is only available when custom model class feature flag is on';
|
|
130
182
|
}
|
|
131
|
-
return this._schemaDefinitionService;
|
|
132
183
|
}
|
|
133
184
|
}
|
|
134
185
|
|
|
@@ -501,10 +501,10 @@ export default class FetchManager {
|
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
503
|
|
|
504
|
-
getPendingFetch(identifier: StableRecordIdentifier
|
|
505
|
-
let pendingRequests = this.requestCache
|
|
506
|
-
|
|
507
|
-
|
|
504
|
+
getPendingFetch(identifier: StableRecordIdentifier) {
|
|
505
|
+
let pendingRequests = this.requestCache
|
|
506
|
+
.getPendingRequestsForRecord(identifier)
|
|
507
|
+
.filter((req) => req.type === 'query');
|
|
508
508
|
|
|
509
509
|
if (pendingRequests.length > 0) {
|
|
510
510
|
return pendingRequests[0][RequestPromise];
|
|
@@ -532,8 +532,3 @@ function assertIsString(id: string | null): asserts id is string {
|
|
|
532
532
|
}
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
|
-
|
|
536
|
-
// this function helps resolve whether we have a pending request that we should use instead
|
|
537
|
-
function isSameRequest(options: Dict<unknown> = {}, reqOptions: Dict<unknown> = {}) {
|
|
538
|
-
return options.include === reqOptions.include;
|
|
539
|
-
}
|