UNPKG

10.8 kBJavaScriptView Raw
1import { deprecate } from '@ember/debug';
2import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';
3import Adapter, { BuildURLMixin } from '@ember-data/adapter';
4import AdapterError, { InvalidError, TimeoutError, AbortError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, ServerError } from '@ember-data/adapter/error';
5import JSONAPIAdapter from '@ember-data/adapter/json-api';
6import RESTAdapter from '@ember-data/adapter/rest';
7import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
8import Serializer from '@ember-data/serializer';
9import JSONSerializer from '@ember-data/serializer/json';
10import JSONAPISerializer from '@ember-data/serializer/json-api';
11import RESTSerializer, { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
12import Transform, { DateTransform, StringTransform, NumberTransform, BooleanTransform } from '@ember-data/serializer/transform';
13import { PromiseArray, PromiseObject } from "./-private/index.js";
14import setupContainer from "./setup-container.js";
15import { DS } from "./-private/core.js";
16import Store from "./store.js";
17import { PromiseManyArray, Errors, ManyArray } from '@ember-data/model/-private';
18import { Snapshot } from '@ember-data/legacy-compat/-private';
19import { RecordArrayManager } from '@ember-data/store/-private';
20
21/**
22 <p align="center">
23 <img
24 class="project-logo"
25 src="https://raw.githubusercontent.com/emberjs/data/4612c9354e4c54d53327ec2cf21955075ce21294/ember-data-logo-light.svg#gh-light-mode-only"
26 alt="EmberData"
27 width="240px"
28 title="EmberData"
29 />
30</p>
31
32<p align="center">The lightweight reactive data library for JavaScript applications</p>
33
34---
35
36Wrangle your application's data management with scalable patterns for developer productivity.
37
38- ⚡️ Committed to Best-In-Class Performance
39- 🌲 Focused on being as svelte as possible
40- 🚀 SSR Ready
41- 🔜 Typescript Support
42- 🐹 Built with ♥️ by [Ember](https://emberjs.com)
43- ⚛️ Supports any API: `GraphQL` `JSON:API` `REST` `tRPC` ...bespoke or a mix
44
45### 📖 On This Page
46
47- [Overview](./#overview)
48 - [Architecture](#🪜-architecture)
49 - [Basic Installation](#basic-installation)
50 - [Advanced Installation](#advanced-installation)
51- [Configuration](#configuration)
52 - [Deprecation Stripping](#deprecation-stripping)
53 - [randomUUID polyfill](#randomuuid-polyfill)
54 - [Removing inspector support in production](#removing-inspector-support-in-production)
55 - [Debugging](#debugging)
56
57
58# Overview
59
60*Ember*‍**Data** is a lightweight reactive data library for JavaScript applications that provides composable primitives for ordering query/mutation/peek flows, managing network and cache, and reducing data for presentation.
61
62## 🪜 Architecture
63
64The core of *Ember*‍**Data** is the `Store`, which coordinates interaction between your application, the `Cache`, and sources of data (such as your `API` or a local persistence layer).
65Optionally, the Store can be configured to hydrate the response data into rich presentation classes.
66
67*Ember*‍**Data** is both resource centric and document centric in it's approach to caching, requesting and presenting data. Your application's configuration and usage drives which is important and when.
68
69The `Store` is a **coordinator**. When using a `Store` you configure what cache to use, how cache data should be presented to the UI, and where it should look for requested data when it is not available in the cache.
70
71This coordination is handled opaquely to the nature of the requests issued and the format of the data being handled. This approach gives applications broad flexibility to configure *Ember*‍**Data** to best suite their needs. This makes *Ember*‍**Data** a powerful solution for applications regardless of their size and complexity.
72
73*Ember*‍**Data** is designed to scale, with a religious focus on performance and asset-size to keep its footprint small but speedy while still being able to handle large complex APIs in huge data-driven applications with no additional code and no added application complexity. It's goal is to prevent applications from writing code to manage data that is difficult to maintain or reason about.
74
75*Ember*‍**Data**'s power comes not from specific features, data formats, or adherence to specific API specs such as `JSON:API` `trpc` or `GraphQL`, but from solid conventions around requesting and mutating data developed over decades of experience scaling developer productivity.
76
77## Basic Installation
78
79Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
80
81```no-highlight
82pnpm add ember-data
83```
84
85`ember-data` is installed by default for new applications generated with `ember-cli`. You can check what version is installed by looking in the `devDependencies` hash of your project's [package.json](https://docs.npmjs.com/cli/v8/configuring-npm/package-json) file.
86
87If you have generated a new `Ember` application using `ember-cli` but do
88not wish to use `ember-data`, remove `ember-data` from your project's `package.json` file and run your package manager's install command to update your lockfile.
89
90## Advanced Installation
91
92*Ember*‍**Data** is organized into primitives that compose together via public APIs.
93
94- [@ember-data/store](/ember-data/release/modules/@ember-data%2Fstore) is the core and handles coordination
95- [@ember-data/json-api](/ember-data/release/modules/@ember-data%2Fjson-api) provides a resource cache for JSON:API structured data. It integrates with the store via the hook `createCache`
96- [@ember-data/model](/ember-data/release/modules/@ember-data%2Fmodel) is a presentation layer, it integrates with the store via the hooks `instantiateRecord` and `teardownRecord`.
97- [@ember-data/adapter](/ember-data/release/modules/@ember-data%2Fadapter) provides various network API integrations for APIS built over specific REST or JSON:API conventions.
98- [@ember-data/serializer](/ember-data/release/modules/@ember-data%2Fserializer) pairs with `@ember-data/adapter` to normalize and serialize data to and from an API format into the `JSON:API` format understood by `@ember-data/json-api`.
99- [@ember-data/debug](/ember-data/release/modules/@ember-data%2Fdebug) provides debugging support for the `ember-inspector`.
100- **ember-data** is a "meta" package which bundles all of these together for convenience
101
102The packages interop with each other through well defined public API boundaries. The core
103of the library is the store provided by `@ember-data/store`, while each of the other libraries plugs into the store when installed. Because these packages interop via fully
104public APIs, other libraries or applications may provide their own implementations. For instance, [ember-m3](https://github.com/hjdivad/ember-m3) is a commonly used presentation and cache implementation suitable for complex resource objects and graphs.
105
106## Configuration
107
108### Deprecation Stripping
109
110*Ember*‍**Data** allows users to opt-in and remove code that exists to support deprecated behaviors.
111
112If your app has resolved all deprecations present in a given version, you may specify that version as your "compatibility" version to remove the code that supported the deprecated behavior from your app.
113
114```ts
115let app = new EmberApp(defaults, {
116 emberData: {
117 compatWith: '4.8',
118 },
119});
120```
121
122- [Full Documentation](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fdeprecations)
123
124### randomUUID polyfill
125
126*Ember*‍**Data** uses `UUID V4` by default to generate identifiers for new data created on the client. Identifier generation is configurable, but we also for convenience will polyfill
127the necessary feature if your browser support or deployment environment demands it. To
128activate this polyfill:
129
130```ts
131let app = new EmberApp(defaults, {
132 '@embroider/macros': {
133 setConfig: {
134 '@ember-data/store': {
135 polyfillUUID: true
136 },
137 },
138 },
139});
140```
141
142### removing inspector support in production
143
144If you do not with to ship inspector support in your production application, you can specify
145that all support for it should be stripped from the build.
146
147```ts
148let app = new EmberApp(defaults, {
149 emberData: {
150 includeDataAdapterInProduction: false
151 }
152});
153```
154
155- [Full Documentation](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fdebug)
156
157### Debugging
158
159Many portions of the internals are helpfully instrumented with logging that can be activated
160at build time. This instrumentation is always removed from production builds or any builds
161that has not explicitly activated it. To activate it set the appropriate flag to `true`.
162
163```ts
164 let app = new EmberApp(defaults, {
165 emberData: {
166 debug: {
167 LOG_PAYLOADS: false, // data store received to update cache with
168 LOG_OPERATIONS: false, // updates to cache remote state
169 LOG_MUTATIONS: false, // updates to cache local state
170 LOG_NOTIFICATIONS: false,
171 LOG_REQUESTS: false, // log Requests issued via the request manager
172 LOG_REQUEST_STATUS: false,
173 LOG_IDENTIFIERS: false,
174 LOG_GRAPH: false,
175 LOG_INSTANCE_CACHE: false,
176 }
177 }
178 });
179 ```
180
181 @module ember-data-overview
182 @main ember-data-overview
183*/
184deprecate('Importing from `ember-data` is deprecated. Please import from the appropriate `@ember-data/*` instead.', false, {
185 id: 'ember-data:deprecate-legacy-imports',
186 for: 'ember-data',
187 until: '6.0',
188 since: {
189 enabled: '5.2',
190 available: '5.2'
191 }
192});
193DS.Store = Store;
194DS.PromiseArray = PromiseArray;
195DS.PromiseObject = PromiseObject;
196DS.PromiseManyArray = PromiseManyArray;
197DS.Model = Model;
198DS.attr = attr;
199DS.Errors = Errors;
200DS.Snapshot = Snapshot;
201DS.Adapter = Adapter;
202DS.AdapterError = AdapterError;
203DS.InvalidError = InvalidError;
204DS.TimeoutError = TimeoutError;
205DS.AbortError = AbortError;
206DS.UnauthorizedError = UnauthorizedError;
207DS.ForbiddenError = ForbiddenError;
208DS.NotFoundError = NotFoundError;
209DS.ConflictError = ConflictError;
210DS.ServerError = ServerError;
211DS.Serializer = Serializer;
212if (macroCondition(dependencySatisfies('@ember-data/debug', '*'))) {
213 DS.DebugAdapter = importSync('@ember-data/debug');
214}
215DS.ManyArray = ManyArray;
216DS.RecordArrayManager = RecordArrayManager;
217DS.RESTAdapter = RESTAdapter;
218DS.BuildURLMixin = BuildURLMixin;
219DS.RESTSerializer = RESTSerializer;
220DS.JSONSerializer = JSONSerializer;
221DS.JSONAPIAdapter = JSONAPIAdapter;
222DS.JSONAPISerializer = JSONAPISerializer;
223DS.Transform = Transform;
224DS.DateTransform = DateTransform;
225DS.StringTransform = StringTransform;
226DS.NumberTransform = NumberTransform;
227DS.BooleanTransform = BooleanTransform;
228DS.EmbeddedRecordsMixin = EmbeddedRecordsMixin;
229DS.belongsTo = belongsTo;
230DS.hasMany = hasMany;
231DS._setupContainer = setupContainer;
232export { DS as default };
\No newline at end of file