@ldsg/key-value-cache 0.3.31 → 0.3.33
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/dist/constants.d.ts +3 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +8 -8
- package/dist/handler.d.ts +4 -4
- package/dist/index.d.ts +5 -5
- package/dist/instantiate-resource.d.ts +3 -3
- package/dist/instantiate-resource.js +1 -1
- package/dist/resource.d.ts +12 -6
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +16 -12
- package/dist/types/index.d.ts +1 -1
- package/dist/types/specific-resource-settings.d.ts +3 -3
- package/dist/types/specific-resource-settings.js +3 -3
- package/package.json +16 -12
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HandlerSpecificResourceSettings } from
|
|
2
|
-
import { ResourceDefinitionSpecificResourceSettings } from
|
|
3
|
-
import { GeneralResourceSettings } from
|
|
1
|
+
import { HandlerSpecificResourceSettings } from "@ldsg/handler";
|
|
2
|
+
import { ResourceDefinitionSpecificResourceSettings } from "@ldsg/resource-definition";
|
|
3
|
+
import { GeneralResourceSettings } from "@ldsg/types";
|
|
4
4
|
/**
|
|
5
5
|
* Instantiate Resource Handler General Resource Settings
|
|
6
6
|
* 实例化资源处理程序普通资源配置
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAQnE,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAG1D,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -6,8 +6,8 @@ exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINI
|
|
|
6
6
|
* 实例化资源处理程序普通资源配置
|
|
7
7
|
*/
|
|
8
8
|
exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = {
|
|
9
|
-
title:
|
|
10
|
-
description:
|
|
9
|
+
title: "键值对缓存实例化资源处理程序",
|
|
10
|
+
description: "",
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
13
|
* Instantiate Resource Handler Specific Resource Settings
|
|
@@ -18,14 +18,14 @@ exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
|
|
|
18
18
|
code: `export * from "@ldsg/key-value-cache";`,
|
|
19
19
|
dependencies: [
|
|
20
20
|
{
|
|
21
|
-
name:
|
|
22
|
-
}
|
|
23
|
-
]
|
|
21
|
+
name: "@ldsg/key-value-cache",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
24
|
};
|
|
25
25
|
exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
|
|
26
|
-
title:
|
|
27
|
-
description:
|
|
26
|
+
title: "键值对缓存资源定义",
|
|
27
|
+
description: "",
|
|
28
28
|
};
|
|
29
29
|
exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
|
|
30
|
-
kind:
|
|
30
|
+
kind: "key_value_cache",
|
|
31
31
|
};
|
package/dist/handler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Handler } from
|
|
2
|
-
import { InstantiateResourceParams, InstantiateResourceRes } from
|
|
3
|
-
import { KeyValueCacheResource } from
|
|
4
|
-
import { KeyValueCacheSpecificResourceSettings } from
|
|
1
|
+
import { Handler } from "@ldsg/handler";
|
|
2
|
+
import { InstantiateResourceParams, InstantiateResourceRes } from "@ldsg/resource";
|
|
3
|
+
import { KeyValueCacheResource } from "./resource";
|
|
4
|
+
import { KeyValueCacheSpecificResourceSettings } from "./types";
|
|
5
5
|
export declare const handler: Handler<InstantiateResourceParams<KeyValueCacheSpecificResourceSettings>, InstantiateResourceRes<KeyValueCacheResource>>;
|
|
6
6
|
//# sourceMappingURL=handler.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./constants";
|
|
2
|
+
export * from "./handler";
|
|
3
|
+
export * from "./instantiate-resource";
|
|
4
|
+
export * from "./resource";
|
|
5
|
+
export * from "./types";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InstantiateResource } from
|
|
2
|
-
import { KeyValueCacheResource } from
|
|
3
|
-
import { KeyValueCacheSpecificResourceSettings } from
|
|
1
|
+
import { InstantiateResource } from "@ldsg/resource";
|
|
2
|
+
import { KeyValueCacheResource } from "./resource";
|
|
3
|
+
import { KeyValueCacheSpecificResourceSettings } from "./types";
|
|
4
4
|
export declare const instantiateResource: InstantiateResource<KeyValueCacheSpecificResourceSettings, KeyValueCacheResource>;
|
|
5
5
|
//# sourceMappingURL=instantiate-resource.d.ts.map
|
package/dist/resource.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Resource, ResourceConstructorParams } from
|
|
2
|
-
import mongoose from
|
|
3
|
-
import { KeyValueCacheSpecificResourceSettings } from
|
|
1
|
+
import { Resource, ResourceConstructorParams } from "@ldsg/resource";
|
|
2
|
+
import mongoose from "mongoose";
|
|
3
|
+
import { KeyValueCacheSpecificResourceSettings } from "./types";
|
|
4
4
|
export declare class KeyValueCacheResource extends Resource<KeyValueCacheSpecificResourceSettings> {
|
|
5
5
|
keyValueCacheModel: mongoose.Model<{
|
|
6
6
|
key?: string | null | undefined;
|
|
@@ -8,20 +8,26 @@ export declare class KeyValueCacheResource extends Resource<KeyValueCacheSpecifi
|
|
|
8
8
|
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
9
9
|
key?: string | null | undefined;
|
|
10
10
|
value?: string | null | undefined;
|
|
11
|
-
}, {},
|
|
11
|
+
}, {}, {
|
|
12
|
+
collection: string;
|
|
13
|
+
}> & {
|
|
12
14
|
key?: string | null | undefined;
|
|
13
15
|
value?: string | null | undefined;
|
|
14
16
|
} & {
|
|
15
17
|
_id: mongoose.Types.ObjectId;
|
|
16
18
|
} & {
|
|
17
19
|
__v: number;
|
|
18
|
-
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {},
|
|
20
|
+
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
21
|
+
collection: string;
|
|
22
|
+
}, {
|
|
19
23
|
key?: string | null | undefined;
|
|
20
24
|
value?: string | null | undefined;
|
|
21
25
|
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
22
26
|
key?: string | null | undefined;
|
|
23
27
|
value?: string | null | undefined;
|
|
24
|
-
}>, {}, mongoose.ResolveSchemaOptions<
|
|
28
|
+
}>, {}, mongoose.ResolveSchemaOptions<{
|
|
29
|
+
collection: string;
|
|
30
|
+
}>> & mongoose.FlatRecord<{
|
|
25
31
|
key?: string | null | undefined;
|
|
26
32
|
value?: string | null | undefined;
|
|
27
33
|
}> & {
|
package/dist/resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,QAAoB,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,qCAAqC,EAAE,MAAM,SAAS,CAAC;AAEhE,qBAAa,qBAAsB,SAAQ,QAAQ,CAAC,qCAAqC,CAAC;IACxF,kBAAkB
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,QAAoB,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,qCAAqC,EAAE,MAAM,SAAS,CAAC;AAEhE,qBAAa,qBAAsB,SAAQ,QAAQ,CAAC,qCAAqC,CAAC;IACxF,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAAC;gBAEP,MAAM,EAAE,yBAAyB,CAAC,qCAAqC,CAAC;IA4BpF,oBAAoB,GAAI,KAAK,MAAM,YAMjC;IAEF,KAAK,sBAEH;IAEF,OAAO,GAAU,KAAK,MAAM,wCAU1B;IAEF,OAAO,GAAU,KAAK,MAAM,EAAE,OAAO,GAAG,mBAmBtC;IAEF,UAAU,GAAU,KAAK,MAAM,mBAM7B;CACH"}
|
package/dist/resource.js
CHANGED
|
@@ -44,7 +44,7 @@ class KeyValueCacheResource extends resource_1.Resource {
|
|
|
44
44
|
constructor(params) {
|
|
45
45
|
super(params);
|
|
46
46
|
this.getRealKeyInDatabase = (key) => {
|
|
47
|
-
const { keyPrefix =
|
|
47
|
+
const { keyPrefix = "" } = this.settings;
|
|
48
48
|
const res = `${keyPrefix}${key}`;
|
|
49
49
|
return res;
|
|
50
50
|
};
|
|
@@ -54,7 +54,7 @@ class KeyValueCacheResource extends resource_1.Resource {
|
|
|
54
54
|
this.getItem = async (key) => {
|
|
55
55
|
const realKey = this.getRealKeyInDatabase(key);
|
|
56
56
|
const findOneRes = await this.keyValueCacheModel.findOne({
|
|
57
|
-
|
|
57
|
+
key: realKey,
|
|
58
58
|
});
|
|
59
59
|
const res = findOneRes === null || findOneRes === void 0 ? void 0 : findOneRes.value;
|
|
60
60
|
return res;
|
|
@@ -63,34 +63,38 @@ class KeyValueCacheResource extends resource_1.Resource {
|
|
|
63
63
|
const realKey = this.getRealKeyInDatabase(key);
|
|
64
64
|
const setValue = lodash_1.default.isObject(value) ? JSON.stringify(value) : value;
|
|
65
65
|
await this.keyValueCacheModel.findOneAndUpdate({
|
|
66
|
-
key: realKey
|
|
66
|
+
key: realKey,
|
|
67
67
|
}, {
|
|
68
68
|
$set: {
|
|
69
|
-
value: setValue
|
|
70
|
-
}
|
|
69
|
+
value: setValue,
|
|
70
|
+
},
|
|
71
71
|
}, {
|
|
72
72
|
upsert: true,
|
|
73
|
-
new: true
|
|
73
|
+
new: true,
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
76
|
this.removeItem = async (key) => {
|
|
77
77
|
const realKey = this.getRealKeyInDatabase(key);
|
|
78
78
|
await this.keyValueCacheModel.deleteMany({
|
|
79
|
-
key: realKey
|
|
79
|
+
key: realKey,
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
-
const {
|
|
82
|
+
const { slug = "key-value-cache" } = params.settings;
|
|
83
|
+
const collectionName = lodash_1.default.snakeCase(slug);
|
|
84
|
+
const modelName = lodash_1.default.upperFirst(lodash_1.default.camelCase(slug));
|
|
83
85
|
const keyValueCacheSchema = new mongoose_1.Schema({
|
|
84
86
|
key: {
|
|
85
87
|
type: String,
|
|
86
88
|
index: true,
|
|
87
|
-
unique: true
|
|
89
|
+
unique: true,
|
|
88
90
|
},
|
|
89
91
|
value: {
|
|
90
|
-
type: String
|
|
91
|
-
}
|
|
92
|
+
type: String,
|
|
93
|
+
},
|
|
94
|
+
}, {
|
|
95
|
+
collection: collectionName,
|
|
92
96
|
});
|
|
93
|
-
this.keyValueCacheModel = mongoose_1.default.model(
|
|
97
|
+
this.keyValueCacheModel = mongoose_1.default.model(modelName, keyValueCacheSchema);
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
exports.KeyValueCacheResource = KeyValueCacheResource;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./specific-resource-settings";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
export declare const KeyValueCacheSpecificResourceSettingsSchema: z.ZodObject<{
|
|
3
|
-
|
|
3
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
4
4
|
keyPrefix: z.ZodOptional<z.ZodString>;
|
|
5
5
|
}, z.core.$catchall<z.ZodAny>>;
|
|
6
6
|
export declare const SpecificResourceSettingsSchema: z.ZodObject<{
|
|
7
|
-
|
|
7
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
8
8
|
keyPrefix: z.ZodOptional<z.ZodString>;
|
|
9
9
|
}, z.core.$catchall<z.ZodAny>>;
|
|
10
10
|
export type KeyValueCacheSpecificResourceSettings = z.infer<typeof KeyValueCacheSpecificResourceSettingsSchema>;
|
|
@@ -5,13 +5,13 @@ const zod_1 = require("zod");
|
|
|
5
5
|
exports.KeyValueCacheSpecificResourceSettingsSchema = zod_1.z
|
|
6
6
|
.object({
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Key Value Cache Slug
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
slug: zod_1.z.string().optional(),
|
|
11
11
|
/**
|
|
12
12
|
* Key Prefix
|
|
13
13
|
*/
|
|
14
|
-
keyPrefix: zod_1.z.string().optional()
|
|
14
|
+
keyPrefix: zod_1.z.string().optional(),
|
|
15
15
|
})
|
|
16
16
|
.catchall(zod_1.z.any());
|
|
17
17
|
exports.SpecificResourceSettingsSchema = exports.KeyValueCacheSpecificResourceSettingsSchema;
|
package/package.json
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/key-value-cache",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.33",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "wanxger",
|
|
8
|
-
"main": "dist/index.js",
|
|
9
|
-
"types": "dist",
|
|
10
8
|
"files": [
|
|
11
9
|
"dist/"
|
|
12
10
|
],
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
13
16
|
"dependencies": {
|
|
14
17
|
"lodash": "4.17.21",
|
|
15
18
|
"mongoose": "^8.14.3",
|
|
16
19
|
"zod": "^4.1.11",
|
|
17
|
-
"@ldsg/constants": "0.3.
|
|
18
|
-
"@ldsg/
|
|
19
|
-
"@ldsg/resource": "0.3.
|
|
20
|
-
"@ldsg/
|
|
21
|
-
"@ldsg/types": "0.3.
|
|
20
|
+
"@ldsg/constants": "0.3.33",
|
|
21
|
+
"@ldsg/resource": "0.3.33",
|
|
22
|
+
"@ldsg/resource-definition": "0.3.33",
|
|
23
|
+
"@ldsg/handler": "0.3.33",
|
|
24
|
+
"@ldsg/types": "0.3.33"
|
|
22
25
|
},
|
|
23
26
|
"devDependencies": {
|
|
24
27
|
"@types/jest": "^29.5.2",
|
|
@@ -26,16 +29,17 @@
|
|
|
26
29
|
"@types/node": "^20.13.0",
|
|
27
30
|
"@types/supertest": "^6.0.0",
|
|
28
31
|
"jest": "^29.5.0",
|
|
32
|
+
"oxfmt": "latest",
|
|
33
|
+
"oxlint": "latest",
|
|
29
34
|
"supertest": "^6.3.4",
|
|
30
35
|
"ts-jest": "^29.1.5",
|
|
31
36
|
"ts-node": "^10.9.2",
|
|
32
37
|
"typescript": "^5.8.3"
|
|
33
38
|
},
|
|
34
|
-
"publishConfig": {
|
|
35
|
-
"access": "public"
|
|
36
|
-
},
|
|
37
39
|
"scripts": {
|
|
38
40
|
"build": "tsc --project tsconfig.build.json",
|
|
39
|
-
"clean": "rm -rf dist"
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"format": "oxfmt --write src/",
|
|
43
|
+
"lint": "oxlint src/"
|
|
40
44
|
}
|
|
41
45
|
}
|