@warp-drive/core 5.6.0-beta.1 → 5.6.0-beta.3
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.
- package/declarations/graph/-private/-diff.d.ts +7 -20
- package/declarations/graph/-private/-edge-definition.d.ts +3 -12
- package/declarations/graph/-private/-state.d.ts +0 -87
- package/declarations/graph/-private/-utils.d.ts +5 -11
- package/declarations/graph/-private/coerce-id.d.ts +0 -6
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +2 -14
- package/declarations/graph/-private/edges/collection.d.ts +10 -10
- package/declarations/graph/-private/edges/implicit.d.ts +5 -5
- package/declarations/graph/-private/edges/resource.d.ts +6 -7
- package/declarations/graph/-private/graph.d.ts +17 -51
- package/declarations/graph/-private/normalize-link.d.ts +0 -6
- package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -59
- package/declarations/graph/-private/operations/update-relationship.d.ts +3 -7
- package/declarations/index.d.ts +1 -1
- package/declarations/reactive/-private/default-mode.d.ts +73 -0
- package/declarations/reactive/-private/document.d.ts +11 -27
- package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +7 -11
- package/declarations/reactive/-private/fields/managed-object.d.ts +7 -11
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
- package/declarations/reactive/-private/hooks.d.ts +2 -2
- package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
- package/declarations/reactive/-private/record.d.ts +44 -34
- package/declarations/reactive/-private/schema.d.ts +50 -68
- package/declarations/reactive/-private/symbols.d.ts +2 -33
- package/declarations/reactive/-private.d.ts +1 -1
- package/declarations/reactive.d.ts +278 -1
- package/declarations/request/-private/context.d.ts +3 -5
- package/declarations/request/-private/fetch.d.ts +2 -0
- package/declarations/request/-private/manager.d.ts +24 -28
- package/declarations/request/-private/types.d.ts +22 -24
- package/declarations/request/-private/utils.d.ts +44 -2
- package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
- package/declarations/store/-private/cache-handler/types.d.ts +10 -10
- package/declarations/store/-private/cache-handler/utils.d.ts +4 -5
- package/declarations/store/-private/caches/instance-cache.d.ts +22 -28
- package/declarations/store/-private/debug/utils.d.ts +1 -0
- package/declarations/store/-private/default-cache-policy.d.ts +25 -40
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
- package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +35 -53
- package/declarations/store/-private/managers/cache-manager.d.ts +46 -111
- package/declarations/store/-private/managers/notification-manager.d.ts +30 -45
- package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
- package/declarations/store/-private/network/request-cache.d.ts +21 -25
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +132 -37
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -135
- package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
- package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
- package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
- package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
- package/declarations/store/-private/record-arrays/resource-array.d.ts +67 -0
- package/declarations/store/-private/store-service.d.ts +167 -877
- package/declarations/store/-private/utils/coerce-id.d.ts +0 -6
- package/declarations/store/-private.d.ts +13 -14
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
- package/declarations/store/-types/q/identifier.d.ts +9 -6
- package/declarations/store/-types/q/record-instance.d.ts +0 -1
- package/declarations/store/-types/q/schema-service.d.ts +64 -40
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +223 -0
- package/declarations/store/deprecated/store.d.ts +783 -0
- package/declarations/types/-private.d.ts +1 -1
- package/declarations/types/cache/aliases.d.ts +0 -11
- package/declarations/types/cache/change.d.ts +2 -2
- package/declarations/types/cache/mutations.d.ts +13 -37
- package/declarations/types/cache/operations.d.ts +115 -32
- package/declarations/types/cache/relationship.d.ts +4 -7
- package/declarations/types/cache.d.ts +51 -127
- package/declarations/types/graph.d.ts +12 -12
- package/declarations/types/identifier.d.ts +52 -78
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +66 -42
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +391 -14
- package/declarations/types/spec/document.d.ts +6 -10
- package/declarations/types/spec/json-api-raw.d.ts +6 -9
- package/declarations/types.d.ts +1 -1
- package/declarations/utils/string.d.ts +2 -3
- package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
- package/dist/configure.js +1 -1
- package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
- package/dist/graph/-private.js +137 -144
- package/dist/index.js +25 -14
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +337 -1422
- package/dist/{request-state-CjLph1LP.js → request-state-C955e0AL.js} +8352 -5912
- package/dist/request.js +1 -1
- package/dist/store/-private.js +2 -3
- package/dist/store.js +32 -44
- package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
- package/dist/types/-private.js +1 -1
- package/dist/types/identifier.js +19 -45
- package/dist/types/request.js +45 -3
- package/dist/types/schema/fields.js +23 -2
- package/dist/utils/string.js +2 -2
- package/package.json +11 -11
- package/declarations/reactive/-private/fields/compute.d.ts +0 -43
- package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
- package/declarations/store/-private/legacy-model-support/record-reference.d.ts +0 -159
- package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
- package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
- package/declarations/store/-types/q/ds-model.d.ts +0 -21
- package/dist/handler-C2T-IyJK.js +0 -339
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
import type { Graph } from "../../graph/-private.js";
|
|
2
2
|
import type { Future } from "../../request.js";
|
|
3
|
-
import type { RequestManager } from "../../request/-private/manager.js";
|
|
3
|
+
import type { PrivateRequestManager, RequestManager } from "../../request/-private/manager.js";
|
|
4
4
|
import type { Cache } from "../../types/cache.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { PersistedResourceKey, ResourceKey } from "../../types/identifier.js";
|
|
6
6
|
import type { TypedRecordInstance, TypeFromInstance } from "../../types/record.js";
|
|
7
7
|
import type { CollectionResourceDocument, EmptyResourceDocument, JsonApiDocument, ResourceIdentifierObject, SingleResourceDocument } from "../../types/spec/json-api-raw.js";
|
|
8
8
|
import type { Type } from "../../types/symbols.js";
|
|
9
9
|
import type { CacheCapabilitiesManager } from "../-types/q/cache-capabilities-manager.js";
|
|
10
|
-
import type { ModelSchema } from "../-types/q/ds-model.js";
|
|
11
10
|
import type { OpaqueRecordInstance } from "../-types/q/record-instance.js";
|
|
12
11
|
import type { SchemaService } from "../-types/q/schema-service.js";
|
|
13
|
-
import type { FindAllOptions, FindRecordOptions, LegacyResourceQuery, QueryOptions } from "../-types/q/store.js";
|
|
14
12
|
import type { StoreRequestInput } from "./cache-handler/handler.js";
|
|
15
13
|
import type { CachePolicy } from "./cache-handler/types.js";
|
|
16
|
-
import { IdentifierCache } from "./caches/identifier-cache.js";
|
|
17
14
|
import { InstanceCache, storeFor } from "./caches/instance-cache.js";
|
|
18
|
-
import type
|
|
15
|
+
import type { PrivateCacheKeyManager } from "./managers/cache-key-manager.js";
|
|
16
|
+
import { CacheKeyManager } from "./managers/cache-key-manager.js";
|
|
17
|
+
import type { PrivateNotificationManager } from "./managers/notification-manager.js";
|
|
19
18
|
import NotificationManager from "./managers/notification-manager.js";
|
|
20
|
-
import {
|
|
19
|
+
import type { PrivateRecordArrayManager } from "./managers/record-array-manager.js";
|
|
20
|
+
import type { PrivateRequestStateService } from "./network/request-cache.js";
|
|
21
21
|
import { RequestStateService } from "./network/request-cache.js";
|
|
22
|
-
import type {
|
|
22
|
+
import type { LegacyLiveArray } from "./record-arrays/legacy-live-array.js";
|
|
23
23
|
export { storeFor };
|
|
24
|
-
// We inline this list of methods to avoid importing EmberObject
|
|
25
24
|
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
25
|
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
26
|
type DownlevelArrays<T> = T extends Array<infer U> ? U[] : T;
|
|
28
27
|
type AwaitedKeys<T> = { [K in keyof T & string] : DownlevelArrays<Awaited<T[K]>> };
|
|
29
|
-
// `AwaitedKeys` is needed here to resolve any promise types like `PromiseBelongsTo`.
|
|
30
28
|
type FilteredKeys<T> = AwaitedKeys<Omit<T, typeof Type | EmberObjectKey | DSModelKeys | "constructor">>;
|
|
31
29
|
type MaybeHasId = {
|
|
32
30
|
id?: string | null;
|
|
@@ -48,12 +46,22 @@ type MaybeHasId = {
|
|
|
48
46
|
*
|
|
49
47
|
*/
|
|
50
48
|
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>;
|
|
51
|
-
|
|
49
|
+
export interface CreateContext {
|
|
50
|
+
lid?: string;
|
|
51
|
+
}
|
|
52
52
|
type ConstructorFunction = new (...args: any[]) => any;
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
54
53
|
declare const EmptyClass: ConstructorFunction;
|
|
55
54
|
declare const BaseClass: typeof EmptyClass;
|
|
56
55
|
export interface Store {
|
|
56
|
+
/**
|
|
57
|
+
* Instantiation hook allowing applications or addons to configure the store
|
|
58
|
+
* to utilize a custom Cache implementation.
|
|
59
|
+
*
|
|
60
|
+
* This hook should not be called directly by consuming applications or libraries.
|
|
61
|
+
* Use `Store.cache` to access the Cache instance.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
57
65
|
createCache(capabilities: CacheCapabilitiesManager): Cache;
|
|
58
66
|
/**
|
|
59
67
|
* A hook which an app or addon may implement. Called when
|
|
@@ -69,8 +77,7 @@ export interface Store {
|
|
|
69
77
|
* @return A record instance
|
|
70
78
|
* @public
|
|
71
79
|
*/
|
|
72
|
-
|
|
73
|
-
instantiateRecord<T>(identifier: StableRecordIdentifier, createRecordArgs: {
|
|
80
|
+
instantiateRecord<T>(identifier: ResourceKey, createRecordArgs: {
|
|
74
81
|
[key: string]: unknown;
|
|
75
82
|
}): OpaqueRecordInstance;
|
|
76
83
|
/**
|
|
@@ -138,7 +145,6 @@ export interface Store {
|
|
|
138
145
|
* be sourced from directly registered schemas, then will fallback
|
|
139
146
|
* to sourcing a schema from available models if no schema is found.
|
|
140
147
|
*
|
|
141
|
-
* @return {SchemaService}
|
|
142
148
|
* @public
|
|
143
149
|
*/
|
|
144
150
|
createSchemaService(): SchemaService;
|
|
@@ -184,11 +190,11 @@ export interface Store {
|
|
|
184
190
|
* return this._schema.hasResource(resource);
|
|
185
191
|
* }
|
|
186
192
|
*
|
|
187
|
-
* attributesDefinitionFor(identifier:
|
|
193
|
+
* attributesDefinitionFor(identifier: ResourceKey | { type: string }): AttributesSchema {
|
|
188
194
|
* return this._schema.attributesDefinitionFor(identifier);
|
|
189
195
|
* }
|
|
190
196
|
*
|
|
191
|
-
* relationshipsDefinitionFor(identifier:
|
|
197
|
+
* relationshipsDefinitionFor(identifier: ResourceKey | { type: string }): RelationshipsSchema {
|
|
192
198
|
* const schema = AbstractSchemas.get(identifier.type);
|
|
193
199
|
* return schema || this._schema.relationshipsDefinitionFor(identifier);
|
|
194
200
|
* }
|
|
@@ -238,11 +244,11 @@ export interface Store {
|
|
|
238
244
|
* return this._schema.hasResource(resource);
|
|
239
245
|
* }
|
|
240
246
|
*
|
|
241
|
-
* attributesDefinitionFor(identifier:
|
|
247
|
+
* attributesDefinitionFor(identifier: ResourceKey | { type: string }): AttributesSchema {
|
|
242
248
|
* return this._schema.attributesDefinitionFor(identifier);
|
|
243
249
|
* }
|
|
244
250
|
*
|
|
245
|
-
* relationshipsDefinitionFor(identifier:
|
|
251
|
+
* relationshipsDefinitionFor(identifier: ResourceKey | { type: string }): RelationshipsSchema {
|
|
246
252
|
* const schema = AbstractSchemas.get(identifier.type);
|
|
247
253
|
* return schema || this._schema.relationshipsDefinitionFor(identifier);
|
|
248
254
|
* }
|
|
@@ -283,8 +289,6 @@ export interface Store {
|
|
|
283
289
|
* @hideconstructor
|
|
284
290
|
*/
|
|
285
291
|
export declare class Store extends BaseClass {
|
|
286
|
-
/** @internal */
|
|
287
|
-
readonly recordArrayManager: RecordArrayManager;
|
|
288
292
|
/**
|
|
289
293
|
* Provides access to the NotificationManager associated
|
|
290
294
|
* with this Store instance.
|
|
@@ -305,18 +309,17 @@ export declare class Store extends BaseClass {
|
|
|
305
309
|
* @public
|
|
306
310
|
*/
|
|
307
311
|
get schema(): ReturnType<this["createSchemaService"]>;
|
|
308
|
-
/** @internal */
|
|
309
|
-
_schema: SchemaService;
|
|
310
312
|
/**
|
|
311
|
-
* Provides access to the
|
|
313
|
+
* Provides access to the CacheKeyManager
|
|
312
314
|
* for this store.
|
|
313
315
|
*
|
|
314
|
-
* The
|
|
315
|
-
* retrieve a stable unique
|
|
316
|
+
* The CacheKeyManager can be used to generate or
|
|
317
|
+
* retrieve a stable unique CacheKey for any resource
|
|
318
|
+
* or request.
|
|
316
319
|
*
|
|
317
320
|
* @public
|
|
318
321
|
*/
|
|
319
|
-
readonly
|
|
322
|
+
readonly cacheKeyManager: CacheKeyManager;
|
|
320
323
|
/**
|
|
321
324
|
* Provides access to the requestManager instance associated
|
|
322
325
|
* with this Store instance.
|
|
@@ -347,7 +350,7 @@ export declare class Store extends BaseClass {
|
|
|
347
350
|
*
|
|
348
351
|
* Note, when defined, these methods will only be invoked if a
|
|
349
352
|
* cache key exists for the request, either because the request
|
|
350
|
-
* contains `cacheOptions.key` or because the [
|
|
353
|
+
* contains `cacheOptions.key` or because the [CacheKeyManager](/ember-data/release/classes/CacheKeyManager)
|
|
351
354
|
* was able to generate a key for the request using the configured
|
|
352
355
|
* [generation method](/ember-data/release/functions/@ember-data%2Fstore/setIdentifierGenerationMethod).
|
|
353
356
|
*
|
|
@@ -356,12 +359,12 @@ export declare class Store extends BaseClass {
|
|
|
356
359
|
* ```ts
|
|
357
360
|
* store.lifetimes = {
|
|
358
361
|
* // make the request and ignore the current cache state
|
|
359
|
-
* isHardExpired(
|
|
362
|
+
* isHardExpired(key: RequestKey): boolean {
|
|
360
363
|
* return false;
|
|
361
364
|
* }
|
|
362
365
|
*
|
|
363
366
|
* // make the request in the background if true, return cache state
|
|
364
|
-
* isSoftExpired(
|
|
367
|
+
* isSoftExpired(key: RequestKey): boolean {
|
|
365
368
|
* return false;
|
|
366
369
|
* }
|
|
367
370
|
* }
|
|
@@ -370,65 +373,16 @@ export declare class Store extends BaseClass {
|
|
|
370
373
|
* @public
|
|
371
374
|
*/
|
|
372
375
|
lifetimes?: CachePolicy;
|
|
373
|
-
|
|
374
|
-
/** @internal */
|
|
375
|
-
_graph?: Graph;
|
|
376
|
-
/** @internal */
|
|
377
|
-
_requestCache: RequestStateService;
|
|
378
|
-
/** @internal */
|
|
379
|
-
_instanceCache: InstanceCache;
|
|
380
|
-
/** @internal */
|
|
381
|
-
_cbs: {
|
|
382
|
-
coalesce?: () => void;
|
|
383
|
-
sync?: () => void;
|
|
384
|
-
notify?: () => void;
|
|
385
|
-
} | null;
|
|
386
|
-
/** @internal */
|
|
387
|
-
_forceShim: boolean;
|
|
388
|
-
/**
|
|
389
|
-
* Async flush buffers notifications until flushed
|
|
390
|
-
* by finalization of a future configured by store.request
|
|
391
|
-
*
|
|
392
|
-
* This is useful for ensuring that notifications are delivered
|
|
393
|
-
* prior to the promise resolving but without risk of promise
|
|
394
|
-
* interleaving.
|
|
395
|
-
*
|
|
396
|
-
* @internal
|
|
397
|
-
*/
|
|
398
|
-
_enableAsyncFlush: boolean | null;
|
|
399
|
-
// DEBUG-only properties
|
|
400
|
-
/** @internal */
|
|
401
|
-
DISABLE_WAITER?: boolean;
|
|
402
|
-
/** @internal */
|
|
403
|
-
_isDestroying: boolean;
|
|
404
|
-
/** @internal */
|
|
405
|
-
_isDestroyed: boolean;
|
|
406
|
-
/** @internal */
|
|
376
|
+
/** @private */
|
|
407
377
|
get isDestroying(): boolean;
|
|
408
|
-
/** @
|
|
409
|
-
set isDestroying(value: boolean);
|
|
410
|
-
/** @internal */
|
|
378
|
+
/** @private */
|
|
411
379
|
get isDestroyed(): boolean;
|
|
412
|
-
/** @
|
|
413
|
-
|
|
380
|
+
/** @deprecated use {@link Store.cacheKeyManager} */
|
|
381
|
+
get identifierCache(): CacheKeyManager;
|
|
414
382
|
/**
|
|
415
383
|
@private
|
|
416
384
|
*/
|
|
417
385
|
constructor(createArgs?: unknown);
|
|
418
|
-
/** @internal */
|
|
419
|
-
_run(cb: () => void): void;
|
|
420
|
-
/**
|
|
421
|
-
* Executes the callback, ensurng that any work that calls
|
|
422
|
-
* store._schedule is executed after in the right order.
|
|
423
|
-
*
|
|
424
|
-
* When queues already exist, scheduled callbacks will
|
|
425
|
-
* join the existing queue.
|
|
426
|
-
*
|
|
427
|
-
* @internal
|
|
428
|
-
*/
|
|
429
|
-
_join(cb: () => void): void;
|
|
430
|
-
/** @internal */
|
|
431
|
-
_schedule(name: "coalesce" | "sync" | "notify", cb: () => void): void;
|
|
432
386
|
/**
|
|
433
387
|
* Retrieve the RequestStateService instance
|
|
434
388
|
* associated with this Store.
|
|
@@ -440,10 +394,6 @@ export declare class Store extends BaseClass {
|
|
|
440
394
|
* @public
|
|
441
395
|
*/
|
|
442
396
|
getRequestStateService(): RequestStateService;
|
|
443
|
-
/** @internal */
|
|
444
|
-
_getAllPending(): (Promise<unknown[]> & {
|
|
445
|
-
length: number;
|
|
446
|
-
}) | void;
|
|
447
397
|
/**
|
|
448
398
|
* ::: tip 💡 For a more complete overview see the [Request Guide](/guides/2-requests/1-overview)
|
|
449
399
|
* :::
|
|
@@ -458,7 +408,7 @@ export declare class Store extends BaseClass {
|
|
|
458
408
|
* {@link CacheOptions.key | cache key} will have the request result
|
|
459
409
|
* and document cached.
|
|
460
410
|
*
|
|
461
|
-
* The cache key used is {@link RequestInfo.cacheOptions | RequestInfo.cacheOptions.key}
|
|
411
|
+
* The cache key used is {@link RequestInfo.cacheOptions.key | RequestInfo.cacheOptions.key}
|
|
462
412
|
* if present, falling back to {@link RequestInfo.url}.
|
|
463
413
|
*
|
|
464
414
|
* Params are not serialized as part of the cache-key, so
|
|
@@ -497,64 +447,77 @@ export declare class Store extends BaseClass {
|
|
|
497
447
|
*
|
|
498
448
|
* @public
|
|
499
449
|
*/
|
|
500
|
-
request<
|
|
501
|
-
RT,
|
|
502
|
-
T = unknown
|
|
503
|
-
>(requestConfig: StoreRequestInput<RT, T>): Future<RT>;
|
|
450
|
+
request<RT>(requestConfig: StoreRequestInput<RT>): Future<RT>;
|
|
504
451
|
/**
|
|
505
|
-
|
|
452
|
+
Creates a new record in the current store.
|
|
506
453
|
|
|
507
|
-
|
|
508
|
-
|
|
454
|
+
> [!CAUTION]
|
|
455
|
+
> This should not be used to mock records or to create
|
|
456
|
+
> a record representing data that could be fetched from
|
|
457
|
+
> the API.
|
|
509
458
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
should be considered legacy and exists primarily to continue to support
|
|
513
|
-
Adapter/Serializer APIs which expect it's return value in their method
|
|
514
|
-
signatures.
|
|
515
|
-
|
|
516
|
-
The class of a model might be useful if you want to get a list of all the
|
|
517
|
-
relationship names of the model, see
|
|
518
|
-
[`relationshipNames`](/ember-data/release/classes/Model?anchor=relationshipNames)
|
|
519
|
-
for example.
|
|
520
|
-
|
|
521
|
-
@public
|
|
522
|
-
@deprecated
|
|
523
|
-
@param {String} type
|
|
524
|
-
@return {ModelSchema}
|
|
525
|
-
*/
|
|
526
|
-
modelFor<T>(type: TypeFromInstance<T>): ModelSchema<T>;
|
|
527
|
-
modelFor(type: string): ModelSchema;
|
|
528
|
-
/**
|
|
529
|
-
Create a new record in the current store. The properties passed
|
|
530
|
-
to this method are set on the newly created record.
|
|
459
|
+
The properties passed to this method are set on
|
|
460
|
+
the newly created record.
|
|
531
461
|
|
|
532
|
-
|
|
462
|
+
For instance: to create a new `post`:
|
|
533
463
|
|
|
534
464
|
```js
|
|
535
465
|
store.createRecord('post', {
|
|
536
|
-
title: '
|
|
466
|
+
title: 'WarpDrive is Stellar!'
|
|
537
467
|
});
|
|
538
468
|
```
|
|
539
469
|
|
|
540
|
-
|
|
470
|
+
Relationships can be set during create. For instance,
|
|
471
|
+
to create a new `post` that has an existing user as
|
|
472
|
+
it's author:
|
|
541
473
|
|
|
542
474
|
```js
|
|
543
|
-
|
|
475
|
+
const user = store.peekRecord('user', '1');
|
|
476
|
+
|
|
544
477
|
store.createRecord('post', {
|
|
545
|
-
title: '
|
|
478
|
+
title: 'WarpDrive is Stellar!',
|
|
546
479
|
user: user
|
|
547
480
|
});
|
|
548
481
|
```
|
|
549
482
|
|
|
483
|
+
### lid handling
|
|
484
|
+
|
|
485
|
+
All new records are assigned an `lid` that can be used to handle
|
|
486
|
+
transactional saves of multiple records, or to link the data to
|
|
487
|
+
other data in scenarios involving eventual-consistency or remote
|
|
488
|
+
syncing.
|
|
489
|
+
|
|
490
|
+
```ts
|
|
491
|
+
const post = store.createRecord('post', {
|
|
492
|
+
title: 'WarpDrive is Stellar!'
|
|
493
|
+
});
|
|
494
|
+
const { lid } = recordIdentifierFor(post);
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
The `lid` defaults to a uuidv4 string.
|
|
498
|
+
|
|
499
|
+
In order to support receiving knowledge about unpersisted creates
|
|
500
|
+
from other sources (say a different tab in the same web-browser),
|
|
501
|
+
createRecord allows for the `lid` to be provided as part of an
|
|
502
|
+
optional third argument. **If this lid already exists in the store
|
|
503
|
+
an error will be thrown.**
|
|
504
|
+
|
|
505
|
+
```ts
|
|
506
|
+
const post = store.createRecord(
|
|
507
|
+
'post',
|
|
508
|
+
{ title: 'WarpDrive is Stellar!' },
|
|
509
|
+
{ lid: '4d47bb88-931f-496e-986d-c4888cef7373' }
|
|
510
|
+
);
|
|
511
|
+
```
|
|
512
|
+
|
|
550
513
|
@public
|
|
551
|
-
@param
|
|
552
|
-
@param
|
|
514
|
+
@param type the name of the resource
|
|
515
|
+
@param inputProperties a hash of properties to set on the
|
|
553
516
|
newly created record.
|
|
554
|
-
@return
|
|
517
|
+
@return a record in the "isNew" state
|
|
555
518
|
*/
|
|
556
|
-
createRecord<T>(type: TypeFromInstance<T>, inputProperties: CreateRecordProperties<T
|
|
557
|
-
createRecord(type: string, inputProperties: CreateRecordProperties): OpaqueRecordInstance;
|
|
519
|
+
createRecord<T>(type: TypeFromInstance<T>, inputProperties: CreateRecordProperties<T>, context?: CreateContext): T;
|
|
520
|
+
createRecord(type: string, inputProperties: CreateRecordProperties, context?: CreateContext): OpaqueRecordInstance;
|
|
558
521
|
/**
|
|
559
522
|
For symmetry, a record can be deleted via the store.
|
|
560
523
|
|
|
@@ -588,401 +551,6 @@ export declare class Store extends BaseClass {
|
|
|
588
551
|
*/
|
|
589
552
|
unloadRecord<T>(record: T): void;
|
|
590
553
|
/**
|
|
591
|
-
This method returns a record for a given identifier or type and id combination.
|
|
592
|
-
|
|
593
|
-
The `findRecord` method will always resolve its promise with the same
|
|
594
|
-
object for a given identifier or type and `id`.
|
|
595
|
-
|
|
596
|
-
The `findRecord` method will always return a **promise** that will be
|
|
597
|
-
resolved with the record.
|
|
598
|
-
|
|
599
|
-
**Example 1**
|
|
600
|
-
|
|
601
|
-
```js [app/routes/post.js]
|
|
602
|
-
export default class PostRoute extends Route {
|
|
603
|
-
model({ post_id }) {
|
|
604
|
-
return this.store.findRecord('post', post_id);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
**Example 2**
|
|
610
|
-
|
|
611
|
-
`findRecord` can be called with a single identifier argument instead of the combination
|
|
612
|
-
of `type` (modelName) and `id` as separate arguments. You may recognize this combo as
|
|
613
|
-
the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)
|
|
614
|
-
|
|
615
|
-
```js [app/routes/post.js]
|
|
616
|
-
export default class PostRoute extends Route {
|
|
617
|
-
model({ post_id: id }) {
|
|
618
|
-
return this.store.findRecord({ type: 'post', id });
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
**Example 3**
|
|
624
|
-
|
|
625
|
-
If you have previously received an lid via an Identifier for this record, and the record
|
|
626
|
-
has already been assigned an id, you can find the record again using just the lid.
|
|
627
|
-
|
|
628
|
-
```js [app/routes/post.js]
|
|
629
|
-
store.findRecord({ lid });
|
|
630
|
-
```
|
|
631
|
-
|
|
632
|
-
If the record is not yet available, the store will ask the adapter's `findRecord`
|
|
633
|
-
method to retrieve and supply the necessary data. If the record is already present
|
|
634
|
-
in the store, it depends on the reload behavior _when_ the returned promise
|
|
635
|
-
resolves.
|
|
636
|
-
|
|
637
|
-
### Preloading
|
|
638
|
-
|
|
639
|
-
You can optionally `preload` specific attributes and relationships that you know of
|
|
640
|
-
by passing them via the passed `options`.
|
|
641
|
-
|
|
642
|
-
For example, if your Ember route looks like `/posts/1/comments/2` and your API route
|
|
643
|
-
for the comment also looks like `/posts/1/comments/2` if you want to fetch the comment
|
|
644
|
-
without also fetching the post you can pass in the post to the `findRecord` call:
|
|
645
|
-
|
|
646
|
-
```js [app/routes/post-comments.js]
|
|
647
|
-
export default class PostRoute extends Route {
|
|
648
|
-
model({ post_id, comment_id: id }) {
|
|
649
|
-
return this.store.findRecord({ type: 'comment', id, { preload: { post: post_id }} });
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
```
|
|
653
|
-
|
|
654
|
-
In your adapter you can then access this id without triggering a network request via the
|
|
655
|
-
snapshot:
|
|
656
|
-
|
|
657
|
-
```js [app/adapters/application.js]
|
|
658
|
-
export default class Adapter {
|
|
659
|
-
|
|
660
|
-
findRecord(store, schema, id, snapshot) {
|
|
661
|
-
let type = schema.modelName;
|
|
662
|
-
|
|
663
|
-
if (type === 'comment')
|
|
664
|
-
let postId = snapshot.belongsTo('post', { id: true });
|
|
665
|
-
|
|
666
|
-
return fetch(`./posts/${postId}/comments/${id}`)
|
|
667
|
-
.then(response => response.json())
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
static create() {
|
|
672
|
-
return new this();
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
```
|
|
676
|
-
|
|
677
|
-
This could also be achieved by supplying the post id to the adapter via the adapterOptions
|
|
678
|
-
property on the options hash.
|
|
679
|
-
|
|
680
|
-
```js [app/routes/post-comments.js]
|
|
681
|
-
export default class PostRoute extends Route {
|
|
682
|
-
model({ post_id, comment_id: id }) {
|
|
683
|
-
return this.store.findRecord({ type: 'comment', id, { adapterOptions: { post: post_id }} });
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
```
|
|
687
|
-
|
|
688
|
-
```js [app/adapters/application.js]
|
|
689
|
-
export default class Adapter {
|
|
690
|
-
findRecord(store, schema, id, snapshot) {
|
|
691
|
-
let type = schema.modelName;
|
|
692
|
-
|
|
693
|
-
if (type === 'comment')
|
|
694
|
-
let postId = snapshot.adapterOptions.post;
|
|
695
|
-
|
|
696
|
-
return fetch(`./posts/${postId}/comments/${id}`)
|
|
697
|
-
.then(response => response.json())
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
static create() {
|
|
702
|
-
return new this();
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
```
|
|
706
|
-
|
|
707
|
-
If you have access to the post model you can also pass the model itself to preload:
|
|
708
|
-
|
|
709
|
-
```javascript
|
|
710
|
-
let post = await store.findRecord('post', '1');
|
|
711
|
-
let comment = await store.findRecord('comment', '2', { post: myPostModel });
|
|
712
|
-
```
|
|
713
|
-
|
|
714
|
-
### Reloading
|
|
715
|
-
|
|
716
|
-
The reload behavior is configured either via the passed `options` hash or
|
|
717
|
-
the result of the adapter's `shouldReloadRecord`.
|
|
718
|
-
|
|
719
|
-
If `{ reload: true }` is passed or `adapter.shouldReloadRecord` evaluates
|
|
720
|
-
to `true`, then the returned promise resolves once the adapter returns
|
|
721
|
-
data, regardless if the requested record is already in the store:
|
|
722
|
-
|
|
723
|
-
```js
|
|
724
|
-
store.push({
|
|
725
|
-
data: {
|
|
726
|
-
id: 1,
|
|
727
|
-
type: 'post',
|
|
728
|
-
revision: 1
|
|
729
|
-
}
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
// adapter#findRecord resolves with
|
|
733
|
-
// [
|
|
734
|
-
// {
|
|
735
|
-
// id: 1,
|
|
736
|
-
// type: 'post',
|
|
737
|
-
// revision: 2
|
|
738
|
-
// }
|
|
739
|
-
// ]
|
|
740
|
-
store.findRecord('post', '1', { reload: true }).then(function(post) {
|
|
741
|
-
post.revision; // 2
|
|
742
|
-
});
|
|
743
|
-
```
|
|
744
|
-
|
|
745
|
-
If no reload is indicated via the above mentioned ways, then the promise
|
|
746
|
-
immediately resolves with the cached version in the store.
|
|
747
|
-
|
|
748
|
-
### Background Reloading
|
|
749
|
-
|
|
750
|
-
Optionally, if `adapter.shouldBackgroundReloadRecord` evaluates to `true`,
|
|
751
|
-
then a background reload is started, which updates the records' data, once
|
|
752
|
-
it is available:
|
|
753
|
-
|
|
754
|
-
```js
|
|
755
|
-
// app/adapters/post.js
|
|
756
|
-
import ApplicationAdapter from "./application";
|
|
757
|
-
|
|
758
|
-
export default class PostAdapter extends ApplicationAdapter {
|
|
759
|
-
shouldReloadRecord(store, snapshot) {
|
|
760
|
-
return false;
|
|
761
|
-
},
|
|
762
|
-
|
|
763
|
-
shouldBackgroundReloadRecord(store, snapshot) {
|
|
764
|
-
return true;
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
// ...
|
|
769
|
-
|
|
770
|
-
store.push({
|
|
771
|
-
data: {
|
|
772
|
-
id: 1,
|
|
773
|
-
type: 'post',
|
|
774
|
-
revision: 1
|
|
775
|
-
}
|
|
776
|
-
});
|
|
777
|
-
|
|
778
|
-
let blogPost = store.findRecord('post', '1').then(function(post) {
|
|
779
|
-
post.revision; // 1
|
|
780
|
-
});
|
|
781
|
-
|
|
782
|
-
// later, once adapter#findRecord resolved with
|
|
783
|
-
// [
|
|
784
|
-
// {
|
|
785
|
-
// id: 1,
|
|
786
|
-
// type: 'post',
|
|
787
|
-
// revision: 2
|
|
788
|
-
// }
|
|
789
|
-
// ]
|
|
790
|
-
|
|
791
|
-
blogPost.revision; // 2
|
|
792
|
-
```
|
|
793
|
-
|
|
794
|
-
If you would like to force or prevent background reloading, you can set a
|
|
795
|
-
boolean value for `backgroundReload` in the options object for
|
|
796
|
-
`findRecord`.
|
|
797
|
-
|
|
798
|
-
```js [app/routes/post/edit.js]
|
|
799
|
-
export default class PostEditRoute extends Route {
|
|
800
|
-
model(params) {
|
|
801
|
-
return this.store.findRecord('post', params.post_id, { backgroundReload: false });
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
```
|
|
805
|
-
|
|
806
|
-
If you pass an object on the `adapterOptions` property of the options
|
|
807
|
-
argument it will be passed to your adapter via the snapshot
|
|
808
|
-
|
|
809
|
-
```js [app/routes/post/edit.js]
|
|
810
|
-
export default class PostEditRoute extends Route {
|
|
811
|
-
model(params) {
|
|
812
|
-
return this.store.findRecord('post', params.post_id, {
|
|
813
|
-
adapterOptions: { subscribe: false }
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
```
|
|
818
|
-
|
|
819
|
-
```js [app/adapters/post.js]
|
|
820
|
-
import MyCustomAdapter from './custom-adapter';
|
|
821
|
-
|
|
822
|
-
export default class PostAdapter extends MyCustomAdapter {
|
|
823
|
-
findRecord(store, type, id, snapshot) {
|
|
824
|
-
if (snapshot.adapterOptions.subscribe) {
|
|
825
|
-
// ...
|
|
826
|
-
}
|
|
827
|
-
// ...
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
```
|
|
831
|
-
|
|
832
|
-
See [peekRecord](../methods/peekRecord?anchor=peekRecord) to get the cached version of a record.
|
|
833
|
-
|
|
834
|
-
### Retrieving Related Model Records
|
|
835
|
-
|
|
836
|
-
If you use an adapter such as Ember's default
|
|
837
|
-
[`JSONAPIAdapter`](/ember-data/release/classes/JSONAPIAdapter)
|
|
838
|
-
that supports the [JSON API specification](http://jsonapi.org/) and if your server
|
|
839
|
-
endpoint supports the use of an
|
|
840
|
-
['include' query parameter](http://jsonapi.org/format/#fetching-includes),
|
|
841
|
-
you can use `findRecord()` or `findAll()` to automatically retrieve additional records related to
|
|
842
|
-
the one you request by supplying an `include` parameter in the `options` object.
|
|
843
|
-
|
|
844
|
-
For example, given a `post` model that has a `hasMany` relationship with a `comment`
|
|
845
|
-
model, when we retrieve a specific post we can have the server also return that post's
|
|
846
|
-
comments in the same request:
|
|
847
|
-
|
|
848
|
-
```js [app/routes/post.js]
|
|
849
|
-
export default class PostRoute extends Route {
|
|
850
|
-
model(params) {
|
|
851
|
-
return this.store.findRecord('post', params.post_id, { include: ['comments'] });
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
```
|
|
855
|
-
|
|
856
|
-
```js [app/adapters/application.js]
|
|
857
|
-
export default class Adapter {
|
|
858
|
-
findRecord(store, schema, id, snapshot) {
|
|
859
|
-
let type = schema.modelName;
|
|
860
|
-
|
|
861
|
-
if (type === 'post')
|
|
862
|
-
let includes = snapshot.adapterOptions.include;
|
|
863
|
-
|
|
864
|
-
return fetch(`./posts/${postId}?include=${includes}`)
|
|
865
|
-
.then(response => response.json())
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
static create() {
|
|
870
|
-
return new this();
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
```
|
|
874
|
-
|
|
875
|
-
In this case, the post's comments would then be available in your template as
|
|
876
|
-
`model.comments`.
|
|
877
|
-
|
|
878
|
-
Multiple relationships can be requested using an `include` parameter consisting of a
|
|
879
|
-
list of relationship names, while nested relationships can be specified
|
|
880
|
-
using a dot-separated sequence of relationship names. So to request both the post's
|
|
881
|
-
comments and the authors of those comments the request would look like this:
|
|
882
|
-
|
|
883
|
-
```js [app/routes/post.js]
|
|
884
|
-
export default class PostRoute extends Route {
|
|
885
|
-
model(params) {
|
|
886
|
-
return this.store.findRecord('post', params.post_id, { include: ['comments','comments.author'] });
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
```
|
|
890
|
-
|
|
891
|
-
### Retrieving Specific Fields by Type
|
|
892
|
-
|
|
893
|
-
If your server endpoint supports the use of a ['fields' query parameter](https://jsonapi.org/format/#fetching-sparse-fieldsets),
|
|
894
|
-
you can use pass those fields through to your server. At this point in time, this requires a few manual steps on your part.
|
|
895
|
-
|
|
896
|
-
1. Implement `buildQuery` in your adapter.
|
|
897
|
-
|
|
898
|
-
```js [app/adapters/application.js]
|
|
899
|
-
buildQuery(snapshot) {
|
|
900
|
-
let query = super.buildQuery(...arguments);
|
|
901
|
-
|
|
902
|
-
let { fields } = snapshot.adapterOptions;
|
|
903
|
-
|
|
904
|
-
if (fields) {
|
|
905
|
-
query.fields = fields;
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
return query;
|
|
909
|
-
}
|
|
910
|
-
```
|
|
911
|
-
|
|
912
|
-
2. Then pass through the applicable fields to your `findRecord` request.
|
|
913
|
-
|
|
914
|
-
Given a `post` model with attributes body, title, publishDate and meta, you can retrieve a filtered list of attributes.
|
|
915
|
-
|
|
916
|
-
```js [app/routes/post.js]
|
|
917
|
-
export default class extends Route {
|
|
918
|
-
model(params) {
|
|
919
|
-
return this.store.findRecord('post', params.post_id, { adapterOptions: { fields: { post: 'body,title' } });
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
```
|
|
923
|
-
|
|
924
|
-
Moreover, you can filter attributes on related models as well. If a `post` has a `belongsTo` relationship to a user,
|
|
925
|
-
just include the relationship key and attributes.
|
|
926
|
-
|
|
927
|
-
```js [app/routes/post.js]
|
|
928
|
-
export default class extends Route {
|
|
929
|
-
model(params) {
|
|
930
|
-
return this.store.findRecord('post', params.post_id, { adapterOptions: { fields: { post: 'body,title', user: 'name,email' } });
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
```
|
|
934
|
-
|
|
935
|
-
@since 1.13.0
|
|
936
|
-
@public
|
|
937
|
-
@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
|
|
938
|
-
@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
|
|
939
|
-
@param {Object} [options] - if the first param is a string this will be the optional options for the request. See examples for available options.
|
|
940
|
-
@return {Promise} promise
|
|
941
|
-
*/
|
|
942
|
-
findRecord<T>(type: TypeFromInstance<T>, id: string | number, options?: FindRecordOptions<T>): Promise<T>;
|
|
943
|
-
findRecord(type: string, id: string | number, options?: FindRecordOptions): Promise<unknown>;
|
|
944
|
-
findRecord<T>(resource: ResourceIdentifierObject<TypeFromInstance<T>>, options?: FindRecordOptions<T>): Promise<T>;
|
|
945
|
-
findRecord(resource: ResourceIdentifierObject, options?: FindRecordOptions): Promise<unknown>;
|
|
946
|
-
/**
|
|
947
|
-
Get the reference for the specified record.
|
|
948
|
-
|
|
949
|
-
Example
|
|
950
|
-
|
|
951
|
-
```javascript
|
|
952
|
-
let userRef = store.getReference('user', '1');
|
|
953
|
-
|
|
954
|
-
// check if the user is loaded
|
|
955
|
-
let isLoaded = userRef.value() !== null;
|
|
956
|
-
|
|
957
|
-
// get the record of the reference (null if not yet available)
|
|
958
|
-
let user = userRef.value();
|
|
959
|
-
|
|
960
|
-
// get the identifier of the reference
|
|
961
|
-
if (userRef.remoteType() === 'id') {
|
|
962
|
-
let id = userRef.id();
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
// load user (via store.find)
|
|
966
|
-
userRef.load().then(...)
|
|
967
|
-
|
|
968
|
-
// or trigger a reload
|
|
969
|
-
userRef.reload().then(...)
|
|
970
|
-
|
|
971
|
-
// provide data for reference
|
|
972
|
-
userRef.push({ id: 1, username: '@user' }).then(function(user) {
|
|
973
|
-
userRef.value() === user;
|
|
974
|
-
});
|
|
975
|
-
```
|
|
976
|
-
|
|
977
|
-
@public
|
|
978
|
-
@param {String|object} resource - modelName (string) or Identifier (object)
|
|
979
|
-
@param {String|Integer} id
|
|
980
|
-
@since 2.5.0
|
|
981
|
-
@return {RecordReference}
|
|
982
|
-
*/
|
|
983
|
-
// TODO @deprecate getReference (and references generally)
|
|
984
|
-
getReference(resource: string | ResourceIdentifierObject, id: string | number): RecordReference;
|
|
985
|
-
/**
|
|
986
554
|
Get a record by a given type and ID without triggering a fetch.
|
|
987
555
|
|
|
988
556
|
This method will synchronously return the record if it is available in the store,
|
|
@@ -1034,336 +602,6 @@ export declare class Store extends BaseClass {
|
|
|
1034
602
|
peekRecord<T>(identifier: ResourceIdentifierObject<TypeFromInstance<T>>): T | null;
|
|
1035
603
|
peekRecord(identifier: ResourceIdentifierObject): unknown | null;
|
|
1036
604
|
/**
|
|
1037
|
-
This method delegates a query to the adapter. This is the one place where
|
|
1038
|
-
adapter-level semantics are exposed to the application.
|
|
1039
|
-
|
|
1040
|
-
Each time this method is called a new request is made through the adapter.
|
|
1041
|
-
|
|
1042
|
-
Exposing queries this way seems preferable to creating an abstract query
|
|
1043
|
-
language for all server-side queries, and then require all adapters to
|
|
1044
|
-
implement them.
|
|
1045
|
-
|
|
1046
|
-
---
|
|
1047
|
-
|
|
1048
|
-
If you do something like this:
|
|
1049
|
-
|
|
1050
|
-
```javascript
|
|
1051
|
-
store.query('person', { page: 1 });
|
|
1052
|
-
```
|
|
1053
|
-
|
|
1054
|
-
The request made to the server will look something like this:
|
|
1055
|
-
|
|
1056
|
-
```
|
|
1057
|
-
GET "/api/v1/person?page=1"
|
|
1058
|
-
```
|
|
1059
|
-
|
|
1060
|
-
---
|
|
1061
|
-
|
|
1062
|
-
If you do something like this:
|
|
1063
|
-
|
|
1064
|
-
```javascript
|
|
1065
|
-
store.query('person', { ids: ['1', '2', '3'] });
|
|
1066
|
-
```
|
|
1067
|
-
|
|
1068
|
-
The request made to the server will look something like this:
|
|
1069
|
-
|
|
1070
|
-
```
|
|
1071
|
-
GET "/api/v1/person?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3"
|
|
1072
|
-
decoded: "/api/v1/person?ids[]=1&ids[]=2&ids[]=3"
|
|
1073
|
-
```
|
|
1074
|
-
|
|
1075
|
-
This method returns a promise, which is resolved with a
|
|
1076
|
-
[`Collection`](/ember-data/release/classes/Collection)
|
|
1077
|
-
once the server returns.
|
|
1078
|
-
|
|
1079
|
-
@since 1.13.0
|
|
1080
|
-
@public
|
|
1081
|
-
@param {String} type the name of the resource
|
|
1082
|
-
@param {Object} query a query to be used by the adapter
|
|
1083
|
-
@param {Object} options optional, may include `adapterOptions` hash which will be passed to adapter.query
|
|
1084
|
-
@return {Promise} promise
|
|
1085
|
-
*/
|
|
1086
|
-
query<T>(type: TypeFromInstance<T>, query: LegacyResourceQuery<T>, options?: QueryOptions): Promise<Collection<T>>;
|
|
1087
|
-
query(type: string, query: LegacyResourceQuery, options?: QueryOptions): Promise<Collection>;
|
|
1088
|
-
/**
|
|
1089
|
-
This method makes a request for one record, where the `id` is not known
|
|
1090
|
-
beforehand (if the `id` is known, use [`findRecord`](../methods/findRecord?anchor=findRecord)
|
|
1091
|
-
instead).
|
|
1092
|
-
|
|
1093
|
-
This method can be used when it is certain that the server will return a
|
|
1094
|
-
single object for the primary data.
|
|
1095
|
-
|
|
1096
|
-
Each time this method is called a new request is made through the adapter.
|
|
1097
|
-
|
|
1098
|
-
Let's assume our API provides an endpoint for the currently logged in user
|
|
1099
|
-
via:
|
|
1100
|
-
|
|
1101
|
-
```
|
|
1102
|
-
// GET /api/current_user
|
|
1103
|
-
{
|
|
1104
|
-
user: {
|
|
1105
|
-
id: 1234,
|
|
1106
|
-
username: 'admin'
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
```
|
|
1110
|
-
|
|
1111
|
-
Since the specific `id` of the `user` is not known beforehand, we can use
|
|
1112
|
-
`queryRecord` to get the user:
|
|
1113
|
-
|
|
1114
|
-
```javascript
|
|
1115
|
-
store.queryRecord('user', {}).then(function(user) {
|
|
1116
|
-
let username = user.username;
|
|
1117
|
-
// do thing
|
|
1118
|
-
});
|
|
1119
|
-
```
|
|
1120
|
-
|
|
1121
|
-
The request is made through the adapters' `queryRecord`:
|
|
1122
|
-
|
|
1123
|
-
```js [app/adapters/user.js]
|
|
1124
|
-
import Adapter from '@ember-data/adapter';
|
|
1125
|
-
import $ from 'jquery';
|
|
1126
|
-
|
|
1127
|
-
export default class UserAdapter extends Adapter {
|
|
1128
|
-
queryRecord(modelName, query) {
|
|
1129
|
-
return $.getJSON('/api/current_user');
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
```
|
|
1133
|
-
|
|
1134
|
-
Note: the primary use case for `store.queryRecord` is when a single record
|
|
1135
|
-
is queried and the `id` is not known beforehand. In all other cases
|
|
1136
|
-
`store.query` and using the first item of the array is likely the preferred
|
|
1137
|
-
way:
|
|
1138
|
-
|
|
1139
|
-
```
|
|
1140
|
-
// GET /users?username=unique
|
|
1141
|
-
{
|
|
1142
|
-
data: [{
|
|
1143
|
-
id: 1234,
|
|
1144
|
-
type: 'user',
|
|
1145
|
-
attributes: {
|
|
1146
|
-
username: "unique"
|
|
1147
|
-
}
|
|
1148
|
-
}]
|
|
1149
|
-
}
|
|
1150
|
-
```
|
|
1151
|
-
|
|
1152
|
-
```javascript
|
|
1153
|
-
store.query('user', { username: 'unique' }).then(function(users) {
|
|
1154
|
-
return users.firstObject;
|
|
1155
|
-
}).then(function(user) {
|
|
1156
|
-
let id = user.id;
|
|
1157
|
-
});
|
|
1158
|
-
```
|
|
1159
|
-
|
|
1160
|
-
This method returns a promise, which resolves with the found record.
|
|
1161
|
-
|
|
1162
|
-
If the adapter returns no data for the primary data of the payload, then
|
|
1163
|
-
`queryRecord` resolves with `null`:
|
|
1164
|
-
|
|
1165
|
-
```
|
|
1166
|
-
// GET /users?username=unique
|
|
1167
|
-
{
|
|
1168
|
-
data: null
|
|
1169
|
-
}
|
|
1170
|
-
```
|
|
1171
|
-
|
|
1172
|
-
```javascript
|
|
1173
|
-
store.queryRecord('user', { username: 'unique' }).then(function(user) {
|
|
1174
|
-
// user is null
|
|
1175
|
-
});
|
|
1176
|
-
```
|
|
1177
|
-
|
|
1178
|
-
@since 1.13.0
|
|
1179
|
-
@public
|
|
1180
|
-
@param {String} type
|
|
1181
|
-
@param {Object} query an opaque query to be used by the adapter
|
|
1182
|
-
@param {Object} options optional, may include `adapterOptions` hash which will be passed to adapter.queryRecord
|
|
1183
|
-
@return {Promise} promise which resolves with the found record or `null`
|
|
1184
|
-
*/
|
|
1185
|
-
queryRecord<T>(type: TypeFromInstance<T>, query: LegacyResourceQuery<T>, options?: QueryOptions): Promise<T | null>;
|
|
1186
|
-
queryRecord(type: string, query: LegacyResourceQuery, options?: QueryOptions): Promise<unknown | null>;
|
|
1187
|
-
/**
|
|
1188
|
-
`findAll` asks the adapter's `findAll` method to find the records for the
|
|
1189
|
-
given type, and returns a promise which will resolve with all records of
|
|
1190
|
-
this type present in the store, even if the adapter only returns a subset
|
|
1191
|
-
of them.
|
|
1192
|
-
|
|
1193
|
-
```js [app/routes/authors.js]
|
|
1194
|
-
export default class AuthorsRoute extends Route {
|
|
1195
|
-
model(params) {
|
|
1196
|
-
return this.store.findAll('author');
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
```
|
|
1200
|
-
|
|
1201
|
-
_When_ the returned promise resolves depends on the reload behavior,
|
|
1202
|
-
configured via the passed `options` hash and the result of the adapter's
|
|
1203
|
-
`shouldReloadAll` method.
|
|
1204
|
-
|
|
1205
|
-
### Reloading
|
|
1206
|
-
|
|
1207
|
-
If `{ reload: true }` is passed or `adapter.shouldReloadAll` evaluates to
|
|
1208
|
-
`true`, then the returned promise resolves once the adapter returns data,
|
|
1209
|
-
regardless if there are already records in the store:
|
|
1210
|
-
|
|
1211
|
-
```js
|
|
1212
|
-
store.push({
|
|
1213
|
-
data: {
|
|
1214
|
-
id: 'first',
|
|
1215
|
-
type: 'author'
|
|
1216
|
-
}
|
|
1217
|
-
});
|
|
1218
|
-
|
|
1219
|
-
// adapter#findAll resolves with
|
|
1220
|
-
// [
|
|
1221
|
-
// {
|
|
1222
|
-
// id: 'second',
|
|
1223
|
-
// type: 'author'
|
|
1224
|
-
// }
|
|
1225
|
-
// ]
|
|
1226
|
-
store.findAll('author', { reload: true }).then(function(authors) {
|
|
1227
|
-
authors.getEach('id'); // ['first', 'second']
|
|
1228
|
-
});
|
|
1229
|
-
```
|
|
1230
|
-
|
|
1231
|
-
If no reload is indicated via the above mentioned ways, then the promise
|
|
1232
|
-
immediately resolves with all the records currently loaded in the store.
|
|
1233
|
-
|
|
1234
|
-
### Background Reloading
|
|
1235
|
-
|
|
1236
|
-
Optionally, if `adapter.shouldBackgroundReloadAll` evaluates to `true`,
|
|
1237
|
-
then a background reload is started. Once this resolves, the array with
|
|
1238
|
-
which the promise resolves, is updated automatically so it contains all the
|
|
1239
|
-
records in the store:
|
|
1240
|
-
|
|
1241
|
-
```js [app/adapters/application.js]
|
|
1242
|
-
import Adapter from '@ember-data/adapter';
|
|
1243
|
-
|
|
1244
|
-
export default class ApplicationAdapter extends Adapter {
|
|
1245
|
-
shouldReloadAll(store, snapshotsArray) {
|
|
1246
|
-
return false;
|
|
1247
|
-
},
|
|
1248
|
-
|
|
1249
|
-
shouldBackgroundReloadAll(store, snapshotsArray) {
|
|
1250
|
-
return true;
|
|
1251
|
-
}
|
|
1252
|
-
});
|
|
1253
|
-
|
|
1254
|
-
// ...
|
|
1255
|
-
|
|
1256
|
-
store.push({
|
|
1257
|
-
data: {
|
|
1258
|
-
id: 'first',
|
|
1259
|
-
type: 'author'
|
|
1260
|
-
}
|
|
1261
|
-
});
|
|
1262
|
-
|
|
1263
|
-
let allAuthors;
|
|
1264
|
-
store.findAll('author').then(function(authors) {
|
|
1265
|
-
authors.getEach('id'); // ['first']
|
|
1266
|
-
|
|
1267
|
-
allAuthors = authors;
|
|
1268
|
-
});
|
|
1269
|
-
|
|
1270
|
-
// later, once adapter#findAll resolved with
|
|
1271
|
-
// [
|
|
1272
|
-
// {
|
|
1273
|
-
// id: 'second',
|
|
1274
|
-
// type: 'author'
|
|
1275
|
-
// }
|
|
1276
|
-
// ]
|
|
1277
|
-
|
|
1278
|
-
allAuthors.getEach('id'); // ['first', 'second']
|
|
1279
|
-
```
|
|
1280
|
-
|
|
1281
|
-
If you would like to force or prevent background reloading, you can set a
|
|
1282
|
-
boolean value for `backgroundReload` in the options object for
|
|
1283
|
-
`findAll`.
|
|
1284
|
-
|
|
1285
|
-
```js [app/routes/post/edit.js]
|
|
1286
|
-
export default class PostEditRoute extends Route {
|
|
1287
|
-
model() {
|
|
1288
|
-
return this.store.findAll('post', { backgroundReload: false });
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
```
|
|
1292
|
-
|
|
1293
|
-
If you pass an object on the `adapterOptions` property of the options
|
|
1294
|
-
argument it will be passed to you adapter via the `snapshotRecordArray`
|
|
1295
|
-
|
|
1296
|
-
```js [app/routes/posts.js]
|
|
1297
|
-
export default class PostsRoute extends Route {
|
|
1298
|
-
model(params) {
|
|
1299
|
-
return this.store.findAll('post', {
|
|
1300
|
-
adapterOptions: { subscribe: false }
|
|
1301
|
-
});
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
```
|
|
1305
|
-
|
|
1306
|
-
```js [app/adapters/post.js]
|
|
1307
|
-
import MyCustomAdapter from './custom-adapter';
|
|
1308
|
-
|
|
1309
|
-
export default class UserAdapter extends MyCustomAdapter {
|
|
1310
|
-
findAll(store, type, sinceToken, snapshotRecordArray) {
|
|
1311
|
-
if (snapshotRecordArray.adapterOptions.subscribe) {
|
|
1312
|
-
// ...
|
|
1313
|
-
}
|
|
1314
|
-
// ...
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
```
|
|
1318
|
-
|
|
1319
|
-
See [peekAll](../methods/peekAll?anchor=peekAll) to get an array of current records in the
|
|
1320
|
-
store, without waiting until a reload is finished.
|
|
1321
|
-
|
|
1322
|
-
### Retrieving Related Model Records
|
|
1323
|
-
|
|
1324
|
-
If you use an adapter such as Ember's default
|
|
1325
|
-
[`JSONAPIAdapter`](/ember-data/release/classes/JSONAPIAdapter)
|
|
1326
|
-
that supports the [JSON API specification](http://jsonapi.org/) and if your server
|
|
1327
|
-
endpoint supports the use of an
|
|
1328
|
-
['include' query parameter](http://jsonapi.org/format/#fetching-includes),
|
|
1329
|
-
you can use `findAll()` to automatically retrieve additional records related to
|
|
1330
|
-
those requested by supplying an `include` parameter in the `options` object.
|
|
1331
|
-
|
|
1332
|
-
For example, given a `post` model that has a `hasMany` relationship with a `comment`
|
|
1333
|
-
model, when we retrieve all of the post records we can have the server also return
|
|
1334
|
-
all of the posts' comments in the same request:
|
|
1335
|
-
|
|
1336
|
-
```js [app/routes/posts.js]
|
|
1337
|
-
export default class PostsRoute extends Route {
|
|
1338
|
-
model() {
|
|
1339
|
-
return this.store.findAll('post', { include: ['comments'] });
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
```
|
|
1343
|
-
Multiple relationships can be requested using an `include` parameter consisting of a
|
|
1344
|
-
list or relationship names, while nested relationships can be specified
|
|
1345
|
-
using a dot-separated sequence of relationship names. So to request both the posts'
|
|
1346
|
-
comments and the authors of those comments the request would look like this:
|
|
1347
|
-
|
|
1348
|
-
```js [app/routes/posts.js]
|
|
1349
|
-
export default class PostsRoute extends Route {
|
|
1350
|
-
model() {
|
|
1351
|
-
return this.store.findAll('post', { include: ['comments','comments.author'] });
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
```
|
|
1355
|
-
|
|
1356
|
-
See [query](../methods/query?anchor=query) to only get a subset of records from the server.
|
|
1357
|
-
|
|
1358
|
-
@since 1.13.0
|
|
1359
|
-
@public
|
|
1360
|
-
@param {String} type the name of the resource
|
|
1361
|
-
@param {Object} options
|
|
1362
|
-
@return {Promise} promise
|
|
1363
|
-
*/
|
|
1364
|
-
findAll<T>(type: TypeFromInstance<T>, options?: FindAllOptions<T>): Promise<IdentifierArray<T>>;
|
|
1365
|
-
findAll(type: string, options?: FindAllOptions): Promise<IdentifierArray>;
|
|
1366
|
-
/**
|
|
1367
605
|
This method returns a filtered array that contains all of the
|
|
1368
606
|
known records for a given type in the store.
|
|
1369
607
|
|
|
@@ -1387,8 +625,8 @@ export declare class Store extends BaseClass {
|
|
|
1387
625
|
@param {String} type the name of the resource
|
|
1388
626
|
@return {RecordArray}
|
|
1389
627
|
*/
|
|
1390
|
-
peekAll<T>(type: TypeFromInstance<T>):
|
|
1391
|
-
peekAll(type: string):
|
|
628
|
+
peekAll<T>(type: TypeFromInstance<T>): LegacyLiveArray<T>;
|
|
629
|
+
peekAll(type: string): LegacyLiveArray;
|
|
1392
630
|
/**
|
|
1393
631
|
This method unloads all records in the store.
|
|
1394
632
|
It schedules unloading to happen during the next run loop.
|
|
@@ -1566,40 +804,92 @@ export declare class Store extends BaseClass {
|
|
|
1566
804
|
|
|
1567
805
|
@private
|
|
1568
806
|
@param {Object} jsonApiDoc
|
|
1569
|
-
@return {
|
|
807
|
+
@return {ResourceKey|Array<ResourceKey>|null} identifiers for the primary records that had data loaded
|
|
1570
808
|
*/
|
|
1571
|
-
_push(jsonApiDoc: JsonApiDocument, asyncFlush?: boolean):
|
|
809
|
+
_push(jsonApiDoc: JsonApiDocument, asyncFlush?: boolean): PersistedResourceKey | PersistedResourceKey[] | null;
|
|
1572
810
|
/**
|
|
1573
|
-
*
|
|
1574
|
-
*
|
|
1575
|
-
* Returns a promise resolving with the same record when the save is complete.
|
|
811
|
+
* Returns the cache instance associated to this Store, instantiates the Cache
|
|
812
|
+
* if necessary via `Store.createCache`
|
|
1576
813
|
*
|
|
1577
814
|
* @public
|
|
1578
|
-
* @param {unknown} record
|
|
1579
|
-
* @param options
|
|
1580
|
-
* @return {Promise<record>}
|
|
1581
815
|
*/
|
|
1582
|
-
|
|
816
|
+
get cache(): ReturnType<this["createCache"]>;
|
|
817
|
+
/** @private */
|
|
818
|
+
destroy(): void;
|
|
1583
819
|
/**
|
|
1584
|
-
*
|
|
1585
|
-
* to utilize a custom Cache implementation.
|
|
820
|
+
* This method
|
|
1586
821
|
*
|
|
1587
|
-
*
|
|
1588
|
-
|
|
822
|
+
* @private
|
|
823
|
+
*/
|
|
824
|
+
static create(args?: Record<string, unknown>): Store;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* This type exists for internal use only for
|
|
828
|
+
* where intimate contracts still exist either for
|
|
829
|
+
* the Test Suite or for Legacy code.
|
|
830
|
+
*
|
|
831
|
+
* @private
|
|
832
|
+
*/
|
|
833
|
+
export interface PrivateStore extends Store {
|
|
834
|
+
readonly recordArrayManager: PrivateRecordArrayManager;
|
|
835
|
+
notifications: PrivateNotificationManager;
|
|
836
|
+
requestManager: PrivateRequestManager;
|
|
837
|
+
cacheKeyManager: PrivateCacheKeyManager;
|
|
838
|
+
_schema: SchemaService;
|
|
839
|
+
_graph?: Graph;
|
|
840
|
+
_requestCache: PrivateRequestStateService;
|
|
841
|
+
getRequestStateService(): PrivateRequestStateService;
|
|
842
|
+
_instanceCache: InstanceCache;
|
|
843
|
+
_cbs: {
|
|
844
|
+
coalesce?: () => void;
|
|
845
|
+
sync?: () => void;
|
|
846
|
+
notify?: () => void;
|
|
847
|
+
} | null;
|
|
848
|
+
_forceShim: boolean;
|
|
849
|
+
/**
|
|
850
|
+
* Async flush buffers notifications until flushed
|
|
851
|
+
* by finalization of a future configured by store.request
|
|
1589
852
|
*
|
|
1590
|
-
*
|
|
1591
|
-
*
|
|
1592
|
-
*
|
|
853
|
+
* This is useful for ensuring that notifications are delivered
|
|
854
|
+
* prior to the promise resolving but without risk of promise
|
|
855
|
+
* interleaving.
|
|
1593
856
|
*/
|
|
857
|
+
_enableAsyncFlush: boolean | null;
|
|
1594
858
|
/**
|
|
1595
|
-
*
|
|
1596
|
-
|
|
859
|
+
* Available in DEBUG Only
|
|
860
|
+
*/
|
|
861
|
+
DISABLE_WAITER?: boolean;
|
|
862
|
+
_isDestroying: boolean;
|
|
863
|
+
_isDestroyed: boolean;
|
|
864
|
+
isDestroying: boolean;
|
|
865
|
+
isDestroyed: boolean;
|
|
866
|
+
_run(cb: () => void): void;
|
|
867
|
+
/**
|
|
868
|
+
* Executes the callback, ensurng that any work that calls
|
|
869
|
+
* store._schedule is executed after in the right order.
|
|
870
|
+
*
|
|
871
|
+
* When queues already exist, scheduled callbacks will
|
|
872
|
+
* join the existing queue.
|
|
1597
873
|
*
|
|
1598
|
-
* @property cache
|
|
1599
|
-
* @type {Cache}
|
|
1600
|
-
* @public
|
|
1601
874
|
*/
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
875
|
+
_join(cb: () => void): void;
|
|
876
|
+
_schedule(name: "coalesce" | "sync" | "notify", cb: () => void): void;
|
|
877
|
+
_getAllPending(): (Promise<unknown[]> & {
|
|
878
|
+
length: number;
|
|
879
|
+
}) | void;
|
|
1605
880
|
}
|
|
881
|
+
/**
|
|
882
|
+
* Upgrade the type for Store to PrivateStore, which will also
|
|
883
|
+
* upgrade any associated types to their private equivalents.
|
|
884
|
+
*
|
|
885
|
+
* @private
|
|
886
|
+
*/
|
|
887
|
+
export declare function assertPrivateStore(store: unknown): asserts store is PrivateStore;
|
|
888
|
+
/**
|
|
889
|
+
* Upgrade the type for Store to PrivateStore, which will also
|
|
890
|
+
* upgrade any associated types to their private equivalents.
|
|
891
|
+
*
|
|
892
|
+
* @private
|
|
893
|
+
*/
|
|
894
|
+
export declare function isPrivateStore(store: unknown): PrivateStore;
|
|
895
|
+
export declare function isMaybeIdentifier(maybeIdentifier: string | ResourceIdentifierObject): maybeIdentifier is ResourceIdentifierObject;
|