From 14a68255337bcd29224a7e46472d576bcabba4e7 Mon Sep 17 00:00:00 2001 From: DubrovinPavel Date: Fri, 26 Jul 2024 13:52:13 +0500 Subject: [PATCH] Fix ember-data imports --- addon/stores/base-store.js | 6 +- addon/stores/compatible-store.js | 38 ++++++------- addon/stores/local-store.js | 4 +- addon/stores/online-store.js | 5 +- addon/utils/store-functions.js | 15 ----- app/ember-data-imports.js | 6 ++ package-lock.json | 4 +- package.json | 6 +- tests/dummy/app/services/store.js | 55 ------------------- .../ember-flexberry-data/register-version.js | 2 +- 10 files changed, 37 insertions(+), 104 deletions(-) delete mode 100644 addon/utils/store-functions.js create mode 100644 app/ember-data-imports.js diff --git a/addon/stores/base-store.js b/addon/stores/base-store.js index 3f4e5650..bf559b03 100644 --- a/addon/stores/base-store.js +++ b/addon/stores/base-store.js @@ -3,12 +3,12 @@ import { isNone, isEmpty } from '@ember/utils'; import { computed } from '@ember/object'; import $ from 'jquery'; import { getOwner } from '@ember/application'; -import Store from '@ember-data/store'; import decorateAdapter from './base-store/decorate-adapter'; import decorateAPICall from './base-store/decorate-api-call'; import QueryObject from '../query/query-object'; import isObject from '../utils/is-object'; import OnlineStore from './online-store'; +import CompatibleStore from './compatible-store'; /** Base class for application store. @@ -17,7 +17,7 @@ import OnlineStore from './online-store'; @class Store @extends DS.Store */ -export default class extends Store { +export default class extends CompatibleStore { /** Store offline schemas for all databases. @@ -136,11 +136,13 @@ export default class extends Store { if (isNone(this.onlineStore)) { let onlineStore = OnlineStore.create(owner.ownerInjection()); this.onlineStore = onlineStore; + this.fixLegacyStore(this.onlineStore); } // Set offline store. let offlineStore = owner.lookup('store:local'); this.offlineStore = offlineStore; + this.fixLegacyStore(this.offlineStore); this.offlineStore.offlineSchema = this.offlineSchema; } diff --git a/addon/stores/compatible-store.js b/addon/stores/compatible-store.js index 9a4b412d..1b370325 100644 --- a/addon/stores/compatible-store.js +++ b/addon/stores/compatible-store.js @@ -1,10 +1,9 @@ -/*import Store from '@ember-data/store'; +import Store from '@ember-data/store'; import { CacheHandler } from '@ember-data/store'; import RequestManager from '@ember-data/request'; import Fetch from '@ember-data/request/fetch'; import { adapterFor, - cleanup, LegacyNetworkHandler, normalize, pushPayload, @@ -15,21 +14,23 @@ import JSONAPICache from '@ember-data/json-api'; import { buildSchema, instantiateRecord, modelFor, teardownRecord } from '@ember-data/model/hooks'; export default class extends Store { - adapterFor = adapterFor; - serializerFor = serializerFor; - pushPayload = pushPayload; - normalize = normalize; - serializeRecord = serializeRecord; - - constructor() { - super(...arguments); - - if (!this.requestManager) { - this.requestManager = new RequestManager(); - this.requestManager.use([LegacyNetworkHandler, Fetch]); + fixLegacyStore(store) { + store.adapterFor ??= adapterFor; + store.serializerFor ??= serializerFor; + store.pushPayload ??= pushPayload; + store.normalize ??= normalize; + store.serializeRecord ??= serializeRecord; + store.createSchemaService ??= this.createSchemaService; + store.createCache ??= this.createCache; + store.instantiateRecord = this.instantiateRecord; + store.teardownRecord = this.teardownRecord; + store.modelFor = this.modelFor; + if (!store.requestManager) { + store.requestManager = new RequestManager(); + store.requestManager.use([LegacyNetworkHandler, Fetch]); } - this.requestManager.useCache(CacheHandler); + store.requestManager.useCache(CacheHandler); } createSchemaService() { @@ -51,9 +52,4 @@ export default class extends Store { modelFor(type) { return (modelFor.call(this, type)) || super.modelFor(type); } - - destroy() { - cleanup.call(this); - super.destroy(); - } -}*/ \ No newline at end of file +} \ No newline at end of file diff --git a/addon/stores/local-store.js b/addon/stores/local-store.js index 3513a145..ff628fe0 100644 --- a/addon/stores/local-store.js +++ b/addon/stores/local-store.js @@ -6,12 +6,12 @@ import { computed } from '@ember/object'; import { getOwner } from '@ember/application'; import { isArray } from '@ember/array'; import { assert, debug } from '@ember/debug'; +import { cleanup } from '@ember-data/legacy-compat'; +import Store from '@ember-data/store'; import { isNone, isBlank } from '@ember/utils'; import RSVP from 'rsvp'; -import Store from '@ember-data/store'; import OfflineAdapter from '../adapters/offline'; import QueryBuilder from '../query/builder'; -import { cleanup } from '../utils/store-functions'; /** Store that used in offline mode by default. diff --git a/addon/stores/online-store.js b/addon/stores/online-store.js index bc4995e4..9c5b6203 100644 --- a/addon/stores/online-store.js +++ b/addon/stores/online-store.js @@ -5,12 +5,11 @@ import { assert, debug } from '@ember/debug'; import { isNone, isBlank } from '@ember/utils'; import { A } from '@ember/array'; +import { cleanup } from '@ember-data/legacy-compat'; +import Store from '@ember-data/store'; import RSVP from 'rsvp'; import { isArray } from '@ember/array'; import QueryBuilder from '../query/builder'; -import { cleanup } from '../utils/store-functions'; - -import Store from '@ember-data/store'; /** Store that used in online mode by default. diff --git a/addon/utils/store-functions.js b/addon/utils/store-functions.js deleted file mode 100644 index 84f0ca91..00000000 --- a/addon/utils/store-functions.js +++ /dev/null @@ -1,15 +0,0 @@ -export function cleanup() { - for (const adapterName in this._adapterCache) { - const adapter = this._adapterCache[adapterName]; - if (typeof adapter.destroy === 'function') { - adapter.destroy(); - } - } - - for (const serializerName in this._serializerCache) { - const serializer = this._serializerCache[serializerName]; - if (typeof serializer.destroy === 'function') { - serializer.destroy(); - } - } -} \ No newline at end of file diff --git a/app/ember-data-imports.js b/app/ember-data-imports.js new file mode 100644 index 00000000..0d54e1af --- /dev/null +++ b/app/ember-data-imports.js @@ -0,0 +1,6 @@ +import DS from 'ember-data'; +import RequestManager from '@ember-data/request'; +import Fetch from '@ember-data/request/fetch'; +import Legacy from '@ember-data/legacy-compat'; +import JSONAPICache from '@ember-data/json-api'; +import ModelHooks from '@ember-data/model/hooks'; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 59687d43..6a9702db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ember-flexberry-data", - "version": "5.0.0-beta.2", + "version": "5.0.0-beta.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ember-flexberry-data", - "version": "5.0.0-beta.2", + "version": "5.0.0-beta.3", "license": "MIT", "dependencies": { "@babel/core": "^7.24.7", diff --git a/package.json b/package.json index 802cd6d7..362bc686 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-flexberry-data", - "version": "5.0.0-beta.2", + "version": "5.0.0-beta.3", "description": "Support of database projections, JavaScript Query Language and working with several kinds of backends", "keywords": [ "ember-addon", @@ -38,8 +38,7 @@ "dependencies": { "@babel/core": "^7.24.7", "ember-cli-babel": "^8.2.0", - "ember-cli-htmlbars": "^6.3.0", - "ember-data": "^5.3.4" + "ember-cli-htmlbars": "^6.3.0" }, "devDependencies": { "@babel/eslint-parser": "^7.24.7", @@ -54,6 +53,7 @@ "concurrently": "^8.2.2", "dexie": "^2.0.2", "ember-auto-import": "^2.7.4", + "ember-data": "^5.3.4", "ember-cli": "~5.10.0", "ember-cli-clean-css": "^3.0.0", "ember-cli-dependency-checker": "^3.3.2", diff --git a/tests/dummy/app/services/store.js b/tests/dummy/app/services/store.js index 1a61f74e..cfa79282 100644 --- a/tests/dummy/app/services/store.js +++ b/tests/dummy/app/services/store.js @@ -1,18 +1,5 @@ import BaseStore from 'ember-flexberry-data/stores/base-store'; -import { CacheHandler } from '@ember-data/store'; import { set } from '@ember/object'; -import RequestManager from '@ember-data/request'; -import Fetch from '@ember-data/request/fetch'; -import { - adapterFor, - LegacyNetworkHandler, - normalize, - pushPayload, - serializeRecord, - serializerFor, -} from '@ember-data/legacy-compat'; -import JSONAPICache from '@ember-data/json-api'; -import { buildSchema, instantiateRecord, modelFor, teardownRecord } from '@ember-data/model/hooks'; export default class extends BaseStore { constructor() { @@ -56,51 +43,9 @@ export default class extends BaseStore { }); this.offlineStore.dbName = 'TestDB'; - this.fixLegacyStore(this.onlineStore); - this.fixLegacyStore(this.offlineStore); - this._dbInit(); } - fixLegacyStore(store) { - store.adapterFor ??= adapterFor; - store.serializerFor ??= serializerFor; - store.pushPayload ??= pushPayload; - store.normalize ??= normalize; - store.serializeRecord ??= serializeRecord; - store.createSchemaService ??= this.createSchemaService; - store.createCache ??= this.createCache; - store.instantiateRecord = this.instantiateRecord; - store.teardownRecord = this.teardownRecord; - store.modelFor = this.modelFor; - if (!store.requestManager) { - store.requestManager = new RequestManager(); - store.requestManager.use([LegacyNetworkHandler, Fetch]); - } - - store.requestManager.useCache(CacheHandler); - } - - createSchemaService() { - return buildSchema(this); - } - - createCache(storeWrapper) { - return new JSONAPICache(storeWrapper); - } - - instantiateRecord(identifier, createRecordArgs) { - return instantiateRecord.call(this, identifier, createRecordArgs); - } - - teardownRecord(record) { - teardownRecord.call(this, record); - } - - modelFor(type) { - return (modelFor.call(this, type)) || super.modelFor(type); - } - offlineModels = { 'i-c-s-soft-s-t-o-r-m-n-e-t-business-audit-objects-audit-entity': true, 'i-c-s-soft-s-t-o-r-m-n-e-t-business-audit-objects-audit-field': true, diff --git a/vendor/ember-flexberry-data/register-version.js b/vendor/ember-flexberry-data/register-version.js index b523bbb8..e916d6ad 100644 --- a/vendor/ember-flexberry-data/register-version.js +++ b/vendor/ember-flexberry-data/register-version.js @@ -1,3 +1,3 @@ /* globals Ember */ -var version = '5.0.0-beta.2'; +var version = '5.0.0-beta.3'; Ember.libraries.register('Ember Flexberry Data', version);