@warp-drive/core 5.6.0-alpha.5 → 5.6.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,135 +1,162 @@
|
|
|
1
|
-
import type { StableDocumentIdentifier } from
|
|
2
|
-
import type { RequestInfo } from
|
|
3
|
-
import type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from
|
|
4
|
-
import { IS_CACHE_HANDLER } from
|
|
1
|
+
import type { StableDocumentIdentifier } from "../../types/identifier.js";
|
|
2
|
+
import type { RequestInfo } from "../../types/request.js";
|
|
3
|
+
import type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from "./types.js";
|
|
4
|
+
import { IS_CACHE_HANDLER } from "./utils.js";
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
6
|
+
* ## Import
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { RequestManager } from '@warp-drive/core';
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* For complete usage guide see the [RequestManager Documentation](/guides/).
|
|
13
|
+
*
|
|
14
|
+
* ## How It Works
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* interface RequestManager {
|
|
18
|
+
* request<T>(req: RequestInfo): Future<T>;
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* A RequestManager provides a request/response flow in which configured
|
|
23
|
+
* handlers are successively given the opportunity to handle, modify, or
|
|
24
|
+
* pass-along a request.
|
|
25
|
+
*
|
|
26
|
+
* <img src="/images/handlers-all-labeled.gif" alt="RequestManager Flow Animation" width="100%" />
|
|
27
|
+
*
|
|
28
|
+
* For example:
|
|
29
|
+
*
|
|
30
|
+
* ::: code-group
|
|
31
|
+
*
|
|
32
|
+
* ```ts [Setup.ts]
|
|
33
|
+
* import { RequestManager, Fetch } from '@warp-drive/core';
|
|
34
|
+
* import { AutoCompress } from '@warp-drive/utilities/handlers';
|
|
35
|
+
* import Auth from 'ember-simple-auth/handler';
|
|
36
|
+
*
|
|
37
|
+
* // ... create manager
|
|
38
|
+
* const manager = new RequestManager()
|
|
39
|
+
* .use([Auth, new AutoCompress(), Fetch]); // [!code focus]
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ```ts [Usage.ts]
|
|
43
|
+
* import Config from './config';
|
|
44
|
+
*
|
|
45
|
+
* const { apiUrl } = Config;
|
|
46
|
+
*
|
|
47
|
+
* // ... execute a request
|
|
48
|
+
* const response = await manager.request({
|
|
49
|
+
* url: `${apiUrl}/users`
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* :::
|
|
54
|
+
*
|
|
55
|
+
* ### Futures
|
|
56
|
+
*
|
|
57
|
+
* The return value of `manager.request` is a `Future`, which allows
|
|
58
|
+
* access to limited information about the request while it is still
|
|
59
|
+
* pending and fulfills with the final state when the request completes.
|
|
60
|
+
*
|
|
61
|
+
* A `Future` is cancellable via `abort`.
|
|
62
|
+
*
|
|
63
|
+
* Handlers may optionally expose a `ReadableStream` to the `Future` for
|
|
64
|
+
* streaming data; however, when doing so the future should not resolve
|
|
65
|
+
* until the response stream is fully read.
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* interface Future<T> extends Promise<StructuredDocument<T>> {
|
|
69
|
+
* abort(): void;
|
|
70
|
+
*
|
|
71
|
+
* async getStream(): ReadableStream | null;
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ### StructuredDocuments
|
|
76
|
+
*
|
|
77
|
+
* A Future resolves with a `StructuredDataDocument` or rejects with a `StructuredErrorDocument`.
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* interface StructuredDataDocument<T> {
|
|
81
|
+
* request: ImmutableRequestInfo;
|
|
82
|
+
* response: ImmutableResponseInfo;
|
|
83
|
+
* content: T;
|
|
84
|
+
* }
|
|
85
|
+
* interface StructuredErrorDocument extends Error {
|
|
86
|
+
* request: ImmutableRequestInfo;
|
|
87
|
+
* response: ImmutableResponseInfo;
|
|
88
|
+
* error: string | object;
|
|
89
|
+
* }
|
|
90
|
+
* type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @class RequestManager
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
80
96
|
export declare class RequestManager {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
97
|
+
#private;
|
|
98
|
+
/** @internal */
|
|
99
|
+
_hasCacheHandler: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* A map of pending requests from request.id to their
|
|
102
|
+
* associated CacheHandler promise.
|
|
103
|
+
*
|
|
104
|
+
* This queue is managed by the CacheHandler
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
_pending: Map<number, Promise<unknown>>;
|
|
109
|
+
/** @internal */
|
|
110
|
+
_deduped: Map<StableDocumentIdentifier, {
|
|
111
|
+
priority: ManagedRequestPriority;
|
|
112
|
+
promise: Promise<unknown>;
|
|
113
|
+
}>;
|
|
114
|
+
constructor(options?: GenericCreateArgs);
|
|
115
|
+
/**
|
|
116
|
+
* Register a handler to use for primary cache intercept.
|
|
117
|
+
*
|
|
118
|
+
* Only one such handler may exist. If using the same
|
|
119
|
+
* RequestManager as the Store instance the Store
|
|
120
|
+
* registers itself as a Cache handler.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
useCache(cacheHandler: CacheHandler & {
|
|
125
|
+
[IS_CACHE_HANDLER]?: true;
|
|
126
|
+
}): this;
|
|
127
|
+
/**
|
|
128
|
+
* Register handler(s) to use when a request is issued.
|
|
129
|
+
*
|
|
130
|
+
* Handlers will be invoked in the order they are registered.
|
|
131
|
+
* Each Handler is given the opportunity to handle the request,
|
|
132
|
+
* curry the request, or pass along a modified request.
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
* @param {Handler[]} newHandlers
|
|
136
|
+
* @return {ThisType}
|
|
137
|
+
*/
|
|
138
|
+
use(newHandlers: Handler[]): this;
|
|
139
|
+
/**
|
|
140
|
+
* Issue a Request.
|
|
141
|
+
*
|
|
142
|
+
* Returns a Future that fulfills with a StructuredDocument
|
|
143
|
+
*
|
|
144
|
+
* @public
|
|
145
|
+
* @param {RequestInfo} request
|
|
146
|
+
* @return {Future}
|
|
147
|
+
*/
|
|
148
|
+
request<
|
|
149
|
+
RT,
|
|
150
|
+
T = unknown
|
|
151
|
+
>(request: RequestInfo<RT, T>): Future<RT>;
|
|
152
|
+
/**
|
|
153
|
+
* This method exists so that the RequestManager can be created
|
|
154
|
+
* can be created by container/factory systems that expect to
|
|
155
|
+
* call a static `create` method to instantiate the class.
|
|
156
|
+
*
|
|
157
|
+
* Using `new RequestManager()` directly is preferred.
|
|
158
|
+
*
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
static create(options?: GenericCreateArgs): RequestManager;
|
|
134
162
|
}
|
|
135
|
-
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
export type CacheResult<
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type CacheResult<
|
|
2
|
+
T = unknown,
|
|
3
|
+
E = unknown
|
|
4
|
+
> = {
|
|
5
|
+
isError: true;
|
|
6
|
+
result: E;
|
|
4
7
|
} | {
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
isError: false;
|
|
9
|
+
result: T;
|
|
7
10
|
};
|
|
8
|
-
export type Awaitable<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
export type Awaitable<
|
|
12
|
+
T = unknown,
|
|
13
|
+
E = unknown
|
|
14
|
+
> = {
|
|
15
|
+
then: (onFulfilled: (value: T) => unknown, onRejected: (reason: E) => unknown) => unknown;
|
|
16
|
+
catch: (onRejected: (reason: E) => unknown) => unknown;
|
|
17
|
+
finally: (onFinally: () => unknown) => unknown;
|
|
12
18
|
};
|
|
13
|
-
export declare const PromiseCache: WeakMap<Awaitable
|
|
14
|
-
export declare const RequestMap: Map<number, CacheResult
|
|
19
|
+
export declare const PromiseCache: WeakMap<Awaitable, CacheResult>;
|
|
20
|
+
export declare const RequestMap: Map<number, CacheResult>;
|
|
15
21
|
export declare function setRequestResult(requestId: number, result: CacheResult): void;
|
|
16
22
|
export declare function clearRequestResult(requestId: number): void;
|
|
17
23
|
export declare function getRequestResult(requestId: number): CacheResult | undefined;
|
|
18
24
|
export declare function setPromiseResult(promise: Promise<unknown> | Awaitable, result: CacheResult): void;
|
|
19
|
-
export declare function getPromiseResult<
|
|
20
|
-
|
|
25
|
+
export declare function getPromiseResult<
|
|
26
|
+
T,
|
|
27
|
+
E
|
|
28
|
+
>(promise: Promise<T> | Awaitable<T, E>): CacheResult<T, E> | undefined;
|
|
@@ -1,89 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
1
|
+
/* eslint-disable no-irregular-whitespace */
|
|
2
|
+
import type { StableDocumentIdentifier } from "../../types/identifier.js";
|
|
3
|
+
import type { IS_FUTURE, RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from "../../types/request.js";
|
|
3
4
|
export interface GodContext {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
controller: AbortController;
|
|
6
|
+
response: ResponseInfo | null;
|
|
7
|
+
stream: ReadableStream | Promise<ReadableStream | null> | null;
|
|
8
|
+
hasRequestedStream: boolean;
|
|
9
|
+
id: number;
|
|
10
|
+
identifier: StableDocumentIdentifier | null;
|
|
10
11
|
}
|
|
11
12
|
export type Deferred<T> = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
resolve(v: T): void;
|
|
14
|
+
reject(v: unknown): void;
|
|
15
|
+
promise: Promise<T>;
|
|
15
16
|
};
|
|
16
17
|
export type ManagedRequestPriority = {
|
|
17
|
-
|
|
18
|
+
blocking: boolean;
|
|
18
19
|
};
|
|
19
20
|
export type DeferredStream = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
resolve(v: ReadableStream | null): void;
|
|
22
|
+
reject(v: unknown): void;
|
|
23
|
+
promise: Promise<ReadableStream | null> & {
|
|
24
|
+
sizeHint?: number;
|
|
25
|
+
};
|
|
25
26
|
};
|
|
26
27
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*/
|
|
28
|
+
* A Future is a {@link Promise} which resolves to a {@link StructuredDataDocument | StructuredDocument}
|
|
29
|
+
* while providing the ability to {@link Future.abort | abort} the underlying request, and
|
|
30
|
+
* {@link Future.getStream | access the response stream} before the outer promise resolves;
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
34
|
export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
35
|
+
[IS_FUTURE]: true;
|
|
36
|
+
/**
|
|
37
|
+
* Cancel this request by firing the {@link AbortController}'s signal.
|
|
38
|
+
*
|
|
39
|
+
* @privateRemarks
|
|
40
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/abort)
|
|
41
|
+
*
|
|
42
|
+
* @param reason optional reason for aborting the request
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
abort(reason?: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get the response stream, if any, once made available.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
* @return {Promise<ReadableStream | null>}
|
|
51
|
+
*/
|
|
52
|
+
getStream(): Promise<ReadableStream | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Run a callback when this request completes. Use sparingly,
|
|
55
|
+
* mostly useful for instrumentation and infrastructure.
|
|
56
|
+
*
|
|
57
|
+
* @param cb the callback to run
|
|
58
|
+
* @public
|
|
59
|
+
* @return {void}
|
|
60
|
+
*/
|
|
61
|
+
onFinalize(cb: () => void): void;
|
|
62
|
+
/**
|
|
63
|
+
* The identifier of the associated request, if any, as
|
|
64
|
+
* assigned by the CacheHandler.
|
|
65
|
+
*
|
|
66
|
+
* @property lid
|
|
67
|
+
* @type {StableDocumentIdentifier | null}
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
lid: StableDocumentIdentifier | null;
|
|
71
|
+
/**
|
|
72
|
+
* The id of the associated request, if any, as assigned
|
|
73
|
+
* by the RequestManager
|
|
74
|
+
*
|
|
75
|
+
* @property id
|
|
76
|
+
* @type {Number}
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
id: number;
|
|
78
80
|
}
|
|
79
81
|
export type DeferredFuture<T> = {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
resolve(v: StructuredDataDocument<T>): void;
|
|
83
|
+
reject(v: unknown): void;
|
|
84
|
+
promise: Future<T>;
|
|
83
85
|
};
|
|
84
86
|
export type NextFn<P = unknown> = (req: RequestInfo) => Future<P>;
|
|
85
87
|
/**
|
|
86
|
-
|
|
88
|
+
* Requests are fulfilled by handlers. A handler receives the request context
|
|
87
89
|
as well as a `next` function with which to pass along a request to the next
|
|
88
90
|
handler if it so chooses.
|
|
89
91
|
|
|
@@ -97,7 +99,7 @@ that it can then compose how it sees fit with its own response.
|
|
|
97
99
|
type NextFn<P> = (req: RequestInfo) => Future<P>;
|
|
98
100
|
|
|
99
101
|
interface Handler {
|
|
100
|
-
|
|
102
|
+
async request<T>(context: RequestContext, next: NextFn<P>): T;
|
|
101
103
|
}
|
|
102
104
|
```
|
|
103
105
|
|
|
@@ -105,10 +107,10 @@ interface Handler {
|
|
|
105
107
|
|
|
106
108
|
```ts
|
|
107
109
|
interface RequestContext<T> {
|
|
108
|
-
|
|
110
|
+
readonly request: RequestInfo;
|
|
109
111
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
setStream(stream: ReadableStream | Promise<ReadableStream>): void;
|
|
113
|
+
setResponse(response: Response | ResponseInfo): void;
|
|
112
114
|
}
|
|
113
115
|
```
|
|
114
116
|
|
|
@@ -121,13 +123,13 @@ response content before passing along the chunk downstream.
|
|
|
121
123
|
|
|
122
124
|
```ts
|
|
123
125
|
const FetchHandler = {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
async request(context) {
|
|
127
|
+
const response = await fetch(context.request);
|
|
128
|
+
context.setResponse(reponse);
|
|
129
|
+
context.setStream(response.clone().body);
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
return response.json();
|
|
132
|
+
}
|
|
131
133
|
}
|
|
132
134
|
```
|
|
133
135
|
|
|
@@ -138,13 +140,13 @@ const FetchHandler = {
|
|
|
138
140
|
For context, it helps to understand a few of the use-cases that RequestManager
|
|
139
141
|
is intended to allow.
|
|
140
142
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
- to manage and return streaming content (such as video files)
|
|
144
|
+
- to fulfill a request from multiple sources or by splitting one request into multiple requests
|
|
145
|
+
- for instance one API call for a user and another for the user's friends
|
|
146
|
+
- or e.g. fulfilling part of the request from one source (one API, in-memory, localStorage, IndexedDB etc.) and the rest from another source (a different API, a WebWorker, etc.)
|
|
147
|
+
- to coalesce multiple requests
|
|
148
|
+
- to decorate a request with additional info
|
|
149
|
+
- e.g. an Auth handler that ensures the correct tokens or headers or cookies are attached.
|
|
148
150
|
|
|
149
151
|
----
|
|
150
152
|
|
|
@@ -184,52 +186,51 @@ Request handlers are registered by configuring the manager via `use`
|
|
|
184
186
|
|
|
185
187
|
```ts
|
|
186
188
|
const manager = new RequestManager()
|
|
187
|
-
|
|
189
|
+
.use([Handler1, Handler2]);
|
|
188
190
|
```
|
|
189
191
|
|
|
190
192
|
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.
|
|
191
193
|
|
|
192
194
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
@class (Interface) Handler
|
|
196
|
+
@public
|
|
195
197
|
*/
|
|
196
198
|
export interface Handler {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Method to implement to handle requests. Receives the request
|
|
201
|
+
* context and a nextFn to call to pass-along the request to
|
|
202
|
+
* other handlers.
|
|
203
|
+
*
|
|
204
|
+
* @public
|
|
205
|
+
* @param context
|
|
206
|
+
* @param next
|
|
207
|
+
*/
|
|
208
|
+
request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T>;
|
|
207
209
|
}
|
|
208
210
|
/**
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
211
|
+
* The CacheHandler is identical to other handlers ecxept that it
|
|
212
|
+
* is allowed to return a value synchronously. This is useful for
|
|
213
|
+
* features like reducing microtask queueing when de-duping.
|
|
214
|
+
*
|
|
215
|
+
* A RequestManager may only have one CacheHandler, registered via
|
|
216
|
+
* `manager.useCache(CacheHandler)`.
|
|
217
|
+
*
|
|
218
|
+
* @class (Interface) CacheHandler
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
219
221
|
export interface CacheHandler {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Method to implement to handle requests. Receives the request
|
|
224
|
+
* context and a nextFn to call to pass-along the request to
|
|
225
|
+
* other handlers.
|
|
226
|
+
*
|
|
227
|
+
* @public
|
|
228
|
+
* @param context
|
|
229
|
+
* @param next
|
|
230
|
+
*/
|
|
231
|
+
request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T> | T;
|
|
230
232
|
}
|
|
231
233
|
export interface RequestResponse<T> {
|
|
232
|
-
|
|
234
|
+
result: T;
|
|
233
235
|
}
|
|
234
236
|
export type GenericCreateArgs = Record<string | symbol, unknown>;
|
|
235
|
-
//# sourceMappingURL=types.d.ts.map
|