@anjianshi/utils 3.5.0 → 3.6.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.
@@ -115,8 +115,8 @@ export class FileHandler extends LogHandler {
115
115
  if (this.options.flushInterval === 0 || this.bufferSize >= this.options.flushLength) {
116
116
  this.flush();
117
117
  }
118
- else if (!this.flushTimeoutId) {
119
- this.flushTimeoutId = setTimeout(() => this.flush(), this.options.flushInterval);
118
+ else {
119
+ this.flushTimeoutId ??= setTimeout(() => this.flush(), this.options.flushInterval);
120
120
  }
121
121
  }
122
122
  flush(sync) {
@@ -1,17 +1,17 @@
1
1
  import type { getPrismaClient } from '@prisma/client/runtime/library.js';
2
2
  import { type Logger } from '../../logging/index.js';
3
3
  type PrismalClient = ReturnType<typeof getPrismaClient> extends new () => infer T ? T : never;
4
- export declare function getPrismaLoggingOptions(debug: boolean): {
4
+ export declare function getPrismaLoggingOptions(level: 'debug' | 'info' | 'warn' | 'error'): {
5
5
  errorFormat: "pretty";
6
6
  log: ({
7
7
  readonly emit: "event";
8
8
  readonly level: "query";
9
9
  } | {
10
- emit: "event";
11
- level: "info";
10
+ readonly emit: "event";
11
+ readonly level: "info";
12
12
  } | {
13
- emit: "event";
14
- level: "warn";
13
+ readonly emit: "event";
14
+ readonly level: "warn";
15
15
  } | {
16
16
  emit: "event";
17
17
  level: "error";
@@ -9,13 +9,15 @@
9
9
  */
10
10
  import nodeUtil from 'node:util';
11
11
  import chalk from 'chalk';
12
- export function getPrismaLoggingOptions(debug) {
12
+ export function getPrismaLoggingOptions(level) {
13
13
  return {
14
14
  errorFormat: 'pretty',
15
15
  log: [
16
- ...(debug ? [{ emit: 'event', level: 'query' }] : []),
17
- { emit: 'event', level: 'info' },
18
- { emit: 'event', level: 'warn' },
16
+ ...(level === 'debug' ? [{ emit: 'event', level: 'query' }] : []),
17
+ ...(['debug', 'info'].includes(level) ? [{ emit: 'event', level: 'info' }] : []),
18
+ ...(['debug', 'info', 'warn'].includes(level)
19
+ ? [{ emit: 'event', level: 'warn' }]
20
+ : []),
19
21
  { emit: 'event', level: 'error' },
20
22
  ],
21
23
  };
@@ -1,4 +1,4 @@
1
- import { Prisma } from '@prisma/client/extension';
1
+ import { Prisma } from '@prisma/client/extension.js';
2
2
  /**
3
3
  * 快速检查指定条件的数据是否存在
4
4
  * const exists = await prisma.xxx.exists({ id: '1' })
@@ -1,4 +1,4 @@
1
- import { Prisma } from '@prisma/client/extension';
1
+ import { Prisma } from '@prisma/client/extension.js';
2
2
  /**
3
3
  * 快速检查指定条件的数据是否存在
4
4
  * const exists = await prisma.xxx.exists({ id: '1' })
@@ -1,4 +1,4 @@
1
- import { Prisma } from '@prisma/client/extension';
1
+ import { Prisma } from '@prisma/client/extension.js';
2
2
  import { type SoftDeleteQueryArgs } from './soft-delete.js';
3
3
  export declare const findAndCount: (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
4
4
  $allModels: {
@@ -1,4 +1,4 @@
1
- import { Prisma } from '@prisma/client/extension';
1
+ import { Prisma } from '@prisma/client/extension.js';
2
2
  export const findAndCount = Prisma.defineExtension({
3
3
  name: 'findAndCount',
4
4
  model: {
@@ -13,7 +13,7 @@
13
13
  * 此扩展修改了 Prisma 的原生方法。
14
14
  * 为保证其他扩展也应用到修改过的这些方法,此扩展应尽可能放在最前面。
15
15
  */
16
- import { Prisma } from '@prisma/client/extension';
16
+ import { Prisma } from '@prisma/client/extension.js';
17
17
  import type { Operation } from '@prisma/client/runtime/library.js';
18
18
  import { type OptionalFields } from '../../../index.js';
19
19
  type DeleteArgs<T> = Prisma.Args<T, 'delete'> & {
@@ -13,7 +13,7 @@
13
13
  * 此扩展修改了 Prisma 的原生方法。
14
14
  * 为保证其他扩展也应用到修改过的这些方法,此扩展应尽可能放在最前面。
15
15
  */
16
- import { Prisma } from '@prisma/client/extension';
16
+ import { Prisma } from '@prisma/client/extension.js';
17
17
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
18
18
  function getModel(that) {
19
19
  const context = Prisma.getExtensionContext(that);
package/logging/adapt.js CHANGED
@@ -31,8 +31,7 @@ export function adaptDebugLib(debugLib, enable = '', logger) {
31
31
  };
32
32
  Object.assign(debugLib, emulate);
33
33
  // 将 debugLib 日志转发给 logger
34
- if (!logger)
35
- logger = getLogger('3rd-library');
34
+ logger ??= getLogger('3rd-library');
36
35
  debugLib.log = logger.debug.bind(logger);
37
36
  if (enable) {
38
37
  // 有些库(例如 prisma)重新实现了自己的 debug 库,且模仿 debug 也读取 DEBUG 环境变量。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anjianshi/utils",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "description": "Common JavaScript Utils",
5
5
  "homepage": "https://github.com/anjianshi/js-packages/utils",
6
6
  "bugs": {
@@ -23,56 +23,27 @@
23
23
  "lodash": "^4.17.21"
24
24
  },
25
25
  "devDependencies": {
26
- "@types/lodash": "^4.17.20",
27
- "@types/node": "^22.16.0",
28
- "@types/react": "^19.1.8",
29
- "dotenv": "^17.0.1",
30
- "eslint": "^9.30.1",
31
- "redis": "^5.5.6",
32
- "typescript": "^5.8.3",
33
- "vconsole": "^3.15.1",
34
- "@anjianshi/presets-eslint-node": "6.0.0",
35
- "@anjianshi/presets-eslint-base": "6.0.0",
36
- "@anjianshi/presets-eslint-typescript": "6.0.0",
37
- "@anjianshi/presets-prettier": "3.0.5",
38
- "@anjianshi/presets-eslint-react": "6.0.0",
39
- "@anjianshi/presets-typescript": "3.2.5"
40
- },
41
- "peerDependencies": {
42
26
  "@emotion/react": "^11.14.0",
43
27
  "@emotion/serialize": "^1.3.3",
44
28
  "@emotion/utils": "^1.4.2",
45
29
  "@prisma/client": "^6.8.2",
30
+ "@types/lodash": "^4.17.20",
31
+ "@types/node": "^22.16.0",
32
+ "@types/react": "^19.1.8",
46
33
  "chalk": "^5.4.1",
47
34
  "dayjs": "^1.11.13",
48
35
  "dotenv": "^17.0.1",
49
- "react": "^19.1.0"
50
- },
51
- "peerDependenciesMeta": {
52
- "@emotion/react": {
53
- "optional": true
54
- },
55
- "@emotion/serialize": {
56
- "optional": true
57
- },
58
- "@emotion/utils": {
59
- "optional": true
60
- },
61
- "@prisma/client": {
62
- "optional": true
63
- },
64
- "chalk": {
65
- "optional": true
66
- },
67
- "dayjs": {
68
- "optional": true
69
- },
70
- "dotenv": {
71
- "optional": true
72
- },
73
- "react": {
74
- "optional": true
75
- }
36
+ "eslint": "^9.39.2",
37
+ "react": "^19.1.0",
38
+ "redis": "^5.5.6",
39
+ "typescript": "^5.8.3",
40
+ "vconsole": "^3.15.1",
41
+ "@anjianshi/presets-eslint-base": "6.1.0",
42
+ "@anjianshi/presets-eslint-node": "6.1.0",
43
+ "@anjianshi/presets-eslint-react": "6.1.1",
44
+ "@anjianshi/presets-eslint-typescript": "6.1.0",
45
+ "@anjianshi/presets-typescript": "3.2.5",
46
+ "@anjianshi/presets-prettier": "3.2.0"
76
47
  },
77
48
  "prettier": "@anjianshi/presets-prettier/prettierrc"
78
49
  }