@atri-bot/lib-cron 1.1.3 → 1.1.5

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.
@@ -0,0 +1,21 @@
1
+ import * as _atri_bot_core0 from "@atri-bot/core";
2
+ import { CronJob } from "cron";
3
+
4
+ //#region src/index.d.ts
5
+ interface CronConfig {
6
+ timeZone?: string;
7
+ }
8
+ type AddCronOptions = Parameters<typeof CronJob.from>[0] & {
9
+ name: string;
10
+ };
11
+ declare function CronPlugin(config: CronConfig): _atri_bot_core0.definePluginReturnType<CronConfig, {
12
+ pluginName: string;
13
+ config: CronConfig;
14
+ install(): void;
15
+ uninstall(): void;
16
+ getCronJobs(): Record<string, CronJob<null, null>>;
17
+ add(options: AddCronOptions): [false, string] | [true, CronJob];
18
+ remove(name: string): void;
19
+ }>;
20
+ //#endregion
21
+ export { AddCronOptions, CronConfig, CronPlugin };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{definePlugin as e}from"@atri-bot/core";import{CronJob as t}from"cron";const n={};function r(r){return e({pluginName:`Cron`,config:r,install(){},uninstall(){},getCronJobs(){return n},add(e){if(n[e.name])return[!1,`name already exists`];`timeZone`in e||(e.timeZone=this.config.timeZone??`Asia/Shanghai`);let r=t.from(e);return n[e.name]=r,[!0,r]},remove(e){let t=n[e];t&&(t.stop(),delete n[e])}})}export{r as CronPlugin};
package/package.json CHANGED
@@ -1,24 +1,23 @@
1
1
  {
2
2
  "name": "@atri-bot/lib-cron",
3
- "version": "1.1.3",
3
+ "type": "module",
4
+ "version": "1.1.5",
4
5
  "description": "cron lib for atri framework",
5
6
  "author": "huan_kong",
6
7
  "license": "MIT",
7
- "type": "module",
8
- "main": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
8
+ "main": "./dist/index.mjs",
9
+ "types": "./dist/index.d.mts",
10
10
  "files": [
11
11
  "./dist/**/*"
12
12
  ],
13
13
  "scripts": {
14
- "build": "pnpm run type-check && pnpm run lint && tsup",
15
- "clean": "rimraf dist",
14
+ "build": "tsdown",
16
15
  "lint": "eslint",
17
- "lint:fix": "eslint --fix",
18
16
  "type-check": "tsc --noEmit -p tsconfig.json --composite false"
19
17
  },
20
18
  "dependencies": {
21
- "@huan_kong/logger": "^1.0.6",
22
- "cron": "^4.3.3"
19
+ "@atri-bot/core": "^2.0.0-beta.3",
20
+ "cron": "^4.4.0",
21
+ "cron-validate": "^1.5.3"
23
22
  }
24
23
  }
package/dist/index.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { LogLevel, Logger } from '@huan_kong/logger';
2
- import { CronJob } from 'cron';
3
-
4
- interface CronConfig {
5
- debug?: boolean;
6
- logLevel?: LogLevel;
7
- }
8
- type AddCronOptions = Parameters<typeof CronJob.from>[0] & {
9
- onTick: () => void | Promise<void>;
10
- name: string;
11
- };
12
-
13
- declare class Cron {
14
- config: CronConfig;
15
- logger: Logger;
16
- cronJobs: Record<string, CronJob<null, null>>;
17
- constructor(config: CronConfig);
18
- add(options: AddCronOptions): CronJob;
19
- }
20
-
21
- export { Cron };
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- import{Logger as s,LogLevel as g}from"@huan_kong/logger";import{CronJob as c}from"cron";var r=class extends Error{constructor(o){super(o),this.name="CronJobNameExistsError"}};var m={},e=class{config;logger;cronJobs=m;constructor(o){this.config=o,this.logger=new s({title:"Cron",level:o.logLevel??(o.debug?g.DEBUG:void 0)})}add(o){if(this.cronJobs[o.name])throw new r;"timeZone"in o||(o.timeZone="Asia/Shanghai"),o.onTick=(i=>async()=>{this.logger.DEBUG("\u5B9A\u65F6\u4EFB\u52A1\u89E6\u53D1!"),await i()})(o.onTick);let n=c.from(o);return this.cronJobs[o.name]=n,n}};export{e as Cron};