@ember-data-mirror/request 5.6.0-alpha.3 → 5.6.0-alpha.4
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/fetch.js +1 -2
- package/dist/fetch.js.map +1 -1
- package/dist/index.js +246 -252
- package/dist/index.js.map +1 -1
- package/package.json +5 -8
- package/unstable-preview-types/-private/manager.d.ts +0 -3
- package/unstable-preview-types/-private/manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/types.d.ts +5 -14
- package/unstable-preview-types/-private/types.d.ts.map +1 -1
- package/unstable-preview-types/fetch.d.ts +1 -2
- package/unstable-preview-types/fetch.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +4 -4
- package/unstable-preview-types/index.d.ts.map +1 -1
package/dist/fetch.js
CHANGED
|
@@ -11,8 +11,7 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
|
11
11
|
* manager.use([Fetch]);
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* @module
|
|
15
|
-
* @main @ember-data-mirror/request/fetch
|
|
14
|
+
* @module
|
|
16
15
|
*/
|
|
17
16
|
|
|
18
17
|
// Lazily close over fetch to avoid breaking Mirage
|
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\ninterface FastbootRequest {\n protocol: string;\n host: string;\n}\ninterface FastBoot {\n require(moduleName: string): unknown;\n isFastBoot: boolean;\n request: FastbootRequest;\n}\ndeclare global {\n const FastBoot: undefined | FastBoot;\n}\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 HttpErrorProps).statusText = 'Aborted';\n (e as HttpErrorProps).status = 20;\n (e 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;;AAoBA;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;AAClD,CAAmB;;AAE3B;AACA;AACA,SAASC,aAAaA,CAACC,QAAkB,EAAEC,SAA4B,EAAE;AACvE,EAAA,MAAMC,KAAK,GAAGC,uBAAuB,CAACH,QAAQ,CAAC;AAC/C,EAAA,OAAO,IAAII,QAAQ,CAAC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pD,UAAU,GAAGA,UAAU;MAC7BoD,KAAK,CAAClD,cAAc,GAAG,IAAI;AAC3BkD,MAAAA,KAAK,CAACE,IAAI,GAAGF,KAAK,CAACnD,MAAM;AACzBmD,MAAAA,KAAK,CAACrD,IAAI,GAAGqD,KAAK,CAACpD,UAAU,CAACuD,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,OAAO;MAC3DH,KAAK,CAACI,OAAO,GAAGf,YAAY;AAC5B,MAAA,MAAMW,KAAK;AACb,KAAC,MAAM;AACL,MAAA,OAAOV,IAAI,CAACC,KAAK,CAAC7B,IAAI,CAAC;AACzB;AACF;AACF;AAEA,SAASiC,MAAMA,CAACU,CAAU,EAAgC;AACxD,EAAA,OAAOA,CAAC,KAAK,IAAI,IAAI,OAAOA,CAAC,KAAK,QAAQ;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\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\ninterface FastbootRequest {\n protocol: string;\n host: string;\n}\ninterface FastBoot {\n require(moduleName: string): unknown;\n isFastBoot: boolean;\n request: FastbootRequest;\n}\ndeclare global {\n const FastBoot: undefined | FastBoot;\n}\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 HttpErrorProps).statusText = 'Aborted';\n (e as HttpErrorProps).status = 20;\n (e 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;;AAoBA;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;AAClD,CAAmB;;AAE3B;AACA;AACA,SAASC,aAAaA,CAACC,QAAkB,EAAEC,SAA4B,EAAE;AACvE,EAAA,MAAMC,KAAK,GAAGC,uBAAuB,CAACH,QAAQ,CAAC;AAC/C,EAAA,OAAO,IAAII,QAAQ,CAACJ,QAAQ,CAACK,IAAI,EAAEC,MAAM,CAACC,MAAM,CAACL,KAAK,EAAED,SAAS,CAAC,CAAC;AACrE;AAEA,IAAIO,eAAe,GAAGA,MAAM,KAAK;AACjC,IAAAC,cAAA,CAAAC,eAAA,EAAA,CAAAC,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAW,EAAA;AACTL,EAAAA,eAAe,GAAGA,MAChBM,OAAO,CACL,OAAOC,MAAM,KAAK,WAAW,KACzBA,MAAM,CAAyCC,MAAM,EAAEC,SAAS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L,MAAA,OAAOV,IAAI,CAACC,KAAK,CAAC7B,IAAI,CAAC;AACzB;AACF;AACF;AAEA,SAASiC,MAAMA,CAACU,CAAU,EAAgC;AACxD,EAAA,OAAOA,CAAC,KAAK,IAAI,IAAI,OAAOA,CAAC,KAAK,QAAQ;AAC5C;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,250 @@ import { peekUniversalTransient, setUniversalTransient } from '@warp-drive-mirro
|
|
|
4
4
|
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-CyVgT8K4.js";
|
|
5
5
|
export { b as createDeferred, d as getPromiseResult } from "./debug-CyVgT8K4.js";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* ```js
|
|
9
|
+
* import RequestManager from '@ember-data-mirror/request';
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* A RequestManager provides a request/response flow in which configured
|
|
13
|
+
* handlers are successively given the opportunity to handle, modify, or
|
|
14
|
+
* pass-along a request.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* interface RequestManager {
|
|
18
|
+
* request<T>(req: RequestInfo): Future<T>;
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* For example:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import RequestManager from '@ember-data-mirror/request';
|
|
26
|
+
* import Fetch from '@ember-data-mirror/request/fetch';
|
|
27
|
+
* import Auth from 'ember-simple-auth/ember-data-handler';
|
|
28
|
+
* import Config from './config';
|
|
29
|
+
*
|
|
30
|
+
* const { apiUrl } = Config;
|
|
31
|
+
*
|
|
32
|
+
* // ... create manager
|
|
33
|
+
* const manager = new RequestManager().use([Auth, Fetch]);
|
|
34
|
+
*
|
|
35
|
+
* // ... execute a request
|
|
36
|
+
* const response = await manager.request({
|
|
37
|
+
* url: `${apiUrl}/users`
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* ### Futures
|
|
42
|
+
*
|
|
43
|
+
* The return value of `manager.request` is a `Future`, which allows
|
|
44
|
+
* access to limited information about the request while it is still
|
|
45
|
+
* pending and fulfills with the final state when the request completes.
|
|
46
|
+
*
|
|
47
|
+
* A `Future` is cancellable via `abort`.
|
|
48
|
+
*
|
|
49
|
+
* Handlers may optionally expose a `ReadableStream` to the `Future` for
|
|
50
|
+
* streaming data; however, when doing so the future should not resolve
|
|
51
|
+
* until the response stream is fully read.
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* interface Future<T> extends Promise<StructuredDocument<T>> {
|
|
55
|
+
* abort(): void;
|
|
56
|
+
*
|
|
57
|
+
* async getStream(): ReadableStream | null;
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* ### StructuredDocuments
|
|
62
|
+
*
|
|
63
|
+
* A Future resolves with a `StructuredDataDocument` or rejects with a `StructuredErrorDocument`.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* interface StructuredDataDocument<T> {
|
|
67
|
+
* request: ImmutableRequestInfo;
|
|
68
|
+
* response: ImmutableResponseInfo;
|
|
69
|
+
* content: T;
|
|
70
|
+
* }
|
|
71
|
+
* interface StructuredErrorDocument extends Error {
|
|
72
|
+
* request: ImmutableRequestInfo;
|
|
73
|
+
* response: ImmutableResponseInfo;
|
|
74
|
+
* error: string | object;
|
|
75
|
+
* }
|
|
76
|
+
* type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @class RequestManager
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
class RequestManager {
|
|
83
|
+
#handlers = [];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A map of pending requests from request.id to their
|
|
87
|
+
* associated CacheHandler promise.
|
|
88
|
+
*
|
|
89
|
+
* This queue is managed by the CacheHandler
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
constructor(options) {
|
|
95
|
+
Object.assign(this, options);
|
|
96
|
+
this._pending = new Map();
|
|
97
|
+
this._deduped = new Map();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Register a handler to use for primary cache intercept.
|
|
102
|
+
*
|
|
103
|
+
* Only one such handler may exist. If using the same
|
|
104
|
+
* RequestManager as the Store instance the Store
|
|
105
|
+
* registers itself as a Cache handler.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
* @param {Handler[]} cacheHandler
|
|
109
|
+
* @return {ThisType}
|
|
110
|
+
*/
|
|
111
|
+
useCache(cacheHandler) {
|
|
112
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
113
|
+
if (this._hasCacheHandler) {
|
|
114
|
+
throw new Error(`\`RequestManager.useCache(<handler>)\` May only be invoked once.`);
|
|
115
|
+
}
|
|
116
|
+
if (Object.isFrozen(this.#handlers)) {
|
|
117
|
+
throw new Error(`\`RequestManager.useCache(<handler>)\` May only be invoked prior to any request having been made.`);
|
|
118
|
+
}
|
|
119
|
+
this._hasCacheHandler = true;
|
|
120
|
+
}
|
|
121
|
+
cacheHandler[IS_CACHE_HANDLER] = true;
|
|
122
|
+
this.#handlers.unshift(cacheHandler);
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Register handler(s) to use when a request is issued.
|
|
128
|
+
*
|
|
129
|
+
* Handlers will be invoked in the order they are registered.
|
|
130
|
+
* Each Handler is given the opportunity to handle the request,
|
|
131
|
+
* curry the request, or pass along a modified request.
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
* @param {Handler[]} newHandlers
|
|
135
|
+
* @return {ThisType}
|
|
136
|
+
*/
|
|
137
|
+
use(newHandlers) {
|
|
138
|
+
const handlers = this.#handlers;
|
|
139
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
140
|
+
if (Object.isFrozen(handlers)) {
|
|
141
|
+
throw new Error(`Cannot add a Handler to a RequestManager after a request has been made`);
|
|
142
|
+
}
|
|
143
|
+
if (!Array.isArray(newHandlers)) {
|
|
144
|
+
throw new Error(`\`RequestManager.use(<Handler[]>)\` expects an array of handlers, but was called with \`${typeof newHandlers}\``);
|
|
145
|
+
}
|
|
146
|
+
newHandlers.forEach((handler, index) => {
|
|
147
|
+
if (!handler || typeof handler !== 'object' || typeof handler.request !== 'function') {
|
|
148
|
+
throw new Error(`\`RequestManager.use(<Handler[]>)\` expected to receive an array of handler objects with request methods, by the handler at index ${index} does not conform.`);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
handlers.push(...newHandlers);
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Issue a Request.
|
|
158
|
+
*
|
|
159
|
+
* Returns a Future that fulfills with a StructuredDocument
|
|
160
|
+
*
|
|
161
|
+
* @public
|
|
162
|
+
* @param {RequestInfo} request
|
|
163
|
+
* @return {Future}
|
|
164
|
+
*/
|
|
165
|
+
request(request) {
|
|
166
|
+
const handlers = this.#handlers;
|
|
167
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
168
|
+
if (!Object.isFrozen(handlers)) {
|
|
169
|
+
Object.freeze(handlers);
|
|
170
|
+
}
|
|
171
|
+
assertValidRequest(request, true);
|
|
172
|
+
}
|
|
173
|
+
const controller = request.controller || new AbortController();
|
|
174
|
+
if (request.controller) {
|
|
175
|
+
delete request.controller;
|
|
176
|
+
}
|
|
177
|
+
const requestId = peekUniversalTransient('REQ_ID') ?? 0;
|
|
178
|
+
setUniversalTransient('REQ_ID', requestId + 1);
|
|
179
|
+
const context = {
|
|
180
|
+
controller,
|
|
181
|
+
response: null,
|
|
182
|
+
stream: null,
|
|
183
|
+
hasRequestedStream: false,
|
|
184
|
+
id: requestId,
|
|
185
|
+
identifier: null
|
|
186
|
+
};
|
|
187
|
+
const promise = executeNextHandler(handlers, request, 0, context);
|
|
188
|
+
|
|
189
|
+
// the cache handler will set the result of the request synchronously
|
|
190
|
+
// if it is able to fulfill the request from the cache
|
|
191
|
+
const cacheResult = getRequestResult(requestId);
|
|
192
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
|
|
193
|
+
if (!request.disableTestWaiter) {
|
|
194
|
+
const {
|
|
195
|
+
waitForPromise
|
|
196
|
+
} = importSync('@ember/test-waiters');
|
|
197
|
+
const newPromise = waitForPromise(promise);
|
|
198
|
+
const finalPromise = upgradePromise(newPromise.then(result => {
|
|
199
|
+
setPromiseResult(finalPromise, {
|
|
200
|
+
isError: false,
|
|
201
|
+
result
|
|
202
|
+
});
|
|
203
|
+
clearRequestResult(requestId);
|
|
204
|
+
return result;
|
|
205
|
+
}, error => {
|
|
206
|
+
setPromiseResult(finalPromise, {
|
|
207
|
+
isError: true,
|
|
208
|
+
result: error
|
|
209
|
+
});
|
|
210
|
+
clearRequestResult(requestId);
|
|
211
|
+
throw error;
|
|
212
|
+
}), promise);
|
|
213
|
+
if (cacheResult) {
|
|
214
|
+
setPromiseResult(finalPromise, cacheResult);
|
|
215
|
+
}
|
|
216
|
+
return finalPromise;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// const promise1 = store.request(myRequest);
|
|
221
|
+
// const promise2 = store.request(myRequest);
|
|
222
|
+
// promise1 === promise2; // false
|
|
223
|
+
// either we need to make promise1 === promise2, or we need to make sure that
|
|
224
|
+
// we need to have a way to key from request to result
|
|
225
|
+
// such that we can lookup the result here and return it if it exists
|
|
226
|
+
const finalPromise = upgradePromise(promise.then(result => {
|
|
227
|
+
setPromiseResult(finalPromise, {
|
|
228
|
+
isError: false,
|
|
229
|
+
result
|
|
230
|
+
});
|
|
231
|
+
clearRequestResult(requestId);
|
|
232
|
+
return result;
|
|
233
|
+
}, error => {
|
|
234
|
+
setPromiseResult(finalPromise, {
|
|
235
|
+
isError: true,
|
|
236
|
+
result: error
|
|
237
|
+
});
|
|
238
|
+
clearRequestResult(requestId);
|
|
239
|
+
throw error;
|
|
240
|
+
}), promise);
|
|
241
|
+
if (cacheResult) {
|
|
242
|
+
setPromiseResult(finalPromise, cacheResult);
|
|
243
|
+
}
|
|
244
|
+
return finalPromise;
|
|
245
|
+
}
|
|
246
|
+
static create(options) {
|
|
247
|
+
return new this(options);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
8
251
|
/**
|
|
9
252
|
*
|
|
10
253
|
<p align="center">
|
|
@@ -330,7 +573,7 @@ code *while chunks are still being received by the browser*.
|
|
|
330
573
|
|
|
331
574
|
When an app chooses to `await response.json()` what occurs is the browser reads the stream to completion and then returns the result. Additionally, this stream may only be read **once**.
|
|
332
575
|
|
|
333
|
-
The `RequestManager` preserves this ability to subscribe to and utilize the stream by either the application or the handler –
|
|
576
|
+
The `RequestManager` preserves this ability to subscribe to and utilize the stream by either the application or the handler – thereby delivering the full power and flexibility of native APIs – without restricting developers in ways that lead to complicated workarounds.
|
|
334
577
|
|
|
335
578
|
Each handler may call `setStream` only once, but may do so *at any time* until the promise that the handler returns has resolved. The associated promise returned by calling `future.getStream` will resolve with the stream set by `setStream` if that method is called, or `null` if that method
|
|
336
579
|
has not been called by the time that the handler's request method has resolved.
|
|
@@ -430,257 +673,8 @@ For usage of the store's `requestManager` via `store.request(<req>)` see the
|
|
|
430
673
|
[Store](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fstore) documentation.
|
|
431
674
|
|
|
432
675
|
*
|
|
433
|
-
* @module
|
|
434
|
-
* @main @ember-data-mirror/request
|
|
676
|
+
* @module
|
|
435
677
|
*/
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* ```js
|
|
439
|
-
* import RequestManager from '@ember-data-mirror/request';
|
|
440
|
-
* ```
|
|
441
|
-
*
|
|
442
|
-
* A RequestManager provides a request/response flow in which configured
|
|
443
|
-
* handlers are successively given the opportunity to handle, modify, or
|
|
444
|
-
* pass-along a request.
|
|
445
|
-
*
|
|
446
|
-
* ```ts
|
|
447
|
-
* interface RequestManager {
|
|
448
|
-
* request<T>(req: RequestInfo): Future<T>;
|
|
449
|
-
* }
|
|
450
|
-
* ```
|
|
451
|
-
*
|
|
452
|
-
* For example:
|
|
453
|
-
*
|
|
454
|
-
* ```ts
|
|
455
|
-
* import RequestManager from '@ember-data-mirror/request';
|
|
456
|
-
* import Fetch from '@ember-data-mirror/request/fetch';
|
|
457
|
-
* import Auth from 'ember-simple-auth/ember-data-handler';
|
|
458
|
-
* import Config from './config';
|
|
459
|
-
*
|
|
460
|
-
* const { apiUrl } = Config;
|
|
461
|
-
*
|
|
462
|
-
* // ... create manager
|
|
463
|
-
* const manager = new RequestManager().use([Auth, Fetch]);
|
|
464
|
-
*
|
|
465
|
-
* // ... execute a request
|
|
466
|
-
* const response = await manager.request({
|
|
467
|
-
* url: `${apiUrl}/users`
|
|
468
|
-
* });
|
|
469
|
-
* ```
|
|
470
|
-
*
|
|
471
|
-
* ### Futures
|
|
472
|
-
*
|
|
473
|
-
* The return value of `manager.request` is a `Future`, which allows
|
|
474
|
-
* access to limited information about the request while it is still
|
|
475
|
-
* pending and fulfills with the final state when the request completes.
|
|
476
|
-
*
|
|
477
|
-
* A `Future` is cancellable via `abort`.
|
|
478
|
-
*
|
|
479
|
-
* Handlers may optionally expose a `ReadableStream` to the `Future` for
|
|
480
|
-
* streaming data; however, when doing so the future should not resolve
|
|
481
|
-
* until the response stream is fully read.
|
|
482
|
-
*
|
|
483
|
-
* ```ts
|
|
484
|
-
* interface Future<T> extends Promise<StructuredDocument<T>> {
|
|
485
|
-
* abort(): void;
|
|
486
|
-
*
|
|
487
|
-
* async getStream(): ReadableStream | null;
|
|
488
|
-
* }
|
|
489
|
-
* ```
|
|
490
|
-
*
|
|
491
|
-
* ### StructuredDocuments
|
|
492
|
-
*
|
|
493
|
-
* A Future resolves with a `StructuredDataDocument` or rejects with a `StructuredErrorDocument`.
|
|
494
|
-
*
|
|
495
|
-
* ```ts
|
|
496
|
-
* interface StructuredDataDocument<T> {
|
|
497
|
-
* request: ImmutableRequestInfo;
|
|
498
|
-
* response: ImmutableResponseInfo;
|
|
499
|
-
* content: T;
|
|
500
|
-
* }
|
|
501
|
-
* interface StructuredErrorDocument extends Error {
|
|
502
|
-
* request: ImmutableRequestInfo;
|
|
503
|
-
* response: ImmutableResponseInfo;
|
|
504
|
-
* error: string | object;
|
|
505
|
-
* }
|
|
506
|
-
* type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;
|
|
507
|
-
* ```
|
|
508
|
-
*
|
|
509
|
-
* @class RequestManager
|
|
510
|
-
* @public
|
|
511
|
-
*/
|
|
512
|
-
class RequestManager {
|
|
513
|
-
#handlers = [];
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* A map of pending requests from request.id to their
|
|
517
|
-
* associated CacheHandler promise.
|
|
518
|
-
*
|
|
519
|
-
* This queue is managed by the CacheHandler
|
|
520
|
-
*
|
|
521
|
-
* @internal
|
|
522
|
-
*/
|
|
523
|
-
|
|
524
|
-
constructor(options) {
|
|
525
|
-
Object.assign(this, options);
|
|
526
|
-
this._pending = new Map();
|
|
527
|
-
this._deduped = new Map();
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Register a handler to use for primary cache intercept.
|
|
532
|
-
*
|
|
533
|
-
* Only one such handler may exist. If using the same
|
|
534
|
-
* RequestManager as the Store instance the Store
|
|
535
|
-
* registers itself as a Cache handler.
|
|
536
|
-
*
|
|
537
|
-
* @method useCache
|
|
538
|
-
* @public
|
|
539
|
-
* @param {Handler[]} cacheHandler
|
|
540
|
-
* @return {ThisType}
|
|
541
|
-
*/
|
|
542
|
-
useCache(cacheHandler) {
|
|
543
|
-
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
544
|
-
if (this._hasCacheHandler) {
|
|
545
|
-
throw new Error(`\`RequestManager.useCache(<handler>)\` May only be invoked once.`);
|
|
546
|
-
}
|
|
547
|
-
if (Object.isFrozen(this.#handlers)) {
|
|
548
|
-
throw new Error(`\`RequestManager.useCache(<handler>)\` May only be invoked prior to any request having been made.`);
|
|
549
|
-
}
|
|
550
|
-
this._hasCacheHandler = true;
|
|
551
|
-
}
|
|
552
|
-
cacheHandler[IS_CACHE_HANDLER] = true;
|
|
553
|
-
this.#handlers.unshift(cacheHandler);
|
|
554
|
-
return this;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* Register handler(s) to use when a request is issued.
|
|
559
|
-
*
|
|
560
|
-
* Handlers will be invoked in the order they are registered.
|
|
561
|
-
* Each Handler is given the opportunity to handle the request,
|
|
562
|
-
* curry the request, or pass along a modified request.
|
|
563
|
-
*
|
|
564
|
-
* @method use
|
|
565
|
-
* @public
|
|
566
|
-
* @param {Handler[]} newHandlers
|
|
567
|
-
* @return {ThisType}
|
|
568
|
-
*/
|
|
569
|
-
use(newHandlers) {
|
|
570
|
-
const handlers = this.#handlers;
|
|
571
|
-
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
572
|
-
if (Object.isFrozen(handlers)) {
|
|
573
|
-
throw new Error(`Cannot add a Handler to a RequestManager after a request has been made`);
|
|
574
|
-
}
|
|
575
|
-
if (!Array.isArray(newHandlers)) {
|
|
576
|
-
throw new Error(`\`RequestManager.use(<Handler[]>)\` expects an array of handlers, but was called with \`${typeof newHandlers}\``);
|
|
577
|
-
}
|
|
578
|
-
newHandlers.forEach((handler, index) => {
|
|
579
|
-
if (!handler || typeof handler !== 'object' || typeof handler.request !== 'function') {
|
|
580
|
-
throw new Error(`\`RequestManager.use(<Handler[]>)\` expected to receive an array of handler objects with request methods, by the handler at index ${index} does not conform.`);
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
handlers.push(...newHandlers);
|
|
585
|
-
return this;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* Issue a Request.
|
|
590
|
-
*
|
|
591
|
-
* Returns a Future that fulfills with a StructuredDocument
|
|
592
|
-
*
|
|
593
|
-
* @method request
|
|
594
|
-
* @public
|
|
595
|
-
* @param {RequestInfo} request
|
|
596
|
-
* @return {Future}
|
|
597
|
-
*/
|
|
598
|
-
request(request) {
|
|
599
|
-
const handlers = this.#handlers;
|
|
600
|
-
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
601
|
-
if (!Object.isFrozen(handlers)) {
|
|
602
|
-
Object.freeze(handlers);
|
|
603
|
-
}
|
|
604
|
-
assertValidRequest(request, true);
|
|
605
|
-
}
|
|
606
|
-
const controller = request.controller || new AbortController();
|
|
607
|
-
if (request.controller) {
|
|
608
|
-
delete request.controller;
|
|
609
|
-
}
|
|
610
|
-
const requestId = peekUniversalTransient('REQ_ID') ?? 0;
|
|
611
|
-
setUniversalTransient('REQ_ID', requestId + 1);
|
|
612
|
-
const context = {
|
|
613
|
-
controller,
|
|
614
|
-
response: null,
|
|
615
|
-
stream: null,
|
|
616
|
-
hasRequestedStream: false,
|
|
617
|
-
id: requestId,
|
|
618
|
-
identifier: null
|
|
619
|
-
};
|
|
620
|
-
const promise = executeNextHandler(handlers, request, 0, context);
|
|
621
|
-
|
|
622
|
-
// the cache handler will set the result of the request synchronously
|
|
623
|
-
// if it is able to fulfill the request from the cache
|
|
624
|
-
const cacheResult = getRequestResult(requestId);
|
|
625
|
-
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
|
|
626
|
-
if (!request.disableTestWaiter) {
|
|
627
|
-
const {
|
|
628
|
-
waitForPromise
|
|
629
|
-
} = importSync('@ember/test-waiters');
|
|
630
|
-
const newPromise = waitForPromise(promise);
|
|
631
|
-
const finalPromise = upgradePromise(newPromise.then(result => {
|
|
632
|
-
setPromiseResult(finalPromise, {
|
|
633
|
-
isError: false,
|
|
634
|
-
result
|
|
635
|
-
});
|
|
636
|
-
clearRequestResult(requestId);
|
|
637
|
-
return result;
|
|
638
|
-
}, error => {
|
|
639
|
-
setPromiseResult(finalPromise, {
|
|
640
|
-
isError: true,
|
|
641
|
-
result: error
|
|
642
|
-
});
|
|
643
|
-
clearRequestResult(requestId);
|
|
644
|
-
throw error;
|
|
645
|
-
}), promise);
|
|
646
|
-
if (cacheResult) {
|
|
647
|
-
setPromiseResult(finalPromise, cacheResult);
|
|
648
|
-
}
|
|
649
|
-
return finalPromise;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
// const promise1 = store.request(myRequest);
|
|
654
|
-
// const promise2 = store.request(myRequest);
|
|
655
|
-
// promise1 === promise2; // false
|
|
656
|
-
// either we need to make promise1 === promise2, or we need to make sure that
|
|
657
|
-
// we need to have a way to key from request to result
|
|
658
|
-
// such that we can lookup the result here and return it if it exists
|
|
659
|
-
const finalPromise = upgradePromise(promise.then(result => {
|
|
660
|
-
setPromiseResult(finalPromise, {
|
|
661
|
-
isError: false,
|
|
662
|
-
result
|
|
663
|
-
});
|
|
664
|
-
clearRequestResult(requestId);
|
|
665
|
-
return result;
|
|
666
|
-
}, error => {
|
|
667
|
-
setPromiseResult(finalPromise, {
|
|
668
|
-
isError: true,
|
|
669
|
-
result: error
|
|
670
|
-
});
|
|
671
|
-
clearRequestResult(requestId);
|
|
672
|
-
throw error;
|
|
673
|
-
}), promise);
|
|
674
|
-
if (cacheResult) {
|
|
675
|
-
setPromiseResult(finalPromise, cacheResult);
|
|
676
|
-
}
|
|
677
|
-
return finalPromise;
|
|
678
|
-
}
|
|
679
|
-
static create(options) {
|
|
680
|
-
return new this(options);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
|
|
684
678
|
// @ts-expect-error adding to globalThis
|
|
685
679
|
globalThis.setWarpDriveLogging = setLogging;
|
|
686
680
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/-private/manager.ts","../src/index.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()\n .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 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 .use([Fetch])\n .useCache(CacheHandler);\n}\n```\n\n---\n\n### Using as a Service\n\nSome 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 { CacheHandler } from '@ember-data-mirror/store';\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 {\n create() {\n return new RequestManager()\n .use([Auth, Fetch])\n .use(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 from 'ember-data-mirror/store';\nimport { 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 .use([LegacyNetworkHandler, Fetch])\n .useCache(CacheHandler);\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<RT, T>): 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","import { getRuntimeConfig, setLogging } from '@warp-drive-mirror/core-types/runtime';\n\nexport { RequestManager as default } from './-private/manager';\nexport { createDeferred } from './-private/future';\nexport type { Future, Handler, CacheHandler, NextFn } from './-private/types';\nexport type {\n RequestContext,\n ImmutableRequestInfo,\n RequestInfo,\n ResponseInfo,\n StructuredDocument,\n StructuredErrorDocument,\n StructuredDataDocument,\n} from '@warp-drive-mirror/core-types/request';\nexport { setPromiseResult, getPromiseResult } from './-private/promise-cache';\nexport type { Awaitable } from './-private/promise-cache';\n\n// @ts-expect-error adding to globalThis\nglobalThis.setWarpDriveLogging = setLogging;\n\n// @ts-expect-error adding to globalThis\nglobalThis.getWarpDriveRuntimeConfig = getRuntimeConfig;\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","globalThis","setWarpDriveLogging","setLogging","getWarpDriveRuntimeConfig","getRuntimeConfig"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAGA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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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AW,CAAC;AAC7C;AAEA,QAAA,OAAOO,YAAY;AACrB;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;IACA,MAAMA,YAAY,GAAGC,cAAc,CACjCV,OAAO,CAACW,IAAI,CACTC,MAAM,IAAK;MACVC,gBAAgB,CAACJ,YAAY,EAAE;AAAEK,QAAAA,OAAO,EAAE,KAAK;AAAEF,QAAAA;AAAO,OAAC,CAAC;MAC1DG,kBAAkB,CAACxB,SAAS,CAAC;AAC7B,MAAA,OAAOqB,MAAM;KACd,EACAI,KAA8B,IAAK;MAClCH,gBAAgB,CAACJ,YAAY,EAAE;AAAEK,QAAAA,OAAO,EAAE,IAAI;AAAEF,QAAAA,MAAM,EAAEI;AAAM,OAAC,CAAC;MAChED,kBAAkB,CAACxB,SAAS,CAAC;AAC7B,MAAA,MAAMyB,KAAK;KAEf,CAAC,EACDhB,OACF,CAAC;AAED,IAAA,IAAIE,WAAW,EAAE;AACfW,MAAAA,gBAAgB,CAACJ,YAAY,EAAEP,WAAW,CAAC;AAC7C;AAEA,IAAA,OAAOO,YAAY;AACrB;EAEA,OAAOQ,MAAMA,CAAC1D,OAA2B,EAAE;AACzC,IAAA,OAAO,IAAI,IAAI,CAACA,OAAO,CAAC;AAC1B;AACF;;AC/qBA;AACA2D,UAAU,CAACC,mBAAmB,GAAGC,UAAU;;AAE3C;AACAF,UAAU,CAACG,yBAAyB,GAAGC,gBAAgB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/-private/manager.ts","../src/index.ts"],"sourcesContent":["import { 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 * @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 * @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 * @public\n * @param {RequestInfo} request\n * @return {Future}\n */\n request<RT, T = unknown>(request: RequestInfo<RT, T>): 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","/**\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()\n .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 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 .use([Fetch])\n .useCache(CacheHandler);\n}\n```\n\n---\n\n### Using as a Service\n\nSome 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 { CacheHandler } from '@ember-data-mirror/store';\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 {\n create() {\n return new RequestManager()\n .use([Auth, Fetch])\n .use(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 from 'ember-data-mirror/store';\nimport { 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 .use([LegacyNetworkHandler, Fetch])\n .useCache(CacheHandler);\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\n */\nimport { getRuntimeConfig, setLogging } from '@warp-drive-mirror/core-types/runtime';\n\nexport { RequestManager as default } from './-private/manager';\nexport { createDeferred } from './-private/future';\nexport type { Future, Handler, CacheHandler, NextFn } from './-private/types';\nexport type {\n RequestContext,\n ImmutableRequestInfo,\n RequestInfo,\n ResponseInfo,\n StructuredDocument,\n StructuredErrorDocument,\n StructuredDataDocument,\n} from '@warp-drive-mirror/core-types/request';\nexport { setPromiseResult, getPromiseResult } from './-private/promise-cache';\nexport type { Awaitable } from './-private/promise-cache';\n\n// @ts-expect-error adding to globalThis\nglobalThis.setWarpDriveLogging = setLogging;\n\n// @ts-expect-error adding to globalThis\nglobalThis.getWarpDriveRuntimeConfig = getRuntimeConfig;\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","globalThis","setWarpDriveLogging","setLogging","getWarpDriveRuntimeConfig","getRuntimeConfig"],"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;A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;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAGA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AAkBA;AACA2D,UAAU,CAACC,mBAAmB,GAAGC,UAAU;;AAE3C;AACAF,UAAU,CAACG,yBAAyB,GAAGC,gBAAgB;;;;"}
|
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.6.0-alpha.
|
|
4
|
+
"version": "5.6.0-alpha.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chris Thoburn <runspired@users.noreply.github.com>",
|
|
7
7
|
"repository": {
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@warp-drive-mirror/core-types": "5.6.0-alpha.
|
|
37
|
+
"@warp-drive-mirror/core-types": "5.6.0-alpha.4",
|
|
38
38
|
"@ember/test-waiters": "^3.1.0 || ^4.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@embroider/macros": "^1.16.12",
|
|
42
|
-
"@warp-drive-mirror/build-config": "5.6.0-alpha.
|
|
42
|
+
"@warp-drive-mirror/build-config": "5.6.0-alpha.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@babel/core": "^7.26.10",
|
|
@@ -47,15 +47,12 @@
|
|
|
47
47
|
"@babel/preset-env": "^7.26.9",
|
|
48
48
|
"@babel/preset-typescript": "^7.27.0",
|
|
49
49
|
"@glimmer/component": "^2.0.0",
|
|
50
|
-
"@warp-drive-mirror/core-types": "5.6.0-alpha.
|
|
51
|
-
"@warp-drive/internal-config": "5.6.0-alpha.
|
|
50
|
+
"@warp-drive-mirror/core-types": "5.6.0-alpha.4",
|
|
51
|
+
"@warp-drive/internal-config": "5.6.0-alpha.4",
|
|
52
52
|
"@ember/test-waiters": "^4.1.0",
|
|
53
53
|
"ember-source": "~6.3.0",
|
|
54
54
|
"vite": "^5.4.15"
|
|
55
55
|
},
|
|
56
|
-
"engines": {
|
|
57
|
-
"node": ">= 18.20.8"
|
|
58
|
-
},
|
|
59
56
|
"volta": {
|
|
60
57
|
"extends": "../../../../../../package.json"
|
|
61
58
|
},
|
|
@@ -102,7 +102,6 @@ declare module '@ember-data-mirror/request/-private/manager' {
|
|
|
102
102
|
* RequestManager as the Store instance the Store
|
|
103
103
|
* registers itself as a Cache handler.
|
|
104
104
|
*
|
|
105
|
-
* @method useCache
|
|
106
105
|
* @public
|
|
107
106
|
* @param {Handler[]} cacheHandler
|
|
108
107
|
* @return {ThisType}
|
|
@@ -117,7 +116,6 @@ declare module '@ember-data-mirror/request/-private/manager' {
|
|
|
117
116
|
* Each Handler is given the opportunity to handle the request,
|
|
118
117
|
* curry the request, or pass along a modified request.
|
|
119
118
|
*
|
|
120
|
-
* @method use
|
|
121
119
|
* @public
|
|
122
120
|
* @param {Handler[]} newHandlers
|
|
123
121
|
* @return {ThisType}
|
|
@@ -128,7 +126,6 @@ declare module '@ember-data-mirror/request/-private/manager' {
|
|
|
128
126
|
*
|
|
129
127
|
* Returns a Future that fulfills with a StructuredDocument
|
|
130
128
|
*
|
|
131
|
-
* @method request
|
|
132
129
|
* @public
|
|
133
130
|
* @param {RequestInfo} request
|
|
134
131
|
* @return {Future}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/-private/manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/-private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
|
|
2
2
|
import type { StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';
|
|
3
3
|
import type { IS_FUTURE, RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from '@warp-drive-mirror/core-types/request';
|
|
4
|
-
/**
|
|
5
|
-
* @module @ember-data-mirror/request
|
|
6
|
-
*/
|
|
7
4
|
export interface GodContext {
|
|
8
5
|
controller: AbortController;
|
|
9
6
|
response: ResponseInfo | null;
|
|
@@ -33,15 +30,13 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
33
30
|
* `getStream` the response before the outer promise resolves;
|
|
34
31
|
*
|
|
35
32
|
* @class Future
|
|
36
|
-
* @extends Promise
|
|
37
33
|
* @public
|
|
38
34
|
*/
|
|
39
|
-
export
|
|
35
|
+
export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
40
36
|
[IS_FUTURE]: true;
|
|
41
37
|
/**
|
|
42
38
|
* Cancel this request by firing the AbortController's signal.
|
|
43
39
|
*
|
|
44
|
-
* @method abort
|
|
45
40
|
* @param {String} [reason] optional reason for aborting the request
|
|
46
41
|
* @public
|
|
47
42
|
* @return {void}
|
|
@@ -50,7 +45,6 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
50
45
|
/**
|
|
51
46
|
* Get the response stream, if any, once made available.
|
|
52
47
|
*
|
|
53
|
-
* @method getStream
|
|
54
48
|
* @public
|
|
55
49
|
* @return {Promise<ReadableStream | null>}
|
|
56
50
|
*/
|
|
@@ -59,10 +53,9 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
59
53
|
* Run a callback when this request completes. Use sparingly,
|
|
60
54
|
* mostly useful for instrumentation and infrastructure.
|
|
61
55
|
*
|
|
62
|
-
* @method onFinalize
|
|
63
56
|
* @param cb the callback to run
|
|
64
57
|
* @public
|
|
65
|
-
* @return void
|
|
58
|
+
* @return {void}
|
|
66
59
|
*/
|
|
67
60
|
onFinalize(cb: () => void): void;
|
|
68
61
|
/**
|
|
@@ -83,7 +76,7 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
83
76
|
* @public
|
|
84
77
|
*/
|
|
85
78
|
id: number;
|
|
86
|
-
}
|
|
79
|
+
}
|
|
87
80
|
export type DeferredFuture<T> = {
|
|
88
81
|
resolve(v: StructuredDataDocument<T>): void;
|
|
89
82
|
reject(v: unknown): void;
|
|
@@ -198,7 +191,7 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
198
191
|
Handlers will be invoked in the order they are registered ("fifo", first-in first-out), and may only be registered up until the first request is made. It is recommended but not required to register all handlers at one time in order to ensure explicitly visible handler ordering.
|
|
199
192
|
|
|
200
193
|
|
|
201
|
-
@class
|
|
194
|
+
@class (Interface) Handler
|
|
202
195
|
@public
|
|
203
196
|
*/
|
|
204
197
|
export interface Handler {
|
|
@@ -207,7 +200,6 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
207
200
|
* context and a nextFn to call to pass-along the request to
|
|
208
201
|
* other handlers.
|
|
209
202
|
*
|
|
210
|
-
* @method request
|
|
211
203
|
* @public
|
|
212
204
|
* @param context
|
|
213
205
|
* @param next
|
|
@@ -222,7 +214,7 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
222
214
|
* A RequestManager may only have one CacheHandler, registered via
|
|
223
215
|
* `manager.useCache(CacheHandler)`.
|
|
224
216
|
*
|
|
225
|
-
* @class
|
|
217
|
+
* @class (Interface) CacheHandler
|
|
226
218
|
* @public
|
|
227
219
|
*/
|
|
228
220
|
export interface CacheHandler {
|
|
@@ -231,7 +223,6 @@ declare module '@ember-data-mirror/request/-private/types' {
|
|
|
231
223
|
* context and a nextFn to call to pass-along the request to
|
|
232
224
|
* other handlers.
|
|
233
225
|
*
|
|
234
|
-
* @method request
|
|
235
226
|
* @public
|
|
236
227
|
* @param context
|
|
237
228
|
* @param next
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/-private/types.ts"],"names":[],"mappings":"AAE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,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;CACpH;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,GAAG,OAAO,EACjB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GACd,OAAO,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC;CACX;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -9,8 +9,7 @@ declare module '@ember-data-mirror/request/fetch' {
|
|
|
9
9
|
* manager.use([Fetch]);
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @module
|
|
13
|
-
* @main @ember-data-mirror/request/fetch
|
|
12
|
+
* @module
|
|
14
13
|
*/
|
|
15
14
|
import { type Context } from '@ember-data-mirror/request/-private/context';
|
|
16
15
|
interface FastbootRequest {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG3E,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AACD,UAAU,QAAQ;IAChB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,eAAe,CAAC;CAC1B;AACD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAC;CACtC;AA6ED;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,KAAK;YACK,CAAC,WAAW,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAgJ/C,CAAC;AAMF,eAAe,KAAK,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference path="./fetch.d.ts" />
|
|
2
|
-
/// <reference path="./-private/utils.d.ts" />
|
|
3
|
-
/// <reference path="./-private/types.d.ts" />
|
|
4
|
-
/// <reference path="./-private/debug.d.ts" />
|
|
5
2
|
/// <reference path="./-private/context.d.ts" />
|
|
6
3
|
/// <reference path="./-private/manager.d.ts" />
|
|
7
|
-
/// <reference path="./-private/
|
|
4
|
+
/// <reference path="./-private/types.d.ts" />
|
|
5
|
+
/// <reference path="./-private/utils.d.ts" />
|
|
6
|
+
/// <reference path="./-private/debug.d.ts" />
|
|
8
7
|
/// <reference path="./-private/future.d.ts" />
|
|
8
|
+
/// <reference path="./-private/promise-cache.d.ts" />
|
|
9
9
|
declare module '@ember-data-mirror/request' {
|
|
10
10
|
export { RequestManager as default } from '@ember-data-mirror/request/-private/manager';
|
|
11
11
|
export { createDeferred } from '@ember-data-mirror/request/-private/future';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA6aA,OAAO,EAAE,cAAc,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9E,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC9E,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC"}
|