@ember-data/store 5.4.0-beta.3 → 5.4.0-beta.5

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