@ember-data/store 4.1.0 → 4.2.0-alpha.3

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.
@@ -1,11 +1,9 @@
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';
5
4
  import { isPresent } from '@ember/utils';
6
5
  import { DEBUG } from '@glimmer/env';
7
6
 
8
- import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
9
7
  import type DSModelClass from '@ember-data/model';
10
8
 
11
9
  import type { DSModel } from '../ts-interfaces/ds-model';
@@ -69,7 +67,7 @@ class Store extends CoreStore {
69
67
  // for factorFor factory/class split
70
68
  let klass = maybeFactory && maybeFactory.class ? maybeFactory.class : maybeFactory;
71
69
  if (!klass || !klass.isModel) {
72
- if (!CUSTOM_MODEL_CLASS || !this.getSchemaDefinitionService().doesTypeExist(modelName)) {
70
+ if (!this.getSchemaDefinitionService().doesTypeExist(modelName)) {
73
71
  throw new EmberError(`No model was found for '${modelName}' and no schema handles the type`);
74
72
  }
75
73
  return getShimClass(this, modelName);
@@ -103,83 +101,34 @@ class Store extends CoreStore {
103
101
  typeof modelName === 'string'
104
102
  );
105
103
 
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
- }
104
+ return this.getSchemaDefinitionService().doesTypeExist(modelName);
119
105
  }
120
106
 
121
107
  _relationshipMetaFor(modelName: string, id: string | null, key: string) {
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
- }
108
+ return this._relationshipsDefinitionFor(modelName)[key];
129
109
  }
130
110
 
131
111
  _attributesDefinitionFor(modelName: string, identifier?: StableRecordIdentifier) {
132
- if (CUSTOM_MODEL_CLASS) {
133
- if (identifier) {
134
- return this.getSchemaDefinitionService().attributesDefinitionFor(identifier);
135
- } else {
136
- return this.getSchemaDefinitionService().attributesDefinitionFor(modelName);
137
- }
112
+ if (identifier) {
113
+ return this.getSchemaDefinitionService().attributesDefinitionFor(identifier);
138
114
  } else {
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;
115
+ return this.getSchemaDefinitionService().attributesDefinitionFor(modelName);
151
116
  }
152
117
  }
153
118
 
154
119
  _relationshipsDefinitionFor(modelName: string, identifier?: StableRecordIdentifier): RelationshipsSchema {
155
- if (CUSTOM_MODEL_CLASS) {
156
- if (identifier) {
157
- return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier);
158
- } else {
159
- return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName);
160
- }
120
+ if (identifier) {
121
+ return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier);
161
122
  } else {
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;
123
+ return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName);
171
124
  }
172
125
  }
173
126
 
174
127
  getSchemaDefinitionService(): 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';
128
+ if (!this._schemaDefinitionService) {
129
+ this._schemaDefinitionService = new DSModelSchemaDefinitionService(this);
182
130
  }
131
+ return this._schemaDefinitionService;
183
132
  }
184
133
  }
185
134