@ember-data/store 5.4.0-alpha.32 → 5.4.0-alpha.33

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.
Files changed (35) hide show
  1. package/package.json +9 -9
  2. package/unstable-preview-types/-private/cache-handler.d.ts +101 -99
  3. package/unstable-preview-types/-private/caches/cache-utils.d.ts +11 -9
  4. package/unstable-preview-types/-private/caches/identifier-cache.d.ts +181 -179
  5. package/unstable-preview-types/-private/caches/instance-cache.d.ts +63 -61
  6. package/unstable-preview-types/-private/caches/resource-utils.d.ts +12 -10
  7. package/unstable-preview-types/-private/document.d.ts +146 -144
  8. package/unstable-preview-types/-private/index.d.ts +18 -16
  9. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts +178 -176
  10. package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts +19 -17
  11. package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts +29 -27
  12. package/unstable-preview-types/-private/managers/cache-manager.d.ts +442 -440
  13. package/unstable-preview-types/-private/managers/notification-manager.d.ts +98 -96
  14. package/unstable-preview-types/-private/managers/record-array-manager.d.ts +97 -95
  15. package/unstable-preview-types/-private/network/request-cache.d.ts +109 -107
  16. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts +134 -132
  17. package/unstable-preview-types/-private/store-service.d.ts +1503 -1501
  18. package/unstable-preview-types/-private/utils/coerce-id.d.ts +10 -8
  19. package/unstable-preview-types/-private/utils/construct-resource.d.ts +10 -8
  20. package/unstable-preview-types/-private/utils/identifier-debug-consts.d.ts +7 -5
  21. package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts +4 -2
  22. package/unstable-preview-types/-private/utils/normalize-model-name.d.ts +4 -2
  23. package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts +4 -2
  24. package/unstable-preview-types/-private.d.ts +4 -2
  25. package/unstable-preview-types/-types/overview.d.ts +21 -19
  26. package/unstable-preview-types/-types/q/cache-store-wrapper.d.ts +107 -105
  27. package/unstable-preview-types/-types/q/cache.d.ts +47 -45
  28. package/unstable-preview-types/-types/q/ds-model.d.ts +15 -13
  29. package/unstable-preview-types/-types/q/identifier.d.ts +169 -167
  30. package/unstable-preview-types/-types/q/promise-proxies.d.ts +4 -2
  31. package/unstable-preview-types/-types/q/record-data-json-api.d.ts +36 -34
  32. package/unstable-preview-types/-types/q/record-instance.d.ts +29 -27
  33. package/unstable-preview-types/-types/q/schema-service.d.ts +214 -212
  34. package/unstable-preview-types/-types/q/store.d.ts +17 -15
  35. package/unstable-preview-types/index.d.ts +220 -185
@@ -1,185 +1,220 @@
1
- /**
2
- * <p align="center">
3
- * <img
4
- * class="project-logo"
5
- * src="https://raw.githubusercontent.com/emberjs/data/4612c9354e4c54d53327ec2cf21955075ce21294/ember-data-logo-light.svg#gh-light-mode-only"
6
- * alt="EmberData Store"
7
- * width="240px"
8
- * title="EmberData Store"
9
- * />
10
- * </p>
11
- *
12
- * This package provides [*Ember***Data**](https://github.com/emberjs/data/)'s `Store` class.
13
- *
14
- * A [Store](https://api.emberjs.com/ember-data/release/classes/Store) coordinates interaction between your application, a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache),
15
- * and sources of data (such as your API or a local persistence layer) accessed via a [RequestManager](https://github.com/emberjs/data/tree/main/packages/request).
16
- *
17
- * Optionally, a Store can be configured to hydrate the response data into rich presentation classes.
18
- *
19
- * ## Installation
20
- *
21
- * If you have installed `ember-data` then you already have this package installed.
22
- * Otherwise you can install it using your javascript package manager of choice.
23
- * For instance with [pnpm](https://pnpm.io/)
24
- *
25
- * ```
26
- * pnpm add @ember-data/store
27
- * ```
28
- *
29
- * After installing you will want to configure your first `Store`. Read more below
30
- * for how to create and configure stores for your application.
31
- *
32
- *
33
- * ## 🔨 Creating A Store
34
- *
35
- * To use a `Store` we will need to do few things: add a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache)
36
- * to store data **in-memory**, add a [Handler](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache) to fetch data from a source,
37
- * and implement `instantiateRecord` to tell the store how to display the data for individual resources.
38
- *
39
- * > **Note**
40
- * > If you are using the package `ember-data` then a JSON:API cache, RequestManager, LegacyNetworkHandler,
41
- * > and `instantiateRecord` are configured for you by default.
42
- *
43
- * ### Configuring A Cache
44
- *
45
- * To start, let's install a [JSON:API](https://jsonapi.org/) cache. If your app uses `GraphQL` or `REST` other
46
- * caches may better fit your data. You can author your own cache by creating one that
47
- * conforms to the [spec](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache).
48
- *
49
- * The package `@ember-data/json-api` provides a [JSON:API](https://jsonapi.org/) cache we can use.
50
- * After installing it, we can configure the store to use this cache.
51
- *
52
- * ```js
53
- * import Store from '@ember-data/store';
54
- * import Cache from '@ember-data/json-api';
55
- *
56
- * class extends Store {
57
- * createCache(storeWrapper) {
58
- * return new Cache(storeWrapper);
59
- * }
60
- * }
61
- * ```
62
- *
63
- * Now that we have a `cache` let's setup something to handle fetching
64
- * and saving data via our API.
65
- *
66
- * > **Note**
67
- * > The `ember-data` package automatically includes and configures
68
- * > the `@ember-data/json-api` cache for you.
69
- *
70
- * ### Handling Requests
71
- *
72
- * When *Ember***Data** needs to fetch or save data it will pass that request to your application's `RequestManager` for fulfillment. How this fulfillment occurs (in-memory, device storage, via single or multiple API requests, etc.) is then up to the registered request handlers.
73
- *
74
- * To start, let's install the `RequestManager` from `@ember-data/request` and the basic `Fetch` handler from ``@ember-data/request/fetch`.
75
- *
76
- * > **Note**
77
- * > If your app uses `GraphQL`, `REST` or different conventions for `JSON:API` than your cache expects, other handlers may better fit your data. You can author your own handler by creating one that conforms to the [handler interface](https://github.com/emberjs/data/tree/main/packages/request#handling-requests).
78
- *
79
- * ```ts
80
- * import Store from '@ember-data/store';
81
- * import RequestManager from '@ember-data/request';
82
- * import Fetch from '@ember-data/request/fetch';
83
- *
84
- * export default class extends Store {
85
- * constructor() {
86
- * super(...arguments);
87
- * this.requestManager = new RequestManager();
88
- * this.requestManager.use([Fetch]);
89
- * }
90
- * }
91
- * ```
92
- *
93
- * **Using RequestManager as a Service**
94
- *
95
- * Alternatively if you have configured the `RequestManager` to be a service you may re-use it.
96
- *
97
- * *app/services/request.js*
98
- * ```ts
99
- * import RequestManager from '@ember-data/request';
100
- * import Fetch from '@ember-data/request/fetch';
101
- *
102
- * export default class extends RequestManager {
103
- * constructor(createArgs) {
104
- * super(createArgs);
105
- * this.use([Fetch]);
106
- * }
107
- * }
108
- * ```
109
- *
110
- * *app/services/store.js*
111
- * ```ts
112
- * import Store from '@ember-data/store';
113
- * import { service } from '@ember/service';
114
- *
115
- * export default class extends Store {
116
- * @service('request') requestManager
117
- * }
118
- * ```
119
- *
120
- *
121
- * ### Presenting Data from the Cache
122
- *
123
- * Now that we have a source and a cach for our data, we need to configure how
124
- * the Store delivers that data back to our application. We do this via the hook
125
- * [instantiateRecord](https://api.emberjs.com/ember-data/release/classes/Store/methods/instantiateRecord%20(hook)?anchor=instantiateRecord%20(hook)),
126
- * which allows us to transform the data for a resource before handing it to the application.
127
- *
128
- * A naive way to present the data would be to return it as JSON. Typically instead
129
- * this hook will be used to add reactivity and make each unique resource a singleton,
130
- * ensuring that if the cache updates our presented data will reflect the new state.
131
- *
132
- * Below is an example of using the hooks `instantiateRecord` and a `teardownRecord`
133
- * to provide minimal read-only reactive state for simple resources.
134
- *
135
- * ```ts
136
- * import Store, { recordIdentifierFor } from '@ember-data/store';
137
- * import { TrackedObject } from 'tracked-built-ins';
138
- *
139
- * class extends Store {
140
- * instantiateRecord(identifier) {
141
- * const { cache, notifications } = this;
142
- *
143
- * // create a TrackedObject with our attributes, id and type
144
- * const record = new TrackedObject(Object.assign({}, cache.peek(identifier)));
145
- * record.type = identifier.type;
146
- * record.id = identifier.id;
147
- *
148
- * notifications.subscribe(identifier, (_, change) => {
149
- * if (change === 'attributes') {
150
- * Object.assign(record, cache.peek(identifier));
151
- * }
152
- * });
153
- *
154
- * return record;
155
- * }
156
- * }
157
- * ```
158
- *
159
- * Because `instantiateRecord` is opaque to the nature of the record, an implementation
160
- * can be anything from a fairly simple object to a robust proxy that intelligently links
161
- * together associated records through relationships.
162
- *
163
- * This also enables creating a record that separates `edit` flows from `create` flows
164
- * entirely. A record class might choose to implement a `checkout`method that gives access
165
- * to an editable instance while the primary record continues to be read-only and reflect
166
- * only persisted (non-mutated) state.
167
- *
168
- * Typically you will choose an existing record implementation such as `@ember-data/model`
169
- * for your application.
170
- *
171
- * Because of the boundaries around instantiation and the cache, record implementations
172
- * should be capable of interop both with each other and with any `Cache`. Due to this,
173
- * if needed an application can utilize multiple record implementations and multiple cache
174
- * implementations either to support enhanced features for only a subset of records or to
175
- * be able to incrementally migrate from one record/cache to another record or cache.
176
- *
177
- * > **Note**
178
- * > The `ember-data` package automatically includes the `@ember-data/model`
179
- * > package and configures it for you.
180
- *
181
- * @module @ember-data/store
182
- * @main @ember-data/store
183
- */
184
- export { Store as default, CacheHandler, type LifetimesService, setIdentifierGenerationMethod, setIdentifierUpdateMethod, setIdentifierForgetMethod, setIdentifierResetMethod, recordIdentifierFor, storeFor, } from './-private';
185
- //# sourceMappingURL=index.d.ts.map
1
+ /// <reference path="./-private.d.ts" />
2
+ /// <reference path="./-private/cache-handler.d.ts" />
3
+ /// <reference path="./-private/document.d.ts" />
4
+ /// <reference path="./-private/index.d.ts" />
5
+ /// <reference path="./-private/store-service.d.ts" />
6
+ /// <reference path="./-private/network/request-cache.d.ts" />
7
+ /// <reference path="./-private/managers/cache-capabilities-manager.d.ts" />
8
+ /// <reference path="./-private/managers/cache-manager.d.ts" />
9
+ /// <reference path="./-private/managers/notification-manager.d.ts" />
10
+ /// <reference path="./-private/managers/record-array-manager.d.ts" />
11
+ /// <reference path="./-private/record-arrays/identifier-array.d.ts" />
12
+ /// <reference path="./-private/legacy-model-support/shim-model-class.d.ts" />
13
+ /// <reference path="./-private/legacy-model-support/record-reference.d.ts" />
14
+ /// <reference path="./-private/caches/instance-cache.d.ts" />
15
+ /// <reference path="./-private/caches/identifier-cache.d.ts" />
16
+ /// <reference path="./-private/caches/resource-utils.d.ts" />
17
+ /// <reference path="./-private/caches/cache-utils.d.ts" />
18
+ /// <reference path="./-private/utils/normalize-model-name.d.ts" />
19
+ /// <reference path="./-private/utils/identifier-debug-consts.d.ts" />
20
+ /// <reference path="./-private/utils/construct-resource.d.ts" />
21
+ /// <reference path="./-private/utils/coerce-id.d.ts" />
22
+ /// <reference path="./-private/utils/uuid-polyfill.d.ts" />
23
+ /// <reference path="./-private/utils/is-non-empty-string.d.ts" />
24
+ /// <reference path="./-types/overview.d.ts" />
25
+ /// <reference path="./-types/q/record-data-json-api.d.ts" />
26
+ /// <reference path="./-types/q/store.d.ts" />
27
+ /// <reference path="./-types/q/record-instance.d.ts" />
28
+ /// <reference path="./-types/q/identifier.d.ts" />
29
+ /// <reference path="./-types/q/promise-proxies.d.ts" />
30
+ /// <reference path="./-types/q/ds-model.d.ts" />
31
+ /// <reference path="./-types/q/schema-service.d.ts" />
32
+ /// <reference path="./-types/q/cache-store-wrapper.d.ts" />
33
+ /// <reference path="./-types/q/cache.d.ts" />
34
+ declare module '@ember-data/store' {
35
+ /**
36
+ * <p align="center">
37
+ * <img
38
+ * class="project-logo"
39
+ * src="https://raw.githubusercontent.com/emberjs/data/4612c9354e4c54d53327ec2cf21955075ce21294/ember-data-logo-light.svg#gh-light-mode-only"
40
+ * alt="EmberData Store"
41
+ * width="240px"
42
+ * title="EmberData Store"
43
+ * />
44
+ * </p>
45
+ *
46
+ * This package provides [*Ember***Data**](https://github.com/emberjs/data/)'s `Store` class.
47
+ *
48
+ * A [Store](https://api.emberjs.com/ember-data/release/classes/Store) coordinates interaction between your application, a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache),
49
+ * and sources of data (such as your API or a local persistence layer) accessed via a [RequestManager](https://github.com/emberjs/data/tree/main/packages/request).
50
+ *
51
+ * Optionally, a Store can be configured to hydrate the response data into rich presentation classes.
52
+ *
53
+ * ## Installation
54
+ *
55
+ * If you have installed `ember-data` then you already have this package installed.
56
+ * Otherwise you can install it using your javascript package manager of choice.
57
+ * For instance with [pnpm](https://pnpm.io/)
58
+ *
59
+ * ```
60
+ * pnpm add @ember-data/store
61
+ * ```
62
+ *
63
+ * After installing you will want to configure your first `Store`. Read more below
64
+ * for how to create and configure stores for your application.
65
+ *
66
+ *
67
+ * ## 🔨 Creating A Store
68
+ *
69
+ * To use a `Store` we will need to do few things: add a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache)
70
+ * to store data **in-memory**, add a [Handler](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache) to fetch data from a source,
71
+ * and implement `instantiateRecord` to tell the store how to display the data for individual resources.
72
+ *
73
+ * > **Note**
74
+ * > If you are using the package `ember-data` then a JSON:API cache, RequestManager, LegacyNetworkHandler,
75
+ * > and `instantiateRecord` are configured for you by default.
76
+ *
77
+ * ### Configuring A Cache
78
+ *
79
+ * To start, let's install a [JSON:API](https://jsonapi.org/) cache. If your app uses `GraphQL` or `REST` other
80
+ * caches may better fit your data. You can author your own cache by creating one that
81
+ * conforms to the [spec](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache).
82
+ *
83
+ * The package `@ember-data/json-api` provides a [JSON:API](https://jsonapi.org/) cache we can use.
84
+ * After installing it, we can configure the store to use this cache.
85
+ *
86
+ * ```js
87
+ * import Store from '@ember-data/store';
88
+ * import Cache from '@ember-data/json-api';
89
+ *
90
+ * class extends Store {
91
+ * createCache(storeWrapper) {
92
+ * return new Cache(storeWrapper);
93
+ * }
94
+ * }
95
+ * ```
96
+ *
97
+ * Now that we have a `cache` let's setup something to handle fetching
98
+ * and saving data via our API.
99
+ *
100
+ * > **Note**
101
+ * > The `ember-data` package automatically includes and configures
102
+ * > the `@ember-data/json-api` cache for you.
103
+ *
104
+ * ### Handling Requests
105
+ *
106
+ * When *Ember***Data** needs to fetch or save data it will pass that request to your application's `RequestManager` for fulfillment. How this fulfillment occurs (in-memory, device storage, via single or multiple API requests, etc.) is then up to the registered request handlers.
107
+ *
108
+ * To start, let's install the `RequestManager` from `@ember-data/request` and the basic `Fetch` handler from ``@ember-data/request/fetch`.
109
+ *
110
+ * > **Note**
111
+ * > If your app uses `GraphQL`, `REST` or different conventions for `JSON:API` than your cache expects, other handlers may better fit your data. You can author your own handler by creating one that conforms to the [handler interface](https://github.com/emberjs/data/tree/main/packages/request#handling-requests).
112
+ *
113
+ * ```ts
114
+ * import Store from '@ember-data/store';
115
+ * import RequestManager from '@ember-data/request';
116
+ * import Fetch from '@ember-data/request/fetch';
117
+ *
118
+ * export default class extends Store {
119
+ * constructor() {
120
+ * super(...arguments);
121
+ * this.requestManager = new RequestManager();
122
+ * this.requestManager.use([Fetch]);
123
+ * }
124
+ * }
125
+ * ```
126
+ *
127
+ * **Using RequestManager as a Service**
128
+ *
129
+ * Alternatively if you have configured the `RequestManager` to be a service you may re-use it.
130
+ *
131
+ * *app/services/request.js*
132
+ * ```ts
133
+ * import RequestManager from '@ember-data/request';
134
+ * import Fetch from '@ember-data/request/fetch';
135
+ *
136
+ * export default class extends RequestManager {
137
+ * constructor(createArgs) {
138
+ * super(createArgs);
139
+ * this.use([Fetch]);
140
+ * }
141
+ * }
142
+ * ```
143
+ *
144
+ * *app/services/store.js*
145
+ * ```ts
146
+ * import Store from '@ember-data/store';
147
+ * import { service } from '@ember/service';
148
+ *
149
+ * export default class extends Store {
150
+ * @service('request') requestManager
151
+ * }
152
+ * ```
153
+ *
154
+ *
155
+ * ### Presenting Data from the Cache
156
+ *
157
+ * Now that we have a source and a cach for our data, we need to configure how
158
+ * the Store delivers that data back to our application. We do this via the hook
159
+ * [instantiateRecord](https://api.emberjs.com/ember-data/release/classes/Store/methods/instantiateRecord%20(hook)?anchor=instantiateRecord%20(hook)),
160
+ * which allows us to transform the data for a resource before handing it to the application.
161
+ *
162
+ * A naive way to present the data would be to return it as JSON. Typically instead
163
+ * this hook will be used to add reactivity and make each unique resource a singleton,
164
+ * ensuring that if the cache updates our presented data will reflect the new state.
165
+ *
166
+ * Below is an example of using the hooks `instantiateRecord` and a `teardownRecord`
167
+ * to provide minimal read-only reactive state for simple resources.
168
+ *
169
+ * ```ts
170
+ * import Store, { recordIdentifierFor } from '@ember-data/store';
171
+ * import { TrackedObject } from 'tracked-built-ins';
172
+ *
173
+ * class extends Store {
174
+ * instantiateRecord(identifier) {
175
+ * const { cache, notifications } = this;
176
+ *
177
+ * // create a TrackedObject with our attributes, id and type
178
+ * const record = new TrackedObject(Object.assign({}, cache.peek(identifier)));
179
+ * record.type = identifier.type;
180
+ * record.id = identifier.id;
181
+ *
182
+ * notifications.subscribe(identifier, (_, change) => {
183
+ * if (change === 'attributes') {
184
+ * Object.assign(record, cache.peek(identifier));
185
+ * }
186
+ * });
187
+ *
188
+ * return record;
189
+ * }
190
+ * }
191
+ * ```
192
+ *
193
+ * Because `instantiateRecord` is opaque to the nature of the record, an implementation
194
+ * can be anything from a fairly simple object to a robust proxy that intelligently links
195
+ * together associated records through relationships.
196
+ *
197
+ * This also enables creating a record that separates `edit` flows from `create` flows
198
+ * entirely. A record class might choose to implement a `checkout`method that gives access
199
+ * to an editable instance while the primary record continues to be read-only and reflect
200
+ * only persisted (non-mutated) state.
201
+ *
202
+ * Typically you will choose an existing record implementation such as `@ember-data/model`
203
+ * for your application.
204
+ *
205
+ * Because of the boundaries around instantiation and the cache, record implementations
206
+ * should be capable of interop both with each other and with any `Cache`. Due to this,
207
+ * if needed an application can utilize multiple record implementations and multiple cache
208
+ * implementations either to support enhanced features for only a subset of records or to
209
+ * be able to incrementally migrate from one record/cache to another record or cache.
210
+ *
211
+ * > **Note**
212
+ * > The `ember-data` package automatically includes the `@ember-data/model`
213
+ * > package and configures it for you.
214
+ *
215
+ * @module @ember-data/store
216
+ * @main @ember-data/store
217
+ */
218
+ export { Store as default, CacheHandler, type LifetimesService, setIdentifierGenerationMethod, setIdentifierUpdateMethod, setIdentifierForgetMethod, setIdentifierResetMethod, recordIdentifierFor, storeFor, } from '@ember-data/store/-private';
219
+ //# sourceMappingURL=index.d.ts.map
220
+ }