From afca2f61e5d5d5f57562985f476d7a4a85c4f7a0 Mon Sep 17 00:00:00 2001 From: scott-newcomer Date: Sun, 30 May 2021 14:11:27 -0500 Subject: [PATCH] [Refactor]: private model store --- .eslintrc.js | 1 - packages/store/addon/-private/index.ts | 2 +- .../store/addon/-private/system/core-store.ts | 211 ++++++++++++++-- .../addon/-private/system/ds-model-store.ts | 237 ------------------ .../-private/system/model/internal-model.ts | 11 +- .../system/schema-definition-service.ts | 10 +- tsconfig.json | 1 - 7 files changed, 195 insertions(+), 278 deletions(-) delete mode 100644 packages/store/addon/-private/system/ds-model-store.ts diff --git a/.eslintrc.js b/.eslintrc.js index 5f5f3d32140..805e85d936f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -216,7 +216,6 @@ module.exports = { 'packages/store/addon/-private/system/internal-model-map.ts', 'packages/store/addon/-private/system/identity-map.ts', 'packages/store/addon/-private/system/fetch-manager.ts', - 'packages/store/addon/-private/system/ds-model-store.ts', 'packages/store/addon/-private/system/core-store.ts', 'packages/store/addon/-private/system/coerce-id.ts', 'packages/store/addon/-private/index.ts', diff --git a/packages/store/addon/-private/index.ts b/packages/store/addon/-private/index.ts index 16fb90d09c3..90aeecfba90 100644 --- a/packages/store/addon/-private/index.ts +++ b/packages/store/addon/-private/index.ts @@ -2,7 +2,7 @@ @module @ember-data/store */ -export { default as Store } from './system/ds-model-store'; +export { default as Store } from './system/core-store'; export { recordIdentifierFor } from './system/store/internal-model-factory'; diff --git a/packages/store/addon/-private/system/core-store.ts b/packages/store/addon/-private/system/core-store.ts index 101cfa76ec0..8d95cc16835 100644 --- a/packages/store/addon/-private/system/core-store.ts +++ b/packages/store/addon/-private/system/core-store.ts @@ -1,9 +1,10 @@ /** @module @ember-data/store */ -import { getOwner } from '@ember/application'; +import { getOwner, setOwner } from '@ember/application'; import { A } from '@ember/array'; import { assert, deprecate, inspect, warn } from '@ember/debug'; +import EmberError from '@ember/error'; import { computed, defineProperty, get, set } from '@ember/object'; import { assign } from '@ember/polyfills'; import { _backburner as emberBackburner } from '@ember/runloop'; @@ -25,6 +26,7 @@ import { import { HAS_ADAPTER_PACKAGE, HAS_EMBER_DATA_PACKAGE, + HAS_MODEL_PACKAGE, HAS_RECORD_DATA_PACKAGE, HAS_SERIALIZER_PACKAGE, } from '@ember-data/private-build-infra'; @@ -55,6 +57,7 @@ import { setRecordDataFor } from './record-data-for'; import NotificationManager from './record-notification-manager'; import { RecordReference } from './references'; import { RequestPromise } from './request-cache'; +import { DSModelSchemaDefinitionService, getModelFactory } from './schema-definition-service'; import { _bind, _guard, _objectIsAlive, guardDestroyedStore } from './store/common'; import { _find, _findAll, _findBelongsTo, _findHasMany, _findMany, _query, _queryRecord } from './store/finders'; import { internalModelFactoryFor, recordIdentifierFor, setRecordIdentifier } from './store/internal-model-factory'; @@ -79,6 +82,7 @@ type ResourceIdentifierObject = import('../ts-interfaces/ember-data-json-api').R type EmptyResourceDocument = import('../ts-interfaces/ember-data-json-api').EmptyResourceDocument; type SingleResourceDocument = import('../ts-interfaces/ember-data-json-api').SingleResourceDocument; type CollectionResourceDocument = import('../ts-interfaces/ember-data-json-api').CollectionResourceDocument; +type DSModelClass = import('@ember-data/model').default; type JsonApiDocument = import('../ts-interfaces/ember-data-json-api').JsonApiDocument; type ExistingResourceObject = import('../ts-interfaces/ember-data-json-api').ExistingResourceObject; type RecordIdentifier = import('../ts-interfaces/identifier').RecordIdentifier; @@ -218,7 +222,7 @@ interface CoreStore { adapter: string; } -abstract class CoreStore extends Service { +class CoreStore extends Service { /** * EmberData specific backburner instance * @property _backburner @@ -227,6 +231,10 @@ abstract class CoreStore extends Service { public _backburner: Backburner = edBackburner; public recordArrayManager: RecordArrayManager = new RecordArrayManager({ store: this }); + private _attributesDefCache = Object.create(null); + private _relationshipsDefCache = Object.create(null); + public _modelFactoryCache = Object.create(null); + declare _notificationManager: NotificationManager; private _adapterCache = Object.create(null); private _serializerCache = Object.create(null); @@ -495,14 +503,33 @@ abstract class CoreStore extends Service { assert('should not be here, custom model class ff error', false); } - abstract instantiateRecord( + instantiateRecord( identifier: StableRecordIdentifier, - createRecordArgs: { [key: string]: unknown }, // args passed in to store.createRecord() and processed by recordData to be set on creation - recordDataFor: (identifier: RecordIdentifier) => RecordDataRecordWrapper, + createRecordArgs: { [key: string]: any }, + recordDataFor: (identifier: StableRecordIdentifier) => RecordDataRecordWrapper, notificationManager: NotificationManager - ): RecordInstance; + ): DSModel { + let modelName = identifier.type; + + let internalModel = this._internalModelForResource(identifier); + let createOptions: any = { + store: this, + _internalModel: internalModel, + container: null, + }; + assign(createOptions, createRecordArgs); + + // ensure that `getOwner(this)` works inside a model instance + setOwner(createOptions, getOwner(this)); + + delete createOptions.container; + let record = this._modelFactoryFor(modelName).create(createOptions); + return record; + } - abstract teardownRecord(record: RecordInstance): void; + teardownRecord(record: DSModel) { + record.destroy(); + } _internalDeleteRecord(internalModel: InternalModel) { internalModel.deleteRecord(); @@ -510,18 +537,61 @@ abstract class CoreStore extends Service { // FeatureFlagged in the DSModelStore claas _attributesDefinitionFor(modelName: string, identifier?: StableRecordIdentifier): AttributesSchema { - if (identifier) { - return this.getSchemaDefinitionService().attributesDefinitionFor(identifier); + if (HAS_MODEL_PACKAGE) { + if (CUSTOM_MODEL_CLASS) { + if (identifier) { + return this.getSchemaDefinitionService().attributesDefinitionFor(identifier); + } else { + return this.getSchemaDefinitionService().attributesDefinitionFor(modelName); + } + } else { + let attributes = this._attributesDefCache[modelName]; + + if (attributes === undefined) { + let modelClass = this.modelFor(modelName); + let attributeMap = get(modelClass, 'attributes'); + + attributes = Object.create(null); + attributeMap.forEach((meta, name) => (attributes[name] = meta)); + this._attributesDefCache[modelName] = attributes; + } + + return attributes; + } } else { - return this.getSchemaDefinitionService().attributesDefinitionFor(modelName); + if (identifier) { + return this.getSchemaDefinitionService().attributesDefinitionFor(identifier); + } else { + return this.getSchemaDefinitionService().attributesDefinitionFor(modelName); + } } } _relationshipsDefinitionFor(modelName: string, identifier?: StableRecordIdentifier) { - if (identifier) { - return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier); + if (HAS_MODEL_PACKAGE) { + if (CUSTOM_MODEL_CLASS) { + if (identifier) { + return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier); + } else { + return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName); + } + } else { + let relationships = this._relationshipsDefCache[modelName]; + + if (relationships === undefined) { + let modelClass = this.modelFor(modelName); + relationships = get(modelClass, 'relationshipsObject') || null; + this._relationshipsDefCache[modelName] = relationships; + } + + return relationships; + } } else { - return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName); + if (identifier) { + return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier); + } else { + return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName); + } } } @@ -530,15 +600,36 @@ abstract class CoreStore extends Service { } getSchemaDefinitionService(): SchemaDefinitionService { - if (CUSTOM_MODEL_CLASS) { - return this._schemaDefinitionService; + if (HAS_MODEL_PACKAGE) { + if (CUSTOM_MODEL_CLASS) { + if (!this._schemaDefinitionService) { + this._schemaDefinitionService = new DSModelSchemaDefinitionService(this); + } + return this._schemaDefinitionService; + } else { + throw 'schema service is only available when custom model class feature flag is on'; + } + } else { + if (CUSTOM_MODEL_CLASS) { + return this._schemaDefinitionService; + } + assert('need to enable CUSTOM_MODEL_CLASS feature flag in order to access SchemaDefinitionService'); } - assert('need to enable CUSTOM_MODEL_CLASS feature flag in order to access SchemaDefinitionService'); } // TODO Double check this return value is correct _relationshipMetaFor(modelName: string, id: string | null, key: string) { - return this._relationshipsDefinitionFor(modelName)[key]; + if (HAS_MODEL_PACKAGE) { + if (CUSTOM_MODEL_CLASS) { + return this._relationshipsDefinitionFor(modelName)[key]; + } else { + let modelClass = this.modelFor(modelName); + let relationshipsByName = get(modelClass, 'relationshipsByName'); + return relationshipsByName.get(key); + } + } else { + return this._relationshipsDefinitionFor(modelName)[key]; + } } /** @@ -557,12 +648,53 @@ abstract class CoreStore extends Service { @param {String} modelName @return {subclass of Model | ShimModelClass} */ - modelFor(modelName: string): ShimModelClass { - if (DEBUG) { - assertDestroyedStoreOnly(this, 'modelFor'); + modelFor(modelName: string): ShimModelClass | DSModelClass { + if (HAS_MODEL_PACKAGE) { + if (DEBUG) { + assertDestroyedStoreOnly(this, 'modelFor'); + } + assert(`You need to pass a model name to the store's modelFor method`, isPresent(modelName)); + assert( + `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, + typeof modelName === 'string' + ); + + let maybeFactory = this._modelFactoryFor(modelName); + + // for factorFor factory/class split + let klass = maybeFactory && maybeFactory.class ? maybeFactory.class : maybeFactory; + if (!klass || !klass.isModel) { + if (!CUSTOM_MODEL_CLASS || !this.getSchemaDefinitionService().doesTypeExist(modelName)) { + throw new EmberError(`No model was found for '${modelName}' and no schema handles the type`); + } + return getShimClass(this, modelName); + } else { + return klass; + } + } else { + if (DEBUG) { + assertDestroyedStoreOnly(this, 'modelFor'); + } + + return getShimClass(this, modelName); } + } - return getShimClass(this, modelName); + _modelFactoryFor(modelName: string): DSModelClass { + if (HAS_MODEL_PACKAGE) { + if (DEBUG) { + assertDestroyedStoreOnly(this, '_modelFactoryFor'); + } + assert(`You need to pass a model name to the store's _modelFactoryFor method`, isPresent(modelName)); + assert( + `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, + typeof modelName === 'string' + ); + let normalizedModelName = normalizeModelName(modelName); + let factory = getModelFactory(this, this._modelFactoryCache, normalizedModelName); + + return factory; + } } // Feature Flagged in DSModelStore @@ -579,13 +711,38 @@ abstract class CoreStore extends Service { @private */ _hasModelFor(modelName: string): boolean { - assert(`You need to pass a model name to the store's hasModelFor method`, isPresent(modelName)); - assert( - `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, - typeof modelName === 'string' - ); + if (HAS_MODEL_PACKAGE) { + if (DEBUG) { + assertDestroyingStore(this, '_hasModelFor'); + } + assert(`You need to pass a model name to the store's hasModelFor method`, isPresent(modelName)); + assert( + `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, + typeof modelName === 'string' + ); - return this.getSchemaDefinitionService().doesTypeExist(modelName); + if (CUSTOM_MODEL_CLASS) { + return this.getSchemaDefinitionService().doesTypeExist(modelName); + } else { + assert(`You need to pass a model name to the store's hasModelFor method`, isPresent(modelName)); + assert( + `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, + typeof modelName === 'string' + ); + let normalizedModelName = normalizeModelName(modelName); + let factory = getModelFactory(this, this._modelFactoryCache, normalizedModelName); + + return factory !== null; + } + } else { + assert(`You need to pass a model name to the store's hasModelFor method`, isPresent(modelName)); + assert( + `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, + typeof modelName === 'string' + ); + + return this.getSchemaDefinitionService().doesTypeExist(modelName); + } } // ..................... diff --git a/packages/store/addon/-private/system/ds-model-store.ts b/packages/store/addon/-private/system/ds-model-store.ts deleted file mode 100644 index 6bd0cb08519..00000000000 --- a/packages/store/addon/-private/system/ds-model-store.ts +++ /dev/null @@ -1,237 +0,0 @@ -import { getOwner, setOwner } from '@ember/application'; -import { assert, deprecate } from '@ember/debug'; -import EmberError from '@ember/error'; -import { get } from '@ember/object'; -import { assign } from '@ember/polyfills'; -import { isPresent } from '@ember/utils'; -import { DEBUG } from '@glimmer/env'; - -import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features'; - -import CoreStore from './core-store'; -import { getShimClass } from './model/shim-model-class'; -import normalizeModelName from './normalize-model-name'; -import { DSModelSchemaDefinitionService, getModelFactory } from './schema-definition-service'; - -type RelationshipsSchema = import('../ts-interfaces/record-data-schemas').RelationshipsSchema; -type SchemaDefinitionService = import('../ts-interfaces/schema-definition-service').SchemaDefinitionService; -type RecordDataRecordWrapper = import('../ts-interfaces/record-data-record-wrapper').RecordDataRecordWrapper; -type StableRecordIdentifier = import('../ts-interfaces/identifier').StableRecordIdentifier; -type NotificationManager = import('./record-notification-manager').default; -type DSModel = import('../ts-interfaces/ds-model').DSModel; -type ShimModelClass = import('./model/shim-model-class').default; -type DSModelClass = import('@ember-data/model').default; - -class Store extends CoreStore { - public _modelFactoryCache = Object.create(null); - private _relationshipsDefCache = Object.create(null); - private _attributesDefCache = Object.create(null); - - instantiateRecord( - identifier: StableRecordIdentifier, - createRecordArgs: { [key: string]: any }, - recordDataFor: (identifier: StableRecordIdentifier) => RecordDataRecordWrapper, - notificationManager: NotificationManager - ): DSModel { - let modelName = identifier.type; - - let internalModel = this._internalModelForResource(identifier); - let createOptions: any = { - store: this, - _internalModel: internalModel, - container: null, - }; - assign(createOptions, createRecordArgs); - - // ensure that `getOwner(this)` works inside a model instance - setOwner(createOptions, getOwner(this)); - - delete createOptions.container; - let record = this._modelFactoryFor(modelName).create(createOptions); - return record; - } - - teardownRecord(record: DSModel) { - record.destroy(); - } - - modelFor(modelName: string): ShimModelClass | DSModelClass { - if (DEBUG) { - assertDestroyedStoreOnly(this, 'modelFor'); - } - assert(`You need to pass a model name to the store's modelFor method`, isPresent(modelName)); - assert( - `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, - typeof modelName === 'string' - ); - - let maybeFactory = this._modelFactoryFor(modelName); - - // for factorFor factory/class split - let klass = maybeFactory && maybeFactory.class ? maybeFactory.class : maybeFactory; - if (!klass || !klass.isModel) { - if (!CUSTOM_MODEL_CLASS || !this.getSchemaDefinitionService().doesTypeExist(modelName)) { - throw new EmberError(`No model was found for '${modelName}' and no schema handles the type`); - } - return getShimClass(this, modelName); - } else { - return klass; - } - } - - _modelFactoryFor(modelName: string): DSModelClass { - if (DEBUG) { - assertDestroyedStoreOnly(this, '_modelFactoryFor'); - } - assert(`You need to pass a model name to the store's _modelFactoryFor method`, isPresent(modelName)); - assert( - `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, - typeof modelName === 'string' - ); - let normalizedModelName = normalizeModelName(modelName); - let factory = getModelFactory(this, this._modelFactoryCache, normalizedModelName); - - return factory; - } - - _hasModelFor(modelName) { - if (DEBUG) { - assertDestroyingStore(this, '_hasModelFor'); - } - assert(`You need to pass a model name to the store's hasModelFor method`, isPresent(modelName)); - assert( - `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, - typeof modelName === 'string' - ); - - if (CUSTOM_MODEL_CLASS) { - return this.getSchemaDefinitionService().doesTypeExist(modelName); - } else { - assert(`You need to pass a model name to the store's hasModelFor method`, isPresent(modelName)); - assert( - `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, - typeof modelName === 'string' - ); - let normalizedModelName = normalizeModelName(modelName); - let factory = getModelFactory(this, this._modelFactoryCache, normalizedModelName); - - return factory !== null; - } - } - - _relationshipMetaFor(modelName: string, id: string | null, key: string) { - if (CUSTOM_MODEL_CLASS) { - return this._relationshipsDefinitionFor(modelName)[key]; - } else { - let modelClass = this.modelFor(modelName); - let relationshipsByName = get(modelClass, 'relationshipsByName'); - return relationshipsByName.get(key); - } - } - - _attributesDefinitionFor(modelName: string, identifier?: StableRecordIdentifier) { - if (CUSTOM_MODEL_CLASS) { - if (identifier) { - return this.getSchemaDefinitionService().attributesDefinitionFor(identifier); - } else { - return this.getSchemaDefinitionService().attributesDefinitionFor(modelName); - } - } else { - let attributes = this._attributesDefCache[modelName]; - - if (attributes === undefined) { - let modelClass = this.modelFor(modelName); - let attributeMap = get(modelClass, 'attributes'); - - attributes = Object.create(null); - attributeMap.forEach((meta, name) => (attributes[name] = meta)); - this._attributesDefCache[modelName] = attributes; - } - - return attributes; - } - } - - _relationshipsDefinitionFor(modelName: string, identifier?: StableRecordIdentifier): RelationshipsSchema { - if (CUSTOM_MODEL_CLASS) { - if (identifier) { - return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier); - } else { - return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName); - } - } else { - let relationships = this._relationshipsDefCache[modelName]; - - if (relationships === undefined) { - let modelClass = this.modelFor(modelName); - relationships = get(modelClass, 'relationshipsObject') || null; - this._relationshipsDefCache[modelName] = relationships; - } - - return relationships; - } - } - - getSchemaDefinitionService(): SchemaDefinitionService { - if (CUSTOM_MODEL_CLASS) { - if (!this._schemaDefinitionService) { - this._schemaDefinitionService = new DSModelSchemaDefinitionService(this); - } - return this._schemaDefinitionService; - } else { - throw 'schema service is only available when custom model class feature flag is on'; - } - } -} - -let assertDestroyingStore: Function; -let assertDestroyedStoreOnly: Function; - -if (DEBUG) { - assertDestroyingStore = function assertDestroyedStore(store, method) { - if (!store.shouldAssertMethodCallsOnDestroyedStore) { - deprecate( - `Attempted to call store.${method}(), but the store instance has already been destroyed.`, - !(store.isDestroying || store.isDestroyed), - { - id: 'ember-data:method-calls-on-destroyed-store', - until: '3.8', - for: '@ember-data/store', - since: { - available: '3.8', - enabled: '3.8', - }, - } - ); - } else { - assert( - `Attempted to call store.${method}(), but the store instance has already been destroyed.`, - !(store.isDestroying || store.isDestroyed) - ); - } - }; - assertDestroyedStoreOnly = function assertDestroyedStoreOnly(store, method) { - if (!store.shouldAssertMethodCallsOnDestroyedStore) { - deprecate( - `Attempted to call store.${method}(), but the store instance has already been destroyed.`, - !store.isDestroyed, - { - id: 'ember-data:method-calls-on-destroyed-store', - until: '3.8', - for: '@ember-data/store', - since: { - available: '3.8', - enabled: '3.8', - }, - } - ); - } else { - assert( - `Attempted to call store.${method}(), but the store instance has already been destroyed.`, - !store.isDestroyed - ); - } - }; -} - -export default Store; diff --git a/packages/store/addon/-private/system/model/internal-model.ts b/packages/store/addon/-private/system/model/internal-model.ts index 25f3247aebc..08d00283704 100644 --- a/packages/store/addon/-private/system/model/internal-model.ts +++ b/packages/store/addon/-private/system/model/internal-model.ts @@ -33,7 +33,7 @@ type ManyRelationship = import('@ember-data/record-data/-private').ManyRelations type UpgradedMeta = import('@ember-data/record-data/-private/graph/-edge-definition').UpgradedMeta; -type CoreStore = import('../core-store').default; +type Store = import('../core-store').default; type StableRecordIdentifier = import('../../ts-interfaces/identifier').StableRecordIdentifier; type ConfidentDict = import('../../ts-interfaces/utils').ConfidentDict; type Dict = import('../../ts-interfaces/utils').Dict; @@ -41,7 +41,6 @@ type RecordInstance = import('../../ts-interfaces/record-instance').RecordInstan type JsonApiResource = import('../../ts-interfaces/record-data-json-api').JsonApiResource; type JsonApiValidationError = import('../../ts-interfaces/record-data-json-api').JsonApiValidationError; type RecordData = import('../../ts-interfaces/record-data').RecordData; -type Store = import('../ds-model-store').default; type DefaultRecordData = import('@ember-data/record-data/-private').RecordData; // move to TS hacks module that we can delete when this is no longer a necessary recast @@ -76,12 +75,12 @@ if (HAS_MODEL_PACKAGE) { // TODO this should be integrated with the code removal so we can use it together with the if condition // and not alongside it -function isNotCustomModelClass(store: CoreStore | Store): store is Store { +function isNotCustomModelClass(store: Store): store is Store { return !CUSTOM_MODEL_CLASS; } interface BelongsToMetaWrapper { key: string; - store: CoreStore; + store: Store; originatingInternalModel: InternalModel; modelName: string; } @@ -139,7 +138,7 @@ export default class InternalModel { declare currentState: any; declare _previousState: any; - constructor(public store: CoreStore | Store, public identifier: StableRecordIdentifier) { + constructor(public store: Store, public identifier: StableRecordIdentifier) { if (HAS_MODEL_PACKAGE) { _getModelPackage(); } @@ -1457,7 +1456,7 @@ export function extractRecordDataFromRecord(recordOrPromiseRecord) { return recordDataFor(recordOrPromiseRecord); } -function anyUnloaded(store: CoreStore, relationship: ManyRelationship) { +function anyUnloaded(store: Store, relationship: ManyRelationship) { // Can't use `find` because of IE11 and these arrays are potentially massive let state = relationship.currentState; let unloaded = false; diff --git a/packages/store/addon/-private/system/schema-definition-service.ts b/packages/store/addon/-private/system/schema-definition-service.ts index 481a7d4b946..4f68c2d43ae 100644 --- a/packages/store/addon/-private/system/schema-definition-service.ts +++ b/packages/store/addon/-private/system/schema-definition-service.ts @@ -10,10 +10,10 @@ import normalizeModelName from './normalize-model-name'; type RelationshipsSchema = import('../ts-interfaces/record-data-schemas').RelationshipsSchema; type AttributesSchema = import('../ts-interfaces/record-data-schemas').AttributesSchema; type RecordIdentifier = import('../ts-interfaces/identifier').RecordIdentifier; -type Store = import('./ds-model-store').default; +type CoreStore = import('./core-store').default; type Model = import('@ember-data/model').default; -type ModelForMixin = (store: Store, normalizedModelName: string) => Model | null; +type ModelForMixin = (store: CoreStore, normalizedModelName: string) => Model | null; let _modelForMixin: ModelForMixin; if (HAS_MODEL_PACKAGE) { @@ -31,7 +31,7 @@ export class DSModelSchemaDefinitionService { private _relationshipsDefCache = Object.create(null); private _attributesDefCache = Object.create(null); - constructor(public store: Store) {} + constructor(public store: CoreStore) {} // Following the existing RD implementation attributesDefinitionFor(identifier: RecordIdentifier | string): AttributesSchema { @@ -84,7 +84,7 @@ export class DSModelSchemaDefinitionService { } } -export function getModelFactory(store: Store, cache, normalizedModelName: string): Model | null { +export function getModelFactory(store: CoreStore, cache, normalizedModelName: string): Model | null { let factory = cache[normalizedModelName]; if (!factory) { @@ -115,7 +115,7 @@ export function getModelFactory(store: Store, cache, normalizedModelName: string return factory; } -export function _lookupModelFactory(store: Store, normalizedModelName: string): Model | null { +export function _lookupModelFactory(store: CoreStore, normalizedModelName: string): Model | null { let owner = getOwner(store); return owner.factoryFor(`model:${normalizedModelName}`); diff --git a/tsconfig.json b/tsconfig.json index 7deff6d2ad8..49053228e8e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -71,7 +71,6 @@ "packages/store/addon/-private/system/internal-model-map.ts", "packages/store/addon/-private/system/identity-map.ts", "packages/store/addon/-private/system/fetch-manager.ts", - "packages/store/addon/-private/system/ds-model-store.ts", "packages/store/addon/-private/system/core-store.ts", "packages/store/addon/-private/system/coerce-id.ts", "packages/store/addon/-private/index.ts",