Skip to content

Commit

Permalink
refactor: core/schedule-decorator (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Feb 16, 2025
1 parent 2465d5d commit f53d001
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 43 deletions.
6 changes: 0 additions & 6 deletions core/schedule-decorator/index.ts

This file was deleted.

32 changes: 16 additions & 16 deletions core/schedule-decorator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
"name": "@eggjs/tegg-schedule-decorator",
"version": "3.52.0",
"description": "tegg schedule decorator",
"main": "dist/index.js",
"type": "module",
"exports": {
".": {
"types": "./src/index.d.ts",
"default": "./src/index.js"
}
},
"files": [
"dist/**/*.js",
"dist/**/*.d.ts"
"src/**/*.js",
"src/**/*.d.ts"
],
"typings": "dist/index.d.ts",
"keywords": [
"egg",
"typescript",
Expand All @@ -17,8 +22,8 @@
"scripts": {
"clean": "tsc -b --clean",
"tsc": "npm run clean && tsc -p ./tsconfig.json",
"tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json",
"prepublishOnly": "npm run tsc:pub"
"tsc:pub": "npm run tsc",
"prepublishOnly": "npm run tsc"
},
"author": "killagu <[email protected]>",
"license": "MIT",
Expand All @@ -32,23 +37,18 @@
"directory": "core/schedule-decorator"
},
"engines": {
"node": ">=14.0.0"
"node": ">=20.0.0"
},
"dependencies": {
"@eggjs/core-decorator": "^3.52.0",
"@eggjs/tegg-common-util": "^3.52.0",
"@eggjs/tegg-metadata": "^3.52.0",
"@eggjs/tegg-types": "^3.52.0",
"cron-parser": "^2.18.0"
"@eggjs/tegg-types": "^3.52.0"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "^20.2.4",
"cross-env": "^7.0.3",
"egg-schedule": "^3.6.6",
"mocha": "^10.2.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"@types/node": "22",
"ts-node": "10",
"typescript": "5"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions core/schedule-decorator/src/builder/ScheduleMetaBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EggProtoImplClass, ScheduleOptions } from '@eggjs/tegg-types';
import { ScheduleMetadata } from '../model/ScheduleMetadata';
import { ScheduleInfoUtil } from '../util/ScheduleInfoUtil';
import { ScheduleMetadata } from '../model/index.js';
import { ScheduleInfoUtil } from '../util/index.js';

const DEFAULT_SCHEDULE_OPTIONS: ScheduleOptions = {
immediate: false,
Expand Down
1 change: 1 addition & 0 deletions core/schedule-decorator/src/builder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ScheduleMetaBuilder.js';
2 changes: 1 addition & 1 deletion core/schedule-decorator/src/decorator/Schedule.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PrototypeUtil, SingletonProto } from '@eggjs/core-decorator';
import { AccessLevel } from '@eggjs/tegg-types';
import type { EggProtoImplClass, ScheduleOptions, ScheduleParams, ScheduleSubscriber } from '@eggjs/tegg-types';
import { ScheduleInfoUtil } from '../util/ScheduleInfoUtil';
import { StackUtil } from '@eggjs/tegg-common-util';
import { ScheduleInfoUtil } from '../util/index.js';

export function Schedule<T>(param: ScheduleParams<T>, options?: ScheduleOptions) {
return function(clazz: EggProtoImplClass<ScheduleSubscriber>) {
Expand Down
1 change: 1 addition & 0 deletions core/schedule-decorator/src/decorator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Schedule.js';
5 changes: 5 additions & 0 deletions core/schedule-decorator/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from '@eggjs/tegg-types/schedule';
export * from './builder/index.js';
export * from './decorator/index.js';
export * from './model/index.js';
export * from './util/index.js';
1 change: 1 addition & 0 deletions core/schedule-decorator/src/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ScheduleMetadata.js';
4 changes: 2 additions & 2 deletions core/schedule-decorator/src/util/ScheduleMetadataUtil.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { MetadataUtil } from '@eggjs/core-decorator';
import { SCHEDULE_METADATA } from '@eggjs/tegg-types';
import type { EggProtoImplClass } from '@eggjs/tegg-types';
import { ScheduleMetadata } from '../model/ScheduleMetadata';
import { ScheduleMetadata } from '../model/index.js';

export class ScheduleMetadataUtil {
static setScheduleMetadata(clazz: EggProtoImplClass, metaData: ScheduleMetadata<object>) {
MetadataUtil.defineMetaData(SCHEDULE_METADATA, metaData, clazz);
}

static getScheduleMetadata(clazz): ScheduleMetadata<object> | undefined {
static getScheduleMetadata(clazz: EggProtoImplClass): ScheduleMetadata<object> | undefined {
return MetadataUtil.getMetaData(SCHEDULE_METADATA, clazz);
}
}
2 changes: 2 additions & 0 deletions core/schedule-decorator/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ScheduleInfoUtil.js';
export * from './ScheduleMetadataUtil.js';
19 changes: 19 additions & 0 deletions core/schedule-decorator/test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should export stable 1`] = `
{
"IS_SCHEDULE": Symbol(EggPrototype#isSchedule),
"SCHEDULE_METADATA": Symbol(EggPrototype#schedule#metadata),
"SCHEDULE_OPTIONS": Symbol(EggPrototype#schedule#options),
"SCHEDULE_PARAMS": Symbol(EggPrototype#schedule#params),
"Schedule": [Function],
"ScheduleInfoUtil": [Function],
"ScheduleMetaBuilder": [Function],
"ScheduleMetadata": [Function],
"ScheduleMetadataUtil": [Function],
"ScheduleType": {
"ALL": "all",
"WORKER": "worker",
},
}
`;
6 changes: 6 additions & 0 deletions core/schedule-decorator/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, it } from 'vitest';
import * as types from '../src/index.js';

it('should export stable', async () => {
expect(types).toMatchSnapshot();
});
3 changes: 0 additions & 3 deletions core/schedule-decorator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"baseUrl": "./"
},
"exclude": [
"dist",
"node_modules",
"test"
]
}
12 changes: 0 additions & 12 deletions core/schedule-decorator/tsconfig.pub.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"tsc-workspaces": "npm run tsc --workspaces --if-present",
"tsc:pub": "lerna run tsc:pub",
"tsc:pub-workspaces": "npm run tsc:pub --workspaces --if-present",
"coverage": "vitest run --coverage core/types core/core-decorator core/common-util core/aop-decorator core/lifecycle core/ajv-decorator core/loader core/runtime core/test-util core/aop-runtime core/background-task core/controller-decorator core/dal-decorator core/dal-runtime core/dynamic-inject core/dynamic-inject-runtime core/eventbus-decorator core/eventbus-runtime core/orm-decorator",
"coverage": "vitest run --coverage core/types core/core-decorator core/common-util core/aop-decorator core/lifecycle core/ajv-decorator core/loader core/runtime core/test-util core/aop-runtime core/background-task core/controller-decorator core/dal-decorator core/dal-runtime core/dynamic-inject core/dynamic-inject-runtime core/eventbus-decorator core/eventbus-runtime core/orm-decorator core/schedule-decorator",
"preci": "npm run clean && npm run lint",
"ci": "npm run coverage",
"postci-skip": "npm run prepublishOnly --workspaces --if-present"
Expand Down

0 comments on commit f53d001

Please sign in to comment.