@anjianshi/utils 2.4.17 → 2.5.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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type ITXClientDenyList } from '@prisma/client/runtime/library.js';
|
|
2
|
-
import type { MaySuccess } from '../../../index.js';
|
|
2
|
+
import type { MaySuccess, Failed } from '../../../index.js';
|
|
3
3
|
export declare const withTransaction: (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {}, {}, {
|
|
4
4
|
$withTransaction: typeof $withTransaction;
|
|
5
5
|
}>>;
|
|
6
6
|
export type GetPrismaClientInTransaction<PrismaClient> = Omit<PrismaClient, ITXClientDenyList>;
|
|
7
7
|
export type WithTransactionMethod = typeof $withTransaction;
|
|
8
|
-
declare function $withTransaction<That extends object, R extends MaySuccess<unknown, unknown>>(this: That, callback: (dbInTransaction: GetPrismaClientInTransaction<That>) => Promise<R>): Promise<R>;
|
|
8
|
+
declare function $withTransaction<That extends object, R extends MaySuccess<unknown, unknown>>(this: That, callback: (dbInTransaction: GetPrismaClientInTransaction<That>) => Promise<R>): Promise<Failed<any> | R>;
|
|
9
9
|
export {};
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* }
|
|
13
13
|
* )
|
|
14
14
|
*/
|
|
15
|
-
import { Prisma } from '@prisma/client/extension';
|
|
15
|
+
import { Prisma } from '@prisma/client/extension.js';
|
|
16
16
|
export const withTransaction = Prisma.defineExtension({
|
|
17
17
|
name: 'withTransaction',
|
|
18
18
|
client: {
|
|
@@ -26,6 +26,8 @@ class FailedInTransaction extends Error {
|
|
|
26
26
|
this.failed = failed;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
// 注意:此函数的返回值为 `R | Failed<any>`,例如实际可能为 `MaySuccess<xxx, xxx> | Failed<any>`,这是有意为之的,`Failed<any>` 并不多余。
|
|
30
|
+
// 因为有时 callback() 只会返回 success 结果,此时 R=Success<xxx>,但是 $withTransaction 整体的返回值仍有可能有 Failed<any>,所以不能用 R 作为整体返回值。
|
|
29
31
|
async function $withTransaction(callback) {
|
|
30
32
|
const executeCallback = async (dbInTransaction) => {
|
|
31
33
|
const result = await callback(dbInTransaction);
|
|
@@ -33,7 +33,7 @@ export declare class Cache<T> {
|
|
|
33
33
|
/** 移除一项内容 */
|
|
34
34
|
delete(identity?: string | string[]): Promise<number>;
|
|
35
35
|
/** 刷新一项内容的过期时间 */
|
|
36
|
-
refresh(identity?: string): Promise<
|
|
36
|
+
refresh(identity?: string): Promise<number | false>;
|
|
37
37
|
/** 确认一项内容是否存在 */
|
|
38
38
|
exists(identity?: string): Promise<boolean>;
|
|
39
39
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { logger as rootLogger } from '../logging/index.js';
|
|
2
2
|
export function initRedisLogging(redis, logger) {
|
|
3
|
-
|
|
4
|
-
logger = rootLogger.getChild('redis');
|
|
3
|
+
logger ??= rootLogger.getChild('redis');
|
|
5
4
|
redis.on('connect', () => logger.info('connecting'));
|
|
6
5
|
redis.on('ready', () => logger.info('connected'));
|
|
7
6
|
redis.on('end', () => logger.info('connection closed'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anjianshi/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Common JavaScript Utils",
|
|
5
5
|
"homepage": "https://github.com/anjianshi/js-packages/utils",
|
|
6
6
|
"bugs": {
|
|
@@ -20,28 +20,28 @@
|
|
|
20
20
|
"lodash": "^4.17.21"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/lodash": "^4.17.
|
|
24
|
-
"@types/node": "^
|
|
25
|
-
"@types/react": "^
|
|
26
|
-
"dotenv": "^16.
|
|
27
|
-
"redis": "^
|
|
28
|
-
"typescript": "^5.
|
|
23
|
+
"@types/lodash": "^4.17.17",
|
|
24
|
+
"@types/node": "^22.15.21",
|
|
25
|
+
"@types/react": "^19.1.5",
|
|
26
|
+
"dotenv": "^16.5.0",
|
|
27
|
+
"redis": "^5.1.0",
|
|
28
|
+
"typescript": "^5.8.3",
|
|
29
29
|
"vconsole": "^3.15.1",
|
|
30
|
-
"@anjianshi/presets-eslint-node": "4.2.
|
|
31
|
-
"@anjianshi/presets-eslint-react": "4.2.
|
|
32
|
-
"@anjianshi/presets-
|
|
33
|
-
"@anjianshi/presets-
|
|
34
|
-
"@anjianshi/presets-typescript": "
|
|
30
|
+
"@anjianshi/presets-eslint-node": "4.2.3",
|
|
31
|
+
"@anjianshi/presets-eslint-react": "4.2.3",
|
|
32
|
+
"@anjianshi/presets-prettier": "3.0.3",
|
|
33
|
+
"@anjianshi/presets-typescript": "3.2.4",
|
|
34
|
+
"@anjianshi/presets-eslint-typescript": "5.2.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@emotion/react": "^11.
|
|
38
|
-
"@emotion/serialize": "^1.3.
|
|
39
|
-
"@emotion/utils": "^1.4.
|
|
40
|
-
"@prisma/client": "^6.2
|
|
41
|
-
"chalk": "^5.
|
|
42
|
-
"dayjs": "^1.11.
|
|
43
|
-
"dotenv": "^16.
|
|
44
|
-
"react": "^
|
|
37
|
+
"@emotion/react": "^11.14.0",
|
|
38
|
+
"@emotion/serialize": "^1.3.3",
|
|
39
|
+
"@emotion/utils": "^1.4.2",
|
|
40
|
+
"@prisma/client": "^6.8.2",
|
|
41
|
+
"chalk": "^5.4.1",
|
|
42
|
+
"dayjs": "^1.11.13",
|
|
43
|
+
"dotenv": "^16.5.0",
|
|
44
|
+
"react": "^19.1.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependenciesMeta": {
|
|
47
47
|
"@emotion/react": {
|