@jayfong/x-server 2.118.1 → 3.0.0
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/lib/_virtual/_rolldown/runtime.mjs +4 -0
- package/lib/cli/api_generator.d.mts +74 -0
- package/lib/cli/api_generator.mjs +310 -0
- package/lib/cli/build_util.d.mts +17 -0
- package/lib/cli/build_util.mjs +156 -0
- package/lib/cli/cli.d.mts +1 -0
- package/lib/cli/cli.mjs +355 -0
- package/lib/cli/css_register.d.mts +1 -0
- package/lib/cli/css_register.mjs +7 -0
- package/lib/cli/deploy_util.d.mts +23 -0
- package/lib/cli/deploy_util.mjs +70 -0
- package/lib/cli/dev_util.d.mts +7 -0
- package/lib/cli/dev_util.mjs +25 -0
- package/lib/cli/env_util.d.mts +45 -0
- package/lib/cli/env_util.mjs +207 -0
- package/lib/cli/esbuild_register.d.mts +1 -0
- package/lib/cli/esbuild_register.mjs +7 -0
- package/lib/cli/template_util.d.mts +18 -0
- package/lib/cli/template_util.mjs +85 -0
- package/lib/cli/templates/crons.ts +1 -1
- package/lib/cli/templates/handlers.ts +1 -1
- package/lib/cli/templates/hooks.ts +1 -1
- package/lib/cli/templates/models.ts +7 -7
- package/lib/cli/templates/package.json +11 -1
- package/lib/cli/templates/routes.ts +2 -1
- package/lib/core/ctx_storage.d.mts +3 -0
- package/lib/core/ctx_storage.mjs +4 -0
- package/lib/core/define_bus.d.mts +37 -0
- package/lib/core/define_bus.mjs +12 -0
- package/lib/core/{define_cron.d.ts → define_cron.d.mts} +2 -2
- package/lib/core/define_cron.mjs +11 -0
- package/lib/core/{define_handler.d.ts → define_handler.d.mts} +19 -19
- package/lib/core/define_handler.mjs +44 -0
- package/lib/core/define_hook.d.mts +2 -0
- package/lib/core/define_hook.mjs +6 -0
- package/lib/core/define_server.d.mts +3 -0
- package/lib/core/define_server.mjs +8 -0
- package/lib/core/{define_task.d.ts → define_task.d.mts} +2 -2
- package/lib/core/define_task.mjs +102 -0
- package/lib/core/get_handler_url.d.mts +2 -0
- package/lib/core/get_handler_url.mjs +7 -0
- package/lib/core/handler.d.mts +16 -0
- package/lib/core/handler.mjs +132 -0
- package/lib/core/http_error.d.mts +2 -0
- package/lib/core/http_error.mjs +1 -0
- package/lib/core/http_header.d.mts +856 -0
- package/lib/core/http_header.mjs +860 -0
- package/lib/core/http_method.d.mts +3 -0
- package/lib/core/http_method.mjs +10 -0
- package/lib/core/http_redirect.d.mts +5 -0
- package/lib/core/http_redirect.mjs +10 -0
- package/lib/core/server.d.mts +20 -0
- package/lib/core/server.mjs +186 -0
- package/lib/core/types.d.mts +256 -0
- package/lib/exports.d.mts +46 -0
- package/lib/exports.mjs +46 -0
- package/lib/index.d.mts +48 -0
- package/lib/index.mjs +45 -0
- package/lib/plugins/base.d.mts +4 -0
- package/lib/plugins/compress.d.mts +12 -0
- package/lib/plugins/compress.mjs +15 -0
- package/lib/plugins/cookie.d.mts +12 -0
- package/lib/plugins/cookie.mjs +15 -0
- package/lib/plugins/cors.d.mts +22 -0
- package/lib/plugins/cors.mjs +34 -0
- package/lib/plugins/file_parser.d.mts +15 -0
- package/lib/plugins/file_parser.mjs +24 -0
- package/lib/plugins/form_body_parser.d.mts +12 -0
- package/lib/plugins/form_body_parser.mjs +15 -0
- package/lib/plugins/ws_parser.d.mts +12 -0
- package/lib/plugins/ws_parser.mjs +15 -0
- package/lib/plugins/xml_parser.d.mts +19 -0
- package/lib/plugins/xml_parser.mjs +40 -0
- package/lib/services/ai.d.mts +31 -0
- package/lib/services/ai.mjs +44 -0
- package/lib/services/base.d.mts +4 -0
- package/lib/services/base.mjs +1 -0
- package/lib/services/cache.d.mts +165 -0
- package/lib/services/cache.mjs +323 -0
- package/lib/services/captcha.d.mts +65 -0
- package/lib/services/captcha.mjs +61 -0
- package/lib/services/{crypto.js → crypto.d.mts} +19 -78
- package/lib/services/crypto.mjs +141 -0
- package/lib/services/db_value.d.mts +60 -0
- package/lib/services/db_value.mjs +64 -0
- package/lib/services/dingtalk.d.mts +39 -0
- package/lib/services/dingtalk.mjs +44 -0
- package/lib/services/dispose.d.mts +17 -0
- package/lib/services/dispose.mjs +18 -0
- package/lib/services/emoji.d.mts +10 -0
- package/lib/services/emoji.mjs +2025 -0
- package/lib/services/file_store.d.mts +49 -0
- package/lib/services/file_store.mjs +58 -0
- package/lib/services/html.d.mts +11 -0
- package/lib/services/html.mjs +12 -0
- package/lib/services/jwt.d.mts +33 -0
- package/lib/services/jwt.mjs +42 -0
- package/lib/services/log.d.mts +37 -0
- package/lib/services/log.mjs +99 -0
- package/lib/services/mail.d.mts +22 -0
- package/lib/services/mail.mjs +28 -0
- package/lib/services/pay.d.mts +123 -0
- package/lib/services/pay.mjs +157 -0
- package/lib/services/random.d.mts +27 -0
- package/lib/services/random.mjs +42 -0
- package/lib/services/rate_limit.d.mts +37 -0
- package/lib/services/rate_limit.mjs +40 -0
- package/lib/services/redis.d.mts +11 -0
- package/lib/services/redis.mjs +6 -0
- package/lib/services/sensitive_words.d.mts +29 -0
- package/lib/services/sensitive_words.mjs +37 -0
- package/lib/services/sms.d.mts +40 -0
- package/lib/services/sms.mjs +30238 -0
- package/lib/types/dto.d.mts +30 -0
- package/lib/types/dto.mjs +1 -0
- package/lib/x.d.mts +11 -0
- package/lib/x.mjs +21 -0
- package/lib/x_init.d.mts +1 -0
- package/lib/x_init.mjs +10 -0
- package/package.json +99 -43
- package/lib/_cjs/cli/api_generator.js +0 -438
- package/lib/_cjs/cli/build_util.js +0 -243
- package/lib/_cjs/cli/cli.js +0 -378
- package/lib/_cjs/cli/css_register.js +0 -7
- package/lib/_cjs/cli/deploy_util.js +0 -76
- package/lib/_cjs/cli/dev_util.js +0 -25
- package/lib/_cjs/cli/env_util.js +0 -252
- package/lib/_cjs/cli/esbuild_register.js +0 -7
- package/lib/_cjs/cli/template_util.js +0 -101
- package/lib/_cjs/cli/templates/crons.ts +0 -2
- package/lib/_cjs/cli/templates/handlers.ts +0 -3
- package/lib/_cjs/cli/templates/hooks.ts +0 -2
- package/lib/_cjs/cli/templates/models.ts +0 -123
- package/lib/_cjs/cli/templates/package.json +0 -3
- package/lib/_cjs/cli/templates/routes.ts +0 -68
- package/lib/_cjs/core/ctx_storage.js +0 -6
- package/lib/_cjs/core/define_bus.js +0 -31
- package/lib/_cjs/core/define_cron.js +0 -13
- package/lib/_cjs/core/define_handler.js +0 -56
- package/lib/_cjs/core/define_hook.js +0 -8
- package/lib/_cjs/core/define_server.js +0 -10
- package/lib/_cjs/core/define_task.js +0 -113
- package/lib/_cjs/core/get_handler_url.js +0 -11
- package/lib/_cjs/core/handler.js +0 -216
- package/lib/_cjs/core/http_error.js +0 -6
- package/lib/_cjs/core/http_header.js +0 -142
- package/lib/_cjs/core/http_method.js +0 -12
- package/lib/_cjs/core/http_redirect.js +0 -11
- package/lib/_cjs/core/server.js +0 -221
- package/lib/_cjs/core/types.js +0 -8
- package/lib/_cjs/exports.js +0 -273
- package/lib/_cjs/index.js +0 -15
- package/lib/_cjs/plugins/base.js +0 -3
- package/lib/_cjs/plugins/compress.js +0 -18
- package/lib/_cjs/plugins/cookie.js +0 -18
- package/lib/_cjs/plugins/cors.js +0 -38
- package/lib/_cjs/plugins/file_parser.js +0 -28
- package/lib/_cjs/plugins/form_body_parser.js +0 -18
- package/lib/_cjs/plugins/ws_parser.js +0 -18
- package/lib/_cjs/plugins/xml_parser.js +0 -48
- package/lib/_cjs/services/ai.js +0 -48
- package/lib/_cjs/services/base.js +0 -3
- package/lib/_cjs/services/cache.js +0 -400
- package/lib/_cjs/services/captcha.js +0 -78
- package/lib/_cjs/services/crypto.js +0 -175
- package/lib/_cjs/services/db_value.js +0 -77
- package/lib/_cjs/services/dingtalk.js +0 -51
- package/lib/_cjs/services/dispose.js +0 -23
- package/lib/_cjs/services/emoji.js +0 -2034
- package/lib/_cjs/services/file_store.js +0 -67
- package/lib/_cjs/services/html.js +0 -17
- package/lib/_cjs/services/jwt.js +0 -65
- package/lib/_cjs/services/log.js +0 -108
- package/lib/_cjs/services/mail.js +0 -31
- package/lib/_cjs/services/pay.js +0 -191
- package/lib/_cjs/services/random.js +0 -51
- package/lib/_cjs/services/rate_limit.js +0 -54
- package/lib/_cjs/services/redis.js +0 -12
- package/lib/_cjs/services/sensitive_words.js +0 -62
- package/lib/_cjs/services/sms.js +0 -84
- package/lib/_cjs/types/dto.js +0 -3
- package/lib/_cjs/x.js +0 -35
- package/lib/cli/api_generator.d.ts +0 -74
- package/lib/cli/api_generator.js +0 -432
- package/lib/cli/build_util.d.ts +0 -17
- package/lib/cli/build_util.js +0 -236
- package/lib/cli/cli.d.ts +0 -2
- package/lib/cli/cli.js +0 -374
- package/lib/cli/css_register.js +0 -5
- package/lib/cli/deploy_util.d.ts +0 -23
- package/lib/cli/deploy_util.js +0 -70
- package/lib/cli/dev_util.d.ts +0 -8
- package/lib/cli/dev_util.js +0 -19
- package/lib/cli/env_util.d.ts +0 -45
- package/lib/cli/env_util.js +0 -246
- package/lib/cli/esbuild_register.js +0 -5
- package/lib/cli/template_util.d.ts +0 -18
- package/lib/cli/template_util.js +0 -95
- package/lib/core/ctx_storage.d.ts +0 -3
- package/lib/core/ctx_storage.js +0 -2
- package/lib/core/define_bus.d.ts +0 -37
- package/lib/core/define_bus.js +0 -27
- package/lib/core/define_cron.js +0 -9
- package/lib/core/define_handler.js +0 -48
- package/lib/core/define_hook.d.ts +0 -2
- package/lib/core/define_hook.js +0 -4
- package/lib/core/define_server.d.ts +0 -3
- package/lib/core/define_server.js +0 -6
- package/lib/core/define_task.js +0 -107
- package/lib/core/get_handler_url.d.ts +0 -2
- package/lib/core/get_handler_url.js +0 -7
- package/lib/core/handler.d.ts +0 -16
- package/lib/core/handler.js +0 -209
- package/lib/core/http_error.d.ts +0 -2
- package/lib/core/http_error.js +0 -2
- package/lib/core/http_header.d.ts +0 -856
- package/lib/core/http_header.js +0 -139
- package/lib/core/http_method.d.ts +0 -3
- package/lib/core/http_method.js +0 -8
- package/lib/core/http_redirect.d.ts +0 -5
- package/lib/core/http_redirect.js +0 -6
- package/lib/core/server.d.ts +0 -20
- package/lib/core/server.js +0 -215
- package/lib/core/types.d.ts +0 -265
- package/lib/core/types.js +0 -4
- package/lib/exports.d.ts +0 -45
- package/lib/exports.js +0 -47
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -3
- package/lib/plugins/base.d.ts +0 -4
- package/lib/plugins/base.js +0 -1
- package/lib/plugins/compress.d.ts +0 -13
- package/lib/plugins/compress.js +0 -12
- package/lib/plugins/cookie.d.ts +0 -13
- package/lib/plugins/cookie.js +0 -12
- package/lib/plugins/cors.d.ts +0 -22
- package/lib/plugins/cors.js +0 -33
- package/lib/plugins/file_parser.d.ts +0 -16
- package/lib/plugins/file_parser.js +0 -22
- package/lib/plugins/form_body_parser.d.ts +0 -13
- package/lib/plugins/form_body_parser.js +0 -12
- package/lib/plugins/ws_parser.d.ts +0 -13
- package/lib/plugins/ws_parser.js +0 -12
- package/lib/plugins/xml_parser.d.ts +0 -19
- package/lib/plugins/xml_parser.js +0 -43
- package/lib/services/ai.d.ts +0 -31
- package/lib/services/ai.js +0 -43
- package/lib/services/base.d.ts +0 -4
- package/lib/services/base.js +0 -1
- package/lib/services/cache.d.ts +0 -173
- package/lib/services/cache.js +0 -394
- package/lib/services/captcha.d.ts +0 -65
- package/lib/services/captcha.js +0 -72
- package/lib/services/crypto.d.ts +0 -110
- package/lib/services/db_value.d.ts +0 -60
- package/lib/services/db_value.js +0 -72
- package/lib/services/dingtalk.d.ts +0 -39
- package/lib/services/dingtalk.js +0 -45
- package/lib/services/dispose.d.ts +0 -17
- package/lib/services/dispose.js +0 -17
- package/lib/services/emoji.d.ts +0 -10
- package/lib/services/emoji.js +0 -2029
- package/lib/services/file_store.d.ts +0 -49
- package/lib/services/file_store.js +0 -61
- package/lib/services/html.d.ts +0 -11
- package/lib/services/html.js +0 -12
- package/lib/services/jwt.d.ts +0 -34
- package/lib/services/jwt.js +0 -59
- package/lib/services/log.d.ts +0 -37
- package/lib/services/log.js +0 -102
- package/lib/services/mail.d.ts +0 -23
- package/lib/services/mail.js +0 -25
- package/lib/services/pay.d.ts +0 -123
- package/lib/services/pay.js +0 -185
- package/lib/services/random.d.ts +0 -27
- package/lib/services/random.js +0 -45
- package/lib/services/rate_limit.d.ts +0 -37
- package/lib/services/rate_limit.js +0 -49
- package/lib/services/redis.d.ts +0 -12
- package/lib/services/redis.js +0 -7
- package/lib/services/sensitive_words.d.ts +0 -30
- package/lib/services/sensitive_words.js +0 -57
- package/lib/services/sms.d.ts +0 -40
- package/lib/services/sms.js +0 -78
- package/lib/types/dto.d.ts +0 -86
- package/lib/types/dto.js +0 -1
- package/lib/x.d.ts +0 -17
- package/lib/x.js +0 -30
- /package/lib/{cli/css_register.d.ts → core/types.mjs} +0 -0
- /package/lib/{cli/esbuild_register.d.ts → plugins/base.mjs} +0 -0
package/lib/services/cache.js
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import cuid from 'cuid';
|
|
2
|
-
import superjson from 'superjson';
|
|
3
|
-
import { ms } from 'vtils';
|
|
4
|
-
import { x } from "../x";
|
|
5
|
-
const nativeJsonSerializer = {
|
|
6
|
-
stringify: JSON.stringify,
|
|
7
|
-
parse: JSON.parse
|
|
8
|
-
};
|
|
9
|
-
const superJsonSerializer = {
|
|
10
|
-
stringify: superjson.stringify,
|
|
11
|
-
parse: superjson.parse
|
|
12
|
-
};
|
|
13
|
-
export class CacheService {
|
|
14
|
-
constructor(options) {
|
|
15
|
-
this.options = options;
|
|
16
|
-
this.serviceName = 'cache';
|
|
17
|
-
this.prefix = void 0;
|
|
18
|
-
this.hasMemoryCache = false;
|
|
19
|
-
this.hasMemoryCacheOnly = false;
|
|
20
|
-
this.memoryCache = void 0;
|
|
21
|
-
this.serializer = void 0;
|
|
22
|
-
this.prefix = `${x.appId}:`;
|
|
23
|
-
this.hasMemoryCache = !!options.memory;
|
|
24
|
-
this.hasMemoryCacheOnly = options.memory === 'only';
|
|
25
|
-
this.serializer = options.serializer == null || options.serializer === 'nativeJson' ? nativeJsonSerializer : options.serializer === 'superJson' ? superJsonSerializer : options.serializer;
|
|
26
|
-
this.memoryCache = !this.hasMemoryCache ? undefined : new Map();
|
|
27
|
-
}
|
|
28
|
-
toRedisKey(key) {
|
|
29
|
-
return `${this.prefix}${Array.isArray(key) ? key.join('_') : String(key)}`;
|
|
30
|
-
}
|
|
31
|
-
serialize(value) {
|
|
32
|
-
return this.serializer.stringify(value);
|
|
33
|
-
}
|
|
34
|
-
deserialize(value) {
|
|
35
|
-
return this.serializer.parse(value);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 设置缓存内容。对象类内容尽量避免使用,以免造成问题。
|
|
40
|
-
*
|
|
41
|
-
* @memory 支持
|
|
42
|
-
* @param key 键
|
|
43
|
-
* @param value 值
|
|
44
|
-
* @param ttlOrOptions 缓存时间或选项
|
|
45
|
-
* @returns 返回设置的缓存内容
|
|
46
|
-
*/
|
|
47
|
-
async set(key, value, ttlOrOptions) {
|
|
48
|
-
const ttl = ttlOrOptions == null ? this.options.ttl : typeof ttlOrOptions === 'object' ? ttlOrOptions.ttl : ttlOrOptions;
|
|
49
|
-
const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
|
|
50
|
-
if (redisTtl) {
|
|
51
|
-
const redisTtlMs = ms(redisTtl);
|
|
52
|
-
// Redis 的 TTL 不能小于等于 0
|
|
53
|
-
if (redisTtlMs > 0) {
|
|
54
|
-
const redisKey = this.toRedisKey(key);
|
|
55
|
-
if (!this.hasMemoryCacheOnly) {
|
|
56
|
-
const redisValue = this.serialize(value);
|
|
57
|
-
await x.redis.set(redisKey, redisValue,
|
|
58
|
-
// 毫秒
|
|
59
|
-
'PX', redisTtlMs);
|
|
60
|
-
}
|
|
61
|
-
if (this.hasMemoryCache) {
|
|
62
|
-
this.memoryCache.set(redisKey, value);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 存储值然后返回其对应的键,该键 URL 友好。
|
|
71
|
-
*
|
|
72
|
-
* @memory 支持
|
|
73
|
-
* @param value 值
|
|
74
|
-
* @param ttl 存活时间
|
|
75
|
-
*/
|
|
76
|
-
async save(value, ttl = this.options.ttl) {
|
|
77
|
-
const key = `X__${cuid()}`;
|
|
78
|
-
await this.set(key, typeof value === 'function' ? await value(key) : value, ttl);
|
|
79
|
-
return key;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 获取缓存内容。
|
|
84
|
-
*
|
|
85
|
-
* @memory 支持
|
|
86
|
-
* @param key 键
|
|
87
|
-
* @param options 选项
|
|
88
|
-
* @returns 返回获取到的缓存内容
|
|
89
|
-
*/
|
|
90
|
-
async get(key) {
|
|
91
|
-
const redisKey = this.toRedisKey(key);
|
|
92
|
-
if (this.hasMemoryCache) {
|
|
93
|
-
if (this.memoryCache.has(redisKey)) {
|
|
94
|
-
return this.memoryCache.get(redisKey);
|
|
95
|
-
} else if (this.hasMemoryCacheOnly) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const gotValue = await x.redis.get(redisKey);
|
|
100
|
-
if (gotValue) {
|
|
101
|
-
try {
|
|
102
|
-
const parsedValue = this.deserialize(gotValue);
|
|
103
|
-
if (this.hasMemoryCache) {
|
|
104
|
-
this.memoryCache.set(redisKey, parsedValue);
|
|
105
|
-
}
|
|
106
|
-
return parsedValue;
|
|
107
|
-
} catch {}
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 获取多个缓存内容。
|
|
114
|
-
*
|
|
115
|
-
* @memory 支持
|
|
116
|
-
* @param keys 键
|
|
117
|
-
* @returns 返回获取到的缓存内容
|
|
118
|
-
*/
|
|
119
|
-
async getMany(...keys) {
|
|
120
|
-
const redisKeys = keys.map(key => this.toRedisKey(key));
|
|
121
|
-
if (!redisKeys.length) return [];
|
|
122
|
-
if (this.hasMemoryCacheOnly) {
|
|
123
|
-
return redisKeys.map(redisKey => this.memoryCache.has(redisKey) ? this.memoryCache.get(redisKey) : null);
|
|
124
|
-
}
|
|
125
|
-
if (this.hasMemoryCache) {
|
|
126
|
-
const result = new Array(keys.length).fill(null);
|
|
127
|
-
const missIndexes = [];
|
|
128
|
-
const missRedisKeys = [];
|
|
129
|
-
for (let i = 0; i < redisKeys.length; i++) {
|
|
130
|
-
if (this.memoryCache.has(redisKeys[i])) {
|
|
131
|
-
result[i] = this.memoryCache.get(redisKeys[i]);
|
|
132
|
-
} else {
|
|
133
|
-
missIndexes.push(i);
|
|
134
|
-
missRedisKeys.push(redisKeys[i]);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (missRedisKeys.length) {
|
|
138
|
-
const gotValues = await x.redis.mget(...missRedisKeys);
|
|
139
|
-
gotValues.forEach((value, idx) => {
|
|
140
|
-
if (value != null) {
|
|
141
|
-
try {
|
|
142
|
-
const parsed = this.deserialize(value);
|
|
143
|
-
this.memoryCache.set(missRedisKeys[idx], parsed);
|
|
144
|
-
result[missIndexes[idx]] = parsed;
|
|
145
|
-
} catch {}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
const gotValues = await x.redis.mget(...redisKeys);
|
|
152
|
-
return gotValues.map(value => {
|
|
153
|
-
if (value == null) return null;
|
|
154
|
-
try {
|
|
155
|
-
return this.deserialize(value);
|
|
156
|
-
} catch {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 获取距离过期时间的毫秒数(未设置过期时间返回-1,键不存在返回-2)。
|
|
164
|
-
* memory=only 模式下内存缓存无 TTL 概念,始终返回-1。
|
|
165
|
-
*
|
|
166
|
-
* @memory 支持
|
|
167
|
-
* @param key 键
|
|
168
|
-
* @returns 返回距离过期时间的毫秒数
|
|
169
|
-
*/
|
|
170
|
-
async ttl(key) {
|
|
171
|
-
if (this.hasMemoryCacheOnly) {
|
|
172
|
-
return -1;
|
|
173
|
-
}
|
|
174
|
-
const redisKey = this.toRedisKey(key);
|
|
175
|
-
return x.redis.pttl(redisKey);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* 缓存内容。
|
|
180
|
-
*
|
|
181
|
-
* @memory 支持
|
|
182
|
-
* @param key 键
|
|
183
|
-
* @param action 获取缓存内容的操作
|
|
184
|
-
* @param ttlOrOptions 缓存时间或选项
|
|
185
|
-
* @returns 返回获取到的内容
|
|
186
|
-
*/
|
|
187
|
-
async remember(key, action, ttlOrOptions) {
|
|
188
|
-
let value = await this.get(key);
|
|
189
|
-
if (value === null) {
|
|
190
|
-
value = await action();
|
|
191
|
-
await this.set(key, value, ttlOrOptions);
|
|
192
|
-
}
|
|
193
|
-
return value;
|
|
194
|
-
}
|
|
195
|
-
async rememberMany(raws, key, action, ttlOrOptions) {
|
|
196
|
-
const keys = raws.map(key);
|
|
197
|
-
const values = await this.getMany(...keys);
|
|
198
|
-
const shouldUpdateIndexes = [];
|
|
199
|
-
for (let i = 0, len = values.length; i < len; i++) {
|
|
200
|
-
if (values[i] === null) {
|
|
201
|
-
shouldUpdateIndexes.push(i);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (shouldUpdateIndexes.length) {
|
|
205
|
-
const nextValues = await action(shouldUpdateIndexes.map(i => raws[i]));
|
|
206
|
-
await Promise.all(nextValues.map(async (nextValue, index) => {
|
|
207
|
-
values[shouldUpdateIndexes[index]] = nextValue;
|
|
208
|
-
await this.set(keys[shouldUpdateIndexes[index]], nextValue, ttlOrOptions);
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
return values;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* 自增。
|
|
216
|
-
*
|
|
217
|
-
* @memory 支持
|
|
218
|
-
* @param key 键
|
|
219
|
-
* @param increment 增量
|
|
220
|
-
*/
|
|
221
|
-
async increase(key, increment = 1) {
|
|
222
|
-
const redisKey = this.toRedisKey(key);
|
|
223
|
-
if (this.hasMemoryCacheOnly) {
|
|
224
|
-
const current = this.memoryCache.get(redisKey) ?? 0;
|
|
225
|
-
const next = current + increment;
|
|
226
|
-
this.memoryCache.set(redisKey, next);
|
|
227
|
-
return next;
|
|
228
|
-
}
|
|
229
|
-
const result = await x.redis.incrby(redisKey, increment);
|
|
230
|
-
if (this.hasMemoryCache) {
|
|
231
|
-
this.memoryCache.delete(redisKey);
|
|
232
|
-
}
|
|
233
|
-
return result;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* 自减。
|
|
238
|
-
*
|
|
239
|
-
* @memory 支持
|
|
240
|
-
* @param key 键
|
|
241
|
-
* @param decrement 减量
|
|
242
|
-
*/
|
|
243
|
-
async decrease(key, decrement = 1) {
|
|
244
|
-
return this.increase(key, -decrement);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 新增元素。
|
|
249
|
-
*
|
|
250
|
-
* @memory 支持
|
|
251
|
-
* @param key 键
|
|
252
|
-
* @param values 元素列表
|
|
253
|
-
*/
|
|
254
|
-
async push(key, ...values) {
|
|
255
|
-
const redisKey = this.toRedisKey(key);
|
|
256
|
-
if (this.hasMemoryCacheOnly) {
|
|
257
|
-
const arr = this.memoryCache.get(redisKey) ?? [];
|
|
258
|
-
arr.push(...values);
|
|
259
|
-
this.memoryCache.set(redisKey, arr);
|
|
260
|
-
return arr.length;
|
|
261
|
-
}
|
|
262
|
-
const result = await x.redis.rpush(redisKey, ...values.map(value => this.serialize(value)));
|
|
263
|
-
if (this.hasMemoryCache) {
|
|
264
|
-
this.memoryCache.delete(redisKey);
|
|
265
|
-
}
|
|
266
|
-
return result;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* 从头部弹出元素并返回。
|
|
271
|
-
*
|
|
272
|
-
* @memory 支持
|
|
273
|
-
* @param key 键
|
|
274
|
-
* @param count 弹出元素个数
|
|
275
|
-
*/
|
|
276
|
-
async shift(key, count = 1) {
|
|
277
|
-
const redisKey = this.toRedisKey(key);
|
|
278
|
-
if (this.hasMemoryCacheOnly) {
|
|
279
|
-
const arr = this.memoryCache.get(redisKey) ?? [];
|
|
280
|
-
const res = arr.splice(0, count);
|
|
281
|
-
if (arr.length) {
|
|
282
|
-
this.memoryCache.set(redisKey, arr);
|
|
283
|
-
} else {
|
|
284
|
-
this.memoryCache.delete(redisKey);
|
|
285
|
-
}
|
|
286
|
-
return res;
|
|
287
|
-
}
|
|
288
|
-
const res = [];
|
|
289
|
-
for (let i = 0; i < count; i++) {
|
|
290
|
-
const item = await x.redis.lpop(redisKey);
|
|
291
|
-
if (item) {
|
|
292
|
-
res.push(this.deserialize(item));
|
|
293
|
-
} else {
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (this.hasMemoryCache && res.length) {
|
|
298
|
-
this.memoryCache.delete(redisKey);
|
|
299
|
-
}
|
|
300
|
-
return res;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* 删除缓存。
|
|
305
|
-
*
|
|
306
|
-
* @memory 支持
|
|
307
|
-
* @param keys 键列表
|
|
308
|
-
*/
|
|
309
|
-
async remove(...keys) {
|
|
310
|
-
if (!keys.length) {
|
|
311
|
-
return 0;
|
|
312
|
-
}
|
|
313
|
-
const redisKeys = keys.map(key => this.toRedisKey(key));
|
|
314
|
-
let count = 0;
|
|
315
|
-
if (!this.hasMemoryCacheOnly) {
|
|
316
|
-
count = await x.redis.del(...redisKeys);
|
|
317
|
-
}
|
|
318
|
-
if (this.hasMemoryCache) {
|
|
319
|
-
let deletedCount = 0;
|
|
320
|
-
redisKeys.forEach(redisKey => {
|
|
321
|
-
const isDeleted = this.memoryCache.delete(redisKey);
|
|
322
|
-
if (isDeleted) {
|
|
323
|
-
deletedCount++;
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
if (this.hasMemoryCacheOnly) {
|
|
327
|
-
count = deletedCount;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return count;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* 清空全部缓存。
|
|
335
|
-
*
|
|
336
|
-
* @memory 支持
|
|
337
|
-
*/
|
|
338
|
-
async clearAll() {
|
|
339
|
-
let count = 0;
|
|
340
|
-
if (!this.hasMemoryCacheOnly) {
|
|
341
|
-
const keys = await x.redis.keys(`${this.prefix}*`);
|
|
342
|
-
count = keys.length ? await x.redis.del(...keys) : 0;
|
|
343
|
-
}
|
|
344
|
-
if (this.hasMemoryCache) {
|
|
345
|
-
const memoryCacheSize = this.memoryCache.size;
|
|
346
|
-
this.memoryCache.clear();
|
|
347
|
-
if (this.hasMemoryCacheOnly) {
|
|
348
|
-
count = memoryCacheSize;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return count;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* 清空指定前缀的缓存。
|
|
356
|
-
*
|
|
357
|
-
* @memory 支持
|
|
358
|
-
*/
|
|
359
|
-
async clear(...prefixes) {
|
|
360
|
-
if (!prefixes.length) {
|
|
361
|
-
return 0;
|
|
362
|
-
}
|
|
363
|
-
let count = 0;
|
|
364
|
-
if (!this.hasMemoryCacheOnly) {
|
|
365
|
-
const keys = (await Promise.all(prefixes.map(prefix => x.redis.keys(`${this.toRedisKey(prefix)}*`)))).flat();
|
|
366
|
-
count = keys.length ? await x.redis.del(...keys) : 0;
|
|
367
|
-
}
|
|
368
|
-
if (this.options.memory) {
|
|
369
|
-
let deletedCount = 0;
|
|
370
|
-
this.memoryCache.forEach((_v, k) => {
|
|
371
|
-
if (prefixes.some(prefix => k.startsWith(this.toRedisKey(prefix)))) {
|
|
372
|
-
const isDeleted = this.memoryCache.delete(k);
|
|
373
|
-
if (isDeleted) {
|
|
374
|
-
deletedCount++;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
if (this.hasMemoryCacheOnly) {
|
|
379
|
-
count = deletedCount;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return count;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* 派生出一个指定类型的缓存服务。
|
|
387
|
-
*/
|
|
388
|
-
fork(options) {
|
|
389
|
-
return options ? new CacheService({
|
|
390
|
-
...this.options,
|
|
391
|
-
...options
|
|
392
|
-
}) : this;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { type MsValue } from 'vtils';
|
|
2
|
-
import { BaseService } from './base';
|
|
3
|
-
export type CaptchaServiceGenerateCharset = '09' | '19' | 'az' | 'AZ' | 'aZ' | '0z' | '0Z' | '1z' | '1Z';
|
|
4
|
-
export interface CaptchaServiceGeneratePayload<T> {
|
|
5
|
-
/**
|
|
6
|
-
* 场景值
|
|
7
|
-
*
|
|
8
|
-
* 比如:防止后台验证码图片登录用其他场景下的短信验证码
|
|
9
|
-
*/
|
|
10
|
-
scene: string;
|
|
11
|
-
/**
|
|
12
|
-
* 验证码长度
|
|
13
|
-
*/
|
|
14
|
-
size: number;
|
|
15
|
-
/**
|
|
16
|
-
* 验证码存活时长
|
|
17
|
-
*/
|
|
18
|
-
ttl: MsValue;
|
|
19
|
-
/**
|
|
20
|
-
* 字符集
|
|
21
|
-
*/
|
|
22
|
-
charset: CaptchaServiceGenerateCharset;
|
|
23
|
-
/**
|
|
24
|
-
* 可重试次数
|
|
25
|
-
*
|
|
26
|
-
* @default 0
|
|
27
|
-
*/
|
|
28
|
-
retryCount?: number;
|
|
29
|
-
/**
|
|
30
|
-
* 其他信息
|
|
31
|
-
*/
|
|
32
|
-
extra?: T;
|
|
33
|
-
}
|
|
34
|
-
export interface CaptchaServiceGenerateResult {
|
|
35
|
-
token: string;
|
|
36
|
-
code: string;
|
|
37
|
-
}
|
|
38
|
-
export interface CaptchaServiceGenerateImageResult {
|
|
39
|
-
token: string;
|
|
40
|
-
code: string;
|
|
41
|
-
svg: string;
|
|
42
|
-
}
|
|
43
|
-
export interface CaptchaServiceGenerateDataUrlResult {
|
|
44
|
-
token: string;
|
|
45
|
-
code: string;
|
|
46
|
-
dataUrl: string;
|
|
47
|
-
}
|
|
48
|
-
export interface CaptchaServiceVerifyOptions<T> {
|
|
49
|
-
token: string;
|
|
50
|
-
code: string;
|
|
51
|
-
scene: string;
|
|
52
|
-
extra?: (extra: T) => boolean;
|
|
53
|
-
}
|
|
54
|
-
export declare class CaptchaService implements BaseService {
|
|
55
|
-
serviceName: string;
|
|
56
|
-
private charsetMap;
|
|
57
|
-
generate<T extends Record<string, any>>(payload: CaptchaServiceGeneratePayload<T>): Promise<CaptchaServiceGenerateResult>;
|
|
58
|
-
generateDataUrl<T extends Record<string, any>>(payload: CaptchaServiceGeneratePayload<T>): Promise<CaptchaServiceGenerateDataUrlResult>;
|
|
59
|
-
verify<T extends Record<string, any>>(options: CaptchaServiceVerifyOptions<T>): Promise<boolean>;
|
|
60
|
-
}
|
|
61
|
-
declare module '../x' {
|
|
62
|
-
interface X {
|
|
63
|
-
captcha: CaptchaService;
|
|
64
|
-
}
|
|
65
|
-
}
|
package/lib/services/captcha.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import svgToDataUrl from 'mini-svg-data-uri';
|
|
2
|
-
import svgCaptcha from 'svg-captcha';
|
|
3
|
-
import { sample } from 'vtils';
|
|
4
|
-
import { x } from "../x";
|
|
5
|
-
export class CaptchaService {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.serviceName = 'captcha';
|
|
8
|
-
this.charsetMap = {
|
|
9
|
-
'09': '0123456789'.split(''),
|
|
10
|
-
'19': '123456789'.split(''),
|
|
11
|
-
'az': 'abcdefghijklmnopqrstuvwxyz'.split(''),
|
|
12
|
-
'AZ': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''),
|
|
13
|
-
'aZ': 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''),
|
|
14
|
-
'0z': '0123456789abcdefghijklmnopqrstuvwxyz'.split(''),
|
|
15
|
-
'0Z': '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''),
|
|
16
|
-
'1z': '123456789abcdefghijklmnopqrstuvwxyz'.split(''),
|
|
17
|
-
'1Z': '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
async generate(payload) {
|
|
21
|
-
const chars = this.charsetMap[payload.charset];
|
|
22
|
-
let code = '';
|
|
23
|
-
for (let i = 0; i < payload.size; i++) {
|
|
24
|
-
code += sample(chars);
|
|
25
|
-
}
|
|
26
|
-
const token = await x.cache.save({
|
|
27
|
-
code: code,
|
|
28
|
-
scene: payload.scene,
|
|
29
|
-
retryCount: payload.retryCount ?? 0,
|
|
30
|
-
extra: payload.extra
|
|
31
|
-
}, payload.ttl);
|
|
32
|
-
return {
|
|
33
|
-
token: token,
|
|
34
|
-
code: code
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
async generateDataUrl(payload) {
|
|
38
|
-
const {
|
|
39
|
-
text: code,
|
|
40
|
-
data: svg
|
|
41
|
-
} = svgCaptcha.create({
|
|
42
|
-
size: payload.size,
|
|
43
|
-
charPreset: this.charsetMap[payload.charset].join('')
|
|
44
|
-
});
|
|
45
|
-
const token = await x.cache.save({
|
|
46
|
-
code: code,
|
|
47
|
-
scene: payload.scene,
|
|
48
|
-
retryCount: payload.retryCount || 0,
|
|
49
|
-
extra: payload.extra
|
|
50
|
-
}, payload.ttl);
|
|
51
|
-
const dataUrl = svgToDataUrl(svg);
|
|
52
|
-
return {
|
|
53
|
-
token: token,
|
|
54
|
-
code: code,
|
|
55
|
-
dataUrl: dataUrl
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
async verify(options) {
|
|
59
|
-
const expected = await x.cache.get(options.token);
|
|
60
|
-
if (expected == null) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
if (expected.retryCount === 0) {
|
|
64
|
-
await x.cache.remove(options.token);
|
|
65
|
-
} else {
|
|
66
|
-
expected.retryCount--;
|
|
67
|
-
const ttl = await x.cache.ttl(options.token);
|
|
68
|
-
await x.cache.set(options.token, expected, ttl);
|
|
69
|
-
}
|
|
70
|
-
return expected.scene === options.scene && options.code.toLowerCase() === expected.code.toLowerCase() && (options.extra ? options.extra(expected.extra) : true);
|
|
71
|
-
}
|
|
72
|
-
}
|
package/lib/services/crypto.d.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { BaseService } from './base';
|
|
2
|
-
export declare class CryptoService implements BaseService {
|
|
3
|
-
serviceName: string;
|
|
4
|
-
/**
|
|
5
|
-
* 将给定的文本转换为 Base64 编码的字符串
|
|
6
|
-
*
|
|
7
|
-
* @param text 需要编码的原始文本
|
|
8
|
-
* @returns 返回 Base64 编码后的字符串
|
|
9
|
-
*/
|
|
10
|
-
base64Encode(text: string): string;
|
|
11
|
-
/**
|
|
12
|
-
* 将 Base64 编码的字符串转换为 UTF-8 编码的字符串
|
|
13
|
-
*
|
|
14
|
-
* @param text Base64 编码的字符串
|
|
15
|
-
* @returns 转换后的 UTF-8 编码的字符串
|
|
16
|
-
*/
|
|
17
|
-
base64Decode(text: string): string;
|
|
18
|
-
/**
|
|
19
|
-
* 将字符串文本编码为Base64 URL格式
|
|
20
|
-
*
|
|
21
|
-
* 此函数的目的是将输入的字符串转换为Base64编码,并进一步转换为URL安全的格式
|
|
22
|
-
* Base64标准字符集中的'+'和'/'在URL中有特殊意义,因此需要被替换为'-'和'_'
|
|
23
|
-
* 此外,Base64编码中用于填充的'='字符在URL中通常被视为不必要的,因此也会被移除
|
|
24
|
-
*
|
|
25
|
-
* @param text 需要被编码的字符串文本
|
|
26
|
-
* @returns 编码后的Base64 URL安全字符串
|
|
27
|
-
*/
|
|
28
|
-
base64UrlEncode(text: string): string;
|
|
29
|
-
/**
|
|
30
|
-
* 解码base64url格式的字符串
|
|
31
|
-
* base64url是一种用于URL的base64编码变体,它将标准base64中的'+'和'/'字符替换为'-'和'_',以避免URL编码
|
|
32
|
-
* 此函数的作用是将base64url编码的字符串解码回原始字符串
|
|
33
|
-
*
|
|
34
|
-
* @param text 需要解码的base64url格式的字符串
|
|
35
|
-
* @returns 解码后的原始字符串
|
|
36
|
-
*/
|
|
37
|
-
base64UrlDecode(text: string): string;
|
|
38
|
-
/**
|
|
39
|
-
* 使用MD5算法对文本进行哈希处理
|
|
40
|
-
*
|
|
41
|
-
* @param text 需要进行哈希处理的文本
|
|
42
|
-
* @returns 返回经过MD5哈希处理后的字符串
|
|
43
|
-
*/
|
|
44
|
-
md5(text: string): string;
|
|
45
|
-
/**
|
|
46
|
-
* 使用SHA-1算法对文本进行哈希处理
|
|
47
|
-
*
|
|
48
|
-
* SHA-1是一种安全散列算法,它接收一个输入(在此例中为文本字符串),
|
|
49
|
-
* 并返回一个固定大小的160位散列值,通常以40位的十六进制数字表示
|
|
50
|
-
* 此函数用于将给定的文本转换为SHA-1散列值,常用于数据完整性校验或存储密码的散列值
|
|
51
|
-
*
|
|
52
|
-
* @param text 待哈希处理的文本字符串
|
|
53
|
-
* @returns 返回文本的SHA-1散列值,以十六进制字符串形式表示
|
|
54
|
-
*/
|
|
55
|
-
sha1(text: string): string;
|
|
56
|
-
/**
|
|
57
|
-
* 使用SHA-256算法对文本进行哈希处理
|
|
58
|
-
*
|
|
59
|
-
* @param text 输入的文本字符串
|
|
60
|
-
* @returns 返回经过SHA-256哈希处理后的十六进制字符串
|
|
61
|
-
*/
|
|
62
|
-
sha256(text: string): string;
|
|
63
|
-
/**
|
|
64
|
-
* 使用SHA-512算法对文本进行哈希处理
|
|
65
|
-
*
|
|
66
|
-
* @param text 输入的文本字符串
|
|
67
|
-
* @returns 返回经过SHA-512哈希处理后的字符串
|
|
68
|
-
*/
|
|
69
|
-
sha512(text: string): string;
|
|
70
|
-
/**
|
|
71
|
-
* 使用给定的密钥对给定的字符串执行 AES 加密(加密模式为 ECB,填充方式为 PKCS7)。
|
|
72
|
-
*
|
|
73
|
-
* @param text - 要加密的字符串。
|
|
74
|
-
* @param key - 用于加密的密钥(仅支持16字节的密钥)。
|
|
75
|
-
*/
|
|
76
|
-
aesEncrypt(text: string, key: string): string;
|
|
77
|
-
/**
|
|
78
|
-
* 使用给定的密钥对给定的字符串执行 AES 解密(解密模式为 ECB,填充方式为 PKCS7)。
|
|
79
|
-
*
|
|
80
|
-
* @param text - 要解密的字符串。
|
|
81
|
-
* @param key - 用于解密的密钥(仅支持16字节的密钥)。
|
|
82
|
-
*/
|
|
83
|
-
aesDecrypt(text: string, key: string): string;
|
|
84
|
-
/**
|
|
85
|
-
* 使用AES加密算法对JSON数据进行加密
|
|
86
|
-
*
|
|
87
|
-
* 该方法首先将payload参数序列化为JSON字符串,然后使用指定的密钥进行AES加密
|
|
88
|
-
* 主要用于在传输敏感信息前,对数据进行加密处理,以确保数据的安全性
|
|
89
|
-
*
|
|
90
|
-
* @param payload 任何类型的对象,代表需要加密的原始数据
|
|
91
|
-
* @param key 字符串类型的密钥,用于AES加密算法
|
|
92
|
-
* 密钥需要符合AES加密算法的长度要求
|
|
93
|
-
* @returns 返回加密后的字符串数据
|
|
94
|
-
* 加密后的数据可以安全地进行网络传输或存储
|
|
95
|
-
*/
|
|
96
|
-
aesEncryptJson(payload: any, key: string): string;
|
|
97
|
-
/**
|
|
98
|
-
* 使用AES算法解密给定的文本,并将解密后的结果解析为JSON对象
|
|
99
|
-
*
|
|
100
|
-
* @param text 需要解密的加密文本
|
|
101
|
-
* @param key 解密用的密钥,必须与加密时使用的密钥相同
|
|
102
|
-
* @returns 返回解密后的JSON对象,类型为泛型T,根据调用时指定的类型解析
|
|
103
|
-
*/
|
|
104
|
-
aesDecryptJson<T>(text: string, key: string): T;
|
|
105
|
-
}
|
|
106
|
-
declare module '../x' {
|
|
107
|
-
interface X {
|
|
108
|
-
crypto: CryptoService;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { BaseService } from './base';
|
|
2
|
-
export type DbValueServiceSimpleArrayOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* 分隔符
|
|
5
|
-
*
|
|
6
|
-
* @default ,
|
|
7
|
-
*/
|
|
8
|
-
separator?: string;
|
|
9
|
-
/**
|
|
10
|
-
* 前缀后缀
|
|
11
|
-
*/
|
|
12
|
-
affix?: string;
|
|
13
|
-
/**
|
|
14
|
-
* 是否数字
|
|
15
|
-
*/
|
|
16
|
-
number?: boolean;
|
|
17
|
-
};
|
|
18
|
-
export type DbValueServiceJsonObjectOptions<T> = {
|
|
19
|
-
transform?: {
|
|
20
|
-
add?: (value: T) => T;
|
|
21
|
-
get?: (value: T) => T;
|
|
22
|
-
update?: (value: T) => T;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export declare class DbValueService implements BaseService {
|
|
26
|
-
serviceName: string;
|
|
27
|
-
SimpleArray: {
|
|
28
|
-
new <T extends string | number = string>(options?: DbValueServiceSimpleArrayOptions): {
|
|
29
|
-
separator: string;
|
|
30
|
-
affix: string;
|
|
31
|
-
number: boolean;
|
|
32
|
-
add: (value?: T[], defaultValue?: T[]) => string;
|
|
33
|
-
get: (value?: string) => T[];
|
|
34
|
-
update: (value?: T[]) => string | undefined;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
JsonArray: {
|
|
38
|
-
new <T = string>(): {
|
|
39
|
-
add: (value?: T[], defaultValue?: T[]) => string;
|
|
40
|
-
get: (value?: string) => T[];
|
|
41
|
-
update: (value?: T[]) => string | undefined;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
JsonObject: {
|
|
45
|
-
new <T>(options?: DbValueServiceJsonObjectOptions<T>): {
|
|
46
|
-
options?: DbValueServiceJsonObjectOptions<T>;
|
|
47
|
-
hasTransformAdd: boolean;
|
|
48
|
-
hasTransformGet: boolean;
|
|
49
|
-
hasTransformUpdate: boolean;
|
|
50
|
-
add: (value?: T, defaultValue?: T) => string;
|
|
51
|
-
get: (value?: string) => T;
|
|
52
|
-
update: (value?: T) => string | undefined;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
declare module '../x' {
|
|
57
|
-
interface X {
|
|
58
|
-
dbValue: DbValueService;
|
|
59
|
-
}
|
|
60
|
-
}
|