@ldsg/schedules 0.3.30 → 0.3.32

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.
@@ -1,6 +1,6 @@
1
- import { HandlerSpecificResourceSettings } from '@ldsg/handler';
2
- import { ResourceDefinitionSpecificResourceSettings } from '@ldsg/resource-definition';
3
- import { GeneralResourceSettings } from '@ldsg/types';
1
+ import { HandlerSpecificResourceSettings } from "@ldsg/handler";
2
+ import { ResourceDefinitionSpecificResourceSettings } from "@ldsg/resource-definition";
3
+ import { GeneralResourceSettings } from "@ldsg/types";
4
4
  export declare const INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
5
5
  export declare const INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS: HandlerSpecificResourceSettings;
6
6
  export declare const RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF,eAAO,MAAM,uDAAuD,EAAE,+BAOrE,CAAC;AAEF,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAE5D,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF,eAAO,MAAM,uDAAuD,EAAE,+BAQnE,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAG1D,CAAC"}
package/dist/constants.js CHANGED
@@ -2,21 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
4
4
  exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = {
5
- title: '定时任务组实例化资源处理程序',
6
- description: ''
5
+ title: "定时任务组实例化资源处理程序",
6
+ description: "",
7
7
  };
8
8
  exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
9
9
  code: `export * from "@ldsg/schedules";`,
10
10
  dependencies: [
11
11
  {
12
- name: '@ldsg/schedules'
13
- }
14
- ]
12
+ name: "@ldsg/schedules",
13
+ },
14
+ ],
15
15
  };
16
16
  exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
17
- title: '定时任务组资源定义',
18
- description: ''
17
+ title: "定时任务组资源定义",
18
+ description: "",
19
19
  };
20
20
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
21
- kind: 'schedules'
21
+ kind: "schedules",
22
22
  };
package/dist/handler.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Handler } from '@ldsg/handler';
2
- import { InstantiateResourceParams, InstantiateResourceRes } from '@ldsg/resource';
3
- import { SchedulesResource } from './resource';
4
- import { SchedulesSpecificResourceSettings } from './types';
1
+ import { Handler } from "@ldsg/handler";
2
+ import { InstantiateResourceParams, InstantiateResourceRes } from "@ldsg/resource";
3
+ import { SchedulesResource } from "./resource";
4
+ import { SchedulesSpecificResourceSettings } from "./types";
5
5
  export declare const handler: Handler<InstantiateResourceParams<SchedulesSpecificResourceSettings>, InstantiateResourceRes<SchedulesResource>>;
6
6
  //# sourceMappingURL=handler.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from './constants';
2
- export * from './handler';
3
- export * from './instantiate-resource';
4
- export * from './resource';
5
- export * from './types';
1
+ export * from "./constants";
2
+ export * from "./handler";
3
+ export * from "./instantiate-resource";
4
+ export * from "./resource";
5
+ export * from "./types";
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
- import { InstantiateResource } from '@ldsg/resource';
2
- import { SchedulesResource } from './resource';
3
- import { SchedulesSpecificResourceSettings } from './types';
1
+ import { InstantiateResource } from "@ldsg/resource";
2
+ import { SchedulesResource } from "./resource";
3
+ import { SchedulesSpecificResourceSettings } from "./types";
4
4
  export declare const instantiateResource: InstantiateResource<SchedulesSpecificResourceSettings, SchedulesResource>;
5
5
  //# sourceMappingURL=instantiate-resource.d.ts.map
@@ -6,7 +6,7 @@ const instantiateResource = (params) => {
6
6
  const { resourceConstructorParams } = params;
7
7
  const resource = new resource_1.SchedulesResource(resourceConstructorParams);
8
8
  const res = {
9
- resource
9
+ resource,
10
10
  };
11
11
  return res;
12
12
  };
@@ -1,8 +1,7 @@
1
- import { ExtendExpressApp } from '@ldsg/application';
2
- import { Resource } from '@ldsg/resource';
3
- import { ScheduleInfo } from '@ldsg/schedule';
4
- import { Agenda, Job } from 'agenda';
5
- import { CancelJobParams, ScheduleJobParams, SchedulesSpecificResourceSettings } from './types';
1
+ import { Resource } from "@ldsg/resource";
2
+ import { ScheduleInfo } from "@ldsg/schedule";
3
+ import { Agenda, Job } from "agenda";
4
+ import { CancelJobParams, ScheduleJobParams, SchedulesSpecificResourceSettings } from "./types";
6
5
  interface JobData {
7
6
  _static?: boolean;
8
7
  workflowResourceId: string;
@@ -16,7 +15,7 @@ export declare class SchedulesResource extends Resource<SchedulesSpecificResourc
16
15
  agenda: Agenda;
17
16
  getScheduleInfoList: GetScheduleInfoList;
18
17
  executeWorkflow: (params: JobData) => Promise<void>;
19
- extendExpressApp: ExtendExpressApp;
18
+ init: () => Promise<void>;
20
19
  scheduleJob: (params: ScheduleJobParams) => Promise<Job>;
21
20
  cancelJob: (params: CancelJobParams) => Promise<void>;
22
21
  stopSchedules: () => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAmB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAEhG,UAAU,OAAO;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAED,UAAU,sBAAsB;IAC9B,gBAAgB,EAAE,YAAY,EAAE,CAAC;CAClC;AAED,KAAK,mBAAmB,GAAG,MAAM,sBAAsB,CAAC;AAIxD,qBAAa,iBAAkB,SAAQ,QAAQ,CAAC,iCAAiC,CAAC;IAChF,MAAM,EAAG,MAAM,CAAC;IAEhB,mBAAmB,EAAE,mBAAmB,CAsBtC;IAEF,eAAe,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAiBjD;IAEF,gBAAgB,EAAE,gBAAgB,CAuDhC;IAEF,WAAW,GAAU,QAAQ,iBAAiB,KAAG,OAAO,CAAC,GAAG,CAAC,CA8B3D;IAEF,SAAS,GAAU,QAAQ,eAAe,mBAOxC;IAEF,aAAa,sBAEX;CACH"}
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAmB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAEhG,UAAU,OAAO;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAED,UAAU,sBAAsB;IAC9B,gBAAgB,EAAE,YAAY,EAAE,CAAC;CAClC;AAED,KAAK,mBAAmB,GAAG,MAAM,sBAAsB,CAAC;AAIxD,qBAAa,iBAAkB,SAAQ,QAAQ,CAAC,iCAAiC,CAAC;IAChF,MAAM,EAAG,MAAM,CAAC;IAEhB,mBAAmB,EAAE,mBAAmB,CAsBtC;IAEF,eAAe,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAiBjD;IAEF,IAAI,sBAwDF;IAEF,WAAW,GAAU,QAAQ,iBAAiB,KAAG,OAAO,CAAC,GAAG,CAAC,CAsC3D;IAEF,SAAS,GAAU,QAAQ,eAAe,mBAOxC;IAEF,aAAa,sBAEX;CACH"}
package/dist/resource.js CHANGED
@@ -4,34 +4,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SchedulesResource = void 0;
7
+ const mongo_backend_1 = require("@agendajs/mongo-backend");
7
8
  const resource_1 = require("@ldsg/resource");
8
9
  const agenda_1 = require("agenda");
9
- const mongo_backend_1 = require("@agendajs/mongo-backend");
10
10
  const lodash_1 = __importDefault(require("lodash"));
11
- const JOB_NAME = 'executeWorkflow';
11
+ const JOB_NAME = "executeWorkflow";
12
12
  class SchedulesResource extends resource_1.Resource {
13
13
  constructor() {
14
14
  super(...arguments);
15
15
  this.getScheduleInfoList = () => {
16
16
  const { id, getFilteredResources } = this;
17
17
  const { resources } = getFilteredResources({
18
- parentId: id
18
+ parentId: id,
19
19
  });
20
20
  const mapRes = resources.map((resource) => {
21
21
  var _a;
22
22
  return (_a = resource.getScheduleInfo) === null || _a === void 0 ? void 0 : _a.call(resource);
23
23
  });
24
24
  const filterRes = lodash_1.default.filter(mapRes, (value) => !lodash_1.default.isUndefined(value));
25
- const scheduleInfoList = lodash_1.default.map(filterRes, 'scheduleInfo');
25
+ const scheduleInfoList = lodash_1.default.map(filterRes, "scheduleInfo");
26
26
  const res = {
27
- scheduleInfoList
27
+ scheduleInfoList,
28
28
  };
29
29
  return res;
30
30
  };
31
31
  this.executeWorkflow = async (params) => {
32
32
  const { workflowResourceId, workflowVariables } = params;
33
33
  const { resource: workflowResource } = this.getFilteredResource({
34
- id: workflowResourceId
34
+ id: workflowResourceId,
35
35
  });
36
36
  const wr = workflowResource;
37
37
  if (!(wr === null || wr === void 0 ? void 0 : wr.execute)) {
@@ -39,33 +39,34 @@ class SchedulesResource extends resource_1.Resource {
39
39
  }
40
40
  await wr.execute({
41
41
  context: {},
42
- variables: workflowVariables || {}
42
+ variables: workflowVariables || {},
43
43
  });
44
44
  };
45
- this.extendExpressApp = async (params) => {
45
+ this.init = async () => {
46
46
  var _a;
47
- const { getFilteredResource, getResourcesFromSettings, settings: { processEvery } } = this;
48
- const databaseResourceFromSettings = getResourcesFromSettings().databaseResource;
47
+ const { getFilteredResource, getResourcesFromSettings, settings: { processEvery }, } = this;
48
+ const databaseResourceFromSettings = getResourcesFromSettings()
49
+ .databaseResource;
49
50
  const databaseResource = databaseResourceFromSettings !== null && databaseResourceFromSettings !== void 0 ? databaseResourceFromSettings : getFilteredResource({
50
- kind: 'database'
51
+ kind: "database",
51
52
  }).resource;
52
53
  const databaseInfo = (_a = databaseResource === null || databaseResource === void 0 ? void 0 : databaseResource.getDatabaseInfo) === null || _a === void 0 ? void 0 : _a.call(databaseResource);
53
54
  if (!(databaseInfo === null || databaseInfo === void 0 ? void 0 : databaseInfo.uri)) {
54
- throw new Error('database uri not available');
55
+ throw new Error("database uri not available");
55
56
  }
56
57
  this.agenda = new agenda_1.Agenda({
57
58
  backend: new mongo_backend_1.MongoBackend({ address: databaseInfo.uri }),
58
- processEvery
59
+ processEvery,
59
60
  });
60
- this.agenda.on('error', (error) => {
61
- console.error('Agenda error:', error);
61
+ this.agenda.on("error", (error) => {
62
+ console.error("Agenda error:", error);
62
63
  });
63
64
  this.agenda.define(JOB_NAME, async (job) => {
64
65
  await this.executeWorkflow(job.attrs.data);
65
66
  });
66
67
  await this.agenda.start();
67
68
  const { scheduleInfoList } = this.getScheduleInfoList();
68
- const hasEvery = scheduleInfoList.some((info) => info.triggerType === 'every');
69
+ const hasEvery = scheduleInfoList.some((info) => info.triggerType === "every");
69
70
  if (hasEvery) {
70
71
  await this.agenda.cancel({ name: JOB_NAME });
71
72
  }
@@ -77,21 +78,21 @@ class SchedulesResource extends resource_1.Resource {
77
78
  triggerType: scheduleInfo.triggerType,
78
79
  delay: scheduleInfo.delay,
79
80
  scheduledAt: scheduleInfo.scheduledAt,
80
- cron: scheduleInfo.cron
81
+ cron: scheduleInfo.cron,
81
82
  });
82
83
  }
83
84
  };
84
85
  this.scheduleJob = async (params) => {
85
86
  if (!this.agenda) {
86
- throw new Error('agenda not initialized');
87
+ throw new Error("agenda not initialized");
87
88
  }
88
- const { workflowResourceId, workflowVariables, triggerType, delay, scheduledAt, cron, _static } = params;
89
+ const { workflowResourceId, workflowVariables, triggerType, delay, scheduledAt, cron, _static, } = params;
89
90
  const jobData = { _static, workflowResourceId, workflowVariables };
90
- if (triggerType === 'now') {
91
+ if (triggerType === "now") {
91
92
  return this.agenda.now(JOB_NAME, jobData);
92
93
  }
93
94
  const job = this.agenda.create(JOB_NAME, jobData);
94
- if (triggerType === 'once') {
95
+ if (triggerType === "once") {
95
96
  if (scheduledAt) {
96
97
  job.schedule(new Date(scheduledAt));
97
98
  }
@@ -99,20 +100,20 @@ class SchedulesResource extends resource_1.Resource {
99
100
  job.schedule(new Date(Date.now() + delay));
100
101
  }
101
102
  else {
102
- throw new Error('invalid scheduling parameters: delay or scheduledAt required');
103
+ throw new Error("invalid scheduling parameters: delay or scheduledAt required");
103
104
  }
104
105
  }
105
- else if (triggerType === 'every' && cron) {
106
+ else if (triggerType === "every" && cron) {
106
107
  job.repeatEvery(cron);
107
108
  }
108
109
  else {
109
- throw new Error('invalid scheduling parameters');
110
+ throw new Error("invalid scheduling parameters");
110
111
  }
111
112
  return job.save();
112
113
  };
113
114
  this.cancelJob = async (params) => {
114
115
  if (!this.agenda) {
115
- throw new Error('agenda not initialized');
116
+ throw new Error("agenda not initialized");
116
117
  }
117
118
  const { jobId } = params;
118
119
  await this.agenda.cancel({ id: jobId });
@@ -1,3 +1,3 @@
1
- export * from './job-params';
2
- export * from './specific-resource-settings';
1
+ export * from "./job-params";
2
+ export * from "./specific-resource-settings";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { TriggerType } from '@ldsg/schedule';
1
+ import { TriggerType } from "@ldsg/schedule";
2
2
  export interface ScheduleJobParams {
3
3
  workflowResourceId: string;
4
4
  workflowVariables?: Record<string, unknown>;
@@ -1,4 +1,4 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
  export declare const SchedulesSpecificResourceSettingsSchema: z.ZodObject<{
3
3
  databaseResourceId: z.ZodOptional<z.ZodString>;
4
4
  processEvery: z.ZodOptional<z.ZodNumber>;
@@ -1 +1 @@
1
- {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,uCAAuC;;;8BAMhC,CAAC;AAErB,eAAO,MAAM,8BAA8B;;;8BAA0C,CAAC;AACtF,MAAM,MAAM,iCAAiC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uCAAuC,CAAC,CAAC"}
1
+ {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,uCAAuC;;;8BAMhC,CAAC;AAErB,eAAO,MAAM,8BAA8B;;;8BAA0C,CAAC;AACtF,MAAM,MAAM,iCAAiC,GAAG,CAAC,CAAC,KAAK,CACrD,OAAO,uCAAuC,CAC/C,CAAC"}
@@ -6,7 +6,7 @@ exports.SchedulesSpecificResourceSettingsSchema = zod_1.z
6
6
  .object({
7
7
  databaseResourceId: zod_1.z.string().optional(),
8
8
  /** 轮询间隔(毫秒),默认 1000 */
9
- processEvery: zod_1.z.number().optional()
9
+ processEvery: zod_1.z.number().optional(),
10
10
  })
11
11
  .catchall(zod_1.z.any());
12
12
  exports.SpecificResourceSettingsSchema = exports.SchedulesSpecificResourceSettingsSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldsg/schedules",
3
- "version": "0.3.30",
3
+ "version": "0.3.32",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -15,22 +15,24 @@
15
15
  "agenda": "^6.2.5",
16
16
  "lodash": "^4.17.21",
17
17
  "zod": "^4.1.11",
18
- "@ldsg/database": "0.3.30",
19
- "@ldsg/handler": "0.3.30",
20
- "@ldsg/resource-definition": "0.3.30",
21
- "@ldsg/resource": "0.3.30",
22
- "@ldsg/schedule": "0.3.30"
18
+ "@ldsg/handler": "0.3.32",
19
+ "@ldsg/resource-definition": "0.3.32",
20
+ "@ldsg/schedule": "0.3.32",
21
+ "@ldsg/resource": "0.3.32",
22
+ "@ldsg/database": "0.3.32"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/jest": "^29.5.2",
26
26
  "@types/lodash": "^4.14.202",
27
27
  "@types/node": "^20.13.0",
28
28
  "jest": "^29.5.0",
29
+ "oxfmt": "latest",
30
+ "oxlint": "latest",
29
31
  "ts-jest": "^29.1.5",
30
32
  "ts-node": "^10.9.2",
31
33
  "typescript": "^5.8.3",
32
- "@ldsg/types": "0.3.30",
33
- "@ldsg/application": "0.3.30"
34
+ "@ldsg/application": "0.3.32",
35
+ "@ldsg/types": "0.3.32"
34
36
  },
35
37
  "publishConfig": {
36
38
  "access": "public"
@@ -38,6 +40,8 @@
38
40
  "scripts": {
39
41
  "build": "tsc --project tsconfig.build.json",
40
42
  "clean": "rm -rf dist",
43
+ "format": "oxfmt --write src/",
44
+ "lint": "oxlint src/",
41
45
  "test": "jest"
42
46
  }
43
47
  }