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

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