@warp-drive/core 5.6.0-beta.0 → 5.6.0-beta.2

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 (120) hide show
  1. package/declarations/graph/-private/-diff.d.ts +7 -20
  2. package/declarations/graph/-private/-edge-definition.d.ts +3 -12
  3. package/declarations/graph/-private/-state.d.ts +2 -2
  4. package/declarations/graph/-private/-utils.d.ts +5 -5
  5. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +3 -3
  6. package/declarations/graph/-private/edges/collection.d.ts +10 -10
  7. package/declarations/graph/-private/edges/implicit.d.ts +5 -5
  8. package/declarations/graph/-private/edges/resource.d.ts +6 -7
  9. package/declarations/graph/-private/graph.d.ts +17 -15
  10. package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -4
  11. package/declarations/graph/-private/operations/update-relationship.d.ts +3 -3
  12. package/declarations/index.d.ts +1 -1
  13. package/declarations/reactive/-private/default-mode.d.ts +73 -0
  14. package/declarations/reactive/-private/document.d.ts +11 -27
  15. package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
  16. package/declarations/reactive/-private/fields/managed-array.d.ts +7 -10
  17. package/declarations/reactive/-private/fields/managed-object.d.ts +7 -9
  18. package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
  19. package/declarations/reactive/-private/hooks.d.ts +2 -2
  20. package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
  21. package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
  22. package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
  23. package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
  24. package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
  25. package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
  26. package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
  27. package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
  28. package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
  29. package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
  30. package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
  31. package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
  32. package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
  33. package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
  34. package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
  35. package/declarations/reactive/-private/record.d.ts +44 -33
  36. package/declarations/reactive/-private/schema.d.ts +50 -66
  37. package/declarations/reactive/-private/symbols.d.ts +2 -7
  38. package/declarations/reactive/-private.d.ts +1 -1
  39. package/declarations/reactive.d.ts +278 -1
  40. package/declarations/request/-private/context.d.ts +3 -5
  41. package/declarations/request/-private/fetch.d.ts +2 -0
  42. package/declarations/request/-private/manager.d.ts +24 -28
  43. package/declarations/request/-private/types.d.ts +22 -23
  44. package/declarations/request/-private/utils.d.ts +44 -2
  45. package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
  46. package/declarations/store/-private/cache-handler/types.d.ts +10 -10
  47. package/declarations/store/-private/cache-handler/utils.d.ts +4 -4
  48. package/declarations/store/-private/caches/instance-cache.d.ts +22 -27
  49. package/declarations/store/-private/debug/utils.d.ts +1 -0
  50. package/declarations/store/-private/default-cache-policy.d.ts +25 -38
  51. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
  52. package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +38 -52
  53. package/declarations/store/-private/managers/cache-manager.d.ts +46 -95
  54. package/declarations/store/-private/managers/notification-manager.d.ts +30 -43
  55. package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
  56. package/declarations/store/-private/network/request-cache.d.ts +21 -24
  57. package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
  58. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
  59. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
  60. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
  61. package/declarations/store/-private/new-core-tmp/request-state.d.ts +133 -37
  62. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -133
  63. package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
  64. package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
  65. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
  66. package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
  67. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
  68. package/declarations/store/-private/record-arrays/resource-array.d.ts +75 -0
  69. package/declarations/store/-private/store-service.d.ts +167 -872
  70. package/declarations/store/-private.d.ts +14 -10
  71. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
  72. package/declarations/store/-types/q/identifier.d.ts +9 -6
  73. package/declarations/store/-types/q/record-instance.d.ts +0 -1
  74. package/declarations/store/-types/q/schema-service.d.ts +64 -40
  75. package/declarations/store/-types/q/store.d.ts +6 -7
  76. package/declarations/store/deprecated/-private.d.ts +224 -0
  77. package/declarations/store/deprecated/store.d.ts +787 -0
  78. package/declarations/types/-private.d.ts +1 -1
  79. package/declarations/types/cache/aliases.d.ts +2 -2
  80. package/declarations/types/cache/change.d.ts +2 -2
  81. package/declarations/types/cache/mutations.d.ts +13 -13
  82. package/declarations/types/cache/operations.d.ts +115 -32
  83. package/declarations/types/cache/relationship.d.ts +4 -4
  84. package/declarations/types/cache.d.ts +51 -115
  85. package/declarations/types/graph.d.ts +12 -12
  86. package/declarations/types/identifier.d.ts +52 -76
  87. package/declarations/types/params.d.ts +2 -3
  88. package/declarations/types/request.d.ts +69 -42
  89. package/declarations/types/schema/concepts.d.ts +2 -2
  90. package/declarations/types/schema/fields.d.ts +391 -14
  91. package/declarations/types/spec/document.d.ts +6 -6
  92. package/declarations/types/spec/json-api-raw.d.ts +6 -8
  93. package/declarations/types.d.ts +2 -1
  94. package/declarations/utils/string.d.ts +2 -2
  95. package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
  96. package/dist/configure.js +1 -1
  97. package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
  98. package/dist/graph/-private.js +137 -144
  99. package/dist/index.js +25 -14
  100. package/dist/reactive/-private.js +1 -1
  101. package/dist/reactive.js +337 -1422
  102. package/dist/{request-state-CjLph1LP.js → request-state-C955e0AL.js} +8352 -5912
  103. package/dist/request.js +1 -1
  104. package/dist/store/-private.js +2 -3
  105. package/dist/store.js +32 -44
  106. package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
  107. package/dist/types/-private.js +1 -1
  108. package/dist/types/identifier.js +19 -45
  109. package/dist/types/request.js +45 -3
  110. package/dist/types/schema/fields.js +23 -2
  111. package/dist/utils/string.js +2 -2
  112. package/package.json +10 -10
  113. package/declarations/reactive/-private/fields/compute.d.ts +0 -43
  114. package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
  115. package/declarations/store/-private/legacy-model-support/record-reference.d.ts +0 -159
  116. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
  117. package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
  118. package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
  119. package/declarations/store/-types/q/ds-model.d.ts +0 -21
  120. package/dist/handler-C2T-IyJK.js +0 -339
@@ -1,25 +1,25 @@
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 { StableExistingRecordIdentifier, StableRecordIdentifier } from "../../types/identifier.js";
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 RecordReference from "./legacy-model-support/record-reference.js";
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 { RecordArrayManager } from "./managers/record-array-manager.js";
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 { Collection, IdentifierArray } from "./record-arrays/identifier-array.js";
22
+ import type { LegacyLiveArray } from "./record-arrays/legacy-live-array.js";
23
23
  export { storeFor };
24
24
  // We inline this list of methods to avoid importing EmberObject
25
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";
@@ -48,12 +48,24 @@ type MaybeHasId = {
48
48
  *
49
49
  */
50
50
  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
+ export interface CreateContext {
52
+ lid?: string;
53
+ }
51
54
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
55
  type ConstructorFunction = new (...args: any[]) => any;
53
56
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
54
57
  declare const EmptyClass: ConstructorFunction;
55
58
  declare const BaseClass: typeof EmptyClass;
56
59
  export interface Store {
60
+ /**
61
+ * Instantiation hook allowing applications or addons to configure the store
62
+ * to utilize a custom Cache implementation.
63
+ *
64
+ * This hook should not be called directly by consuming applications or libraries.
65
+ * Use `Store.cache` to access the Cache instance.
66
+ *
67
+ * @public
68
+ */
57
69
  createCache(capabilities: CacheCapabilitiesManager): Cache;
58
70
  /**
59
71
  * A hook which an app or addon may implement. Called when
@@ -70,7 +82,7 @@ export interface Store {
70
82
  * @public
71
83
  */
72
84
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
73
- instantiateRecord<T>(identifier: StableRecordIdentifier, createRecordArgs: {
85
+ instantiateRecord<T>(identifier: ResourceKey, createRecordArgs: {
74
86
  [key: string]: unknown;
75
87
  }): OpaqueRecordInstance;
76
88
  /**
@@ -138,7 +150,6 @@ export interface Store {
138
150
  * be sourced from directly registered schemas, then will fallback
139
151
  * to sourcing a schema from available models if no schema is found.
140
152
  *
141
- * @return {SchemaService}
142
153
  * @public
143
154
  */
144
155
  createSchemaService(): SchemaService;
@@ -184,11 +195,11 @@ export interface Store {
184
195
  * return this._schema.hasResource(resource);
185
196
  * }
186
197
  *
187
- * attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {
198
+ * attributesDefinitionFor(identifier: ResourceKey | { type: string }): AttributesSchema {
188
199
  * return this._schema.attributesDefinitionFor(identifier);
189
200
  * }
190
201
  *
191
- * relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {
202
+ * relationshipsDefinitionFor(identifier: ResourceKey | { type: string }): RelationshipsSchema {
192
203
  * const schema = AbstractSchemas.get(identifier.type);
193
204
  * return schema || this._schema.relationshipsDefinitionFor(identifier);
194
205
  * }
@@ -238,11 +249,11 @@ export interface Store {
238
249
  * return this._schema.hasResource(resource);
239
250
  * }
240
251
  *
241
- * attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {
252
+ * attributesDefinitionFor(identifier: ResourceKey | { type: string }): AttributesSchema {
242
253
  * return this._schema.attributesDefinitionFor(identifier);
243
254
  * }
244
255
  *
245
- * relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {
256
+ * relationshipsDefinitionFor(identifier: ResourceKey | { type: string }): RelationshipsSchema {
246
257
  * const schema = AbstractSchemas.get(identifier.type);
247
258
  * return schema || this._schema.relationshipsDefinitionFor(identifier);
248
259
  * }
@@ -283,8 +294,6 @@ export interface Store {
283
294
  * @hideconstructor
284
295
  */
285
296
  export declare class Store extends BaseClass {
286
- /** @internal */
287
- readonly recordArrayManager: RecordArrayManager;
288
297
  /**
289
298
  * Provides access to the NotificationManager associated
290
299
  * with this Store instance.
@@ -305,18 +314,17 @@ export declare class Store extends BaseClass {
305
314
  * @public
306
315
  */
307
316
  get schema(): ReturnType<this["createSchemaService"]>;
308
- /** @internal */
309
- _schema: SchemaService;
310
317
  /**
311
- * Provides access to the IdentifierCache instance
318
+ * Provides access to the CacheKeyManager
312
319
  * for this store.
313
320
  *
314
- * The IdentifierCache can be used to generate or
315
- * retrieve a stable unique identifier for any resource.
321
+ * The CacheKeyManager can be used to generate or
322
+ * retrieve a stable unique CacheKey for any resource
323
+ * or request.
316
324
  *
317
325
  * @public
318
326
  */
319
- readonly identifierCache: IdentifierCache;
327
+ readonly cacheKeyManager: CacheKeyManager;
320
328
  /**
321
329
  * Provides access to the requestManager instance associated
322
330
  * with this Store instance.
@@ -347,7 +355,7 @@ export declare class Store extends BaseClass {
347
355
  *
348
356
  * Note, when defined, these methods will only be invoked if a
349
357
  * cache key exists for the request, either because the request
350
- * contains `cacheOptions.key` or because the [IdentifierCache](/ember-data/release/classes/IdentifierCache)
358
+ * contains `cacheOptions.key` or because the [CacheKeyManager](/ember-data/release/classes/CacheKeyManager)
351
359
  * was able to generate a key for the request using the configured
352
360
  * [generation method](/ember-data/release/functions/@ember-data%2Fstore/setIdentifierGenerationMethod).
353
361
  *
@@ -356,12 +364,12 @@ export declare class Store extends BaseClass {
356
364
  * ```ts
357
365
  * store.lifetimes = {
358
366
  * // make the request and ignore the current cache state
359
- * isHardExpired(identifier: StableDocumentIdentifier): boolean {
367
+ * isHardExpired(key: RequestKey): boolean {
360
368
  * return false;
361
369
  * }
362
370
  *
363
371
  * // make the request in the background if true, return cache state
364
- * isSoftExpired(identifier: StableDocumentIdentifier): boolean {
372
+ * isSoftExpired(key: RequestKey): boolean {
365
373
  * return false;
366
374
  * }
367
375
  * }
@@ -370,65 +378,16 @@ export declare class Store extends BaseClass {
370
378
  * @public
371
379
  */
372
380
  lifetimes?: CachePolicy;
373
- // Private
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 */
381
+ /** @private */
407
382
  get isDestroying(): boolean;
408
- /** @internal */
409
- set isDestroying(value: boolean);
410
- /** @internal */
383
+ /** @private */
411
384
  get isDestroyed(): boolean;
412
- /** @internal */
413
- set isDestroyed(value: boolean);
385
+ /** @deprecated use {@link Store.cacheKeyManager} */
386
+ get identifierCache(): CacheKeyManager;
414
387
  /**
415
388
  @private
416
389
  */
417
390
  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
391
  /**
433
392
  * Retrieve the RequestStateService instance
434
393
  * associated with this Store.
@@ -440,10 +399,6 @@ export declare class Store extends BaseClass {
440
399
  * @public
441
400
  */
442
401
  getRequestStateService(): RequestStateService;
443
- /** @internal */
444
- _getAllPending(): (Promise<unknown[]> & {
445
- length: number;
446
- }) | void;
447
402
  /**
448
403
  * ::: tip 💡 For a more complete overview see the [Request Guide](/guides/2-requests/1-overview)
449
404
  * :::
@@ -458,7 +413,7 @@ export declare class Store extends BaseClass {
458
413
  * {@link CacheOptions.key | cache key} will have the request result
459
414
  * and document cached.
460
415
  *
461
- * The cache key used is {@link RequestInfo.cacheOptions | RequestInfo.cacheOptions.key}
416
+ * The cache key used is {@link RequestInfo.cacheOptions.key | RequestInfo.cacheOptions.key}
462
417
  * if present, falling back to {@link RequestInfo.url}.
463
418
  *
464
419
  * Params are not serialized as part of the cache-key, so
@@ -497,64 +452,77 @@ export declare class Store extends BaseClass {
497
452
  *
498
453
  * @public
499
454
  */
500
- request<
501
- RT,
502
- T = unknown
503
- >(requestConfig: StoreRequestInput<RT, T>): Future<RT>;
455
+ request<RT>(requestConfig: StoreRequestInput<RT>): Future<RT>;
504
456
  /**
505
- Returns the schema for a particular resource type (modelName).
457
+ Creates a new record in the current store.
506
458
 
507
- When used with Model from @ember-data/model the return is the model class,
508
- but this is not guaranteed.
459
+ > [!CAUTION]
460
+ > This should not be used to mock records or to create
461
+ > a record representing data that could be fetched from
462
+ > the API.
509
463
 
510
- If looking to query attribute or relationship information it is
511
- recommended to use `getSchemaDefinitionService` instead. This method
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.
464
+ The properties passed to this method are set on
465
+ the newly created record.
531
466
 
532
- To create a new instance of a `Post`:
467
+ For instance: to create a new `post`:
533
468
 
534
469
  ```js
535
470
  store.createRecord('post', {
536
- title: 'Ember is awesome!'
471
+ title: 'WarpDrive is Stellar!'
537
472
  });
538
473
  ```
539
474
 
540
- To create a new instance of a `Post` that has a relationship with a `User` record:
475
+ Relationships can be set during create. For instance,
476
+ to create a new `post` that has an existing user as
477
+ it's author:
541
478
 
542
479
  ```js
543
- let user = this.store.peekRecord('user', '1');
480
+ const user = store.peekRecord('user', '1');
481
+
544
482
  store.createRecord('post', {
545
- title: 'Ember is awesome!',
483
+ title: 'WarpDrive is Stellar!',
546
484
  user: user
547
485
  });
548
486
  ```
549
487
 
488
+ ### lid handling
489
+
490
+ All new records are assigned an `lid` that can be used to handle
491
+ transactional saves of multiple records, or to link the data to
492
+ other data in scenarios involving eventual-consistency or remote
493
+ syncing.
494
+
495
+ ```ts
496
+ const post = store.createRecord('post', {
497
+ title: 'WarpDrive is Stellar!'
498
+ });
499
+ const { lid } = recordIdentifierFor(post);
500
+ ```
501
+
502
+ The `lid` defaults to a uuidv4 string.
503
+
504
+ In order to support receiving knowledge about unpersisted creates
505
+ from other sources (say a different tab in the same web-browser),
506
+ createRecord allows for the `lid` to be provided as part of an
507
+ optional third argument. **If this lid already exists in the store
508
+ an error will be thrown.**
509
+
510
+ ```ts
511
+ const post = store.createRecord(
512
+ 'post',
513
+ { title: 'WarpDrive is Stellar!' },
514
+ { lid: '4d47bb88-931f-496e-986d-c4888cef7373' }
515
+ );
516
+ ```
517
+
550
518
  @public
551
- @param {String} type the name of the resource
552
- @param {Object} inputProperties a hash of properties to set on the
519
+ @param type the name of the resource
520
+ @param inputProperties a hash of properties to set on the
553
521
  newly created record.
554
- @return {Model} record
522
+ @return a record in the "isNew" state
555
523
  */
556
- createRecord<T>(type: TypeFromInstance<T>, inputProperties: CreateRecordProperties<T>): T;
557
- createRecord(type: string, inputProperties: CreateRecordProperties): OpaqueRecordInstance;
524
+ createRecord<T>(type: TypeFromInstance<T>, inputProperties: CreateRecordProperties<T>, context?: CreateContext): T;
525
+ createRecord(type: string, inputProperties: CreateRecordProperties, context?: CreateContext): OpaqueRecordInstance;
558
526
  /**
559
527
  For symmetry, a record can be deleted via the store.
560
528
 
@@ -588,401 +556,6 @@ export declare class Store extends BaseClass {
588
556
  */
589
557
  unloadRecord<T>(record: T): void;
590
558
  /**
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
559
  Get a record by a given type and ID without triggering a fetch.
987
560
 
988
561
  This method will synchronously return the record if it is available in the store,
@@ -1034,336 +607,6 @@ export declare class Store extends BaseClass {
1034
607
  peekRecord<T>(identifier: ResourceIdentifierObject<TypeFromInstance<T>>): T | null;
1035
608
  peekRecord(identifier: ResourceIdentifierObject): unknown | null;
1036
609
  /**
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
610
  This method returns a filtered array that contains all of the
1368
611
  known records for a given type in the store.
1369
612
 
@@ -1387,8 +630,8 @@ export declare class Store extends BaseClass {
1387
630
  @param {String} type the name of the resource
1388
631
  @return {RecordArray}
1389
632
  */
1390
- peekAll<T>(type: TypeFromInstance<T>): IdentifierArray<T>;
1391
- peekAll(type: string): IdentifierArray;
633
+ peekAll<T>(type: TypeFromInstance<T>): LegacyLiveArray<T>;
634
+ peekAll(type: string): LegacyLiveArray;
1392
635
  /**
1393
636
  This method unloads all records in the store.
1394
637
  It schedules unloading to happen during the next run loop.
@@ -1566,40 +809,92 @@ export declare class Store extends BaseClass {
1566
809
 
1567
810
  @private
1568
811
  @param {Object} jsonApiDoc
1569
- @return {StableRecordIdentifier|Array<StableRecordIdentifier>|null} identifiers for the primary records that had data loaded
812
+ @return {ResourceKey|Array<ResourceKey>|null} identifiers for the primary records that had data loaded
1570
813
  */
1571
- _push(jsonApiDoc: JsonApiDocument, asyncFlush?: boolean): StableExistingRecordIdentifier | StableExistingRecordIdentifier[] | null;
814
+ _push(jsonApiDoc: JsonApiDocument, asyncFlush?: boolean): PersistedResourceKey | PersistedResourceKey[] | null;
1572
815
  /**
1573
- * Trigger a save for a Record.
1574
- *
1575
- * Returns a promise resolving with the same record when the save is complete.
816
+ * Returns the cache instance associated to this Store, instantiates the Cache
817
+ * if necessary via `Store.createCache`
1576
818
  *
1577
819
  * @public
1578
- * @param {unknown} record
1579
- * @param options
1580
- * @return {Promise<record>}
1581
820
  */
1582
- saveRecord<T>(record: T, options?: Record<string, unknown>): Promise<T>;
821
+ get cache(): ReturnType<this["createCache"]>;
822
+ /** @private */
823
+ destroy(): void;
1583
824
  /**
1584
- * Instantiation hook allowing applications or addons to configure the store
1585
- * to utilize a custom Cache implementation.
825
+ * This method
1586
826
  *
1587
- * This hook should not be called directly by consuming applications or libraries.
1588
- * Use `Store.cache` to access the Cache instance.
827
+ * @private
828
+ */
829
+ static create(args?: Record<string, unknown>): Store;
830
+ }
831
+ /**
832
+ * This type exists for internal use only for
833
+ * where intimate contracts still exist either for
834
+ * the Test Suite or for Legacy code.
835
+ *
836
+ * @private
837
+ */
838
+ export interface PrivateStore extends Store {
839
+ readonly recordArrayManager: PrivateRecordArrayManager;
840
+ notifications: PrivateNotificationManager;
841
+ requestManager: PrivateRequestManager;
842
+ cacheKeyManager: PrivateCacheKeyManager;
843
+ _schema: SchemaService;
844
+ _graph?: Graph;
845
+ _requestCache: PrivateRequestStateService;
846
+ getRequestStateService(): PrivateRequestStateService;
847
+ _instanceCache: InstanceCache;
848
+ _cbs: {
849
+ coalesce?: () => void;
850
+ sync?: () => void;
851
+ notify?: () => void;
852
+ } | null;
853
+ _forceShim: boolean;
854
+ /**
855
+ * Async flush buffers notifications until flushed
856
+ * by finalization of a future configured by store.request
1589
857
  *
1590
- * @public
1591
- * @param storeWrapper
1592
- * @return {Cache}
858
+ * This is useful for ensuring that notifications are delivered
859
+ * prior to the promise resolving but without risk of promise
860
+ * interleaving.
1593
861
  */
862
+ _enableAsyncFlush: boolean | null;
1594
863
  /**
1595
- * Returns the cache instance associated to this Store, instantiates the Cache
1596
- * if necessary via `Store.createCache`
864
+ * Available in DEBUG Only
865
+ */
866
+ DISABLE_WAITER?: boolean;
867
+ _isDestroying: boolean;
868
+ _isDestroyed: boolean;
869
+ isDestroying: boolean;
870
+ isDestroyed: boolean;
871
+ _run(cb: () => void): void;
872
+ /**
873
+ * Executes the callback, ensurng that any work that calls
874
+ * store._schedule is executed after in the right order.
875
+ *
876
+ * When queues already exist, scheduled callbacks will
877
+ * join the existing queue.
1597
878
  *
1598
- * @property cache
1599
- * @type {Cache}
1600
- * @public
1601
879
  */
1602
- get cache(): ReturnType<this["createCache"]>;
1603
- destroy(): void;
1604
- static create(args?: Record<string, unknown>): Store;
880
+ _join(cb: () => void): void;
881
+ _schedule(name: "coalesce" | "sync" | "notify", cb: () => void): void;
882
+ _getAllPending(): (Promise<unknown[]> & {
883
+ length: number;
884
+ }) | void;
1605
885
  }
886
+ /**
887
+ * Upgrade the type for Store to PrivateStore, which will also
888
+ * upgrade any associated types to their private equivalents.
889
+ *
890
+ * @private
891
+ */
892
+ export declare function assertPrivateStore(store: unknown): asserts store is PrivateStore;
893
+ /**
894
+ * Upgrade the type for Store to PrivateStore, which will also
895
+ * upgrade any associated types to their private equivalents.
896
+ *
897
+ * @private
898
+ */
899
+ export declare function isPrivateStore(store: unknown): PrivateStore;
900
+ export declare function isMaybeIdentifier(maybeIdentifier: string | ResourceIdentifierObject): maybeIdentifier is ResourceIdentifierObject;