@warp-drive/core 5.6.0-alpha.5 → 5.6.0-beta.0
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 +8 -7
- package/cjs-dist/addon-shim.cjs +1 -0
- package/cjs-dist/cjs-set-config.cjs +1 -0
- package/declarations/build-config/babel-macros.d.ts +1 -0
- package/declarations/build-config/canary-features.d.ts +1 -0
- package/declarations/build-config/debugging.d.ts +1 -0
- package/declarations/build-config/deprecations.d.ts +1 -0
- package/declarations/build-config/env.d.ts +1 -0
- package/declarations/build-config/macros.d.ts +1 -0
- package/declarations/build-config.d.ts +1 -0
- package/declarations/configure.d.ts +7 -0
- package/declarations/graph/-private/-diff.d.ts +32 -0
- package/declarations/graph/-private/-edge-definition.d.ts +148 -0
- package/declarations/graph/-private/-state.d.ts +96 -0
- package/declarations/graph/-private/-utils.d.ts +31 -0
- package/declarations/graph/-private/coerce-id.d.ts +10 -0
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +18 -0
- package/declarations/graph/-private/edges/collection.d.ts +39 -0
- package/declarations/graph/-private/edges/implicit.d.ts +43 -0
- package/declarations/graph/-private/edges/resource.d.ts +24 -0
- package/declarations/graph/-private/graph.d.ts +90 -0
- package/declarations/graph/-private/normalize-link.d.ts +8 -0
- package/declarations/graph/-private/operations/add-to-related-records.d.ts +4 -0
- package/declarations/graph/-private/operations/merge-identifier.d.ts +3 -0
- package/declarations/graph/-private/operations/remove-from-related-records.d.ts +4 -0
- package/declarations/graph/-private/operations/replace-related-record.d.ts +3 -0
- package/declarations/graph/-private/operations/replace-related-records.d.ts +62 -0
- package/declarations/graph/-private/operations/update-relationship.d.ts +13 -0
- package/declarations/graph/-private.d.ts +13 -0
- package/declarations/index.d.ts +14 -3
- package/declarations/reactive/-private/document.d.ts +146 -0
- package/declarations/reactive/-private/fields/compute.d.ts +43 -0
- package/declarations/reactive/-private/fields/extension.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +22 -0
- package/declarations/reactive/-private/fields/managed-object.d.ts +21 -0
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +19 -0
- package/declarations/reactive/-private/hooks.d.ts +5 -0
- package/declarations/reactive/-private/record.d.ts +64 -0
- package/declarations/reactive/-private/schema.d.ts +271 -0
- package/declarations/reactive/-private/symbols.d.ts +36 -0
- package/declarations/reactive/-private.d.ts +1 -0
- package/declarations/reactive.d.ts +4 -0
- package/declarations/request/-private/context.d.ts +34 -35
- package/declarations/request/-private/debug.d.ts +2 -3
- package/declarations/request/-private/fetch.d.ts +24 -36
- package/declarations/request/-private/future.d.ts +3 -4
- package/declarations/request/-private/manager.d.ts +159 -132
- package/declarations/request/-private/promise-cache.d.ts +21 -13
- package/declarations/request/-private/types.d.ts +124 -123
- package/declarations/request/-private/utils.d.ts +8 -9
- package/declarations/request.d.ts +5 -433
- package/declarations/store/-private/cache-handler/handler.d.ts +62 -0
- package/declarations/store/-private/cache-handler/types.d.ts +98 -0
- package/declarations/store/-private/cache-handler/utils.d.ts +32 -0
- package/declarations/store/-private/caches/cache-utils.d.ts +12 -0
- package/declarations/store/-private/caches/identifier-cache.d.ts +304 -0
- package/declarations/store/-private/caches/instance-cache.d.ts +65 -0
- package/declarations/store/-private/caches/resource-utils.d.ts +9 -0
- package/declarations/store/-private/debug/utils.d.ts +6 -0
- package/declarations/store/-private/default-cache-policy.d.ts +384 -0
- package/declarations/store/-private/legacy-model-support/record-reference.d.ts +159 -0
- package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +17 -0
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +25 -0
- package/declarations/store/-private/managers/cache-manager.d.ts +443 -0
- package/declarations/store/-private/managers/notification-manager.d.ts +98 -0
- package/declarations/store/-private/managers/record-array-manager.d.ts +97 -0
- package/declarations/store/-private/network/request-cache.d.ts +107 -0
- package/declarations/store/-private/new-core-tmp/promise-state.d.ts +263 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +176 -0
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +169 -0
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +35 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +277 -0
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +261 -0
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +147 -0
- package/declarations/store/-private/record-arrays/many-array.d.ts +197 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +126 -0
- package/declarations/store/-private/store-service.d.ts +1605 -0
- package/declarations/store/-private/utils/coerce-id.d.ts +10 -0
- package/declarations/store/-private/utils/construct-resource.d.ts +6 -0
- package/declarations/store/-private/utils/is-non-empty-string.d.ts +1 -0
- package/declarations/store/-private/utils/normalize-model-name.d.ts +1 -0
- package/declarations/store/-private/utils/uuid-polyfill.d.ts +1 -0
- package/declarations/store/-private.d.ts +31 -0
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +99 -0
- package/declarations/store/-types/q/ds-model.d.ts +21 -0
- package/declarations/store/-types/q/identifier.d.ts +20 -0
- package/declarations/store/-types/q/record-instance.d.ts +23 -0
- package/declarations/store/-types/q/schema-service.d.ts +354 -0
- package/declarations/store/-types/q/store.d.ts +32 -0
- package/declarations/store.d.ts +1 -0
- package/declarations/types/-private.d.ts +16 -8
- package/declarations/types/cache/aliases.d.ts +11 -1
- package/declarations/types/cache/change.d.ts +4 -5
- package/declarations/types/cache/mutations.d.ts +51 -28
- package/declarations/types/cache/operations.d.ts +60 -47
- package/declarations/types/cache/relationship.d.ts +11 -9
- package/declarations/types/cache.d.ts +495 -484
- package/declarations/types/graph.d.ts +31 -40
- package/declarations/types/identifier.d.ts +83 -82
- package/declarations/types/json/raw.d.ts +1 -2
- package/declarations/types/params.d.ts +4 -5
- package/declarations/types/record.d.ts +117 -76
- package/declarations/types/request.d.ts +289 -266
- package/declarations/types/runtime.d.ts +8 -9
- package/declarations/types/schema/concepts.d.ts +19 -13
- package/declarations/types/schema/fields.d.ts +1712 -1741
- package/declarations/types/schema/fields.type-test.d.ts +0 -1
- package/declarations/types/spec/document.d.ts +28 -22
- package/declarations/types/spec/error.d.ts +16 -17
- package/declarations/types/spec/json-api-raw.d.ts +102 -102
- package/declarations/types/symbols.d.ts +74 -75
- package/declarations/types/utils.d.ts +5 -5
- package/declarations/types.d.ts +10 -7
- package/declarations/utils/string.d.ts +48 -0
- package/dist/build-config/babel-macros.js +1 -0
- package/dist/build-config/canary-features.js +1 -0
- package/dist/build-config/debugging.js +1 -0
- package/dist/build-config/deprecations.js +1 -0
- package/dist/build-config/env.js +1 -0
- package/dist/build-config/macros.js +1 -0
- package/dist/build-config.js +1 -0
- package/dist/configure-B48bFHOl.js +181 -0
- package/dist/configure.js +1 -0
- package/dist/{context-DE5sFezZ.js → context-COmAnXUQ.js} +2 -2
- package/dist/graph/-private.js +3372 -0
- package/dist/handler-C2T-IyJK.js +339 -0
- package/dist/index.js +37 -104
- package/dist/reactive/-private.js +1 -0
- package/dist/reactive.js +1988 -0
- package/dist/request-state-CjLph1LP.js +8139 -0
- package/dist/request.js +1 -1
- package/dist/store/-private.js +3 -0
- package/dist/store.js +545 -0
- package/dist/symbols-SIstXMLI.js +44 -0
- package/dist/types/-private.js +3 -3
- package/dist/types/record.js +1 -1
- package/dist/types/request.js +2 -2
- package/dist/types/runtime.js +1 -1
- package/dist/types/schema/fields.js +8 -41
- package/dist/types/symbols.js +3 -3
- package/dist/utils/string.js +92 -0
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/ember-data-logo-dark.svg +12 -0
- package/logos/ember-data-logo-light.svg +12 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +11 -8
- package/declarations/index.d.ts.map +0 -1
- package/declarations/request/-private/context.d.ts.map +0 -1
- package/declarations/request/-private/debug.d.ts.map +0 -1
- package/declarations/request/-private/fetch.d.ts.map +0 -1
- package/declarations/request/-private/future.d.ts.map +0 -1
- package/declarations/request/-private/manager.d.ts.map +0 -1
- package/declarations/request/-private/promise-cache.d.ts.map +0 -1
- package/declarations/request/-private/types.d.ts.map +0 -1
- package/declarations/request/-private/utils.d.ts.map +0 -1
- package/declarations/request.d.ts.map +0 -1
- package/declarations/types/-private.d.ts.map +0 -1
- package/declarations/types/cache/aliases.d.ts.map +0 -1
- package/declarations/types/cache/change.d.ts.map +0 -1
- package/declarations/types/cache/mutations.d.ts.map +0 -1
- package/declarations/types/cache/operations.d.ts.map +0 -1
- package/declarations/types/cache/relationship.d.ts.map +0 -1
- package/declarations/types/cache.d.ts.map +0 -1
- package/declarations/types/graph.d.ts.map +0 -1
- package/declarations/types/identifier.d.ts.map +0 -1
- package/declarations/types/json/raw.d.ts.map +0 -1
- package/declarations/types/params.d.ts.map +0 -1
- package/declarations/types/record.d.ts.map +0 -1
- package/declarations/types/record.type-test.d.ts +0 -2
- package/declarations/types/record.type-test.d.ts.map +0 -1
- package/declarations/types/request.d.ts.map +0 -1
- package/declarations/types/request.type-test.d.ts +0 -2
- package/declarations/types/request.type-test.d.ts.map +0 -1
- package/declarations/types/runtime.d.ts.map +0 -1
- package/declarations/types/schema/concepts.d.ts.map +0 -1
- package/declarations/types/schema/fields.d.ts.map +0 -1
- package/declarations/types/schema/fields.type-test.d.ts.map +0 -1
- package/declarations/types/spec/document.d.ts.map +0 -1
- package/declarations/types/spec/error.d.ts.map +0 -1
- package/declarations/types/spec/json-api-raw.d.ts.map +0 -1
- package/declarations/types/symbols.d.ts.map +0 -1
- package/declarations/types/utils.d.ts.map +0 -1
- package/declarations/types.d.ts.map +0 -1
- package/dist/context-DE5sFezZ.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/request.js.map +0 -1
- package/dist/types/-private.js.map +0 -1
- package/dist/types/cache/aliases.js.map +0 -1
- package/dist/types/cache/change.js.map +0 -1
- package/dist/types/cache/mutations.js.map +0 -1
- package/dist/types/cache/operations.js.map +0 -1
- package/dist/types/cache/relationship.js.map +0 -1
- package/dist/types/cache.js.map +0 -1
- package/dist/types/graph.js.map +0 -1
- package/dist/types/identifier.js.map +0 -1
- package/dist/types/json/raw.js.map +0 -1
- package/dist/types/params.js.map +0 -1
- package/dist/types/record.js.map +0 -1
- package/dist/types/request.js.map +0 -1
- package/dist/types/runtime.js.map +0 -1
- package/dist/types/schema/concepts.js.map +0 -1
- package/dist/types/schema/fields.js.map +0 -1
- package/dist/types/schema/fields.type-test.js.map +0 -1
- package/dist/types/spec/document.js.map +0 -1
- package/dist/types/spec/error.js.map +0 -1
- package/dist/types/spec/json-api-raw.js.map +0 -1
- package/dist/types/symbols.js.map +0 -1
- package/dist/types/utils.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type { RequestInfo, StructuredDataDocument } from
|
|
2
|
-
import { ContextOwner } from
|
|
3
|
-
import type { DeferredFuture, Future, GodContext, Handler } from
|
|
1
|
+
import type { RequestInfo, StructuredDataDocument } from "../../types/request.js";
|
|
2
|
+
import { ContextOwner } from "./context.js";
|
|
3
|
+
import type { DeferredFuture, Future, GodContext, Handler } from "./types.js";
|
|
4
4
|
export declare const IS_CACHE_HANDLER: "___(unique) Symbol(IS_CACHE_HANDLER)";
|
|
5
5
|
export declare function curryFuture<T>(owner: ContextOwner, inbound: Future<T>, outbound: DeferredFuture<T>): Future<T>;
|
|
6
6
|
export interface HttpErrorProps extends DOMException {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
code: number;
|
|
8
|
+
name: string;
|
|
9
|
+
status: number;
|
|
10
|
+
statusText: string;
|
|
11
|
+
isRequestError: boolean;
|
|
12
12
|
}
|
|
13
13
|
export declare function enhanceReason(reason?: string): DOMException;
|
|
14
14
|
export declare function handleOutcome<T>(owner: ContextOwner, inbound: Promise<T | StructuredDataDocument<T>>, outbound: DeferredFuture<T>): Future<T>;
|
|
15
15
|
export declare function executeNextHandler<T>(wares: Readonly<Handler[]>, request: RequestInfo, i: number, god: GodContext): Future<T>;
|
|
16
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1,433 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
src="https://raw.githubusercontent.com/emberjs/data/4612c9354e4c54d53327ec2cf21955075ce21294/ember-data-logo-light.svg#gh-light-mode-only"
|
|
7
|
-
alt="EmberData RequestManager"
|
|
8
|
-
width="240px"
|
|
9
|
-
title="EmberData RequestManager"
|
|
10
|
-
/>
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
<p align="center">⚡️ a simple abstraction over fetch to enable easy management of request/response flows</p>
|
|
14
|
-
|
|
15
|
-
This package provides [*Ember***Data**](https://github.com/emberjs/data/)'s `RequestManager`, a framework agnostic library that can be integrated with any Javascript application to make [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) happen.
|
|
16
|
-
|
|
17
|
-
- [Installation](#installation)
|
|
18
|
-
- [Basic Usage](#🚀-basic-usage)
|
|
19
|
-
- [Architecture](#🪜-architecture)
|
|
20
|
-
- [Usage](#usage)
|
|
21
|
-
- [Making Requests](#making-requests)
|
|
22
|
-
- [Using The Response](#using-the-response)
|
|
23
|
-
- [Request Handlers](#handling-requests)
|
|
24
|
-
- [Handling Errors](#handling-errors)
|
|
25
|
-
- [Handling Abort](#handling-abort)
|
|
26
|
-
- [Stream Currying](#stream-currying)
|
|
27
|
-
- [Automatic Currying](#automatic-currying-of-stream-and-response)
|
|
28
|
-
- [Using as a Service](#using-as-a-service)
|
|
29
|
-
- [Using with `@ember-data/store`](#using-with-ember-datastore)
|
|
30
|
-
- [Using with `ember-data`](#using-with-ember-data)
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## Installation
|
|
35
|
-
|
|
36
|
-
Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
|
|
37
|
-
|
|
38
|
-
```no-highlight
|
|
39
|
-
pnpm add @ember-data/request
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## 🚀 Basic Usage
|
|
45
|
-
|
|
46
|
-
A `RequestManager` provides a request/response flow in which configured handlers are successively given the opportunity to handle, modify, or pass-along a request.
|
|
47
|
-
|
|
48
|
-
The RequestManager on its own does not know how to fulfill requests. For this we must register at least one handler. A basic `Fetch` handler is provided that will take the request options provided and execute `fetch`.
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
import RequestManager from '@ember-data/request';
|
|
52
|
-
import Fetch from '@ember-data/request/fetch';
|
|
53
|
-
import { apiUrl } from './config';
|
|
54
|
-
|
|
55
|
-
// ... create manager and add our Fetch handler
|
|
56
|
-
const manager = new RequestManager()
|
|
57
|
-
.use([Fetch]);
|
|
58
|
-
|
|
59
|
-
// ... execute a request
|
|
60
|
-
const response = await manager.request({
|
|
61
|
-
url: `${apiUrl}/users`
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
## 🪜 Architecture
|
|
68
|
-
|
|
69
|
-
A `RequestManager` receives a request and manages fulfillment via configured handlers. It may be used standalone from the rest of *Ember***Data** and is not specific to any library or framework.
|
|
70
|
-
|
|
71
|
-
Each handler may choose to fulfill the request using some source of data or to pass the request along to other handlers.
|
|
72
|
-
|
|
73
|
-
The same or a separate instance of a `RequestManager` may also be used to fulfill requests issued by [*Ember***Data**{Store}](https://github.com/emberjs/data/tree/main/packages/store)
|
|
74
|
-
|
|
75
|
-
When the same instance is used by both this allows for simple coordination throughout the application. Requests issued by the Store will use the in-memory cache
|
|
76
|
-
and return hydrated responses, requests issued directly to the RequestManager
|
|
77
|
-
will skip the in-memory cache and return raw responses.
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Usage
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
const userList = await manager.request({
|
|
85
|
-
url: `/api/v1/users.list`
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const users = userList.content;
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
### Making Requests
|
|
94
|
-
|
|
95
|
-
`RequestManager` has a single asyncronous method as it's API: `request`
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
class RequestManager {
|
|
99
|
-
request<T>(req: RequestInfo): Future<T>;
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
`manager.request(<RequestInfo>)` accepts an object containing the information
|
|
104
|
-
necessary for the request to be handled successfully.
|
|
105
|
-
|
|
106
|
-
These options extend the [options](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters) provided to `fetch`, and can accept a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request). All properties accepted by Request options and fetch options are valid.
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
interface RequestInfo extends FetchOptions {
|
|
110
|
-
op?: string;
|
|
111
|
-
store?: Store;
|
|
112
|
-
|
|
113
|
-
url: string;
|
|
114
|
-
// data that a handler should convert into
|
|
115
|
-
// the query (GET) or body (POST)
|
|
116
|
-
data?: Record<string, unknown>;
|
|
117
|
-
|
|
118
|
-
// options specifically intended for handlers
|
|
119
|
-
// to utilize to process the request
|
|
120
|
-
options?: Record<string, unknown>;
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
> **note**
|
|
125
|
-
> providing a `signal` is unnecessary as an `AbortController` is automatically provided if none is present.
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
#### Using the Response
|
|
130
|
-
|
|
131
|
-
`manager.request` returns a `Future`, which allows access to limited information about the request while it is still pending and fulfills with the final state when the request completes and the response has been read.
|
|
132
|
-
|
|
133
|
-
```ts
|
|
134
|
-
const usersFuture = manager.request({
|
|
135
|
-
url: `/api/v1/users.list`
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
A `Future` is cancellable via `abort`.
|
|
140
|
-
|
|
141
|
-
```ts
|
|
142
|
-
usersFuture.abort();
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
Handlers may *optionally* expose a ReadableStream to the `Future` for streaming data; however, when doing so the handler should not resolve until it has fully read the response stream itself.
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
interface Future<T> extends Promise<StructuredDocument<T>> {
|
|
149
|
-
abort(): void;
|
|
150
|
-
|
|
151
|
-
async getStream(): ReadableStream | null;
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
A Future resolves or rejects with a `StructuredDocument`.
|
|
156
|
-
|
|
157
|
-
```ts
|
|
158
|
-
interface StructuredDocument<T> {
|
|
159
|
-
request: RequestInfo;
|
|
160
|
-
response: ResponseInfo | null;
|
|
161
|
-
content?: T;
|
|
162
|
-
error?: Error;
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
The `RequestInfo` specified by `document.request` is the same as originally provided to `manager.request`. If any handler fulfilled this request using different request info it is not represented here. This contract helps to ensure that `retry` and `caching` are possible since the original arguments are correctly preserved. This also allows handlers to "fork" the request or fulfill from multiple sources without the details of fulfillment muddying the original request.
|
|
167
|
-
|
|
168
|
-
The `ResponseInfo` is a serializable fulfilled subset of a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) if set via `setResponse`. If no response was ever set this will be `null`.
|
|
169
|
-
|
|
170
|
-
```ts
|
|
171
|
-
interface ResponseInfo {
|
|
172
|
-
headers?: Record<string, string>;
|
|
173
|
-
ok?: boolean;
|
|
174
|
-
redirected?: boolean;
|
|
175
|
-
status?: HTTPStatusCode;
|
|
176
|
-
statusText?: string;
|
|
177
|
-
type?: 'basic' | 'cors';
|
|
178
|
-
url?: string;
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
### Request Handlers
|
|
185
|
-
|
|
186
|
-
Requests are fulfilled by handlers. A handler receives the request context
|
|
187
|
-
as well as a `next` function with which to pass along a request to the next
|
|
188
|
-
handler if it so chooses.
|
|
189
|
-
|
|
190
|
-
A handler may be any object with a `request` method. This allows both stateful and non-stateful
|
|
191
|
-
handlers to be utilized.
|
|
192
|
-
|
|
193
|
-
If a handler calls `next`, it receives a `Future` which resolves to a `StructuredDocument`
|
|
194
|
-
that it can then compose how it sees fit with its own response.
|
|
195
|
-
|
|
196
|
-
```ts
|
|
197
|
-
|
|
198
|
-
type NextFn<P> = (req: RequestInfo) => Future<P>;
|
|
199
|
-
|
|
200
|
-
interface Handler {
|
|
201
|
-
async request<T>(context: RequestContext, next: NextFn<P>): T;
|
|
202
|
-
}
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
`RequestContext` contains a readonly version of the RequestInfo as well as a few methods for building up the `StructuredDocument` and `Future` that will be part of the response.
|
|
206
|
-
|
|
207
|
-
```ts
|
|
208
|
-
interface RequestContext<T> {
|
|
209
|
-
readonly request: RequestInfo;
|
|
210
|
-
|
|
211
|
-
setStream(stream: ReadableStream | Promise<ReadableStream>): void;
|
|
212
|
-
setResponse(response: Response | ResponseInfo): void;
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
A basic `fetch` handler with support for streaming content updates while
|
|
217
|
-
the download is still underway might look like the following, where we use
|
|
218
|
-
[`response.clone()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/clone) to `tee` the `ReadableStream` into two streams.
|
|
219
|
-
|
|
220
|
-
A more efficient handler might read from the response stream, building up the
|
|
221
|
-
response content before passing along the chunk downstream.
|
|
222
|
-
|
|
223
|
-
```ts
|
|
224
|
-
const FetchHandler = {
|
|
225
|
-
async request(context) {
|
|
226
|
-
const response = await fetch(context.request);
|
|
227
|
-
context.setResponse(reponse);
|
|
228
|
-
context.setStream(response.clone().body);
|
|
229
|
-
|
|
230
|
-
return response.json();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
Request handlers are registered by configuring the manager via `use`
|
|
236
|
-
|
|
237
|
-
```ts
|
|
238
|
-
manager.use([Handler1, Handler2])
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
Handlers will be invoked in the order they are registered ("fifo", first-in first-out), and may only be registered up until the first request is made. It is recommended but not required to register all handlers at one time in order to ensure explicitly visible handler ordering.
|
|
242
|
-
|
|
243
|
-
---
|
|
244
|
-
|
|
245
|
-
#### Handling Errors
|
|
246
|
-
|
|
247
|
-
Each handler in the chain can catch errors from upstream and choose to
|
|
248
|
-
either handle the error, re-throw the error, or throw a new error.
|
|
249
|
-
|
|
250
|
-
```ts
|
|
251
|
-
const MAX_RETRIES = 5;
|
|
252
|
-
|
|
253
|
-
const Handler = {
|
|
254
|
-
async request(context, next) {
|
|
255
|
-
let attempts = 0;
|
|
256
|
-
|
|
257
|
-
while (attempts < MAX_RETRIES) {
|
|
258
|
-
attempts++;
|
|
259
|
-
try {
|
|
260
|
-
const response = await next(context.request);
|
|
261
|
-
return response;
|
|
262
|
-
} catch (e) {
|
|
263
|
-
if (isTimeoutError(e) && attempts < MAX_RETRIES) {
|
|
264
|
-
// retry request
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
// rethrow if it is not a timeout error
|
|
268
|
-
throw e;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
---
|
|
276
|
-
|
|
277
|
-
#### Handling Abort
|
|
278
|
-
|
|
279
|
-
Aborting a request will reject the current handler in the chain. However,
|
|
280
|
-
every handler can potentially catch this error. If your handler needs to
|
|
281
|
-
separate AbortError from other Error types, it is recommended to check
|
|
282
|
-
`context.request.signal.aborted` (or if a custom controller was supplied `controller.signal.aborted`).
|
|
283
|
-
|
|
284
|
-
In this manner it is possible for a request to recover from an abort and
|
|
285
|
-
still proceed; however, as a best practice this should be used for necessary
|
|
286
|
-
cleanup only and the original AbortError rethrown if the abort signal comes
|
|
287
|
-
from the root controller.
|
|
288
|
-
|
|
289
|
-
**AbortControllers are Always Present and Always Entangled**
|
|
290
|
-
|
|
291
|
-
If the initial request does not supply an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController), one will be generated.
|
|
292
|
-
|
|
293
|
-
The [signal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) for this controller is automatically added to the request passed into the first handler.
|
|
294
|
-
|
|
295
|
-
Each handler has the option to supply a new controller to the request when calling `next`. If a new controller is provided it will be automatically
|
|
296
|
-
entangled with the root controller. If the root controller aborts, so will
|
|
297
|
-
any entangled controllers.
|
|
298
|
-
|
|
299
|
-
If an entangled controller aborts, the root controller will not abort. This
|
|
300
|
-
allows for advanced request-flow scenarios to abort subsections of the request tree without aborting the entire request.
|
|
301
|
-
|
|
302
|
-
---
|
|
303
|
-
|
|
304
|
-
#### Stream Currying
|
|
305
|
-
|
|
306
|
-
`RequestManager.request` and `next` differ from `fetch` in one **crucial detail** in that the outer Promise resolves only once the response stream has been processed.
|
|
307
|
-
|
|
308
|
-
For context, it helps to understand a few of the use-cases that RequestManager
|
|
309
|
-
is intended to allow.
|
|
310
|
-
|
|
311
|
-
- to manage and return streaming content (such as video files)
|
|
312
|
-
- to fulfill a request from multiple sources or by splitting one request into multiple requests
|
|
313
|
-
- for instance one API call for a user and another for the user's friends
|
|
314
|
-
- or e.g. fulfilling part of the request from one source (one API, in-memory, localStorage, IndexedDB
|
|
315
|
-
etc.) and the rest from another source (a different API, a WebWorker, etc.)
|
|
316
|
-
- to coalesce multiple requests
|
|
317
|
-
- to decorate a request with additional info
|
|
318
|
-
- e.g. an Auth handler that ensures the correct tokens or headers or cookies are attached.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
`await fetch(<req>)` resolves at the moment headers are received. This allows for the body of the request to be processed as a stream by application
|
|
322
|
-
code *while chunks are still being received by the browser*.
|
|
323
|
-
|
|
324
|
-
When an app chooses to `await response.json()` what occurs is the browser reads the stream to completion and then returns the result. Additionally, this stream may only be read **once**.
|
|
325
|
-
|
|
326
|
-
The `RequestManager` preserves this ability to subscribe to and utilize the stream by either the application or the handler – thereby delivering the full power and flexibility of native APIs – without restricting developers in ways that lead to complicated workarounds.
|
|
327
|
-
|
|
328
|
-
Each handler may call `setStream` only once, but may do so *at any time* until the promise that the handler returns has resolved. The associated promise returned by calling `future.getStream` will resolve with the stream set by `setStream` if that method is called, or `null` if that method
|
|
329
|
-
has not been called by the time that the handler's request method has resolved.
|
|
330
|
-
|
|
331
|
-
Handlers that do not create a stream of their own, but which call `next`, should defensively pipe the stream forward. While this is not required (see automatic currying below) it is better to do so in most cases as otherwise the stream may not become available to downstream handlers or the application until the upstream handler has fully read it.
|
|
332
|
-
|
|
333
|
-
```ts
|
|
334
|
-
context.setStream(future.getStream());
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
Handlers that either call `next` multiple times or otherwise have reason to create multiple fetch requests should either choose to return no stream, meaningfully combine the streams, or select a single prioritized stream.
|
|
338
|
-
|
|
339
|
-
Of course, any handler may choose to read and handle the stream, and return either no stream or a different stream in the process.
|
|
340
|
-
|
|
341
|
-
---
|
|
342
|
-
|
|
343
|
-
#### Automatic Currying of Stream and Response
|
|
344
|
-
|
|
345
|
-
In order to simplify the common case for handlers which decorate a request, if `next` is called only a single time and `setResponse` was never called by the handler, the response set by the next handler in the chain will be applied to that handler's outcome. For instance, this makes the following pattern possible `return (await next(<req>)).content;`.
|
|
346
|
-
|
|
347
|
-
Similarly, if `next` is called only a single time and neither `setStream` nor `getStream` was called, we automatically curry the stream from the future returned by `next` onto the future returned by the handler.
|
|
348
|
-
|
|
349
|
-
Finally, if the return value of a handler is a `Future`, we curry `content` and `errors` as well, thus enabling the simplest form `return next(<req>)`.
|
|
350
|
-
|
|
351
|
-
In the case of the `Future` being returned, `Stream` proxying is automatic and immediate and does not wait for the `Future` to resolve.
|
|
352
|
-
|
|
353
|
-
---
|
|
354
|
-
|
|
355
|
-
#### Using with `@ember-data/store`
|
|
356
|
-
|
|
357
|
-
To have a request service unique to a Store:
|
|
358
|
-
|
|
359
|
-
```ts
|
|
360
|
-
import Store, { CacheHandler } from '@ember-data/store';
|
|
361
|
-
import RequestManager from '@ember-data/request';
|
|
362
|
-
import Fetch from '@ember-data/request/fetch';
|
|
363
|
-
|
|
364
|
-
class extends Store {
|
|
365
|
-
requestManager = new RequestManager()
|
|
366
|
-
.use([Fetch])
|
|
367
|
-
.useCache(CacheHandler);
|
|
368
|
-
}
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
---
|
|
372
|
-
|
|
373
|
-
### Using as a Service
|
|
374
|
-
|
|
375
|
-
Some applications will desire to have a single `RequestManager` instance, which can be achieved using module-state patterns for singletons, or for [Ember](https://emberjs.com) applications by exporting the manager as a [service](https://guides.emberjs.com/release/services/).
|
|
376
|
-
|
|
377
|
-
*services/request.ts*
|
|
378
|
-
```ts
|
|
379
|
-
import { CacheHandler } from '@ember-data/store';
|
|
380
|
-
import RequestManager from '@ember-data/request';
|
|
381
|
-
import Fetch from '@ember-data/request/fetch';
|
|
382
|
-
import Auth from 'ember-simple-auth/ember-data-handler';
|
|
383
|
-
|
|
384
|
-
export default {
|
|
385
|
-
create() {
|
|
386
|
-
return new RequestManager()
|
|
387
|
-
.use([Auth, Fetch])
|
|
388
|
-
.use(CacheHandler);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
---
|
|
394
|
-
|
|
395
|
-
#### Using with `ember-data`
|
|
396
|
-
|
|
397
|
-
If using the package [ember-data](https://github.com/emberjs/data/tree/main/packages/-ember-data),
|
|
398
|
-
the following configuration will automatically be done in order to preserve the
|
|
399
|
-
legacy [Adapter](https://github.com/emberjs/data/tree/main/packages/adapter) and
|
|
400
|
-
[Serializer](https://github.com/emberjs/data/tree/main/packages/serializer) behavior.
|
|
401
|
-
Additional handlers or a service injection like the above would need to be done by the
|
|
402
|
-
consuming application in order to make broader use of `RequestManager`.
|
|
403
|
-
|
|
404
|
-
```ts
|
|
405
|
-
import Store from 'ember-data/store';
|
|
406
|
-
import { CacheHandler } from '@ember-data/store';
|
|
407
|
-
import RequestManager from '@ember-data/request';
|
|
408
|
-
import Fetch from '@ember-data/request/fetch';
|
|
409
|
-
import { LegacyNetworkHandler } from '@ember-data/legacy-compat';
|
|
410
|
-
|
|
411
|
-
export default class extends Store {
|
|
412
|
-
requestManager = new RequestManager()
|
|
413
|
-
.use([LegacyNetworkHandler, Fetch])
|
|
414
|
-
.useCache(CacheHandler);
|
|
415
|
-
}
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
To provide a different configuration, import and extend `ember-data/store`. The
|
|
419
|
-
default configuration will be ignored if the `requestManager` property is set,
|
|
420
|
-
though the store will still register the CacheHandler.
|
|
421
|
-
|
|
422
|
-
For usage of the store's `requestManager` via `store.request(<req>)` see the
|
|
423
|
-
[Store](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fstore) documentation.
|
|
424
|
-
|
|
425
|
-
*
|
|
426
|
-
* @module
|
|
427
|
-
*/
|
|
428
|
-
export { createDeferred } from './request/-private/future.ts';
|
|
429
|
-
export type { Future, Handler, CacheHandler, NextFn, Deferred, ManagedRequestPriority, } from './request/-private/types.ts';
|
|
430
|
-
export { setPromiseResult, getPromiseResult } from './request/-private/promise-cache.ts';
|
|
431
|
-
export type { Awaitable } from './request/-private/promise-cache.ts';
|
|
432
|
-
export type { Context } from './request/-private/context.ts';
|
|
433
|
-
//# sourceMappingURL=request.d.ts.map
|
|
1
|
+
export { createDeferred } from "./request/-private/future.js";
|
|
2
|
+
export type { Future, Handler, CacheHandler, NextFn, Deferred, ManagedRequestPriority } from "./request/-private/types.js";
|
|
3
|
+
export { setPromiseResult, getPromiseResult } from "./request/-private/promise-cache.js";
|
|
4
|
+
export type { Awaitable } from "./request/-private/promise-cache.js";
|
|
5
|
+
export type { Context } from "./request/-private/context.js";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { CacheHandler as CacheHandlerType } from "../../../request.js";
|
|
2
|
+
import type { ImmutableRequestInfo, RequestContext } from "../../../types/request.js";
|
|
3
|
+
import type { ResourceIdentifierObject } from "../../../types/spec/json-api-raw.js";
|
|
4
|
+
import type { RequestSignature } from "../../../types/symbols.js";
|
|
5
|
+
import type { Store } from "../store-service.js";
|
|
6
|
+
export type LooseStoreRequestInfo<
|
|
7
|
+
RT = unknown,
|
|
8
|
+
T = unknown
|
|
9
|
+
> = Omit<ImmutableRequestInfo<RT, T>, "records" | "headers" | typeof RequestSignature> & {
|
|
10
|
+
records?: ResourceIdentifierObject[];
|
|
11
|
+
headers?: Headers;
|
|
12
|
+
};
|
|
13
|
+
export type StoreRequestInput<
|
|
14
|
+
RT = unknown,
|
|
15
|
+
T = unknown
|
|
16
|
+
> = ImmutableRequestInfo<RT, T> | LooseStoreRequestInfo<RT, T>;
|
|
17
|
+
export interface StoreRequestContext extends RequestContext {
|
|
18
|
+
request: ImmutableRequestInfo & {
|
|
19
|
+
store: Store;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A CacheHandler that adds support for using an WarpDrive Cache with a RequestManager.
|
|
24
|
+
*
|
|
25
|
+
* This handler will only run when a request has supplied a `store` instance. Requests
|
|
26
|
+
* issued by the store via `store.request()` will automatically have the `store` instance
|
|
27
|
+
* attached to the request.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* requestManager.request({
|
|
31
|
+
* store: store,
|
|
32
|
+
* url: '/api/posts',
|
|
33
|
+
* method: 'GET'
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* When this handler elects to handle a request, it will return the raw `StructuredDocument`
|
|
38
|
+
* unless the request has `[EnableHydration]` set to `true`. In this case, the handler will
|
|
39
|
+
* return a `Document` instance that will automatically update the UI when the cache is updated
|
|
40
|
+
* in the future and will hydrate any identifiers in the StructuredDocument into Record instances.
|
|
41
|
+
*
|
|
42
|
+
* When issuing a request via the store, [EnableHydration] is automatically set to `true`. This
|
|
43
|
+
* means that if desired you can issue requests that utilize the cache without needing to also
|
|
44
|
+
* utilize Record instances if desired.
|
|
45
|
+
*
|
|
46
|
+
* Said differently, you could elect to issue all requests via a RequestManager, without ever using
|
|
47
|
+
* the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not
|
|
48
|
+
* necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature
|
|
49
|
+
* approach of WarpDrive allows for this flexibility.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { EnableHydration } from '@warp-drive/core/types/request';
|
|
53
|
+
*
|
|
54
|
+
* requestManager.request({
|
|
55
|
+
* store: store,
|
|
56
|
+
* url: '/api/posts',
|
|
57
|
+
* method: 'GET',
|
|
58
|
+
* [EnableHydration]: true
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
export declare const CacheHandler: CacheHandlerType;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { StableDocumentIdentifier } from "../../../types/identifier.js";
|
|
2
|
+
import type { ImmutableRequestInfo, ResponseInfo } from "../../../types/request.js";
|
|
3
|
+
import type { Store } from "../store-service.js";
|
|
4
|
+
/**
|
|
5
|
+
* A service which an application may provide to the store via
|
|
6
|
+
* the store's `lifetimes` property to configure the behavior
|
|
7
|
+
* of the CacheHandler.
|
|
8
|
+
*
|
|
9
|
+
* The default behavior for request lifetimes is to never expire
|
|
10
|
+
* unless manually refreshed via `cacheOptions.reload` or `cacheOptions.backgroundReload`.
|
|
11
|
+
*
|
|
12
|
+
* Implementing this service allows you to programatically define
|
|
13
|
+
* when a request should be considered expired.
|
|
14
|
+
*
|
|
15
|
+
* @class (Interface) CachePolicy
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export interface CachePolicy {
|
|
19
|
+
/**
|
|
20
|
+
* Invoked to determine if the request may be fulfilled from cache
|
|
21
|
+
* if possible.
|
|
22
|
+
*
|
|
23
|
+
* Note, this is only invoked if the request has a cache-key.
|
|
24
|
+
*
|
|
25
|
+
* If no cache entry is found or the entry is hard expired,
|
|
26
|
+
* the request will be fulfilled from the configured request handlers
|
|
27
|
+
* and the cache will be updated before returning the response.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
* @param {StableDocumentIdentifier} identifier
|
|
31
|
+
* @param {Store} store
|
|
32
|
+
* @return {Boolean} true if the request is considered hard expired
|
|
33
|
+
*/
|
|
34
|
+
isHardExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Invoked if `isHardExpired` is false to determine if the request
|
|
37
|
+
* should be update behind the scenes if cache data is already available.
|
|
38
|
+
*
|
|
39
|
+
* Note, this is only invoked if the request has a cache-key.
|
|
40
|
+
*
|
|
41
|
+
* If true, the request will be fulfilled from cache while a backgrounded
|
|
42
|
+
* request is made to update the cache via the configured request handlers.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
* @param {StableDocumentIdentifier} identifier
|
|
46
|
+
* @param {Store} store
|
|
47
|
+
* @return {Boolean} true if the request is considered soft expired
|
|
48
|
+
*/
|
|
49
|
+
isSoftExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Invoked when a request will be sent to the configured request handlers.
|
|
52
|
+
* This is invoked for both foreground and background requests.
|
|
53
|
+
*
|
|
54
|
+
* Note, this is invoked regardless of whether the request has a cache-key.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
* @param {ImmutableRequestInfo} request
|
|
58
|
+
* @param {StableDocumentIdentifier | null} identifier
|
|
59
|
+
* @param {Store} store
|
|
60
|
+
* @return {void}
|
|
61
|
+
*/
|
|
62
|
+
willRequest?(request: ImmutableRequestInfo, identifier: StableDocumentIdentifier | null, store: Store): void;
|
|
63
|
+
/**
|
|
64
|
+
* Invoked when a request has been fulfilled from the configured request handlers.
|
|
65
|
+
* This is invoked for both foreground and background requests once the cache has
|
|
66
|
+
* been updated.
|
|
67
|
+
*
|
|
68
|
+
* Note, this is invoked regardless of whether the request has a cache-key.
|
|
69
|
+
*
|
|
70
|
+
* It is best practice to notify the store of any requests marked as invalidated
|
|
71
|
+
* so that request subscriptions can reload when needed.
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* store.notifications.notify(identifier, 'invalidated');
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* This allows anything subscribed to the request to be notified of the change
|
|
78
|
+
*
|
|
79
|
+
* e.g.
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* store.notifications.subscribe(identifier, (_, type) => {
|
|
83
|
+
* if (type === 'invalidated') {
|
|
84
|
+
* // do update
|
|
85
|
+
* }
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
* @param {ImmutableRequestInfo} request
|
|
92
|
+
* @param {ImmutableResponse} response
|
|
93
|
+
* @param {StableDocumentIdentifier | null} identifier
|
|
94
|
+
* @param {Store} store
|
|
95
|
+
* @return {void}
|
|
96
|
+
*/
|
|
97
|
+
didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: StableDocumentIdentifier | null, store: Store): void;
|
|
98
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { StableDocumentIdentifier } from "../../../types/identifier.js";
|
|
2
|
+
import type { ImmutableCreateRequestOptions, ImmutableDeleteRequestOptions, ImmutableRequestInfo, ImmutableUpdateRequestOptions, StructuredDataDocument } from "../../../types/request.js";
|
|
3
|
+
import type { ResourceDataDocument, ResourceErrorDocument } from "../../../types/spec/document.js";
|
|
4
|
+
import type { ApiError } from "../../../types/spec/error.js";
|
|
5
|
+
import type { Store } from "../store-service.js";
|
|
6
|
+
export declare const MUTATION_OPS: Set<string>;
|
|
7
|
+
export declare function calcShouldFetch(store: Store, request: ImmutableRequestInfo, hasCachedValue: boolean, identifier: StableDocumentIdentifier | null): boolean;
|
|
8
|
+
export declare function calcShouldBackgroundFetch(store: Store, request: ImmutableRequestInfo, willFetch: boolean, identifier: StableDocumentIdentifier | null): boolean;
|
|
9
|
+
export declare function isMutation(request: Partial<ImmutableRequestInfo>): request is ImmutableUpdateRequestOptions | ImmutableCreateRequestOptions | ImmutableDeleteRequestOptions;
|
|
10
|
+
export declare function isCacheAffecting<T>(document: StructuredDataDocument<T>): boolean;
|
|
11
|
+
export declare function isAggregateError(error: Error & {
|
|
12
|
+
errors?: ApiError[];
|
|
13
|
+
}): error is AggregateError & {
|
|
14
|
+
errors: ApiError[];
|
|
15
|
+
};
|
|
16
|
+
export type RobustError = Error & {
|
|
17
|
+
error: string | object;
|
|
18
|
+
errors?: ApiError[];
|
|
19
|
+
content?: unknown;
|
|
20
|
+
};
|
|
21
|
+
// TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them
|
|
22
|
+
export declare function cloneError(error: RobustError): RobustError;
|
|
23
|
+
export declare function isErrorDocument(document: ResourceDataDocument | ResourceErrorDocument): document is ResourceErrorDocument;
|
|
24
|
+
export declare function getPriority(identifier: StableDocumentIdentifier | null, deduped: Map<StableDocumentIdentifier, {
|
|
25
|
+
priority: {
|
|
26
|
+
blocking: boolean;
|
|
27
|
+
};
|
|
28
|
+
}>, priority: {
|
|
29
|
+
blocking: boolean;
|
|
30
|
+
}): {
|
|
31
|
+
blocking: boolean;
|
|
32
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Cache } from "../../../types/cache.js";
|
|
2
|
+
import type { StableRecordIdentifier } from "../../../types/identifier.js";
|
|
3
|
+
import type { OpaqueRecordInstance } from "../../-types/q/record-instance.js";
|
|
4
|
+
/*
|
|
5
|
+
* Returns the Cache instance associated with a given
|
|
6
|
+
* Model or Identifier
|
|
7
|
+
*/
|
|
8
|
+
export declare const CacheForIdentifierCache: Map<unknown, Cache>;
|
|
9
|
+
export declare function setCacheFor(identifier: StableRecordIdentifier | OpaqueRecordInstance, cache: Cache): void;
|
|
10
|
+
export declare function removeRecordDataFor(identifier: StableRecordIdentifier | OpaqueRecordInstance): void;
|
|
11
|
+
export declare function peekCache(instance: StableRecordIdentifier): Cache | null;
|
|
12
|
+
export declare function peekCache(instance: OpaqueRecordInstance): Cache;
|