ember-data
Version:
(Legacy) The lightweight reactive data library for Ember applications
136 lines (134 loc) • 6.9 kB
JavaScript
import { deprecate } from "@ember/debug";
import { buildSchema, instantiateRecord, modelFor, teardownRecord } from "@ember-data/model";
import { getGlobalConfig, macroCondition } from "@embroider/macros";
import JSONAPICache from "@ember-data/json-api";
import { LegacyNetworkHandler, adapterFor, cleanup, normalize, pushPayload, serializeRecord, serializerFor } from "@ember-data/legacy-compat";
import RequestManager from "@ember-data/request";
import Fetch from "@ember-data/request/fetch";
import BaseStore, { CacheHandler } from "@ember-data/store";
//#region src/store.ts
function hasRequestManager(store) {
return "requestManager" in store;
}
var Store = class extends BaseStore {
constructor(args) {
super(args);
if (!hasRequestManager(this)) {
this.requestManager = new RequestManager();
this.requestManager.use(macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS) ? [LegacyNetworkHandler, Fetch] : [Fetch]);
}
this.requestManager.useCache(CacheHandler);
}
createSchemaService() {
return buildSchema(this);
}
createCache(storeWrapper) {
return new JSONAPICache(storeWrapper);
}
instantiateRecord(key, createRecordArgs) {
return instantiateRecord.call(this, key, createRecordArgs);
}
teardownRecord(record) {
return teardownRecord.call(this, record);
}
modelFor(type) {
return modelFor.call(this, type) || super.modelFor(type);
}
adapterFor(modelName, _allowMissing) {
if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
if (!test) throw new Error(`You cannot use store.adapterFor when ENABLE_LEGACY_REQUEST_METHODS is false without explicitly registering the adapterFor hook from -data/legacy-compat or -drive/legacy.`);
})(false);
else {
deprecate(`store.adapterFor is deprecated, please use store.request to perform requests and builders/handlers/utils to produce and process them, or explicitly register the adapterFor hook and LegacyNetworkHandler from -data/legacy-compat or -drive/legacy.`, false, {
id: "warp-drive:deprecate-legacy-request-methods",
until: "6.0",
for: "@warp-drive/core",
url: "https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS",
since: {
enabled: "5.7",
available: "5.7"
}
});
return adapterFor.call(this, modelName, _allowMissing);
}
}
serializerFor = (...args) => {
if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
if (!test) throw new Error(`You cannot use store.serializerFor when ENABLE_LEGACY_REQUEST_METHODS is false without explicitly registering the serializerFor hook from -data/legacy-compat or -drive/legacy.`);
})(false);
else {
deprecate(`store.serializerFor is deprecated, please use store.request to perform requests and builders/handlers/utils to produce and process them, or explicitly register the serializerFor hook and LegacyNetworkHandler from -data/legacy-compat or -drive/legacy.`, false, {
id: "warp-drive:deprecate-legacy-request-methods",
until: "6.0",
for: "@warp-drive/core",
url: "https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS",
since: {
enabled: "5.7",
available: "5.7"
}
});
return serializerFor.call(this, ...args);
}
};
pushPayload = (...args) => {
if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
if (!test) throw new Error(`You cannot use store.pushPayload when ENABLE_LEGACY_REQUEST_METHODS is false without explicitly registering the pushPayload hook from -data/legacy-compat or -drive/legacy.`);
})(false);
else {
deprecate(`store.pushPayload is deprecated, please use store.request to perform requests and builders/handlers/utils to produce and process them, or explicitly register the pushPayload and serializerFor hooks from -data/legacy-compat or -drive/legacy.`, false, {
id: "warp-drive:deprecate-legacy-request-methods",
until: "6.0",
for: "@warp-drive/core",
url: "https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS",
since: {
enabled: "5.7",
available: "5.7"
}
});
return pushPayload.call(this, ...args);
}
};
normalize = (...args) => {
if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
if (!test) throw new Error(`You cannot use store.normalize when ENABLE_LEGACY_REQUEST_METHODS is false without explicitly registering the normalize hook from -data/legacy-compat or -drive/legacy.`);
})(false);
else {
deprecate(`store.normalize is deprecated, please use store.request to perform requests and builders/handlers/utils to produce and process them, or explicitly register the normalize and serializerFor hooks from -data/legacy-compat or -drive/legacy.`, false, {
id: "warp-drive:deprecate-legacy-request-methods",
until: "6.0",
for: "@warp-drive/core",
url: "https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS",
since: {
enabled: "5.7",
available: "5.7"
}
});
return normalize.call(this, ...args);
}
};
serializeRecord = (...args) => {
if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
if (!test) throw new Error(`You cannot use store.serializeRecord when ENABLE_LEGACY_REQUEST_METHODS is false without explicitly registering the serializeRecord hook from -data/legacy-compat or -drive/legacy.`);
})(false);
else {
deprecate(`store.serializeRecord is deprecated, please use store.request to perform requests and builders/handlers/utils to produce and process them, or explicitly register the serializeRecord and serializerFor hooks from -data/legacy-compat or -drive/legacy.`, false, {
id: "warp-drive:deprecate-legacy-request-methods",
until: "6.0",
for: "@warp-drive/core",
url: "https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS",
since: {
enabled: "5.7",
available: "5.7"
}
});
return serializeRecord.call(this, ...args);
}
};
destroy() {
cleanup.call(this);
super.destroy();
}
};
//#endregion
export { Store as default };
//# sourceMappingURL=store.js.map