@ember-data/legacy-compat 5.4.0-alpha.32 → 5.4.0-alpha.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,547 +1,549 @@
1
- /**
2
- * @module @ember-data/experimental-preview-types
3
- */
4
- import type Store from '@ember-data/store';
5
- import type { Collection } from '@ember-data/store/-private/record-arrays/identifier-array';
6
- import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
7
- import type { RelationshipSchema } from '@warp-drive/core-types/schema';
8
- import type Snapshot from './snapshot';
9
- import type SnapshotRecordArray from './snapshot-record-array';
10
- type Group = Snapshot[];
11
- export type AdapterPayload = Record<string, unknown> | unknown[];
12
- /**
13
- * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
14
- <p>
15
- ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
16
- If starting a new app or thinking of implementing a new adapter, consider writing a
17
- <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
18
- </p>
19
- </blockquote>
20
-
21
- The following documentation describes the methods an
22
- adapter should implement with descriptions around when an
23
- application might expect these methods to be called.
24
-
25
- Methods that are not required are marked as **optional**.
26
-
27
- @class <Interface> Adapter
28
- @public
29
- */
30
- export interface MinimumAdapterInterface {
31
- /**
32
- * `adapter.findRecord` takes a request for a resource of a given `type` and `id` combination
33
- * and should return a `Promise` which fulfills with data for a single resource matching that
34
- * `type` and `id`.
35
- *
36
- * The response will be fed to the associated serializer's `normalizeResponse` method with the
37
- * `requestType` set to `findRecord`, which should return a `JSON:API` document.
38
- *
39
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
40
- * it will merge with any existing data for the record.
41
- *
42
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
43
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
44
- * processing within the adapter.
45
- *
46
- * `adapter.findRecord` is called whenever the `store` needs to load, reload, or backgroundReload
47
- * the resource data for a given `type` and `id`.
48
- *
49
- * @method findRecord
50
- * @public
51
- * @param {Store} store The store service that initiated the request being normalized
52
- * @param {ModelSchema} schema An object with methods for accessing information about
53
- * the type, attributes and relationships of the primary type associated with the request.
54
- * @param {String} id
55
- * @param {Snapshot} snapshot
56
- * @return {Promise} a promise resolving with resource data to feed to the associated serializer
57
- */
58
- findRecord(store: Store, schema: ModelSchema, id: string, snapshot: Snapshot): Promise<AdapterPayload>;
59
- /**
60
- * `adapter.findAll` takes a request for resources of a given `type` and should return
61
- * a `Promise` which fulfills with a collection of resource data matching that `type`.
62
- *
63
- * The response will be fed to the associated serializer's `normalizeResponse` method
64
- * with the `requestType` set to `findAll`, which should return a `JSON:API` document.
65
- *
66
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
67
- * it will merge with any existing records for `type`. Existing records for the `type` will not be removed.
68
- *
69
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
70
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
71
- * processing within the adapter.
72
- *
73
- * `adapter.findAll` is called whenever `store.findAll` is asked to reload or backgroundReload.
74
- * The records in the response are merged with the contents of the store. Existing records for
75
- * the `type` will not be removed.
76
- *
77
- * See also `shouldReloadAll` and `shouldBackgroundReloadAll`
78
- *
79
- * @method findAll
80
- * @public
81
- * @param {Store} store The store service that initiated the request being normalized
82
- * @param {ModelSchema} schema An object with methods for accessing information about
83
- * the type, attributes and relationships of the primary type associated with the request.
84
- * @param {null} sinceToken This parameter is no longer used and will always be null.
85
- * @param {SnapshotRecordArray} snapshotRecordArray an object containing any passed in options,
86
- * adapterOptions, and the ability to access a snapshot for each existing record of the type.
87
- * @return {Promise} a promise resolving with resource data to feed to the associated serializer
88
- */
89
- findAll(store: Store, schema: ModelSchema, sinceToken: null, snapshotRecordArray: SnapshotRecordArray): Promise<AdapterPayload>;
90
- /**
91
- * `adapter.query` takes a request for resources of a given `type` and should return
92
- * a `Promise` which fulfills with a collection of resource data matching that `type`.
93
- *
94
- * The response will be fed to the associated serializer's `normalizeResponse` method
95
- * with the `requestType` set to `query`, which should return a `JSON:API` document.
96
- *
97
- * As with `findAll`, the final result after normalization to `JSON:API` will be added to
98
- * store via `store.push` where it will merge with any existing records for `type`.
99
- *
100
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
101
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
102
- * processing within the adapter.
103
- *
104
- * `adapter.query` is called whenever `store.query` is called or a previous query result is
105
- * asked to reload.
106
- *
107
- * Existing records for the `type` will not be removed. The key difference is in the result
108
- * returned by the `store`. For `findAll` the result is all known records of the `type`,
109
- * while for `query` it will only be the records returned from `adapter.query`.
110
- *
111
- * @method query
112
- * @public
113
- * @param {Store} store The store service that initiated the request being normalized
114
- * @param {ModelSchema} schema An object with methods for accessing information about
115
- * the type, attributes and relationships of the primary type associated with the request.
116
- * @param {object} query
117
- * @param {Collection} recordArray
118
- * @param {object} options
119
- * @return {Promise} a promise resolving with resource data to feed to the associated serializer
120
- */
121
- query(store: Store, schema: ModelSchema, query: Record<string, unknown>, recordArray: Collection, options: {
122
- adapterOptions?: unknown;
123
- }): Promise<AdapterPayload>;
124
- /**
125
- * `adapter.queryRecord` takes a request for resource of a given `type` and should return
126
- * a `Promise` which fulfills with data for a single resource matching that `type`.
127
- *
128
- * The response will be fed to the associated serializer's `normalizeResponse` method
129
- * with the `requestType` set to `queryRecord`, which should return a `JSON:API` document.
130
- *
131
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
132
- * it will merge with any existing data for the returned record.
133
- *
134
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
135
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
136
- * processing within the adapter.
137
- *
138
- * @method queryRecord
139
- * @public
140
- * @param {Store} store The store service that initiated the request being normalized
141
- * @param {ModelSchema} schema An object with methods for accessing information about
142
- * the type, attributes and relationships of the primary type associated with the request.
143
- * @param query
144
- * @param options
145
- * @return {Promise} a promise resolving with resource data to feed to the associated serializer
146
- */
147
- queryRecord(store: Store, schema: ModelSchema, query: Record<string, unknown>, options: {
148
- adapterOptions?: unknown;
149
- }): Promise<AdapterPayload>;
150
- /**
151
- * `adapter.createRecord` takes a request to create a resource of a given `type` and should
152
- * return a `Promise` which fulfills with data for the newly created resource.
153
- *
154
- * The response will be fed to the associated serializer's `normalizeResponse` method
155
- * with the `requestType` set to `createRecord`, which should return a `JSON:API` document.
156
- *
157
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
158
- * it will merge with any existing data for the record.
159
- *
160
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
161
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
162
- * processing within the adapter.
163
- *
164
- * If the adapter rejects or throws an error the record will enter an error state and the attributes
165
- * that had attempted to be saved will still be considered dirty.
166
- *
167
- * ### InvalidErrors
168
- *
169
- * When rejecting a `createRecord` request due to validation issues during save (typically a 422 status code),
170
- * you may throw an `InvalidError`.
171
- *
172
- * Throwing an `InvalidError` makes per-attribute errors available for records to use in the UI as needed.
173
- * Records can also use this information to mark themselves as being in an `invalid` state.
174
- * For more reading [see the RecordData Errors RFC](https://emberjs.github.io/rfcs/0465-record-data-errors.html)
175
- *
176
- * ```js
177
- * let error = new Error(errorMessage);
178
- *
179
- * // these two properties combined
180
- * // alert EmberData to this error being for
181
- * // invalid properties on the record during
182
- * // the request
183
- * error.isAdapterError = true;
184
- * error.code = 'InvalidError';
185
- *
186
- * // A JSON:API formatted array of errors
187
- * // See https://jsonapi.org/format/#errors
188
- * error.errors = [];
189
- *
190
- * throw error;
191
- * ```
192
- *
193
- * @method createRecord
194
- * @public
195
- * @param {Store} store The store service that initiated the request being normalized
196
- * @param {ModelSchema} schema An object with methods for accessing information about
197
- * the type, attributes and relationships of the primary type associated with the request.
198
- * @param {Snapshot} snapshot
199
- * @return {Promise} a promise resolving with resource data to feed to the associated serializer
200
- */
201
- createRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
202
- /**
203
- * `adapter.updateRecord` takes a request to update a resource of a given `type` and should
204
- * return a `Promise` which fulfills with the updated data for the resource.
205
- *
206
- * The response will be fed to the associated serializer's `normalizeResponse` method
207
- * with the `requestType` set to `updateRecord`, which should return a `JSON:API` document.
208
- *
209
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
210
- * it will merge with any existing data for the record.
211
- *
212
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
213
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
214
- * processing within the adapter.
215
- *
216
- * If the adapter rejects or throws an error the record will enter an error state and the attributes
217
- * that had attempted to be saved will still be considered dirty.
218
- *
219
- * ### InvalidErrors
220
- *
221
- * When rejecting a `createRecord` request due to validation issues during save (typically a 422 status code),
222
- * you may throw an `InvalidError`.
223
- *
224
- * Throwing an `InvalidError` makes per-attribute errors available for records to use in the UI as needed.
225
- * Records can also use this information to mark themselves as being in an `invalid` state.
226
- * For more reading [see the RecordData Errors RFC](https://emberjs.github.io/rfcs/0465-record-data-errors.html)
227
- *
228
- * ```js
229
- * let error = new Error(errorMessage);
230
- *
231
- * // these two properties combined
232
- * // alert EmberData to this error being for
233
- * // invalid properties on the record during
234
- * // the request
235
- * error.isAdapterError = true;
236
- * error.code = 'InvalidError';
237
- *
238
- * // A JSON:API formatted array of errors
239
- * // See https://jsonapi.org/format/#errors
240
- * error.errors = [];
241
- *
242
- * throw error;
243
- * ```
244
- *
245
- * @method updateRecord
246
- * @public
247
- * @param {Store} store The store service that initiated the request being normalized
248
- * @param {ModelSchema} schema An object with methods for accessing information about
249
- * the type, attributes and relationships of the primary type associated with the request.
250
- * @param {Snapshot} snapshot
251
- */
252
- updateRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
253
- /**
254
- * `adapter.deleteRecord` takes a request to delete a resource of a given `type` and
255
- * should return a `Promise` which resolves when that deletion is complete.
256
- *
257
- * Usually the response will be empty, but you may include additional updates in the
258
- * response. The response will be fed to the associated serializer's `normalizeResponse` method
259
- * with the `requestType` set to `deleteRecord`, which should return a `JSON:API` document.
260
- *
261
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
262
- * it will merge with any existing data.
263
- *
264
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
265
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
266
- * processing within the adapter.
267
- *
268
- * If the adapter rejects or errors the record will need to be saved again once the reason
269
- * for the error is addressed in order to persist the deleted state.
270
- *
271
- * @method deleteRecord
272
- * @public
273
- * @param {Store} store The store service that initiated the request being normalized
274
- * @param {ModelSchema} schema An object with methods for accessing information about
275
- * the type, attributes and relationships of the primary type associated with the request.
276
- * @param {Snapshot} snapshot A Snapshot containing the record's current data
277
- * @return
278
- */
279
- deleteRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
280
- /**
281
- * `adapter.findBelongsTo` takes a request to fetch a related resource located at a
282
- * `relatedLink` and should return a `Promise` which fulfills with data for a single
283
- * resource.
284
- *
285
- * ⚠️ This method is only called if the store previously received relationship information for a resource
286
- * containing a [related link](https://jsonapi.org/format/#document-resource-object-related-resource-links).
287
- *
288
- * If the cache does not have a `link` for the relationship then `findRecord` will be used if a `type` and `id`
289
- * for the related resource is known.
290
- *
291
- * The response will be fed to the associated serializer's `normalizeResponse` method
292
- * with the `requestType` set to `findBelongsTo`, which should return a `JSON:API` document.
293
- *
294
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
295
- * it will merge with any existing data.
296
- *
297
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
298
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
299
- * processing within the adapter.
300
- *
301
- * @method findBelongsTo [OPTIONAL]
302
- * @public
303
- * @optional
304
- * @param {Store} store The store service that initiated the request being normalized
305
- * @param {Snapshot} snapshot A Snapshot containing the parent record's current data
306
- * @param {string} relatedLink The link at which the associated resource might be found
307
- * @param {RelationshipSchema} relationship
308
- * @return {Promise} a promise resolving with resource data to feed to the associated serializer
309
- */
310
- findBelongsTo?(store: Store, snapshot: Snapshot, relatedLink: string, relationship: RelationshipSchema): Promise<AdapterPayload>;
311
- /**
312
- * `adapter.findHasMany` takes a request to fetch a related resource collection located
313
- * at a `relatedLink` and should return a `Promise` which fulfills with data for that
314
- * collection.
315
- *
316
- * ⚠️ This method is only called if the store previously received relationship information for a resource
317
- * containing a [related link](https://jsonapi.org/format/#document-resource-object-related-resource-links).
318
- *
319
- * If the cache does not have a `link` for the relationship but the `type` and `id` of
320
- * related resources are known then `findRecord` will be used for each individual related
321
- * resource.
322
- *
323
- * The response will be fed to the associated serializer's `normalizeResponse` method
324
- * with the `requestType` set to `findHasMany`, which should return a `JSON:API` document.
325
- *
326
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
327
- * it will merge with any existing data.
328
- *
329
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
330
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
331
- * processing within the adapter.
332
- *
333
- * @method findhasMany [OPTIONAL]
334
- * @public
335
- * @optional
336
- * @param {Store} store The store service that initiated the request being normalized
337
- * @param {Snapshot} snapshot A Snapshot containing the parent record's current data
338
- * @param {string} relatedLink The link at which the associated resource collection might be found
339
- * @param {RelationshipSchema} relationship
340
- * @return {Promise} a promise resolving with resource data to feed to the associated serializer
341
- */
342
- findHasMany?(store: Store, snapshot: Snapshot, relatedLink: string, relationship: RelationshipSchema): Promise<AdapterPayload>;
343
- /**
344
- * ⚠️ This Method is only called if `coalesceFindRequests` is `true`. The array passed to it is determined
345
- * by the adapter's `groupRecordsForFindMany` method, and will be called once per group returned.
346
- *
347
- * `adapter.findMany` takes a request to fetch a collection of resources and should return a
348
- * `Promise` which fulfills with data for that collection.
349
- *
350
- * The response will be fed to the associated serializer's `normalizeResponse` method
351
- * with the `requestType` set to `findMany`, which should return a `JSON:API` document.
352
- *
353
- * The final result after normalization to `JSON:API` will be added to store via `store.push` where
354
- * it will merge with any existing data.
355
- *
356
- * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
357
- * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
358
- * processing within the adapter.
359
- *
360
- * See also `groupRecordsForFindMany` and `coalesceFindRequests`
361
- *
362
- * @method findMany [OPTIONAL]
363
- * @public
364
- * @optional
365
- * @param {Store} store The store service that initiated the request being normalized
366
- * @param {ModelSchema} schema An object with methods for accessing information about
367
- * the type, attributes and relationships of the primary type associated with the request.
368
- * @param {Array<string>} ids An array of the ids of the resources to fetch
369
- * @param {Array<Snapshot>} snapshots An array of snapshots of the available data for the resources to fetch
370
- * @return {Promise} a promise resolving with resource data to feed to the associated serializer
371
- */
372
- findMany?(store: Store, schema: ModelSchema, ids: string[], snapshots: Snapshot[]): Promise<AdapterPayload>;
373
- /**
374
- * This method provides the ability to generate an ID to assign to a new record whenever `store.createRecord`
375
- * is called if no `id` was provided.
376
- *
377
- * Alternatively you can pass an id into the call to `store.createRecord` directly.
378
- *
379
- * ```js
380
- * let id = generateNewId(type);
381
- * let newRecord = store.createRecord(type, { id });
382
- * ```
383
- *
384
- * @method generateIdForRecord [OPTIONAL]
385
- * @public
386
- * @optional
387
- * @param {Store} store The store service that initiated the request being normalized
388
- * @param {String} type The type (or modelName) of record being created
389
- * @param properties the properties passed as the second arg to `store.createRecord`
390
- * @return {String} a string ID that should be unique (no other models of `type` in the cache should have this `id`)
391
- */
392
- generateIdForRecord?(store: Store, type: string, properties: unknown): string;
393
- /**
394
- * If your adapter implements `findMany`, setting this to `true` will cause `findRecord`
395
- * requests triggered within the same `runloop` to be coalesced into one or more calls
396
- * to `adapter.findMany`. The number of calls made and the records contained in each call
397
- * can be tuned by your adapter's `groupRecordsForHasMany` method.
398
- *
399
- * Implementing coalescing using this flag and the associated methods does not always offer
400
- * the right level of correctness, timing control or granularity. If your application would
401
- * be better suited coalescing across multiple types, coalescing for longer than a single runloop,
402
- * or with a more custom request structure, coalescing within your application adapter may prove
403
- * more effective.
404
- *
405
- * @property coalesceFindRequests [OPTIONAL]
406
- * @public
407
- * @optional
408
- * @type {boolean} true if the requests to find individual records should be coalesced, false otherwise
409
- */
410
- coalesceFindRequests?: boolean;
411
- /**
412
- * ⚠️ This Method is only called if `coalesceFindRequests` is `true`.
413
- *
414
- * This method allows for you to split pending requests for records into multiple `findMany`
415
- * requests. It receives an array of snapshots where each snapshot represents a unique record
416
- * requested via `store.findRecord` during the most recent `runloop` that was not found in the
417
- * cache or needs to be reloaded. It should return an array of groups.
418
- *
419
- * A group is an array of snapshots meant to be fetched together by a single `findMany` request.
420
- *
421
- * By default if this method is not implemented EmberData will call `findMany` once with all
422
- * requested records as a single group when `coalesceFindRequests` is `true`.
423
- *
424
- * See also `findMany` and `coalesceFindRequests`
425
- *
426
- * @method groupRecordsForFindMany [OPTIONAL]
427
- * @public
428
- * @optional
429
- * @param {Store} store The store service that initiated the request being normalized
430
- * @param {Array<Snapshot>} snapshots An array of snapshots
431
- * @return {Array<Array<Snapshot>>} An array of Snapshot arrays
432
- */
433
- groupRecordsForFindMany?(store: Store, snapshots: Snapshot[]): Group[];
434
- /**
435
- * When a record is already available in the store and is requested again via `store.findRecord`,
436
- * and `reload` is not specified as an option in the request, this method is called to determine
437
- * whether the record should be reloaded prior to returning the result.
438
- *
439
- * If `reload` is specified as an option in the request (`true` or `false`) this method will not
440
- * be called.
441
- *
442
- * ```js
443
- * store.findRecord('user', '1', { reload: false })
444
- * ```
445
- *
446
- * The default behavior if this method is not implemented and the option is not specified is to
447
- * not reload, the same as a return of `false`.
448
- *
449
- * See also the documentation for `shouldBackgroundReloadRecord` which defaults to `true`.
450
- *
451
- * @method shouldReloadRecord [OPTIONAL]
452
- * @public
453
- * @optional
454
- * @param {Store} store The store service that initiated the request being normalized
455
- * @param {Snapshot} snapshot A Snapshot containing the record's current data
456
- * @return {boolean} true if the record should be reloaded immediately, false otherwise
457
- */
458
- shouldReloadRecord?(store: Store, snapshot: Snapshot): boolean;
459
- /**
460
- * When `store.findAll(<type>)` is called without a `reload` option, the adapter
461
- * is presented the opportunity to trigger a new request for records of that type.
462
- *
463
- * If `reload` is specified as an option in the request (`true` or `false`) this method will not
464
- * be called.
465
- *
466
- * ```js
467
- * store.findAll('user', { reload: false })
468
- * ```
469
- *
470
- * The default behavior if this method is not implemented and the option is not specified is to
471
- * not reload, the same as a return of `false`.
472
- *
473
- * Note: the Promise returned by `store.findAll` resolves to the same RecordArray instance
474
- * returned by `store.peekAll` for that type, and will include all records in the store for
475
- * the given type, including any previously existing records not returned by the reload request.
476
- *
477
- * @method shouldReloadAll [OPTIONAL]
478
- * @public
479
- * @optional
480
- * @param {Store} store The store service that initiated the request being normalized
481
- * @param {SnapshotRecordArray} snapshotArray
482
- * @return {boolean} true if the a new request for all records of the type in SnapshotRecordArray should be made immediately, false otherwise
483
- */
484
- shouldReloadAll?(store: Store, snapshotArray: SnapshotRecordArray): boolean;
485
- /**
486
- * When a record is already available in the store and is requested again via `store.findRecord`,
487
- * and the record does not need to be reloaded prior to return, this method provides the ability
488
- * to specify whether a refresh of the data for the reload should be scheduled to occur in the background.
489
- *
490
- * Users may explicitly declare a record should/should not be background reloaded by passing
491
- * `backgroundReload: true` or `backgroundReload: false` as an option to the request respectively.
492
- *
493
- * ```js
494
- * store.findRecord('user', '1', { backgroundReload: false })
495
- * ```
496
- *
497
- * If the `backgroundReload` option is not present, this method will be called to determine whether
498
- * a backgroundReload should be performed.
499
- *
500
- * The default behavior if this method is not implemented and the option was not specified is to
501
- * background reload, the same as a return of `true`.
502
- *
503
- * @method shouldBackgroundReloadRecord [OPTIONAL]
504
- * @public
505
- * @optional
506
- * @param {Store} store The store service that initiated the request being normalized
507
- * @param {Snapshot} snapshot A Snapshot containing the record's current data
508
- * @return {boolean} true if the record should be reloaded in the background, false otherwise
509
- */
510
- shouldBackgroundReloadRecord?(store: Store, snapshot: Snapshot): boolean;
511
- /**
512
- * When `store.findAll(<type>)` is called and a `reload` is not initiated, the adapter
513
- * is presented the opportunity to trigger a new non-blocking (background) request for
514
- * records of that type
515
- *
516
- * Users may explicitly declare that this background request should/should not occur by passing
517
- * `backgroundReload: true` or `backgroundReload: false` as an option to the request respectively.
518
- *
519
- * ```js
520
- * store.findAll('user', { backgroundReload: false })
521
- * ```
522
- *
523
- * The default behavior if this method is not implemented and the option is not specified is to
524
- * perform a reload, the same as a return of `true`.
525
- *
526
- * @method shouldBackgroundReloadAll [OPTIONAL]
527
- * @public
528
- * @optional
529
- * @param {Store} store The store service that initiated the request being normalized
530
- * @param {SnapshotRecordArray} snapshotArray
531
- * @return {boolean} true if the a new request for all records of the type in SnapshotRecordArray should be made in the background, false otherwise
532
- */
533
- shouldBackgroundReloadAll?(store: Store, snapshotArray: SnapshotRecordArray): boolean;
534
- /**
535
- * In some situations the adapter may need to perform cleanup when destroyed,
536
- * that cleanup can be done in `destroy`.
537
- *
538
- * If not implemented, the store does not inform the adapter of destruction.
539
- *
540
- * @method destroy [OPTIONAL]
541
- * @public
542
- * @optional
543
- */
544
- destroy?(): void;
545
- }
546
- export {};
547
- //# sourceMappingURL=minimum-adapter-interface.d.ts.map
1
+ declare module '@ember-data/legacy-compat/legacy-network-handler/minimum-adapter-interface' {
2
+ /**
3
+ * @module @ember-data/experimental-preview-types
4
+ */
5
+ import type Store from '@ember-data/store';
6
+ import type { Collection } from '@ember-data/store/-private/record-arrays/identifier-array';
7
+ import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
8
+ import type { RelationshipSchema } from '@warp-drive/core-types/schema';
9
+ import type Snapshot from '@ember-data/legacy-compat/legacy-network-handler/snapshot';
10
+ import type SnapshotRecordArray from '@ember-data/legacy-compat/legacy-network-handler/snapshot-record-array';
11
+ type Group = Snapshot[];
12
+ export type AdapterPayload = Record<string, unknown> | unknown[];
13
+ /**
14
+ * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
15
+ <p>
16
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
17
+ If starting a new app or thinking of implementing a new adapter, consider writing a
18
+ <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
19
+ </p>
20
+ </blockquote>
21
+
22
+ The following documentation describes the methods an
23
+ adapter should implement with descriptions around when an
24
+ application might expect these methods to be called.
25
+
26
+ Methods that are not required are marked as **optional**.
27
+
28
+ @class <Interface> Adapter
29
+ @public
30
+ */
31
+ export interface MinimumAdapterInterface {
32
+ /**
33
+ * `adapter.findRecord` takes a request for a resource of a given `type` and `id` combination
34
+ * and should return a `Promise` which fulfills with data for a single resource matching that
35
+ * `type` and `id`.
36
+ *
37
+ * The response will be fed to the associated serializer's `normalizeResponse` method with the
38
+ * `requestType` set to `findRecord`, which should return a `JSON:API` document.
39
+ *
40
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
41
+ * it will merge with any existing data for the record.
42
+ *
43
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
44
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
45
+ * processing within the adapter.
46
+ *
47
+ * `adapter.findRecord` is called whenever the `store` needs to load, reload, or backgroundReload
48
+ * the resource data for a given `type` and `id`.
49
+ *
50
+ * @method findRecord
51
+ * @public
52
+ * @param {Store} store The store service that initiated the request being normalized
53
+ * @param {ModelSchema} schema An object with methods for accessing information about
54
+ * the type, attributes and relationships of the primary type associated with the request.
55
+ * @param {String} id
56
+ * @param {Snapshot} snapshot
57
+ * @return {Promise} a promise resolving with resource data to feed to the associated serializer
58
+ */
59
+ findRecord(store: Store, schema: ModelSchema, id: string, snapshot: Snapshot): Promise<AdapterPayload>;
60
+ /**
61
+ * `adapter.findAll` takes a request for resources of a given `type` and should return
62
+ * a `Promise` which fulfills with a collection of resource data matching that `type`.
63
+ *
64
+ * The response will be fed to the associated serializer's `normalizeResponse` method
65
+ * with the `requestType` set to `findAll`, which should return a `JSON:API` document.
66
+ *
67
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
68
+ * it will merge with any existing records for `type`. Existing records for the `type` will not be removed.
69
+ *
70
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
71
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
72
+ * processing within the adapter.
73
+ *
74
+ * `adapter.findAll` is called whenever `store.findAll` is asked to reload or backgroundReload.
75
+ * The records in the response are merged with the contents of the store. Existing records for
76
+ * the `type` will not be removed.
77
+ *
78
+ * See also `shouldReloadAll` and `shouldBackgroundReloadAll`
79
+ *
80
+ * @method findAll
81
+ * @public
82
+ * @param {Store} store The store service that initiated the request being normalized
83
+ * @param {ModelSchema} schema An object with methods for accessing information about
84
+ * the type, attributes and relationships of the primary type associated with the request.
85
+ * @param {null} sinceToken This parameter is no longer used and will always be null.
86
+ * @param {SnapshotRecordArray} snapshotRecordArray an object containing any passed in options,
87
+ * adapterOptions, and the ability to access a snapshot for each existing record of the type.
88
+ * @return {Promise} a promise resolving with resource data to feed to the associated serializer
89
+ */
90
+ findAll(store: Store, schema: ModelSchema, sinceToken: null, snapshotRecordArray: SnapshotRecordArray): Promise<AdapterPayload>;
91
+ /**
92
+ * `adapter.query` takes a request for resources of a given `type` and should return
93
+ * a `Promise` which fulfills with a collection of resource data matching that `type`.
94
+ *
95
+ * The response will be fed to the associated serializer's `normalizeResponse` method
96
+ * with the `requestType` set to `query`, which should return a `JSON:API` document.
97
+ *
98
+ * As with `findAll`, the final result after normalization to `JSON:API` will be added to
99
+ * store via `store.push` where it will merge with any existing records for `type`.
100
+ *
101
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
102
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
103
+ * processing within the adapter.
104
+ *
105
+ * `adapter.query` is called whenever `store.query` is called or a previous query result is
106
+ * asked to reload.
107
+ *
108
+ * Existing records for the `type` will not be removed. The key difference is in the result
109
+ * returned by the `store`. For `findAll` the result is all known records of the `type`,
110
+ * while for `query` it will only be the records returned from `adapter.query`.
111
+ *
112
+ * @method query
113
+ * @public
114
+ * @param {Store} store The store service that initiated the request being normalized
115
+ * @param {ModelSchema} schema An object with methods for accessing information about
116
+ * the type, attributes and relationships of the primary type associated with the request.
117
+ * @param {object} query
118
+ * @param {Collection} recordArray
119
+ * @param {object} options
120
+ * @return {Promise} a promise resolving with resource data to feed to the associated serializer
121
+ */
122
+ query(store: Store, schema: ModelSchema, query: Record<string, unknown>, recordArray: Collection, options: {
123
+ adapterOptions?: unknown;
124
+ }): Promise<AdapterPayload>;
125
+ /**
126
+ * `adapter.queryRecord` takes a request for resource of a given `type` and should return
127
+ * a `Promise` which fulfills with data for a single resource matching that `type`.
128
+ *
129
+ * The response will be fed to the associated serializer's `normalizeResponse` method
130
+ * with the `requestType` set to `queryRecord`, which should return a `JSON:API` document.
131
+ *
132
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
133
+ * it will merge with any existing data for the returned record.
134
+ *
135
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
136
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
137
+ * processing within the adapter.
138
+ *
139
+ * @method queryRecord
140
+ * @public
141
+ * @param {Store} store The store service that initiated the request being normalized
142
+ * @param {ModelSchema} schema An object with methods for accessing information about
143
+ * the type, attributes and relationships of the primary type associated with the request.
144
+ * @param query
145
+ * @param options
146
+ * @return {Promise} a promise resolving with resource data to feed to the associated serializer
147
+ */
148
+ queryRecord(store: Store, schema: ModelSchema, query: Record<string, unknown>, options: {
149
+ adapterOptions?: unknown;
150
+ }): Promise<AdapterPayload>;
151
+ /**
152
+ * `adapter.createRecord` takes a request to create a resource of a given `type` and should
153
+ * return a `Promise` which fulfills with data for the newly created resource.
154
+ *
155
+ * The response will be fed to the associated serializer's `normalizeResponse` method
156
+ * with the `requestType` set to `createRecord`, which should return a `JSON:API` document.
157
+ *
158
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
159
+ * it will merge with any existing data for the record.
160
+ *
161
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
162
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
163
+ * processing within the adapter.
164
+ *
165
+ * If the adapter rejects or throws an error the record will enter an error state and the attributes
166
+ * that had attempted to be saved will still be considered dirty.
167
+ *
168
+ * ### InvalidErrors
169
+ *
170
+ * When rejecting a `createRecord` request due to validation issues during save (typically a 422 status code),
171
+ * you may throw an `InvalidError`.
172
+ *
173
+ * Throwing an `InvalidError` makes per-attribute errors available for records to use in the UI as needed.
174
+ * Records can also use this information to mark themselves as being in an `invalid` state.
175
+ * For more reading [see the RecordData Errors RFC](https://emberjs.github.io/rfcs/0465-record-data-errors.html)
176
+ *
177
+ * ```js
178
+ * let error = new Error(errorMessage);
179
+ *
180
+ * // these two properties combined
181
+ * // alert EmberData to this error being for
182
+ * // invalid properties on the record during
183
+ * // the request
184
+ * error.isAdapterError = true;
185
+ * error.code = 'InvalidError';
186
+ *
187
+ * // A JSON:API formatted array of errors
188
+ * // See https://jsonapi.org/format/#errors
189
+ * error.errors = [];
190
+ *
191
+ * throw error;
192
+ * ```
193
+ *
194
+ * @method createRecord
195
+ * @public
196
+ * @param {Store} store The store service that initiated the request being normalized
197
+ * @param {ModelSchema} schema An object with methods for accessing information about
198
+ * the type, attributes and relationships of the primary type associated with the request.
199
+ * @param {Snapshot} snapshot
200
+ * @return {Promise} a promise resolving with resource data to feed to the associated serializer
201
+ */
202
+ createRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
203
+ /**
204
+ * `adapter.updateRecord` takes a request to update a resource of a given `type` and should
205
+ * return a `Promise` which fulfills with the updated data for the resource.
206
+ *
207
+ * The response will be fed to the associated serializer's `normalizeResponse` method
208
+ * with the `requestType` set to `updateRecord`, which should return a `JSON:API` document.
209
+ *
210
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
211
+ * it will merge with any existing data for the record.
212
+ *
213
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
214
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
215
+ * processing within the adapter.
216
+ *
217
+ * If the adapter rejects or throws an error the record will enter an error state and the attributes
218
+ * that had attempted to be saved will still be considered dirty.
219
+ *
220
+ * ### InvalidErrors
221
+ *
222
+ * When rejecting a `createRecord` request due to validation issues during save (typically a 422 status code),
223
+ * you may throw an `InvalidError`.
224
+ *
225
+ * Throwing an `InvalidError` makes per-attribute errors available for records to use in the UI as needed.
226
+ * Records can also use this information to mark themselves as being in an `invalid` state.
227
+ * For more reading [see the RecordData Errors RFC](https://emberjs.github.io/rfcs/0465-record-data-errors.html)
228
+ *
229
+ * ```js
230
+ * let error = new Error(errorMessage);
231
+ *
232
+ * // these two properties combined
233
+ * // alert EmberData to this error being for
234
+ * // invalid properties on the record during
235
+ * // the request
236
+ * error.isAdapterError = true;
237
+ * error.code = 'InvalidError';
238
+ *
239
+ * // A JSON:API formatted array of errors
240
+ * // See https://jsonapi.org/format/#errors
241
+ * error.errors = [];
242
+ *
243
+ * throw error;
244
+ * ```
245
+ *
246
+ * @method updateRecord
247
+ * @public
248
+ * @param {Store} store The store service that initiated the request being normalized
249
+ * @param {ModelSchema} schema An object with methods for accessing information about
250
+ * the type, attributes and relationships of the primary type associated with the request.
251
+ * @param {Snapshot} snapshot
252
+ */
253
+ updateRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
254
+ /**
255
+ * `adapter.deleteRecord` takes a request to delete a resource of a given `type` and
256
+ * should return a `Promise` which resolves when that deletion is complete.
257
+ *
258
+ * Usually the response will be empty, but you may include additional updates in the
259
+ * response. The response will be fed to the associated serializer's `normalizeResponse` method
260
+ * with the `requestType` set to `deleteRecord`, which should return a `JSON:API` document.
261
+ *
262
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
263
+ * it will merge with any existing data.
264
+ *
265
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
266
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
267
+ * processing within the adapter.
268
+ *
269
+ * If the adapter rejects or errors the record will need to be saved again once the reason
270
+ * for the error is addressed in order to persist the deleted state.
271
+ *
272
+ * @method deleteRecord
273
+ * @public
274
+ * @param {Store} store The store service that initiated the request being normalized
275
+ * @param {ModelSchema} schema An object with methods for accessing information about
276
+ * the type, attributes and relationships of the primary type associated with the request.
277
+ * @param {Snapshot} snapshot A Snapshot containing the record's current data
278
+ * @return
279
+ */
280
+ deleteRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
281
+ /**
282
+ * `adapter.findBelongsTo` takes a request to fetch a related resource located at a
283
+ * `relatedLink` and should return a `Promise` which fulfills with data for a single
284
+ * resource.
285
+ *
286
+ * ⚠️ This method is only called if the store previously received relationship information for a resource
287
+ * containing a [related link](https://jsonapi.org/format/#document-resource-object-related-resource-links).
288
+ *
289
+ * If the cache does not have a `link` for the relationship then `findRecord` will be used if a `type` and `id`
290
+ * for the related resource is known.
291
+ *
292
+ * The response will be fed to the associated serializer's `normalizeResponse` method
293
+ * with the `requestType` set to `findBelongsTo`, which should return a `JSON:API` document.
294
+ *
295
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
296
+ * it will merge with any existing data.
297
+ *
298
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
299
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
300
+ * processing within the adapter.
301
+ *
302
+ * @method findBelongsTo [OPTIONAL]
303
+ * @public
304
+ * @optional
305
+ * @param {Store} store The store service that initiated the request being normalized
306
+ * @param {Snapshot} snapshot A Snapshot containing the parent record's current data
307
+ * @param {string} relatedLink The link at which the associated resource might be found
308
+ * @param {RelationshipSchema} relationship
309
+ * @return {Promise} a promise resolving with resource data to feed to the associated serializer
310
+ */
311
+ findBelongsTo?(store: Store, snapshot: Snapshot, relatedLink: string, relationship: RelationshipSchema): Promise<AdapterPayload>;
312
+ /**
313
+ * `adapter.findHasMany` takes a request to fetch a related resource collection located
314
+ * at a `relatedLink` and should return a `Promise` which fulfills with data for that
315
+ * collection.
316
+ *
317
+ * ⚠️ This method is only called if the store previously received relationship information for a resource
318
+ * containing a [related link](https://jsonapi.org/format/#document-resource-object-related-resource-links).
319
+ *
320
+ * If the cache does not have a `link` for the relationship but the `type` and `id` of
321
+ * related resources are known then `findRecord` will be used for each individual related
322
+ * resource.
323
+ *
324
+ * The response will be fed to the associated serializer's `normalizeResponse` method
325
+ * with the `requestType` set to `findHasMany`, which should return a `JSON:API` document.
326
+ *
327
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
328
+ * it will merge with any existing data.
329
+ *
330
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
331
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
332
+ * processing within the adapter.
333
+ *
334
+ * @method findhasMany [OPTIONAL]
335
+ * @public
336
+ * @optional
337
+ * @param {Store} store The store service that initiated the request being normalized
338
+ * @param {Snapshot} snapshot A Snapshot containing the parent record's current data
339
+ * @param {string} relatedLink The link at which the associated resource collection might be found
340
+ * @param {RelationshipSchema} relationship
341
+ * @return {Promise} a promise resolving with resource data to feed to the associated serializer
342
+ */
343
+ findHasMany?(store: Store, snapshot: Snapshot, relatedLink: string, relationship: RelationshipSchema): Promise<AdapterPayload>;
344
+ /**
345
+ * ⚠️ This Method is only called if `coalesceFindRequests` is `true`. The array passed to it is determined
346
+ * by the adapter's `groupRecordsForFindMany` method, and will be called once per group returned.
347
+ *
348
+ * `adapter.findMany` takes a request to fetch a collection of resources and should return a
349
+ * `Promise` which fulfills with data for that collection.
350
+ *
351
+ * The response will be fed to the associated serializer's `normalizeResponse` method
352
+ * with the `requestType` set to `findMany`, which should return a `JSON:API` document.
353
+ *
354
+ * The final result after normalization to `JSON:API` will be added to store via `store.push` where
355
+ * it will merge with any existing data.
356
+ *
357
+ * ⚠️ If the adapter's response resolves to a false-y value, the associated `serializer.normalizeResponse`
358
+ * call will NOT be made. In this scenario you may need to do at least a minimum amount of response
359
+ * processing within the adapter.
360
+ *
361
+ * See also `groupRecordsForFindMany` and `coalesceFindRequests`
362
+ *
363
+ * @method findMany [OPTIONAL]
364
+ * @public
365
+ * @optional
366
+ * @param {Store} store The store service that initiated the request being normalized
367
+ * @param {ModelSchema} schema An object with methods for accessing information about
368
+ * the type, attributes and relationships of the primary type associated with the request.
369
+ * @param {Array<string>} ids An array of the ids of the resources to fetch
370
+ * @param {Array<Snapshot>} snapshots An array of snapshots of the available data for the resources to fetch
371
+ * @return {Promise} a promise resolving with resource data to feed to the associated serializer
372
+ */
373
+ findMany?(store: Store, schema: ModelSchema, ids: string[], snapshots: Snapshot[]): Promise<AdapterPayload>;
374
+ /**
375
+ * This method provides the ability to generate an ID to assign to a new record whenever `store.createRecord`
376
+ * is called if no `id` was provided.
377
+ *
378
+ * Alternatively you can pass an id into the call to `store.createRecord` directly.
379
+ *
380
+ * ```js
381
+ * let id = generateNewId(type);
382
+ * let newRecord = store.createRecord(type, { id });
383
+ * ```
384
+ *
385
+ * @method generateIdForRecord [OPTIONAL]
386
+ * @public
387
+ * @optional
388
+ * @param {Store} store The store service that initiated the request being normalized
389
+ * @param {String} type The type (or modelName) of record being created
390
+ * @param properties the properties passed as the second arg to `store.createRecord`
391
+ * @return {String} a string ID that should be unique (no other models of `type` in the cache should have this `id`)
392
+ */
393
+ generateIdForRecord?(store: Store, type: string, properties: unknown): string;
394
+ /**
395
+ * If your adapter implements `findMany`, setting this to `true` will cause `findRecord`
396
+ * requests triggered within the same `runloop` to be coalesced into one or more calls
397
+ * to `adapter.findMany`. The number of calls made and the records contained in each call
398
+ * can be tuned by your adapter's `groupRecordsForHasMany` method.
399
+ *
400
+ * Implementing coalescing using this flag and the associated methods does not always offer
401
+ * the right level of correctness, timing control or granularity. If your application would
402
+ * be better suited coalescing across multiple types, coalescing for longer than a single runloop,
403
+ * or with a more custom request structure, coalescing within your application adapter may prove
404
+ * more effective.
405
+ *
406
+ * @property coalesceFindRequests [OPTIONAL]
407
+ * @public
408
+ * @optional
409
+ * @type {boolean} true if the requests to find individual records should be coalesced, false otherwise
410
+ */
411
+ coalesceFindRequests?: boolean;
412
+ /**
413
+ * ⚠️ This Method is only called if `coalesceFindRequests` is `true`.
414
+ *
415
+ * This method allows for you to split pending requests for records into multiple `findMany`
416
+ * requests. It receives an array of snapshots where each snapshot represents a unique record
417
+ * requested via `store.findRecord` during the most recent `runloop` that was not found in the
418
+ * cache or needs to be reloaded. It should return an array of groups.
419
+ *
420
+ * A group is an array of snapshots meant to be fetched together by a single `findMany` request.
421
+ *
422
+ * By default if this method is not implemented EmberData will call `findMany` once with all
423
+ * requested records as a single group when `coalesceFindRequests` is `true`.
424
+ *
425
+ * See also `findMany` and `coalesceFindRequests`
426
+ *
427
+ * @method groupRecordsForFindMany [OPTIONAL]
428
+ * @public
429
+ * @optional
430
+ * @param {Store} store The store service that initiated the request being normalized
431
+ * @param {Array<Snapshot>} snapshots An array of snapshots
432
+ * @return {Array<Array<Snapshot>>} An array of Snapshot arrays
433
+ */
434
+ groupRecordsForFindMany?(store: Store, snapshots: Snapshot[]): Group[];
435
+ /**
436
+ * When a record is already available in the store and is requested again via `store.findRecord`,
437
+ * and `reload` is not specified as an option in the request, this method is called to determine
438
+ * whether the record should be reloaded prior to returning the result.
439
+ *
440
+ * If `reload` is specified as an option in the request (`true` or `false`) this method will not
441
+ * be called.
442
+ *
443
+ * ```js
444
+ * store.findRecord('user', '1', { reload: false })
445
+ * ```
446
+ *
447
+ * The default behavior if this method is not implemented and the option is not specified is to
448
+ * not reload, the same as a return of `false`.
449
+ *
450
+ * See also the documentation for `shouldBackgroundReloadRecord` which defaults to `true`.
451
+ *
452
+ * @method shouldReloadRecord [OPTIONAL]
453
+ * @public
454
+ * @optional
455
+ * @param {Store} store The store service that initiated the request being normalized
456
+ * @param {Snapshot} snapshot A Snapshot containing the record's current data
457
+ * @return {boolean} true if the record should be reloaded immediately, false otherwise
458
+ */
459
+ shouldReloadRecord?(store: Store, snapshot: Snapshot): boolean;
460
+ /**
461
+ * When `store.findAll(<type>)` is called without a `reload` option, the adapter
462
+ * is presented the opportunity to trigger a new request for records of that type.
463
+ *
464
+ * If `reload` is specified as an option in the request (`true` or `false`) this method will not
465
+ * be called.
466
+ *
467
+ * ```js
468
+ * store.findAll('user', { reload: false })
469
+ * ```
470
+ *
471
+ * The default behavior if this method is not implemented and the option is not specified is to
472
+ * not reload, the same as a return of `false`.
473
+ *
474
+ * Note: the Promise returned by `store.findAll` resolves to the same RecordArray instance
475
+ * returned by `store.peekAll` for that type, and will include all records in the store for
476
+ * the given type, including any previously existing records not returned by the reload request.
477
+ *
478
+ * @method shouldReloadAll [OPTIONAL]
479
+ * @public
480
+ * @optional
481
+ * @param {Store} store The store service that initiated the request being normalized
482
+ * @param {SnapshotRecordArray} snapshotArray
483
+ * @return {boolean} true if the a new request for all records of the type in SnapshotRecordArray should be made immediately, false otherwise
484
+ */
485
+ shouldReloadAll?(store: Store, snapshotArray: SnapshotRecordArray): boolean;
486
+ /**
487
+ * When a record is already available in the store and is requested again via `store.findRecord`,
488
+ * and the record does not need to be reloaded prior to return, this method provides the ability
489
+ * to specify whether a refresh of the data for the reload should be scheduled to occur in the background.
490
+ *
491
+ * Users may explicitly declare a record should/should not be background reloaded by passing
492
+ * `backgroundReload: true` or `backgroundReload: false` as an option to the request respectively.
493
+ *
494
+ * ```js
495
+ * store.findRecord('user', '1', { backgroundReload: false })
496
+ * ```
497
+ *
498
+ * If the `backgroundReload` option is not present, this method will be called to determine whether
499
+ * a backgroundReload should be performed.
500
+ *
501
+ * The default behavior if this method is not implemented and the option was not specified is to
502
+ * background reload, the same as a return of `true`.
503
+ *
504
+ * @method shouldBackgroundReloadRecord [OPTIONAL]
505
+ * @public
506
+ * @optional
507
+ * @param {Store} store The store service that initiated the request being normalized
508
+ * @param {Snapshot} snapshot A Snapshot containing the record's current data
509
+ * @return {boolean} true if the record should be reloaded in the background, false otherwise
510
+ */
511
+ shouldBackgroundReloadRecord?(store: Store, snapshot: Snapshot): boolean;
512
+ /**
513
+ * When `store.findAll(<type>)` is called and a `reload` is not initiated, the adapter
514
+ * is presented the opportunity to trigger a new non-blocking (background) request for
515
+ * records of that type
516
+ *
517
+ * Users may explicitly declare that this background request should/should not occur by passing
518
+ * `backgroundReload: true` or `backgroundReload: false` as an option to the request respectively.
519
+ *
520
+ * ```js
521
+ * store.findAll('user', { backgroundReload: false })
522
+ * ```
523
+ *
524
+ * The default behavior if this method is not implemented and the option is not specified is to
525
+ * perform a reload, the same as a return of `true`.
526
+ *
527
+ * @method shouldBackgroundReloadAll [OPTIONAL]
528
+ * @public
529
+ * @optional
530
+ * @param {Store} store The store service that initiated the request being normalized
531
+ * @param {SnapshotRecordArray} snapshotArray
532
+ * @return {boolean} true if the a new request for all records of the type in SnapshotRecordArray should be made in the background, false otherwise
533
+ */
534
+ shouldBackgroundReloadAll?(store: Store, snapshotArray: SnapshotRecordArray): boolean;
535
+ /**
536
+ * In some situations the adapter may need to perform cleanup when destroyed,
537
+ * that cleanup can be done in `destroy`.
538
+ *
539
+ * If not implemented, the store does not inform the adapter of destruction.
540
+ *
541
+ * @method destroy [OPTIONAL]
542
+ * @public
543
+ * @optional
544
+ */
545
+ destroy?(): void;
546
+ }
547
+ export {};
548
+ //# sourceMappingURL=minimum-adapter-interface.d.ts.map
549
+ }