@envelop/response-cache-cloudflare-kv 0.3.0 → 1.0.0-alpha-20240520005117-b223e41e

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/README.md CHANGED
@@ -35,27 +35,24 @@ export type Env = {
35
35
  }
36
36
  export type GraphQLContext = YogaInitialContext & Env & ExecutionContext
37
37
 
38
- export default {
39
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
40
- const kvCache = createKvCache({
41
- KV: env.GRAPHQL_RESPONSE_CACHE,
42
- ctx,
43
- keyPrefix: 'graphql' // optional
44
- })
45
-
46
- const graphqlServer = createYoga<GraphQLContext>({
47
- schema: createSchema({ typeDefs, resolvers }),
48
- plugins: [
49
- useResponseCache({
50
- cache: kvCache,
51
- session: () => null,
52
- includeExtensionMetadata: true,
53
- ttl: 1000 * 10 // 10 seconds
54
- })
55
- ]
38
+ const graphqlServer = createYoga<GraphQLContext>({
39
+ schema: createSchema({ typeDefs, resolvers }),
40
+ plugins: [
41
+ useResponseCache({
42
+ cache: ctx =>
43
+ createKvCache({
44
+ KV: ctx.GRAPHQL_RESPONSE_CACHE,
45
+ waitUntil: ctx.waitUntil,
46
+ keyPrefix: 'graphql' // optional
47
+ }),
48
+ session: () => null,
49
+ includeExtensionMetadata: true,
50
+ ttl: 1000 * 10 // 10 seconds
56
51
  })
52
+ ]
53
+ })
57
54
 
58
- return graphqlServer.fetch(request, env, ctx)
59
- }
55
+ export default {
56
+ fetch: graphqlServer
60
57
  }
61
58
  ```
package/cjs/index.js CHANGED
@@ -40,11 +40,11 @@ function createKvCache(config) {
40
40
  /** how long the operation should be cached (in milliseconds) */
41
41
  ttl) {
42
42
  // Do not block execution of the worker while caching the result
43
- config.ctx.waitUntil((0, set_js_1.set)(id, data, entities, ttl, config));
43
+ config.waitUntil((0, set_js_1.set)(id, data, entities, ttl, config));
44
44
  },
45
45
  invalidate(entities) {
46
46
  // Do not block execution of the worker while invalidating the cache
47
- config.ctx.waitUntil((0, invalidate_js_1.invalidate)(entities, config));
47
+ config.waitUntil((0, invalidate_js_1.invalidate)(entities, config));
48
48
  },
49
49
  };
50
50
  return cache;
package/esm/index.js CHANGED
@@ -37,11 +37,11 @@ export function createKvCache(config) {
37
37
  /** how long the operation should be cached (in milliseconds) */
38
38
  ttl) {
39
39
  // Do not block execution of the worker while caching the result
40
- config.ctx.waitUntil(set(id, data, entities, ttl, config));
40
+ config.waitUntil(set(id, data, entities, ttl, config));
41
41
  },
42
42
  invalidate(entities) {
43
43
  // Do not block execution of the worker while invalidating the cache
44
- config.ctx.waitUntil(invalidate(entities, config));
44
+ config.waitUntil(invalidate(entities, config));
45
45
  },
46
46
  };
47
47
  return cache;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/response-cache-cloudflare-kv",
3
- "version": "0.3.0",
3
+ "version": "1.0.0-alpha-20240520005117-b223e41e",
4
4
  "sideEffects": false,
5
5
  "peerDependenciesMeta": {
6
6
  "@cloudflare/workers-types": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "peerDependencies": {
11
11
  "@cloudflare/workers-types": "^4.20231121.0",
12
- "@envelop/response-cache": "^6.1.2",
12
+ "@envelop/response-cache": "6.2.0-alpha-20240520005117-b223e41e",
13
13
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
14
14
  },
15
15
  "dependencies": {
@@ -1,4 +1,4 @@
1
- import type { ExecutionContext, KVNamespace } from '@cloudflare/workers-types';
1
+ import type { KVNamespace } from '@cloudflare/workers-types';
2
2
  import type { Cache } from '@envelop/response-cache';
3
3
  export type KvCacheConfig = {
4
4
  /**
@@ -6,9 +6,9 @@ export type KvCacheConfig = {
6
6
  */
7
7
  KV: KVNamespace;
8
8
  /**
9
- * The Cloudflare worker execution context. Used to perform non-blocking actions like cache storage and invalidation.
9
+ * The function that should be used to wait for non-blocking actions to complete
10
10
  */
11
- ctx: ExecutionContext;
11
+ waitUntil: (promise: Promise<unknown>) => void;
12
12
  /**
13
13
  * Defines the length of time in milliseconds that a KV result is cached in the global network location it is accessed from.
14
14
  *
@@ -1,4 +1,4 @@
1
- import type { ExecutionContext, KVNamespace } from '@cloudflare/workers-types';
1
+ import type { KVNamespace } from '@cloudflare/workers-types';
2
2
  import type { Cache } from '@envelop/response-cache';
3
3
  export type KvCacheConfig = {
4
4
  /**
@@ -6,9 +6,9 @@ export type KvCacheConfig = {
6
6
  */
7
7
  KV: KVNamespace;
8
8
  /**
9
- * The Cloudflare worker execution context. Used to perform non-blocking actions like cache storage and invalidation.
9
+ * The function that should be used to wait for non-blocking actions to complete
10
10
  */
11
- ctx: ExecutionContext;
11
+ waitUntil: (promise: Promise<unknown>) => void;
12
12
  /**
13
13
  * Defines the length of time in milliseconds that a KV result is cached in the global network location it is accessed from.
14
14
  *