@ember-data/store 5.5.0-alpha.2 → 5.5.0-alpha.20

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