@anjianshi/utils 2.3.6 → 2.3.9

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.
@@ -38,7 +38,9 @@ export declare class EnvReader {
38
38
  batchGet<Defs extends Record<string, EnvValue>>(definitions: Defs): Defs;
39
39
  /**
40
40
  * 同 envReader.getByType(),只不过是通过对象指定各 env 的类型来批量获取。
41
- * 若 required 为 true,要求所有 env 都必须有值,否则会抛出异常;默认为 false。
41
+ *
42
+ * - required=false(默认)时,不存在或值为 undefined 的 env 不会出现在返回对象里,以保证 { ...defaults, ...envReader.batchGetByType(...) } 的用法能正常保留默认值。
43
+ * - required=true 时要求所有 env 都必须有值,否则会抛出异常
42
44
  *
43
45
  * envReader.batchGetByType({
44
46
  * port: 'number',
@@ -68,9 +68,10 @@ export class EnvReader {
68
68
  const result = {};
69
69
  for (const [key, def] of Object.entries(definitions)) {
70
70
  const value = typeof def === 'string' ? this.getByType(key, def) : this.getByType(key, 'json');
71
- if (value === undefined && required)
71
+ if (value !== undefined)
72
+ result[key] = value;
73
+ else if (required)
72
74
  throw new Error(`env ${key} needs a value`);
73
- result[key] = value;
74
75
  }
75
76
  return result;
76
77
  }
@@ -1,9 +1,9 @@
1
- import { Prisma } from '@prisma/client';
1
+ import { Prisma } from '@prisma/client/extension';
2
2
  /**
3
3
  * 快速检查指定条件的数据是否存在
4
4
  * const exists = await prisma.xxx.exists({ id: '1' })
5
5
  */
6
- export declare const exists: (client: any) => import("@prisma/client").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
6
+ export declare const exists: (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
7
7
  $allModels: {
8
8
  exists<T>(this: T, where: Prisma.Args<T, "count">["where"], withDeleted?: boolean): Promise<boolean>;
9
9
  };
@@ -1,4 +1,4 @@
1
- import { Prisma } from '@prisma/client';
1
+ import { Prisma } from '@prisma/client/extension';
2
2
  /**
3
3
  * 快速检查指定条件的数据是否存在
4
4
  * const exists = await prisma.xxx.exists({ id: '1' })
@@ -1,6 +1,6 @@
1
- import { Prisma } from '@prisma/client';
1
+ import { Prisma } from '@prisma/client/extension';
2
2
  import { type SoftDeleteQueryArgs } from './soft-delete.js';
3
- export declare const findAndCount: (client: any) => import("@prisma/client").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
3
+ export declare const findAndCount: (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
4
4
  $allModels: {
5
5
  findAndCount<T, A>(this: T, rawArgs: Prisma.Exact<A, Prisma.Args<T, "findMany"> & SoftDeleteQueryArgs>): Promise<[Awaited<Prisma.Result<T, A, "findMany">>, Awaited<Prisma.Result<T, A, "count">>]>;
6
6
  };
@@ -1,4 +1,4 @@
1
- import { Prisma } from '@prisma/client';
1
+ import { Prisma } from '@prisma/client/extension';
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';
16
+ import { Prisma } from '@prisma/client/extension';
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'> & {
@@ -33,7 +33,7 @@ interface QueryExtraArgs {
33
33
  }
34
34
  export type { QueryExtraArgs as SoftDeleteQueryArgs };
35
35
  type QueryInputArgs<T, A, K extends Operation> = Prisma.Exact<A, Prisma.Args<T, K> & QueryExtraArgs>;
36
- export declare const softDelete: (client: any) => import("@prisma/client").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
36
+ export declare const softDelete: (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {
37
37
  $allModels: {
38
38
  withSoftDeleteExtension: boolean;
39
39
  delete<T, A>(this: T, rawArgs: Prisma.Exact<A, DeleteArgs<T>>): DeleteReturn<T, A>;
@@ -13,7 +13,7 @@
13
13
  * 此扩展修改了 Prisma 的原生方法。
14
14
  * 为保证其他扩展也应用到修改过的这些方法,此扩展应尽可能放在最前面。
15
15
  */
16
- import { Prisma } from '@prisma/client';
16
+ import { Prisma } from '@prisma/client/extension';
17
17
  function getModel(that) {
18
18
  const context = Prisma.getExtensionContext(that);
19
19
  // 1. 此扩展修改了 Prisma 原生的方法,所以要通过 context.$parent[context.$name] 获取上一层的 model,不然会自己调用自己导致死循环。
@@ -1,6 +1,6 @@
1
1
  import { type ITXClientDenyList } from '@prisma/client/runtime/library.js';
2
2
  import type { MaySuccess } from '../../../index.js';
3
- export declare const withTransaction: (client: any) => import("@prisma/client").PrismaClientExtends<import("@prisma/client/runtime/library").InternalArgs<{}, {}, {}, {
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>;
@@ -12,7 +12,7 @@
12
12
  * }
13
13
  * )
14
14
  */
15
- import { Prisma } from '@prisma/client';
15
+ import { Prisma } from '@prisma/client/extension';
16
16
  export const withTransaction = Prisma.defineExtension({
17
17
  name: 'withTransaction',
18
18
  client: {
@@ -6,6 +6,6 @@ import type { WithTransactionMethod } from './extensions/with-transaction.js';
6
6
  * 注意:应给每个线性流程(例如一个请求)单独生成一个此对象,不能作为全局对象使用,不然可能出现事务冲突。
7
7
  */
8
8
  export declare function getTransactionContextedPrismaClient<AppPrismaClient extends {
9
- $transaction: (...args: unknown[]) => Promise<unknown>;
9
+ $transaction: (...args: any[]) => Promise<unknown>;
10
10
  $withTransaction: WithTransactionMethod;
11
11
  }>(prisma: AppPrismaClient): AppPrismaClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anjianshi/utils",
3
- "version": "2.3.6",
3
+ "version": "2.3.9",
4
4
  "description": "Common JavaScript Utils",
5
5
  "homepage": "https://github.com/anjianshi/js-packages/utils",
6
6
  "bugs": {
@@ -26,9 +26,9 @@
26
26
  "dotenv": "^16.4.5",
27
27
  "typescript": "^5.5.4",
28
28
  "vconsole": "^3.15.1",
29
- "@anjianshi/presets-prettier": "3.0.1",
30
29
  "@anjianshi/presets-eslint-typescript": "5.0.5",
31
30
  "@anjianshi/presets-eslint-node": "4.0.8",
31
+ "@anjianshi/presets-prettier": "3.0.1",
32
32
  "@anjianshi/presets-typescript": "3.2.2",
33
33
  "@anjianshi/presets-eslint-react": "4.0.7"
34
34
  },