@warp-drive/core 5.8.0-alpha.3 → 5.8.0-alpha.30
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 +22 -38
- package/declarations/build-config.d.ts +18 -1
- package/declarations/graph/-private/-edge-definition.d.ts +12 -2
- package/declarations/index.d.ts +82 -3
- package/declarations/reactive/-private/document.d.ts +58 -46
- package/declarations/reactive/-private/record.d.ts +10 -1
- package/declarations/reactive/-private/schema.d.ts +77 -4
- package/declarations/reactive/-private.d.ts +1 -0
- 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/new-core-tmp/request-state.d.ts +1 -1
- 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/record.d.ts +132 -0
- package/declarations/types/request.d.ts +26 -14
- package/declarations/types/schema/fields.d.ts +30 -6
- 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 +13 -4
- package/dist/{request-state-CUuZzgvE.js → index-CHrZ1B2X.js} +10081 -8924
- 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/record.js +127 -0
- package/dist/types/request.js +14 -12
- 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/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +3 -3
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
package/README.md
CHANGED
|
@@ -1,52 +1,44 @@
|
|
|
1
|
-
<
|
|
2
|
-
<img
|
|
3
|
-
class="project-logo light-only"
|
|
4
|
-
src="./logos/github-header.svg#gh-light-mode-only"
|
|
5
|
-
alt="WarpDrive | Boldly go where no app has gone before"
|
|
6
|
-
title="WarpDrive | Boldly go where no app has gone before"
|
|
7
|
-
/>
|
|
1
|
+
<p align="center">
|
|
8
2
|
<img
|
|
9
|
-
class="project-logo
|
|
10
|
-
src="./logos/
|
|
11
|
-
alt="WarpDrive
|
|
12
|
-
|
|
3
|
+
class="project-logo"
|
|
4
|
+
src="./logos/logo-yellow-slab.svg"
|
|
5
|
+
alt="WarpDrive"
|
|
6
|
+
width="180px"
|
|
7
|
+
title="WarpDrive"
|
|
13
8
|
/>
|
|
14
|
-
</
|
|
9
|
+
</p>
|
|
15
10
|
|
|
16
|
-
](https://discord.gg/zT3asNS
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+
[](https://discord.gg/zT3asNS
|
|
21
15
|
)
|
|
22
|
-
[](https://discord.gg/PHBbnWJx5S
|
|
23
17
|
)
|
|
24
18
|
|
|
25
|
-
|
|
26
19
|
<p align="center">
|
|
27
20
|
<br>
|
|
28
|
-
<a href="https://warp-drive.io">WarpDrive</a> is
|
|
21
|
+
<a href="https://warp-drive.io">WarpDrive</a> is the lightweight data library for web apps —
|
|
29
22
|
<br>
|
|
30
23
|
universal, typed, reactive, and ready to scale.
|
|
31
|
-
<br
|
|
32
|
-
<br>
|
|
24
|
+
<br/><br/>
|
|
33
25
|
</p>
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
rich
|
|
27
|
+
***Warp*Drive** makes it easy to build scalable, fast, feature
|
|
28
|
+
rich applications — letting you ship better experiences more quickly without re-architecting your app or API. ***Warp*Drive** is:
|
|
37
29
|
|
|
30
|
+
- 🌌 Seamless Reactivity in any Framework
|
|
38
31
|
- ⚡️ Committed to Best-In-Class Performance
|
|
39
|
-
- 🌲 Focused on being as svelte as possible
|
|
40
|
-
- 🚀 SSR Ready
|
|
41
32
|
- 💚 Typed
|
|
42
|
-
-
|
|
43
|
-
-
|
|
33
|
+
- ⚛️ Works with any API
|
|
34
|
+
- 🌲 Focused on being as tiny as possible
|
|
35
|
+
- 🚀 SSR Ready
|
|
44
36
|
- 🐹 Built with ♥️ by [Ember](https://emberjs.com)
|
|
45
37
|
|
|
46
38
|
<br>
|
|
47
39
|
<br>
|
|
48
40
|
|
|
49
|
-
*Get Started* → [Guides](
|
|
41
|
+
*Get Started* → [Guides](https://warp-drive.io/guides/)
|
|
50
42
|
|
|
51
43
|
<br>
|
|
52
44
|
|
|
@@ -54,17 +46,9 @@ rich application — letting you ship better experiences more quickly withou
|
|
|
54
46
|
|
|
55
47
|
<br>
|
|
56
48
|
|
|
57
|
-
## Installation
|
|
58
|
-
|
|
59
|
-
```sh
|
|
60
|
-
pnpm add -E @warp-drive/core@latest
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
<br>
|
|
64
|
-
|
|
65
49
|
## Code of Conduct
|
|
66
50
|
|
|
67
|
-
Refer to the [Code of Conduct](https://github.com/
|
|
51
|
+
Refer to the [Code of Conduct](https://github.com/warp-drive-data/warp-drive/blob/main/CODE_OF_CONDUCT.md) for community guidelines and inclusivity.
|
|
68
52
|
|
|
69
53
|
<br>
|
|
70
54
|
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This module provides a build-plugin that enables configuration of deprecations,
|
|
3
|
+
* optional features, development/testing support and debug logging.
|
|
4
|
+
*
|
|
5
|
+
* Available settings include:
|
|
6
|
+
*
|
|
7
|
+
* - {@link LOGGING | debugging}
|
|
8
|
+
* - {@link DEPRECATIONS | deprecations}
|
|
9
|
+
* - {@link FEATURES | features}
|
|
10
|
+
* - {@link WarpDriveConfig.polyfillUUID | polyfillUUID}
|
|
11
|
+
* - {@link WarpDriveConfig.includeDataAdapterInProduction | includeDataAdapterInProduction}
|
|
12
|
+
* - {@link WarpDriveConfig.compatWith | compatWith}
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
import type { WarpDriveConfig } from "@warp-drive/build-config";
|
|
17
|
+
export { setConfig, babelPlugin } from "@warp-drive/build-config";
|
|
18
|
+
export type { WarpDriveConfig };
|
|
@@ -75,10 +75,15 @@ export declare function temporaryConvertToLegacy(field: ResourceField | Collecti
|
|
|
75
75
|
export interface UpgradedMeta {
|
|
76
76
|
kind: "implicit" | RelationshipFieldKind;
|
|
77
77
|
/**
|
|
78
|
-
* The field
|
|
78
|
+
* The field sourceKey on `this` record,
|
|
79
|
+
* name if sourceKey is not set.
|
|
79
80
|
*/
|
|
80
81
|
key: string;
|
|
81
82
|
/**
|
|
83
|
+
* The field name on `this` record
|
|
84
|
+
*/
|
|
85
|
+
name: string;
|
|
86
|
+
/**
|
|
82
87
|
* The `type` of the related record
|
|
83
88
|
*
|
|
84
89
|
*/
|
|
@@ -91,10 +96,15 @@ export interface UpgradedMeta {
|
|
|
91
96
|
isLinksMode: boolean;
|
|
92
97
|
inverseKind: "implicit" | RelationshipFieldKind;
|
|
93
98
|
/**
|
|
94
|
-
* The field
|
|
99
|
+
* The field sourceKey on the opposing record,
|
|
100
|
+
* name if sourceKey is not set.
|
|
95
101
|
*/
|
|
96
102
|
inverseKey: string;
|
|
97
103
|
/**
|
|
104
|
+
* The field name on the opposing record,
|
|
105
|
+
*/
|
|
106
|
+
inverseName: string;
|
|
107
|
+
/**
|
|
98
108
|
* The `type` of `this` record
|
|
99
109
|
*/
|
|
100
110
|
inverseType: string;
|
package/declarations/index.d.ts
CHANGED
|
@@ -2,13 +2,92 @@
|
|
|
2
2
|
* @module
|
|
3
3
|
* @mergeModuleWith <project>
|
|
4
4
|
*/
|
|
5
|
+
import type { CAUTION_MEGA_DANGER_ZONE_Extension } from "./reactive.js";
|
|
5
6
|
import type { ReactiveDocument } from "./reactive/-private/document.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import type { Handler } from "./request.js";
|
|
8
|
+
import { Fetch } from "./request/-private/fetch.js";
|
|
9
|
+
import { RequestManager } from "./request/-private/manager.js";
|
|
10
|
+
import { CacheHandler, type CachePolicy, Store } from "./store/-private.js";
|
|
11
|
+
import { recordIdentifierFor } from "./store/-private.js";
|
|
12
|
+
import type { CacheCapabilitiesManager } from "./types.js";
|
|
13
|
+
import type { Cache } from "./types/cache.js";
|
|
14
|
+
import type { Derivation, HashFn, Transformation } from "./types/schema/concepts.js";
|
|
15
|
+
import type { ObjectSchema, PolarisResourceSchema, Trait } from "./types/schema/fields.js";
|
|
16
|
+
export { recordIdentifierFor, recordIdentifierFor as cacheKeyFor };
|
|
17
|
+
export { Fetch, RequestManager };
|
|
18
|
+
export { Store, CacheHandler, type CachePolicy };
|
|
19
|
+
export { type StoreRequestContext, type StoreRequestInput, storeFor } from "./store/-private.js";
|
|
9
20
|
/**
|
|
10
21
|
* @deprecated use `ReactiveDocument` instead
|
|
11
22
|
*/
|
|
12
23
|
export type Document<T> = ReactiveDocument<T>;
|
|
13
24
|
export type { DocumentCacheOperation, CacheOperation, NotificationType } from "./store/-private/managers/notification-manager.js";
|
|
14
25
|
export { setIdentifierGenerationMethod, setIdentifierUpdateMethod, setIdentifierForgetMethod, setIdentifierResetMethod, setKeyInfoForResource } from "./store/-private/managers/cache-key-manager.js";
|
|
26
|
+
/**
|
|
27
|
+
* Options for setting up a Store instance with `useRecommendedStore`.
|
|
28
|
+
*/
|
|
29
|
+
export interface StoreSetupOptions<T extends Cache = Cache> {
|
|
30
|
+
/**
|
|
31
|
+
* The Cache implementation to use
|
|
32
|
+
*/
|
|
33
|
+
cache: new (capabilities: CacheCapabilitiesManager) => T;
|
|
34
|
+
/**
|
|
35
|
+
* The Cache policy to use.
|
|
36
|
+
*
|
|
37
|
+
* Defaults to {@link DefaultCachePolicy} configured to
|
|
38
|
+
* respect `Expires`, `X-WarpDrive-Expires`, and `Cache-Control` headers
|
|
39
|
+
* with a fallback to 30s soft expiration and 15m hard expiration.
|
|
40
|
+
*/
|
|
41
|
+
policy?: CachePolicy;
|
|
42
|
+
/**
|
|
43
|
+
* The request handlers to use. {@link Fetch} will automatically
|
|
44
|
+
* be added to the end of the handler chain and {@link CacheHandler}
|
|
45
|
+
* will automatically be added as the cache handler.
|
|
46
|
+
*/
|
|
47
|
+
handlers?: Handler[];
|
|
48
|
+
/**
|
|
49
|
+
* Schemas describing the structure of your resource data.
|
|
50
|
+
*
|
|
51
|
+
* See {@link PolarisResourceSchema,} and {@link ObjectSchema} for more information.
|
|
52
|
+
*/
|
|
53
|
+
schemas?: Array<PolarisResourceSchema | ObjectSchema>;
|
|
54
|
+
/**
|
|
55
|
+
* {@link Trait | Traits} to use with {@link PolarisResourceSchema, | Resource Schemas}
|
|
56
|
+
*/
|
|
57
|
+
traits?: Trait[];
|
|
58
|
+
/**
|
|
59
|
+
* {@link Derivation | Derivations} to use for derived fields.
|
|
60
|
+
*/
|
|
61
|
+
derivations?: Derivation[];
|
|
62
|
+
/**
|
|
63
|
+
* {@link Transformation | Transformations} to use for transforming fields.
|
|
64
|
+
*/
|
|
65
|
+
transformations?: Transformation[];
|
|
66
|
+
/**
|
|
67
|
+
* {@link HashFn | Hash Functions} to use for embedded object identity and polymorphic type calculations
|
|
68
|
+
*/
|
|
69
|
+
hashFns?: HashFn[];
|
|
70
|
+
/**
|
|
71
|
+
* {@link CAUTION_MEGA_DANGER_ZONE_Extension | Extensions} to use with resources, objects and arrays
|
|
72
|
+
* to provide custom behaviors and capabilities that are not described by Schema.
|
|
73
|
+
*
|
|
74
|
+
* This feature should only be used during a transition period to support migrating towards
|
|
75
|
+
* schemas from existing Model and ModelFragments implementations.
|
|
76
|
+
*/
|
|
77
|
+
CAUTION_MEGA_DANGER_ZONE_extensions?: CAUTION_MEGA_DANGER_ZONE_Extension[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a configured Store class with recommended defaults
|
|
81
|
+
* for schema handling, reactivity, caching, and request management.
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { useRecommendedStore } from '@warp-drive/core';
|
|
85
|
+
* import { JSONAPICache } from '@warp-drive/json-api';
|
|
86
|
+
*
|
|
87
|
+
* export const Store = useRecommendedStore({
|
|
88
|
+
* cache: JSONAPICache,
|
|
89
|
+
* schemas: [],
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function useRecommendedStore(options: StoreSetupOptions, StoreKlass?: typeof Store): typeof Store;
|
|
@@ -3,25 +3,13 @@ import type { RequestKey } from "../../types/identifier.js";
|
|
|
3
3
|
import type { ImmutableRequestInfo, RequestInfo } from "../../types/request.js";
|
|
4
4
|
import type { ResourceDocument } from "../../types/spec/document.js";
|
|
5
5
|
import type { Meta, PaginationLinks } from "../../types/spec/json-api-raw.js";
|
|
6
|
-
|
|
7
|
-
* A Document is a class that wraps the response content from a request to the API
|
|
8
|
-
* returned by `Cache.put` or `Cache.peek`, converting ResourceKeys into
|
|
9
|
-
* ReactiveResource instances.
|
|
10
|
-
*
|
|
11
|
-
* It is not directly instantiated by the user, and its properties should not
|
|
12
|
-
* be directly modified. Whether individual properties are mutable or not is
|
|
13
|
-
* determined by the record instance itself.
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
* @hideconstructor
|
|
17
|
-
*/
|
|
18
|
-
export declare class ReactiveDocument<T> {
|
|
6
|
+
export interface ReactiveDocumentBase<T> {
|
|
19
7
|
/**
|
|
20
8
|
* The links object for this document, if any
|
|
21
9
|
*
|
|
22
10
|
* e.g.
|
|
23
11
|
*
|
|
24
|
-
* ```
|
|
12
|
+
* ```ts
|
|
25
13
|
* {
|
|
26
14
|
* self: '/articles?page[number]=3',
|
|
27
15
|
* }
|
|
@@ -31,24 +19,6 @@ export declare class ReactiveDocument<T> {
|
|
|
31
19
|
*/
|
|
32
20
|
readonly links?: PaginationLinks;
|
|
33
21
|
/**
|
|
34
|
-
* The primary data for this document, if any.
|
|
35
|
-
*
|
|
36
|
-
* If this document has no primary data (e.g. because it is an error document)
|
|
37
|
-
* this property will be `undefined`.
|
|
38
|
-
*
|
|
39
|
-
* For collections this will be an array of record instances,
|
|
40
|
-
* for single resource requests it will be a single record instance or null.
|
|
41
|
-
*
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
readonly data?: T;
|
|
45
|
-
/**
|
|
46
|
-
* The errors returned by the API for this request, if any
|
|
47
|
-
*
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
readonly errors?: object[];
|
|
51
|
-
/**
|
|
52
22
|
* The meta object for this document, if any
|
|
53
23
|
*
|
|
54
24
|
* @public
|
|
@@ -60,18 +30,12 @@ export declare class ReactiveDocument<T> {
|
|
|
60
30
|
* @public
|
|
61
31
|
*/
|
|
62
32
|
readonly identifier: RequestKey | null;
|
|
63
|
-
constructor(store: Store, cacheKey: RequestKey | null, localCache: {
|
|
64
|
-
document: ResourceDocument;
|
|
65
|
-
request: ImmutableRequestInfo;
|
|
66
|
-
} | null);
|
|
67
33
|
/**
|
|
68
34
|
* Fetches the related link for this document, returning a promise that resolves
|
|
69
35
|
* with the document when the request completes. If no related link is present,
|
|
70
36
|
* will fallback to the self link if present
|
|
71
37
|
*
|
|
72
38
|
* @public
|
|
73
|
-
* @param {Object} options
|
|
74
|
-
* @return {Promise<Document>}
|
|
75
39
|
*/
|
|
76
40
|
fetch(options?: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T>>;
|
|
77
41
|
/**
|
|
@@ -80,8 +44,6 @@ export declare class ReactiveDocument<T> {
|
|
|
80
44
|
* next link.
|
|
81
45
|
*
|
|
82
46
|
* @public
|
|
83
|
-
* @param {Object} options
|
|
84
|
-
* @return {Promise<Document | null>}
|
|
85
47
|
*/
|
|
86
48
|
next(options?: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
|
|
87
49
|
/**
|
|
@@ -90,8 +52,6 @@ export declare class ReactiveDocument<T> {
|
|
|
90
52
|
* prev link.
|
|
91
53
|
*
|
|
92
54
|
* @public
|
|
93
|
-
* @param {Object} options
|
|
94
|
-
* @return {Promise<Document | null>}
|
|
95
55
|
*/
|
|
96
56
|
prev(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
|
|
97
57
|
/**
|
|
@@ -100,8 +60,6 @@ export declare class ReactiveDocument<T> {
|
|
|
100
60
|
* first link.
|
|
101
61
|
*
|
|
102
62
|
* @public
|
|
103
|
-
* @param {Object} options
|
|
104
|
-
* @return {Promise<Document | null>}
|
|
105
63
|
*/
|
|
106
64
|
first(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
|
|
107
65
|
/**
|
|
@@ -110,8 +68,6 @@ export declare class ReactiveDocument<T> {
|
|
|
110
68
|
* last link.
|
|
111
69
|
*
|
|
112
70
|
* @public
|
|
113
|
-
* @param {Object} options
|
|
114
|
-
* @return {Promise<Document | null>}
|
|
115
71
|
*/
|
|
116
72
|
last(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
|
|
117
73
|
/**
|
|
@@ -128,3 +84,59 @@ export declare class ReactiveDocument<T> {
|
|
|
128
84
|
*/
|
|
129
85
|
toJSON(): object;
|
|
130
86
|
}
|
|
87
|
+
export interface ReactiveErrorDocument<T> extends ReactiveDocumentBase<T> {
|
|
88
|
+
/**
|
|
89
|
+
* The primary data for this document, if any.
|
|
90
|
+
*
|
|
91
|
+
* If this document has no primary data (e.g. because it is an error document)
|
|
92
|
+
* this property will be `undefined`.
|
|
93
|
+
*
|
|
94
|
+
* For collections this will be an array of record instances,
|
|
95
|
+
* for single resource requests it will be a single record instance or null.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
readonly data?: undefined;
|
|
100
|
+
/**
|
|
101
|
+
* The errors returned by the API for this request, if any
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
readonly errors: object[];
|
|
106
|
+
}
|
|
107
|
+
export interface ReactiveDataDocument<T> extends ReactiveDocumentBase<T> {
|
|
108
|
+
/**
|
|
109
|
+
* The primary data for this document, if any.
|
|
110
|
+
*
|
|
111
|
+
* If this document has no primary data (e.g. because it is an error document)
|
|
112
|
+
* this property will be `undefined`.
|
|
113
|
+
*
|
|
114
|
+
* For collections this will be an array of record instances,
|
|
115
|
+
* for single resource requests it will be a single record instance or null.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
readonly data: T;
|
|
120
|
+
/**
|
|
121
|
+
* The errors returned by the API for this request, if any
|
|
122
|
+
*
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
readonly errors?: undefined;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A Document is a class that wraps the response content from a request to the API
|
|
129
|
+
* returned by `Cache.put` or `Cache.peek`, converting ResourceKeys into
|
|
130
|
+
* ReactiveResource instances.
|
|
131
|
+
*
|
|
132
|
+
* It is not directly instantiated by the user, and its properties should not
|
|
133
|
+
* be directly modified. Whether individual properties are mutable or not is
|
|
134
|
+
* determined by the record instance itself.
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
export type ReactiveDocument<T> = ReactiveDataDocument<T> | ReactiveErrorDocument<T>;
|
|
139
|
+
export declare function createReactiveDocument<T>(store: Store, cacheKey: RequestKey | null, localCache: {
|
|
140
|
+
document: ResourceDocument;
|
|
141
|
+
request: ImmutableRequestInfo;
|
|
142
|
+
} | null): ReactiveDocument<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ObjectContext, ResourceContext } from "./default-mode.js";
|
|
2
|
-
import { Checkout } from "./symbols.js";
|
|
2
|
+
import { Checkout, Context } from "./symbols.js";
|
|
3
3
|
export interface ReactiveResource {
|
|
4
4
|
/**
|
|
5
5
|
* Create an editable copy of the record
|
|
@@ -21,6 +21,15 @@ export interface ReactiveResource {
|
|
|
21
21
|
[Checkout]<T>(): Promise<T>;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
export interface PrivateReactiveResource extends ReactiveResource {
|
|
27
|
+
/**
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
[Context]: ObjectContext | ResourceContext;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
24
33
|
* A class that uses a the ResourceSchema for a ResourceType
|
|
25
34
|
* and a ResourceKey to transform data from the cache into a rich, reactive
|
|
26
35
|
* object.
|
|
@@ -8,17 +8,22 @@ import type { WithPartial } from "../../types/utils.js";
|
|
|
8
8
|
import type { ReactiveResource } from "./record.js";
|
|
9
9
|
/**
|
|
10
10
|
* Extensions allow providing non-schema driven behaviors to
|
|
11
|
-
*
|
|
11
|
+
* ReactiveResources, ReactiveArrays, and ReactiveObjects.
|
|
12
|
+
*
|
|
13
|
+
* This should only be used for temporary migration purposes
|
|
14
|
+
* to the new schema system when migrating from either Model
|
|
15
|
+
* or ModelFragments.
|
|
12
16
|
*/
|
|
13
17
|
export interface CAUTION_MEGA_DANGER_ZONE_Extension {
|
|
14
18
|
/**
|
|
15
19
|
* Whether this extension extends the behaviors of objects
|
|
16
|
-
* or of arrays.
|
|
20
|
+
* (both ReactiveObjects and ReactiveResources) or of arrays.
|
|
17
21
|
*/
|
|
18
22
|
kind: "object" | "array";
|
|
19
23
|
/**
|
|
20
24
|
* The name of the extension, to be used when specifying
|
|
21
|
-
* either `objectExtensions` or `arrayExtensions`
|
|
25
|
+
* either `objectExtensions` or `arrayExtensions` on the
|
|
26
|
+
* field, ResourceSchema or ObjectSchema
|
|
22
27
|
*/
|
|
23
28
|
name: string;
|
|
24
29
|
/**
|
|
@@ -29,6 +34,74 @@ export interface CAUTION_MEGA_DANGER_ZONE_Extension {
|
|
|
29
34
|
*
|
|
30
35
|
* A constructable such as a Function or Class whose prototype
|
|
31
36
|
* will be iterated with getOwnPropertyNames.
|
|
37
|
+
*
|
|
38
|
+
* Examples:
|
|
39
|
+
*
|
|
40
|
+
* **An Object with methods**
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* store.schema.CAUTION_MEGA_DANGER_ZONE_registerExtension({
|
|
44
|
+
* kind: 'object',
|
|
45
|
+
* name: 'do-thing-1',
|
|
46
|
+
* features: {
|
|
47
|
+
* doThingOne(this: { street: string }) {
|
|
48
|
+
* return `do-thing-1:${this.street}`;
|
|
49
|
+
* },
|
|
50
|
+
* doThingTwo(this: { street: string }) {
|
|
51
|
+
* return `do-thing-1:${this.street}`;
|
|
52
|
+
* },
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* **A class with getters, methods and decorated fields**
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* class Features {
|
|
61
|
+
* sayHello() {
|
|
62
|
+
* return 'hello!';
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* @tracked trackedField = 'initial tracked value';
|
|
66
|
+
*
|
|
67
|
+
* get realName() {
|
|
68
|
+
* const self = this as unknown as { name: string };
|
|
69
|
+
* return self.name;
|
|
70
|
+
* }
|
|
71
|
+
* set realName(v: string) {
|
|
72
|
+
* const self = this as unknown as { name: string };
|
|
73
|
+
* self.name = v;
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* get greeting() {
|
|
77
|
+
* const self = this as unknown as { name: string };
|
|
78
|
+
* return `hello ${self.name}!`;
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* @computed('name')
|
|
82
|
+
* get salutation() {
|
|
83
|
+
* const self = this as unknown as { name: string };
|
|
84
|
+
* return `salutations ${self.name}!`;
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* @cached
|
|
88
|
+
* get helloThere() {
|
|
89
|
+
* const self = this as unknown as { name: string };
|
|
90
|
+
* return `Well Hello There ${self.name}!`;
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* // non-decorated fields dont appear on class prototypes as they are instance only
|
|
95
|
+
* // @ts-expect-error
|
|
96
|
+
* Features.prototype.untrackedField = 'initial untracked value';
|
|
97
|
+
*
|
|
98
|
+
* store.schema.CAUTION_MEGA_DANGER_ZONE_registerExtension({
|
|
99
|
+
* kind: 'object',
|
|
100
|
+
* name: 'my-ext',
|
|
101
|
+
* features: Features,
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
32
105
|
*/
|
|
33
106
|
features: Record<string | symbol, unknown> | Function;
|
|
34
107
|
}
|
|
@@ -80,7 +153,7 @@ export interface ExtensibleField {
|
|
|
80
153
|
* @param schema
|
|
81
154
|
* @return {PolarisResourceSchema}
|
|
82
155
|
*/
|
|
83
|
-
export declare function withDefaults(schema: WithPartial<PolarisResourceSchema, "identity">):
|
|
156
|
+
export declare function withDefaults(schema: WithPartial<PolarisResourceSchema, "identity">): PolarisResourceSchema;
|
|
84
157
|
interface FromIdentityDerivation {
|
|
85
158
|
(record: ReactiveResource, options: {
|
|
86
159
|
key: "lid";
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* reactive representations of the raw data for requests, resources and their relationships
|
|
6
6
|
* stored in the cache.
|
|
7
7
|
*
|
|
8
|
-
* - For configuring the store to use these reactive objects, see [The Setup Guide](/guides/
|
|
9
|
-
* - For defining resource schemas, see [The Schema Guide](/guides)
|
|
8
|
+
* - For configuring the store to use these reactive objects, see [The Setup Guide](/guides/configuration/)
|
|
9
|
+
* - For defining resource schemas, see [The Schema Guide](/guides/the-manual/schemas/)
|
|
10
10
|
*
|
|
11
11
|
* Any method that returns a record instance will use the `instantiateRecord`
|
|
12
12
|
* hook configured above to instantiate a ReactiveResource once this is in place.
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* - local changes immediately reflect app wide
|
|
27
27
|
* - records have all the APIs of Model (references, state props, currentState, methods etc)
|
|
28
28
|
* - the continued use of `@warp-drive/legacy` is required (though most imports from it can be removed)
|
|
29
|
-
* - `async: true` relationships are supported (but not recommended outside of [LinksMode](
|
|
29
|
+
* - `async: true` relationships are supported (but not recommended outside of [LinksMode](/guides/the-manual/misc/links-mode.md))
|
|
30
30
|
*
|
|
31
31
|
* ---
|
|
32
32
|
*
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
* - local changes are isolated until committed, displaying only via the editable version of the record
|
|
39
39
|
* - records have a more limited API, focused on only what is in their schema.
|
|
40
40
|
* - some common operations may have more friction to perform because intended utilities are not yet available
|
|
41
|
-
* - `async: true` relationships are not supported (see [LinksMode](
|
|
41
|
+
* - `async: true` relationships are not supported (see [LinksMode](/guides/the-manual/misc/links-mode.md))
|
|
42
42
|
* - The `@warp-drive/legacy` package is not required
|
|
43
43
|
*
|
|
44
44
|
* These modes are interopable. The reactive object (record) for a resource in PolarisMode can relate to
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
* The shape of the object and the transformation of raw cache data into its
|
|
56
56
|
* reactive form is controlled by a resource schema.
|
|
57
57
|
*
|
|
58
|
-
* For instance, lets say your API is a [{
|
|
59
|
-
* the Cache provided by
|
|
58
|
+
* For instance, lets say your API is a [{json:api}](https://jsonapi.org) and your store is using
|
|
59
|
+
* the Cache provided by {@link @warp-drive/json-api! | @warp-drive/json-api}, and a request
|
|
60
60
|
* returns the following raw data:
|
|
61
61
|
*
|
|
62
62
|
* ```ts
|
|
@@ -277,5 +277,11 @@ export { type CAUTION_MEGA_DANGER_ZONE_Extension, type ProcessedExtension, type
|
|
|
277
277
|
export { commit, type ReactiveResource } from "./reactive/-private/record.js";
|
|
278
278
|
export { checkout };
|
|
279
279
|
export { Checkout } from "./reactive/-private/symbols.js";
|
|
280
|
-
export { type ReactiveDocument } from "./reactive/-private/document.js";
|
|
280
|
+
export { type ReactiveDocument, type ReactiveDataDocument, type ReactiveErrorDocument } from "./reactive/-private/document.js";
|
|
281
281
|
export { getExpensiveRequestSubscription } from "./store/-private/new-core-tmp/expensive-subscription.js";
|
|
282
|
+
export { createRequestSubscription, getRequestState, type RequestState } from "./store/-private.js";
|
|
283
|
+
export { getPromiseState, type PromiseState, type ResolvedPromise, type RejectedPromise, type PendingPromise } from "./store/-private/new-core-tmp/promise-state.js";
|
|
284
|
+
export type { LegacyLiveArray } from "./store/-private/record-arrays/legacy-live-array.js";
|
|
285
|
+
export type { LegacyManyArray } from "./store/-private/record-arrays/legacy-many-array.js";
|
|
286
|
+
export type { LegacyQueryArray } from "./store/-private/record-arrays/legacy-query.js";
|
|
287
|
+
export type { ReactiveResourceArray } from "./store/-private/record-arrays/resource-array.js";
|
|
@@ -27,7 +27,7 @@ export type DeferredStream = {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
* A Future is a {@link Promise} which resolves
|
|
30
|
+
* A Future is a {@link Promise} which resolves or rejects with a {@link StructuredDocument}
|
|
31
31
|
* while providing the ability to {@link Future.abort | abort} the underlying request, and
|
|
32
32
|
* {@link Future.getStream | access the response stream} before the outer promise resolves;
|
|
33
33
|
*
|
|
@@ -1,5 +1,52 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "./reactive.js";
|
|
2
|
+
import type { RequestInfo } from "./types/request.js";
|
|
3
|
+
import type { RequestSignature } from "./types/symbols.js";
|
|
1
4
|
export { createDeferred } from "./request/-private/future.js";
|
|
2
5
|
export type { Future, Handler, CacheHandler, NextFn, Deferred, ManagedRequestPriority } from "./request/-private/types.js";
|
|
3
6
|
export { setPromiseResult, getPromiseResult } from "./request/-private/promise-cache.js";
|
|
4
7
|
export type { Awaitable } from "./request/-private/promise-cache.js";
|
|
5
8
|
export type { Context } from "./request/-private/context.js";
|
|
9
|
+
/**
|
|
10
|
+
* Brands the supplied object with the supplied response type.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import type { ReactiveDataDocument } from '@warp-drive/core/reactive';
|
|
14
|
+
* import { withResponseType } from '@warp-drive/core/request';
|
|
15
|
+
* import type { User } from '#/data/user.ts'
|
|
16
|
+
*
|
|
17
|
+
* const result = await store.request(
|
|
18
|
+
* withResponseType<ReactiveDataDocument<User>>({ url: '/users/1' })
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* result.content.data; // will have type User
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
export declare function withResponseType<T>(obj: RequestInfo): RequestInfo<T> & {
|
|
26
|
+
[RequestSignature]: T;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Brands the supplied object with the supplied response type
|
|
30
|
+
* wrapped in {@link ReactiveDataDocument}. This is a convenience for
|
|
31
|
+
* the common case of using {@link withResponseType} with `ReactiveDataDocument`.
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { withReactiveResponse } from '@warp-drive/core/request';
|
|
35
|
+
* import type { User } from '#/data/user.ts'
|
|
36
|
+
*
|
|
37
|
+
* const result = await store.request(
|
|
38
|
+
* withReactiveResponse<User>({ url: '/users/1' })
|
|
39
|
+
* );
|
|
40
|
+
*
|
|
41
|
+
* result.content.data; // will have type User
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export declare function withReactiveResponse<T>(obj: RequestInfo): RequestInfo<ReactiveDataDocument<T>> & {
|
|
47
|
+
[RequestSignature]: ReactiveDataDocument<T>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated use {@link withResponseType} instead
|
|
51
|
+
*/
|
|
52
|
+
export declare const withBrand: typeof withResponseType;
|