@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.
Files changed (219) hide show
  1. package/README.md +8 -7
  2. package/cjs-dist/addon-shim.cjs +1 -0
  3. package/cjs-dist/cjs-set-config.cjs +1 -0
  4. package/declarations/build-config/babel-macros.d.ts +1 -0
  5. package/declarations/build-config/canary-features.d.ts +1 -0
  6. package/declarations/build-config/debugging.d.ts +1 -0
  7. package/declarations/build-config/deprecations.d.ts +1 -0
  8. package/declarations/build-config/env.d.ts +1 -0
  9. package/declarations/build-config/macros.d.ts +1 -0
  10. package/declarations/build-config.d.ts +1 -0
  11. package/declarations/configure.d.ts +7 -0
  12. package/declarations/graph/-private/-diff.d.ts +32 -0
  13. package/declarations/graph/-private/-edge-definition.d.ts +148 -0
  14. package/declarations/graph/-private/-state.d.ts +96 -0
  15. package/declarations/graph/-private/-utils.d.ts +31 -0
  16. package/declarations/graph/-private/coerce-id.d.ts +10 -0
  17. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +18 -0
  18. package/declarations/graph/-private/edges/collection.d.ts +39 -0
  19. package/declarations/graph/-private/edges/implicit.d.ts +43 -0
  20. package/declarations/graph/-private/edges/resource.d.ts +24 -0
  21. package/declarations/graph/-private/graph.d.ts +90 -0
  22. package/declarations/graph/-private/normalize-link.d.ts +8 -0
  23. package/declarations/graph/-private/operations/add-to-related-records.d.ts +4 -0
  24. package/declarations/graph/-private/operations/merge-identifier.d.ts +3 -0
  25. package/declarations/graph/-private/operations/remove-from-related-records.d.ts +4 -0
  26. package/declarations/graph/-private/operations/replace-related-record.d.ts +3 -0
  27. package/declarations/graph/-private/operations/replace-related-records.d.ts +62 -0
  28. package/declarations/graph/-private/operations/update-relationship.d.ts +13 -0
  29. package/declarations/graph/-private.d.ts +13 -0
  30. package/declarations/index.d.ts +14 -3
  31. package/declarations/reactive/-private/document.d.ts +146 -0
  32. package/declarations/reactive/-private/fields/compute.d.ts +43 -0
  33. package/declarations/reactive/-private/fields/extension.d.ts +8 -0
  34. package/declarations/reactive/-private/fields/managed-array.d.ts +22 -0
  35. package/declarations/reactive/-private/fields/managed-object.d.ts +21 -0
  36. package/declarations/reactive/-private/fields/many-array-manager.d.ts +19 -0
  37. package/declarations/reactive/-private/hooks.d.ts +5 -0
  38. package/declarations/reactive/-private/record.d.ts +64 -0
  39. package/declarations/reactive/-private/schema.d.ts +271 -0
  40. package/declarations/reactive/-private/symbols.d.ts +36 -0
  41. package/declarations/reactive/-private.d.ts +1 -0
  42. package/declarations/reactive.d.ts +4 -0
  43. package/declarations/request/-private/context.d.ts +34 -35
  44. package/declarations/request/-private/debug.d.ts +2 -3
  45. package/declarations/request/-private/fetch.d.ts +24 -36
  46. package/declarations/request/-private/future.d.ts +3 -4
  47. package/declarations/request/-private/manager.d.ts +159 -132
  48. package/declarations/request/-private/promise-cache.d.ts +21 -13
  49. package/declarations/request/-private/types.d.ts +124 -123
  50. package/declarations/request/-private/utils.d.ts +8 -9
  51. package/declarations/request.d.ts +5 -433
  52. package/declarations/store/-private/cache-handler/handler.d.ts +62 -0
  53. package/declarations/store/-private/cache-handler/types.d.ts +98 -0
  54. package/declarations/store/-private/cache-handler/utils.d.ts +32 -0
  55. package/declarations/store/-private/caches/cache-utils.d.ts +12 -0
  56. package/declarations/store/-private/caches/identifier-cache.d.ts +304 -0
  57. package/declarations/store/-private/caches/instance-cache.d.ts +65 -0
  58. package/declarations/store/-private/caches/resource-utils.d.ts +9 -0
  59. package/declarations/store/-private/debug/utils.d.ts +6 -0
  60. package/declarations/store/-private/default-cache-policy.d.ts +384 -0
  61. package/declarations/store/-private/legacy-model-support/record-reference.d.ts +159 -0
  62. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +17 -0
  63. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +25 -0
  64. package/declarations/store/-private/managers/cache-manager.d.ts +443 -0
  65. package/declarations/store/-private/managers/notification-manager.d.ts +98 -0
  66. package/declarations/store/-private/managers/record-array-manager.d.ts +97 -0
  67. package/declarations/store/-private/network/request-cache.d.ts +107 -0
  68. package/declarations/store/-private/new-core-tmp/promise-state.d.ts +263 -0
  69. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +176 -0
  70. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +169 -0
  71. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +35 -0
  72. package/declarations/store/-private/new-core-tmp/request-state.d.ts +277 -0
  73. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +261 -0
  74. package/declarations/store/-private/record-arrays/identifier-array.d.ts +147 -0
  75. package/declarations/store/-private/record-arrays/many-array.d.ts +197 -0
  76. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +126 -0
  77. package/declarations/store/-private/store-service.d.ts +1605 -0
  78. package/declarations/store/-private/utils/coerce-id.d.ts +10 -0
  79. package/declarations/store/-private/utils/construct-resource.d.ts +6 -0
  80. package/declarations/store/-private/utils/is-non-empty-string.d.ts +1 -0
  81. package/declarations/store/-private/utils/normalize-model-name.d.ts +1 -0
  82. package/declarations/store/-private/utils/uuid-polyfill.d.ts +1 -0
  83. package/declarations/store/-private.d.ts +31 -0
  84. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +99 -0
  85. package/declarations/store/-types/q/ds-model.d.ts +21 -0
  86. package/declarations/store/-types/q/identifier.d.ts +20 -0
  87. package/declarations/store/-types/q/record-instance.d.ts +23 -0
  88. package/declarations/store/-types/q/schema-service.d.ts +354 -0
  89. package/declarations/store/-types/q/store.d.ts +32 -0
  90. package/declarations/store.d.ts +1 -0
  91. package/declarations/types/-private.d.ts +16 -8
  92. package/declarations/types/cache/aliases.d.ts +11 -1
  93. package/declarations/types/cache/change.d.ts +4 -5
  94. package/declarations/types/cache/mutations.d.ts +51 -28
  95. package/declarations/types/cache/operations.d.ts +60 -47
  96. package/declarations/types/cache/relationship.d.ts +11 -9
  97. package/declarations/types/cache.d.ts +495 -484
  98. package/declarations/types/graph.d.ts +31 -40
  99. package/declarations/types/identifier.d.ts +83 -82
  100. package/declarations/types/json/raw.d.ts +1 -2
  101. package/declarations/types/params.d.ts +4 -5
  102. package/declarations/types/record.d.ts +117 -76
  103. package/declarations/types/request.d.ts +289 -266
  104. package/declarations/types/runtime.d.ts +8 -9
  105. package/declarations/types/schema/concepts.d.ts +19 -13
  106. package/declarations/types/schema/fields.d.ts +1712 -1741
  107. package/declarations/types/schema/fields.type-test.d.ts +0 -1
  108. package/declarations/types/spec/document.d.ts +28 -22
  109. package/declarations/types/spec/error.d.ts +16 -17
  110. package/declarations/types/spec/json-api-raw.d.ts +102 -102
  111. package/declarations/types/symbols.d.ts +74 -75
  112. package/declarations/types/utils.d.ts +5 -5
  113. package/declarations/types.d.ts +10 -7
  114. package/declarations/utils/string.d.ts +48 -0
  115. package/dist/build-config/babel-macros.js +1 -0
  116. package/dist/build-config/canary-features.js +1 -0
  117. package/dist/build-config/debugging.js +1 -0
  118. package/dist/build-config/deprecations.js +1 -0
  119. package/dist/build-config/env.js +1 -0
  120. package/dist/build-config/macros.js +1 -0
  121. package/dist/build-config.js +1 -0
  122. package/dist/configure-B48bFHOl.js +181 -0
  123. package/dist/configure.js +1 -0
  124. package/dist/{context-DE5sFezZ.js → context-COmAnXUQ.js} +2 -2
  125. package/dist/graph/-private.js +3372 -0
  126. package/dist/handler-C2T-IyJK.js +339 -0
  127. package/dist/index.js +37 -104
  128. package/dist/reactive/-private.js +1 -0
  129. package/dist/reactive.js +1988 -0
  130. package/dist/request-state-CjLph1LP.js +8139 -0
  131. package/dist/request.js +1 -1
  132. package/dist/store/-private.js +3 -0
  133. package/dist/store.js +545 -0
  134. package/dist/symbols-SIstXMLI.js +44 -0
  135. package/dist/types/-private.js +3 -3
  136. package/dist/types/record.js +1 -1
  137. package/dist/types/request.js +2 -2
  138. package/dist/types/runtime.js +1 -1
  139. package/dist/types/schema/fields.js +8 -41
  140. package/dist/types/symbols.js +3 -3
  141. package/dist/utils/string.js +92 -0
  142. package/logos/NCC-1701-a-blue.svg +4 -0
  143. package/logos/NCC-1701-a-gold.svg +4 -0
  144. package/logos/NCC-1701-a-gold_100.svg +1 -0
  145. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  146. package/logos/NCC-1701-a.svg +4 -0
  147. package/logos/README.md +4 -0
  148. package/logos/docs-badge.svg +2 -0
  149. package/logos/ember-data-logo-dark.svg +12 -0
  150. package/logos/ember-data-logo-light.svg +12 -0
  151. package/logos/github-header.svg +444 -0
  152. package/logos/social1.png +0 -0
  153. package/logos/social2.png +0 -0
  154. package/logos/warp-drive-logo-dark.svg +4 -0
  155. package/logos/warp-drive-logo-gold.svg +4 -0
  156. package/package.json +11 -8
  157. package/declarations/index.d.ts.map +0 -1
  158. package/declarations/request/-private/context.d.ts.map +0 -1
  159. package/declarations/request/-private/debug.d.ts.map +0 -1
  160. package/declarations/request/-private/fetch.d.ts.map +0 -1
  161. package/declarations/request/-private/future.d.ts.map +0 -1
  162. package/declarations/request/-private/manager.d.ts.map +0 -1
  163. package/declarations/request/-private/promise-cache.d.ts.map +0 -1
  164. package/declarations/request/-private/types.d.ts.map +0 -1
  165. package/declarations/request/-private/utils.d.ts.map +0 -1
  166. package/declarations/request.d.ts.map +0 -1
  167. package/declarations/types/-private.d.ts.map +0 -1
  168. package/declarations/types/cache/aliases.d.ts.map +0 -1
  169. package/declarations/types/cache/change.d.ts.map +0 -1
  170. package/declarations/types/cache/mutations.d.ts.map +0 -1
  171. package/declarations/types/cache/operations.d.ts.map +0 -1
  172. package/declarations/types/cache/relationship.d.ts.map +0 -1
  173. package/declarations/types/cache.d.ts.map +0 -1
  174. package/declarations/types/graph.d.ts.map +0 -1
  175. package/declarations/types/identifier.d.ts.map +0 -1
  176. package/declarations/types/json/raw.d.ts.map +0 -1
  177. package/declarations/types/params.d.ts.map +0 -1
  178. package/declarations/types/record.d.ts.map +0 -1
  179. package/declarations/types/record.type-test.d.ts +0 -2
  180. package/declarations/types/record.type-test.d.ts.map +0 -1
  181. package/declarations/types/request.d.ts.map +0 -1
  182. package/declarations/types/request.type-test.d.ts +0 -2
  183. package/declarations/types/request.type-test.d.ts.map +0 -1
  184. package/declarations/types/runtime.d.ts.map +0 -1
  185. package/declarations/types/schema/concepts.d.ts.map +0 -1
  186. package/declarations/types/schema/fields.d.ts.map +0 -1
  187. package/declarations/types/schema/fields.type-test.d.ts.map +0 -1
  188. package/declarations/types/spec/document.d.ts.map +0 -1
  189. package/declarations/types/spec/error.d.ts.map +0 -1
  190. package/declarations/types/spec/json-api-raw.d.ts.map +0 -1
  191. package/declarations/types/symbols.d.ts.map +0 -1
  192. package/declarations/types/utils.d.ts.map +0 -1
  193. package/declarations/types.d.ts.map +0 -1
  194. package/dist/context-DE5sFezZ.js.map +0 -1
  195. package/dist/index.js.map +0 -1
  196. package/dist/request.js.map +0 -1
  197. package/dist/types/-private.js.map +0 -1
  198. package/dist/types/cache/aliases.js.map +0 -1
  199. package/dist/types/cache/change.js.map +0 -1
  200. package/dist/types/cache/mutations.js.map +0 -1
  201. package/dist/types/cache/operations.js.map +0 -1
  202. package/dist/types/cache/relationship.js.map +0 -1
  203. package/dist/types/cache.js.map +0 -1
  204. package/dist/types/graph.js.map +0 -1
  205. package/dist/types/identifier.js.map +0 -1
  206. package/dist/types/json/raw.js.map +0 -1
  207. package/dist/types/params.js.map +0 -1
  208. package/dist/types/record.js.map +0 -1
  209. package/dist/types/request.js.map +0 -1
  210. package/dist/types/runtime.js.map +0 -1
  211. package/dist/types/schema/concepts.js.map +0 -1
  212. package/dist/types/schema/fields.js.map +0 -1
  213. package/dist/types/schema/fields.type-test.js.map +0 -1
  214. package/dist/types/spec/document.js.map +0 -1
  215. package/dist/types/spec/error.js.map +0 -1
  216. package/dist/types/spec/json-api-raw.js.map +0 -1
  217. package/dist/types/symbols.js.map +0 -1
  218. package/dist/types/utils.js.map +0 -1
  219. package/dist/types.js.map +0 -1
@@ -1,135 +1,162 @@
1
- import type { StableDocumentIdentifier } from '../../types/identifier';
2
- import type { RequestInfo } from '../../types/request';
3
- import type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from './types';
4
- import { IS_CACHE_HANDLER } from './utils';
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
- * ```js
7
- * import RequestManager from '@ember-data/request';
8
- * ```
9
- *
10
- * A RequestManager provides a request/response flow in which configured
11
- * handlers are successively given the opportunity to handle, modify, or
12
- * pass-along a request.
13
- *
14
- * ```ts
15
- * interface RequestManager {
16
- * request<T>(req: RequestInfo): Future<T>;
17
- * }
18
- * ```
19
- *
20
- * For example:
21
- *
22
- * ```ts
23
- * import RequestManager from '@ember-data/request';
24
- * import Fetch from '@ember-data/request/fetch';
25
- * import Auth from 'ember-simple-auth/ember-data-handler';
26
- * import Config from './config';
27
- *
28
- * const { apiUrl } = Config;
29
- *
30
- * // ... create manager
31
- * const manager = new RequestManager().use([Auth, Fetch]);
32
- *
33
- * // ... execute a request
34
- * const response = await manager.request({
35
- * url: `${apiUrl}/users`
36
- * });
37
- * ```
38
- *
39
- * ### Futures
40
- *
41
- * The return value of `manager.request` is a `Future`, which allows
42
- * access to limited information about the request while it is still
43
- * pending and fulfills with the final state when the request completes.
44
- *
45
- * A `Future` is cancellable via `abort`.
46
- *
47
- * Handlers may optionally expose a `ReadableStream` to the `Future` for
48
- * streaming data; however, when doing so the future should not resolve
49
- * until the response stream is fully read.
50
- *
51
- * ```ts
52
- * interface Future<T> extends Promise<StructuredDocument<T>> {
53
- * abort(): void;
54
- *
55
- * async getStream(): ReadableStream | null;
56
- * }
57
- * ```
58
- *
59
- * ### StructuredDocuments
60
- *
61
- * A Future resolves with a `StructuredDataDocument` or rejects with a `StructuredErrorDocument`.
62
- *
63
- * ```ts
64
- * interface StructuredDataDocument<T> {
65
- * request: ImmutableRequestInfo;
66
- * response: ImmutableResponseInfo;
67
- * content: T;
68
- * }
69
- * interface StructuredErrorDocument extends Error {
70
- * request: ImmutableRequestInfo;
71
- * response: ImmutableResponseInfo;
72
- * error: string | object;
73
- * }
74
- * type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;
75
- * ```
76
- *
77
- * @class RequestManager
78
- * @public
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
- #private;
82
- _hasCacheHandler: boolean;
83
- /**
84
- * A map of pending requests from request.id to their
85
- * associated CacheHandler promise.
86
- *
87
- * This queue is managed by the CacheHandler
88
- *
89
- * @internal
90
- */
91
- _pending: Map<number, Promise<unknown>>;
92
- _deduped: Map<StableDocumentIdentifier, {
93
- priority: ManagedRequestPriority;
94
- promise: Promise<unknown>;
95
- }>;
96
- constructor(options?: GenericCreateArgs);
97
- /**
98
- * Register a handler to use for primary cache intercept.
99
- *
100
- * Only one such handler may exist. If using the same
101
- * RequestManager as the Store instance the Store
102
- * registers itself as a Cache handler.
103
- *
104
- * @public
105
- * @param {Handler[]} cacheHandler
106
- * @return {ThisType}
107
- */
108
- useCache(cacheHandler: CacheHandler & {
109
- [IS_CACHE_HANDLER]?: true;
110
- }): this;
111
- /**
112
- * Register handler(s) to use when a request is issued.
113
- *
114
- * Handlers will be invoked in the order they are registered.
115
- * Each Handler is given the opportunity to handle the request,
116
- * curry the request, or pass along a modified request.
117
- *
118
- * @public
119
- * @param {Handler[]} newHandlers
120
- * @return {ThisType}
121
- */
122
- use(newHandlers: Handler[]): this;
123
- /**
124
- * Issue a Request.
125
- *
126
- * Returns a Future that fulfills with a StructuredDocument
127
- *
128
- * @public
129
- * @param {RequestInfo} request
130
- * @return {Future}
131
- */
132
- request<RT, T = unknown>(request: RequestInfo<RT, T>): Future<RT>;
133
- static create(options?: GenericCreateArgs): RequestManager;
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<T = unknown, E = unknown> = {
2
- isError: true;
3
- result: E;
1
+ export type CacheResult<
2
+ T = unknown,
3
+ E = unknown
4
+ > = {
5
+ isError: true;
6
+ result: E;
4
7
  } | {
5
- isError: false;
6
- result: T;
8
+ isError: false;
9
+ result: T;
7
10
  };
8
- export type Awaitable<T = unknown, E = unknown> = {
9
- then: (onFulfilled: (value: T) => unknown, onRejected: (reason: E) => unknown) => unknown;
10
- catch: (onRejected: (reason: E) => unknown) => unknown;
11
- finally: (onFinally: () => unknown) => unknown;
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<unknown, unknown>, CacheResult<unknown, unknown>>;
14
- export declare const RequestMap: Map<number, CacheResult<unknown, unknown>>;
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<T, E>(promise: Promise<T> | Awaitable<T, E>): CacheResult<T, E> | undefined;
20
- //# sourceMappingURL=promise-cache.d.ts.map
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
- import type { StableDocumentIdentifier } from '../../types/identifier';
2
- import type { IS_FUTURE, RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from '../../types/request';
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
- controller: AbortController;
5
- response: ResponseInfo | null;
6
- stream: ReadableStream | Promise<ReadableStream | null> | null;
7
- hasRequestedStream: boolean;
8
- id: number;
9
- identifier: StableDocumentIdentifier | null;
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
- resolve(v: T): void;
13
- reject(v: unknown): void;
14
- promise: Promise<T>;
13
+ resolve(v: T): void;
14
+ reject(v: unknown): void;
15
+ promise: Promise<T>;
15
16
  };
16
17
  export type ManagedRequestPriority = {
17
- blocking: boolean;
18
+ blocking: boolean;
18
19
  };
19
20
  export type DeferredStream = {
20
- resolve(v: ReadableStream | null): void;
21
- reject(v: unknown): void;
22
- promise: Promise<ReadableStream | null> & {
23
- sizeHint?: number;
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
- * A Future is a Promise which resolves to a StructuredDocument
28
- * while providing the ability to `abort` the underlying request,
29
- * `getStream` the response before the outer promise resolves;
30
- *
31
- * @class Future
32
- * @public
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
- [IS_FUTURE]: true;
36
- /**
37
- * Cancel this request by firing the AbortController's signal.
38
- *
39
- * @param {String} [reason] optional reason for aborting the request
40
- * @public
41
- * @return {void}
42
- */
43
- abort(reason?: string): void;
44
- /**
45
- * Get the response stream, if any, once made available.
46
- *
47
- * @public
48
- * @return {Promise<ReadableStream | null>}
49
- */
50
- getStream(): Promise<ReadableStream | null>;
51
- /**
52
- * Run a callback when this request completes. Use sparingly,
53
- * mostly useful for instrumentation and infrastructure.
54
- *
55
- * @param cb the callback to run
56
- * @public
57
- * @return {void}
58
- */
59
- onFinalize(cb: () => void): void;
60
- /**
61
- * The identifier of the associated request, if any, as
62
- * assigned by the CacheHandler.
63
- *
64
- * @property lid
65
- * @type {StableDocumentIdentifier | null}
66
- * @public
67
- */
68
- lid: StableDocumentIdentifier | null;
69
- /**
70
- * The id of the associated request, if any, as assigned
71
- * by the RequestManager
72
- *
73
- * @property id
74
- * @type {Number}
75
- * @public
76
- */
77
- id: number;
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
- resolve(v: StructuredDataDocument<T>): void;
81
- reject(v: unknown): void;
82
- promise: Future<T>;
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
- * Requests are fulfilled by handlers. A handler receives the request context
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
- async request<T>(context: RequestContext, next: NextFn<P>): T;
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
- readonly request: RequestInfo;
110
+ readonly request: RequestInfo;
109
111
 
110
- setStream(stream: ReadableStream | Promise<ReadableStream>): void;
111
- setResponse(response: Response | ResponseInfo): void;
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
- async request(context) {
125
- const response = await fetch(context.request);
126
- context.setResponse(reponse);
127
- context.setStream(response.clone().body);
126
+ async request(context) {
127
+ const response = await fetch(context.request);
128
+ context.setResponse(reponse);
129
+ context.setStream(response.clone().body);
128
130
 
129
- return response.json();
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
- - to manage and return streaming content (such as video files)
142
- - to fulfill a request from multiple sources or by splitting one request into multiple requests
143
- - for instance one API call for a user and another for the user's friends
144
- - 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.)
145
- - to coalesce multiple requests
146
- - to decorate a request with additional info
147
- - e.g. an Auth handler that ensures the correct tokens or headers or cookies are attached.
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
- .use([Handler1, Handler2]);
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
- @class (Interface) Handler
194
- @public
195
+ @class (Interface) Handler
196
+ @public
195
197
  */
196
198
  export interface Handler {
197
- /**
198
- * Method to implement to handle requests. Receives the request
199
- * context and a nextFn to call to pass-along the request to
200
- * other handlers.
201
- *
202
- * @public
203
- * @param context
204
- * @param next
205
- */
206
- request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T>;
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
- * The CacheHandler is identical to other handlers ecxept that it
210
- * is allowed to return a value synchronously. This is useful for
211
- * features like reducing microtask queueing when de-duping.
212
- *
213
- * A RequestManager may only have one CacheHandler, registered via
214
- * `manager.useCache(CacheHandler)`.
215
- *
216
- * @class (Interface) CacheHandler
217
- * @public
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
- * Method to implement to handle requests. Receives the request
222
- * context and a nextFn to call to pass-along the request to
223
- * other handlers.
224
- *
225
- * @public
226
- * @param context
227
- * @param next
228
- */
229
- request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T> | T;
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
- result: T;
234
+ result: T;
233
235
  }
234
236
  export type GenericCreateArgs = Record<string | symbol, unknown>;
235
- //# sourceMappingURL=types.d.ts.map