@ember-data/store 5.4.0-alpha.15 → 5.4.0-alpha.151

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