@jayfong/x-server 1.30.2 → 1.31.3
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 +18 -0
- package/lib/_cjs/cli/templates/crons.ts +2 -0
- package/lib/_cjs/core/define_cron.js +15 -0
- package/lib/_cjs/core/define_task.js +0 -9
- package/lib/_cjs/core/server.js +3 -3
- package/lib/_cjs/core/types.js +7 -2
- package/lib/_cjs/index.js +8 -0
- package/lib/cli/templates/crons.ts +2 -0
- package/lib/core/define_cron.d.ts +2 -0
- package/lib/core/define_cron.js +9 -0
- package/lib/core/define_task.js +0 -9
- package/lib/core/server.d.ts +1 -1
- package/lib/core/server.js +3 -3
- package/lib/core/types.d.ts +20 -4
- package/lib/core/types.js +5 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/package.json +3 -1
- package/lib/_cjs/cli/templates/tasks.ts +0 -1
- package/lib/cli/templates/tasks.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
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.31.3](https://github.com/jfWorks/x-server/compare/v1.31.2...v1.31.3) (2022-05-30)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* defineCron ([5d72533](https://github.com/jfWorks/x-server/commit/5d72533c039645833391ce31f0403c96b2c5ef77))
|
|
11
|
+
|
|
12
|
+
### [1.31.2](https://github.com/jfWorks/x-server/compare/v1.31.1...v1.31.2) (2022-05-30)
|
|
13
|
+
|
|
14
|
+
### [1.31.1](https://github.com/jfWorks/x-server/compare/v1.31.0...v1.31.1) (2022-05-30)
|
|
15
|
+
|
|
16
|
+
## [1.31.0](https://github.com/jfWorks/x-server/compare/v1.30.2...v1.31.0) (2022-05-30)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* defineCron ([f9f362e](https://github.com/jfWorks/x-server/commit/f9f362ee0a9845f662af0b686781299390c5647d))
|
|
22
|
+
|
|
5
23
|
### [1.30.2](https://github.com/jfWorks/x-server/compare/v1.30.1...v1.30.2) (2022-05-26)
|
|
6
24
|
|
|
7
25
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.defineCron = defineCron;
|
|
5
|
+
|
|
6
|
+
var _cron = require("cron");
|
|
7
|
+
|
|
8
|
+
function defineCron(options) {
|
|
9
|
+
return new _cron.CronJob({
|
|
10
|
+
cronTime: options.expression,
|
|
11
|
+
runOnInit: options.runOnInit,
|
|
12
|
+
start: true,
|
|
13
|
+
onTick: options.handle
|
|
14
|
+
});
|
|
15
|
+
}
|
package/lib/_cjs/core/server.js
CHANGED
|
@@ -31,7 +31,7 @@ class Server {
|
|
|
31
31
|
await this.applyRoutes();
|
|
32
32
|
await this.applyHooks();
|
|
33
33
|
await this.startFastify();
|
|
34
|
-
await this.
|
|
34
|
+
await this.startCrons();
|
|
35
35
|
await this.applyAutoClose();
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -145,9 +145,9 @@ class Server {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
async
|
|
148
|
+
async startCrons() {
|
|
149
149
|
// @ts-ignore
|
|
150
|
-
await Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('.x/
|
|
150
|
+
await Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('.x/crons')));
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
async applyAutoClose() {
|
package/lib/_cjs/core/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.XTask = exports.XServer = exports.XHandler = void 0;
|
|
4
|
+
exports.XTask = exports.XServer = exports.XHandler = exports.XCron = void 0;
|
|
5
5
|
let XServer;
|
|
6
6
|
exports.XServer = XServer;
|
|
7
7
|
|
|
@@ -15,4 +15,9 @@ exports.XHandler = XHandler;
|
|
|
15
15
|
let XTask;
|
|
16
16
|
exports.XTask = XTask;
|
|
17
17
|
|
|
18
|
-
(function (_XTask) {})(XTask || (exports.XTask = XTask = {}));
|
|
18
|
+
(function (_XTask) {})(XTask || (exports.XTask = XTask = {}));
|
|
19
|
+
|
|
20
|
+
let XCron;
|
|
21
|
+
exports.XCron = XCron;
|
|
22
|
+
|
|
23
|
+
(function (_XCron) {})(XCron || (exports.XCron = XCron = {}));
|
package/lib/_cjs/index.js
CHANGED
|
@@ -10,6 +10,14 @@ Object.keys(_define_bus).forEach(function (key) {
|
|
|
10
10
|
exports[key] = _define_bus[key];
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
var _define_cron = require("./core/define_cron");
|
|
14
|
+
|
|
15
|
+
Object.keys(_define_cron).forEach(function (key) {
|
|
16
|
+
if (key === "default" || key === "__esModule") return;
|
|
17
|
+
if (key in exports && exports[key] === _define_cron[key]) return;
|
|
18
|
+
exports[key] = _define_cron[key];
|
|
19
|
+
});
|
|
20
|
+
|
|
13
21
|
var _define_handler = require("./core/define_handler");
|
|
14
22
|
|
|
15
23
|
Object.keys(_define_handler).forEach(function (key) {
|
package/lib/core/define_task.js
CHANGED
package/lib/core/server.d.ts
CHANGED
package/lib/core/server.js
CHANGED
|
@@ -18,7 +18,7 @@ export class Server {
|
|
|
18
18
|
await this.applyRoutes();
|
|
19
19
|
await this.applyHooks();
|
|
20
20
|
await this.startFastify();
|
|
21
|
-
await this.
|
|
21
|
+
await this.startCrons();
|
|
22
22
|
await this.applyAutoClose();
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -130,9 +130,9 @@ export class Server {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
async
|
|
133
|
+
async startCrons() {
|
|
134
134
|
// @ts-ignore
|
|
135
|
-
await import('.x/
|
|
135
|
+
await import('.x/crons');
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
async applyAutoClose() {
|
package/lib/core/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BasePlugin } from '../plugins/base';
|
|
3
3
|
import { BaseService } from '../services/base';
|
|
4
|
+
import { CronJob } from 'cron';
|
|
4
5
|
import { FastifyReply, FastifyRequest, FastifyServerOptions } from 'fastify';
|
|
5
6
|
import { yup } from 'vtils/validator';
|
|
6
7
|
import type { AsyncOrSync, LiteralUnion, OneOrMore, RequiredDeep } from 'vtils/types';
|
|
@@ -139,17 +140,32 @@ export declare namespace XTask {
|
|
|
139
140
|
*/
|
|
140
141
|
name: string;
|
|
141
142
|
/**
|
|
142
|
-
*
|
|
143
|
+
* 处理器
|
|
144
|
+
*/
|
|
145
|
+
handle: (data: T) => any;
|
|
146
|
+
}
|
|
147
|
+
interface Task<T> extends Queue<T> {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export declare namespace XCron {
|
|
151
|
+
interface Options {
|
|
152
|
+
/**
|
|
153
|
+
* 定时语法
|
|
143
154
|
*
|
|
144
155
|
* @see https://crontab.guru/
|
|
156
|
+
* @see https://crontab.cronhub.io/
|
|
157
|
+
*/
|
|
158
|
+
expression: string;
|
|
159
|
+
/**
|
|
160
|
+
* 是否初始化后执行一次
|
|
145
161
|
*/
|
|
146
|
-
|
|
162
|
+
runOnInit?: boolean;
|
|
147
163
|
/**
|
|
148
164
|
* 处理器
|
|
149
165
|
*/
|
|
150
|
-
handle: (
|
|
166
|
+
handle: () => any;
|
|
151
167
|
}
|
|
152
|
-
interface
|
|
168
|
+
interface Cron extends CronJob {
|
|
153
169
|
}
|
|
154
170
|
}
|
|
155
171
|
export declare type XFile = MultipartFile;
|
package/lib/core/types.js
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// @index(['./**/*.ts', '!**/*.test.ts', '!./cli/**'], f => `export * from '${f.path}'`)
|
|
1
|
+
// @index(['./**/*.ts', '!**/*.test.ts', '!./cli/**', '!./client_helper.ts'], f => `export * from '${f.path}'`)
|
|
2
2
|
export * from "./core/define_bus";
|
|
3
|
+
export * from "./core/define_cron";
|
|
3
4
|
export * from "./core/define_handler";
|
|
4
5
|
export * from "./core/define_hook";
|
|
5
6
|
export * from "./core/define_server";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.3",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@prisma/client": "^3.12.0",
|
|
31
31
|
"@types/bull": "^3.15.8",
|
|
32
32
|
"@types/busboy": "^0.3.2",
|
|
33
|
+
"@types/cron": "^2.0.0",
|
|
33
34
|
"@types/http-errors": "^1.8.2",
|
|
34
35
|
"@types/jsonwebtoken": "^8.5.8",
|
|
35
36
|
"@types/nodemailer": "^6.4.4",
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"chokidar": "^3.5.3",
|
|
41
42
|
"comment-parser": "^1.3.1",
|
|
42
43
|
"compressing": "^1.5.1",
|
|
44
|
+
"cron": "^2.0.0",
|
|
43
45
|
"cuid": "^2.1.8",
|
|
44
46
|
"debug": "^4.3.4",
|
|
45
47
|
"esbuild": "^0.14.36",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../../src/tasks/index'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../../src/tasks/index'
|