@zenweb/schedule 5.1.0 → 5.3.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,8 +1,14 @@
1
1
  import { Core, Middleware } from '@zenweb/core';
2
- import { RecurrenceRule, RecurrenceSpecDateRange, RecurrenceSpecObjLit } from 'node-schedule';
2
+ import { type Spec } from 'node-schedule';
3
3
  import { ScheduleOption } from './types.js';
4
4
  interface ScheduleMethodOption {
5
- rule: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number;
5
+ /**
6
+ * 定时规则
7
+ */
8
+ rule: Spec;
9
+ /**
10
+ * 中间件
11
+ */
6
12
  middleware?: Middleware | Middleware[];
7
13
  }
8
14
  /**
package/dist/register.js CHANGED
@@ -9,9 +9,8 @@ const scheduleDecorator = makeMethodDecorator();
9
9
  * 定时任务设定
10
10
  */
11
11
  export function schedule(opt) {
12
- return scheduleDecorator.wrap((descriptor, target) => {
13
- const path = `/${target.constructor.name}.${descriptor.handle.name}`;
14
- return Object.assign({ path }, descriptor, opt);
12
+ return scheduleDecorator.wrap(descriptor => {
13
+ return Object.assign({}, opt, descriptor);
15
14
  });
16
15
  }
17
16
  export class ScheduleRegister {
@@ -33,7 +32,19 @@ export class ScheduleRegister {
33
32
  const methods = scheduleDecorator.getMethods(target.prototype);
34
33
  if (methods.length > 0) {
35
34
  for (const item of methods) {
36
- const apath = prefix ? path.join('/', prefix, item.path) : item.path;
35
+ let apath = prefix ? path.join('/', prefix, item.handle.name) : item.handle.name;
36
+ // 重复定义自增
37
+ let i = 1;
38
+ let c = apath;
39
+ while (true) {
40
+ if (this.router.matchSelf(c, 'POST')) {
41
+ c = apath + i++;
42
+ }
43
+ else {
44
+ apath = c;
45
+ break;
46
+ }
47
+ }
37
48
  // 添加到路由中
38
49
  this.router.post(apath, ...(item.middleware ?
39
50
  (Array.isArray(item.middleware) ? item.middleware : [item.middleware]) : []), async (ctx) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zenweb/schedule",
3
3
  "type": "module",
4
- "version": "5.1.0",
4
+ "version": "5.3.0",
5
5
  "description": "Zenweb Schedule module",
6
6
  "exports": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "@types/node": "^22.19.15",
39
39
  "@zenweb/core": "^5.2.1",
40
40
  "@zenweb/inject": "^5.1.0",
41
- "@zenweb/router": "^6.0.3",
41
+ "@zenweb/router": "^6.4.0",
42
42
  "rimraf": "^4.4.1",
43
43
  "ts-node": "^10.9.2",
44
44
  "typescript": "^5.9.3"