@fromdeno/cache
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
export declare class CacheEntry { | ||
@@ -20,3 +21,3 @@ /** Input URL */ | ||
*/ | ||
read(): Promise<Response>; | ||
read(options?: Deno.ReadFileOptions): Promise<Response>; | ||
/** | ||
@@ -28,3 +29,3 @@ * Stores the response in cache. | ||
} | ||
import { Response } from "./shim.node.js"; | ||
import { Response, URL, Deno } from "./shim.node.js"; | ||
//# sourceMappingURL=entry.d.ts.map |
@@ -45,6 +45,6 @@ import { Path, sha256 } from "./deps.node.js"; | ||
*/ | ||
async read() { | ||
async read(options) { | ||
const [body, meta] = await Promise.all([ | ||
Deno.readFile(this.path), | ||
Deno.readTextFile(this.metaPath).then(JSON.parse), | ||
Deno.readFile(this.path, options), | ||
Deno.readTextFile(this.metaPath, options).then(JSON.parse), | ||
]); | ||
@@ -69,2 +69,2 @@ const headers = new Headers(meta.headers); | ||
} | ||
import { Headers, Response, Deno } from "./shim.node.js"; | ||
import { Headers, Response, URL, Deno } from "./shim.node.js"; |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
/** | ||
@@ -5,4 +6,4 @@ * If `Response` isn't cached, performs the request and caches `Response`. | ||
*/ | ||
export declare function fetchCache(url: string | URL): Promise<Response>; | ||
import { Response } from "./shim.node.js"; | ||
export declare function fetchCache(url: string | URL, { signal }?: Deno.ReadFileOptions): Promise<Response>; | ||
import { Response, URL, Deno } from "./shim.node.js"; | ||
//# sourceMappingURL=fetch.d.ts.map |
@@ -19,6 +19,6 @@ import { CacheEntry } from "./entry.js"; | ||
*/ | ||
export async function fetchCache(url) { | ||
export async function fetchCache(url, { signal } = {}) { | ||
const entry = new CacheEntry(url); | ||
try { | ||
return await entry.read(); | ||
return await entry.read({ signal }); | ||
} | ||
@@ -29,3 +29,3 @@ catch (error) { | ||
} | ||
const res = await fetch(url, { headers }); | ||
const res = await fetch(url, { headers, signal }); | ||
if (res.status === 200) | ||
@@ -32,0 +32,0 @@ await entry.write(res.clone()); |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
/** | ||
@@ -6,4 +7,4 @@ * @permissions `--allow-read --allow-env` | ||
*/ | ||
export declare function readCache(url: string | URL): Promise<Response>; | ||
import { Response } from "./shim.node.js"; | ||
export declare function readCache(url: string | URL, options?: Deno.ReadFileOptions): Promise<Response>; | ||
import { Response, URL, Deno } from "./shim.node.js"; | ||
//# sourceMappingURL=read.d.ts.map |
@@ -7,4 +7,4 @@ import { CacheEntry } from "./entry.js"; | ||
*/ | ||
export async function readCache(url) { | ||
return await new CacheEntry(url).read(); | ||
export async function readCache(url, options) { | ||
return await new CacheEntry(url).read(options); | ||
} |
@@ -1,4 +0,2 @@ | ||
export { default as fetch } from "node-fetch"; | ||
export * from "node-fetch"; | ||
export * from "deno.ns"; | ||
//# sourceMappingURL=shim.node.d.ts.map |
// Node-only, see https://doc.deno.land/https/deno.land/x/deno2node/src/mod.ts#deno2node | ||
export { default as fetch } from "node-fetch"; | ||
export * from "node-fetch"; | ||
export * from "deno.ns"; |
{ | ||
"name": "@fromdeno/cache", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Simple API for Deno cache.", | ||
@@ -42,4 +42,3 @@ "type": "module", | ||
"@types/node-fetch": "^2.5.12", | ||
"deno.ns": "^0.2.0", | ||
"node-fetch": "^2.6.1" | ||
"deno.ns": "^0.3.0" | ||
}, | ||
@@ -46,0 +45,0 @@ "devDependencies": { |
@@ -41,6 +41,6 @@ import { Path, sha256 } from "./deps.deno.ts"; | ||
*/ | ||
async read(): Promise<Response> { | ||
async read(options?: Deno.ReadFileOptions): Promise<Response> { | ||
const [body, meta] = await Promise.all([ | ||
Deno.readFile(this.path), | ||
Deno.readTextFile(this.metaPath).then(JSON.parse), | ||
Deno.readFile(this.path, options), | ||
Deno.readTextFile(this.metaPath, options).then(JSON.parse), | ||
]); | ||
@@ -47,0 +47,0 @@ const headers = new Headers(meta.headers); |
@@ -21,12 +21,15 @@ import { CacheEntry } from "./entry.ts"; | ||
*/ | ||
export async function fetchCache(url: string | URL): Promise<Response> { | ||
export async function fetchCache( | ||
url: string | URL, | ||
{ signal }: Deno.ReadFileOptions = {}, | ||
): Promise<Response> { | ||
const entry = new CacheEntry(url); | ||
try { | ||
return await entry.read(); | ||
return await entry.read({ signal }); | ||
} catch (error: unknown) { | ||
if (!(error instanceof Deno.errors.NotFound)) throw error; | ||
} | ||
const res = await fetch(url, { headers }); | ||
const res = await fetch(url, { headers, signal }); | ||
if (res.status === 200) await entry.write(res.clone()); | ||
return res; | ||
} |
@@ -8,4 +8,7 @@ import { CacheEntry } from "./entry.ts"; | ||
*/ | ||
export async function readCache(url: string | URL): Promise<Response> { | ||
return await new CacheEntry(url).read(); | ||
export async function readCache( | ||
url: string | URL, | ||
options?: Deno.ReadFileOptions, | ||
): Promise<Response> { | ||
return await new CacheEntry(url).read(options); | ||
} |
// Node-only, see https://doc.deno.land/https/deno.land/x/deno2node/src/mod.ts#deno2node | ||
export { default as fetch } from "node-fetch"; | ||
export * from "node-fetch"; | ||
export * from "deno.ns"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17006
2
349
+ Addeddeno.ns@0.3.1(transitive)
+ Addedfetch-blob@3.2.0(transitive)
+ Addednode-domexception@1.0.0(transitive)
+ Addedweb-streams-polyfill@3.3.3(transitive)
- Removednode-fetch@^2.6.1
- Removeddeno.ns@0.2.0(transitive)
- Removedfetch-blob@2.1.2(transitive)
Updateddeno.ns@^0.3.0