@graphql-mesh/cache-cfw-kv 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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.
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
class CFWorkerKVCache {
|
|
2
4
|
constructor(config) {
|
|
5
|
+
// @ts-expect-error - KV is in globalThis for CFW
|
|
3
6
|
this.kvNamespace = globalThis[config.namespace];
|
|
4
7
|
if (this.kvNamespace === undefined) {
|
|
5
8
|
// We don't use mocks because they increase the bundle size.
|
|
6
9
|
config.logger.warn(`Make sure KV Namespace: ${config.namespace} exists.`);
|
|
7
10
|
}
|
|
8
11
|
}
|
|
9
|
-
get(key) {
|
|
12
|
+
async get(key) {
|
|
10
13
|
var _a;
|
|
11
14
|
return (_a = this.kvNamespace) === null || _a === void 0 ? void 0 : _a.get(key, 'json');
|
|
12
15
|
}
|
|
@@ -20,16 +23,15 @@ class CFWorkerKVCache {
|
|
|
20
23
|
}
|
|
21
24
|
return result.keys.map(keyEntry => keyEntry.name);
|
|
22
25
|
}
|
|
23
|
-
set(key, value, options) {
|
|
26
|
+
async set(key, value, options) {
|
|
24
27
|
var _a;
|
|
25
28
|
return (_a = this.kvNamespace) === null || _a === void 0 ? void 0 : _a.put(key, JSON.stringify(value), {
|
|
26
29
|
expirationTtl: options === null || options === void 0 ? void 0 : options.ttl,
|
|
27
30
|
});
|
|
28
31
|
}
|
|
29
|
-
delete(key) {
|
|
32
|
+
async delete(key) {
|
|
30
33
|
var _a;
|
|
31
34
|
return (_a = this.kvNamespace) === null || _a === void 0 ? void 0 : _a.delete(key);
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
export default CFWorkerKVCache;
|
|
37
|
+
exports.default = CFWorkerKVCache;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class CFWorkerKVCache {
|
|
1
|
+
export default class CFWorkerKVCache {
|
|
4
2
|
constructor(config) {
|
|
3
|
+
// @ts-expect-error - KV is in globalThis for CFW
|
|
5
4
|
this.kvNamespace = globalThis[config.namespace];
|
|
6
5
|
if (this.kvNamespace === undefined) {
|
|
7
6
|
// We don't use mocks because they increase the bundle size.
|
|
8
7
|
config.logger.warn(`Make sure KV Namespace: ${config.namespace} exists.`);
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
|
-
get(key) {
|
|
10
|
+
async get(key) {
|
|
12
11
|
var _a;
|
|
13
12
|
return (_a = this.kvNamespace) === null || _a === void 0 ? void 0 : _a.get(key, 'json');
|
|
14
13
|
}
|
|
@@ -22,16 +21,14 @@ class CFWorkerKVCache {
|
|
|
22
21
|
}
|
|
23
22
|
return result.keys.map(keyEntry => keyEntry.name);
|
|
24
23
|
}
|
|
25
|
-
set(key, value, options) {
|
|
24
|
+
async set(key, value, options) {
|
|
26
25
|
var _a;
|
|
27
26
|
return (_a = this.kvNamespace) === null || _a === void 0 ? void 0 : _a.put(key, JSON.stringify(value), {
|
|
28
27
|
expirationTtl: options === null || options === void 0 ? void 0 : options.ttl,
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
|
-
delete(key) {
|
|
30
|
+
async delete(key) {
|
|
32
31
|
var _a;
|
|
33
32
|
return (_a = this.kvNamespace) === null || _a === void 0 ? void 0 : _a.delete(key);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
module.exports = CFWorkerKVCache;
|
package/package.json
CHANGED
|
@@ -1,38 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/cache-cfw-kv",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/types": "0.
|
|
7
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
8
|
-
"graphql": "*"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"@udacity/types-service-worker-mock": "1.2.0",
|
|
12
|
-
"cloudflare-worker-mock": "1.2.0",
|
|
6
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
7
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"graphql": "*",
|
|
13
9
|
"tslib": "^2.4.0"
|
|
14
10
|
},
|
|
11
|
+
"dependencies": {},
|
|
15
12
|
"repository": {
|
|
16
13
|
"type": "git",
|
|
17
14
|
"url": "Urigo/graphql-mesh",
|
|
18
15
|
"directory": "packages/cache/cfw-kv"
|
|
19
16
|
},
|
|
20
17
|
"license": "MIT",
|
|
21
|
-
"main": "index.js",
|
|
22
|
-
"module": "index.
|
|
23
|
-
"typings": "index.d.ts",
|
|
18
|
+
"main": "cjs/index.js",
|
|
19
|
+
"module": "esm/index.js",
|
|
20
|
+
"typings": "typings/index.d.ts",
|
|
24
21
|
"typescript": {
|
|
25
|
-
"definition": "index.d.ts"
|
|
22
|
+
"definition": "typings/index.d.ts"
|
|
26
23
|
},
|
|
24
|
+
"type": "module",
|
|
27
25
|
"exports": {
|
|
28
26
|
".": {
|
|
29
|
-
"require":
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./typings/index.d.cts",
|
|
29
|
+
"default": "./cjs/index.js"
|
|
30
|
+
},
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./typings/index.d.ts",
|
|
33
|
+
"default": "./esm/index.js"
|
|
34
|
+
},
|
|
35
|
+
"default": {
|
|
36
|
+
"types": "./typings/index.d.ts",
|
|
37
|
+
"default": "./esm/index.js"
|
|
38
|
+
}
|
|
35
39
|
},
|
|
36
40
|
"./package.json": "./package.json"
|
|
37
41
|
}
|
|
38
|
-
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { KeyValueCache, Logger } from '@graphql-mesh/types';
|
|
2
|
+
export default class CFWorkerKVCache implements KeyValueCache {
|
|
3
|
+
private kvNamespace?;
|
|
4
|
+
constructor(config: {
|
|
5
|
+
namespace: string;
|
|
6
|
+
logger: Logger;
|
|
7
|
+
});
|
|
8
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
9
|
+
getKeysByPrefix(prefix: string): Promise<string[]>;
|
|
10
|
+
set(key: string, value: any, options?: {
|
|
11
|
+
ttl?: number;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
}
|
|
File without changes
|