@ember-data-types/store 4.13.0-alpha.1

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