@warp-drive/core 5.6.0 → 5.7.0-alpha.1

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.
@@ -7,19 +7,16 @@ import type { TypedRecordInstance, TypeFromInstance } from "../../types/record.j
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
14
  import { IdentifierCache } from "./caches/identifier-cache.js";
17
15
  import { InstanceCache, storeFor } from "./caches/instance-cache.js";
18
- import type RecordReference from "./legacy-model-support/record-reference.js";
19
16
  import NotificationManager from "./managers/notification-manager.js";
20
17
  import { RecordArrayManager } from "./managers/record-array-manager.js";
21
18
  import { RequestStateService } from "./network/request-cache.js";
22
- import type { Collection, IdentifierArray } from "./record-arrays/identifier-array.js";
19
+ import type { IdentifierArray } from "./record-arrays/identifier-array.js";
23
20
  export { storeFor };
24
21
  // We inline this list of methods to avoid importing EmberObject
25
22
  type EmberObjectKey = "_debugContainerKey" | "_super" | "addObserver" | "cacheFor" | "concatenatedProperties" | "decrementProperty" | "destroy" | "get" | "getProperties" | "incrementProperty" | "init" | "isDestroyed" | "isDestroying" | "mergedProperties" | "notifyPropertyChange" | "removeObserver" | "reopen" | "set" | "setProperties" | "toggleProperty" | "toString" | "willDestroy";
@@ -54,6 +51,15 @@ type ConstructorFunction = new (...args: any[]) => any;
54
51
  declare const EmptyClass: ConstructorFunction;
55
52
  declare const BaseClass: typeof EmptyClass;
56
53
  export interface Store {
54
+ /**
55
+ * Instantiation hook allowing applications or addons to configure the store
56
+ * to utilize a custom Cache implementation.
57
+ *
58
+ * This hook should not be called directly by consuming applications or libraries.
59
+ * Use `Store.cache` to access the Cache instance.
60
+ *
61
+ * @public
62
+ */
57
63
  createCache(capabilities: CacheCapabilitiesManager): Cache;
58
64
  /**
59
65
  * A hook which an app or addon may implement. Called when
@@ -502,30 +508,6 @@ export declare class Store extends BaseClass {
502
508
  T = unknown
503
509
  >(requestConfig: StoreRequestInput<RT, T>): Future<RT>;
504
510
  /**
505
- Returns the schema for a particular resource type (modelName).
506
-
507
- When used with Model from @ember-data/model the return is the model class,
508
- but this is not guaranteed.
509
-
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
511
  Create a new record in the current store. The properties passed
530
512
  to this method are set on the newly created record.
531
513
 
@@ -588,401 +570,6 @@ export declare class Store extends BaseClass {
588
570
  */
589
571
  unloadRecord<T>(record: T): void;
590
572
  /**
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
573
  Get a record by a given type and ID without triggering a fetch.
987
574
 
988
575
  This method will synchronously return the record if it is available in the store,
@@ -1034,336 +621,6 @@ export declare class Store extends BaseClass {
1034
621
  peekRecord<T>(identifier: ResourceIdentifierObject<TypeFromInstance<T>>): T | null;
1035
622
  peekRecord(identifier: ResourceIdentifierObject): unknown | null;
1036
623
  /**
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
624
  This method returns a filtered array that contains all of the
1368
625
  known records for a given type in the store.
1369
626
 
@@ -1570,36 +827,19 @@ export declare class Store extends BaseClass {
1570
827
  */
1571
828
  _push(jsonApiDoc: JsonApiDocument, asyncFlush?: boolean): StableExistingRecordIdentifier | StableExistingRecordIdentifier[] | null;
1572
829
  /**
1573
- * Trigger a save for a Record.
1574
- *
1575
- * Returns a promise resolving with the same record when the save is complete.
1576
- *
1577
- * @public
1578
- * @param {unknown} record
1579
- * @param options
1580
- * @return {Promise<record>}
1581
- */
1582
- saveRecord<T>(record: T, options?: Record<string, unknown>): Promise<T>;
1583
- /**
1584
- * Instantiation hook allowing applications or addons to configure the store
1585
- * to utilize a custom Cache implementation.
1586
- *
1587
- * This hook should not be called directly by consuming applications or libraries.
1588
- * Use `Store.cache` to access the Cache instance.
1589
- *
1590
- * @public
1591
- * @param storeWrapper
1592
- * @return {Cache}
1593
- */
1594
- /**
1595
830
  * Returns the cache instance associated to this Store, instantiates the Cache
1596
831
  * if necessary via `Store.createCache`
1597
832
  *
1598
- * @property cache
1599
- * @type {Cache}
1600
833
  * @public
1601
834
  */
1602
835
  get cache(): ReturnType<this["createCache"]>;
836
+ /** @internal */
1603
837
  destroy(): void;
838
+ /**
839
+ * This method
840
+ *
841
+ * @private
842
+ */
1604
843
  static create(args?: Record<string, unknown>): Store;
1605
844
  }
845
+ export declare function isMaybeIdentifier(maybeIdentifier: string | ResourceIdentifierObject): maybeIdentifier is ResourceIdentifierObject;