@anjianshi/utils 2.4.16 → 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.
- package/env-browser/device.js +1 -0
- package/env-browser/load-script.js +1 -1
- package/env-browser/manage-vconsole.d.ts +1 -1
- package/env-browser/manage-vconsole.js +1 -1
- package/env-node/logging/handlers.js +1 -1
- package/env-react/emotion.d.ts +3 -1
- package/env-service/index.d.ts +0 -1
- package/env-service/index.js +0 -1
- package/env-service/prisma/adapt-logging.js +1 -0
- package/env-service/prisma/extensions/soft-delete.js +2 -0
- package/env-service/prisma/extensions/with-transaction.d.ts +2 -2
- package/env-service/prisma/extensions/with-transaction.js +3 -1
- package/env-service/redis-cache.d.ts +1 -1
- package/env-service/redis-cache.js +1 -2
- package/lang/async.js +1 -1
- package/lang/string.js +1 -0
- package/package.json +20 -20
package/env-browser/device.js
CHANGED
|
@@ -7,7 +7,7 @@ export default async function loadScript(url) {
|
|
|
7
7
|
const script = document.createElement('script');
|
|
8
8
|
script.src = url;
|
|
9
9
|
script.onload = () => resolve();
|
|
10
|
-
script.onerror = err => reject(err);
|
|
10
|
+
script.onerror = err => reject(err); // eslint-disable-line @typescript-eslint/prefer-promise-reject-errors
|
|
11
11
|
window.document.head.appendChild(script);
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -12,5 +12,5 @@ export declare function isVConsoleEnabled(): boolean;
|
|
|
12
12
|
export declare function detectVConsole(): void;
|
|
13
13
|
export declare function enableVConsole(): void;
|
|
14
14
|
export declare function disableVConsole(): void;
|
|
15
|
-
export declare function runVConsole():
|
|
15
|
+
export declare function runVConsole(): void;
|
|
16
16
|
export declare function destoryVConsole(): void;
|
|
@@ -27,7 +27,7 @@ export function runVConsole() {
|
|
|
27
27
|
if (window.VConsole !== null)
|
|
28
28
|
return;
|
|
29
29
|
if (VConsoleLib === undefined)
|
|
30
|
-
return
|
|
30
|
+
return console.warn('尚未传入 VConsole 对象,无法启动');
|
|
31
31
|
window.VConsole = new VConsoleLib();
|
|
32
32
|
}
|
|
33
33
|
export function destoryVConsole() {
|
|
@@ -147,7 +147,7 @@ export class FileHandler extends LogHandler {
|
|
|
147
147
|
else {
|
|
148
148
|
fs.appendFile(this.filepath, content, error => {
|
|
149
149
|
if (error)
|
|
150
|
-
console.error('[logger] write failed: '
|
|
150
|
+
console.error('[logger] write failed: ', error);
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
}
|
package/env-react/emotion.d.ts
CHANGED
|
@@ -14,5 +14,7 @@ import { type CSSInterpolation } from '@emotion/serialize';
|
|
|
14
14
|
export declare const useEmotionCache: () => EmotionCache | undefined;
|
|
15
15
|
export declare const EmotionCacheProvider: import("react").FC<{
|
|
16
16
|
children: React.ReactNode;
|
|
17
|
-
} & import("react").
|
|
17
|
+
} & import("react").RefAttributes<any>> | import("react").ForwardRefExoticComponent<{
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
} & import("react").RefAttributes<any>>;
|
|
18
20
|
export declare function useEmotionClassName(): (...args: CSSInterpolation[]) => string;
|
package/env-service/index.d.ts
CHANGED
package/env-service/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export function getPrismaLoggingOptions(debug) {
|
|
|
17
17
|
],
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
20
21
|
export function adaptPrismaLogging(prisma, baseLogger) {
|
|
21
22
|
// 记录 Prisma 相关日志
|
|
22
23
|
const queryLogger = baseLogger.getChild('query');
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* 为保证其他扩展也应用到修改过的这些方法,此扩展应尽可能放在最前面。
|
|
15
15
|
*/
|
|
16
16
|
import { Prisma } from '@prisma/client/extension';
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
17
18
|
function getModel(that) {
|
|
18
19
|
const context = Prisma.getExtensionContext(that);
|
|
19
20
|
// 1. 此扩展修改了 Prisma 原生的方法,所以要通过 context.$parent[context.$name] 获取上一层的 model,不然会自己调用自己导致死循环。
|
|
@@ -29,6 +30,7 @@ function getModel(that) {
|
|
|
29
30
|
}
|
|
30
31
|
function query(that, inputArgs, method) {
|
|
31
32
|
const { model, supportSoftDelete } = getModel(that);
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
32
34
|
const { withDeleted = false, ...args } = inputArgs;
|
|
33
35
|
return model[method]({
|
|
34
36
|
...args,
|
|
@@ -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/lang/async.js
CHANGED
package/lang/string.js
CHANGED
|
@@ -81,6 +81,7 @@ export function readableSize(bytes, si = false, dp = 1) {
|
|
|
81
81
|
/**
|
|
82
82
|
* 解析 JSON,失败时不抛出异常,而是返回 undefined
|
|
83
83
|
*/
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
84
85
|
export function safeParseJSON(json) {
|
|
85
86
|
try {
|
|
86
87
|
return JSON.parse(json);
|
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.
|
|
31
|
-
"@anjianshi/presets-eslint-react": "4.
|
|
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": "^
|
|
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": {
|