@jayfong/x-server 1.32.0 → 1.33.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.33.1](https://github.com/jfWorks/x-server/compare/v1.33.0...v1.33.1) (2022-06-12)
6
+
7
+ ## [1.33.0](https://github.com/jfWorks/x-server/compare/v1.32.1...v1.33.0) (2022-06-11)
8
+
9
+
10
+ ### Features
11
+
12
+ * defineTask concurrency ([d8174aa](https://github.com/jfWorks/x-server/commit/d8174aa302e9013610d41265d937512a02412359))
13
+
14
+ ### [1.32.1](https://github.com/jfWorks/x-server/compare/v1.32.0...v1.32.1) (2022-06-02)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * trustProxy: true ([b116aaa](https://github.com/jfWorks/x-server/commit/b116aaac3dd90364d5aaf939bf66e50a6911aad2))
20
+
5
21
  ## [1.32.0](https://github.com/jfWorks/x-server/compare/v1.31.3...v1.32.0) (2022-05-31)
6
22
 
7
23
 
@@ -1,11 +1,11 @@
1
1
  import { x, HttpError } from '@jayfong/x-server'
2
2
  import { PrismaClient } from '@prisma/client'
3
3
 
4
- const prisma = new PrismaClient({
4
+ export const prismaClient = new PrismaClient({
5
5
  rejectOnNotFound: err => new HttpError.NotFound(err.message),
6
6
  })
7
7
 
8
- x.dispose.add(() => prisma.$disconnect())
8
+ x.dispose.add(() => prismaClient.$disconnect())
9
9
 
10
10
  type ModelName =
11
11
  // @index('../.prisma/client/index.d.ts', /(?<=const ModelName:).+?(?=\})/s, /(\S+?):/g, (m, _) => `| '${_.camel(m[1])}'`)
@@ -14,7 +14,7 @@ type ModelName =
14
14
 
15
15
  function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
16
16
  return class BaseModel {
17
- public query = prisma[name]
17
+ public query = prismaClient[name]
18
18
  }
19
19
  }
20
20
 
@@ -18,7 +18,7 @@ function defineTask(options) {
18
18
  },
19
19
  prefix: `${_x.x.appId}_task`
20
20
  });
21
- queue.process(async job => {
21
+ queue.process(options.concurrency || 1, async job => {
22
22
  return options.handle(job.data);
23
23
  });
24
24
  return queue;
@@ -46,6 +46,9 @@ class Server {
46
46
  logger: process.env.NODE_ENV === 'development' ? {
47
47
  prettyPrint: true
48
48
  } : false,
49
+ // 信任 X-Forwarded-For 头以获取正确的 IP,
50
+ // 否则通过 nginx 代理后 remoteAddr 将始终为 127.0.0.1
51
+ trustProxy: true,
49
52
  ...this.options.fastifyOptions
50
53
  });
51
54
  }
@@ -1,11 +1,11 @@
1
1
  import { x, HttpError } from '@jayfong/x-server'
2
2
  import { PrismaClient } from '@prisma/client'
3
3
 
4
- const prisma = new PrismaClient({
4
+ export const prismaClient = new PrismaClient({
5
5
  rejectOnNotFound: err => new HttpError.NotFound(err.message),
6
6
  })
7
7
 
8
- x.dispose.add(() => prisma.$disconnect())
8
+ x.dispose.add(() => prismaClient.$disconnect())
9
9
 
10
10
  type ModelName =
11
11
  // @index('../.prisma/client/index.d.ts', /(?<=const ModelName:).+?(?=\})/s, /(\S+?):/g, (m, _) => `| '${_.camel(m[1])}'`)
@@ -14,7 +14,7 @@ type ModelName =
14
14
 
15
15
  function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
16
16
  return class BaseModel {
17
- public query = prisma[name]
17
+ public query = prismaClient[name]
18
18
  }
19
19
  }
20
20
 
@@ -9,7 +9,7 @@ export function defineTask(options) {
9
9
  },
10
10
  prefix: `${x.appId}_task`
11
11
  });
12
- queue.process(async job => {
12
+ queue.process(options.concurrency || 1, async job => {
13
13
  return options.handle(job.data);
14
14
  });
15
15
  return queue;
@@ -33,6 +33,9 @@ export class Server {
33
33
  logger: process.env.NODE_ENV === 'development' ? {
34
34
  prettyPrint: true
35
35
  } : false,
36
+ // 信任 X-Forwarded-For 头以获取正确的 IP,
37
+ // 否则通过 nginx 代理后 remoteAddr 将始终为 127.0.0.1
38
+ trustProxy: true,
36
39
  ...this.options.fastifyOptions
37
40
  });
38
41
  }
@@ -139,6 +139,12 @@ export declare namespace XTask {
139
139
  * 任务名称
140
140
  */
141
141
  name: string;
142
+ /**
143
+ * 并发数量
144
+ *
145
+ * @default 1
146
+ */
147
+ concurrency?: number;
142
148
  /**
143
149
  * 处理器
144
150
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.32.0",
3
+ "version": "1.33.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",