diff --git a/docs/queryable/behaviors.md b/docs/queryable/behaviors.md index b7fb91964..5bc94e91f 100644 --- a/docs/queryable/behaviors.md +++ b/docs/queryable/behaviors.md @@ -176,19 +176,16 @@ export function Caching(props?: ICachingProps): TimelinePipe { const cached = getCachedValue(); // we need to ensure that result stays "undefined" unless we mean to set null as the result - if (cached === null) { + if (cached === null) { // if we don't have a cached result we need to get it after the request is sent. Get the raw value (un-parsed) to store into cache - this.on.rawData(noInherit(async function (response) { - setCachedValue(response); - })); + this.on.post(async function (url: URL, result: any) { + setCachedValue(result); + return [url, result]; + }); } else { - // if we find it in cache, override send request, and continue flow through timeline and parsers. - this.on.auth.clear(); - this.on.send.replace(async function (this: Queryable) { - return new Response(cached, {}); - }); + result = cached; } } diff --git a/packages/queryable/behaviors/caching.ts b/packages/queryable/behaviors/caching.ts index c88d402b4..f1dad8446 100644 --- a/packages/queryable/behaviors/caching.ts +++ b/packages/queryable/behaviors/caching.ts @@ -97,16 +97,13 @@ export function Caching(props?: ICachingProps): TimelinePipe { if (cached === null) { // if we don't have a cached result we need to get it after the request is sent. Get the raw value (un-parsed) to store into cache - instance.on.rawData(noInherit(async function (response) { - setCachedValue(response); + this.on.post(noInherit(async function (url: URL, result: any) { + setCachedValue(result); + return [url, result]; })); } else { - // if we find it in cache, override send request, and continue flow through timeline and parsers. - this.on.auth.clear(); - this.on.send.replace(async function (this: Queryable) { - return new Response(cached, {}); - }); + result = cached; } } diff --git a/packages/queryable/behaviors/parsers.ts b/packages/queryable/behaviors/parsers.ts index 753a5dd74..68b171310 100644 --- a/packages/queryable/behaviors/parsers.ts +++ b/packages/queryable/behaviors/parsers.ts @@ -108,12 +108,7 @@ export function parseBinderWithErrorCheck(impl: (r: Response) => Promise): instance.on.parse(async (url: URL, response: Response, result: any): Promise<[URL, Response, any]> => { if (response.ok && typeof result === "undefined") { - const respClone = response.clone(); - - // https://github.com/node-fetch/node-fetch?tab=readme-ov-file#custom-highwatermark - const [implResult, raw] = await Promise.all([impl(response), respClone.text()]); - result = implResult; - (instance).emit.rawData(raw); + result = await impl(response); } return [url, response, result]; diff --git a/packages/queryable/queryable.ts b/packages/queryable/queryable.ts index b1db19f6f..d30904fbe 100644 --- a/packages/queryable/queryable.ts +++ b/packages/queryable/queryable.ts @@ -25,7 +25,6 @@ const DefaultMoments = { parse: asyncReduce(), post: asyncReduce(), data: broadcast(), - rawData: broadcast(), } as const; export type QueryableInit = Queryable | string | [Queryable, string];