cf-workers-query
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -0,1 +1,12 @@ | ||
## 0.7.1 (2024-09-26) | ||
### 🩹 Fixes | ||
- **build:** better handling commonjs ([a0c85f1](https://github.com/anymaniax/cf-workers-query/commit/a0c85f1)) | ||
### ❤️ Thank You | ||
- Victor Bury | ||
## 0.7.0 (2024-09-09) | ||
@@ -2,0 +13,0 @@ |
{ | ||
"name": "cf-workers-query", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"license": "MIT", | ||
@@ -51,2 +51,3 @@ "description": "Automatically cache and revalidate data in Cloudflare Workers. Using the Cache API and Execution Context", | ||
"prettier": "^2.6.2", | ||
"tsup": "^8.3.0", | ||
"typescript": "~5.5.2", | ||
@@ -60,14 +61,25 @@ "vite": "^5.0.0", | ||
"type": "module", | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts", | ||
"types": "./src/index.d.ts", | ||
"main": "./src/index.cjs", | ||
"module": "./src/index.js", | ||
"exports": { | ||
".": { | ||
"types": "./src/index.d.ts", | ||
"require": "./src/index.js", | ||
"import": "./src/index.js" | ||
"import": { | ||
"types": "./src/index.d.ts", | ||
"default": "./src/index.js" | ||
}, | ||
"require": { | ||
"types": "./src/index.d.cts", | ||
"default": "./src/index.cjs" | ||
} | ||
}, | ||
"./hono": { | ||
"types": "./src/lib/hono.d.ts", | ||
"require": "./src/lib/hono.js", | ||
"import": "./src/lib/hono.js" | ||
"import": { | ||
"types": "./src/lib/hono.d.ts", | ||
"default": "./src/lib/hono.js" | ||
}, | ||
"require": { | ||
"types": "./src/lib/hono.d.cts", | ||
"default": "./src/lib/hono.cjs" | ||
} | ||
} | ||
@@ -81,4 +93,3 @@ }, | ||
} | ||
}, | ||
"module": "./src/index.js" | ||
} | ||
} | ||
} |
@@ -1,4 +0,9 @@ | ||
export { createQuery } from './lib/create-query'; | ||
export { CacheApiAdaptor } from './lib/cache-api'; | ||
export { defineCFExecutionContext, getCFExecutionContext } from './lib/context'; | ||
export { invalidateQuery } from './lib/invalidate-query'; | ||
import { Q as QueryKey } from './create-query-njGTTuc4.js'; | ||
export { C as CacheApiAdaptor, c as createQuery, d as defineCFExecutionContext, g as getCFExecutionContext } from './create-query-njGTTuc4.js'; | ||
declare const invalidateQuery: ({ queryKey, cacheName, }: { | ||
queryKey: QueryKey; | ||
cacheName?: string; | ||
}) => Promise<void>; | ||
export { invalidateQuery }; |
@@ -1,4 +0,22 @@ | ||
export { createQuery } from './lib/create-query'; | ||
export { CacheApiAdaptor } from './lib/cache-api'; | ||
export { defineCFExecutionContext, getCFExecutionContext } from './lib/context'; | ||
export { invalidateQuery } from './lib/invalidate-query'; | ||
import { | ||
CacheApiAdaptor, | ||
__name, | ||
createQuery, | ||
defineCFExecutionContext, | ||
getCFExecutionContext | ||
} from "./chunk-2FX6XZNP.js"; | ||
// src/lib/invalidate-query.ts | ||
var invalidateQuery = /* @__PURE__ */ __name(({ queryKey, cacheName }) => { | ||
const cache = new CacheApiAdaptor({ | ||
cacheName | ||
}); | ||
return cache.delete(queryKey); | ||
}, "invalidateQuery"); | ||
export { | ||
CacheApiAdaptor, | ||
createQuery, | ||
defineCFExecutionContext, | ||
getCFExecutionContext, | ||
invalidateQuery | ||
}; |
@@ -1,4 +0,4 @@ | ||
import { Context, Handler, MiddlewareHandler } from 'hono'; | ||
import { CreateQuery } from './create-query'; | ||
import { QueryKey } from './cache-api'; | ||
import { MiddlewareHandler, Handler, Context } from 'hono'; | ||
import { a as CreateQuery, Q as QueryKey } from '../create-query-njGTTuc4.js'; | ||
type CacheKey = QueryKey | ((ctx: Context) => QueryKey); | ||
@@ -10,3 +10,4 @@ type CacheOptions = Omit<CreateQuery, 'queryKey' | 'queryFn' | 'executionCtx' | 'throwOnError' | 'revalidate'> & { | ||
}; | ||
export declare const cache: ({ cacheKey, handler, revalidate, ...options }: CacheOptions) => MiddlewareHandler; | ||
export {}; | ||
declare const cache: ({ cacheKey, handler, revalidate, ...options }: CacheOptions) => MiddlewareHandler; | ||
export { cache }; |
@@ -1,20 +0,53 @@ | ||
import { createQuery } from './create-query'; | ||
import { HTTPException } from 'hono/http-exception'; | ||
export const cache = ({ cacheKey, handler, revalidate, ...options }) => async (ctx, next) => { | ||
const { data: response, error } = await createQuery({ | ||
...options, | ||
queryKey: typeof cacheKey === 'function' ? cacheKey(ctx) : cacheKey, | ||
queryFn: () => handler(ctx, next), | ||
executionCtx: ctx.executionCtx, | ||
throwOnError: true, | ||
...(revalidate | ||
? { | ||
revalidate: typeof revalidate === 'boolean' ? revalidate : revalidate(ctx), | ||
} | ||
: {}), | ||
import { | ||
__name, | ||
createQuery | ||
} from "../chunk-2FX6XZNP.js"; | ||
// node_modules/hono/dist/http-exception.js | ||
var HTTPException = class extends Error { | ||
static { | ||
__name(this, "HTTPException"); | ||
} | ||
res; | ||
status; | ||
constructor(status = 500, options) { | ||
super(options?.message, { | ||
cause: options?.cause | ||
}); | ||
if (!response || error) { | ||
throw new HTTPException(500); | ||
this.res = options?.res; | ||
this.status = status; | ||
} | ||
getResponse() { | ||
if (this.res) { | ||
const newResponse = new Response(this.res.body, { | ||
status: this.status, | ||
headers: this.res.headers | ||
}); | ||
return newResponse; | ||
} | ||
return new Response(response.body, response); | ||
return new Response(this.message, { | ||
status: this.status | ||
}); | ||
} | ||
}; | ||
// src/lib/hono.ts | ||
var cache = /* @__PURE__ */ __name(({ cacheKey, handler, revalidate, ...options }) => async (ctx, next) => { | ||
const { data: response, error } = await createQuery({ | ||
...options, | ||
queryKey: typeof cacheKey === "function" ? cacheKey(ctx) : cacheKey, | ||
queryFn: /* @__PURE__ */ __name(() => handler(ctx, next), "queryFn"), | ||
executionCtx: ctx.executionCtx, | ||
throwOnError: true, | ||
...revalidate ? { | ||
revalidate: typeof revalidate === "boolean" ? revalidate : revalidate(ctx) | ||
} : {} | ||
}); | ||
if (!response || error) { | ||
throw new HTTPException(500); | ||
} | ||
return new Response(response.body, response); | ||
}, "cache"); | ||
export { | ||
cache | ||
}; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
53591
1134
24
2
1