@warp-drive-mirror/json-api 5.8.0-alpha.4 → 5.8.0-alpha.40
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 +17 -30
- package/declarations/-private/cache.d.ts +9 -77
- package/declarations/index.d.ts +4 -0
- package/dist/index.js +225 -237
- package/dist/unpkg/dev/index.js +3338 -0
- package/dist/unpkg/dev-deprecated/index.js +3299 -0
- package/dist/unpkg/prod/index.js +1872 -0
- package/dist/unpkg/prod-deprecated/index.js +1872 -0
- 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 +13 -5
- 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,54 +1,41 @@
|
|
|
1
|
-
<
|
|
2
|
-
<img
|
|
3
|
-
class="project-logo"
|
|
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
3
|
class="project-logo"
|
|
10
|
-
src="./logos/
|
|
11
|
-
alt="WarpDrive
|
|
12
|
-
|
|
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
|
|
|
19
|
+
# @warp-drive-mirror/json-api
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
<p align="center">
|
|
29
|
-
A {JSON:API} Cache Implementation for <em>Warp</em><strong>Drive</strong>.
|
|
30
|
-
</p>
|
|
31
|
-
|
|
32
|
-
<br>
|
|
21
|
+
A {json:api} Cache Implementation for ***Warp*Drive**.
|
|
33
22
|
|
|
34
|
-
|
|
23
|
+
`{json:api}` excels at simplifying common complex problems around cache consistency and information density, especially in regards to relational or polymorphic data.
|
|
35
24
|
|
|
36
|
-
|
|
37
|
-
pnpm add -E @warp-drive-mirror/json-api
|
|
38
|
-
```
|
|
25
|
+
Because most API responses can be quickly transformed into the `{json:api}` format without losing any information, ***Warp*Drive** recommends that most-if-not-all apps should use this Cache implementation.
|
|
39
26
|
|
|
40
27
|
<br>
|
|
41
28
|
|
|
42
29
|
## Documentation
|
|
43
30
|
|
|
44
|
-
*Get Started* → [Guides](https://
|
|
31
|
+
*Get Started* → [Guides](https://warp-drive.io)
|
|
45
32
|
|
|
46
33
|
|
|
47
34
|
<br>
|
|
48
35
|
|
|
49
36
|
## Code of Conduct
|
|
50
37
|
|
|
51
|
-
Refer to the [Code of Conduct](https://github.com/
|
|
38
|
+
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.
|
|
52
39
|
|
|
53
40
|
<br>
|
|
54
41
|
|
|
@@ -11,82 +11,12 @@ import type { CollectionResourceDataDocument, ResourceDocument, ResourceErrorDoc
|
|
|
11
11
|
import type { ApiError } from "@warp-drive-mirror/core/types/spec/error";
|
|
12
12
|
import type { CollectionResourceDocument, ExistingResourceObject, ResourceObject, SingleResourceDocument } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
13
13
|
/**
|
|
14
|
-
* ### JSONAPICache
|
|
15
|
-
*
|
|
16
14
|
* ```ts
|
|
17
15
|
* import { JSONAPICache } from '@warp-drive-mirror/json-api';
|
|
18
16
|
* ```
|
|
19
17
|
*
|
|
20
|
-
A {@link Cache} implementation tuned for [{json:api}](https://jsonapi.org/)
|
|
21
|
-
|
|
22
|
-
This format excels at simiplifying common complex problems around cache
|
|
23
|
-
consistency and information density. Because most API responses can be quickly
|
|
24
|
-
transformed into {json:api} format without losing any information, WarpDrive
|
|
25
|
-
recommends that most apps use this Cache implementation.
|
|
26
|
-
|
|
27
|
-
If a cache built to understand another format would do better for your app then
|
|
28
|
-
it just needs to follow the same interface.
|
|
29
|
-
|
|
30
|
-
Do you really need a cache? Are sunsets beautiful? Caching is what powers features like
|
|
31
|
-
immutability, mutation management, and allows ***Warp*Drive** to understand your relational
|
|
32
|
-
data.
|
|
33
|
-
|
|
34
|
-
Some caches are simple request/response maps. ***Warp*Drive**'s is not. The Cache deeply
|
|
35
|
-
understands the structure of your data, ensuring your data remains consistent both within
|
|
36
|
-
and across requests.
|
|
37
|
-
|
|
38
|
-
### Installation
|
|
39
|
-
|
|
40
|
-
::: code-group
|
|
41
|
-
|
|
42
|
-
```sh [pnpm]
|
|
43
|
-
pnpm add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
```sh [npm]
|
|
47
|
-
npm add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
```sh [yarn]
|
|
51
|
-
yarn add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
```sh [bun]
|
|
55
|
-
bun add --exact @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
:::
|
|
59
|
-
|
|
60
|
-
### Setup
|
|
61
|
-
|
|
62
|
-
```ts [services/store.ts]
|
|
63
|
-
import { Fetch, RequestManager, Store } from '@warp-drive-mirror/core';
|
|
64
|
-
import {
|
|
65
|
-
registerDerivations,
|
|
66
|
-
SchemaService,
|
|
67
|
-
} from '@warp-drive-mirror/core/reactive';
|
|
68
|
-
import { CacheHandler } from '@warp-drive-mirror/core/store';
|
|
69
|
-
import type { CacheCapabilitiesManager } from '@warp-drive-mirror/core/types'; // [!code focus:2]
|
|
70
|
-
import { JSONAPICache } from '@warp-drive-mirror/json-api';
|
|
71
|
-
|
|
72
|
-
export default class AppStore extends Store {
|
|
73
|
-
|
|
74
|
-
requestManager = new RequestManager()
|
|
75
|
-
.use([Fetch])
|
|
76
|
-
.useCache(CacheHandler);
|
|
77
|
-
|
|
78
|
-
createSchemaService() {
|
|
79
|
-
const schema = new SchemaService();
|
|
80
|
-
registerDerivations(schema);
|
|
81
|
-
return schema;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
createCache(capabilities: CacheCapabilitiesManager) { // [!code focus:3]
|
|
85
|
-
return new JSONAPICache(capabilities);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
18
|
+
* A {@link Cache} implementation tuned for [{json:api}](https://jsonapi.org/)
|
|
19
|
+
*
|
|
90
20
|
* @categoryDescription Cache Management
|
|
91
21
|
* APIs for primary cache management functionality
|
|
92
22
|
* @categoryDescription Cache Forking
|
|
@@ -99,8 +29,8 @@ return new JSONAPICache(capabilities);
|
|
|
99
29
|
* APIs that support granular field level management of resource data
|
|
100
30
|
* @categoryDescription Resource State
|
|
101
31
|
* APIs that support managing Resource states
|
|
102
|
-
|
|
103
|
-
@public
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
104
34
|
*/
|
|
105
35
|
export declare class JSONAPICache implements Cache {
|
|
106
36
|
/**
|
|
@@ -325,7 +255,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
325
255
|
* @category Resource Lifecycle
|
|
326
256
|
* @public
|
|
327
257
|
*/
|
|
328
|
-
willCommit(identifier: ResourceKey, _context: RequestContext | null): void;
|
|
258
|
+
willCommit(identifier: ResourceKey | ResourceKey[], _context: RequestContext | null): void;
|
|
329
259
|
/**
|
|
330
260
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
331
261
|
* was successfully updated as part of a save transaction.
|
|
@@ -333,7 +263,9 @@ export declare class JSONAPICache implements Cache {
|
|
|
333
263
|
* @category Resource Lifecycle
|
|
334
264
|
* @public
|
|
335
265
|
*/
|
|
336
|
-
didCommit(committedIdentifier: ResourceKey, result: StructuredDataDocument<
|
|
266
|
+
didCommit(committedIdentifier: ResourceKey, result: StructuredDataDocument<SingleResourceDataDocument> | null): SingleResourceDataDocument;
|
|
267
|
+
didCommit(committedIdentifier: ResourceKey[], result: StructuredDataDocument<SingleResourceDataDocument> | null): SingleResourceDataDocument;
|
|
268
|
+
didCommit(committedIdentifier: ResourceKey[], result: StructuredDataDocument<CollectionResourceDataDocument> | null): CollectionResourceDataDocument;
|
|
337
269
|
/**
|
|
338
270
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
339
271
|
* was update via a save transaction failed.
|
|
@@ -341,7 +273,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
341
273
|
* @category Resource Lifecycle
|
|
342
274
|
* @public
|
|
343
275
|
*/
|
|
344
|
-
commitWasRejected(identifier: ResourceKey, errors?: ApiError[]): void;
|
|
276
|
+
commitWasRejected(identifier: ResourceKey | ResourceKey[], errors?: ApiError[]): void;
|
|
345
277
|
/**
|
|
346
278
|
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
347
279
|
* should be cleared.
|