@stacksjs/cache 0.51.0 → 0.52.1
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 +1 -1
- package/dist/drivers/dynamodb.d.ts +1 -6
- package/dist/drivers/dynamodb.mjs +1 -93
- package/dist/drivers/memcached.d.ts +1 -4
- package/dist/drivers/memcached.mjs +1 -13
- package/dist/drivers/redis.d.ts +1 -1
- package/dist/drivers/redis.mjs +2 -3
- package/package.json +31 -16
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ pnpm test
|
|
|
38
38
|
|
|
39
39
|
Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
|
|
40
40
|
|
|
41
|
-
##
|
|
41
|
+
## 🚜 Contributing
|
|
42
42
|
|
|
43
43
|
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
|
|
44
44
|
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
declare function set(key: string, value: string | number): Promise<void>;
|
|
3
|
-
declare function get(key: string): Promise<string | undefined | null>;
|
|
4
|
-
declare function remove(key: string): Promise<void>;
|
|
5
|
-
declare function del(key: string): Promise<void>;
|
|
6
|
-
export { set, get, remove, del, createTable };
|
|
1
|
+
export {};
|
|
@@ -1,93 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { cache } from "@stacksjs/config";
|
|
3
|
-
const valueAttribute = "value";
|
|
4
|
-
const keyAttribute = "key";
|
|
5
|
-
const tableName = cache.dynamodb.table;
|
|
6
|
-
const dynamodb = new DynamoDB({ region: cache.dynamodb.region });
|
|
7
|
-
async function createTable() {
|
|
8
|
-
const tables = await dynamodb.send(new ListTablesCommand({}));
|
|
9
|
-
const tableExists = tables.TableNames?.includes("cache");
|
|
10
|
-
if (tableExists)
|
|
11
|
-
return;
|
|
12
|
-
const params = {
|
|
13
|
-
AttributeDefinitions: [
|
|
14
|
-
{
|
|
15
|
-
AttributeName: "key",
|
|
16
|
-
AttributeType: "S"
|
|
17
|
-
}
|
|
18
|
-
],
|
|
19
|
-
KeySchema: [
|
|
20
|
-
{
|
|
21
|
-
AttributeName: "key",
|
|
22
|
-
KeyType: "HASH"
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
ProvisionedThroughput: {
|
|
26
|
-
ReadCapacityUnits: 5,
|
|
27
|
-
WriteCapacityUnits: 5
|
|
28
|
-
},
|
|
29
|
-
TableName: tableName
|
|
30
|
-
};
|
|
31
|
-
await dynamodb.createTable(params);
|
|
32
|
-
}
|
|
33
|
-
async function set(key, value) {
|
|
34
|
-
const params = {
|
|
35
|
-
TableName: tableName,
|
|
36
|
-
Item: {
|
|
37
|
-
[keyAttribute]: {
|
|
38
|
-
S: key
|
|
39
|
-
},
|
|
40
|
-
[valueAttribute]: {
|
|
41
|
-
[getValueType(value)]: serialize(value)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
await dynamodb.putItem(params);
|
|
46
|
-
}
|
|
47
|
-
async function get(key) {
|
|
48
|
-
const params = {
|
|
49
|
-
TableName: tableName,
|
|
50
|
-
Key: {
|
|
51
|
-
[keyAttribute]: {
|
|
52
|
-
S: key
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const response = await dynamodb.getItem(params);
|
|
57
|
-
if (!response.Item)
|
|
58
|
-
return null;
|
|
59
|
-
return response.Item[valueAttribute].S ?? response.Item[valueAttribute].N;
|
|
60
|
-
}
|
|
61
|
-
function getValueType(value) {
|
|
62
|
-
if (typeof value === "string")
|
|
63
|
-
return "S";
|
|
64
|
-
if (typeof value === "number")
|
|
65
|
-
return "N";
|
|
66
|
-
return "S";
|
|
67
|
-
}
|
|
68
|
-
async function remove(key) {
|
|
69
|
-
const params = {
|
|
70
|
-
TableName: tableName,
|
|
71
|
-
Key: {
|
|
72
|
-
[keyAttribute]: {
|
|
73
|
-
S: key
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
await dynamodb.deleteItem(params);
|
|
78
|
-
}
|
|
79
|
-
async function del(key) {
|
|
80
|
-
const params = {
|
|
81
|
-
TableName: tableName,
|
|
82
|
-
Key: {
|
|
83
|
-
[keyAttribute]: {
|
|
84
|
-
S: key
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
await dynamodb.deleteItem(params);
|
|
89
|
-
}
|
|
90
|
-
function serialize(value) {
|
|
91
|
-
return String(value);
|
|
92
|
-
}
|
|
93
|
-
export { set, get, remove, del, createTable };
|
|
1
|
+
export {};
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const client = Memcached.Client.create("127.0.0.1:11211");
|
|
3
|
-
async function set(key, value, duration) {
|
|
4
|
-
await client.set(key, value, { expires: duration });
|
|
5
|
-
}
|
|
6
|
-
async function get(key) {
|
|
7
|
-
const value = await client.get(key);
|
|
8
|
-
return value.toString();
|
|
9
|
-
}
|
|
10
|
-
async function del(key) {
|
|
11
|
-
await client.delete(key);
|
|
12
|
-
}
|
|
13
|
-
export { set, get, del };
|
|
1
|
+
export {};
|
package/dist/drivers/redis.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RedisClientType } from 'redis';
|
|
2
2
|
declare const client: RedisClientType;
|
|
3
|
-
declare function set(key:
|
|
3
|
+
declare function set(key: string, value: any): Promise<void>;
|
|
4
4
|
declare function get(key: string): Promise<any>;
|
|
5
5
|
declare function remove(key: string): Promise<void>;
|
|
6
6
|
declare function del(key: string): Promise<void>;
|
package/dist/drivers/redis.mjs
CHANGED
|
@@ -2,12 +2,11 @@ import { createClient } from "redis";
|
|
|
2
2
|
import { cache } from "@stacksjs/config";
|
|
3
3
|
const client = createClient({
|
|
4
4
|
socket: {
|
|
5
|
-
host: cache
|
|
6
|
-
port: cache
|
|
5
|
+
host: cache?.redis?.host,
|
|
6
|
+
port: cache?.redis?.port
|
|
7
7
|
},
|
|
8
8
|
password: ""
|
|
9
9
|
});
|
|
10
|
-
await client.connect();
|
|
11
10
|
async function set(key, value) {
|
|
12
11
|
await client.set(key, value);
|
|
13
12
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/cache",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@
|
|
4
|
+
"version": "0.52.1",
|
|
5
|
+
"packageManager": "pnpm@8.5.1",
|
|
6
6
|
"description": "The Stacks way of caching.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -26,7 +26,28 @@
|
|
|
26
26
|
"functions",
|
|
27
27
|
"stacks"
|
|
28
28
|
],
|
|
29
|
-
"
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./drivers/dynamodb": {
|
|
35
|
+
"types": "./dist/drivers/dynamodb.d.ts",
|
|
36
|
+
"import": "./dist/drivers/dynamodb.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./drivers/memcached": {
|
|
39
|
+
"types": "./dist/drivers/dynamodb.d.ts",
|
|
40
|
+
"import": "./dist/drivers/dynamodb.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./drivers/redis": {
|
|
43
|
+
"types": "./dist/drivers/dynamodb.d.ts",
|
|
44
|
+
"import": "./dist/drivers/dynamodb.mjs"
|
|
45
|
+
},
|
|
46
|
+
"./drivers/upstash": {
|
|
47
|
+
"types": "./dist/drivers/dynamodb.d.ts",
|
|
48
|
+
"import": "./dist/drivers/dynamodb.mjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
30
51
|
"module": "dist/index.mjs",
|
|
31
52
|
"types": "dist/index.d.ts",
|
|
32
53
|
"contributors": [
|
|
@@ -36,26 +57,20 @@
|
|
|
36
57
|
"dist",
|
|
37
58
|
"README.md"
|
|
38
59
|
],
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": ">=v18.14.0",
|
|
41
|
-
"pnpm": ">=7.26.3"
|
|
42
|
-
},
|
|
43
60
|
"peerDependencies": {
|
|
44
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
61
|
+
"@aws-sdk/client-dynamodb": "^3.335.0",
|
|
45
62
|
"@types/memjs": "^1.3.0",
|
|
46
63
|
"memcached": "^2.2.2",
|
|
47
|
-
"memjs": "^1.3.
|
|
48
|
-
"redis": "^4.6.
|
|
49
|
-
"@stacksjs/config": "0.
|
|
64
|
+
"memjs": "^1.3.1",
|
|
65
|
+
"redis": "^4.6.6",
|
|
66
|
+
"@stacksjs/config": "0.52.1"
|
|
50
67
|
},
|
|
51
68
|
"devDependencies": {
|
|
52
|
-
"
|
|
53
|
-
"typescript": "^4.9.5",
|
|
54
|
-
"@stacksjs/testing": "0.51.0"
|
|
69
|
+
"@stacksjs/development": "0.52.1"
|
|
55
70
|
},
|
|
56
71
|
"scripts": {
|
|
57
|
-
"build": "
|
|
58
|
-
"dev": "
|
|
72
|
+
"build": "unbuild",
|
|
73
|
+
"dev": "unbuild --stub",
|
|
59
74
|
"typecheck": "tsc --noEmit"
|
|
60
75
|
}
|
|
61
76
|
}
|