@jayfong/x-server 1.30.2 → 1.31.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 +9 -0
- package/lib/_cjs/cli/templates/crons.ts +2 -0
- package/lib/_cjs/core/define_cron.js +14 -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 +8 -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 +18 -0
- 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,15 @@
|
|
|
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.1](https://github.com/jfWorks/x-server/compare/v1.31.0...v1.31.1) (2022-05-30)
|
|
6
|
+
|
|
7
|
+
## [1.31.0](https://github.com/jfWorks/x-server/compare/v1.30.2...v1.31.0) (2022-05-30)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* defineCron ([f9f362e](https://github.com/jfWorks/x-server/commit/f9f362ee0a9845f662af0b686781299390c5647d))
|
|
13
|
+
|
|
5
14
|
### [1.30.2](https://github.com/jfWorks/x-server/compare/v1.30.1...v1.30.2) (2022-05-26)
|
|
6
15
|
|
|
7
16
|
|
|
@@ -0,0 +1,14 @@
|
|
|
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: true,
|
|
12
|
+
onTick: options.handle
|
|
13
|
+
});
|
|
14
|
+
}
|
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';
|
|
@@ -152,4 +153,21 @@ export declare namespace XTask {
|
|
|
152
153
|
interface Task<T> extends Queue<T> {
|
|
153
154
|
}
|
|
154
155
|
}
|
|
156
|
+
export declare namespace XCron {
|
|
157
|
+
interface Options {
|
|
158
|
+
/**
|
|
159
|
+
* 定时语法
|
|
160
|
+
*
|
|
161
|
+
* @see https://crontab.guru/
|
|
162
|
+
* @see https://crontab.cronhub.io/
|
|
163
|
+
*/
|
|
164
|
+
expression: string;
|
|
165
|
+
/**
|
|
166
|
+
* 处理器
|
|
167
|
+
*/
|
|
168
|
+
handle: () => any;
|
|
169
|
+
}
|
|
170
|
+
interface Cron extends CronJob {
|
|
171
|
+
}
|
|
172
|
+
}
|
|
155
173
|
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.1",
|
|
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'
|