@warp-drive/core 5.8.0-alpha.0 → 5.8.0-alpha.11
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/README.md +6 -3
- package/declarations/build-config.d.ts +18 -1
- package/declarations/index.d.ts +80 -3
- package/declarations/reactive/-private/document.d.ts +58 -46
- package/declarations/reactive/-private/schema.d.ts +77 -4
- package/declarations/reactive.d.ts +13 -7
- package/declarations/request/-private/types.d.ts +1 -1
- package/declarations/request.d.ts +47 -0
- package/declarations/store/-private/caches/instance-cache.d.ts +4 -5
- package/declarations/store/-private/default-cache-policy.d.ts +147 -129
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/-private/managers/cache-key-manager.d.ts +26 -8
- package/declarations/store/-private/managers/cache-manager.d.ts +6 -4
- package/declarations/store/-private/managers/notification-manager.d.ts +1 -1
- package/declarations/store/-private/new-core-tmp/promise-state.d.ts +1 -0
- package/declarations/store/-private/store-service.d.ts +43 -64
- package/declarations/store/-private.d.ts +0 -1
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/deprecated/store.d.ts +33 -32
- package/declarations/store.d.ts +1 -0
- package/declarations/types/cache.d.ts +8 -6
- package/declarations/types/request.d.ts +26 -14
- package/declarations/types/schema/fields.d.ts +15 -4
- package/declarations/{store/-types/q → types/schema}/schema-service.d.ts +11 -9
- package/declarations/types/spec/document.d.ts +34 -0
- package/declarations/types/symbols.d.ts +2 -2
- package/declarations/types.d.ts +1 -1
- package/dist/build-config.js +1 -1
- package/dist/default-cache-policy-D7_u4YRH.js +572 -0
- package/dist/graph/-private.js +1 -1
- package/dist/{request-state-C955e0AL.js → index-D-cCuZLH.js} +10010 -8858
- package/dist/index.js +6 -382
- package/dist/reactive.js +4 -778
- package/dist/{context-C_7OLieY.js → request-oqoLC9rz.js} +219 -172
- package/dist/request.js +1 -1
- package/dist/store/-private.js +1 -1
- package/dist/store.js +1 -533
- package/dist/types/-private.js +1 -1
- package/dist/types/request.js +14 -12
- package/dist/types/runtime.js +1 -1
- package/dist/types/schema/fields.js +14 -0
- package/dist/types/schema/schema-service.js +0 -0
- package/dist/types/symbols.js +2 -2
- package/package.json +4 -4
|
@@ -4,18 +4,18 @@ import type { PrivateRequestManager, RequestManager } from "../../request/-priva
|
|
|
4
4
|
import type { Cache } from "../../types/cache.js";
|
|
5
5
|
import type { PersistedResourceKey, ResourceKey } from "../../types/identifier.js";
|
|
6
6
|
import type { TypedRecordInstance, TypeFromInstance } from "../../types/record.js";
|
|
7
|
+
import type { SchemaService } from "../../types/schema/schema-service.js";
|
|
7
8
|
import type { CollectionResourceDocument, EmptyResourceDocument, JsonApiDocument, ResourceIdentifierObject, SingleResourceDocument } from "../../types/spec/json-api-raw.js";
|
|
8
9
|
import type { Type } from "../../types/symbols.js";
|
|
9
10
|
import type { CacheCapabilitiesManager } from "../-types/q/cache-capabilities-manager.js";
|
|
10
11
|
import type { OpaqueRecordInstance } from "../-types/q/record-instance.js";
|
|
11
|
-
import type { SchemaService } from "../-types/q/schema-service.js";
|
|
12
12
|
import type { StoreRequestInput } from "./cache-handler/handler.js";
|
|
13
13
|
import type { CachePolicy } from "./cache-handler/types.js";
|
|
14
14
|
import { InstanceCache, storeFor } from "./caches/instance-cache.js";
|
|
15
15
|
import type { PrivateCacheKeyManager } from "./managers/cache-key-manager.js";
|
|
16
16
|
import { CacheKeyManager } from "./managers/cache-key-manager.js";
|
|
17
17
|
import type { PrivateNotificationManager } from "./managers/notification-manager.js";
|
|
18
|
-
import NotificationManager from "./managers/notification-manager.js";
|
|
18
|
+
import { NotificationManager } from "./managers/notification-manager.js";
|
|
19
19
|
import type { PrivateRecordArrayManager } from "./managers/record-array-manager.js";
|
|
20
20
|
import type { PrivateRequestStateService } from "./network/request-cache.js";
|
|
21
21
|
import { RequestStateService } from "./network/request-cache.js";
|
|
@@ -101,7 +101,7 @@ export interface Store {
|
|
|
101
101
|
* For Example, to use the default SchemaService for ReactiveResource
|
|
102
102
|
*
|
|
103
103
|
* ```ts
|
|
104
|
-
* import { SchemaService } from '@warp-drive/
|
|
104
|
+
* import { SchemaService } from '@warp-drive/core/reactive';
|
|
105
105
|
*
|
|
106
106
|
* class extends Store {
|
|
107
107
|
* createSchemaService() {
|
|
@@ -110,10 +110,10 @@ export interface Store {
|
|
|
110
110
|
* }
|
|
111
111
|
* ```
|
|
112
112
|
*
|
|
113
|
-
* Or to use the SchemaService for @
|
|
113
|
+
* Or to use the SchemaService for @warp-drive/legacy/model
|
|
114
114
|
*
|
|
115
115
|
* ```ts
|
|
116
|
-
* import { buildSchema } from '@
|
|
116
|
+
* import { buildSchema } from '@warp-drive/legacy/model';
|
|
117
117
|
*
|
|
118
118
|
* class extends Store {
|
|
119
119
|
* createSchemaService() {
|
|
@@ -125,13 +125,13 @@ export interface Store {
|
|
|
125
125
|
* If you wish to chain services, you must either
|
|
126
126
|
* instantiate each schema source directly or super to retrieve
|
|
127
127
|
* an existing service. For convenience, when migrating from
|
|
128
|
-
* `@
|
|
128
|
+
* `@warp-drive/legacy/model` to {@link ReactiveResource} a
|
|
129
129
|
* SchemaService is provided that handles this transition
|
|
130
130
|
* for you:
|
|
131
131
|
*
|
|
132
132
|
* ```ts
|
|
133
|
-
* import { DelegatingSchemaService } from '@
|
|
134
|
-
* import { SchemaService } from '@warp-drive/
|
|
133
|
+
* import { DelegatingSchemaService } from '@warp-drive/legacy/model/migration-support';
|
|
134
|
+
* import { SchemaService } from '@warp-drive/core/reactive';
|
|
135
135
|
*
|
|
136
136
|
* class extends Store {
|
|
137
137
|
* createSchemaService() {
|
|
@@ -176,7 +176,7 @@ export interface Store {
|
|
|
176
176
|
* For Example:
|
|
177
177
|
*
|
|
178
178
|
* ```ts
|
|
179
|
-
* import Store from '@
|
|
179
|
+
* import { Store } from '@warp-drive/core';
|
|
180
180
|
*
|
|
181
181
|
* class SchemaDelegator {
|
|
182
182
|
* constructor(schema) {
|
|
@@ -210,7 +210,6 @@ export interface Store {
|
|
|
210
210
|
* }
|
|
211
211
|
* ```
|
|
212
212
|
*
|
|
213
|
-
* @param {SchemaService} schema
|
|
214
213
|
* @deprecated
|
|
215
214
|
* @public
|
|
216
215
|
*/
|
|
@@ -230,7 +229,7 @@ export interface Store {
|
|
|
230
229
|
* For Example:
|
|
231
230
|
*
|
|
232
231
|
* ```ts
|
|
233
|
-
* import Store from '@
|
|
232
|
+
* import { Store } from '@warp-drive/core';
|
|
234
233
|
*
|
|
235
234
|
* class SchemaDelegator {
|
|
236
235
|
* constructor(schema) {
|
|
@@ -264,7 +263,6 @@ export interface Store {
|
|
|
264
263
|
* }
|
|
265
264
|
* ```
|
|
266
265
|
*
|
|
267
|
-
* @param {SchemaService} schema
|
|
268
266
|
* @deprecated
|
|
269
267
|
* @public
|
|
270
268
|
*/
|
|
@@ -290,7 +288,7 @@ export interface Store {
|
|
|
290
288
|
*/
|
|
291
289
|
export declare class Store extends BaseClass {
|
|
292
290
|
/**
|
|
293
|
-
* Provides access to the NotificationManager associated
|
|
291
|
+
* Provides access to the {@link NotificationManager} associated
|
|
294
292
|
* with this Store instance.
|
|
295
293
|
*
|
|
296
294
|
* The NotificationManager can be used to subscribe to
|
|
@@ -321,20 +319,18 @@ export declare class Store extends BaseClass {
|
|
|
321
319
|
*/
|
|
322
320
|
readonly cacheKeyManager: CacheKeyManager;
|
|
323
321
|
/**
|
|
324
|
-
* Provides access to the
|
|
322
|
+
* Provides access to the {@link RequestManager} instance associated
|
|
325
323
|
* with this Store instance.
|
|
326
324
|
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
325
|
+
* See also:
|
|
326
|
+
* - {@link Fetch}
|
|
327
|
+
* - {@link CacheHandlerInterface | CacheHandler (Interface)}
|
|
328
|
+
* - {@link CacheHandler | CacheHandler (Class)}
|
|
331
329
|
*
|
|
332
330
|
* ```ts
|
|
333
|
-
* import
|
|
334
|
-
* import RequestManager from '@ember-data/request';
|
|
335
|
-
* import Fetch from '@ember-data/request/fetch';
|
|
331
|
+
* import { CacheHandler, Fetch, RequestManager, Store } from '@warp-drive/core';
|
|
336
332
|
*
|
|
337
|
-
* class extends Store {
|
|
333
|
+
* class AppStore extends Store {
|
|
338
334
|
* requestManager = new RequestManager()
|
|
339
335
|
* .use([Fetch])
|
|
340
336
|
* .useCache(CacheHandler);
|
|
@@ -350,9 +346,9 @@ export declare class Store extends BaseClass {
|
|
|
350
346
|
*
|
|
351
347
|
* Note, when defined, these methods will only be invoked if a
|
|
352
348
|
* cache key exists for the request, either because the request
|
|
353
|
-
* contains `cacheOptions.key` or because the
|
|
349
|
+
* contains `cacheOptions.key` or because the {@link CacheKeyManager}
|
|
354
350
|
* was able to generate a key for the request using the configured
|
|
355
|
-
*
|
|
351
|
+
* {@link setIdentifierGenerationMethod | generation method}.
|
|
356
352
|
*
|
|
357
353
|
* `isSoftExpired` will only be invoked if `isHardExpired` returns `false`.
|
|
358
354
|
*
|
|
@@ -557,14 +553,10 @@ export declare class Store extends BaseClass {
|
|
|
557
553
|
otherwise it will return `null`. A record is available if it has been fetched earlier, or
|
|
558
554
|
pushed manually into the store.
|
|
559
555
|
|
|
560
|
-
See [findRecord](../methods/findRecord?anchor=findRecord) if you would like to request this record from the backend.
|
|
561
|
-
|
|
562
|
-
_Note: This is a synchronous method and does not return a promise._
|
|
563
|
-
|
|
564
556
|
**Example 1**
|
|
565
557
|
|
|
566
|
-
```
|
|
567
|
-
|
|
558
|
+
```ts
|
|
559
|
+
const post = store.peekRecord('post', '1');
|
|
568
560
|
|
|
569
561
|
post.id; // '1'
|
|
570
562
|
```
|
|
@@ -575,8 +567,8 @@ export declare class Store extends BaseClass {
|
|
|
575
567
|
|
|
576
568
|
**Example 2**
|
|
577
569
|
|
|
578
|
-
```
|
|
579
|
-
|
|
570
|
+
```ts
|
|
571
|
+
const post = store.peekRecord({ type: 'post', id: '1' });
|
|
580
572
|
post.id; // '1'
|
|
581
573
|
```
|
|
582
574
|
|
|
@@ -590,40 +582,34 @@ export declare class Store extends BaseClass {
|
|
|
590
582
|
post.id; // '1'
|
|
591
583
|
```
|
|
592
584
|
|
|
593
|
-
|
|
594
585
|
@since 1.13.0
|
|
595
586
|
@public
|
|
596
|
-
@param
|
|
597
|
-
@param
|
|
598
|
-
@return {Model|null} record
|
|
587
|
+
@param type - either a string representing the modelName or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
|
|
588
|
+
@param id - optional only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved.
|
|
599
589
|
*/
|
|
600
590
|
peekRecord<T>(type: TypeFromInstance<T>, id: string | number): T | null;
|
|
601
591
|
peekRecord(type: string, id: string | number): unknown | null;
|
|
602
592
|
peekRecord<T>(identifier: ResourceIdentifierObject<TypeFromInstance<T>>): T | null;
|
|
603
593
|
peekRecord(identifier: ResourceIdentifierObject): unknown | null;
|
|
604
594
|
/**
|
|
605
|
-
This method returns
|
|
606
|
-
known records for a given type in the store.
|
|
595
|
+
This method returns the {@link LegacyLiveArray} that contains all of the
|
|
596
|
+
known records for a given type in the store. Each ResourceType has only
|
|
597
|
+
one LiveArray instance, so multiple calls to `peekAll` with the same type
|
|
598
|
+
will always return the same instance.
|
|
607
599
|
|
|
608
|
-
Note that because it's
|
|
600
|
+
Note that because it's a LiveArray, the result will contain any
|
|
609
601
|
locally created records of the type, however, it will not make a
|
|
610
|
-
request to the backend to retrieve additional records.
|
|
611
|
-
would like to request all the records from the backend please use
|
|
612
|
-
[store.findAll](../methods/findAll?anchor=findAll).
|
|
613
|
-
|
|
614
|
-
Also note that multiple calls to `peekAll` for a given type will always
|
|
615
|
-
return the same `RecordArray`.
|
|
602
|
+
request to the backend to retrieve additional records.
|
|
616
603
|
|
|
617
604
|
Example
|
|
618
605
|
|
|
619
|
-
```
|
|
620
|
-
|
|
606
|
+
```ts
|
|
607
|
+
const allPosts = store.peekAll('post');
|
|
621
608
|
```
|
|
622
609
|
|
|
623
610
|
@since 1.13.0
|
|
624
611
|
@public
|
|
625
|
-
@param
|
|
626
|
-
@return {RecordArray}
|
|
612
|
+
@param type the name of the resource
|
|
627
613
|
*/
|
|
628
614
|
peekAll<T>(type: TypeFromInstance<T>): LegacyLiveArray<T>;
|
|
629
615
|
peekAll(type: string): LegacyLiveArray;
|
|
@@ -708,7 +694,7 @@ export declare class Store extends BaseClass {
|
|
|
708
694
|
For this model:
|
|
709
695
|
|
|
710
696
|
```js [app/models/person.js]
|
|
711
|
-
import Model, { attr, hasMany } from '@
|
|
697
|
+
import Model, { attr, hasMany } from '@warp-drive/legacy/model';
|
|
712
698
|
|
|
713
699
|
export default class PersonRoute extends Route {
|
|
714
700
|
@attr('string') firstName;
|
|
@@ -775,23 +761,17 @@ export declare class Store extends BaseClass {
|
|
|
775
761
|
}
|
|
776
762
|
```
|
|
777
763
|
|
|
778
|
-
If you're streaming data or implementing
|
|
779
|
-
that you have converted the incoming data into this form.
|
|
780
|
-
store's [normalize](../methods/normalize?anchor=normalize) method is a convenience
|
|
781
|
-
helper for converting a json payload into the form Ember Data
|
|
782
|
-
expects.
|
|
783
|
-
|
|
784
|
-
```js
|
|
785
|
-
store.push(store.normalize('person', data));
|
|
786
|
-
```
|
|
764
|
+
If you're streaming data, or implementing response handling, make sure
|
|
765
|
+
that you have converted the incoming data into this form.
|
|
787
766
|
|
|
788
767
|
This method can be used both to push in brand new
|
|
789
768
|
records, as well as to update existing records.
|
|
790
769
|
|
|
770
|
+
See also {@link Cache.patch}
|
|
771
|
+
|
|
791
772
|
@public
|
|
792
|
-
@param
|
|
793
|
-
@return the record(s) that
|
|
794
|
-
updated.
|
|
773
|
+
@param data
|
|
774
|
+
@return the primary record(s) that created or updated.
|
|
795
775
|
*/
|
|
796
776
|
push(data: EmptyResourceDocument): null;
|
|
797
777
|
push<T>(data: SingleResourceDocument<TypeFromInstance<T>>): T;
|
|
@@ -803,8 +783,7 @@ export declare class Store extends BaseClass {
|
|
|
803
783
|
without creating materialized records.
|
|
804
784
|
|
|
805
785
|
@private
|
|
806
|
-
@
|
|
807
|
-
@return {ResourceKey|Array<ResourceKey>|null} identifiers for the primary records that had data loaded
|
|
786
|
+
@return identifiers for the primary records that had data loaded
|
|
808
787
|
*/
|
|
809
788
|
_push(jsonApiDoc: JsonApiDocument, asyncFlush?: boolean): PersistedResourceKey | PersistedResourceKey[] | null;
|
|
810
789
|
/**
|
|
@@ -22,7 +22,6 @@ export { normalizeModelName as _deprecatingNormalize } from "./-private/utils/no
|
|
|
22
22
|
export type { StoreRequestInput } from "./-private/cache-handler/handler.js";
|
|
23
23
|
export { type LegacyManyArray, type LegacyManyArray as RelatedCollection, createLegacyManyArray } from "./-private/record-arrays/legacy-many-array.js";
|
|
24
24
|
export { log, logGroup } from "./-private/debug/utils.js";
|
|
25
|
-
export { getPromiseState, type PromiseState } from "./-private/new-core-tmp/promise-state.js";
|
|
26
25
|
export { DISPOSE, createRequestSubscription, type RequestArgs, type SubscriptionArgs, type RequestComponentArgs, type RequestSubscription, type ContentFeatures, type RecoveryFeatures, type AutorefreshBehaviorCombos, type AutorefreshBehaviorType } from "./-private/new-core-tmp/request-subscription.js";
|
|
27
26
|
export { getRequestState, type RequestLoadingState, type RequestCacheRequestState as RequestState } from "./-private/new-core-tmp/request-state.js";
|
|
28
27
|
export { type SignalHooks, waitFor } from "./-private/new-core-tmp/reactivity/configure.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
|
|
2
|
+
import type { SchemaService } from "../../../types/schema/schema-service.js";
|
|
2
3
|
import type { CacheKeyManager } from "../../-private/managers/cache-key-manager.js";
|
|
3
4
|
import type { NotificationType } from "../../-private/managers/notification-manager.js";
|
|
4
|
-
import type { SchemaService } from "./schema-service.js";
|
|
5
5
|
/**
|
|
6
6
|
* CacheCapabilitiesManager provides encapsulated API access to the minimal
|
|
7
7
|
* subset of the Store's functionality that Cache implementations
|
|
@@ -248,13 +248,13 @@ declare module "../-private/store-service" {
|
|
|
248
248
|
}
|
|
249
249
|
```
|
|
250
250
|
|
|
251
|
-
See
|
|
251
|
+
See {@link Store.peekRecord | peekRecord} to get the cached version of a record.
|
|
252
252
|
|
|
253
253
|
### Retrieving Related Model Records
|
|
254
254
|
|
|
255
|
-
If you use an adapter such as
|
|
256
|
-
[
|
|
257
|
-
|
|
255
|
+
If you use an adapter such as the
|
|
256
|
+
[JSONAPIAdapter](/api/@warp-drive/legacy/adapter/json-api/classes/JSONAPIAdapter)
|
|
257
|
+
which supports the [{json:api} specification](http://jsonapi.org/) and if your server
|
|
258
258
|
endpoint supports the use of an
|
|
259
259
|
['include' query parameter](http://jsonapi.org/format/#fetching-includes),
|
|
260
260
|
you can use `findRecord()` or `findAll()` to automatically retrieve additional records related to
|
|
@@ -421,7 +421,7 @@ declare module "../-private/store-service" {
|
|
|
421
421
|
records in the store:
|
|
422
422
|
|
|
423
423
|
```js [app/adapters/application.js]
|
|
424
|
-
import Adapter from '@
|
|
424
|
+
import { Adapter } from '@warp-drive/legacy/adapter';
|
|
425
425
|
|
|
426
426
|
export default class ApplicationAdapter extends Adapter {
|
|
427
427
|
shouldReloadAll(store, snapshotsArray) {
|
|
@@ -498,13 +498,13 @@ declare module "../-private/store-service" {
|
|
|
498
498
|
}
|
|
499
499
|
```
|
|
500
500
|
|
|
501
|
-
See
|
|
501
|
+
See {@link Store.peekAll | peekAll} to get an array of current records in the
|
|
502
502
|
store, without waiting until a reload is finished.
|
|
503
503
|
|
|
504
504
|
### Retrieving Related Model Records
|
|
505
505
|
|
|
506
|
-
If you use an adapter such as
|
|
507
|
-
[
|
|
506
|
+
If you use an adapter such as the default
|
|
507
|
+
[JSONAPIAdapter](/api/@warp-drive/legacy/adapter/json-api/classes/JSONAPIAdapter)
|
|
508
508
|
that supports the [JSON API specification](http://jsonapi.org/) and if your server
|
|
509
509
|
endpoint supports the use of an
|
|
510
510
|
['include' query parameter](http://jsonapi.org/format/#fetching-includes),
|
|
@@ -535,7 +535,7 @@ declare module "../-private/store-service" {
|
|
|
535
535
|
}
|
|
536
536
|
```
|
|
537
537
|
|
|
538
|
-
See
|
|
538
|
+
See {@link Store.query | query} to only get a subset of records from the server.
|
|
539
539
|
|
|
540
540
|
@public
|
|
541
541
|
@deprecated use {@link Store.request} instead
|
|
@@ -575,7 +575,7 @@ declare module "../-private/store-service" {
|
|
|
575
575
|
|
|
576
576
|
If you do something like this:
|
|
577
577
|
|
|
578
|
-
```
|
|
578
|
+
```js
|
|
579
579
|
store.query('person', { ids: ['1', '2', '3'] });
|
|
580
580
|
```
|
|
581
581
|
|
|
@@ -602,7 +602,7 @@ declare module "../-private/store-service" {
|
|
|
602
602
|
query(type: string, query: LegacyResourceQuery, options?: QueryOptions): Promise<LegacyQueryArray>;
|
|
603
603
|
/**
|
|
604
604
|
This method makes a request for one record, where the `id` is not known
|
|
605
|
-
beforehand (if the `id` is known, use
|
|
605
|
+
beforehand (if the `id` is known, use {@link Store.findRecord | findRecord}
|
|
606
606
|
instead).
|
|
607
607
|
|
|
608
608
|
This method can be used when it is certain that the server will return a
|
|
@@ -611,37 +611,40 @@ declare module "../-private/store-service" {
|
|
|
611
611
|
Each time this method is called a new request is made through the adapter.
|
|
612
612
|
|
|
613
613
|
Let's assume our API provides an endpoint for the currently logged in user
|
|
614
|
-
via:
|
|
615
614
|
|
|
616
|
-
```
|
|
617
|
-
// GET /api/
|
|
615
|
+
```ts
|
|
616
|
+
// GET /api/user/me
|
|
618
617
|
{
|
|
619
|
-
|
|
620
|
-
|
|
618
|
+
data: {
|
|
619
|
+
type: 'user',
|
|
620
|
+
id: '1234',
|
|
621
|
+
attributes: {
|
|
621
622
|
username: 'admin'
|
|
622
623
|
}
|
|
623
624
|
}
|
|
625
|
+
}
|
|
624
626
|
```
|
|
625
627
|
|
|
626
628
|
Since the specific `id` of the `user` is not known beforehand, we can use
|
|
627
629
|
`queryRecord` to get the user:
|
|
628
630
|
|
|
629
|
-
```
|
|
630
|
-
store.queryRecord('user', {})
|
|
631
|
-
|
|
632
|
-
// do thing
|
|
633
|
-
});
|
|
631
|
+
```ts
|
|
632
|
+
const user = await store.queryRecord('user', { me: true });
|
|
633
|
+
user.username; // admin
|
|
634
634
|
```
|
|
635
635
|
|
|
636
636
|
The request is made through the adapters' `queryRecord`:
|
|
637
637
|
|
|
638
|
-
```
|
|
639
|
-
import Adapter from '@
|
|
640
|
-
import $ from 'jquery';
|
|
638
|
+
```ts [app/adapters/user.ts]
|
|
639
|
+
import Adapter from '@warp-drive/legacy/adapter';
|
|
641
640
|
|
|
642
641
|
export default class UserAdapter extends Adapter {
|
|
643
|
-
queryRecord(modelName, query) {
|
|
644
|
-
|
|
642
|
+
async queryRecord(modelName, query) {
|
|
643
|
+
if (query.me) {
|
|
644
|
+
const response = await fetch('/api/me');
|
|
645
|
+
return await response.json();
|
|
646
|
+
}
|
|
647
|
+
throw new Error('Unsupported query');
|
|
645
648
|
}
|
|
646
649
|
}
|
|
647
650
|
```
|
|
@@ -664,7 +667,7 @@ declare module "../-private/store-service" {
|
|
|
664
667
|
}
|
|
665
668
|
```
|
|
666
669
|
|
|
667
|
-
```
|
|
670
|
+
```js
|
|
668
671
|
store.query('user', { username: 'unique' }).then(function(users) {
|
|
669
672
|
return users.firstObject;
|
|
670
673
|
}).then(function(user) {
|
|
@@ -684,7 +687,7 @@ declare module "../-private/store-service" {
|
|
|
684
687
|
}
|
|
685
688
|
```
|
|
686
689
|
|
|
687
|
-
```
|
|
690
|
+
```js
|
|
688
691
|
store.queryRecord('user', { username: 'unique' }).then(function(user) {
|
|
689
692
|
// user is null
|
|
690
693
|
});
|
|
@@ -744,7 +747,7 @@ declare module "../-private/store-service" {
|
|
|
744
747
|
/**
|
|
745
748
|
Returns the schema for a particular resource type (modelName).
|
|
746
749
|
|
|
747
|
-
When used with Model
|
|
750
|
+
When used with [Model](/api/@warp-drive/legacy/model/classes/Model) the return is the model class,
|
|
748
751
|
but this is not guaranteed.
|
|
749
752
|
|
|
750
753
|
If looking to query attribute or relationship information it is
|
|
@@ -754,9 +757,7 @@ declare module "../-private/store-service" {
|
|
|
754
757
|
signatures.
|
|
755
758
|
|
|
756
759
|
The class of a model might be useful if you want to get a list of all the
|
|
757
|
-
relationship names of the model
|
|
758
|
-
[`relationshipNames`](/ember-data/release/classes/Model?anchor=relationshipNames)
|
|
759
|
-
for example.
|
|
760
|
+
relationship names of the model.
|
|
760
761
|
|
|
761
762
|
@public
|
|
762
763
|
@deprecated use {@link Store.schema} instead
|
package/declarations/store.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { RequestKey, ResourceKey } from "./identifier.js";
|
|
|
7
7
|
import type { Value } from "./json/raw.js";
|
|
8
8
|
import type { TypeFromInstanceOrString } from "./record.js";
|
|
9
9
|
import type { RequestContext, StructuredDataDocument, StructuredDocument } from "./request.js";
|
|
10
|
-
import type { ResourceDocument, SingleResourceDataDocument } from "./spec/document.js";
|
|
10
|
+
import type { CollectionResourceDataDocument, ResourceDocument, SingleResourceDataDocument } from "./spec/document.js";
|
|
11
11
|
import type { ApiError } from "./spec/error.js";
|
|
12
12
|
/**
|
|
13
13
|
* A hash of changed attributes with the key being the attribute name and the value being an
|
|
@@ -253,23 +253,25 @@ export interface Cache {
|
|
|
253
253
|
*
|
|
254
254
|
* @public
|
|
255
255
|
*/
|
|
256
|
-
willCommit(cacheKey: ResourceKey, context: RequestContext | null): void;
|
|
256
|
+
willCommit(cacheKey: ResourceKey | ResourceKey[], context: RequestContext | null): void;
|
|
257
257
|
/**
|
|
258
258
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
259
259
|
* was successfully updated as part of a save transaction.
|
|
260
260
|
*
|
|
261
261
|
* @public
|
|
262
|
-
* @param the primary ResourceKey that was operated on
|
|
263
|
-
* @param
|
|
262
|
+
* @param cacheKey - the primary ResourceKey that was operated on
|
|
263
|
+
* @param result - a document in the cache format containing any updated data
|
|
264
264
|
*/
|
|
265
|
-
didCommit(cacheKey: ResourceKey, result: StructuredDataDocument<
|
|
265
|
+
didCommit(cacheKey: ResourceKey, result: StructuredDataDocument<SingleResourceDataDocument> | null): SingleResourceDataDocument;
|
|
266
|
+
didCommit(cacheKey: ResourceKey[], result: StructuredDataDocument<SingleResourceDataDocument> | null): SingleResourceDataDocument;
|
|
267
|
+
didCommit(cacheKey: ResourceKey[], result: StructuredDataDocument<CollectionResourceDataDocument> | null): CollectionResourceDataDocument;
|
|
266
268
|
/**
|
|
267
269
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
268
270
|
* was update via a save transaction failed.
|
|
269
271
|
*
|
|
270
272
|
* @public
|
|
271
273
|
*/
|
|
272
|
-
commitWasRejected(cacheKey: ResourceKey, errors?: ApiError[]): void;
|
|
274
|
+
commitWasRejected(cacheKey: ResourceKey | ResourceKey[], errors?: ApiError[]): void;
|
|
273
275
|
/**
|
|
274
276
|
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
275
277
|
* should be cleared.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FetchError } from "../request/-private/utils.js";
|
|
1
2
|
import type { Store } from "../store/-private.js";
|
|
2
3
|
import type { ResourceKey } from "./identifier.js";
|
|
3
4
|
import type { QueryParamsSerializationOptions } from "./params.js";
|
|
@@ -8,12 +9,14 @@ export declare const SkipCache: "___(unique) Symbol(SkipCache)";
|
|
|
8
9
|
export declare const EnableHydration: "___(unique) Symbol(EnableHydration)";
|
|
9
10
|
export declare const IS_FUTURE: "___(unique) Symbol(IS_FUTURE)";
|
|
10
11
|
export declare const STRUCTURED: "___(unique) Symbol(DOC)";
|
|
12
|
+
export type { FetchError };
|
|
11
13
|
export type HTTPMethod = "QUERY" | "GET" | "OPTIONS" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "CONNECT" | "TRACE";
|
|
12
14
|
/**
|
|
13
|
-
* Use these options to adjust CacheHandler behavior for a request
|
|
15
|
+
* Use these options to adjust {@link CacheHandler} behavior for a request
|
|
16
|
+
* via {@link RequestInfo.cacheOptions}.
|
|
14
17
|
*
|
|
15
18
|
*/
|
|
16
|
-
export
|
|
19
|
+
export interface CacheOptions {
|
|
17
20
|
/**
|
|
18
21
|
* A key that uniquely identifies this request. If not present, the url wil be used
|
|
19
22
|
* as the key for any GET request, while all other requests will not be cached.
|
|
@@ -57,7 +60,7 @@ export type CacheOptions = {
|
|
|
57
60
|
*
|
|
58
61
|
*/
|
|
59
62
|
[SkipCache]?: boolean;
|
|
60
|
-
}
|
|
63
|
+
}
|
|
61
64
|
export type FindRecordRequestOptions<
|
|
62
65
|
RT = unknown,
|
|
63
66
|
T = unknown
|
|
@@ -158,11 +161,15 @@ export interface FindRecordOptions extends ConstrainedRequestOptions {
|
|
|
158
161
|
include?: string | string[];
|
|
159
162
|
}
|
|
160
163
|
/**
|
|
161
|
-
* When a
|
|
162
|
-
* containing the original
|
|
163
|
-
* chain (if any), and
|
|
164
|
+
* When a {@link Future} resolves, it returns an object
|
|
165
|
+
* containing the original {@link RequestInfo | request},
|
|
166
|
+
* the {@link Response | response} set by the handler chain (if any), and
|
|
167
|
+
* the processed content.
|
|
164
168
|
*/
|
|
165
169
|
export interface StructuredDataDocument<T> {
|
|
170
|
+
/**
|
|
171
|
+
* @private
|
|
172
|
+
*/
|
|
166
173
|
[STRUCTURED]?: true;
|
|
167
174
|
/**
|
|
168
175
|
* @see {@link ImmutableRequestInfo}
|
|
@@ -172,25 +179,34 @@ export interface StructuredDataDocument<T> {
|
|
|
172
179
|
content: T;
|
|
173
180
|
}
|
|
174
181
|
/**
|
|
175
|
-
* When a
|
|
176
|
-
*
|
|
182
|
+
* When a {@link Future} rejects, it throws either an {@link Error}
|
|
183
|
+
* an {@link AggregateError} or a {@link DOMException} that maintains
|
|
184
|
+
* the `{ request, response, content }` shape but is also an Error instance
|
|
177
185
|
* itself.
|
|
178
186
|
*
|
|
179
187
|
* If using the error originates from the {@link Fetch | Fetch Handler}
|
|
180
188
|
* the error will be a {@link FetchError}
|
|
181
189
|
*/
|
|
182
190
|
export interface StructuredErrorDocument<T = unknown> extends Error {
|
|
191
|
+
/**
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
183
194
|
[STRUCTURED]?: true;
|
|
195
|
+
/**
|
|
196
|
+
* @see {@link ImmutableRequestInfo}
|
|
197
|
+
*/
|
|
184
198
|
request: ImmutableRequestInfo;
|
|
185
199
|
response: Response | ResponseInfo | null;
|
|
186
200
|
error: string | object;
|
|
187
201
|
content?: T;
|
|
188
202
|
}
|
|
189
203
|
/**
|
|
190
|
-
* A union of the resolve/reject data types for
|
|
204
|
+
* A union of the resolve/reject data types for the {@link Future}
|
|
205
|
+
* returned by {@link Store.request | request}
|
|
191
206
|
*
|
|
192
|
-
* See the docs for:
|
|
207
|
+
* See also the docs for:
|
|
193
208
|
*
|
|
209
|
+
* - {@link Future}
|
|
194
210
|
* - {@link StructuredDataDocument} (resolved/successful requests)
|
|
195
211
|
* - {@link StructuredErrorDocument} (rejected/failed requests)
|
|
196
212
|
*/
|
|
@@ -349,7 +365,3 @@ export interface RequestContext {
|
|
|
349
365
|
setStream(stream: ReadableStream | Promise<ReadableStream | null>): void;
|
|
350
366
|
setResponse(response: Response | ResponseInfo | null): void;
|
|
351
367
|
}
|
|
352
|
-
export declare function withBrand<T>(obj: RequestInfo): RequestInfo<T> & {
|
|
353
|
-
[RequestSignature]: T;
|
|
354
|
-
};
|
|
355
|
-
export {};
|
|
@@ -673,7 +673,7 @@ export interface ArrayField {
|
|
|
673
673
|
*
|
|
674
674
|
* Configures which extensions this array is allowed to use.
|
|
675
675
|
* Extensions are registered with the store's schema service
|
|
676
|
-
* via {@link SchemaService.
|
|
676
|
+
* via {@link SchemaService.CAUTION_MEGA_DANGER_ZONE_registerExtension}
|
|
677
677
|
*
|
|
678
678
|
* Extensions should only be used for temporary enhancements
|
|
679
679
|
* to arrays to support migrating away from deprecated behaviors
|
|
@@ -786,7 +786,7 @@ export interface SchemaArrayField {
|
|
|
786
786
|
*
|
|
787
787
|
* Configures which extensions this array is allowed to use.
|
|
788
788
|
* Extensions are registered with the store's schema service
|
|
789
|
-
* via {@link SchemaService.
|
|
789
|
+
* via {@link SchemaService.CAUTION_MEGA_DANGER_ZONE_registerExtension}
|
|
790
790
|
*
|
|
791
791
|
* Extensions should only be used for temporary enhancements
|
|
792
792
|
* to arrays to support migrating away from deprecated behaviors
|
|
@@ -1571,7 +1571,7 @@ export interface LegacyHasManyField {
|
|
|
1571
1571
|
*
|
|
1572
1572
|
* Configures which extensions this array is allowed to use.
|
|
1573
1573
|
* Extensions are registered with the store's schema service
|
|
1574
|
-
* via {@link SchemaService.
|
|
1574
|
+
* via {@link SchemaService.CAUTION_MEGA_DANGER_ZONE_registerExtension}
|
|
1575
1575
|
*
|
|
1576
1576
|
* Extensions should only be used for temporary enhancements
|
|
1577
1577
|
* to arrays to support migrating away from deprecated behaviors
|
|
@@ -1742,7 +1742,7 @@ export interface LinksModeHasManyField {
|
|
|
1742
1742
|
*
|
|
1743
1743
|
* Configures which extensions this array is allowed to use.
|
|
1744
1744
|
* Extensions are registered with the store's schema service
|
|
1745
|
-
* via {@link SchemaService.
|
|
1745
|
+
* via {@link SchemaService.CAUTION_MEGA_DANGER_ZONE_registerExtension}
|
|
1746
1746
|
*
|
|
1747
1747
|
* Extensions should only be used for temporary enhancements
|
|
1748
1748
|
* to arrays to support migrating away from deprecated behaviors
|
|
@@ -2125,18 +2125,29 @@ export interface ObjectSchema {
|
|
|
2125
2125
|
objectExtensions?: string[];
|
|
2126
2126
|
}
|
|
2127
2127
|
export type Schema = ResourceSchema | ObjectSchema;
|
|
2128
|
+
/**
|
|
2129
|
+
* A trait for use on a PolarisMode record
|
|
2130
|
+
*/
|
|
2128
2131
|
export interface PolarisTrait {
|
|
2129
2132
|
name: string;
|
|
2130
2133
|
mode: "polaris";
|
|
2131
2134
|
fields: PolarisModeFieldSchema[];
|
|
2132
2135
|
traits?: string[];
|
|
2133
2136
|
}
|
|
2137
|
+
/**
|
|
2138
|
+
* A trait for use on a LegacyMode record
|
|
2139
|
+
*/
|
|
2134
2140
|
export interface LegacyTrait {
|
|
2135
2141
|
name: string;
|
|
2136
2142
|
mode: "legacy";
|
|
2137
2143
|
fields: LegacyModeFieldSchema[];
|
|
2138
2144
|
traits?: string[];
|
|
2139
2145
|
}
|
|
2146
|
+
/**
|
|
2147
|
+
* A union of
|
|
2148
|
+
* - {@link LegacyTrait}
|
|
2149
|
+
* - {@link PolarisTrait}
|
|
2150
|
+
*/
|
|
2140
2151
|
export type Trait = LegacyTrait | PolarisTrait;
|
|
2141
2152
|
/**
|
|
2142
2153
|
* A no-op type utility that enables type-checking resource schema
|