koatty_schedule 3.1.0 → 3.2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
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
+ ## [3.2.0](https://github.com/thinkkoa/koatty_schedule/compare/v3.1.0...v3.2.0) (2025-06-22)
6
+
7
+
8
+ ### Features
9
+
10
+ * introduce component-specific metadata keys for scheduled and redlock decorators ([803b350](https://github.com/thinkkoa/koatty_schedule/commit/803b3503489c02ab138b3f9f14cb520dd6c7fec4))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * 修复IOC容器元数据键格式不匹配问题 ([065d456](https://github.com/thinkkoa/koatty_schedule/commit/065d456fc65004e25eb19838da96bf0a52cb2af1))
16
+
5
17
  ## [3.1.0](https://github.com/thinkkoa/koatty_schedule/compare/v3.0.0...v3.1.0) (2025-06-21)
6
18
 
7
19
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2025-06-21 15:37:37
3
+ * @Date: 2025-06-22 20:33:52
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2025-06-21 15:37:31
3
+ * @Date: 2025-06-22 20:33:45
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -23,6 +23,8 @@ var cron = require('cron');
23
23
  * @License: BSD (3-Clause)
24
24
  * @Copyright (c): <richenlin(at)gmail.com>
25
25
  */
26
+ const COMPONENT_SCHEDULED = 'COMPONENT_SCHEDULED';
27
+ const COMPONENT_REDLOCK = 'COMPONENT_REDLOCK';
26
28
  /**
27
29
  * Decorator types supported by the system
28
30
  */
@@ -209,9 +211,9 @@ function RedLock(lockName, options) {
209
211
  validateRedLockMethodOptions(options);
210
212
  }
211
213
  // 保存类到IOC容器
212
- koatty_container.IOCContainer.saveClass('COMPONENT', targetClass, targetClass.name);
214
+ koatty_container.IOCContainer.saveClass(COMPONENT_REDLOCK, targetClass, targetClass.name);
213
215
  // 保存RedLock元数据到 IOC 容器(lockName已确定)
214
- koatty_container.IOCContainer.attachClassMetadata('COMPONENT', DecoratorType.REDLOCK, {
216
+ koatty_container.IOCContainer.attachClassMetadata(COMPONENT_REDLOCK, DecoratorType.REDLOCK, {
215
217
  method: methodName,
216
218
  name: lockName, // 确定的锁名称,不会为undefined
217
219
  options
@@ -279,9 +281,9 @@ function Scheduled(cron, timezone) {
279
281
  throw Error("@Scheduled decorator can only be applied to methods");
280
282
  }
281
283
  // 保存类到IOC容器
282
- koatty_container.IOCContainer.saveClass('COMPONENT', targetClass, targetClass.name);
284
+ koatty_container.IOCContainer.saveClass(COMPONENT_SCHEDULED, targetClass, targetClass.name);
283
285
  // 保存调度元数据到 IOC 容器
284
- koatty_container.IOCContainer.attachClassMetadata('COMPONENT', DecoratorType.SCHEDULED, {
286
+ koatty_container.IOCContainer.attachClassMetadata(COMPONENT_SCHEDULED, DecoratorType.SCHEDULED, {
285
287
  method: methodName,
286
288
  cron,
287
289
  timezone // 保存用户指定的值,可能为undefined
@@ -717,9 +719,9 @@ async function initRedLock(options, app) {
717
719
  async function injectRedLock(_options, _app) {
718
720
  try {
719
721
  koatty_logger.DefaultLogger.Debug('Starting batch RedLock injection...');
720
- const componentList = koatty_container.IOCContainer.listClass("COMPONENT");
722
+ const componentList = koatty_container.IOCContainer.listClass(COMPONENT_REDLOCK);
721
723
  for (const component of componentList) {
722
- const classMetadata = koatty_container.IOCContainer.getClassMetadata('COMPONENT', DecoratorType.REDLOCK, component);
724
+ const classMetadata = koatty_container.IOCContainer.getClassMetadata(COMPONENT_REDLOCK, DecoratorType.REDLOCK, component.target);
723
725
  if (!classMetadata) {
724
726
  continue;
725
727
  }
@@ -732,7 +734,7 @@ async function injectRedLock(_options, _app) {
732
734
  }
733
735
  // 查找所有RedLock方法的元数据
734
736
  for (const [key, value] of Object.entries(metadata)) {
735
- if (key.startsWith('REDLOCK:')) {
737
+ if (key.startsWith('REDLOCK')) {
736
738
  const redlockData = value;
737
739
  const targetMethod = instance[redlockData.method];
738
740
  if (!koatty_lib.Helper.isFunction(targetMethod)) {
@@ -903,9 +905,9 @@ function redLockerDescriptor(descriptor, name, method, methodOptions) {
903
905
  async function injectSchedule(_options, _app) {
904
906
  try {
905
907
  koatty_logger.DefaultLogger.Debug('Starting batch schedule injection...');
906
- const componentList = koatty_container.IOCContainer.listClass("COMPONENT");
908
+ const componentList = koatty_container.IOCContainer.listClass(COMPONENT_SCHEDULED);
907
909
  for (const component of componentList) {
908
- const classMetadata = koatty_container.IOCContainer.getClassMetadata('COMPONENT', DecoratorType.SCHEDULED, component);
910
+ const classMetadata = koatty_container.IOCContainer.getClassMetadata(COMPONENT_SCHEDULED, DecoratorType.SCHEDULED, component.target);
909
911
  if (!classMetadata) {
910
912
  continue;
911
913
  }
@@ -918,7 +920,7 @@ async function injectSchedule(_options, _app) {
918
920
  }
919
921
  // 查找所有调度方法的元数据
920
922
  for (const [key, value] of Object.entries(metadata)) {
921
- if (key.startsWith('SCHEDULED:')) {
923
+ if (key.startsWith('SCHEDULED')) {
922
924
  const scheduleData = value;
923
925
  const targetMethod = instance[scheduleData.method];
924
926
  if (!koatty_lib.Helper.isFunction(targetMethod)) {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2025-06-21 15:37:31
3
+ * @Date: 2025-06-22 20:33:45
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -21,6 +21,8 @@ import { CronJob } from 'cron';
21
21
  * @License: BSD (3-Clause)
22
22
  * @Copyright (c): <richenlin(at)gmail.com>
23
23
  */
24
+ const COMPONENT_SCHEDULED = 'COMPONENT_SCHEDULED';
25
+ const COMPONENT_REDLOCK = 'COMPONENT_REDLOCK';
24
26
  /**
25
27
  * Decorator types supported by the system
26
28
  */
@@ -207,9 +209,9 @@ function RedLock(lockName, options) {
207
209
  validateRedLockMethodOptions(options);
208
210
  }
209
211
  // 保存类到IOC容器
210
- IOCContainer.saveClass('COMPONENT', targetClass, targetClass.name);
212
+ IOCContainer.saveClass(COMPONENT_REDLOCK, targetClass, targetClass.name);
211
213
  // 保存RedLock元数据到 IOC 容器(lockName已确定)
212
- IOCContainer.attachClassMetadata('COMPONENT', DecoratorType.REDLOCK, {
214
+ IOCContainer.attachClassMetadata(COMPONENT_REDLOCK, DecoratorType.REDLOCK, {
213
215
  method: methodName,
214
216
  name: lockName, // 确定的锁名称,不会为undefined
215
217
  options
@@ -277,9 +279,9 @@ function Scheduled(cron, timezone) {
277
279
  throw Error("@Scheduled decorator can only be applied to methods");
278
280
  }
279
281
  // 保存类到IOC容器
280
- IOCContainer.saveClass('COMPONENT', targetClass, targetClass.name);
282
+ IOCContainer.saveClass(COMPONENT_SCHEDULED, targetClass, targetClass.name);
281
283
  // 保存调度元数据到 IOC 容器
282
- IOCContainer.attachClassMetadata('COMPONENT', DecoratorType.SCHEDULED, {
284
+ IOCContainer.attachClassMetadata(COMPONENT_SCHEDULED, DecoratorType.SCHEDULED, {
283
285
  method: methodName,
284
286
  cron,
285
287
  timezone // 保存用户指定的值,可能为undefined
@@ -715,9 +717,9 @@ async function initRedLock(options, app) {
715
717
  async function injectRedLock(_options, _app) {
716
718
  try {
717
719
  DefaultLogger.Debug('Starting batch RedLock injection...');
718
- const componentList = IOCContainer.listClass("COMPONENT");
720
+ const componentList = IOCContainer.listClass(COMPONENT_REDLOCK);
719
721
  for (const component of componentList) {
720
- const classMetadata = IOCContainer.getClassMetadata('COMPONENT', DecoratorType.REDLOCK, component);
722
+ const classMetadata = IOCContainer.getClassMetadata(COMPONENT_REDLOCK, DecoratorType.REDLOCK, component.target);
721
723
  if (!classMetadata) {
722
724
  continue;
723
725
  }
@@ -730,7 +732,7 @@ async function injectRedLock(_options, _app) {
730
732
  }
731
733
  // 查找所有RedLock方法的元数据
732
734
  for (const [key, value] of Object.entries(metadata)) {
733
- if (key.startsWith('REDLOCK:')) {
735
+ if (key.startsWith('REDLOCK')) {
734
736
  const redlockData = value;
735
737
  const targetMethod = instance[redlockData.method];
736
738
  if (!Helper.isFunction(targetMethod)) {
@@ -901,9 +903,9 @@ function redLockerDescriptor(descriptor, name, method, methodOptions) {
901
903
  async function injectSchedule(_options, _app) {
902
904
  try {
903
905
  DefaultLogger.Debug('Starting batch schedule injection...');
904
- const componentList = IOCContainer.listClass("COMPONENT");
906
+ const componentList = IOCContainer.listClass(COMPONENT_SCHEDULED);
905
907
  for (const component of componentList) {
906
- const classMetadata = IOCContainer.getClassMetadata('COMPONENT', DecoratorType.SCHEDULED, component);
908
+ const classMetadata = IOCContainer.getClassMetadata(COMPONENT_SCHEDULED, DecoratorType.SCHEDULED, component.target);
907
909
  if (!classMetadata) {
908
910
  continue;
909
911
  }
@@ -916,7 +918,7 @@ async function injectSchedule(_options, _app) {
916
918
  }
917
919
  // 查找所有调度方法的元数据
918
920
  for (const [key, value] of Object.entries(metadata)) {
919
- if (key.startsWith('SCHEDULED:')) {
921
+ if (key.startsWith('SCHEDULED')) {
920
922
  const scheduleData = value;
921
923
  const targetMethod = instance[scheduleData.method];
922
924
  if (!Helper.isFunction(targetMethod)) {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty_schedule",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Schedule for koatty.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty_schedule",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Schedule for koatty.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",