@ember-data-mirror/request 5.4.0-beta.11 → 5.4.0-beta.13
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/dist/{debug-DGStaRpE.js → debug-D0st-bv4.js} +32 -10
- package/dist/debug-D0st-bv4.js.map +1 -0
- package/dist/fetch.js +2 -4
- package/dist/fetch.js.map +1 -1
- package/dist/index.js +27 -13
- package/dist/index.js.map +1 -1
- package/package.json +25 -15
- package/unstable-preview-types/-private/context.d.ts +6 -1
- package/unstable-preview-types/-private/context.d.ts.map +1 -1
- package/unstable-preview-types/-private/future.d.ts.map +1 -1
- package/unstable-preview-types/-private/manager.d.ts +19 -7
- package/unstable-preview-types/-private/manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/types.d.ts +23 -0
- package/unstable-preview-types/-private/types.d.ts.map +1 -1
- package/unstable-preview-types/-private/utils.d.ts.map +1 -1
- package/unstable-preview-types/fetch.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +4 -4
- package/dist/debug-DGStaRpE.js.map +0 -1
|
@@ -122,7 +122,7 @@ function isCacheHandler(handler, index) {
|
|
|
122
122
|
return index === 0 && Boolean(handler[IS_CACHE_HANDLER]);
|
|
123
123
|
}
|
|
124
124
|
function executeNextHandler(wares, request, i, god) {
|
|
125
|
-
if (macroCondition(getGlobalConfig().
|
|
125
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
126
126
|
if (i === wares.length) {
|
|
127
127
|
throw new Error(`No handler was able to handle this request.`);
|
|
128
128
|
}
|
|
@@ -133,11 +133,15 @@ function executeNextHandler(wares, request, i, god) {
|
|
|
133
133
|
owner.nextCalled++;
|
|
134
134
|
return executeNextHandler(wares, r, i + 1, god);
|
|
135
135
|
}
|
|
136
|
-
const
|
|
136
|
+
const _isCacheHandler = isCacheHandler(wares[i], i);
|
|
137
|
+
const context = new Context(owner, _isCacheHandler);
|
|
137
138
|
let outcome;
|
|
138
139
|
try {
|
|
139
140
|
outcome = wares[i].request(context, next);
|
|
140
|
-
if (
|
|
141
|
+
if (_isCacheHandler) {
|
|
142
|
+
context._finalize();
|
|
143
|
+
}
|
|
144
|
+
if (!!outcome && _isCacheHandler) {
|
|
141
145
|
if (!(outcome instanceof Promise)) {
|
|
142
146
|
setRequestResult(owner.requestId, {
|
|
143
147
|
isError: false,
|
|
@@ -145,7 +149,7 @@ function executeNextHandler(wares, request, i, god) {
|
|
|
145
149
|
});
|
|
146
150
|
outcome = Promise.resolve(outcome);
|
|
147
151
|
}
|
|
148
|
-
} else if (macroCondition(getGlobalConfig().
|
|
152
|
+
} else if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
149
153
|
if (!outcome || !(outcome instanceof Promise) && !(typeof outcome === 'object' && 'then' in outcome)) {
|
|
150
154
|
// eslint-disable-next-line no-console
|
|
151
155
|
console.log({
|
|
@@ -160,12 +164,13 @@ function executeNextHandler(wares, request, i, god) {
|
|
|
160
164
|
}
|
|
161
165
|
}
|
|
162
166
|
} catch (e) {
|
|
163
|
-
if (
|
|
167
|
+
if (_isCacheHandler) {
|
|
164
168
|
setRequestResult(owner.requestId, {
|
|
165
169
|
isError: true,
|
|
166
170
|
result: ensureDoc(owner, e, true)
|
|
167
171
|
});
|
|
168
172
|
}
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
169
174
|
outcome = Promise.reject(e);
|
|
170
175
|
}
|
|
171
176
|
const future = createFuture(owner);
|
|
@@ -198,6 +203,8 @@ function upgradePromise(promise, future) {
|
|
|
198
203
|
promise.abort = future.abort;
|
|
199
204
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
200
205
|
promise.onFinalize = future.onFinalize;
|
|
206
|
+
promise.id = future.id;
|
|
207
|
+
promise.lid = future.lid;
|
|
201
208
|
return promise;
|
|
202
209
|
}
|
|
203
210
|
function createFuture(owner) {
|
|
@@ -223,6 +230,8 @@ function createFuture(owner) {
|
|
|
223
230
|
promise.abort = reason => {
|
|
224
231
|
owner.abort(enhanceReason(reason));
|
|
225
232
|
};
|
|
233
|
+
promise.id = owner.requestId;
|
|
234
|
+
promise.lid = owner.god.identifier;
|
|
226
235
|
deferred.promise = promise;
|
|
227
236
|
return deferred;
|
|
228
237
|
}
|
|
@@ -279,7 +288,7 @@ class ContextOwner {
|
|
|
279
288
|
let enhancedRequest = Object.assign({
|
|
280
289
|
signal: this.controller.signal
|
|
281
290
|
}, request);
|
|
282
|
-
if (macroCondition(getGlobalConfig().
|
|
291
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
283
292
|
if (!request?.cacheOptions?.[SkipCache]) {
|
|
284
293
|
request = deepFreeze(request);
|
|
285
294
|
enhancedRequest = deepFreeze(enhancedRequest);
|
|
@@ -340,7 +349,7 @@ class ContextOwner {
|
|
|
340
349
|
}
|
|
341
350
|
setResponse(response) {
|
|
342
351
|
if (this.hasSetResponse) {
|
|
343
|
-
if (macroCondition(getGlobalConfig().
|
|
352
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
344
353
|
throw new Error(`Cannot setResponse when a response has already been set`);
|
|
345
354
|
}
|
|
346
355
|
return;
|
|
@@ -349,7 +358,7 @@ class ContextOwner {
|
|
|
349
358
|
if (response instanceof Response) {
|
|
350
359
|
// TODO potentially avoid cloning in prod
|
|
351
360
|
let responseData = cloneResponseProperties(response);
|
|
352
|
-
if (macroCondition(getGlobalConfig().
|
|
361
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
353
362
|
responseData = deepFreeze(responseData);
|
|
354
363
|
}
|
|
355
364
|
this.response = responseData;
|
|
@@ -364,10 +373,12 @@ class ContextOwner {
|
|
|
364
373
|
}
|
|
365
374
|
class Context {
|
|
366
375
|
#owner;
|
|
367
|
-
constructor(owner) {
|
|
376
|
+
constructor(owner, isCacheHandler) {
|
|
368
377
|
this.id = owner.requestId;
|
|
369
378
|
this.#owner = owner;
|
|
370
379
|
this.request = owner.enhancedRequest;
|
|
380
|
+
this._isCacheHandler = isCacheHandler;
|
|
381
|
+
this._finalized = false;
|
|
371
382
|
}
|
|
372
383
|
setStream(stream) {
|
|
373
384
|
this.#owner.setStream(stream);
|
|
@@ -375,9 +386,20 @@ class Context {
|
|
|
375
386
|
setResponse(response) {
|
|
376
387
|
this.#owner.setResponse(response);
|
|
377
388
|
}
|
|
389
|
+
setIdentifier(identifier) {
|
|
390
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
391
|
+
if (!test) {
|
|
392
|
+
throw new Error(`setIdentifier may only be used synchronously from a CacheHandler`);
|
|
393
|
+
}
|
|
394
|
+
})(identifier && this._isCacheHandler && !this._finalized) : {};
|
|
395
|
+
this.#owner.god.identifier = identifier;
|
|
396
|
+
}
|
|
378
397
|
get hasRequestedStream() {
|
|
379
398
|
return this.#owner.hasRequestedStream;
|
|
380
399
|
}
|
|
400
|
+
_finalize() {
|
|
401
|
+
this._finalized = true;
|
|
402
|
+
}
|
|
381
403
|
}
|
|
382
404
|
const BODY_TYPES = {
|
|
383
405
|
type: 'string',
|
|
@@ -573,7 +595,7 @@ function validateKey(key, value, errors) {
|
|
|
573
595
|
}
|
|
574
596
|
const IgnoredKeys = new Set([]);
|
|
575
597
|
function assertValidRequest(request, isTopLevel) {
|
|
576
|
-
if (macroCondition(getGlobalConfig().
|
|
598
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
577
599
|
// handle basic shape
|
|
578
600
|
if (!request) {
|
|
579
601
|
throw new Error(`Expected ${isTopLevel ? 'RequestManager.request' : 'next'}(<request>) to be called with a request, but none was provided.`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-D0st-bv4.js","sources":["../src/-private/promise-cache.ts","../src/-private/utils.ts","../src/-private/future.ts","../src/-private/context.ts","../src/-private/debug.ts"],"sourcesContent":["import { getOrSetUniversal } from '@warp-drive-mirror/core-types/-private';\n\nexport type CacheResult<T = unknown, E = unknown> = { isError: true; result: E } | { isError: false; result: T };\n\nexport type Awaitable<T = unknown, E = unknown> = {\n then: (onFulfilled: (value: T) => unknown, onRejected: (reason: E) => unknown) => unknown;\n catch: (onRejected: (reason: E) => unknown) => unknown;\n finally: (onFinally: () => unknown) => unknown;\n};\n\nexport const PromiseCache = getOrSetUniversal('PromiseCache', new WeakMap<Awaitable, CacheResult>());\nexport const RequestMap = getOrSetUniversal('RequestMap', new Map<number, CacheResult>());\n\nexport function setRequestResult(requestId: number, result: CacheResult) {\n RequestMap.set(requestId, result);\n}\nexport function clearRequestResult(requestId: number) {\n RequestMap.delete(requestId);\n}\nexport function getRequestResult(requestId: number): CacheResult | undefined {\n return RequestMap.get(requestId);\n}\n\nexport function setPromiseResult(promise: Promise<unknown> | Awaitable, result: CacheResult) {\n PromiseCache.set(promise, result);\n}\n\nexport function getPromiseResult<T, E>(promise: Promise<T> | Awaitable<T, E>): CacheResult<T, E> | undefined {\n return PromiseCache.get(promise) as CacheResult<T, E> | undefined;\n}\n","import { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport { getOrSetGlobal } from '@warp-drive-mirror/core-types/-private';\nimport type {\n RequestInfo,\n StructuredDataDocument,\n StructuredDocument,\n StructuredErrorDocument,\n} from '@warp-drive-mirror/core-types/request';\nimport { STRUCTURED } from '@warp-drive-mirror/core-types/request';\n\nimport { Context, ContextOwner } from './context';\nimport { assertValidRequest } from './debug';\nimport { createFuture, isFuture } from './future';\nimport { setRequestResult } from './promise-cache';\nimport type { DeferredFuture, Future, GodContext, Handler } from './types';\n\nexport const IS_CACHE_HANDLER = getOrSetGlobal('IS_CACHE_HANDLER', Symbol('IS_CACHE_HANDLER'));\nexport function curryFuture<T>(owner: ContextOwner, inbound: Future<T>, outbound: DeferredFuture<T>): Future<T> {\n owner.setStream(inbound.getStream());\n\n inbound.then(\n (doc: StructuredDataDocument<T>) => {\n const document = {\n [STRUCTURED]: true as const,\n request: owner.request,\n response: doc.response,\n content: doc.content,\n };\n outbound.resolve(document);\n },\n (error: Error & StructuredErrorDocument) => {\n if (isDoc(error)) {\n owner.setStream(owner.god.stream);\n }\n if (!error || !(error instanceof Error)) {\n try {\n throw new Error(error ? error : `Request Rejected with an Unknown Error`);\n } catch (e: unknown) {\n if (error && typeof error === 'object') {\n Object.assign(e as Error, error);\n (e as Error & StructuredErrorDocument).message =\n (error as Error).message || `Request Rejected with an Unknown Error`;\n }\n error = e as Error & StructuredErrorDocument;\n }\n }\n\n error[STRUCTURED] = true;\n error.request = owner.request;\n error.response = owner.getResponse();\n error.error = error.error || error.message;\n\n outbound.reject(error);\n }\n );\n return outbound.promise;\n}\n\nfunction isDoc<T>(doc: T | StructuredDataDocument<T>): doc is StructuredDataDocument<T> {\n return doc && (doc as StructuredDataDocument<T>)[STRUCTURED] === true;\n}\n\nfunction ensureDoc<T>(owner: ContextOwner, content: T | Error, isError: boolean): StructuredDocument<T> {\n if (isDoc(content)) {\n return content as StructuredDocument<T>;\n }\n\n if (isError) {\n return {\n [STRUCTURED]: true,\n request: owner.request,\n response: owner.getResponse(),\n error: content as Error,\n } as StructuredErrorDocument<T>;\n }\n\n return {\n [STRUCTURED]: true,\n request: owner.request,\n response: owner.getResponse(),\n content: content as T,\n };\n}\n\nexport type HttpErrorProps = {\n code: number;\n name: string;\n status: number;\n statusText: string;\n isRequestError: boolean;\n};\n\nexport function enhanceReason(reason?: string) {\n return new DOMException(reason || 'The user aborted a request.', 'AbortError');\n}\n\nexport function handleOutcome<T>(\n owner: ContextOwner,\n inbound: Promise<T | StructuredDataDocument<T>>,\n outbound: DeferredFuture<T>\n): Future<T> {\n inbound.then(\n (content: T | StructuredDataDocument<T>) => {\n if (owner.controller.signal.aborted) {\n // the next function did not respect the signal, we handle it here\n outbound.reject(enhanceReason(owner.controller.signal.reason as string));\n return;\n }\n if (isDoc(content)) {\n owner.setStream(owner.god.stream);\n content = content.content;\n }\n const document = {\n [STRUCTURED]: true as const,\n request: owner.request,\n response: owner.getResponse(),\n content,\n };\n outbound.resolve(document);\n },\n (error: Error & StructuredErrorDocument) => {\n if (isDoc(error)) {\n owner.setStream(owner.god.stream);\n }\n if (!error || !(error instanceof Error)) {\n try {\n throw new Error(error ? error : `Request Rejected with an Unknown Error`);\n } catch (e: unknown) {\n if (error && typeof error === 'object') {\n Object.assign(e as Error, error);\n (e as Error & StructuredErrorDocument).message =\n (error as Error).message || `Request Rejected with an Unknown Error`;\n }\n error = e as Error & StructuredErrorDocument;\n }\n }\n\n error[STRUCTURED] = true;\n error.request = owner.request;\n error.response = owner.getResponse();\n error.error = error.error || error.message;\n outbound.reject(error);\n }\n );\n return outbound.promise;\n}\n\nfunction isCacheHandler(handler: Handler & { [IS_CACHE_HANDLER]?: boolean }, index: number): boolean {\n return index === 0 && Boolean(handler[IS_CACHE_HANDLER]);\n}\n\nexport function executeNextHandler<T>(\n wares: Readonly<Handler[]>,\n request: RequestInfo,\n i: number,\n god: GodContext\n): Future<T> {\n if (DEBUG) {\n if (i === wares.length) {\n throw new Error(`No handler was able to handle this request.`);\n }\n assertValidRequest(request, false);\n }\n const owner = new ContextOwner(request, god, i === 0);\n\n function next(r: RequestInfo): Future<T> {\n owner.nextCalled++;\n return executeNextHandler(wares, r, i + 1, god);\n }\n\n const _isCacheHandler = isCacheHandler(wares[i], i);\n const context = new Context(owner, _isCacheHandler);\n let outcome: Promise<T | StructuredDataDocument<T>> | Future<T>;\n try {\n outcome = wares[i].request<T>(context, next);\n if (_isCacheHandler) {\n context._finalize();\n }\n if (!!outcome && _isCacheHandler) {\n if (!(outcome instanceof Promise)) {\n setRequestResult(owner.requestId, { isError: false, result: ensureDoc(owner, outcome, false) });\n outcome = Promise.resolve(outcome);\n }\n } else if (DEBUG) {\n if (!outcome || (!(outcome instanceof Promise) && !(typeof outcome === 'object' && 'then' in outcome))) {\n // eslint-disable-next-line no-console\n console.log({ request, handler: wares[i], outcome });\n if (outcome === undefined) {\n throw new Error(`Expected handler.request to return a promise, instead received undefined.`);\n }\n throw new Error(`Expected handler.request to return a promise, instead received a synchronous value.`);\n }\n }\n } catch (e) {\n if (_isCacheHandler) {\n setRequestResult(owner.requestId, { isError: true, result: ensureDoc(owner, e, true) });\n }\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n outcome = Promise.reject<StructuredDataDocument<T>>(e);\n }\n const future = createFuture<T>(owner);\n\n if (isFuture<T>(outcome)) {\n return curryFuture(owner, outcome, future);\n }\n\n return handleOutcome(owner, outcome, future);\n}\n","import { IS_FUTURE, type StructuredDocument } from '@warp-drive-mirror/core-types/request';\n\nimport type { ContextOwner } from './context';\nimport type { Deferred, DeferredFuture, Future } from './types';\nimport { enhanceReason } from './utils';\n\nexport function isFuture<T>(maybe: unknown): maybe is Future<T> {\n return Boolean(maybe && maybe instanceof Promise && (maybe as Future<T>)[IS_FUTURE] === true);\n}\n\nexport function createDeferred<T>(): Deferred<T> {\n let resolve!: (v: T) => void;\n let reject!: (v: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { resolve, reject, promise };\n}\n\nexport function upgradePromise<T>(promise: Promise<StructuredDocument<T>>, future: Future<T>): Future<T> {\n (promise as Future<T>)[IS_FUTURE] = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).getStream = future.getStream;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).abort = future.abort;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).onFinalize = future.onFinalize;\n (promise as Future<T>).id = future.id;\n (promise as Future<T>).lid = future.lid;\n\n return promise as Future<T>;\n}\n\nexport function createFuture<T>(owner: ContextOwner): DeferredFuture<T> {\n const deferred = createDeferred<T>() as unknown as DeferredFuture<T>;\n let { promise } = deferred;\n let cbs: Array<() => void> | undefined;\n promise = promise.finally(() => {\n owner.resolveStream();\n if (cbs) {\n cbs.forEach((cb) => cb());\n }\n }) as Future<T>;\n promise.onFinalize = (fn: () => void) => {\n cbs = cbs || [];\n cbs.push(fn);\n };\n promise[IS_FUTURE] = true;\n promise.getStream = () => {\n return owner.getStream();\n };\n promise.abort = (reason?: string) => {\n owner.abort(enhanceReason(reason));\n };\n promise.id = owner.requestId;\n promise.lid = owner.god.identifier;\n\n deferred.promise = promise;\n return deferred;\n}\n","import { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\nimport type { StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type { ImmutableHeaders, ImmutableRequestInfo, RequestInfo, ResponseInfo } from '@warp-drive-mirror/core-types/request';\nimport { SkipCache } from '@warp-drive-mirror/core-types/request';\n\nimport { deepFreeze } from './debug';\nimport { createDeferred } from './future';\nimport type { DeferredStream, GodContext } from './types';\n\nexport function upgradeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders {\n (headers as ImmutableHeaders).clone = () => {\n return new Headers(headers);\n };\n (headers as ImmutableHeaders).toJSON = () => {\n return Array.from(headers);\n };\n return headers as ImmutableHeaders;\n}\n\nexport function cloneResponseProperties(response: Response): ResponseInfo {\n const { headers, ok, redirected, status, statusText, type, url } = response;\n upgradeHeaders(headers);\n return {\n headers: headers as ImmutableHeaders,\n ok,\n redirected,\n status,\n statusText,\n type,\n url,\n };\n}\n\nexport class ContextOwner {\n hasSetStream = false;\n hasSetResponse = false;\n hasSubscribers = false;\n stream: DeferredStream = createDeferred<ReadableStream | null>();\n response: ResponseInfo | null = null;\n declare request: ImmutableRequestInfo;\n declare enhancedRequest: ImmutableRequestInfo;\n nextCalled = 0;\n declare god: GodContext;\n declare controller: AbortController;\n declare requestId: number;\n declare isRoot: boolean;\n\n constructor(request: RequestInfo, god: GodContext, isRoot = false) {\n this.isRoot = isRoot;\n this.requestId = god.id;\n this.controller = request.controller || god.controller;\n this.stream.promise.sizeHint = 0;\n\n if (request.controller) {\n if (request.controller !== god.controller) {\n god.controller.signal.addEventListener('abort', () => {\n this.controller.abort(god.controller.signal.reason);\n });\n }\n delete request.controller;\n }\n let enhancedRequest: ImmutableRequestInfo = Object.assign(\n { signal: this.controller.signal },\n request\n ) as ImmutableRequestInfo;\n if (DEBUG) {\n if (!request?.cacheOptions?.[SkipCache]) {\n request = deepFreeze(request) as ImmutableRequestInfo;\n enhancedRequest = deepFreeze(enhancedRequest);\n }\n } else {\n if (request.headers) {\n upgradeHeaders(request.headers);\n }\n }\n this.enhancedRequest = enhancedRequest;\n this.request = request as ImmutableRequestInfo;\n this.god = god;\n this.stream.promise = this.stream.promise.then((stream: ReadableStream | null) => {\n if (this.god.stream === stream && this.hasSubscribers) {\n this.god.stream = null;\n }\n return stream;\n });\n }\n\n get hasRequestedStream(): boolean {\n return this.god.hasRequestedStream;\n }\n\n getResponse(): ResponseInfo | null {\n if (this.hasSetResponse) {\n return this.response;\n }\n if (this.nextCalled === 1) {\n return this.god.response;\n }\n return null;\n }\n getStream(): Promise<ReadableStream | null> {\n if (this.isRoot) {\n this.god.hasRequestedStream = true;\n }\n if (!this.hasSetResponse) {\n const hint = this.god.response?.headers?.get('content-length');\n this.stream.promise.sizeHint = hint ? parseInt(hint, 10) : 0;\n }\n this.hasSubscribers = true;\n return this.stream.promise;\n }\n abort(reason: DOMException) {\n this.controller.abort(reason);\n }\n\n setStream(stream: ReadableStream | Promise<ReadableStream | null> | null) {\n if (!this.hasSetStream) {\n this.hasSetStream = true;\n\n if (!(stream instanceof Promise)) {\n this.god.stream = stream;\n }\n // @ts-expect-error\n this.stream.resolve(stream);\n }\n }\n\n resolveStream() {\n this.setStream(this.nextCalled === 1 ? this.god.stream : null);\n }\n\n setResponse(response: ResponseInfo | Response | null) {\n if (this.hasSetResponse) {\n if (DEBUG) {\n throw new Error(`Cannot setResponse when a response has already been set`);\n }\n return;\n }\n this.hasSetResponse = true;\n if (response instanceof Response) {\n // TODO potentially avoid cloning in prod\n let responseData = cloneResponseProperties(response);\n\n if (DEBUG) {\n responseData = deepFreeze(responseData);\n }\n this.response = responseData;\n this.god.response = responseData;\n const sizeHint = response.headers?.get('content-length');\n this.stream.promise.sizeHint = sizeHint ? parseInt(sizeHint, 10) : 0;\n } else {\n this.response = response;\n this.god.response = response;\n }\n }\n}\n\nexport class Context {\n #owner: ContextOwner;\n declare request: ImmutableRequestInfo;\n declare id: number;\n private declare _isCacheHandler: boolean;\n private declare _finalized: boolean;\n\n constructor(owner: ContextOwner, isCacheHandler: boolean) {\n this.id = owner.requestId;\n this.#owner = owner;\n this.request = owner.enhancedRequest;\n this._isCacheHandler = isCacheHandler;\n this._finalized = false;\n }\n setStream(stream: ReadableStream | Promise<ReadableStream | null>) {\n this.#owner.setStream(stream);\n }\n setResponse(response: ResponseInfo | Response | null) {\n this.#owner.setResponse(response);\n }\n\n setIdentifier(identifier: StableDocumentIdentifier) {\n assert(\n `setIdentifier may only be used synchronously from a CacheHandler`,\n identifier && this._isCacheHandler && !this._finalized\n );\n this.#owner.god.identifier = identifier;\n }\n\n get hasRequestedStream() {\n return this.#owner.hasRequestedStream;\n }\n\n _finalize() {\n this._finalized = true;\n }\n}\nexport type HandlerRequestContext = Context;\n","import { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport { getOrSetGlobal } from '@warp-drive-mirror/core-types/-private';\nimport type { ImmutableHeaders, RequestInfo } from '@warp-drive-mirror/core-types/request';\n\nimport { Context, upgradeHeaders } from './context';\n\nconst BODY_TYPES = {\n type: 'string',\n klass: ['Blob', 'ArrayBuffer', 'TypedArray', 'DataView', 'FormData', 'URLSearchParams', 'ReadableStream'],\n};\nconst ValidKeys = new Map<string, string | string[] | typeof BODY_TYPES>([\n ['records', 'array'],\n ['data', 'json'],\n ['body', BODY_TYPES],\n ['disableTestWaiter', 'boolean'],\n ['options', 'object'],\n ['cacheOptions', 'object'],\n ['op', 'string'],\n ['store', 'object'],\n ['url', 'string'],\n ['cache', ['default', 'force-cache', 'no-cache', 'no-store', 'only-if-cached', 'reload']],\n ['credentials', ['include', 'omit', 'same-origin']],\n [\n 'destination',\n [\n '',\n 'object',\n 'audio',\n 'audioworklet',\n 'document',\n 'embed',\n 'font',\n 'frame',\n 'iframe',\n 'image',\n 'manifest',\n 'paintworklet',\n 'report',\n 'script',\n 'sharedworker',\n 'style',\n 'track',\n 'video',\n 'worker',\n 'xslt',\n ],\n ],\n ['headers', 'headers'],\n ['integrity', 'string'],\n ['keepalive', 'boolean'],\n ['method', ['GET', 'PUT', 'PATCH', 'DELETE', 'POST', 'OPTIONS']],\n ['mode', ['same-origin', 'cors', 'navigate', 'no-cors']],\n ['redirect', ['error', 'follow', 'manual']],\n ['referrer', 'string'],\n ['signal', 'AbortSignal'],\n ['controller', 'AbortController'],\n [\n 'referrerPolicy',\n [\n '',\n 'same-origin',\n 'no-referrer',\n 'no-referrer-when-downgrade',\n 'origin',\n 'origin-when-cross-origin',\n 'strict-origin',\n 'strict-origin-when-cross-origin',\n 'unsafe-url',\n ],\n ],\n]);\n\nconst IS_FROZEN = getOrSetGlobal('IS_FROZEN', Symbol('FROZEN'));\nconst IS_COLLECTION = getOrSetGlobal('IS_COLLECTION', Symbol.for('Collection'));\n\nfunction freezeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders {\n headers.delete =\n headers.set =\n headers.append =\n () => {\n throw new Error(`Cannot Mutate Immutatable Headers, use headers.clone to get a copy`);\n };\n upgradeHeaders(headers);\n return headers as ImmutableHeaders;\n}\n\nexport function deepFreeze<T = unknown>(value: T): T {\n if (value && (value as { [IS_FROZEN]?: true })[IS_FROZEN]) {\n return value;\n }\n const _type = typeof value;\n switch (_type) {\n case 'boolean':\n case 'string':\n case 'number':\n case 'symbol':\n case 'undefined':\n case 'bigint':\n return value;\n case 'function':\n throw new Error(`Cannot deep-freeze a function`);\n case 'object': {\n const _niceType = niceTypeOf(value);\n switch (_niceType) {\n case 'array': {\n if ((value as unknown[] & { [IS_COLLECTION]?: true })[IS_COLLECTION]) {\n return value;\n }\n const arr = (value as unknown[]).map(deepFreeze);\n arr[IS_FROZEN as unknown as number] = true;\n return Object.freeze(arr) as T;\n }\n case 'null':\n return value;\n case 'object':\n Object.keys(value as Record<string, unknown>).forEach((key) => {\n try {\n (value as Record<string, unknown>)[key] = deepFreeze((value as Record<string, unknown>)[key]) as object;\n } catch {\n // continue\n }\n });\n (value as Record<string | symbol, unknown>)[IS_FROZEN] = true;\n return Object.freeze(value);\n case 'headers':\n return freezeHeaders(value as Headers) as T;\n case 'Collection':\n case 'Store':\n case 'AbortSignal':\n return value;\n case 'date':\n case 'map':\n case 'set':\n case 'error':\n case 'stream':\n default:\n // console.log(`Cannot deep-freeze ${_niceType}`);\n return value;\n }\n }\n }\n}\n\nfunction isMaybeContext(request: unknown) {\n if (request && typeof request === 'object') {\n const keys = Object.keys(request);\n if (keys.length === 1 && keys[0] === 'request') {\n return true;\n }\n }\n return false;\n}\n\nfunction niceTypeOf(v: unknown) {\n if (v === null) {\n return 'null';\n }\n if (typeof v === 'string') {\n return v ? 'non-empty-string' : 'empty-string';\n }\n if (!v) {\n return typeof v;\n }\n if (Array.isArray(v)) {\n return 'array';\n }\n if (v instanceof Date) {\n return 'date';\n }\n if (v instanceof Map) {\n return 'map';\n }\n if (v instanceof Set) {\n return 'set';\n }\n if (v instanceof Error) {\n return 'error';\n }\n if (v instanceof ReadableStream || v instanceof WritableStream || v instanceof TransformStream) {\n return 'stream';\n }\n if (v instanceof Headers) {\n return 'headers';\n }\n if (typeof v === 'object' && v.constructor && v.constructor.name !== 'Object') {\n return v.constructor.name;\n }\n return typeof v;\n}\n\nfunction validateKey(key: string, value: unknown, errors: string[]) {\n const schema = ValidKeys.get(key);\n if (!schema && !IgnoredKeys.has(key)) {\n errors.push(`InvalidKey: '${key}'`);\n return;\n }\n if (schema) {\n if (schema === BODY_TYPES) {\n if (typeof value === 'string' || value instanceof ReadableStream) {\n return;\n }\n const type = niceTypeOf(value);\n if (schema.klass.includes(type)) {\n return;\n }\n errors.push(\n `InvalidValue: key 'body' should be a string or one of '${schema.klass.join(\"', '\")}', received ${\n '<a value of type ' + niceTypeOf(value) + '>'\n }`\n );\n return;\n }\n if (Array.isArray(schema)) {\n if (!schema.includes(value as string)) {\n errors.push(\n `InvalidValue: key ${key} should be a one of '${schema.join(\"', '\")}', received ${\n typeof value === 'string' ? value : '<a value of type ' + niceTypeOf(value) + '>'\n }`\n );\n }\n return;\n } else if (schema === 'json') {\n try {\n JSON.stringify(value);\n } catch (e) {\n errors.push(\n `InvalidValue: key ${key} should be a JSON serializable value, but failed to serialize with Error - ${\n (e as Error).message\n }`\n );\n }\n return;\n } else if (schema === 'headers') {\n if (!(value instanceof Headers)) {\n errors.push(`InvalidValue: key ${key} should be an instance of Headers, received ${niceTypeOf(value)}`);\n }\n return;\n } else if (schema === 'record') {\n const _type = typeof value;\n // record must extend plain object or Object.create(null)\n if (!value || _type !== 'object' || (value.constructor && value.constructor !== Object)) {\n errors.push(\n `InvalidValue: key ${key} should be a dictionary of string keys to string values, received ${niceTypeOf(\n value\n )}`\n );\n return;\n }\n const keys = Object.keys(value);\n keys.forEach((k) => {\n const v: unknown = (value as Record<string, unknown>)[k];\n if (typeof k !== 'string') {\n errors.push(`\\tThe key ${String(k)} on ${key} should be a string key`);\n } else if (typeof v !== 'string') {\n errors.push(`\\tThe value of ${key}.${k} should be a string not ${niceTypeOf(v)}`);\n }\n });\n return;\n } else if (schema === 'string') {\n if (typeof value !== 'string' || value.length === 0) {\n errors.push(\n `InvalidValue: key ${key} should be a non-empty string, received ${\n typeof value === 'string' ? \"''\" : typeof value\n }`\n );\n }\n return;\n } else if (schema === 'object') {\n if (!value || Array.isArray(value) || typeof value !== 'object') {\n errors.push(`InvalidValue: key ${key} should be an object`);\n }\n return;\n } else if (schema === 'boolean') {\n if (typeof value !== 'boolean') {\n errors.push(`InvalidValue: key ${key} should be a boolean, received ${typeof value}`);\n }\n return;\n } else if (schema === 'array') {\n if (!Array.isArray(value)) {\n errors.push(`InvalidValue: key ${key} should be an array, received ${typeof value}`);\n }\n return;\n }\n }\n}\n\nconst IgnoredKeys = new Set<string>([]);\n\nexport function assertValidRequest(\n request: RequestInfo | Context,\n isTopLevel: boolean\n): asserts request is RequestInfo {\n if (DEBUG) {\n // handle basic shape\n if (!request) {\n throw new Error(\n `Expected ${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>) to be called with a request, but none was provided.`\n );\n }\n if (Array.isArray(request) || typeof request !== 'object') {\n throw new Error(\n `The \\`request\\` passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` should be an object, received \\`${niceTypeOf(request)}\\``\n );\n }\n if (Object.keys(request).length === 0) {\n throw new Error(\n `The \\`request\\` passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` was empty (\\`{}\\`). Requests need at least one valid key.`\n );\n }\n\n // handle accidentally passing context entirely\n if (request instanceof Context) {\n throw new Error(\n `Expected a request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` but received the previous handler's context instead`\n );\n }\n // handle Object.assign({}, context);\n if (isMaybeContext(request)) {\n throw new Error(\n `Expected a request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` but received an object with a request key instead.`\n );\n }\n\n // handle schema\n const keys = Object.keys(request) as Array<keyof RequestInfo>;\n const validationErrors: string[] = [];\n const isLegacyRequest = Boolean('op' in request && !request.url);\n keys.forEach((key) => {\n if (isLegacyRequest && key === 'data') {\n return;\n }\n validateKey(key, request[key], validationErrors);\n });\n if (validationErrors.length) {\n const error: Error & { errors: string[] } = new Error(\n `Invalid Request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\`.\\n\\nThe following issues were found:\\n\\n\\t${validationErrors.join('\\n\\t')}`\n ) as Error & { errors: string[] };\n error.errors = validationErrors;\n throw error;\n }\n }\n}\n"],"names":["PromiseCache","getOrSetUniversal","WeakMap","RequestMap","Map","setRequestResult","requestId","result","set","clearRequestResult","delete","getRequestResult","get","setPromiseResult","promise","getPromiseResult","IS_CACHE_HANDLER","getOrSetGlobal","Symbol","curryFuture","owner","inbound","outbound","setStream","getStream","then","doc","document","STRUCTURED","request","response","content","resolve","error","isDoc","god","stream","Error","e","Object","assign","message","getResponse","reject","ensureDoc","isError","enhanceReason","reason","DOMException","handleOutcome","controller","signal","aborted","isCacheHandler","handler","index","Boolean","executeNextHandler","wares","i","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","length","assertValidRequest","ContextOwner","next","r","nextCalled","_isCacheHandler","context","Context","outcome","_finalize","Promise","console","log","undefined","future","createFuture","isFuture","maybe","IS_FUTURE","createDeferred","res","rej","upgradePromise","abort","onFinalize","id","lid","deferred","cbs","finally","resolveStream","forEach","cb","fn","push","identifier","upgradeHeaders","headers","clone","Headers","toJSON","Array","from","cloneResponseProperties","ok","redirected","status","statusText","type","url","hasSetStream","hasSetResponse","hasSubscribers","constructor","isRoot","sizeHint","addEventListener","enhancedRequest","cacheOptions","SkipCache","deepFreeze","hasRequestedStream","hint","parseInt","setResponse","Response","responseData","_finalized","setIdentifier","test","BODY_TYPES","klass","ValidKeys","IS_FROZEN","IS_COLLECTION","for","freezeHeaders","append","value","_type","_niceType","niceTypeOf","arr","map","freeze","keys","key","isMaybeContext","v","isArray","Date","Set","ReadableStream","WritableStream","TransformStream","name","validateKey","errors","schema","IgnoredKeys","has","includes","join","JSON","stringify","k","String","isTopLevel","validationErrors","isLegacyRequest"],"mappings":";;;;AAUO,MAAMA,YAAY,GAAGC,iBAAiB,CAAC,cAAc,EAAE,IAAIC,OAAO,EAA0B,CAAC,CAAA;AAC7F,MAAMC,UAAU,GAAGF,iBAAiB,CAAC,YAAY,EAAE,IAAIG,GAAG,EAAuB,CAAC,CAAA;AAElF,SAASC,gBAAgBA,CAACC,SAAiB,EAAEC,MAAmB,EAAE;AACvEJ,EAAAA,UAAU,CAACK,GAAG,CAACF,SAAS,EAAEC,MAAM,CAAC,CAAA;AACnC,CAAA;AACO,SAASE,kBAAkBA,CAACH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.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as cloneResponseProperties } from "./debug-
|
|
1
|
+
import { f as cloneResponseProperties } from "./debug-D0st-bv4.js";
|
|
2
2
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -27,7 +27,7 @@ function cloneResponse(response, overrides) {
|
|
|
27
27
|
return new Response(response.body, Object.assign(props, overrides));
|
|
28
28
|
}
|
|
29
29
|
let IS_MAYBE_MIRAGE = () => false;
|
|
30
|
-
if (macroCondition(getGlobalConfig().
|
|
30
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
31
31
|
IS_MAYBE_MIRAGE = () => Boolean(typeof window !== 'undefined' && (window.server?.pretender || window.fetch.toString().replace(/\s+/g, '') !== 'function fetch() { [native code] }'.replace(/\s+/g, '')));
|
|
32
32
|
}
|
|
33
33
|
const MUTATION_OPS = new Set(['updateRecord', 'createRecord', 'deleteRecord']);
|
|
@@ -102,8 +102,6 @@ const Fetch = {
|
|
|
102
102
|
});
|
|
103
103
|
context.setStream(stream.readable);
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
// eslint-disable-next-line no-constant-condition
|
|
107
105
|
while (true) {
|
|
108
106
|
// we manually read the stream instead of using `response.json()`
|
|
109
107
|
// or `response.text()` because if we need to stream the body
|
package/dist/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sources":["../src/fetch.ts"],"sourcesContent":["/**\n * A basic Fetch Handler which converts a request into a\n * `fetch` call presuming the response to be `json`.\n *\n * ```ts\n * import Fetch from '@ember-data-mirror/request/fetch';\n *\n * manager.use([Fetch]);\n * ```\n *\n * @module @ember-data-mirror/request/fetch\n * @main @ember-data-mirror/request/fetch\n */\n\nimport { DEBUG } from '@warp-drive-mirror/build-config/env';\n\nimport { cloneResponseProperties, type Context } from './-private/context';\nimport type { HttpErrorProps } from './-private/utils';\n\n// Lazily close over fetch to avoid breaking Mirage\nconst _fetch: typeof fetch =\n typeof fetch !== 'undefined'\n ? (...args) => fetch(...args)\n : typeof FastBoot !== 'undefined'\n ? (...args) => (FastBoot.require('node-fetch') as typeof fetch)(...args)\n : ((() => {\n throw new Error('No Fetch Implementation Found');\n }) as typeof fetch);\n\n// clones a response in a way that should still\n// allow it to stream\nfunction cloneResponse(response: Response, overrides: Partial<Response>) {\n const props = cloneResponseProperties(response);\n return new Response(response.body, Object.assign(props, overrides));\n}\n\nlet IS_MAYBE_MIRAGE = () => false;\nif (DEBUG) {\n IS_MAYBE_MIRAGE = () =>\n Boolean(\n typeof window !== 'undefined' &&\n ((window as { server?: { pretender: unknown } }).server?.pretender ||\n window.fetch.toString().replace(/\\s+/g, '') !== 'function fetch() { [native code] }'.replace(/\\s+/g, ''))\n );\n}\n\nconst MUTATION_OPS = new Set(['updateRecord', 'createRecord', 'deleteRecord']);\nconst ERROR_STATUS_CODE_FOR = new Map([\n [400, 'Bad Request'],\n [401, 'Unauthorized'],\n [402, 'Payment Required'],\n [403, 'Forbidden'],\n [404, 'Not Found'],\n [405, 'Method Not Allowed'],\n [406, 'Not Acceptable'],\n [407, 'Proxy Authentication Required'],\n [408, 'Request Timeout'],\n [409, 'Conflict'],\n [410, 'Gone'],\n [411, 'Length Required'],\n [412, 'Precondition Failed'],\n [413, 'Payload Too Large'],\n [414, 'URI Too Long'],\n [415, 'Unsupported Media Type'],\n [416, 'Range Not Satisfiable'],\n [417, 'Expectation Failed'],\n [419, 'Page Expired'],\n [420, 'Enhance Your Calm'],\n [421, 'Misdirected Request'],\n [422, 'Unprocessable Entity'],\n [423, 'Locked'],\n [424, 'Failed Dependency'],\n [425, 'Too Early'],\n [426, 'Upgrade Required'],\n [428, 'Precondition Required'],\n [429, 'Too Many Requests'],\n [430, 'Request Header Fields Too Large'],\n [431, 'Request Header Fields Too Large'],\n [450, 'Blocked By Windows Parental Controls'],\n [451, 'Unavailable For Legal Reasons'],\n [500, 'Internal Server Error'],\n [501, 'Not Implemented'],\n [502, 'Bad Gateway'],\n [503, 'Service Unavailable'],\n [504, 'Gateway Timeout'],\n [505, 'HTTP Version Not Supported'],\n [506, 'Variant Also Negotiates'],\n [507, 'Insufficient Storage'],\n [508, 'Loop Detected'],\n [509, 'Bandwidth Limit Exceeded'],\n [510, 'Not Extended'],\n [511, 'Network Authentication Required'],\n]);\n\n/**\n * A basic handler which converts a request into a\n * `fetch` call presuming the response to be `json`.\n *\n * ```ts\n * import Fetch from '@ember-data-mirror/request/fetch';\n *\n * manager.use([Fetch]);\n * ```\n *\n * @class Fetch\n * @public\n */\nconst Fetch = {\n async request<T>(context: Context): Promise<T> {\n let response: Response;\n\n try {\n response = await _fetch(context.request.url!, context.request);\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') {\n (e as unknown as HttpErrorProps).statusText = 'Aborted';\n (e as unknown as HttpErrorProps).status = 20;\n (e as unknown as HttpErrorProps).isRequestError = true;\n } else {\n (e as HttpErrorProps).statusText = 'Unknown Network Error';\n (e as HttpErrorProps).status = 0;\n (e as HttpErrorProps).isRequestError = true;\n }\n throw e;\n }\n\n const isError = !response.ok || response.status >= 400;\n const op = context.request.op;\n const isMutationOp = Boolean(op && MUTATION_OPS.has(op));\n\n if (!isError && !isMutationOp && response.status !== 204 && !response.headers.has('date')) {\n if (IS_MAYBE_MIRAGE()) {\n response.headers.set('date', new Date().toUTCString());\n } else {\n const headers = new Headers(response.headers);\n headers.set('date', new Date().toUTCString());\n response = cloneResponse(response, {\n headers,\n });\n }\n }\n\n context.setResponse(response);\n\n if (response.status === 204) {\n return null as T;\n }\n\n let text = '';\n // if we are in a mirage context, we cannot support streaming\n if (IS_MAYBE_MIRAGE()) {\n text = await response.text();\n } else {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let isStreaming = context.hasRequestedStream;\n let stream: TransformStream | null = isStreaming ? new TransformStream() : null;\n let writer = stream?.writable.getWriter();\n\n if (isStreaming) {\n // Listen for the abort event on the AbortSignal\n context.request.signal?.addEventListener('abort', () => {\n if (!isStreaming) {\n return;\n }\n void stream!.writable.abort('Request Aborted');\n void stream!.readable.cancel('Request Aborted');\n });\n context.setStream(stream!.readable);\n }\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n // we manually read the stream instead of using `response.json()`\n // or `response.text()` because if we need to stream the body\n // we need to be able to pass the stream along efficiently.\n const { done, value } = await reader.read();\n if (done) {\n if (isStreaming) {\n isStreaming = false;\n await writer!.ready;\n await writer!.close();\n }\n break;\n }\n text += decoder.decode(value, { stream: true });\n\n // if we are streaming, we want to pass the stream along\n if (isStreaming) {\n await writer!.ready;\n await writer!.write(value);\n } else if (context.hasRequestedStream) {\n const encode = new TextEncoder();\n isStreaming = true;\n stream = new TransformStream();\n // Listen for the abort event on the AbortSignal\n // eslint-disable-next-line @typescript-eslint/no-loop-func\n context.request.signal?.addEventListener('abort', () => {\n if (!isStreaming) {\n return;\n }\n void stream!.writable.abort('Request Aborted');\n void stream!.readable.cancel('Request Aborted');\n });\n context.setStream(stream.readable);\n writer = stream.writable.getWriter();\n await writer.ready;\n await writer.write(encode.encode(text));\n await writer.ready;\n await writer.write(value);\n }\n }\n\n if (isStreaming) {\n isStreaming = false;\n await writer!.ready;\n await writer!.close();\n }\n }\n // if we are an error, we will want to throw\n if (isError) {\n let errorPayload: object | undefined;\n try {\n errorPayload = JSON.parse(text) as object;\n } catch {\n // void;\n }\n // attempt errors discovery\n const errors = Array.isArray(errorPayload)\n ? errorPayload\n : isDict(errorPayload) && Array.isArray(errorPayload.errors)\n ? errorPayload.errors\n : null;\n\n const statusText = response.statusText || ERROR_STATUS_CODE_FOR.get(response.status) || 'Unknown Request Error';\n const msg = `[${response.status} ${statusText}] ${context.request.method ?? 'GET'} (${response.type}) - ${\n response.url\n }`;\n\n const error = (errors ? new AggregateError(errors, msg) : new Error(msg)) as Error & {\n content: object | undefined;\n } & HttpErrorProps;\n error.status = response.status;\n error.statusText = statusText;\n error.isRequestError = true;\n error.code = error.status;\n error.name = error.statusText.replaceAll(' ', '') + 'Error';\n error.content = errorPayload;\n throw error;\n } else {\n return JSON.parse(text) as T;\n }\n },\n};\n\nfunction isDict(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object';\n}\n\nexport default Fetch;\n"],"names":["_fetch","fetch","args","FastBoot","require","Error","cloneResponse","response","overrides","props","cloneResponseProperties","Response","body","Object","assign","IS_MAYBE_MIRAGE","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","Boolean","window","server","pretender","toString","replace","MUTATION_OPS","Set","ERROR_STATUS_CODE_FOR","Map","Fetch","request","context","url","e","DOMException","name","statusText","status","isRequestError","isError","ok","op","isMutationOp","has","headers","set","Date","toUTCString","Headers","setResponse","text","reader","getReader","decoder","TextDecoder","isStreaming","hasRequestedStream","stream","TransformStream","writer","writable","getWriter","signal","addEventListener","abort","readable","cancel","setStream","done","value","read","ready","close","decode","write","encode","TextEncoder","errorPayload","JSON","parse","errors","Array","isArray","isDict","get","msg","method","type","error","AggregateError","code","replaceAll","content","v"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACA,MAAMA,MAAoB,GACxB,OAAOC,KAAK,KAAK,WAAW,GACxB,CAAC,GAAGC,IAAI,KAAKD,KAAK,CAAC,GAAGC,IAAI,CAAC,GAC3B,OAAOC,QAAQ,KAAK,WAAW,GAC7B,CAAC,GAAGD,IAAI,KAAMC,QAAQ,CAACC,OAAO,CAAC,YAAY,CAAC,CAAkB,GAAGF,IAAI,CAAC,GACpE,MAAM;AACN,EAAA,MAAM,IAAIG,KAAK,CAAC,+BAA+B,CAAC,CAAA;AAClD,CAAmB,CAAA;;AAE3B;AACA;AACA,SAASC,aAAaA,CAACC,QAAkB,EAAEC,SAA4B,EAAE;AACvE,EAAA,MAAMC,KAAK,GAAGC,uBAAuB,CAACH,QAAQ,CAAC,CAAA;AAC/C,EAAA,OAAO,IAAII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E,QAAQ,CAACgC,MAAM,CAAC,IAAI,uBAAuB,CAAA;MAC/G,MAAMgD,GAAG,GAAI,CAAA,CAAA,EAAGhF,QAAQ,CAACgC,MAAO,CAAGD,CAAAA,EAAAA,UAAW,CAAIL,EAAAA,EAAAA,OAAO,CAACD,OAAO,CAACwD,MAAM,IAAI,KAAM,CAAA,EAAA,EAAIjF,QAAQ,CAACkF,IAAK,CAClGlF,IAAAA,EAAAA,QAAQ,CAAC2B,GACV,CAAC,CAAA,CAAA;AAEF,MAAA,MAAMwD,KAAK,GAAIR,MAAM,GAAG,IAAIS,cAAc,CAACT,MAAM,EAAEK,GAAG,CAAC,GAAG,IAAIlF,KAAK,CAACkF,GAAG,CAErD,CAAA;AAClBG,MAAAA,KAAK,CAACnD,MAAM,GAAGhC,QAAQ,CAACgC,MAAM,CAAA;MAC9BmD,KAAK,CAACpD,UAAU,GAAGA,UAAU,CAAA;MAC7BoD,KAAK,CAAClD,cAAc,GAAG,IAAI,CAAA;AAC3BkD,MAAAA,KAAK,CAACE,IAAI,GAAGF,KAAK,CAACnD,MAAM,CAAA;AACzBmD,MAAAA,KAAK,CAACrD,IAAI,GAAGqD,KAAK,CAACpD,UAAU,CAACuD,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,OAAO,CAAA;MAC3DH,KAAK,CAACI,OAAO,GAAGf,YAAY,CAAA;AAC5B,MAAA,MAAMW,KAAK,CAAA;AACb,KAAC,MAAM;AACL,MAAA,OAAOV,IAAI,CAACC,KAAK,CAAC7B,IAAI,CAAC,CAAA;AACzB,KAAA;AACF,GAAA;AACF,EAAC;AAED,SAASiC,MAAMA,CAACU,CAAU,EAAgC;AACxD,EAAA,OAAOA,CAAC,KAAK,IAAI,IAAI,OAAOA,CAAC,KAAK,QAAQ,CAAA;AAC5C;;;;"}
|
|
1
|
+
{"version":3,"file":"fetch.js","sources":["../src/fetch.ts"],"sourcesContent":["/**\n * A basic Fetch Handler which converts a request into a\n * `fetch` call presuming the response to be `json`.\n *\n * ```ts\n * import Fetch from '@ember-data-mirror/request/fetch';\n *\n * manager.use([Fetch]);\n * ```\n *\n * @module @ember-data-mirror/request/fetch\n * @main @ember-data-mirror/request/fetch\n */\n\nimport { DEBUG } from '@warp-drive-mirror/build-config/env';\n\nimport { cloneResponseProperties, type Context } from './-private/context';\nimport type { HttpErrorProps } from './-private/utils';\n\n// Lazily close over fetch to avoid breaking Mirage\nconst _fetch: typeof fetch =\n typeof fetch !== 'undefined'\n ? (...args) => fetch(...args)\n : typeof FastBoot !== 'undefined'\n ? (...args) => (FastBoot.require('node-fetch') as typeof fetch)(...args)\n : ((() => {\n throw new Error('No Fetch Implementation Found');\n }) as typeof fetch);\n\n// clones a response in a way that should still\n// allow it to stream\nfunction cloneResponse(response: Response, overrides: Partial<Response>) {\n const props = cloneResponseProperties(response);\n return new Response(response.body, Object.assign(props, overrides));\n}\n\nlet IS_MAYBE_MIRAGE = () => false;\nif (DEBUG) {\n IS_MAYBE_MIRAGE = () =>\n Boolean(\n typeof window !== 'undefined' &&\n ((window as { server?: { pretender: unknown } }).server?.pretender ||\n window.fetch.toString().replace(/\\s+/g, '') !== 'function fetch() { [native code] }'.replace(/\\s+/g, ''))\n );\n}\n\nconst MUTATION_OPS = new Set(['updateRecord', 'createRecord', 'deleteRecord']);\nconst ERROR_STATUS_CODE_FOR = new Map([\n [400, 'Bad Request'],\n [401, 'Unauthorized'],\n [402, 'Payment Required'],\n [403, 'Forbidden'],\n [404, 'Not Found'],\n [405, 'Method Not Allowed'],\n [406, 'Not Acceptable'],\n [407, 'Proxy Authentication Required'],\n [408, 'Request Timeout'],\n [409, 'Conflict'],\n [410, 'Gone'],\n [411, 'Length Required'],\n [412, 'Precondition Failed'],\n [413, 'Payload Too Large'],\n [414, 'URI Too Long'],\n [415, 'Unsupported Media Type'],\n [416, 'Range Not Satisfiable'],\n [417, 'Expectation Failed'],\n [419, 'Page Expired'],\n [420, 'Enhance Your Calm'],\n [421, 'Misdirected Request'],\n [422, 'Unprocessable Entity'],\n [423, 'Locked'],\n [424, 'Failed Dependency'],\n [425, 'Too Early'],\n [426, 'Upgrade Required'],\n [428, 'Precondition Required'],\n [429, 'Too Many Requests'],\n [430, 'Request Header Fields Too Large'],\n [431, 'Request Header Fields Too Large'],\n [450, 'Blocked By Windows Parental Controls'],\n [451, 'Unavailable For Legal Reasons'],\n [500, 'Internal Server Error'],\n [501, 'Not Implemented'],\n [502, 'Bad Gateway'],\n [503, 'Service Unavailable'],\n [504, 'Gateway Timeout'],\n [505, 'HTTP Version Not Supported'],\n [506, 'Variant Also Negotiates'],\n [507, 'Insufficient Storage'],\n [508, 'Loop Detected'],\n [509, 'Bandwidth Limit Exceeded'],\n [510, 'Not Extended'],\n [511, 'Network Authentication Required'],\n]);\n\n/**\n * A basic handler which converts a request into a\n * `fetch` call presuming the response to be `json`.\n *\n * ```ts\n * import Fetch from '@ember-data-mirror/request/fetch';\n *\n * manager.use([Fetch]);\n * ```\n *\n * @class Fetch\n * @public\n */\nconst Fetch = {\n async request<T>(context: Context): Promise<T> {\n let response: Response;\n\n try {\n response = await _fetch(context.request.url!, context.request);\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') {\n (e as unknown as HttpErrorProps).statusText = 'Aborted';\n (e as unknown as HttpErrorProps).status = 20;\n (e as unknown as HttpErrorProps).isRequestError = true;\n } else {\n (e as HttpErrorProps).statusText = 'Unknown Network Error';\n (e as HttpErrorProps).status = 0;\n (e as HttpErrorProps).isRequestError = true;\n }\n throw e;\n }\n\n const isError = !response.ok || response.status >= 400;\n const op = context.request.op;\n const isMutationOp = Boolean(op && MUTATION_OPS.has(op));\n\n if (!isError && !isMutationOp && response.status !== 204 && !response.headers.has('date')) {\n if (IS_MAYBE_MIRAGE()) {\n response.headers.set('date', new Date().toUTCString());\n } else {\n const headers = new Headers(response.headers);\n headers.set('date', new Date().toUTCString());\n response = cloneResponse(response, {\n headers,\n });\n }\n }\n\n context.setResponse(response);\n\n if (response.status === 204) {\n return null as T;\n }\n\n let text = '';\n // if we are in a mirage context, we cannot support streaming\n if (IS_MAYBE_MIRAGE()) {\n text = await response.text();\n } else {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let isStreaming = context.hasRequestedStream;\n let stream: TransformStream | null = isStreaming ? new TransformStream() : null;\n let writer = stream?.writable.getWriter();\n\n if (isStreaming) {\n // Listen for the abort event on the AbortSignal\n context.request.signal?.addEventListener('abort', () => {\n if (!isStreaming) {\n return;\n }\n void stream!.writable.abort('Request Aborted');\n void stream!.readable.cancel('Request Aborted');\n });\n context.setStream(stream!.readable);\n }\n\n while (true) {\n // we manually read the stream instead of using `response.json()`\n // or `response.text()` because if we need to stream the body\n // we need to be able to pass the stream along efficiently.\n const { done, value } = await reader.read();\n if (done) {\n if (isStreaming) {\n isStreaming = false;\n await writer!.ready;\n await writer!.close();\n }\n break;\n }\n text += decoder.decode(value, { stream: true });\n\n // if we are streaming, we want to pass the stream along\n if (isStreaming) {\n await writer!.ready;\n await writer!.write(value);\n } else if (context.hasRequestedStream) {\n const encode = new TextEncoder();\n isStreaming = true;\n stream = new TransformStream();\n // Listen for the abort event on the AbortSignal\n // eslint-disable-next-line @typescript-eslint/no-loop-func\n context.request.signal?.addEventListener('abort', () => {\n if (!isStreaming) {\n return;\n }\n void stream!.writable.abort('Request Aborted');\n void stream!.readable.cancel('Request Aborted');\n });\n context.setStream(stream.readable);\n writer = stream.writable.getWriter();\n await writer.ready;\n await writer.write(encode.encode(text));\n await writer.ready;\n await writer.write(value);\n }\n }\n\n if (isStreaming) {\n isStreaming = false;\n await writer!.ready;\n await writer!.close();\n }\n }\n // if we are an error, we will want to throw\n if (isError) {\n let errorPayload: object | undefined;\n try {\n errorPayload = JSON.parse(text) as object;\n } catch {\n // void;\n }\n // attempt errors discovery\n const errors = Array.isArray(errorPayload)\n ? errorPayload\n : isDict(errorPayload) && Array.isArray(errorPayload.errors)\n ? errorPayload.errors\n : null;\n\n const statusText = response.statusText || ERROR_STATUS_CODE_FOR.get(response.status) || 'Unknown Request Error';\n const msg = `[${response.status} ${statusText}] ${context.request.method ?? 'GET'} (${response.type}) - ${\n response.url\n }`;\n\n const error = (errors ? new AggregateError(errors, msg) : new Error(msg)) as Error & {\n content: object | undefined;\n } & HttpErrorProps;\n error.status = response.status;\n error.statusText = statusText;\n error.isRequestError = true;\n error.code = error.status;\n error.name = error.statusText.replaceAll(' ', '') + 'Error';\n error.content = errorPayload;\n throw error;\n } else {\n return JSON.parse(text) as T;\n }\n },\n};\n\nfunction isDict(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object';\n}\n\nexport default Fetch;\n"],"names":["_fetch","fetch","args","FastBoot","require","Error","cloneResponse","response","overrides","props","cloneResponseProperties","Response","body","Object","assign","IS_MAYBE_MIRAGE","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","Boolean","window","server","pretender","toString","replace","MUTATION_OPS","Set","ERROR_STATUS_CODE_FOR","Map","Fetch","request","context","url","e","DOMException","name","statusText","status","isRequestError","isError","ok","op","isMutationOp","has","headers","set","Date","toUTCString","Headers","setResponse","text","reader","getReader","decoder","TextDecoder","isStreaming","hasRequestedStream","stream","TransformStream","writer","writable","getWriter","signal","addEventListener","abort","readable","cancel","setStream","done","value","read","ready","close","decode","write","encode","TextEncoder","errorPayload","JSON","parse","errors","Array","isArray","isDict","get","msg","method","type","error","AggregateError","code","replaceAll","content","v"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACA,MAAMA,MAAoB,GACxB,OAAOC,KAAK,KAAK,WAAW,GACxB,CAAC,GAAGC,IAAI,KAAKD,KAAK,CAAC,GAAGC,IAAI,CAAC,GAC3B,OAAOC,QAAQ,KAAK,WAAW,GAC7B,CAAC,GAAGD,IAAI,KAAMC,QAAQ,CAACC,OAAO,CAAC,YAAY,CAAC,CAAkB,GAAGF,IAAI,CAAC,GACpE,MAAM;AACN,EAAA,MAAM,IAAIG,KAAK,C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,EAAA,OAAOA,CAAC,KAAK,IAAI,IAAI,OAAOA,CAAC,KAAK,QAAQ,CAAA;AAC5C;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';
|
|
2
2
|
import { peekUniversalTransient, setUniversalTransient } from '@warp-drive-mirror/core-types/-private';
|
|
3
|
-
import { I as IS_CACHE_HANDLER, a as assertValidRequest, e as executeNextHandler, g as getRequestResult, u as upgradePromise, s as setPromiseResult, c as clearRequestResult } from "./debug-
|
|
4
|
-
export { b as createDeferred, d as getPromiseResult } from "./debug-
|
|
3
|
+
import { I as IS_CACHE_HANDLER, a as assertValidRequest, e as executeNextHandler, g as getRequestResult, u as upgradePromise, s as setPromiseResult, c as clearRequestResult } from "./debug-D0st-bv4.js";
|
|
4
|
+
export { b as createDeferred, d as getPromiseResult } from "./debug-D0st-bv4.js";
|
|
5
5
|
|
|
6
6
|
/* eslint-disable no-irregular-whitespace */
|
|
7
7
|
/**
|
|
@@ -464,8 +464,7 @@ For usage of the store's `requestManager` via `store.request(<req>)` see the
|
|
|
464
464
|
* const { apiUrl } = Config;
|
|
465
465
|
*
|
|
466
466
|
* // ... create manager
|
|
467
|
-
* const manager = new RequestManager();
|
|
468
|
-
* manager.use([Auth, Fetch]);
|
|
467
|
+
* const manager = new RequestManager().use([Auth, Fetch]);
|
|
469
468
|
*
|
|
470
469
|
* // ... execute a request
|
|
471
470
|
* const response = await manager.request({
|
|
@@ -516,9 +515,20 @@ For usage of the store's `requestManager` via `store.request(<req>)` see the
|
|
|
516
515
|
*/
|
|
517
516
|
class RequestManager {
|
|
518
517
|
#handlers = [];
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* A map of pending requests from request.id to their
|
|
521
|
+
* associated CacheHandler promise.
|
|
522
|
+
*
|
|
523
|
+
* This queue is managed by the CacheHandler
|
|
524
|
+
*
|
|
525
|
+
* @internal
|
|
526
|
+
*/
|
|
527
|
+
|
|
519
528
|
constructor(options) {
|
|
520
529
|
Object.assign(this, options);
|
|
521
530
|
this._pending = new Map();
|
|
531
|
+
this._deduped = new Map();
|
|
522
532
|
}
|
|
523
533
|
|
|
524
534
|
/**
|
|
@@ -531,10 +541,10 @@ class RequestManager {
|
|
|
531
541
|
* @method useCache
|
|
532
542
|
* @public
|
|
533
543
|
* @param {Handler[]} cacheHandler
|
|
534
|
-
* @return {
|
|
544
|
+
* @return {ThisType}
|
|
535
545
|
*/
|
|
536
546
|
useCache(cacheHandler) {
|
|
537
|
-
if (macroCondition(getGlobalConfig().
|
|
547
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
538
548
|
if (this._hasCacheHandler) {
|
|
539
549
|
throw new Error(`\`RequestManager.useCache(<handler>)\` May only be invoked once.`);
|
|
540
550
|
}
|
|
@@ -545,6 +555,7 @@ class RequestManager {
|
|
|
545
555
|
}
|
|
546
556
|
cacheHandler[IS_CACHE_HANDLER] = true;
|
|
547
557
|
this.#handlers.unshift(cacheHandler);
|
|
558
|
+
return this;
|
|
548
559
|
}
|
|
549
560
|
|
|
550
561
|
/**
|
|
@@ -557,11 +568,11 @@ class RequestManager {
|
|
|
557
568
|
* @method use
|
|
558
569
|
* @public
|
|
559
570
|
* @param {Handler[]} newHandlers
|
|
560
|
-
* @return {
|
|
571
|
+
* @return {ThisType}
|
|
561
572
|
*/
|
|
562
573
|
use(newHandlers) {
|
|
563
574
|
const handlers = this.#handlers;
|
|
564
|
-
if (macroCondition(getGlobalConfig().
|
|
575
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
565
576
|
if (Object.isFrozen(handlers)) {
|
|
566
577
|
throw new Error(`Cannot add a Handler to a RequestManager after a request has been made`);
|
|
567
578
|
}
|
|
@@ -575,6 +586,7 @@ class RequestManager {
|
|
|
575
586
|
});
|
|
576
587
|
}
|
|
577
588
|
handlers.push(...newHandlers);
|
|
589
|
+
return this;
|
|
578
590
|
}
|
|
579
591
|
|
|
580
592
|
/**
|
|
@@ -589,7 +601,7 @@ class RequestManager {
|
|
|
589
601
|
*/
|
|
590
602
|
request(request) {
|
|
591
603
|
const handlers = this.#handlers;
|
|
592
|
-
if (macroCondition(getGlobalConfig().
|
|
604
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
593
605
|
if (!Object.isFrozen(handlers)) {
|
|
594
606
|
Object.freeze(handlers);
|
|
595
607
|
}
|
|
@@ -601,18 +613,20 @@ class RequestManager {
|
|
|
601
613
|
}
|
|
602
614
|
const requestId = peekUniversalTransient('REQ_ID') ?? 0;
|
|
603
615
|
setUniversalTransient('REQ_ID', requestId + 1);
|
|
604
|
-
const
|
|
616
|
+
const context = {
|
|
605
617
|
controller,
|
|
606
618
|
response: null,
|
|
607
619
|
stream: null,
|
|
608
620
|
hasRequestedStream: false,
|
|
609
|
-
id: requestId
|
|
610
|
-
|
|
621
|
+
id: requestId,
|
|
622
|
+
identifier: null
|
|
623
|
+
};
|
|
624
|
+
const promise = executeNextHandler(handlers, request, 0, context);
|
|
611
625
|
|
|
612
626
|
// the cache handler will set the result of the request synchronously
|
|
613
627
|
// if it is able to fulfill the request from the cache
|
|
614
628
|
const cacheResult = getRequestResult(requestId);
|
|
615
|
-
if (macroCondition(getGlobalConfig().
|
|
629
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
|
|
616
630
|
if (!request.disableTestWaiter) {
|
|
617
631
|
const {
|
|
618
632
|
waitForPromise
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/-private/manager.ts"],"sourcesContent":["/* eslint-disable no-irregular-whitespace */\n/**\n *\n <p align=\"center\">\n <img\n class=\"project-logo\"\n src=\"https://raw.githubusercontent.com/emberjs/data/4612c9354e4c54d53327ec2cf21955075ce21294/ember-data-logo-light.svg#gh-light-mode-only\"\n alt=\"EmberData RequestManager\"\n width=\"240px\"\n title=\"EmberData RequestManager\"\n />\n</p>\n\n<p align=\"center\">⚡️ a simple abstraction over fetch to enable easy management of request/response flows</p>\n\nThis 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.\n\n- [Installation](#installation)\n- [Basic Usage](#🚀-basic-usage)\n- [Architecture](#🪜-architecture)\n- [Usage](#usage)\n - [Making Requests](#making-requests)\n - [Using The Response](#using-the-response)\n - [Request Handlers](#handling-requests)\n - [Handling Errors](#handling-errors)\n - [Handling Abort](#handling-abort)\n - [Stream Currying](#stream-currying)\n - [Automatic Currying](#automatic-currying-of-stream-and-response)\n - [Using as a Service](#using-as-a-service)\n - [Using with `@ember-data-mirror/store`](#using-with-ember-datastore)\n - [Using with `ember-data`](#using-with-ember-data)\n\n---\n\n## Installation\n\nInstall using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)\n\n```no-highlight\npnpm add @ember-data-mirror/request\n```\n\n---\n\n## 🚀 Basic Usage\n\nA `RequestManager` provides a request/response flow in which configured handlers are successively given the opportunity to handle, modify, or pass-along a request.\n\nThe 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`.\n\n```ts\nimport RequestManager from '@ember-data-mirror/request';\nimport Fetch from '@ember-data-mirror/request/fetch';\nimport { apiUrl } from './config';\n\n// ... create manager and add our Fetch handler\nconst manager = new RequestManager();\nmanager.use([Fetch]);\n\n// ... execute a request\nconst response = await manager.request({\n url: `${apiUrl}/users`\n});\n```\n\n---\n\n## 🪜 Architecture\n\nA `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.\n\nEach handler may choose to fulfill the request using some source of data or to pass the request along to other handlers.\n\nThe 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)\n\nWhen 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\nand return hydrated responses, requests issued directly to the RequestManager\nwill skip the in-memory cache and return raw responses.\n\n---\n\n## Usage\n\n```ts\nconst userList = await manager.request({\n url: `/api/v1/users.list`\n});\n\nconst users = userList.content;\n```\n\n---\n\n### Making Requests\n\n`RequestManager` has a single asyncronous method as it's API: `request`\n\n```ts\nclass RequestManager {\n request<T>(req: RequestInfo): Future<T>;\n}\n```\n\n`manager.request(<RequestInfo>)` accepts an object containing the information\nnecessary for the request to be handled successfully.\n\nThese 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.\n\n```ts\ninterface RequestInfo extends FetchOptions {\n op?: string;\n store?: Store;\n\n url: string;\n // data that a handler should convert into\n // the query (GET) or body (POST)\n data?: Record<string, unknown>;\n\n // options specifically intended for handlers\n // to utilize to process the request\n options?: Record<string, unknown>;\n}\n```\n\n> **note**\n> providing a `signal` is unnecessary as an `AbortController` is automatically provided if none is present.\n\n---\n\n#### Using the Response\n\n`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.\n\n```ts\nconst usersFuture = manager.request({\n url: `/api/v1/users.list`\n});\n```\n\nA `Future` is cancellable via `abort`.\n\n```ts\nusersFuture.abort();\n```\n\nHandlers 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.\n\n```ts\ninterface Future<T> extends Promise<StructuredDocument<T>> {\n abort(): void;\n\n async getStream(): ReadableStream | null;\n}\n```\n\nA Future resolves or rejects with a `StructuredDocument`.\n\n```ts\ninterface StructuredDocument<T> {\n request: RequestInfo;\n response: ResponseInfo | null;\n content?: T;\n error?: Error;\n}\n```\n\nThe `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.\n\nThe `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`.\n\n```ts\ninterface ResponseInfo {\n headers?: Record<string, string>;\n ok?: boolean;\n redirected?: boolean;\n status?: HTTPStatusCode;\n statusText?: string;\n type?: 'basic' | 'cors';\n url?: string;\n}\n```\n\n---\n\n### Request Handlers\n\nRequests are fulfilled by handlers. A handler receives the request context\nas well as a `next` function with which to pass along a request to the next\nhandler if it so chooses.\n\nA handler may be any object with a `request` method. This allows both stateful and non-stateful\nhandlers to be utilized.\n\nIf a handler calls `next`, it receives a `Future` which resolves to a `StructuredDocument`\nthat it can then compose how it sees fit with its own response.\n\n```ts\n\ntype NextFn<P> = (req: RequestInfo) => Future<P>;\n\ninterface Handler {\n async request<T>(context: RequestContext, next: NextFn<P>): T;\n}\n```\n\n`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.\n\n```ts\ninterface RequestContext<T> {\n readonly request: RequestInfo;\n\n setStream(stream: ReadableStream | Promise<ReadableStream>): void;\n setResponse(response: Response | ResponseInfo): void;\n}\n```\n\nA basic `fetch` handler with support for streaming content updates while\nthe download is still underway might look like the following, where we use\n[`response.clone()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/clone) to `tee` the `ReadableStream` into two streams.\n\nA more efficient handler might read from the response stream, building up the\nresponse content before passing along the chunk downstream.\n\n```ts\nconst FetchHandler = {\n async request(context) {\n const response = await fetch(context.request);\n context.setResponse(reponse);\n context.setStream(response.clone().body);\n\n return response.json();\n }\n}\n```\n\nRequest handlers are registered by configuring the manager via `use`\n\n```ts\nmanager.use([Handler1, Handler2])\n```\n\nHandlers 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.\n\n---\n\n#### Handling Errors\n\nEach handler in the chain can catch errors from upstream and choose to\neither handle the error, re-throw the error, or throw a new error.\n\n```ts\nconst MAX_RETRIES = 5;\n\nconst Handler = {\n async request(context, next) {\n let attempts = 0;\n\n while (attempts < MAX_RETRIES) {\n attempts++;\n try {\n const response = await next(context.request);\n return response;\n } catch (e) {\n if (isTimeoutError(e) && attempts < MAX_RETRIES) {\n // retry request\n continue;\n }\n // rethrow if it is not a timeout error\n throw e;\n }\n }\n }\n}\n```\n\n---\n\n#### Handling Abort\n\nAborting a request will reject the current handler in the chain. However,\nevery handler can potentially catch this error. If your handler needs to\nseparate AbortError from other Error types, it is recommended to check\n`context.request.signal.aborted` (or if a custom controller was supplied `controller.signal.aborted`).\n\nIn this manner it is possible for a request to recover from an abort and\nstill proceed; however, as a best practice this should be used for necessary\ncleanup only and the original AbortError rethrown if the abort signal comes\nfrom the root controller.\n\n**AbortControllers are Always Present and Always Entangled**\n\nIf the initial request does not supply an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController), one will be generated.\n\nThe [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.\n\nEach 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\nentangled with the root controller. If the root controller aborts, so will\nany entangled controllers.\n\nIf an entangled controller aborts, the root controller will not abort. This\nallows for advanced request-flow scenarios to abort subsections of the request tree without aborting the entire request.\n\n---\n\n#### Stream Currying\n\n`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.\n\nFor context, it helps to understand a few of the use-cases that RequestManager\nis intended to allow.\n\n- to manage and return streaming content (such as video files)\n- to fulfill a request from multiple sources or by splitting one request into multiple requests\n - for instance one API call for a user and another for the user's friends\n - or e.g. fulfilling part of the request from one source (one API, in-memory, localStorage, IndexedDB\n etc.) and the rest from another source (a different API, a WebWorker, etc.)\n- to coalesce multiple requests\n- to decorate a request with additional info\n - e.g. an Auth handler that ensures the correct tokens or headers or cookies are attached.\n\n\n`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\ncode *while chunks are still being received by the browser*.\n\nWhen 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**.\n\nThe `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.\n\nEach 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\nhas not been called by the time that the handler's request method has resolved.\n\nHandlers 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.\n\n```ts\ncontext.setStream(future.getStream());\n```\n\nHandlers 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.\n\nOf course, any handler may choose to read and handle the stream, and return either no stream or a different stream in the process.\n\n---\n\n#### Automatic Currying of Stream and Response\n\nIn 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;`.\n\nSimilarly, 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.\n\nFinally, 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>)`.\n\nIn the case of the `Future` being returned, `Stream` proxying is automatic and immediate and does not wait for the `Future` to resolve.\n\n---\n\n### Using as a Service\n\nMost 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/).\n\n*services/request.ts*\n```ts\nimport RequestManager from '@ember-data-mirror/request';\nimport Fetch from '@ember-data-mirror/request/fetch';\nimport Auth from 'ember-simple-auth/ember-data-handler';\n\nexport default class extends RequestManager {\n constructor(createArgs) {\n super(createArgs);\n this.use([Auth, Fetch]);\n }\n}\n```\n\n---\n\n#### Using with `@ember-data-mirror/store`\n\nTo have a request service unique to a Store:\n\n```ts\nimport Store, { CacheHandler } from '@ember-data-mirror/store';\nimport RequestManager from '@ember-data-mirror/request';\nimport Fetch from '@ember-data-mirror/request/fetch';\n\nclass extends Store {\n requestManager = new RequestManager();\n\n constructor(args) {\n super(args);\n this.requestManager.use([Fetch]);\n this.requestManager.useCache(CacheHandler);\n }\n}\n```\n\n---\n\n#### Using with `ember-data`\n\nIf using the package [ember-data](https://github.com/emberjs/data/tree/main/packages/-ember-data),\nthe following configuration will automatically be done in order to preserve the\nlegacy [Adapter](https://github.com/emberjs/data/tree/main/packages/adapter) and\n[Serializer](https://github.com/emberjs/data/tree/main/packages/serializer) behavior.\nAdditional handlers or a service injection like the above would need to be done by the\nconsuming application in order to make broader use of `RequestManager`.\n\n```ts\nimport Store, { CacheHandler } from 'ember-data-mirror/store';\nimport RequestManager from '@ember-data-mirror/request';\nimport Fetch from '@ember-data-mirror/request/fetch';\nimport { LegacyNetworkHandler } from '@ember-data-mirror/legacy-compat';\n\nexport default class extends Store {\n requestManager = new RequestManager();\n\n constructor(args) {\n super(args);\n this.requestManager.use([LegacyNetworkHandler, Fetch]);\n this.requestManager.useCache(CacheHandler);\n }\n}\n```\n\nTo provide a different configuration, import and extend `ember-data/store`. The\ndefault configuration will be ignored if the `requestManager` property is set,\nthough the store will still register the CacheHandler.\n\nFor usage of the store's `requestManager` via `store.request(<req>)` see the\n[Store](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fstore) documentation.\n\n *\n * @module @ember-data-mirror/request\n * @main @ember-data-mirror/request\n */\nimport { importSync } from '@embroider/macros';\n\nimport { DEBUG, TESTING } from '@warp-drive-mirror/build-config/env';\nimport { peekUniversalTransient, setUniversalTransient } from '@warp-drive-mirror/core-types/-private';\nimport type { RequestInfo, StructuredErrorDocument } from '@warp-drive-mirror/core-types/request';\n\nimport { assertValidRequest } from './debug';\nimport { upgradePromise } from './future';\nimport { clearRequestResult, getRequestResult, setPromiseResult } from './promise-cache';\nimport type { CacheHandler, Future, GenericCreateArgs, Handler } from './types';\nimport { executeNextHandler, IS_CACHE_HANDLER } from './utils';\n\n/**\n * ```js\n * import RequestManager from '@ember-data-mirror/request';\n * ```\n *\n * A RequestManager provides a request/response flow in which configured\n * handlers are successively given the opportunity to handle, modify, or\n * pass-along a request.\n *\n * ```ts\n * interface RequestManager {\n * request<T>(req: RequestInfo): Future<T>;\n * }\n * ```\n *\n * For example:\n *\n * ```ts\n * import RequestManager from '@ember-data-mirror/request';\n * import Fetch from '@ember-data-mirror/request/fetch';\n * import Auth from 'ember-simple-auth/ember-data-handler';\n * import Config from './config';\n *\n * const { apiUrl } = Config;\n *\n * // ... create manager\n * const manager = new RequestManager();\n * manager.use([Auth, Fetch]);\n *\n * // ... execute a request\n * const response = await manager.request({\n * url: `${apiUrl}/users`\n * });\n * ```\n *\n * ### Futures\n *\n * The return value of `manager.request` is a `Future`, which allows\n * access to limited information about the request while it is still\n * pending and fulfills with the final state when the request completes.\n *\n * A `Future` is cancellable via `abort`.\n *\n * Handlers may optionally expose a `ReadableStream` to the `Future` for\n * streaming data; however, when doing so the future should not resolve\n * until the response stream is fully read.\n *\n * ```ts\n * interface Future<T> extends Promise<StructuredDocument<T>> {\n * abort(): void;\n *\n * async getStream(): ReadableStream | null;\n * }\n * ```\n *\n * ### StructuredDocuments\n *\n * A Future resolves with a `StructuredDataDocument` or rejects with a `StructuredErrorDocument`.\n *\n * ```ts\n * interface StructuredDataDocument<T> {\n * request: ImmutableRequestInfo;\n * response: ImmutableResponseInfo;\n * content: T;\n * }\n * interface StructuredErrorDocument extends Error {\n * request: ImmutableRequestInfo;\n * response: ImmutableResponseInfo;\n * error: string | object;\n * }\n * type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;\n * ```\n *\n * @class RequestManager\n * @public\n */\nexport class RequestManager {\n #handlers: Handler[] = [];\n declare _hasCacheHandler: boolean;\n declare _pending: Map<number, Promise<unknown>>;\n\n constructor(options?: GenericCreateArgs) {\n Object.assign(this, options);\n this._pending = new Map();\n }\n\n /**\n * Register a handler to use for primary cache intercept.\n *\n * Only one such handler may exist. If using the same\n * RequestManager as the Store instance the Store\n * registers itself as a Cache handler.\n *\n * @method useCache\n * @public\n * @param {Handler[]} cacheHandler\n * @return {void}\n */\n useCache(cacheHandler: CacheHandler & { [IS_CACHE_HANDLER]?: true }): void {\n if (DEBUG) {\n if (this._hasCacheHandler) {\n throw new Error(`\\`RequestManager.useCache(<handler>)\\` May only be invoked once.`);\n }\n if (Object.isFrozen(this.#handlers)) {\n throw new Error(\n `\\`RequestManager.useCache(<handler>)\\` May only be invoked prior to any request having been made.`\n );\n }\n this._hasCacheHandler = true;\n }\n cacheHandler[IS_CACHE_HANDLER] = true;\n this.#handlers.unshift(cacheHandler as Handler);\n }\n\n /**\n * Register handler(s) to use when a request is issued.\n *\n * Handlers will be invoked in the order they are registered.\n * Each Handler is given the opportunity to handle the request,\n * curry the request, or pass along a modified request.\n *\n * @method use\n * @public\n * @param {Handler[]} newHandlers\n * @return {void}\n */\n use(newHandlers: Handler[]): void {\n const handlers = this.#handlers;\n if (DEBUG) {\n if (Object.isFrozen(handlers)) {\n throw new Error(`Cannot add a Handler to a RequestManager after a request has been made`);\n }\n if (!Array.isArray(newHandlers)) {\n throw new Error(\n `\\`RequestManager.use(<Handler[]>)\\` expects an array of handlers, but was called with \\`${typeof newHandlers}\\``\n );\n }\n newHandlers.forEach((handler, index) => {\n if (!handler || typeof handler !== 'object' || typeof handler.request !== 'function') {\n throw new Error(\n `\\`RequestManager.use(<Handler[]>)\\` expected to receive an array of handler objects with request methods, by the handler at index ${index} does not conform.`\n );\n }\n });\n }\n handlers.push(...newHandlers);\n }\n\n /**\n * Issue a Request.\n *\n * Returns a Future that fulfills with a StructuredDocument\n *\n * @method request\n * @public\n * @param {RequestInfo} request\n * @return {Future}\n */\n request<RT, T = unknown>(request: RequestInfo<T, RT>): Future<RT> {\n const handlers = this.#handlers;\n if (DEBUG) {\n if (!Object.isFrozen(handlers)) {\n Object.freeze(handlers);\n }\n assertValidRequest(request, true);\n }\n\n const controller = request.controller || new AbortController();\n if (request.controller) {\n delete request.controller;\n }\n\n const requestId = peekUniversalTransient<number>('REQ_ID') ?? 0;\n setUniversalTransient('REQ_ID', requestId + 1);\n\n const promise = executeNextHandler<RT>(handlers, request, 0, {\n controller,\n response: null,\n stream: null,\n hasRequestedStream: false,\n id: requestId,\n });\n\n // the cache handler will set the result of the request synchronously\n // if it is able to fulfill the request from the cache\n const cacheResult = getRequestResult(requestId);\n\n if (TESTING) {\n if (!request.disableTestWaiter) {\n const { waitForPromise } = importSync('@ember/test-waiters') as {\n waitForPromise: <PT>(promise: Promise<PT>) => Promise<PT>;\n };\n const newPromise = waitForPromise(promise);\n const finalPromise = upgradePromise(\n newPromise.then(\n (result) => {\n setPromiseResult(finalPromise, { isError: false, result });\n clearRequestResult(requestId);\n return result;\n },\n (error: StructuredErrorDocument) => {\n setPromiseResult(finalPromise, { isError: true, result: error });\n clearRequestResult(requestId);\n throw error;\n }\n ),\n promise\n );\n\n if (cacheResult) {\n setPromiseResult(finalPromise, cacheResult);\n }\n\n return finalPromise;\n }\n }\n\n // const promise1 = store.request(myRequest);\n // const promise2 = store.request(myRequest);\n // promise1 === promise2; // false\n // either we need to make promise1 === promise2, or we need to make sure that\n // we need to have a way to key from request to result\n // such that we can lookup the result here and return it if it exists\n const finalPromise = upgradePromise(\n promise.then(\n (result) => {\n setPromiseResult(finalPromise, { isError: false, result });\n clearRequestResult(requestId);\n return result;\n },\n (error: StructuredErrorDocument) => {\n setPromiseResult(finalPromise, { isError: true, result: error });\n clearRequestResult(requestId);\n throw error;\n }\n ),\n promise\n );\n\n if (cacheResult) {\n setPromiseResult(finalPromise, cacheResult);\n }\n\n return finalPromise;\n }\n\n static create(options?: GenericCreateArgs) {\n return new this(options);\n }\n}\n"],"names":["RequestManager","constructor","options","Object","assign","_pending","Map","useCache","cacheHandler","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","_hasCacheHandler","Error","isFrozen","IS_CACHE_HANDLER","unshift","use","newHandlers","handlers","Array","isArray","forEach","handler","index","request","push","freeze","assertValidRequest","controller","AbortController","requestId","peekUniversalTransient","setUniversalTransient","promise","executeNextHandler","response","stream","hasRequestedStream","id","cacheResult","getRequestResult","TESTING","disableTestWaiter","waitForPromise","importSync","newPromise","finalPromise","upgradePromise","then","result","setPromiseResult","isError","clearRequestResult","error","create"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc,CAAC;EAC1B,SAAS,GAAc,EAAE,CAAA;EAIzBC,WAAWA,CAACC,OAA2B,EAAE;AACvCC,IAAAA,MAAM,CAACC,MAAM,CAAC,IAAI,EAAEF,OAAO,CAAC,CAAA;AAC5B,IAAA,IAAI,CAACG,QAAQ,GAAG,IAAIC,GAAG,EAAE,CAAA;AAC3B,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,QAAQA,CAACC,YAA0D,EAAQ;IACzE,IAAAC,cAAA,CAAAC,eAAA,EAAA,CAAAC,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAW,EAAA;MACT,IAAI,IAAI,CAACC,gBAAgB,EAAE;AACzB,QAAA,MAAM,IAAIC,KAAK,CAAE,CAAA,gEAAA,CAAiE,CAAC,CAAA;AACrF,OAAA;MACA,IAAIZ,MAAM,CAACa,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACnC,QAAA,MAAM,IAAID,KAAK,CACZ,CAAA,iGAAA,CACH,CAAC,CAAA;AACH,OAAA;MACA,IAAI,CAACD,gBAAgB,GAAG,IAAI,CAAA;AAC9B,KAAA;AAC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ED,IAAA,IAAIM,WAAW,EAAE;AACfW,MAAAA,gBAAgB,CAACJ,YAAY,EAAEP,WAAW,CAAC,CAAA;AAC7C,KAAA;AAEA,IAAA,OAAOO,YAAY,CAAA;AACrB,GAAA;EAEA,OAAOQ,MAAMA,CAACvD,OAA2B,EAAE;AACzC,IAAA,OAAO,IAAI,IAAI,CAACA,OAAO,CAAC,CAAA;AAC1B,GAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/-private/manager.ts"],"sourcesContent":["/* eslint-disable no-irregular-whitespace */\n/**\n *\n <p align=\"center\">\n <img\n class=\"project-logo\"\n src=\"https://raw.githubusercontent.com/emberjs/data/4612c9354e4c54d53327ec2cf21955075ce21294/ember-data-logo-light.svg#gh-light-mode-only\"\n alt=\"EmberData RequestManager\"\n width=\"240px\"\n title=\"EmberData RequestManager\"\n />\n</p>\n\n<p align=\"center\">⚡️ a simple abstraction over fetch to enable easy management of request/response flows</p>\n\nThis 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.\n\n- [Installation](#installation)\n- [Basic Usage](#🚀-basic-usage)\n- [Architecture](#🪜-architecture)\n- [Usage](#usage)\n - [Making Requests](#making-requests)\n - [Using The Response](#using-the-response)\n - [Request Handlers](#handling-requests)\n - [Handling Errors](#handling-errors)\n - [Handling Abort](#handling-abort)\n - [Stream Currying](#stream-currying)\n - [Automatic Currying](#automatic-currying-of-stream-and-response)\n - [Using as a Service](#using-as-a-service)\n - [Using with `@ember-data-mirror/store`](#using-with-ember-datastore)\n - [Using with `ember-data`](#using-with-ember-data)\n\n---\n\n## Installation\n\nInstall using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)\n\n```no-highlight\npnpm add @ember-data-mirror/request\n```\n\n---\n\n## 🚀 Basic Usage\n\nA `RequestManager` provides a request/response flow in which configured handlers are successively given the opportunity to handle, modify, or pass-along a request.\n\nThe 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`.\n\n```ts\nimport RequestManager from '@ember-data-mirror/request';\nimport Fetch from '@ember-data-mirror/request/fetch';\nimport { apiUrl } from './config';\n\n// ... create manager and add our Fetch handler\nconst manager = new RequestManager();\nmanager.use([Fetch]);\n\n// ... execute a request\nconst response = await manager.request({\n url: `${apiUrl}/users`\n});\n```\n\n---\n\n## 🪜 Architecture\n\nA `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.\n\nEach handler may choose to fulfill the request using some source of data or to pass the request along to other handlers.\n\nThe 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)\n\nWhen 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\nand return hydrated responses, requests issued directly to the RequestManager\nwill skip the in-memory cache and return raw responses.\n\n---\n\n## Usage\n\n```ts\nconst userList = await manager.request({\n url: `/api/v1/users.list`\n});\n\nconst users = userList.content;\n```\n\n---\n\n### Making Requests\n\n`RequestManager` has a single asyncronous method as it's API: `request`\n\n```ts\nclass RequestManager {\n request<T>(req: RequestInfo): Future<T>;\n}\n```\n\n`manager.request(<RequestInfo>)` accepts an object containing the information\nnecessary for the request to be handled successfully.\n\nThese 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.\n\n```ts\ninterface RequestInfo extends FetchOptions {\n op?: string;\n store?: Store;\n\n url: string;\n // data that a handler should convert into\n // the query (GET) or body (POST)\n data?: Record<string, unknown>;\n\n // options specifically intended for handlers\n // to utilize to process the request\n options?: Record<string, unknown>;\n}\n```\n\n> **note**\n> providing a `signal` is unnecessary as an `AbortController` is automatically provided if none is present.\n\n---\n\n#### Using the Response\n\n`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.\n\n```ts\nconst usersFuture = manager.request({\n url: `/api/v1/users.list`\n});\n```\n\nA `Future` is cancellable via `abort`.\n\n```ts\nusersFuture.abort();\n```\n\nHandlers 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.\n\n```ts\ninterface Future<T> extends Promise<StructuredDocument<T>> {\n abort(): void;\n\n async getStream(): ReadableStream | null;\n}\n```\n\nA Future resolves or rejects with a `StructuredDocument`.\n\n```ts\ninterface StructuredDocument<T> {\n request: RequestInfo;\n response: ResponseInfo | null;\n content?: T;\n error?: Error;\n}\n```\n\nThe `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.\n\nThe `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`.\n\n```ts\ninterface ResponseInfo {\n headers?: Record<string, string>;\n ok?: boolean;\n redirected?: boolean;\n status?: HTTPStatusCode;\n statusText?: string;\n type?: 'basic' | 'cors';\n url?: string;\n}\n```\n\n---\n\n### Request Handlers\n\nRequests are fulfilled by handlers. A handler receives the request context\nas well as a `next` function with which to pass along a request to the next\nhandler if it so chooses.\n\nA handler may be any object with a `request` method. This allows both stateful and non-stateful\nhandlers to be utilized.\n\nIf a handler calls `next`, it receives a `Future` which resolves to a `StructuredDocument`\nthat it can then compose how it sees fit with its own response.\n\n```ts\n\ntype NextFn<P> = (req: RequestInfo) => Future<P>;\n\ninterface Handler {\n async request<T>(context: RequestContext, next: NextFn<P>): T;\n}\n```\n\n`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.\n\n```ts\ninterface RequestContext<T> {\n readonly request: RequestInfo;\n\n setStream(stream: ReadableStream | Promise<ReadableStream>): void;\n setResponse(response: Response | ResponseInfo): void;\n}\n```\n\nA basic `fetch` handler with support for streaming content updates while\nthe download is still underway might look like the following, where we use\n[`response.clone()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/clone) to `tee` the `ReadableStream` into two streams.\n\nA more efficient handler might read from the response stream, building up the\nresponse content before passing along the chunk downstream.\n\n```ts\nconst FetchHandler = {\n async request(context) {\n const response = await fetch(context.request);\n context.setResponse(reponse);\n context.setStream(response.clone().body);\n\n return response.json();\n }\n}\n```\n\nRequest handlers are registered by configuring the manager via `use`\n\n```ts\nmanager.use([Handler1, Handler2])\n```\n\nHandlers 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.\n\n---\n\n#### Handling Errors\n\nEach handler in the chain can catch errors from upstream and choose to\neither handle the error, re-throw the error, or throw a new error.\n\n```ts\nconst MAX_RETRIES = 5;\n\nconst Handler = {\n async request(context, next) {\n let attempts = 0;\n\n while (attempts < MAX_RETRIES) {\n attempts++;\n try {\n const response = await next(context.request);\n return response;\n } catch (e) {\n if (isTimeoutError(e) && attempts < MAX_RETRIES) {\n // retry request\n continue;\n }\n // rethrow if it is not a timeout error\n throw e;\n }\n }\n }\n}\n```\n\n---\n\n#### Handling Abort\n\nAborting a request will reject the current handler in the chain. However,\nevery handler can potentially catch this error. If your handler needs to\nseparate AbortError from other Error types, it is recommended to check\n`context.request.signal.aborted` (or if a custom controller was supplied `controller.signal.aborted`).\n\nIn this manner it is possible for a request to recover from an abort and\nstill proceed; however, as a best practice this should be used for necessary\ncleanup only and the original AbortError rethrown if the abort signal comes\nfrom the root controller.\n\n**AbortControllers are Always Present and Always Entangled**\n\nIf the initial request does not supply an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController), one will be generated.\n\nThe [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.\n\nEach 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\nentangled with the root controller. If the root controller aborts, so will\nany entangled controllers.\n\nIf an entangled controller aborts, the root controller will not abort. This\nallows for advanced request-flow scenarios to abort subsections of the request tree without aborting the entire request.\n\n---\n\n#### Stream Currying\n\n`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.\n\nFor context, it helps to understand a few of the use-cases that RequestManager\nis intended to allow.\n\n- to manage and return streaming content (such as video files)\n- to fulfill a request from multiple sources or by splitting one request into multiple requests\n - for instance one API call for a user and another for the user's friends\n - or e.g. fulfilling part of the request from one source (one API, in-memory, localStorage, IndexedDB\n etc.) and the rest from another source (a different API, a WebWorker, etc.)\n- to coalesce multiple requests\n- to decorate a request with additional info\n - e.g. an Auth handler that ensures the correct tokens or headers or cookies are attached.\n\n\n`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\ncode *while chunks are still being received by the browser*.\n\nWhen 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**.\n\nThe `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.\n\nEach 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\nhas not been called by the time that the handler's request method has resolved.\n\nHandlers 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.\n\n```ts\ncontext.setStream(future.getStream());\n```\n\nHandlers 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.\n\nOf course, any handler may choose to read and handle the stream, and return either no stream or a different stream in the process.\n\n---\n\n#### Automatic Currying of Stream and Response\n\nIn 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;`.\n\nSimilarly, 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.\n\nFinally, 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>)`.\n\nIn the case of the `Future` being returned, `Stream` proxying is automatic and immediate and does not wait for the `Future` to resolve.\n\n---\n\n### Using as a Service\n\nMost 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/).\n\n*services/request.ts*\n```ts\nimport RequestManager from '@ember-data-mirror/request';\nimport Fetch from '@ember-data-mirror/request/fetch';\nimport Auth from 'ember-simple-auth/ember-data-handler';\n\nexport default class extends RequestManager {\n constructor(createArgs) {\n super(createArgs);\n this.use([Auth, Fetch]);\n }\n}\n```\n\n---\n\n#### Using with `@ember-data-mirror/store`\n\nTo have a request service unique to a Store:\n\n```ts\nimport Store, { CacheHandler } from '@ember-data-mirror/store';\nimport RequestManager from '@ember-data-mirror/request';\nimport Fetch from '@ember-data-mirror/request/fetch';\n\nclass extends Store {\n requestManager = new RequestManager();\n\n constructor(args) {\n super(args);\n this.requestManager.use([Fetch]);\n this.requestManager.useCache(CacheHandler);\n }\n}\n```\n\n---\n\n#### Using with `ember-data`\n\nIf using the package [ember-data](https://github.com/emberjs/data/tree/main/packages/-ember-data),\nthe following configuration will automatically be done in order to preserve the\nlegacy [Adapter](https://github.com/emberjs/data/tree/main/packages/adapter) and\n[Serializer](https://github.com/emberjs/data/tree/main/packages/serializer) behavior.\nAdditional handlers or a service injection like the above would need to be done by the\nconsuming application in order to make broader use of `RequestManager`.\n\n```ts\nimport Store, { CacheHandler } from 'ember-data-mirror/store';\nimport RequestManager from '@ember-data-mirror/request';\nimport Fetch from '@ember-data-mirror/request/fetch';\nimport { LegacyNetworkHandler } from '@ember-data-mirror/legacy-compat';\n\nexport default class extends Store {\n requestManager = new RequestManager();\n\n constructor(args) {\n super(args);\n this.requestManager.use([LegacyNetworkHandler, Fetch]);\n this.requestManager.useCache(CacheHandler);\n }\n}\n```\n\nTo provide a different configuration, import and extend `ember-data/store`. The\ndefault configuration will be ignored if the `requestManager` property is set,\nthough the store will still register the CacheHandler.\n\nFor usage of the store's `requestManager` via `store.request(<req>)` see the\n[Store](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fstore) documentation.\n\n *\n * @module @ember-data-mirror/request\n * @main @ember-data-mirror/request\n */\nimport { importSync } from '@embroider/macros';\n\nimport { DEBUG, TESTING } from '@warp-drive-mirror/build-config/env';\nimport { peekUniversalTransient, setUniversalTransient } from '@warp-drive-mirror/core-types/-private';\nimport type { StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type { RequestInfo, StructuredErrorDocument } from '@warp-drive-mirror/core-types/request';\n\nimport { assertValidRequest } from './debug';\nimport { upgradePromise } from './future';\nimport { clearRequestResult, getRequestResult, setPromiseResult } from './promise-cache';\nimport type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from './types';\nimport { executeNextHandler, IS_CACHE_HANDLER } from './utils';\n\n/**\n * ```js\n * import RequestManager from '@ember-data-mirror/request';\n * ```\n *\n * A RequestManager provides a request/response flow in which configured\n * handlers are successively given the opportunity to handle, modify, or\n * pass-along a request.\n *\n * ```ts\n * interface RequestManager {\n * request<T>(req: RequestInfo): Future<T>;\n * }\n * ```\n *\n * For example:\n *\n * ```ts\n * import RequestManager from '@ember-data-mirror/request';\n * import Fetch from '@ember-data-mirror/request/fetch';\n * import Auth from 'ember-simple-auth/ember-data-handler';\n * import Config from './config';\n *\n * const { apiUrl } = Config;\n *\n * // ... create manager\n * const manager = new RequestManager().use([Auth, Fetch]);\n *\n * // ... execute a request\n * const response = await manager.request({\n * url: `${apiUrl}/users`\n * });\n * ```\n *\n * ### Futures\n *\n * The return value of `manager.request` is a `Future`, which allows\n * access to limited information about the request while it is still\n * pending and fulfills with the final state when the request completes.\n *\n * A `Future` is cancellable via `abort`.\n *\n * Handlers may optionally expose a `ReadableStream` to the `Future` for\n * streaming data; however, when doing so the future should not resolve\n * until the response stream is fully read.\n *\n * ```ts\n * interface Future<T> extends Promise<StructuredDocument<T>> {\n * abort(): void;\n *\n * async getStream(): ReadableStream | null;\n * }\n * ```\n *\n * ### StructuredDocuments\n *\n * A Future resolves with a `StructuredDataDocument` or rejects with a `StructuredErrorDocument`.\n *\n * ```ts\n * interface StructuredDataDocument<T> {\n * request: ImmutableRequestInfo;\n * response: ImmutableResponseInfo;\n * content: T;\n * }\n * interface StructuredErrorDocument extends Error {\n * request: ImmutableRequestInfo;\n * response: ImmutableResponseInfo;\n * error: string | object;\n * }\n * type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;\n * ```\n *\n * @class RequestManager\n * @public\n */\nexport class RequestManager {\n #handlers: Handler[] = [];\n declare _hasCacheHandler: boolean;\n /**\n * A map of pending requests from request.id to their\n * associated CacheHandler promise.\n *\n * This queue is managed by the CacheHandler\n *\n * @internal\n */\n declare _pending: Map<number, Promise<unknown>>;\n declare _deduped: Map<StableDocumentIdentifier, { priority: ManagedRequestPriority; promise: Promise<unknown> }>;\n\n constructor(options?: GenericCreateArgs) {\n Object.assign(this, options);\n this._pending = new Map();\n this._deduped = new Map();\n }\n\n /**\n * Register a handler to use for primary cache intercept.\n *\n * Only one such handler may exist. If using the same\n * RequestManager as the Store instance the Store\n * registers itself as a Cache handler.\n *\n * @method useCache\n * @public\n * @param {Handler[]} cacheHandler\n * @return {ThisType}\n */\n useCache(cacheHandler: CacheHandler & { [IS_CACHE_HANDLER]?: true }): this {\n if (DEBUG) {\n if (this._hasCacheHandler) {\n throw new Error(`\\`RequestManager.useCache(<handler>)\\` May only be invoked once.`);\n }\n if (Object.isFrozen(this.#handlers)) {\n throw new Error(\n `\\`RequestManager.useCache(<handler>)\\` May only be invoked prior to any request having been made.`\n );\n }\n this._hasCacheHandler = true;\n }\n cacheHandler[IS_CACHE_HANDLER] = true;\n this.#handlers.unshift(cacheHandler as Handler);\n return this;\n }\n\n /**\n * Register handler(s) to use when a request is issued.\n *\n * Handlers will be invoked in the order they are registered.\n * Each Handler is given the opportunity to handle the request,\n * curry the request, or pass along a modified request.\n *\n * @method use\n * @public\n * @param {Handler[]} newHandlers\n * @return {ThisType}\n */\n use(newHandlers: Handler[]): this {\n const handlers = this.#handlers;\n if (DEBUG) {\n if (Object.isFrozen(handlers)) {\n throw new Error(`Cannot add a Handler to a RequestManager after a request has been made`);\n }\n if (!Array.isArray(newHandlers)) {\n throw new Error(\n `\\`RequestManager.use(<Handler[]>)\\` expects an array of handlers, but was called with \\`${typeof newHandlers}\\``\n );\n }\n newHandlers.forEach((handler, index) => {\n if (!handler || typeof handler !== 'object' || typeof handler.request !== 'function') {\n throw new Error(\n `\\`RequestManager.use(<Handler[]>)\\` expected to receive an array of handler objects with request methods, by the handler at index ${index} does not conform.`\n );\n }\n });\n }\n handlers.push(...newHandlers);\n return this;\n }\n\n /**\n * Issue a Request.\n *\n * Returns a Future that fulfills with a StructuredDocument\n *\n * @method request\n * @public\n * @param {RequestInfo} request\n * @return {Future}\n */\n request<RT, T = unknown>(request: RequestInfo<T, RT>): Future<RT> {\n const handlers = this.#handlers;\n if (DEBUG) {\n if (!Object.isFrozen(handlers)) {\n Object.freeze(handlers);\n }\n assertValidRequest(request, true);\n }\n\n const controller = request.controller || new AbortController();\n if (request.controller) {\n delete request.controller;\n }\n\n const requestId = peekUniversalTransient<number>('REQ_ID') ?? 0;\n setUniversalTransient('REQ_ID', requestId + 1);\n\n const context = {\n controller,\n response: null,\n stream: null,\n hasRequestedStream: false,\n id: requestId,\n identifier: null,\n };\n const promise = executeNextHandler<RT>(handlers, request, 0, context);\n\n // the cache handler will set the result of the request synchronously\n // if it is able to fulfill the request from the cache\n const cacheResult = getRequestResult(requestId);\n\n if (TESTING) {\n if (!request.disableTestWaiter) {\n const { waitForPromise } = importSync('@ember/test-waiters') as {\n waitForPromise: <PT>(promise: Promise<PT>) => Promise<PT>;\n };\n const newPromise = waitForPromise(promise);\n const finalPromise = upgradePromise(\n newPromise.then(\n (result) => {\n setPromiseResult(finalPromise, { isError: false, result });\n clearRequestResult(requestId);\n return result;\n },\n (error: StructuredErrorDocument) => {\n setPromiseResult(finalPromise, { isError: true, result: error });\n clearRequestResult(requestId);\n throw error;\n }\n ),\n promise\n );\n\n if (cacheResult) {\n setPromiseResult(finalPromise, cacheResult);\n }\n\n return finalPromise;\n }\n }\n\n // const promise1 = store.request(myRequest);\n // const promise2 = store.request(myRequest);\n // promise1 === promise2; // false\n // either we need to make promise1 === promise2, or we need to make sure that\n // we need to have a way to key from request to result\n // such that we can lookup the result here and return it if it exists\n const finalPromise = upgradePromise(\n promise.then(\n (result) => {\n setPromiseResult(finalPromise, { isError: false, result });\n clearRequestResult(requestId);\n return result;\n },\n (error: StructuredErrorDocument) => {\n setPromiseResult(finalPromise, { isError: true, result: error });\n clearRequestResult(requestId);\n throw error;\n }\n ),\n promise\n );\n\n if (cacheResult) {\n setPromiseResult(finalPromise, cacheResult);\n }\n\n return finalPromise;\n }\n\n static create(options?: GenericCreateArgs) {\n return new this(options);\n }\n}\n"],"names":["RequestManager","constructor","options","Object","assign","_pending","Map","_deduped","useCache","cacheHandler","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","_hasCacheHandler","Error","isFrozen","IS_CACHE_HANDLER","unshift","use","newHandlers","handlers","Array","isArray","forEach","handler","index","request","push","freeze","assertValidRequest","controller","AbortController","requestId","peekUniversalTransient","setUniversalTransient","context","response","stream","hasRequestedStream","id","identifier","promise","executeNextHandler","cacheResult","getRequestResult","TESTING","disableTestWaiter","waitForPromise","importSync","newPromise","finalPromise","upgradePromise","then","result","setPromiseResult","isError","clearRequestResult","error","create"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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,GAAA;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data-mirror/request",
|
|
3
3
|
"description": "⚡️ A simple, small and fast framework-agnostic library to make `fetch` happen",
|
|
4
|
-
"version": "5.4.0-beta.
|
|
4
|
+
"version": "5.4.0-beta.13",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chris Thoburn <runspired@users.noreply.github.com>",
|
|
7
7
|
"repository": {
|
|
@@ -14,11 +14,6 @@
|
|
|
14
14
|
"keywords": [
|
|
15
15
|
"ember-addon"
|
|
16
16
|
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"lint": "eslint . --quiet --cache --cache-strategy=content --report-unused-disable-directives",
|
|
19
|
-
"build:pkg": "vite build;",
|
|
20
|
-
"sync-hardlinks": "bun run sync-dependencies-meta-injected"
|
|
21
|
-
},
|
|
22
17
|
"files": [
|
|
23
18
|
"unstable-preview-types",
|
|
24
19
|
"addon-main.cjs",
|
|
@@ -34,15 +29,18 @@
|
|
|
34
29
|
},
|
|
35
30
|
"./*": {
|
|
36
31
|
"default": "./dist/*.js"
|
|
32
|
+
},
|
|
33
|
+
"./unstable-preview-types": {
|
|
34
|
+
"types": "./unstable-preview-types/index.d.ts"
|
|
37
35
|
}
|
|
38
36
|
},
|
|
39
37
|
"peerDependencies": {
|
|
40
|
-
"@warp-drive-mirror/core-types": "0.0.0-beta.
|
|
38
|
+
"@warp-drive-mirror/core-types": "0.0.0-beta.13"
|
|
41
39
|
},
|
|
42
40
|
"dependencies": {
|
|
43
|
-
"@ember/test-waiters": "^3.1.0",
|
|
44
|
-
"@embroider/macros": "^1.16.
|
|
45
|
-
"@warp-drive-mirror/build-config": "0.0.0-beta.
|
|
41
|
+
"@ember/test-waiters": "^3.1.0 || ^4.0.0",
|
|
42
|
+
"@embroider/macros": "^1.16.6",
|
|
43
|
+
"@warp-drive-mirror/build-config": "0.0.0-beta.8"
|
|
46
44
|
},
|
|
47
45
|
"devDependencies": {
|
|
48
46
|
"@babel/core": "^7.24.5",
|
|
@@ -50,11 +48,11 @@
|
|
|
50
48
|
"@babel/preset-env": "^7.24.5",
|
|
51
49
|
"@babel/preset-typescript": "^7.24.1",
|
|
52
50
|
"@glimmer/component": "^1.1.2",
|
|
53
|
-
"@warp-drive-mirror/core-types": "0.0.0-beta.
|
|
54
|
-
"@warp-drive/internal-config": "5.4.0-beta.
|
|
55
|
-
"ember-source": "~5.
|
|
51
|
+
"@warp-drive-mirror/core-types": "0.0.0-beta.13",
|
|
52
|
+
"@warp-drive/internal-config": "5.4.0-beta.13",
|
|
53
|
+
"ember-source": "~5.12.0",
|
|
56
54
|
"pnpm-sync-dependencies-meta-injected": "0.0.14",
|
|
57
|
-
"typescript": "^5.
|
|
55
|
+
"typescript": "^5.7.2",
|
|
58
56
|
"vite": "^5.2.11"
|
|
59
57
|
},
|
|
60
58
|
"dependenciesMeta": {
|
|
@@ -66,7 +64,7 @@
|
|
|
66
64
|
}
|
|
67
65
|
},
|
|
68
66
|
"engines": {
|
|
69
|
-
"node": ">= 18.20.
|
|
67
|
+
"node": ">= 18.20.4"
|
|
70
68
|
},
|
|
71
69
|
"volta": {
|
|
72
70
|
"extends": "../../../../../../package.json"
|
|
@@ -78,5 +76,17 @@
|
|
|
78
76
|
},
|
|
79
77
|
"ember": {
|
|
80
78
|
"edition": "octane"
|
|
79
|
+
},
|
|
80
|
+
"typesVersions": {
|
|
81
|
+
"*": {
|
|
82
|
+
"unstable-preview-types": [
|
|
83
|
+
"./unstable-preview-types"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"scripts": {
|
|
88
|
+
"lint": "eslint . --quiet --cache --cache-strategy=content",
|
|
89
|
+
"build:pkg": "vite build;",
|
|
90
|
+
"sync-hardlinks": "bun run sync-dependencies-meta-injected"
|
|
81
91
|
}
|
|
82
92
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare module '@ember-data-mirror/request/-private/context' {
|
|
2
|
+
import type { StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';
|
|
2
3
|
import type { ImmutableHeaders, ImmutableRequestInfo, RequestInfo, ResponseInfo } from '@warp-drive-mirror/core-types/request';
|
|
3
4
|
import type { DeferredStream, GodContext } from '@ember-data-mirror/request/-private/types';
|
|
4
5
|
export function upgradeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders;
|
|
@@ -29,10 +30,14 @@ declare module '@ember-data-mirror/request/-private/context' {
|
|
|
29
30
|
#private;
|
|
30
31
|
request: ImmutableRequestInfo;
|
|
31
32
|
id: number;
|
|
32
|
-
|
|
33
|
+
private _isCacheHandler;
|
|
34
|
+
private _finalized;
|
|
35
|
+
constructor(owner: ContextOwner, isCacheHandler: boolean);
|
|
33
36
|
setStream(stream: ReadableStream | Promise<ReadableStream | null>): void;
|
|
34
37
|
setResponse(response: ResponseInfo | Response | null): void;
|
|
38
|
+
setIdentifier(identifier: StableDocumentIdentifier): void;
|
|
35
39
|
get hasRequestedStream(): boolean;
|
|
40
|
+
_finalize(): void;
|
|
36
41
|
}
|
|
37
42
|
export type HandlerRequestContext = Context;
|
|
38
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/-private/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/-private/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAKxH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1D,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,GAAG,gBAAgB,CAQpF;AAED,wB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;CAGV;AACD,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../src/-private/future.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGhE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,CAE9D;AAED,wBAAgB,cAAc,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAQ/C;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../src/-private/future.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGhE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,CAE9D;AAED,wBAAgB,cAAc,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAQ/C;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAYvG;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,GAAG,cAAc,CAAC,CAAC,CAAC,CA0BtE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare module '@ember-data-mirror/request/-private/manager' {
|
|
2
|
+
import type { StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';
|
|
2
3
|
import type { RequestInfo } from '@warp-drive-mirror/core-types/request';
|
|
3
|
-
import type { CacheHandler, Future, GenericCreateArgs, Handler } from '@ember-data-mirror/request/-private/types';
|
|
4
|
+
import type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from '@ember-data-mirror/request/-private/types';
|
|
4
5
|
import { IS_CACHE_HANDLER } from '@ember-data-mirror/request/-private/utils';
|
|
5
6
|
/**
|
|
6
7
|
* ```js
|
|
@@ -28,8 +29,7 @@ declare module '@ember-data-mirror/request/-private/manager' {
|
|
|
28
29
|
* const { apiUrl } = Config;
|
|
29
30
|
*
|
|
30
31
|
* // ... create manager
|
|
31
|
-
* const manager = new RequestManager();
|
|
32
|
-
* manager.use([Auth, Fetch]);
|
|
32
|
+
* const manager = new RequestManager().use([Auth, Fetch]);
|
|
33
33
|
*
|
|
34
34
|
* // ... execute a request
|
|
35
35
|
* const response = await manager.request({
|
|
@@ -81,7 +81,19 @@ declare module '@ember-data-mirror/request/-private/manager' {
|
|
|
81
81
|
export class RequestManager {
|
|
82
82
|
#private;
|
|
83
83
|
_hasCacheHandler: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* A map of pending requests from request.id to their
|
|
86
|
+
* associated CacheHandler promise.
|
|
87
|
+
*
|
|
88
|
+
* This queue is managed by the CacheHandler
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
84
92
|
_pending: Map<number, Promise<unknown>>;
|
|
93
|
+
_deduped: Map<StableDocumentIdentifier, {
|
|
94
|
+
priority: ManagedRequestPriority;
|
|
95
|
+
promise: Promise<unknown>;
|
|
96
|
+
}>;
|
|
85
97
|
constructor(options?: GenericCreateArgs);
|
|
86
98
|
/**
|
|
87
99
|
* Register a handler to use for primary cache intercept.
|
|
@@ -93,11 +105,11 @@ declare module '@ember-data-mirror/request/-private/manager' {
|
|
|
93
105
|
* @method useCache
|
|
94
106
|
* @public
|
|
95
107
|
* @param {Handler[]} cacheHandler
|
|
96
|
-
* @return {
|
|
108
|
+
* @return {ThisType}
|
|
97
109
|
*/
|
|
98
110
|
useCache(cacheHandler: CacheHandler & {
|
|
99
111
|
[IS_CACHE_HANDLER]?: true;
|
|
100
|
-
}):
|
|
112
|
+
}): this;
|
|
101
113
|
/**
|
|
102
114
|
* Register handler(s) to use when a request is issued.
|
|
103
115
|
*
|
|
@@ -108,9 +120,9 @@ declare module '@ember-data-mirror/request/-private/manager' {
|
|
|
108
120
|
* @method use
|
|
109
121
|
* @public
|
|
110
122
|
* @param {Handler[]} newHandlers
|
|
111
|
-
* @return {
|
|
123
|
+
* @return {ThisType}
|
|
112
124
|
*/
|
|
113
|
-
use(newHandlers: Handler[]):
|
|
125
|
+
use(newHandlers: Handler[]): this;
|
|
114
126
|
/**
|
|
115
127
|
* Issue a Request.
|
|
116
128
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/-private/manager.ts"],"names":[],"mappings":"AAsbA,OAAO,KAAK,EAAE,WAAW,EAA2B,MAAM,gCAAgC,CAAC;AAK3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/-private/manager.ts"],"names":[],"mappings":"AAsbA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAA2B,MAAM,gCAAgC,CAAC;AAK3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACxG,OAAO,EAAsB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,qBAAa,cAAc;;IAEjB,gBAAgB,EAAE,OAAO,CAAC;IAClC;;;;;;;OAOG;IACK,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACxC,QAAQ,EAAE,GAAG,CAAC,wBAAwB,EAAE;QAAE,QAAQ,EAAE,sBAAsB,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;gBAErG,OAAO,CAAC,EAAE,iBAAiB;IAMvC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,YAAY,EAAE,YAAY,GAAG;QAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI;IAiB1E;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI;IAuBjC;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;IA0FjE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB;CAG1C"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare module '@ember-data-mirror/request/-private/types' {
|
|
2
|
+
import type { StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';
|
|
2
3
|
import type { IS_FUTURE, RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from '@warp-drive-mirror/core-types/request';
|
|
3
4
|
/**
|
|
4
5
|
* @module @ember-data-mirror/request
|
|
@@ -9,12 +10,16 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
9
10
|
stream: ReadableStream | Promise<ReadableStream | null> | null;
|
|
10
11
|
hasRequestedStream: boolean;
|
|
11
12
|
id: number;
|
|
13
|
+
identifier: StableDocumentIdentifier | null;
|
|
12
14
|
}
|
|
13
15
|
export type Deferred<T> = {
|
|
14
16
|
resolve(v: T): void;
|
|
15
17
|
reject(v: unknown): void;
|
|
16
18
|
promise: Promise<T>;
|
|
17
19
|
};
|
|
20
|
+
export type ManagedRequestPriority = {
|
|
21
|
+
blocking: boolean;
|
|
22
|
+
};
|
|
18
23
|
export type DeferredStream = {
|
|
19
24
|
resolve(v: ReadableStream | null): void;
|
|
20
25
|
reject(v: unknown): void;
|
|
@@ -60,6 +65,24 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
60
65
|
* @return void
|
|
61
66
|
*/
|
|
62
67
|
onFinalize(cb: () => void): void;
|
|
68
|
+
/**
|
|
69
|
+
* The identifier of the associated request, if any, as
|
|
70
|
+
* assigned by the CacheHandler.
|
|
71
|
+
*
|
|
72
|
+
* @property lid
|
|
73
|
+
* @type {StableDocumentIdentifier | null}
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
lid: StableDocumentIdentifier | null;
|
|
77
|
+
/**
|
|
78
|
+
* The id of the associated request, if any, as assigned
|
|
79
|
+
* by the RequestManager
|
|
80
|
+
*
|
|
81
|
+
* @property id
|
|
82
|
+
* @type {number}
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
id: number;
|
|
63
86
|
};
|
|
64
87
|
export type DeferredFuture<T> = {
|
|
65
88
|
resolve(v: StructuredDataDocument<T>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/-private/types.ts"],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AAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,gBAE5C;AAED,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC,EAC/C,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAC1B,MAAM,CAAC,CAAC,CAAC,CA6CX;AAMD,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,EAC1B,OAAO,EAAE,WAAW,EACpB,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,UAAU,GACd,MAAM,CAAC,CAAC,CAAC,CAmDX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AA8E3E;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,KAAK;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AA8E3E;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,KAAK;YACK,CAAC,WAAW,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAgJ/C,CAAC;AAMF,eAAe,KAAK,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference path="./fetch.d.ts" />
|
|
2
|
-
/// <reference path="./-private/
|
|
2
|
+
/// <reference path="./-private/future.d.ts" />
|
|
3
3
|
/// <reference path="./-private/utils.d.ts" />
|
|
4
|
-
/// <reference path="./-private/manager.d.ts" />
|
|
5
|
-
/// <reference path="./-private/promise-cache.d.ts" />
|
|
6
4
|
/// <reference path="./-private/types.d.ts" />
|
|
7
|
-
/// <reference path="./-private/
|
|
5
|
+
/// <reference path="./-private/debug.d.ts" />
|
|
6
|
+
/// <reference path="./-private/promise-cache.d.ts" />
|
|
7
|
+
/// <reference path="./-private/manager.d.ts" />
|
|
8
8
|
/// <reference path="./-private/context.d.ts" />
|
|
9
9
|
declare module '@ember-data-mirror/request' {
|
|
10
10
|
export { RequestManager as default } from '@ember-data-mirror/request/-private/manager';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug-DGStaRpE.js","sources":["../src/-private/promise-cache.ts","../src/-private/utils.ts","../src/-private/future.ts","../src/-private/context.ts","../src/-private/debug.ts"],"sourcesContent":["import { getOrSetUniversal } from '@warp-drive-mirror/core-types/-private';\n\nexport type CacheResult<T = unknown, E = unknown> = { isError: true; result: E } | { isError: false; result: T };\n\nexport type Awaitable<T = unknown, E = unknown> = {\n then: (onFulfilled: (value: T) => unknown, onRejected: (reason: E) => unknown) => unknown;\n catch: (onRejected: (reason: E) => unknown) => unknown;\n finally: (onFinally: () => unknown) => unknown;\n};\n\nexport const PromiseCache = getOrSetUniversal('PromiseCache', new WeakMap<Awaitable, CacheResult>());\nexport const RequestMap = getOrSetUniversal('RequestMap', new Map<number, CacheResult>());\n\nexport function setRequestResult(requestId: number, result: CacheResult) {\n RequestMap.set(requestId, result);\n}\nexport function clearRequestResult(requestId: number) {\n RequestMap.delete(requestId);\n}\nexport function getRequestResult(requestId: number): CacheResult | undefined {\n return RequestMap.get(requestId);\n}\n\nexport function setPromiseResult(promise: Promise<unknown> | Awaitable, result: CacheResult) {\n PromiseCache.set(promise, result);\n}\n\nexport function getPromiseResult<T, E>(promise: Promise<T> | Awaitable<T, E>): CacheResult<T, E> | undefined {\n return PromiseCache.get(promise) as CacheResult<T, E> | undefined;\n}\n","import { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport { getOrSetGlobal } from '@warp-drive-mirror/core-types/-private';\nimport type {\n RequestInfo,\n StructuredDataDocument,\n StructuredDocument,\n StructuredErrorDocument,\n} from '@warp-drive-mirror/core-types/request';\nimport { STRUCTURED } from '@warp-drive-mirror/core-types/request';\n\nimport { Context, ContextOwner } from './context';\nimport { assertValidRequest } from './debug';\nimport { createFuture, isFuture } from './future';\nimport { setRequestResult } from './promise-cache';\nimport type { DeferredFuture, Future, GodContext, Handler } from './types';\n\nexport const IS_CACHE_HANDLER = getOrSetGlobal('IS_CACHE_HANDLER', Symbol('IS_CACHE_HANDLER'));\nexport function curryFuture<T>(owner: ContextOwner, inbound: Future<T>, outbound: DeferredFuture<T>): Future<T> {\n owner.setStream(inbound.getStream());\n\n inbound.then(\n (doc: StructuredDataDocument<T>) => {\n const document = {\n [STRUCTURED]: true as const,\n request: owner.request,\n response: doc.response,\n content: doc.content,\n };\n outbound.resolve(document);\n },\n (error: Error & StructuredErrorDocument) => {\n if (isDoc(error)) {\n owner.setStream(owner.god.stream);\n }\n if (!error || !(error instanceof Error)) {\n try {\n throw new Error(error ? error : `Request Rejected with an Unknown Error`);\n } catch (e: unknown) {\n if (error && typeof error === 'object') {\n Object.assign(e as Error, error);\n (e as Error & StructuredErrorDocument).message =\n (error as Error).message || `Request Rejected with an Unknown Error`;\n }\n error = e as Error & StructuredErrorDocument;\n }\n }\n\n error[STRUCTURED] = true;\n error.request = owner.request;\n error.response = owner.getResponse();\n error.error = error.error || error.message;\n\n outbound.reject(error);\n }\n );\n return outbound.promise;\n}\n\nfunction isDoc<T>(doc: T | StructuredDataDocument<T>): doc is StructuredDataDocument<T> {\n return doc && (doc as StructuredDataDocument<T>)[STRUCTURED] === true;\n}\n\nfunction ensureDoc<T>(owner: ContextOwner, content: T | Error, isError: boolean): StructuredDocument<T> {\n if (isDoc(content)) {\n return content as StructuredDocument<T>;\n }\n\n if (isError) {\n return {\n [STRUCTURED]: true,\n request: owner.request,\n response: owner.getResponse(),\n error: content as Error,\n } as StructuredErrorDocument<T>;\n }\n\n return {\n [STRUCTURED]: true,\n request: owner.request,\n response: owner.getResponse(),\n content: content as T,\n };\n}\n\nexport type HttpErrorProps = {\n code: number;\n name: string;\n status: number;\n statusText: string;\n isRequestError: boolean;\n};\n\nexport function enhanceReason(reason?: string) {\n return new DOMException(reason || 'The user aborted a request.', 'AbortError');\n}\n\nexport function handleOutcome<T>(\n owner: ContextOwner,\n inbound: Promise<T | StructuredDataDocument<T>>,\n outbound: DeferredFuture<T>\n): Future<T> {\n inbound.then(\n (content: T | StructuredDataDocument<T>) => {\n if (owner.controller.signal.aborted) {\n // the next function did not respect the signal, we handle it here\n outbound.reject(enhanceReason(owner.controller.signal.reason as string));\n return;\n }\n if (isDoc(content)) {\n owner.setStream(owner.god.stream);\n content = content.content;\n }\n const document = {\n [STRUCTURED]: true as const,\n request: owner.request,\n response: owner.getResponse(),\n content,\n };\n outbound.resolve(document);\n },\n (error: Error & StructuredErrorDocument) => {\n if (isDoc(error)) {\n owner.setStream(owner.god.stream);\n }\n if (!error || !(error instanceof Error)) {\n try {\n throw new Error(error ? error : `Request Rejected with an Unknown Error`);\n } catch (e: unknown) {\n if (error && typeof error === 'object') {\n Object.assign(e as Error, error);\n (e as Error & StructuredErrorDocument).message =\n (error as Error).message || `Request Rejected with an Unknown Error`;\n }\n error = e as Error & StructuredErrorDocument;\n }\n }\n\n error[STRUCTURED] = true;\n error.request = owner.request;\n error.response = owner.getResponse();\n error.error = error.error || error.message;\n outbound.reject(error);\n }\n );\n return outbound.promise;\n}\n\nfunction isCacheHandler(handler: Handler & { [IS_CACHE_HANDLER]?: boolean }, index: number): boolean {\n return index === 0 && Boolean(handler[IS_CACHE_HANDLER]);\n}\n\nexport function executeNextHandler<T>(\n wares: Readonly<Handler[]>,\n request: RequestInfo,\n i: number,\n god: GodContext\n): Future<T> {\n if (DEBUG) {\n if (i === wares.length) {\n throw new Error(`No handler was able to handle this request.`);\n }\n assertValidRequest(request, false);\n }\n const owner = new ContextOwner(request, god, i === 0);\n\n function next(r: RequestInfo): Future<T> {\n owner.nextCalled++;\n return executeNextHandler(wares, r, i + 1, god);\n }\n\n const context = new Context(owner);\n let outcome: Promise<T | StructuredDataDocument<T>> | Future<T>;\n try {\n outcome = wares[i].request<T>(context, next);\n if (!!outcome && isCacheHandler(wares[i], i)) {\n if (!(outcome instanceof Promise)) {\n setRequestResult(owner.requestId, { isError: false, result: ensureDoc(owner, outcome, false) });\n outcome = Promise.resolve(outcome);\n }\n } else if (DEBUG) {\n if (!outcome || (!(outcome instanceof Promise) && !(typeof outcome === 'object' && 'then' in outcome))) {\n // eslint-disable-next-line no-console\n console.log({ request, handler: wares[i], outcome });\n if (outcome === undefined) {\n throw new Error(`Expected handler.request to return a promise, instead received undefined.`);\n }\n throw new Error(`Expected handler.request to return a promise, instead received a synchronous value.`);\n }\n }\n } catch (e) {\n if (isCacheHandler(wares[i], i)) {\n setRequestResult(owner.requestId, { isError: true, result: ensureDoc(owner, e, true) });\n }\n outcome = Promise.reject<StructuredDataDocument<T>>(e);\n }\n const future = createFuture<T>(owner);\n\n if (isFuture<T>(outcome)) {\n return curryFuture(owner, outcome, future);\n }\n\n return handleOutcome(owner, outcome, future);\n}\n","import { IS_FUTURE, type StructuredDocument } from '@warp-drive-mirror/core-types/request';\n\nimport type { ContextOwner } from './context';\nimport type { Deferred, DeferredFuture, Future } from './types';\nimport { enhanceReason } from './utils';\n\nexport function isFuture<T>(maybe: unknown): maybe is Future<T> {\n return Boolean(maybe && maybe instanceof Promise && (maybe as Future<T>)[IS_FUTURE] === true);\n}\n\nexport function createDeferred<T>(): Deferred<T> {\n let resolve!: (v: T) => void;\n let reject!: (v: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { resolve, reject, promise };\n}\n\nexport function upgradePromise<T>(promise: Promise<StructuredDocument<T>>, future: Future<T>): Future<T> {\n (promise as Future<T>)[IS_FUTURE] = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).getStream = future.getStream;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).abort = future.abort;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).onFinalize = future.onFinalize;\n\n return promise as Future<T>;\n}\n\nexport function createFuture<T>(owner: ContextOwner): DeferredFuture<T> {\n const deferred = createDeferred<T>() as unknown as DeferredFuture<T>;\n let { promise } = deferred;\n let cbs: Array<() => void> | undefined;\n promise = promise.finally(() => {\n owner.resolveStream();\n if (cbs) {\n cbs.forEach((cb) => cb());\n }\n }) as Future<T>;\n promise.onFinalize = (fn: () => void) => {\n cbs = cbs || [];\n cbs.push(fn);\n };\n promise[IS_FUTURE] = true;\n promise.getStream = () => {\n return owner.getStream();\n };\n promise.abort = (reason?: string) => {\n owner.abort(enhanceReason(reason));\n };\n deferred.promise = promise;\n return deferred;\n}\n","import { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport type { ImmutableHeaders, ImmutableRequestInfo, RequestInfo, ResponseInfo } from '@warp-drive-mirror/core-types/request';\nimport { SkipCache } from '@warp-drive-mirror/core-types/request';\n\nimport { deepFreeze } from './debug';\nimport { createDeferred } from './future';\nimport type { DeferredStream, GodContext } from './types';\n\nexport function upgradeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders {\n (headers as ImmutableHeaders).clone = () => {\n return new Headers(headers);\n };\n (headers as ImmutableHeaders).toJSON = () => {\n return Array.from(headers);\n };\n return headers as ImmutableHeaders;\n}\n\nexport function cloneResponseProperties(response: Response): ResponseInfo {\n const { headers, ok, redirected, status, statusText, type, url } = response;\n upgradeHeaders(headers);\n return {\n headers: headers as ImmutableHeaders,\n ok,\n redirected,\n status,\n statusText,\n type,\n url,\n };\n}\n\nexport class ContextOwner {\n hasSetStream = false;\n hasSetResponse = false;\n hasSubscribers = false;\n stream: DeferredStream = createDeferred<ReadableStream | null>();\n response: ResponseInfo | null = null;\n declare request: ImmutableRequestInfo;\n declare enhancedRequest: ImmutableRequestInfo;\n nextCalled = 0;\n declare god: GodContext;\n declare controller: AbortController;\n declare requestId: number;\n declare isRoot: boolean;\n\n constructor(request: RequestInfo, god: GodContext, isRoot = false) {\n this.isRoot = isRoot;\n this.requestId = god.id;\n this.controller = request.controller || god.controller;\n this.stream.promise.sizeHint = 0;\n\n if (request.controller) {\n if (request.controller !== god.controller) {\n god.controller.signal.addEventListener('abort', () => {\n this.controller.abort(god.controller.signal.reason);\n });\n }\n delete request.controller;\n }\n let enhancedRequest: ImmutableRequestInfo = Object.assign(\n { signal: this.controller.signal },\n request\n ) as ImmutableRequestInfo;\n if (DEBUG) {\n if (!request?.cacheOptions?.[SkipCache]) {\n request = deepFreeze(request) as ImmutableRequestInfo;\n enhancedRequest = deepFreeze(enhancedRequest);\n }\n } else {\n if (request.headers) {\n upgradeHeaders(request.headers);\n }\n }\n this.enhancedRequest = enhancedRequest;\n this.request = request as ImmutableRequestInfo;\n this.god = god;\n this.stream.promise = this.stream.promise.then((stream: ReadableStream | null) => {\n if (this.god.stream === stream && this.hasSubscribers) {\n this.god.stream = null;\n }\n return stream;\n });\n }\n\n get hasRequestedStream(): boolean {\n return this.god.hasRequestedStream;\n }\n\n getResponse(): ResponseInfo | null {\n if (this.hasSetResponse) {\n return this.response;\n }\n if (this.nextCalled === 1) {\n return this.god.response;\n }\n return null;\n }\n getStream(): Promise<ReadableStream | null> {\n if (this.isRoot) {\n this.god.hasRequestedStream = true;\n }\n if (!this.hasSetResponse) {\n const hint = this.god.response?.headers?.get('content-length');\n this.stream.promise.sizeHint = hint ? parseInt(hint, 10) : 0;\n }\n this.hasSubscribers = true;\n return this.stream.promise;\n }\n abort(reason: DOMException) {\n this.controller.abort(reason);\n }\n\n setStream(stream: ReadableStream | Promise<ReadableStream | null> | null) {\n if (!this.hasSetStream) {\n this.hasSetStream = true;\n\n if (!(stream instanceof Promise)) {\n this.god.stream = stream;\n }\n // @ts-expect-error\n this.stream.resolve(stream);\n }\n }\n\n resolveStream() {\n this.setStream(this.nextCalled === 1 ? this.god.stream : null);\n }\n\n setResponse(response: ResponseInfo | Response | null) {\n if (this.hasSetResponse) {\n if (DEBUG) {\n throw new Error(`Cannot setResponse when a response has already been set`);\n }\n return;\n }\n this.hasSetResponse = true;\n if (response instanceof Response) {\n // TODO potentially avoid cloning in prod\n let responseData = cloneResponseProperties(response);\n\n if (DEBUG) {\n responseData = deepFreeze(responseData);\n }\n this.response = responseData;\n this.god.response = responseData;\n const sizeHint = response.headers?.get('content-length');\n this.stream.promise.sizeHint = sizeHint ? parseInt(sizeHint, 10) : 0;\n } else {\n this.response = response;\n this.god.response = response;\n }\n }\n}\n\nexport class Context {\n #owner: ContextOwner;\n declare request: ImmutableRequestInfo;\n declare id: number;\n\n constructor(owner: ContextOwner) {\n this.id = owner.requestId;\n this.#owner = owner;\n this.request = owner.enhancedRequest;\n }\n setStream(stream: ReadableStream | Promise<ReadableStream | null>) {\n this.#owner.setStream(stream);\n }\n setResponse(response: ResponseInfo | Response | null) {\n this.#owner.setResponse(response);\n }\n\n get hasRequestedStream() {\n return this.#owner.hasRequestedStream;\n }\n}\nexport type HandlerRequestContext = Context;\n","import { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport { getOrSetGlobal } from '@warp-drive-mirror/core-types/-private';\nimport type { ImmutableHeaders, RequestInfo } from '@warp-drive-mirror/core-types/request';\n\nimport { Context, upgradeHeaders } from './context';\n\nconst BODY_TYPES = {\n type: 'string',\n klass: ['Blob', 'ArrayBuffer', 'TypedArray', 'DataView', 'FormData', 'URLSearchParams', 'ReadableStream'],\n};\nconst ValidKeys = new Map<string, string | string[] | typeof BODY_TYPES>([\n ['records', 'array'],\n ['data', 'json'],\n ['body', BODY_TYPES],\n ['disableTestWaiter', 'boolean'],\n ['options', 'object'],\n ['cacheOptions', 'object'],\n ['op', 'string'],\n ['store', 'object'],\n ['url', 'string'],\n ['cache', ['default', 'force-cache', 'no-cache', 'no-store', 'only-if-cached', 'reload']],\n ['credentials', ['include', 'omit', 'same-origin']],\n [\n 'destination',\n [\n '',\n 'object',\n 'audio',\n 'audioworklet',\n 'document',\n 'embed',\n 'font',\n 'frame',\n 'iframe',\n 'image',\n 'manifest',\n 'paintworklet',\n 'report',\n 'script',\n 'sharedworker',\n 'style',\n 'track',\n 'video',\n 'worker',\n 'xslt',\n ],\n ],\n ['headers', 'headers'],\n ['integrity', 'string'],\n ['keepalive', 'boolean'],\n ['method', ['GET', 'PUT', 'PATCH', 'DELETE', 'POST', 'OPTIONS']],\n ['mode', ['same-origin', 'cors', 'navigate', 'no-cors']],\n ['redirect', ['error', 'follow', 'manual']],\n ['referrer', 'string'],\n ['signal', 'AbortSignal'],\n ['controller', 'AbortController'],\n [\n 'referrerPolicy',\n [\n '',\n 'same-origin',\n 'no-referrer',\n 'no-referrer-when-downgrade',\n 'origin',\n 'origin-when-cross-origin',\n 'strict-origin',\n 'strict-origin-when-cross-origin',\n 'unsafe-url',\n ],\n ],\n]);\n\nconst IS_FROZEN = getOrSetGlobal('IS_FROZEN', Symbol('FROZEN'));\nconst IS_COLLECTION = getOrSetGlobal('IS_COLLECTION', Symbol.for('Collection'));\n\nfunction freezeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders {\n headers.delete =\n headers.set =\n headers.append =\n () => {\n throw new Error(`Cannot Mutate Immutatable Headers, use headers.clone to get a copy`);\n };\n upgradeHeaders(headers);\n return headers as ImmutableHeaders;\n}\n\nexport function deepFreeze<T = unknown>(value: T): T {\n if (value && (value as { [IS_FROZEN]?: true })[IS_FROZEN]) {\n return value;\n }\n const _type = typeof value;\n switch (_type) {\n case 'boolean':\n case 'string':\n case 'number':\n case 'symbol':\n case 'undefined':\n case 'bigint':\n return value;\n case 'function':\n throw new Error(`Cannot deep-freeze a function`);\n case 'object': {\n const _niceType = niceTypeOf(value);\n switch (_niceType) {\n case 'array': {\n if ((value as unknown[] & { [IS_COLLECTION]?: true })[IS_COLLECTION]) {\n return value;\n }\n const arr = (value as unknown[]).map(deepFreeze);\n arr[IS_FROZEN as unknown as number] = true;\n return Object.freeze(arr) as T;\n }\n case 'null':\n return value;\n case 'object':\n Object.keys(value as Record<string, unknown>).forEach((key) => {\n try {\n (value as Record<string, unknown>)[key] = deepFreeze((value as Record<string, unknown>)[key]) as object;\n } catch {\n // continue\n }\n });\n (value as Record<string | symbol, unknown>)[IS_FROZEN] = true;\n return Object.freeze(value);\n case 'headers':\n return freezeHeaders(value as Headers) as T;\n case 'Collection':\n case 'Store':\n case 'AbortSignal':\n return value;\n case 'date':\n case 'map':\n case 'set':\n case 'error':\n case 'stream':\n default:\n // console.log(`Cannot deep-freeze ${_niceType}`);\n return value;\n }\n }\n }\n}\n\nfunction isMaybeContext(request: unknown) {\n if (request && typeof request === 'object') {\n const keys = Object.keys(request);\n if (keys.length === 1 && keys[0] === 'request') {\n return true;\n }\n }\n return false;\n}\n\nfunction niceTypeOf(v: unknown) {\n if (v === null) {\n return 'null';\n }\n if (typeof v === 'string') {\n return v ? 'non-empty-string' : 'empty-string';\n }\n if (!v) {\n return typeof v;\n }\n if (Array.isArray(v)) {\n return 'array';\n }\n if (v instanceof Date) {\n return 'date';\n }\n if (v instanceof Map) {\n return 'map';\n }\n if (v instanceof Set) {\n return 'set';\n }\n if (v instanceof Error) {\n return 'error';\n }\n if (v instanceof ReadableStream || v instanceof WritableStream || v instanceof TransformStream) {\n return 'stream';\n }\n if (v instanceof Headers) {\n return 'headers';\n }\n if (typeof v === 'object' && v.constructor && v.constructor.name !== 'Object') {\n return v.constructor.name;\n }\n return typeof v;\n}\n\nfunction validateKey(key: string, value: unknown, errors: string[]) {\n const schema = ValidKeys.get(key);\n if (!schema && !IgnoredKeys.has(key)) {\n errors.push(`InvalidKey: '${key}'`);\n return;\n }\n if (schema) {\n if (schema === BODY_TYPES) {\n if (typeof value === 'string' || value instanceof ReadableStream) {\n return;\n }\n const type = niceTypeOf(value);\n if (schema.klass.includes(type)) {\n return;\n }\n errors.push(\n `InvalidValue: key 'body' should be a string or one of '${schema.klass.join(\"', '\")}', received ${\n '<a value of type ' + niceTypeOf(value) + '>'\n }`\n );\n return;\n }\n if (Array.isArray(schema)) {\n if (!schema.includes(value as string)) {\n errors.push(\n `InvalidValue: key ${key} should be a one of '${schema.join(\"', '\")}', received ${\n typeof value === 'string' ? value : '<a value of type ' + niceTypeOf(value) + '>'\n }`\n );\n }\n return;\n } else if (schema === 'json') {\n try {\n JSON.stringify(value);\n } catch (e) {\n errors.push(\n `InvalidValue: key ${key} should be a JSON serializable value, but failed to serialize with Error - ${\n (e as Error).message\n }`\n );\n }\n return;\n } else if (schema === 'headers') {\n if (!(value instanceof Headers)) {\n errors.push(`InvalidValue: key ${key} should be an instance of Headers, received ${niceTypeOf(value)}`);\n }\n return;\n } else if (schema === 'record') {\n const _type = typeof value;\n // record must extend plain object or Object.create(null)\n if (!value || _type !== 'object' || (value.constructor && value.constructor !== Object)) {\n errors.push(\n `InvalidValue: key ${key} should be a dictionary of string keys to string values, received ${niceTypeOf(\n value\n )}`\n );\n return;\n }\n const keys = Object.keys(value);\n keys.forEach((k) => {\n const v: unknown = (value as Record<string, unknown>)[k];\n if (typeof k !== 'string') {\n errors.push(`\\tThe key ${String(k)} on ${key} should be a string key`);\n } else if (typeof v !== 'string') {\n errors.push(`\\tThe value of ${key}.${k} should be a string not ${niceTypeOf(v)}`);\n }\n });\n return;\n } else if (schema === 'string') {\n if (typeof value !== 'string' || value.length === 0) {\n errors.push(\n `InvalidValue: key ${key} should be a non-empty string, received ${\n typeof value === 'string' ? \"''\" : typeof value\n }`\n );\n }\n return;\n } else if (schema === 'object') {\n if (!value || Array.isArray(value) || typeof value !== 'object') {\n errors.push(`InvalidValue: key ${key} should be an object`);\n }\n return;\n } else if (schema === 'boolean') {\n if (typeof value !== 'boolean') {\n errors.push(`InvalidValue: key ${key} should be a boolean, received ${typeof value}`);\n }\n return;\n } else if (schema === 'array') {\n if (!Array.isArray(value)) {\n errors.push(`InvalidValue: key ${key} should be an array, received ${typeof value}`);\n }\n return;\n }\n }\n}\n\nconst IgnoredKeys = new Set<string>([]);\n\nexport function assertValidRequest(\n request: RequestInfo | Context,\n isTopLevel: boolean\n): asserts request is RequestInfo {\n if (DEBUG) {\n // handle basic shape\n if (!request) {\n throw new Error(\n `Expected ${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>) to be called with a request, but none was provided.`\n );\n }\n if (Array.isArray(request) || typeof request !== 'object') {\n throw new Error(\n `The \\`request\\` passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` should be an object, received \\`${niceTypeOf(request)}\\``\n );\n }\n if (Object.keys(request).length === 0) {\n throw new Error(\n `The \\`request\\` passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` was empty (\\`{}\\`). Requests need at least one valid key.`\n );\n }\n\n // handle accidentally passing context entirely\n if (request instanceof Context) {\n throw new Error(\n `Expected a request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` but received the previous handler's context instead`\n );\n }\n // handle Object.assign({}, context);\n if (isMaybeContext(request)) {\n throw new Error(\n `Expected a request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` but received an object with a request key instead.`\n );\n }\n\n // handle schema\n const keys = Object.keys(request) as Array<keyof RequestInfo>;\n const validationErrors: string[] = [];\n const isLegacyRequest = Boolean('op' in request && !request.url);\n keys.forEach((key) => {\n if (isLegacyRequest && key === 'data') {\n return;\n }\n validateKey(key, request[key], validationErrors);\n });\n if (validationErrors.length) {\n const error: Error & { errors: string[] } = new Error(\n `Invalid Request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\`.\\n\\nThe following issues were found:\\n\\n\\t${validationErrors.join('\\n\\t')}`\n ) as Error & { errors: string[] };\n error.errors = validationErrors;\n throw error;\n }\n }\n}\n"],"names":["PromiseCache","getOrSetUniversal","WeakMap","RequestMap","Map","setRequestResult","requestId","result","set","clearRequestResult","delete","getRequestResult","get","setPromiseResult","promise","getPromiseResult","IS_CACHE_HANDLER","getOrSetGlobal","Symbol","curryFuture","owner","inbound","outbound","setStream","getStream","then","doc","document","STRUCTURED","request","response","content","resolve","error","isDoc","god","stream","Error","e","Object","assign","message","getResponse","reject","ensureDoc","isError","enhanceReason","reason","DOMException","handleOutcome","controller","signal","aborted","isCacheHandler","handler","index","Boolean","executeNextHandler","wares","i","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","length","assertValidRequest","ContextOwner","next","r","nextCalled","context","Context","outcome","Promise","console","log","undefined","future","createFuture","isFuture","maybe","IS_FUTURE","createDeferred","res","rej","upgradePromise","abort","onFinalize","deferred","cbs","finally","resolveStream","forEach","cb","fn","push","upgradeHeaders","headers","clone","Headers","toJSON","Array","from","cloneResponseProperties","ok","redirected","status","statusText","type","url","hasSetStream","hasSetResponse","hasSubscribers","constructor","isRoot","id","sizeHint","addEventListener","enhancedRequest","cacheOptions","SkipCache","deepFreeze","hasRequestedStream","hint","parseInt","setResponse","Response","responseData","BODY_TYPES","klass","ValidKeys","IS_FROZEN","IS_COLLECTION","for","freezeHeaders","append","value","_type","_niceType","niceTypeOf","arr","map","freeze","keys","key","isMaybeContext","v","isArray","Date","Set","ReadableStream","WritableStream","TransformStream","name","validateKey","errors","schema","IgnoredKeys","has","includes","join","JSON","stringify","k","String","isTopLevel","validationErrors","isLegacyRequest"],"mappings":";;;;AAUO,MAAMA,YAAY,GAAGC,iBAAiB,CAAC,cAAc,EAAE,IAAIC,OAAO,EAA0B,CAAC,CAAA;AAC7F,MAAMC,UAAU,GAAGF,iBAAiB,CAAC,YAAY,EAAE,IAAIG,GAAG,EAAuB,CAAC,CAAA;AAElF,SAASC,gBAAgBA,CAACC,SAAiB,EAAEC,MAAmB,EAAE;AACvEJ,EAAAA,UAAU,CAACK,GAAG,CAACF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