@ember-data/store 5.4.0-alpha.14 → 5.4.0-alpha.140

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 (90) hide show
  1. package/README.md +19 -10
  2. package/addon-main.cjs +5 -0
  3. package/dist/-private.js +1 -0
  4. package/{addon → dist}/index.js +4 -1
  5. package/{addon/store-service-6855d74f.js → dist/many-array-DJ3xLLia.js} +2591 -1428
  6. package/dist/many-array-DJ3xLLia.js.map +1 -0
  7. package/dist/types.js +0 -0
  8. package/dist/types.js.map +1 -0
  9. package/package.json +70 -45
  10. package/unstable-preview-types/-private/cache-handler/handler.d.ts +62 -0
  11. package/unstable-preview-types/-private/cache-handler/handler.d.ts.map +1 -0
  12. package/unstable-preview-types/-private/cache-handler/types.d.ts +107 -0
  13. package/unstable-preview-types/-private/cache-handler/types.d.ts.map +1 -0
  14. package/unstable-preview-types/-private/cache-handler/utils.d.ts +39 -0
  15. package/unstable-preview-types/-private/cache-handler/utils.d.ts.map +1 -0
  16. package/unstable-preview-types/-private/caches/cache-utils.d.ts +11 -0
  17. package/unstable-preview-types/-private/caches/cache-utils.d.ts.map +1 -0
  18. package/unstable-preview-types/-private/caches/identifier-cache.d.ts +176 -0
  19. package/unstable-preview-types/-private/caches/identifier-cache.d.ts.map +1 -0
  20. package/unstable-preview-types/-private/caches/instance-cache.d.ts +61 -0
  21. package/unstable-preview-types/-private/caches/instance-cache.d.ts.map +1 -0
  22. package/unstable-preview-types/-private/caches/resource-utils.d.ts +12 -0
  23. package/unstable-preview-types/-private/caches/resource-utils.d.ts.map +1 -0
  24. package/unstable-preview-types/-private/debug/utils.d.ts +9 -0
  25. package/unstable-preview-types/-private/debug/utils.d.ts.map +1 -0
  26. package/unstable-preview-types/-private/document.d.ts +146 -0
  27. package/unstable-preview-types/-private/document.d.ts.map +1 -0
  28. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts +179 -0
  29. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts.map +1 -0
  30. package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts +19 -0
  31. package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts.map +1 -0
  32. package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts +31 -0
  33. package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts.map +1 -0
  34. package/unstable-preview-types/-private/managers/cache-manager.d.ts +463 -0
  35. package/unstable-preview-types/-private/managers/cache-manager.d.ts.map +1 -0
  36. package/unstable-preview-types/-private/managers/notification-manager.d.ts +102 -0
  37. package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -0
  38. package/unstable-preview-types/-private/managers/record-array-manager.d.ts +99 -0
  39. package/unstable-preview-types/-private/managers/record-array-manager.d.ts.map +1 -0
  40. package/unstable-preview-types/-private/network/request-cache.d.ts +109 -0
  41. package/unstable-preview-types/-private/network/request-cache.d.ts.map +1 -0
  42. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts +148 -0
  43. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts.map +1 -0
  44. package/unstable-preview-types/-private/record-arrays/many-array.d.ts +199 -0
  45. package/unstable-preview-types/-private/record-arrays/many-array.d.ts.map +1 -0
  46. package/unstable-preview-types/-private/record-arrays/native-proxy-type-fix.d.ts +118 -0
  47. package/unstable-preview-types/-private/record-arrays/native-proxy-type-fix.d.ts.map +1 -0
  48. package/unstable-preview-types/-private/store-service.d.ts +1538 -0
  49. package/unstable-preview-types/-private/store-service.d.ts.map +1 -0
  50. package/unstable-preview-types/-private/store-service.type-test.d.ts +4 -0
  51. package/unstable-preview-types/-private/store-service.type-test.d.ts.map +1 -0
  52. package/unstable-preview-types/-private/utils/coerce-id.d.ts +10 -0
  53. package/unstable-preview-types/-private/utils/coerce-id.d.ts.map +1 -0
  54. package/unstable-preview-types/-private/utils/construct-resource.d.ts +9 -0
  55. package/unstable-preview-types/-private/utils/construct-resource.d.ts.map +1 -0
  56. package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts +4 -0
  57. package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts.map +1 -0
  58. package/unstable-preview-types/-private/utils/normalize-model-name.d.ts +4 -0
  59. package/unstable-preview-types/-private/utils/normalize-model-name.d.ts.map +1 -0
  60. package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts +4 -0
  61. package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts.map +1 -0
  62. package/unstable-preview-types/-private.d.ts +28 -0
  63. package/unstable-preview-types/-private.d.ts.map +1 -0
  64. package/unstable-preview-types/-types/overview.d.ts +21 -0
  65. package/unstable-preview-types/-types/overview.d.ts.map +1 -0
  66. package/unstable-preview-types/-types/q/cache-capabilities-manager.d.ts +109 -0
  67. package/unstable-preview-types/-types/q/cache-capabilities-manager.d.ts.map +1 -0
  68. package/unstable-preview-types/-types/q/ds-model.d.ts +25 -0
  69. package/unstable-preview-types/-types/q/ds-model.d.ts.map +1 -0
  70. package/unstable-preview-types/-types/q/identifier.d.ts +193 -0
  71. package/unstable-preview-types/-types/q/identifier.d.ts.map +1 -0
  72. package/unstable-preview-types/-types/q/promise-proxies.d.ts +4 -0
  73. package/unstable-preview-types/-types/q/promise-proxies.d.ts.map +1 -0
  74. package/unstable-preview-types/-types/q/record-data-json-api.d.ts +36 -0
  75. package/unstable-preview-types/-types/q/record-data-json-api.d.ts.map +1 -0
  76. package/unstable-preview-types/-types/q/record-instance.d.ts +29 -0
  77. package/unstable-preview-types/-types/q/record-instance.d.ts.map +1 -0
  78. package/unstable-preview-types/-types/q/schema-service.d.ts +358 -0
  79. package/unstable-preview-types/-types/q/schema-service.d.ts.map +1 -0
  80. package/unstable-preview-types/-types/q/store.d.ts +38 -0
  81. package/unstable-preview-types/-types/q/store.d.ts.map +1 -0
  82. package/unstable-preview-types/index.d.ts +223 -0
  83. package/unstable-preview-types/index.d.ts.map +1 -0
  84. package/unstable-preview-types/types.d.ts +7 -0
  85. package/unstable-preview-types/types.d.ts.map +1 -0
  86. package/addon/-private.js +0 -1
  87. package/addon/store-service-6855d74f.js.map +0 -1
  88. package/addon-main.js +0 -93
  89. /package/{addon → dist}/-private.js.map +0 -0
  90. /package/{addon → dist}/index.js.map +0 -0
@@ -0,0 +1,1538 @@
1
+ declare module '@ember-data/store/-private/store-service' {
2
+ import type RequestManager from '@ember-data/request';
3
+ import type { Future } from '@ember-data/request';
4
+ import type { Cache } from '@warp-drive/core-types/cache';
5
+ import type { Graph } from '@warp-drive/core-types/graph';
6
+ import type { StableDocumentIdentifier, StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier';
7
+ import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
8
+ import type { CollectionResourceDocument, EmptyResourceDocument, JsonApiDocument, ResourceIdentifierObject, SingleResourceDocument } from '@warp-drive/core-types/spec/json-api-raw';
9
+ import type { Type } from '@warp-drive/core-types/symbols';
10
+ import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-capabilities-manager';
11
+ import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
12
+ import type { OpaqueRecordInstance } from '@ember-data/store/-types/q/record-instance';
13
+ import type { SchemaService } from '@ember-data/store/-types/q/schema-service';
14
+ import type { FindAllOptions, FindRecordOptions, LegacyResourceQuery, QueryOptions } from '@ember-data/store/-types/q/store';
15
+ import type { StoreRequestInput } from '@ember-data/store/-private/cache-handler/handler';
16
+ import type { CachePolicy } from '@ember-data/store/-private/cache-handler/types';
17
+ import { IdentifierCache } from '@ember-data/store/-private/caches/identifier-cache';
18
+ import { InstanceCache, storeFor } from '@ember-data/store/-private/caches/instance-cache';
19
+ import type { Document } from '@ember-data/store/-private/document';
20
+ import type RecordReference from '@ember-data/store/-private/legacy-model-support/record-reference';
21
+ import NotificationManager from '@ember-data/store/-private/managers/notification-manager';
22
+ import { RecordArrayManager } from '@ember-data/store/-private/managers/record-array-manager';
23
+ import { RequestStateService } from '@ember-data/store/-private/network/request-cache';
24
+ import type { Collection, IdentifierArray } from '@ember-data/store/-private/record-arrays/identifier-array';
25
+ export { storeFor };
26
+ type EmberObjectKey = '_debugContainerKey' | '_super' | 'addObserver' | 'cacheFor' | 'concatenatedProperties' | 'decrementProperty' | 'destroy' | 'get' | 'getProperties' | 'incrementProperty' | 'init' | 'isDestroyed' | 'isDestroying' | 'mergedProperties' | 'notifyPropertyChange' | 'removeObserver' | 'reopen' | 'set' | 'setProperties' | 'toggleProperty' | 'toString' | 'willDestroy';
27
+ type DSModelKeys = '___(unique) Symbol(Store)' | '___private_notifications' | '___recordState' | '_createSnapshot' | 'adapterError' | 'attr' | 'belongsTo' | 'changedAttributes' | 'currentState' | 'deleteRecord' | 'destroyRecord' | 'dirtyType' | 'eachAttribute' | 'eachRelationship' | 'errors' | 'hasDirtyAttributes' | 'hasMany' | 'inverseFor' | 'isDeleted' | 'isEmpty' | 'isError' | 'isLoaded' | 'isLoading' | 'isNew' | 'isReloading' | 'isSaving' | 'isValid' | 'relationshipFor' | 'reload' | 'rollbackAttributes' | 'save' | 'serialize' | 'store' | 'unloadRecord';
28
+ type DownlevelArrays<T> = T extends Array<infer U> ? U[] : T;
29
+ type AwaitedKeys<T> = {
30
+ [K in keyof T & string]: DownlevelArrays<Awaited<T[K]>>;
31
+ };
32
+ type FilteredKeys<T> = AwaitedKeys<Omit<T, typeof Type | EmberObjectKey | DSModelKeys | 'constructor'>>;
33
+ type MaybeHasId = {
34
+ id?: string | null;
35
+ };
36
+ /**
37
+ * Currently only records that extend object can be created via
38
+ * store.createRecord. This is a limitation of the current API,
39
+ * but can be worked around by creating a new identifier, running
40
+ * the cache.clientDidCreate method, and then peeking the record
41
+ * for the identifier.
42
+ *
43
+ * To assign primary key to a record during creation, only `id` will
44
+ * work correctly for `store.createRecord`, other primary key may be
45
+ * handled by updating the record after creation or using the flow
46
+ * described above.
47
+ *
48
+ * TODO: These are limitations we want to (and can) address. If you
49
+ * have need of lifting these limitations, please open an issue.
50
+ *
51
+ * @typedoc
52
+ */
53
+ export type CreateRecordProperties<T = MaybeHasId & Record<string, unknown>> = T extends TypedRecordInstance ? Partial<FilteredKeys<T>> : T extends MaybeHasId ? MaybeHasId & Partial<FilteredKeys<T>> : MaybeHasId & Record<string, unknown>;
54
+ const BaseClass: {
55
+ new (args?: unknown): {};
56
+ };
57
+ export interface Store {
58
+ createCache(capabilities: CacheCapabilitiesManager): Cache;
59
+ instantiateRecord<T>(identifier: StableRecordIdentifier, createRecordArgs: {
60
+ [key: string]: unknown;
61
+ }): OpaqueRecordInstance;
62
+ teardownRecord(record: OpaqueRecordInstance): void;
63
+ createSchemaService(): SchemaService;
64
+ /**
65
+ * DEPRECATED - Use the property `store.schema` instead.
66
+ *
67
+ * Provides access to the SchemaDefinitionService instance
68
+ * for this Store instance.
69
+ *
70
+ * The SchemaDefinitionService can be used to query for
71
+ * information about the schema of a resource.
72
+ *
73
+ * @method getSchemaDefinitionService
74
+ * @deprecated
75
+ * @public
76
+ */
77
+ getSchemaDefinitionService(): SchemaService;
78
+ /**
79
+ * DEPRECATED - Use `createSchemaService` instead.
80
+ *
81
+ * Allows an app to register a custom SchemaService
82
+ * for use when information about a resource's schema needs
83
+ * to be queried.
84
+ *
85
+ * This method can only be called more than once, but only one schema
86
+ * definition service may exist. Therefore if you wish to chain services
87
+ * you must lookup the existing service and close over it with the new
88
+ * service by accessing `store.schema` prior to registration.
89
+ *
90
+ * For Example:
91
+ *
92
+ * ```ts
93
+ * import Store from '@ember-data/store';
94
+ *
95
+ * class SchemaDelegator {
96
+ * constructor(schema) {
97
+ * this._schema = schema;
98
+ * }
99
+ *
100
+ * hasResource(resource: { type: string }): boolean {
101
+ * if (AbstractSchemas.has(resource.type)) {
102
+ * return true;
103
+ * }
104
+ * return this._schema.hasResource(resource);
105
+ * }
106
+ *
107
+ * attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {
108
+ * return this._schema.attributesDefinitionFor(identifier);
109
+ * }
110
+ *
111
+ * relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {
112
+ * const schema = AbstractSchemas.get(identifier.type);
113
+ * return schema || this._schema.relationshipsDefinitionFor(identifier);
114
+ * }
115
+ * }
116
+ *
117
+ * export default class extends Store {
118
+ * constructor(...args) {
119
+ * super(...args);
120
+ *
121
+ * const schema = this.createSchemaService();
122
+ * this.registerSchemaDefinitionService(new SchemaDelegator(schema));
123
+ * }
124
+ * }
125
+ * ```
126
+ *
127
+ * @method registerSchemaDefinitionService
128
+ * @param {SchemaService} schema
129
+ * @deprecated
130
+ * @public
131
+ */
132
+ registerSchemaDefinitionService(schema: SchemaService): void;
133
+ /**
134
+ * DEPRECATED - Use `createSchemaService` instead.
135
+ *
136
+ * Allows an app to register a custom SchemaService
137
+ * for use when information about a resource's schema needs
138
+ * to be queried.
139
+ *
140
+ * This method can only be called more than once, but only one schema
141
+ * definition service may exist. Therefore if you wish to chain services
142
+ * you must lookup the existing service and close over it with the new
143
+ * service by accessing `store.schema` prior to registration.
144
+ *
145
+ * For Example:
146
+ *
147
+ * ```ts
148
+ * import Store from '@ember-data/store';
149
+ *
150
+ * class SchemaDelegator {
151
+ * constructor(schema) {
152
+ * this._schema = schema;
153
+ * }
154
+ *
155
+ * hasResource(resource: { type: string }): boolean {
156
+ * if (AbstractSchemas.has(resource.type)) {
157
+ * return true;
158
+ * }
159
+ * return this._schema.hasResource(resource);
160
+ * }
161
+ *
162
+ * attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {
163
+ * return this._schema.attributesDefinitionFor(identifier);
164
+ * }
165
+ *
166
+ * relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {
167
+ * const schema = AbstractSchemas.get(identifier.type);
168
+ * return schema || this._schema.relationshipsDefinitionFor(identifier);
169
+ * }
170
+ * }
171
+ *
172
+ * export default class extends Store {
173
+ * constructor(...args) {
174
+ * super(...args);
175
+ *
176
+ * const schema = this.schema;
177
+ * this.registerSchema(new SchemaDelegator(schema));
178
+ * }
179
+ * }
180
+ * ```
181
+ *
182
+ * @method registerSchema
183
+ * @param {SchemaService} schema
184
+ * @deprecated
185
+ * @public
186
+ */
187
+ registerSchema(schema: SchemaService): void;
188
+ }
189
+ export class Store extends BaseClass {
190
+ recordArrayManager: RecordArrayManager;
191
+ /**
192
+ * Provides access to the NotificationManager associated
193
+ * with this Store instance.
194
+ *
195
+ * The NotificationManager can be used to subscribe to
196
+ * changes to the cache.
197
+ *
198
+ * @property {NotificationManager} notifications
199
+ * @public
200
+ */
201
+ notifications: NotificationManager;
202
+ /**
203
+ * Provides access to the SchemaService instance
204
+ * for this Store instance.
205
+ *
206
+ * The SchemaService can be used to query for
207
+ * information about the schema of a resource.
208
+ *
209
+ * @property {SchemaService} schema
210
+ * @public
211
+ */
212
+ get schema(): ReturnType<this['createSchemaService']>;
213
+ _schema: SchemaService;
214
+ /**
215
+ * Provides access to the IdentifierCache instance
216
+ * for this store.
217
+ *
218
+ * The IdentifierCache can be used to generate or
219
+ * retrieve a stable unique identifier for any resource.
220
+ *
221
+ * @property {IdentifierCache} identifierCache
222
+ * @public
223
+ */
224
+ identifierCache: IdentifierCache;
225
+ /**
226
+ * Provides access to the requestManager instance associated
227
+ * with this Store instance.
228
+ *
229
+ * When using `ember-data` this property is automatically
230
+ * set to an instance of `RequestManager`. When not using `ember-data`
231
+ * you must configure this property yourself, either by declaring
232
+ * it as a service or by initializing it.
233
+ *
234
+ * ```ts
235
+ * import Store, { CacheHandler } from '@ember-data/store';
236
+ * import RequestManager from '@ember-data/request';
237
+ * import Fetch from '@ember-data/request/fetch';
238
+ *
239
+ * class extends Store {
240
+ * requestManager = new RequestManager()
241
+ * .use([Fetch])
242
+ * .useCache(CacheHandler);
243
+ * }
244
+ * ```
245
+ *
246
+ * @public
247
+ * @property {RequestManager} requestManager
248
+ */
249
+ requestManager: RequestManager;
250
+ /**
251
+ * A Property which an App may set to provide a CachePolicy
252
+ * to control when a cached request becomes stale.
253
+ *
254
+ * Note, when defined, these methods will only be invoked if a
255
+ * cache key exists for the request, either because the request
256
+ * contains `cacheOptions.key` or because the [IdentifierCache](/ember-data/release/classes/IdentifierCache)
257
+ * was able to generate a key for the request using the configured
258
+ * [generation method](/ember-data/release/functions/@ember-data%2Fstore/setIdentifierGenerationMethod).
259
+ *
260
+ * `isSoftExpired` will only be invoked if `isHardExpired` returns `false`.
261
+ *
262
+ * ```ts
263
+ * store.lifetimes = {
264
+ * // make the request and ignore the current cache state
265
+ * isHardExpired(identifier: StableDocumentIdentifier): boolean {
266
+ * return false;
267
+ * }
268
+ *
269
+ * // make the request in the background if true, return cache state
270
+ * isSoftExpired(identifier: StableDocumentIdentifier): boolean {
271
+ * return false;
272
+ * }
273
+ * }
274
+ * ```
275
+ *
276
+ * @public
277
+ * @property {CachePolicy|undefined} lifetimes
278
+ */
279
+ lifetimes?: CachePolicy;
280
+ _graph?: Graph;
281
+ _requestCache: RequestStateService;
282
+ _instanceCache: InstanceCache;
283
+ _documentCache: Map<StableDocumentIdentifier, Document<OpaqueRecordInstance | OpaqueRecordInstance[] | null | undefined>>;
284
+ _cbs: {
285
+ coalesce?: () => void;
286
+ sync?: () => void;
287
+ notify?: () => void;
288
+ } | null;
289
+ _forceShim: boolean;
290
+ /**
291
+ * Async flush buffers notifications until flushed
292
+ * by finalization of a future configured by store.request
293
+ *
294
+ * This is useful for ensuring that notifications are delivered
295
+ * prior to the promise resolving but without risk of promise
296
+ * interleaving.
297
+ *
298
+ * @internal
299
+ */
300
+ _enableAsyncFlush: boolean | null;
301
+ DISABLE_WAITER?: boolean;
302
+ _isDestroying: boolean;
303
+ _isDestroyed: boolean;
304
+ get isDestroying(): boolean;
305
+ set isDestroying(value: boolean);
306
+ get isDestroyed(): boolean;
307
+ set isDestroyed(value: boolean);
308
+ /**
309
+ @method init
310
+ @private
311
+ */
312
+ constructor(createArgs?: unknown);
313
+ _run(cb: () => void): void;
314
+ /**
315
+ * Executes the callback, ensurng that any work that calls
316
+ * store._schedule is executed after in the right order.
317
+ *
318
+ * When queues already exist, scheduled callbacks will
319
+ * join the existing queue.
320
+ *
321
+ * @internal
322
+ */
323
+ _join(cb: () => void): void;
324
+ _schedule(name: 'coalesce' | 'sync' | 'notify', cb: () => void): void;
325
+ /**
326
+ * Retrieve the RequestStateService instance
327
+ * associated with this Store.
328
+ *
329
+ * This can be used to query the status of requests
330
+ * that have been initiated for a given identifier.
331
+ *
332
+ * @method getRequestStateService
333
+ * @return {RequestStateService}
334
+ * @public
335
+ */
336
+ getRequestStateService(): RequestStateService;
337
+ _getAllPending(): (Promise<unknown[]> & {
338
+ length: number;
339
+ }) | void;
340
+ /**
341
+ * Issue a request via the configured RequestManager,
342
+ * inserting the response into the cache and handing
343
+ * back a Future which resolves to a ResponseDocument
344
+ *
345
+ * ## Cache Keys
346
+ *
347
+ * Only GET requests with a url or requests with an explicit
348
+ * cache key (`cacheOptions.key`) will have the request result
349
+ * and document cached.
350
+ *
351
+ * The cache key used is `requestConfig.cacheOptions.key`
352
+ * if present, falling back to `requestConfig.url`.
353
+ *
354
+ * Params are not serialized as part of the cache-key, so
355
+ * either ensure they are already in the url or utilize
356
+ * `requestConfig.cacheOptions.key`. For queries issued
357
+ * via the `POST` method `requestConfig.cacheOptions.key`
358
+ * MUST be supplied for the document to be cached.
359
+ *
360
+ * ## Requesting Without a Cache Key
361
+ *
362
+ * Resource data within the request is always updated in the cache,
363
+ * regardless of whether a cache key is present for the request.
364
+ *
365
+ * ## Fulfilling From Cache
366
+ *
367
+ * When a cache-key is determined, the request may fulfill
368
+ * from cache provided the cache is not stale.
369
+ *
370
+ * Cache staleness is determined by the configured CachePolicy
371
+ * with priority given to the `cacheOptions.reload` and
372
+ * `cacheOptions.backgroundReload` on the request if present.
373
+ *
374
+ * If the cache data has soft expired or the request asks for a background
375
+ * reload, the request will fulfill from cache if possible and
376
+ * make a non-blocking request in the background to update the cache.
377
+ *
378
+ * If the cache data has hard expired or the request asks for a reload,
379
+ * the request will not fulfill from cache and will make a blocking
380
+ * request to update the cache.
381
+ *
382
+ * ## The Response
383
+ *
384
+ * The primary difference between `requestManager.request` and `store.request`
385
+ * is that `store.request` will attempt to hydrate the response content into
386
+ * a response Document containing RecordInstances.
387
+ *
388
+ * @method request
389
+ * @param {StoreRequestInput} requestConfig
390
+ * @return {Future}
391
+ * @public
392
+ */
393
+ request<RT, T = unknown>(requestConfig: StoreRequestInput<T, RT>): Future<RT>;
394
+ /**
395
+ * A hook which an app or addon may implement. Called when
396
+ * the Store is attempting to create a Record Instance for
397
+ * a resource.
398
+ *
399
+ * This hook can be used to select or instantiate any desired
400
+ * mechanism of presenting cache data to the ui for access
401
+ * mutation, and interaction.
402
+ *
403
+ * @method instantiateRecord (hook)
404
+ * @param identifier
405
+ * @param createRecordArgs
406
+ * @param recordDataFor deprecated use this.cache
407
+ * @param notificationManager deprecated use this.notifications
408
+ * @return A record instance
409
+ * @public
410
+ */
411
+ /**
412
+ * A hook which an app or addon may implement. Called when
413
+ * the Store is destroying a Record Instance. This hook should
414
+ * be used to teardown any custom record instances instantiated
415
+ * with `instantiateRecord`.
416
+ *
417
+ * @method teardownRecord (hook)
418
+ * @public
419
+ * @param record
420
+ */
421
+ /**
422
+ Returns the schema for a particular resource type (modelName).
423
+
424
+ When used with Model from @ember-data/model the return is the model class,
425
+ but this is not guaranteed.
426
+
427
+ If looking to query attribute or relationship information it is
428
+ recommended to use `getSchemaDefinitionService` instead. This method
429
+ should be considered legacy and exists primarily to continue to support
430
+ Adapter/Serializer APIs which expect it's return value in their method
431
+ signatures.
432
+
433
+ The class of a model might be useful if you want to get a list of all the
434
+ relationship names of the model, see
435
+ [`relationshipNames`](/ember-data/release/classes/Model?anchor=relationshipNames)
436
+ for example.
437
+
438
+ @method modelFor
439
+ @public
440
+ @deprecated
441
+ @param {string} type
442
+ @return {ModelSchema}
443
+ */
444
+ modelFor<T>(type: TypeFromInstance<T>): ModelSchema<T>;
445
+ modelFor(type: string): ModelSchema;
446
+ /**
447
+ Create a new record in the current store. The properties passed
448
+ to this method are set on the newly created record.
449
+
450
+ To create a new instance of a `Post`:
451
+
452
+ ```js
453
+ store.createRecord('post', {
454
+ title: 'Ember is awesome!'
455
+ });
456
+ ```
457
+
458
+ To create a new instance of a `Post` that has a relationship with a `User` record:
459
+
460
+ ```js
461
+ let user = this.store.peekRecord('user', '1');
462
+ store.createRecord('post', {
463
+ title: 'Ember is awesome!',
464
+ user: user
465
+ });
466
+ ```
467
+
468
+ @method createRecord
469
+ @public
470
+ @param {String} type the name of the resource
471
+ @param {Object} inputProperties a hash of properties to set on the
472
+ newly created record.
473
+ @return {Model} record
474
+ */
475
+ createRecord<T>(type: TypeFromInstance<T>, inputProperties: CreateRecordProperties<T>): T;
476
+ createRecord(type: string, inputProperties: CreateRecordProperties): OpaqueRecordInstance;
477
+ /**
478
+ For symmetry, a record can be deleted via the store.
479
+
480
+ Example
481
+
482
+ ```javascript
483
+ let post = store.createRecord('post', {
484
+ title: 'Ember is awesome!'
485
+ });
486
+
487
+ store.deleteRecord(post);
488
+ ```
489
+
490
+ @method deleteRecord
491
+ @public
492
+ @param {unknown} record
493
+ */
494
+ deleteRecord<T>(record: T): void;
495
+ /**
496
+ For symmetry, a record can be unloaded via the store.
497
+ This will cause the record to be destroyed and freed up for garbage collection.
498
+
499
+ Example
500
+
501
+ ```javascript
502
+ const { content: { data: post } } = await store.request(findRecord({ type: 'post', id: '1' }));
503
+ store.unloadRecord(post);
504
+ ```
505
+
506
+ @method unloadRecord
507
+ @public
508
+ @param {Model} record
509
+ */
510
+ unloadRecord<T>(record: T): void;
511
+ /**
512
+ This method returns a record for a given identifier or type and id combination.
513
+
514
+ The `findRecord` method will always resolve its promise with the same
515
+ object for a given identifier or type and `id`.
516
+
517
+ The `findRecord` method will always return a **promise** that will be
518
+ resolved with the record.
519
+
520
+ **Example 1**
521
+
522
+ ```app/routes/post.js
523
+ export default class PostRoute extends Route {
524
+ model({ post_id }) {
525
+ return this.store.findRecord('post', post_id);
526
+ }
527
+ }
528
+ ```
529
+
530
+ **Example 2**
531
+
532
+ `findRecord` can be called with a single identifier argument instead of the combination
533
+ of `type` (modelName) and `id` as separate arguments. You may recognize this combo as
534
+ the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)
535
+
536
+ ```app/routes/post.js
537
+ export default class PostRoute extends Route {
538
+ model({ post_id: id }) {
539
+ return this.store.findRecord({ type: 'post', id });
540
+ }
541
+ }
542
+ ```
543
+
544
+ **Example 3**
545
+
546
+ If you have previously received an lid via an Identifier for this record, and the record
547
+ has already been assigned an id, you can find the record again using just the lid.
548
+
549
+ ```app/routes/post.js
550
+ store.findRecord({ lid });
551
+ ```
552
+
553
+ If the record is not yet available, the store will ask the adapter's `findRecord`
554
+ method to retrieve and supply the necessary data. If the record is already present
555
+ in the store, it depends on the reload behavior _when_ the returned promise
556
+ resolves.
557
+
558
+ ### Preloading
559
+
560
+ You can optionally `preload` specific attributes and relationships that you know of
561
+ by passing them via the passed `options`.
562
+
563
+ For example, if your Ember route looks like `/posts/1/comments/2` and your API route
564
+ for the comment also looks like `/posts/1/comments/2` if you want to fetch the comment
565
+ without also fetching the post you can pass in the post to the `findRecord` call:
566
+
567
+ ```app/routes/post-comments.js
568
+ export default class PostRoute extends Route {
569
+ model({ post_id, comment_id: id }) {
570
+ return this.store.findRecord({ type: 'comment', id, { preload: { post: post_id }} });
571
+ }
572
+ }
573
+ ```
574
+
575
+ In your adapter you can then access this id without triggering a network request via the
576
+ snapshot:
577
+
578
+ ```app/adapters/application.js
579
+ export default class Adapter {
580
+
581
+ findRecord(store, schema, id, snapshot) {
582
+ let type = schema.modelName;
583
+
584
+ if (type === 'comment')
585
+ let postId = snapshot.belongsTo('post', { id: true });
586
+
587
+ return fetch(`./posts/${postId}/comments/${id}`)
588
+ .then(response => response.json())
589
+ }
590
+ }
591
+
592
+ static create() {
593
+ return new this();
594
+ }
595
+ }
596
+ ```
597
+
598
+ This could also be achieved by supplying the post id to the adapter via the adapterOptions
599
+ property on the options hash.
600
+
601
+ ```app/routes/post-comments.js
602
+ export default class PostRoute extends Route {
603
+ model({ post_id, comment_id: id }) {
604
+ return this.store.findRecord({ type: 'comment', id, { adapterOptions: { post: post_id }} });
605
+ }
606
+ }
607
+ ```
608
+
609
+ ```app/adapters/application.js
610
+ export default class Adapter {
611
+ findRecord(store, schema, id, snapshot) {
612
+ let type = schema.modelName;
613
+
614
+ if (type === 'comment')
615
+ let postId = snapshot.adapterOptions.post;
616
+
617
+ return fetch(`./posts/${postId}/comments/${id}`)
618
+ .then(response => response.json())
619
+ }
620
+ }
621
+
622
+ static create() {
623
+ return new this();
624
+ }
625
+ }
626
+ ```
627
+
628
+ If you have access to the post model you can also pass the model itself to preload:
629
+
630
+ ```javascript
631
+ let post = await store.findRecord('post', '1');
632
+ let comment = await store.findRecord('comment', '2', { post: myPostModel });
633
+ ```
634
+
635
+ ### Reloading
636
+
637
+ The reload behavior is configured either via the passed `options` hash or
638
+ the result of the adapter's `shouldReloadRecord`.
639
+
640
+ If `{ reload: true }` is passed or `adapter.shouldReloadRecord` evaluates
641
+ to `true`, then the returned promise resolves once the adapter returns
642
+ data, regardless if the requested record is already in the store:
643
+
644
+ ```js
645
+ store.push({
646
+ data: {
647
+ id: 1,
648
+ type: 'post',
649
+ revision: 1
650
+ }
651
+ });
652
+
653
+ // adapter#findRecord resolves with
654
+ // [
655
+ // {
656
+ // id: 1,
657
+ // type: 'post',
658
+ // revision: 2
659
+ // }
660
+ // ]
661
+ store.findRecord('post', '1', { reload: true }).then(function(post) {
662
+ post.revision; // 2
663
+ });
664
+ ```
665
+
666
+ If no reload is indicated via the above mentioned ways, then the promise
667
+ immediately resolves with the cached version in the store.
668
+
669
+ ### Background Reloading
670
+
671
+ Optionally, if `adapter.shouldBackgroundReloadRecord` evaluates to `true`,
672
+ then a background reload is started, which updates the records' data, once
673
+ it is available:
674
+
675
+ ```js
676
+ // app/adapters/post.js
677
+ import ApplicationAdapter from "./application";
678
+
679
+ export default class PostAdapter extends ApplicationAdapter {
680
+ shouldReloadRecord(store, snapshot) {
681
+ return false;
682
+ },
683
+
684
+ shouldBackgroundReloadRecord(store, snapshot) {
685
+ return true;
686
+ }
687
+ });
688
+
689
+ // ...
690
+
691
+ store.push({
692
+ data: {
693
+ id: 1,
694
+ type: 'post',
695
+ revision: 1
696
+ }
697
+ });
698
+
699
+ let blogPost = store.findRecord('post', '1').then(function(post) {
700
+ post.revision; // 1
701
+ });
702
+
703
+ // later, once adapter#findRecord resolved with
704
+ // [
705
+ // {
706
+ // id: 1,
707
+ // type: 'post',
708
+ // revision: 2
709
+ // }
710
+ // ]
711
+
712
+ blogPost.revision; // 2
713
+ ```
714
+
715
+ If you would like to force or prevent background reloading, you can set a
716
+ boolean value for `backgroundReload` in the options object for
717
+ `findRecord`.
718
+
719
+ ```app/routes/post/edit.js
720
+ export default class PostEditRoute extends Route {
721
+ model(params) {
722
+ return this.store.findRecord('post', params.post_id, { backgroundReload: false });
723
+ }
724
+ }
725
+ ```
726
+
727
+ If you pass an object on the `adapterOptions` property of the options
728
+ argument it will be passed to your adapter via the snapshot
729
+
730
+ ```app/routes/post/edit.js
731
+ export default class PostEditRoute extends Route {
732
+ model(params) {
733
+ return this.store.findRecord('post', params.post_id, {
734
+ adapterOptions: { subscribe: false }
735
+ });
736
+ }
737
+ }
738
+ ```
739
+
740
+ ```app/adapters/post.js
741
+ import MyCustomAdapter from './custom-adapter';
742
+
743
+ export default class PostAdapter extends MyCustomAdapter {
744
+ findRecord(store, type, id, snapshot) {
745
+ if (snapshot.adapterOptions.subscribe) {
746
+ // ...
747
+ }
748
+ // ...
749
+ }
750
+ }
751
+ ```
752
+
753
+ See [peekRecord](../methods/peekRecord?anchor=peekRecord) to get the cached version of a record.
754
+
755
+ ### Retrieving Related Model Records
756
+
757
+ If you use an adapter such as Ember's default
758
+ [`JSONAPIAdapter`](/ember-data/release/classes/JSONAPIAdapter)
759
+ that supports the [JSON API specification](http://jsonapi.org/) and if your server
760
+ endpoint supports the use of an
761
+ ['include' query parameter](http://jsonapi.org/format/#fetching-includes),
762
+ you can use `findRecord()` or `findAll()` to automatically retrieve additional records related to
763
+ the one you request by supplying an `include` parameter in the `options` object.
764
+
765
+ For example, given a `post` model that has a `hasMany` relationship with a `comment`
766
+ model, when we retrieve a specific post we can have the server also return that post's
767
+ comments in the same request:
768
+
769
+ ```app/routes/post.js
770
+ export default class PostRoute extends Route {
771
+ model(params) {
772
+ return this.store.findRecord('post', params.post_id, { include: ['comments'] });
773
+ }
774
+ }
775
+ ```
776
+
777
+ ```app/adapters/application.js
778
+ export default class Adapter {
779
+ findRecord(store, schema, id, snapshot) {
780
+ let type = schema.modelName;
781
+
782
+ if (type === 'post')
783
+ let includes = snapshot.adapterOptions.include;
784
+
785
+ return fetch(`./posts/${postId}?include=${includes}`)
786
+ .then(response => response.json())
787
+ }
788
+ }
789
+
790
+ static create() {
791
+ return new this();
792
+ }
793
+ }
794
+ ```
795
+
796
+ In this case, the post's comments would then be available in your template as
797
+ `model.comments`.
798
+
799
+ Multiple relationships can be requested using an `include` parameter consisting of a
800
+ list of relationship names, while nested relationships can be specified
801
+ using a dot-separated sequence of relationship names. So to request both the post's
802
+ comments and the authors of those comments the request would look like this:
803
+
804
+ ```app/routes/post.js
805
+ export default class PostRoute extends Route {
806
+ model(params) {
807
+ return this.store.findRecord('post', params.post_id, { include: ['comments','comments.author'] });
808
+ }
809
+ }
810
+ ```
811
+
812
+ ### Retrieving Specific Fields by Type
813
+
814
+ If your server endpoint supports the use of a ['fields' query parameter](https://jsonapi.org/format/#fetching-sparse-fieldsets),
815
+ you can use pass those fields through to your server. At this point in time, this requires a few manual steps on your part.
816
+
817
+ 1. Implement `buildQuery` in your adapter.
818
+
819
+ ```app/adapters/application.js
820
+ buildQuery(snapshot) {
821
+ let query = super.buildQuery(...arguments);
822
+
823
+ let { fields } = snapshot.adapterOptions;
824
+
825
+ if (fields) {
826
+ query.fields = fields;
827
+ }
828
+
829
+ return query;
830
+ }
831
+ ```
832
+
833
+ 2. Then pass through the applicable fields to your `findRecord` request.
834
+
835
+ Given a `post` model with attributes body, title, publishDate and meta, you can retrieve a filtered list of attributes.
836
+
837
+ ```app/routes/post.js
838
+ export default class extends Route {
839
+ model(params) {
840
+ return this.store.findRecord('post', params.post_id, { adapterOptions: { fields: { post: 'body,title' } });
841
+ }
842
+ }
843
+ ```
844
+
845
+ Moreover, you can filter attributes on related models as well. If a `post` has a `belongsTo` relationship to a user,
846
+ just include the relationship key and attributes.
847
+
848
+ ```app/routes/post.js
849
+ export default class extends Route {
850
+ model(params) {
851
+ return this.store.findRecord('post', params.post_id, { adapterOptions: { fields: { post: 'body,title', user: 'name,email' } });
852
+ }
853
+ }
854
+ ```
855
+
856
+ @since 1.13.0
857
+ @method findRecord
858
+ @public
859
+ @param {String|object} type - either a string representing the name of the resource or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
860
+ @param {(String|Integer|Object)} id - optional object with options for the request only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved
861
+ @param {Object} [options] - if the first param is a string this will be the optional options for the request. See examples for available options.
862
+ @return {Promise} promise
863
+ */
864
+ findRecord<T>(type: TypeFromInstance<T>, id: string | number, options?: FindRecordOptions<T>): Promise<T>;
865
+ findRecord(type: string, id: string | number, options?: FindRecordOptions): Promise<unknown>;
866
+ findRecord<T>(resource: ResourceIdentifierObject<TypeFromInstance<T>>, options?: FindRecordOptions<T>): Promise<T>;
867
+ findRecord(resource: ResourceIdentifierObject, options?: FindRecordOptions): Promise<unknown>;
868
+ /**
869
+ Get the reference for the specified record.
870
+
871
+ Example
872
+
873
+ ```javascript
874
+ let userRef = store.getReference('user', '1');
875
+
876
+ // check if the user is loaded
877
+ let isLoaded = userRef.value() !== null;
878
+
879
+ // get the record of the reference (null if not yet available)
880
+ let user = userRef.value();
881
+
882
+ // get the identifier of the reference
883
+ if (userRef.remoteType() === 'id') {
884
+ let id = userRef.id();
885
+ }
886
+
887
+ // load user (via store.find)
888
+ userRef.load().then(...)
889
+
890
+ // or trigger a reload
891
+ userRef.reload().then(...)
892
+
893
+ // provide data for reference
894
+ userRef.push({ id: 1, username: '@user' }).then(function(user) {
895
+ userRef.value() === user;
896
+ });
897
+ ```
898
+
899
+ @method getReference
900
+ @public
901
+ @param {String|object} resource - modelName (string) or Identifier (object)
902
+ @param {String|Integer} id
903
+ @since 2.5.0
904
+ @return {RecordReference}
905
+ */
906
+ getReference(resource: string | ResourceIdentifierObject, id: string | number): RecordReference;
907
+ /**
908
+ Get a record by a given type and ID without triggering a fetch.
909
+
910
+ This method will synchronously return the record if it is available in the store,
911
+ otherwise it will return `null`. A record is available if it has been fetched earlier, or
912
+ pushed manually into the store.
913
+
914
+ See [findRecord](../methods/findRecord?anchor=findRecord) if you would like to request this record from the backend.
915
+
916
+ _Note: This is a synchronous method and does not return a promise._
917
+
918
+ **Example 1**
919
+
920
+ ```js
921
+ let post = store.peekRecord('post', '1');
922
+
923
+ post.id; // '1'
924
+ ```
925
+
926
+ `peekRecord` can be called with a single identifier argument instead of the combination
927
+ of `type` (modelName) and `id` as separate arguments. You may recognize this combo as
928
+ the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)
929
+
930
+ **Example 2**
931
+
932
+ ```js
933
+ let post = store.peekRecord({ type: 'post', id });
934
+ post.id; // '1'
935
+ ```
936
+
937
+ If you have previously received an lid from an Identifier for this record, you can lookup the record again using
938
+ just the lid.
939
+
940
+ **Example 3**
941
+
942
+ ```js
943
+ let post = store.peekRecord({ lid });
944
+ post.id; // '1'
945
+ ```
946
+
947
+
948
+ @since 1.13.0
949
+ @method peekRecord
950
+ @public
951
+ @param {String|object} modelName - either a string representing the modelName or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
952
+ @param {String|Integer} id - optional only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved.
953
+ @return {Model|null} record
954
+ */
955
+ peekRecord<T>(type: TypeFromInstance<T>, id: string | number): T | null;
956
+ peekRecord(type: string, id: string | number): unknown | null;
957
+ peekRecord<T>(identifier: ResourceIdentifierObject<TypeFromInstance<T>>): T | null;
958
+ peekRecord(identifier: ResourceIdentifierObject): unknown | null;
959
+ /**
960
+ This method delegates a query to the adapter. This is the one place where
961
+ adapter-level semantics are exposed to the application.
962
+
963
+ Each time this method is called a new request is made through the adapter.
964
+
965
+ Exposing queries this way seems preferable to creating an abstract query
966
+ language for all server-side queries, and then require all adapters to
967
+ implement them.
968
+
969
+ ---
970
+
971
+ If you do something like this:
972
+
973
+ ```javascript
974
+ store.query('person', { page: 1 });
975
+ ```
976
+
977
+ The request made to the server will look something like this:
978
+
979
+ ```
980
+ GET "/api/v1/person?page=1"
981
+ ```
982
+
983
+ ---
984
+
985
+ If you do something like this:
986
+
987
+ ```javascript
988
+ store.query('person', { ids: ['1', '2', '3'] });
989
+ ```
990
+
991
+ The request made to the server will look something like this:
992
+
993
+ ```
994
+ GET "/api/v1/person?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3"
995
+ decoded: "/api/v1/person?ids[]=1&ids[]=2&ids[]=3"
996
+ ```
997
+
998
+ This method returns a promise, which is resolved with a
999
+ [`Collection`](/ember-data/release/classes/Collection)
1000
+ once the server returns.
1001
+
1002
+ @since 1.13.0
1003
+ @method query
1004
+ @public
1005
+ @param {String} type the name of the resource
1006
+ @param {object} query a query to be used by the adapter
1007
+ @param {Object} options optional, may include `adapterOptions` hash which will be passed to adapter.query
1008
+ @return {Promise} promise
1009
+ */
1010
+ query<T>(type: TypeFromInstance<T>, query: LegacyResourceQuery<T>, options?: QueryOptions): Promise<Collection<T>>;
1011
+ query(type: string, query: LegacyResourceQuery, options?: QueryOptions): Promise<Collection>;
1012
+ /**
1013
+ This method makes a request for one record, where the `id` is not known
1014
+ beforehand (if the `id` is known, use [`findRecord`](../methods/findRecord?anchor=findRecord)
1015
+ instead).
1016
+
1017
+ This method can be used when it is certain that the server will return a
1018
+ single object for the primary data.
1019
+
1020
+ Each time this method is called a new request is made through the adapter.
1021
+
1022
+ Let's assume our API provides an endpoint for the currently logged in user
1023
+ via:
1024
+
1025
+ ```
1026
+ // GET /api/current_user
1027
+ {
1028
+ user: {
1029
+ id: 1234,
1030
+ username: 'admin'
1031
+ }
1032
+ }
1033
+ ```
1034
+
1035
+ Since the specific `id` of the `user` is not known beforehand, we can use
1036
+ `queryRecord` to get the user:
1037
+
1038
+ ```javascript
1039
+ store.queryRecord('user', {}).then(function(user) {
1040
+ let username = user.username;
1041
+ // do thing
1042
+ });
1043
+ ```
1044
+
1045
+ The request is made through the adapters' `queryRecord`:
1046
+
1047
+ ```app/adapters/user.js
1048
+ import Adapter from '@ember-data/adapter';
1049
+ import $ from 'jquery';
1050
+
1051
+ export default class UserAdapter extends Adapter {
1052
+ queryRecord(modelName, query) {
1053
+ return $.getJSON('/api/current_user');
1054
+ }
1055
+ }
1056
+ ```
1057
+
1058
+ Note: the primary use case for `store.queryRecord` is when a single record
1059
+ is queried and the `id` is not known beforehand. In all other cases
1060
+ `store.query` and using the first item of the array is likely the preferred
1061
+ way:
1062
+
1063
+ ```
1064
+ // GET /users?username=unique
1065
+ {
1066
+ data: [{
1067
+ id: 1234,
1068
+ type: 'user',
1069
+ attributes: {
1070
+ username: "unique"
1071
+ }
1072
+ }]
1073
+ }
1074
+ ```
1075
+
1076
+ ```javascript
1077
+ store.query('user', { username: 'unique' }).then(function(users) {
1078
+ return users.firstObject;
1079
+ }).then(function(user) {
1080
+ let id = user.id;
1081
+ });
1082
+ ```
1083
+
1084
+ This method returns a promise, which resolves with the found record.
1085
+
1086
+ If the adapter returns no data for the primary data of the payload, then
1087
+ `queryRecord` resolves with `null`:
1088
+
1089
+ ```
1090
+ // GET /users?username=unique
1091
+ {
1092
+ data: null
1093
+ }
1094
+ ```
1095
+
1096
+ ```javascript
1097
+ store.queryRecord('user', { username: 'unique' }).then(function(user) {
1098
+ // user is null
1099
+ });
1100
+ ```
1101
+
1102
+ @since 1.13.0
1103
+ @method queryRecord
1104
+ @public
1105
+ @param {string} type
1106
+ @param {object} query an opaque query to be used by the adapter
1107
+ @param {object} options optional, may include `adapterOptions` hash which will be passed to adapter.queryRecord
1108
+ @return {Promise} promise which resolves with the found record or `null`
1109
+ */
1110
+ queryRecord<T>(type: TypeFromInstance<T>, query: LegacyResourceQuery<T>, options?: QueryOptions): Promise<T | null>;
1111
+ queryRecord(type: string, query: LegacyResourceQuery, options?: QueryOptions): Promise<unknown | null>;
1112
+ /**
1113
+ `findAll` asks the adapter's `findAll` method to find the records for the
1114
+ given type, and returns a promise which will resolve with all records of
1115
+ this type present in the store, even if the adapter only returns a subset
1116
+ of them.
1117
+
1118
+ ```app/routes/authors.js
1119
+ export default class AuthorsRoute extends Route {
1120
+ model(params) {
1121
+ return this.store.findAll('author');
1122
+ }
1123
+ }
1124
+ ```
1125
+
1126
+ _When_ the returned promise resolves depends on the reload behavior,
1127
+ configured via the passed `options` hash and the result of the adapter's
1128
+ `shouldReloadAll` method.
1129
+
1130
+ ### Reloading
1131
+
1132
+ If `{ reload: true }` is passed or `adapter.shouldReloadAll` evaluates to
1133
+ `true`, then the returned promise resolves once the adapter returns data,
1134
+ regardless if there are already records in the store:
1135
+
1136
+ ```js
1137
+ store.push({
1138
+ data: {
1139
+ id: 'first',
1140
+ type: 'author'
1141
+ }
1142
+ });
1143
+
1144
+ // adapter#findAll resolves with
1145
+ // [
1146
+ // {
1147
+ // id: 'second',
1148
+ // type: 'author'
1149
+ // }
1150
+ // ]
1151
+ store.findAll('author', { reload: true }).then(function(authors) {
1152
+ authors.getEach('id'); // ['first', 'second']
1153
+ });
1154
+ ```
1155
+
1156
+ If no reload is indicated via the above mentioned ways, then the promise
1157
+ immediately resolves with all the records currently loaded in the store.
1158
+
1159
+ ### Background Reloading
1160
+
1161
+ Optionally, if `adapter.shouldBackgroundReloadAll` evaluates to `true`,
1162
+ then a background reload is started. Once this resolves, the array with
1163
+ which the promise resolves, is updated automatically so it contains all the
1164
+ records in the store:
1165
+
1166
+ ```app/adapters/application.js
1167
+ import Adapter from '@ember-data/adapter';
1168
+
1169
+ export default class ApplicationAdapter extends Adapter {
1170
+ shouldReloadAll(store, snapshotsArray) {
1171
+ return false;
1172
+ },
1173
+
1174
+ shouldBackgroundReloadAll(store, snapshotsArray) {
1175
+ return true;
1176
+ }
1177
+ });
1178
+
1179
+ // ...
1180
+
1181
+ store.push({
1182
+ data: {
1183
+ id: 'first',
1184
+ type: 'author'
1185
+ }
1186
+ });
1187
+
1188
+ let allAuthors;
1189
+ store.findAll('author').then(function(authors) {
1190
+ authors.getEach('id'); // ['first']
1191
+
1192
+ allAuthors = authors;
1193
+ });
1194
+
1195
+ // later, once adapter#findAll resolved with
1196
+ // [
1197
+ // {
1198
+ // id: 'second',
1199
+ // type: 'author'
1200
+ // }
1201
+ // ]
1202
+
1203
+ allAuthors.getEach('id'); // ['first', 'second']
1204
+ ```
1205
+
1206
+ If you would like to force or prevent background reloading, you can set a
1207
+ boolean value for `backgroundReload` in the options object for
1208
+ `findAll`.
1209
+
1210
+ ```app/routes/post/edit.js
1211
+ export default class PostEditRoute extends Route {
1212
+ model() {
1213
+ return this.store.findAll('post', { backgroundReload: false });
1214
+ }
1215
+ }
1216
+ ```
1217
+
1218
+ If you pass an object on the `adapterOptions` property of the options
1219
+ argument it will be passed to you adapter via the `snapshotRecordArray`
1220
+
1221
+ ```app/routes/posts.js
1222
+ export default class PostsRoute extends Route {
1223
+ model(params) {
1224
+ return this.store.findAll('post', {
1225
+ adapterOptions: { subscribe: false }
1226
+ });
1227
+ }
1228
+ }
1229
+ ```
1230
+
1231
+ ```app/adapters/post.js
1232
+ import MyCustomAdapter from './custom-adapter';
1233
+
1234
+ export default class UserAdapter extends MyCustomAdapter {
1235
+ findAll(store, type, sinceToken, snapshotRecordArray) {
1236
+ if (snapshotRecordArray.adapterOptions.subscribe) {
1237
+ // ...
1238
+ }
1239
+ // ...
1240
+ }
1241
+ }
1242
+ ```
1243
+
1244
+ See [peekAll](../methods/peekAll?anchor=peekAll) to get an array of current records in the
1245
+ store, without waiting until a reload is finished.
1246
+
1247
+ ### Retrieving Related Model Records
1248
+
1249
+ If you use an adapter such as Ember's default
1250
+ [`JSONAPIAdapter`](/ember-data/release/classes/JSONAPIAdapter)
1251
+ that supports the [JSON API specification](http://jsonapi.org/) and if your server
1252
+ endpoint supports the use of an
1253
+ ['include' query parameter](http://jsonapi.org/format/#fetching-includes),
1254
+ you can use `findAll()` to automatically retrieve additional records related to
1255
+ those requested by supplying an `include` parameter in the `options` object.
1256
+
1257
+ For example, given a `post` model that has a `hasMany` relationship with a `comment`
1258
+ model, when we retrieve all of the post records we can have the server also return
1259
+ all of the posts' comments in the same request:
1260
+
1261
+ ```app/routes/posts.js
1262
+ export default class PostsRoute extends Route {
1263
+ model() {
1264
+ return this.store.findAll('post', { include: ['comments'] });
1265
+ }
1266
+ }
1267
+ ```
1268
+ Multiple relationships can be requested using an `include` parameter consisting of a
1269
+ list or relationship names, while nested relationships can be specified
1270
+ using a dot-separated sequence of relationship names. So to request both the posts'
1271
+ comments and the authors of those comments the request would look like this:
1272
+
1273
+ ```app/routes/posts.js
1274
+ export default class PostsRoute extends Route {
1275
+ model() {
1276
+ return this.store.findAll('post', { include: ['comments','comments.author'] });
1277
+ }
1278
+ }
1279
+ ```
1280
+
1281
+ See [query](../methods/query?anchor=query) to only get a subset of records from the server.
1282
+
1283
+ @since 1.13.0
1284
+ @method findAll
1285
+ @public
1286
+ @param {string} type the name of the resource
1287
+ @param {object} options
1288
+ @return {Promise} promise
1289
+ */
1290
+ findAll<T>(type: TypeFromInstance<T>, options?: FindAllOptions<T>): Promise<IdentifierArray<T>>;
1291
+ findAll(type: string, options?: FindAllOptions): Promise<IdentifierArray>;
1292
+ /**
1293
+ This method returns a filtered array that contains all of the
1294
+ known records for a given type in the store.
1295
+
1296
+ Note that because it's just a filter, the result will contain any
1297
+ locally created records of the type, however, it will not make a
1298
+ request to the backend to retrieve additional records. If you
1299
+ would like to request all the records from the backend please use
1300
+ [store.findAll](../methods/findAll?anchor=findAll).
1301
+
1302
+ Also note that multiple calls to `peekAll` for a given type will always
1303
+ return the same `RecordArray`.
1304
+
1305
+ Example
1306
+
1307
+ ```javascript
1308
+ let localPosts = store.peekAll('post');
1309
+ ```
1310
+
1311
+ @since 1.13.0
1312
+ @method peekAll
1313
+ @public
1314
+ @param {string} type the name of the resource
1315
+ @return {RecordArray}
1316
+ */
1317
+ peekAll<T>(type: TypeFromInstance<T>): IdentifierArray<T>;
1318
+ peekAll(type: string): IdentifierArray;
1319
+ /**
1320
+ This method unloads all records in the store.
1321
+ It schedules unloading to happen during the next run loop.
1322
+
1323
+ Optionally you can pass a type which unload all records for a given type.
1324
+
1325
+ ```javascript
1326
+ store.unloadAll();
1327
+ store.unloadAll('post');
1328
+ ```
1329
+
1330
+ @method unloadAll
1331
+ @param {string} type the name of the resource
1332
+ @public
1333
+ */
1334
+ unloadAll<T>(type: TypeFromInstance<T>): void;
1335
+ unloadAll(type?: string): void;
1336
+ /**
1337
+ Push some data for a given type into the store.
1338
+
1339
+ This method expects normalized [JSON API](http://jsonapi.org/) document. This means you have to follow [JSON API specification](http://jsonapi.org/format/) with few minor adjustments:
1340
+ - record's `type` should always be in singular, dasherized form
1341
+ - members (properties) should be camelCased
1342
+
1343
+ [Your primary data should be wrapped inside `data` property](http://jsonapi.org/format/#document-top-level):
1344
+
1345
+ ```js
1346
+ store.push({
1347
+ data: {
1348
+ // primary data for single record of type `Person`
1349
+ id: '1',
1350
+ type: 'person',
1351
+ attributes: {
1352
+ firstName: 'Daniel',
1353
+ lastName: 'Kmak'
1354
+ }
1355
+ }
1356
+ });
1357
+ ```
1358
+
1359
+ [Demo.](http://ember-twiddle.com/fb99f18cd3b4d3e2a4c7)
1360
+
1361
+ `data` property can also hold an array (of records):
1362
+
1363
+ ```js
1364
+ store.push({
1365
+ data: [
1366
+ // an array of records
1367
+ {
1368
+ id: '1',
1369
+ type: 'person',
1370
+ attributes: {
1371
+ firstName: 'Daniel',
1372
+ lastName: 'Kmak'
1373
+ }
1374
+ },
1375
+ {
1376
+ id: '2',
1377
+ type: 'person',
1378
+ attributes: {
1379
+ firstName: 'Tom',
1380
+ lastName: 'Dale'
1381
+ }
1382
+ }
1383
+ ]
1384
+ });
1385
+ ```
1386
+
1387
+ [Demo.](http://ember-twiddle.com/69cdbeaa3702159dc355)
1388
+
1389
+ There are some typical properties for `JSONAPI` payload:
1390
+ * `id` - mandatory, unique record's key
1391
+ * `type` - mandatory string which matches `model`'s dasherized name in singular form
1392
+ * `attributes` - object which holds data for record attributes - `attr`'s declared in model
1393
+ * `relationships` - object which must contain any of the following properties under each relationships' respective key (example path is `relationships.achievements.data`):
1394
+ - [`links`](http://jsonapi.org/format/#document-links)
1395
+ - [`data`](http://jsonapi.org/format/#document-resource-object-linkage) - place for primary data
1396
+ - [`meta`](http://jsonapi.org/format/#document-meta) - object which contains meta-information about relationship
1397
+
1398
+ For this model:
1399
+
1400
+ ```app/models/person.js
1401
+ import Model, { attr, hasMany } from '@ember-data/model';
1402
+
1403
+ export default class PersonRoute extends Route {
1404
+ @attr('string') firstName;
1405
+ @attr('string') lastName;
1406
+
1407
+ @hasMany('person') children;
1408
+ }
1409
+ ```
1410
+
1411
+ To represent the children as IDs:
1412
+
1413
+ ```js
1414
+ {
1415
+ data: {
1416
+ id: '1',
1417
+ type: 'person',
1418
+ attributes: {
1419
+ firstName: 'Tom',
1420
+ lastName: 'Dale'
1421
+ },
1422
+ relationships: {
1423
+ children: {
1424
+ data: [
1425
+ {
1426
+ id: '2',
1427
+ type: 'person'
1428
+ },
1429
+ {
1430
+ id: '3',
1431
+ type: 'person'
1432
+ },
1433
+ {
1434
+ id: '4',
1435
+ type: 'person'
1436
+ }
1437
+ ]
1438
+ }
1439
+ }
1440
+ }
1441
+ }
1442
+ ```
1443
+
1444
+ [Demo.](http://ember-twiddle.com/343e1735e034091f5bde)
1445
+
1446
+ To represent the children relationship as a URL:
1447
+
1448
+ ```js
1449
+ {
1450
+ data: {
1451
+ id: '1',
1452
+ type: 'person',
1453
+ attributes: {
1454
+ firstName: 'Tom',
1455
+ lastName: 'Dale'
1456
+ },
1457
+ relationships: {
1458
+ children: {
1459
+ links: {
1460
+ related: '/people/1/children'
1461
+ }
1462
+ }
1463
+ }
1464
+ }
1465
+ }
1466
+ ```
1467
+
1468
+ If you're streaming data or implementing an adapter, make sure
1469
+ that you have converted the incoming data into this form. The
1470
+ store's [normalize](../methods/normalize?anchor=normalize) method is a convenience
1471
+ helper for converting a json payload into the form Ember Data
1472
+ expects.
1473
+
1474
+ ```js
1475
+ store.push(store.normalize('person', data));
1476
+ ```
1477
+
1478
+ This method can be used both to push in brand new
1479
+ records, as well as to update existing records.
1480
+
1481
+ @method push
1482
+ @public
1483
+ @param {Object} data
1484
+ @return the record(s) that was created or
1485
+ updated.
1486
+ */
1487
+ push(data: EmptyResourceDocument): null;
1488
+ push<T>(data: SingleResourceDocument<TypeFromInstance<T>>): T;
1489
+ push(data: SingleResourceDocument): OpaqueRecordInstance;
1490
+ push<T>(data: CollectionResourceDocument<TypeFromInstance<T>>): T[];
1491
+ push(data: CollectionResourceDocument): OpaqueRecordInstance[];
1492
+ /**
1493
+ Push some data in the form of a json-api document into the store,
1494
+ without creating materialized records.
1495
+
1496
+ @method _push
1497
+ @private
1498
+ @param {Object} jsonApiDoc
1499
+ @return {StableRecordIdentifier|Array<StableRecordIdentifier>|null} identifiers for the primary records that had data loaded
1500
+ */
1501
+ _push(jsonApiDoc: JsonApiDocument, asyncFlush?: boolean): StableExistingRecordIdentifier | StableExistingRecordIdentifier[] | null;
1502
+ /**
1503
+ * Trigger a save for a Record.
1504
+ *
1505
+ * Returns a promise resolving with the same record when the save is complete.
1506
+ *
1507
+ * @method saveRecord
1508
+ * @public
1509
+ * @param {unknown} record
1510
+ * @param options
1511
+ * @return {Promise<record>}
1512
+ */
1513
+ saveRecord<T>(record: T, options?: Record<string, unknown>): Promise<T>;
1514
+ /**
1515
+ * Instantiation hook allowing applications or addons to configure the store
1516
+ * to utilize a custom Cache implementation.
1517
+ *
1518
+ * This hook should not be called directly by consuming applications or libraries.
1519
+ * Use `Store.cache` to access the Cache instance.
1520
+ *
1521
+ * @method createCache (hook)
1522
+ * @public
1523
+ * @param storeWrapper
1524
+ * @return {Cache}
1525
+ */
1526
+ /**
1527
+ * Returns the cache instance associated to this Store, instantiates the Cache
1528
+ * if necessary via `Store.createCache`
1529
+ *
1530
+ * @property {Cache} cache
1531
+ * @public
1532
+ */
1533
+ get cache(): ReturnType<this['createCache']>;
1534
+ destroy(): void;
1535
+ static create(args?: Record<string, unknown>): Store;
1536
+ }
1537
+ }
1538
+ //# sourceMappingURL=store-service.d.ts.map