@ruiapp/rapid-core 0.1.31 → 0.1.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.
Files changed (30) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +271 -119
  3. package/dist/plugins/cronJob/CronJobPlugin.d.ts +27 -0
  4. package/dist/plugins/cronJob/CronJobPluginTypes.d.ts +39 -0
  5. package/dist/plugins/cronJob/actionHandlers/index.d.ts +3 -0
  6. package/dist/plugins/cronJob/actionHandlers/runCronJob.d.ts +5 -0
  7. package/dist/plugins/cronJob/routes/index.d.ts +12 -0
  8. package/dist/plugins/cronJob/routes/runCronJob.d.ts +12 -0
  9. package/dist/plugins/sequence/SequenceService.d.ts +1 -1
  10. package/dist/plugins/sequence/segments/autoIncrement.d.ts +1 -1
  11. package/dist/plugins/sequence/segments/dayOfMonth.d.ts +1 -1
  12. package/dist/plugins/sequence/segments/literal.d.ts +1 -1
  13. package/dist/plugins/sequence/segments/month.d.ts +1 -1
  14. package/dist/plugins/sequence/segments/parameter.d.ts +1 -1
  15. package/dist/plugins/sequence/segments/year.d.ts +1 -1
  16. package/package.json +2 -1
  17. package/src/index.ts +3 -0
  18. package/src/plugins/cronJob/CronJobPlugin.ts +113 -0
  19. package/src/plugins/cronJob/CronJobPluginTypes.ts +49 -0
  20. package/src/plugins/cronJob/actionHandlers/index.ts +6 -0
  21. package/src/plugins/cronJob/actionHandlers/runCronJob.ts +34 -0
  22. package/src/plugins/cronJob/routes/index.ts +5 -0
  23. package/src/plugins/cronJob/routes/runCronJob.ts +15 -0
  24. package/src/plugins/sequence/SequenceService.ts +1 -2
  25. package/src/plugins/sequence/segments/autoIncrement.ts +1 -1
  26. package/src/plugins/sequence/segments/dayOfMonth.ts +1 -1
  27. package/src/plugins/sequence/segments/literal.ts +1 -1
  28. package/src/plugins/sequence/segments/month.ts +1 -1
  29. package/src/plugins/sequence/segments/parameter.ts +1 -1
  30. package/src/plugins/sequence/segments/year.ts +1 -1
package/dist/index.d.ts CHANGED
@@ -17,6 +17,8 @@ export { default as AuthPlugin } from "./plugins/auth/AuthPlugin";
17
17
  export { default as FileManagePlugin } from "./plugins/fileManage/FileManagePlugin";
18
18
  export { default as ServerOperationPlugin } from "./plugins/serverOperation/ServerOperationPlugin";
19
19
  export * from "./plugins/serverOperation/ServerOperationPluginTypes";
20
+ export { default as CronJobPlugin } from "./plugins/cronJob/CronJobPlugin";
21
+ export * from "./plugins/cronJob/CronJobPluginTypes";
20
22
  export { default as StateMachinePlugin } from "./plugins/stateMachine/StateMachinePlugin";
21
23
  export * from "./plugins/stateMachine/StateMachinePluginTypes";
22
24
  export { default as EntityWatchPlugin } from "./plugins/entityWatch/EntityWatchPlugin";
package/dist/index.js CHANGED
@@ -13,10 +13,29 @@ var bcrypt = require('bcrypt');
13
13
  var path = require('path');
14
14
  var fs = require('fs');
15
15
  var uuid = require('uuid');
16
+ var cron = require('cron');
16
17
  var xstate = require('xstate');
17
18
 
18
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
20
 
21
+ function _interopNamespace(e) {
22
+ if (e && e.__esModule) return e;
23
+ var n = Object.create(null);
24
+ if (e) {
25
+ Object.keys(e).forEach(function (k) {
26
+ if (k !== 'default') {
27
+ var d = Object.getOwnPropertyDescriptor(e, k);
28
+ Object.defineProperty(n, k, d.get ? d : {
29
+ enumerable: true,
30
+ get: function () { return e[k]; }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ n["default"] = e;
36
+ return Object.freeze(n);
37
+ }
38
+
20
39
  var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
21
40
  var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
22
41
  var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
@@ -24,6 +43,7 @@ var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
24
43
  var bcrypt__default = /*#__PURE__*/_interopDefaultLegacy(bcrypt);
25
44
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
26
45
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
46
+ var cron__namespace = /*#__PURE__*/_interopNamespace(cron);
27
47
 
28
48
  function fixBigIntJSONSerialize() {
29
49
  BigInt.prototype.toJSON = function () {
@@ -2799,32 +2819,32 @@ async function generateJwtSecretKey() {
2799
2819
  return encode(exportedKey);
2800
2820
  }
2801
2821
 
2802
- const code$o = "listMetaModels";
2803
- async function handler$o(plugin, ctx, options) {
2822
+ const code$p = "listMetaModels";
2823
+ async function handler$p(plugin, ctx, options) {
2804
2824
  const { applicationConfig } = ctx;
2805
2825
  ctx.output = { list: applicationConfig.models };
2806
2826
  }
2807
2827
 
2808
2828
  var listMetaModels = /*#__PURE__*/Object.freeze({
2809
2829
  __proto__: null,
2810
- code: code$o,
2811
- handler: handler$o
2830
+ code: code$p,
2831
+ handler: handler$p
2812
2832
  });
2813
2833
 
2814
- const code$n = "listMetaRoutes";
2815
- async function handler$n(plugin, ctx, options) {
2834
+ const code$o = "listMetaRoutes";
2835
+ async function handler$o(plugin, ctx, options) {
2816
2836
  const { applicationConfig } = ctx;
2817
2837
  ctx.output = { list: applicationConfig.routes };
2818
2838
  }
2819
2839
 
2820
2840
  var listMetaRoutes = /*#__PURE__*/Object.freeze({
2821
2841
  __proto__: null,
2822
- code: code$n,
2823
- handler: handler$n
2842
+ code: code$o,
2843
+ handler: handler$o
2824
2844
  });
2825
2845
 
2826
- const code$m = "getMetaModelDetail";
2827
- async function handler$m(plugin, ctx, options) {
2846
+ const code$n = "getMetaModelDetail";
2847
+ async function handler$n(plugin, ctx, options) {
2828
2848
  const { server, input } = ctx;
2829
2849
  const model = server.getModel(input);
2830
2850
  ctx.output = model;
@@ -2832,8 +2852,8 @@ async function handler$m(plugin, ctx, options) {
2832
2852
 
2833
2853
  var getMetaModelDetail = /*#__PURE__*/Object.freeze({
2834
2854
  __proto__: null,
2835
- code: code$m,
2836
- handler: handler$m
2855
+ code: code$n,
2856
+ handler: handler$n
2837
2857
  });
2838
2858
 
2839
2859
  /**
@@ -3185,9 +3205,9 @@ function transformFilterWithSubFilters(filter) {
3185
3205
  return filter;
3186
3206
  }
3187
3207
 
3188
- const code$l = "findCollectionEntities";
3189
- async function handler$l(plugin, ctx, options) {
3190
- await runCollectionEntityActionHandler(ctx, options, code$l, async (entityManager, input) => {
3208
+ const code$m = "findCollectionEntities";
3209
+ async function handler$m(plugin, ctx, options) {
3210
+ await runCollectionEntityActionHandler(ctx, options, code$m, async (entityManager, input) => {
3191
3211
  input.filters = removeFiltersWithNullValue(input.filters);
3192
3212
  const entities = await entityManager.findEntities(input);
3193
3213
  const result = { list: entities };
@@ -3202,14 +3222,14 @@ async function handler$l(plugin, ctx, options) {
3202
3222
 
3203
3223
  var findCollectionEntities = /*#__PURE__*/Object.freeze({
3204
3224
  __proto__: null,
3205
- code: code$l,
3206
- handler: handler$l
3225
+ code: code$m,
3226
+ handler: handler$m
3207
3227
  });
3208
3228
 
3209
- const code$k = "findCollectionEntityById";
3210
- async function handler$k(plugin, ctx, options) {
3229
+ const code$l = "findCollectionEntityById";
3230
+ async function handler$l(plugin, ctx, options) {
3211
3231
  const { logger, server, input } = ctx;
3212
- logger.debug(`Running ${code$k} handler...`, { input });
3232
+ logger.debug(`Running ${code$l} handler...`, { input });
3213
3233
  const { id } = input;
3214
3234
  const entityManager = server.getEntityManager(options.singularCode);
3215
3235
  const entity = await entityManager.findById(id);
@@ -3221,13 +3241,13 @@ async function handler$k(plugin, ctx, options) {
3221
3241
 
3222
3242
  var findCollectionEntityById = /*#__PURE__*/Object.freeze({
3223
3243
  __proto__: null,
3224
- code: code$k,
3225
- handler: handler$k
3244
+ code: code$l,
3245
+ handler: handler$l
3226
3246
  });
3227
3247
 
3228
- const code$j = "countCollectionEntities";
3229
- async function handler$j(plugin, ctx, options) {
3230
- await runCollectionEntityActionHandler(ctx, options, code$j, (entityManager, input) => {
3248
+ const code$k = "countCollectionEntities";
3249
+ async function handler$k(plugin, ctx, options) {
3250
+ await runCollectionEntityActionHandler(ctx, options, code$k, (entityManager, input) => {
3231
3251
  input.filters = removeFiltersWithNullValue(input.filters);
3232
3252
  return entityManager.count(input);
3233
3253
  });
@@ -3235,16 +3255,16 @@ async function handler$j(plugin, ctx, options) {
3235
3255
 
3236
3256
  var countCollectionEntities = /*#__PURE__*/Object.freeze({
3237
3257
  __proto__: null,
3238
- code: code$j,
3239
- handler: handler$j
3258
+ code: code$k,
3259
+ handler: handler$k
3240
3260
  });
3241
3261
 
3242
- const code$i = "createCollectionEntity";
3243
- async function handler$i(plugin, ctx, options) {
3262
+ const code$j = "createCollectionEntity";
3263
+ async function handler$j(plugin, ctx, options) {
3244
3264
  const { logger, server, input } = ctx;
3245
3265
  const { defaultInput, fixedInput } = options;
3246
3266
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
3247
- logger.debug(`Running ${code$i} handler...`, { defaultInput, fixedInput, mergedInput });
3267
+ logger.debug(`Running ${code$j} handler...`, { defaultInput, fixedInput, mergedInput });
3248
3268
  const userId = ctx.routerContext.state?.userId;
3249
3269
  if (userId) {
3250
3270
  input.createdBy = userId;
@@ -3258,15 +3278,15 @@ async function handler$i(plugin, ctx, options) {
3258
3278
 
3259
3279
  var createCollectionEntity = /*#__PURE__*/Object.freeze({
3260
3280
  __proto__: null,
3261
- code: code$i,
3262
- handler: handler$i
3281
+ code: code$j,
3282
+ handler: handler$j
3263
3283
  });
3264
3284
 
3265
- const code$h = "createCollectionEntitiesBatch";
3266
- async function handler$h(plugin, ctx, options) {
3285
+ const code$i = "createCollectionEntitiesBatch";
3286
+ async function handler$i(plugin, ctx, options) {
3267
3287
  const { logger, server, input } = ctx;
3268
3288
  const { defaultInput, fixedInput } = options;
3269
- logger.debug(`Running ${code$h} handler...`, { defaultInput, fixedInput, input });
3289
+ logger.debug(`Running ${code$i} handler...`, { defaultInput, fixedInput, input });
3270
3290
  const { entities } = input;
3271
3291
  if (!lodash.isArray(entities)) {
3272
3292
  throw new Error("input.entities should be an array.");
@@ -3289,16 +3309,16 @@ async function handler$h(plugin, ctx, options) {
3289
3309
 
3290
3310
  var createCollectionEntitiesBatch = /*#__PURE__*/Object.freeze({
3291
3311
  __proto__: null,
3292
- code: code$h,
3293
- handler: handler$h
3312
+ code: code$i,
3313
+ handler: handler$i
3294
3314
  });
3295
3315
 
3296
- const code$g = "updateCollectionEntityById";
3297
- async function handler$g(plugin, ctx, options) {
3316
+ const code$h = "updateCollectionEntityById";
3317
+ async function handler$h(plugin, ctx, options) {
3298
3318
  const { logger, server, input } = ctx;
3299
3319
  const { defaultInput, fixedInput } = options;
3300
3320
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
3301
- logger.debug(`Running ${code$g} handler...`, { defaultInput, fixedInput, mergedInput });
3321
+ logger.debug(`Running ${code$h} handler...`, { defaultInput, fixedInput, mergedInput });
3302
3322
  const operation = mergedInput.$operation;
3303
3323
  if (operation) {
3304
3324
  delete mergedInput.$operation;
@@ -3310,14 +3330,14 @@ async function handler$g(plugin, ctx, options) {
3310
3330
 
3311
3331
  var updateCollectionEntityById = /*#__PURE__*/Object.freeze({
3312
3332
  __proto__: null,
3313
- code: code$g,
3314
- handler: handler$g
3333
+ code: code$h,
3334
+ handler: handler$h
3315
3335
  });
3316
3336
 
3317
- const code$f = "deleteCollectionEntityById";
3318
- async function handler$f(plugin, ctx, options) {
3337
+ const code$g = "deleteCollectionEntityById";
3338
+ async function handler$g(plugin, ctx, options) {
3319
3339
  const { logger, server, input } = ctx;
3320
- logger.debug(`Running ${code$f} handler...`);
3340
+ logger.debug(`Running ${code$g} handler...`);
3321
3341
  const entityManager = server.getEntityManager(options.singularCode);
3322
3342
  await entityManager.deleteById(input.id, plugin);
3323
3343
  ctx.status = 200;
@@ -3326,16 +3346,16 @@ async function handler$f(plugin, ctx, options) {
3326
3346
 
3327
3347
  var deleteCollectionEntityById = /*#__PURE__*/Object.freeze({
3328
3348
  __proto__: null,
3329
- code: code$f,
3330
- handler: handler$f
3349
+ code: code$g,
3350
+ handler: handler$g
3331
3351
  });
3332
3352
 
3333
- const code$e = "addEntityRelations";
3334
- async function handler$e(plugin, ctx, options) {
3353
+ const code$f = "addEntityRelations";
3354
+ async function handler$f(plugin, ctx, options) {
3335
3355
  const { logger, server, input } = ctx;
3336
3356
  const { defaultInput, fixedInput } = options;
3337
3357
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
3338
- logger.debug(`Running ${code$e} handler...`, { defaultInput, fixedInput, mergedInput });
3358
+ logger.debug(`Running ${code$f} handler...`, { defaultInput, fixedInput, mergedInput });
3339
3359
  const entityManager = server.getEntityManager(options.singularCode);
3340
3360
  await entityManager.addRelations(mergedInput, plugin);
3341
3361
  ctx.output = {};
@@ -3343,16 +3363,16 @@ async function handler$e(plugin, ctx, options) {
3343
3363
 
3344
3364
  var addEntityRelations = /*#__PURE__*/Object.freeze({
3345
3365
  __proto__: null,
3346
- code: code$e,
3347
- handler: handler$e
3366
+ code: code$f,
3367
+ handler: handler$f
3348
3368
  });
3349
3369
 
3350
- const code$d = "removeEntityRelations";
3351
- async function handler$d(plugin, ctx, options) {
3370
+ const code$e = "removeEntityRelations";
3371
+ async function handler$e(plugin, ctx, options) {
3352
3372
  const { logger, server, input } = ctx;
3353
3373
  const { defaultInput, fixedInput } = options;
3354
3374
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
3355
- logger.debug(`Running ${code$d} handler...`, { defaultInput, fixedInput, mergedInput });
3375
+ logger.debug(`Running ${code$e} handler...`, { defaultInput, fixedInput, mergedInput });
3356
3376
  const entityManager = server.getEntityManager(options.singularCode);
3357
3377
  await entityManager.removeRelations(mergedInput, plugin);
3358
3378
  ctx.output = {};
@@ -3360,16 +3380,16 @@ async function handler$d(plugin, ctx, options) {
3360
3380
 
3361
3381
  var removeEntityRelations = /*#__PURE__*/Object.freeze({
3362
3382
  __proto__: null,
3363
- code: code$d,
3364
- handler: handler$d
3383
+ code: code$e,
3384
+ handler: handler$e
3365
3385
  });
3366
3386
 
3367
- const code$c = "queryDatabase";
3368
- async function handler$c(plugin, ctx, options) {
3387
+ const code$d = "queryDatabase";
3388
+ async function handler$d(plugin, ctx, options) {
3369
3389
  const { logger, server, input } = ctx;
3370
3390
  const { sql, querySingle, defaultInput, fixedInput } = options;
3371
3391
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
3372
- logger.debug(`Running ${code$c} handler...`, { defaultInput, fixedInput, mergedInput });
3392
+ logger.debug(`Running ${code$d} handler...`, { defaultInput, fixedInput, mergedInput });
3373
3393
  const result = await server.queryDatabaseObject(sql, mergedInput);
3374
3394
  if (querySingle) {
3375
3395
  ctx.output = lodash.first(result);
@@ -3381,8 +3401,8 @@ async function handler$c(plugin, ctx, options) {
3381
3401
 
3382
3402
  var queryDatabase = /*#__PURE__*/Object.freeze({
3383
3403
  __proto__: null,
3384
- code: code$c,
3385
- handler: handler$c
3404
+ code: code$d,
3405
+ handler: handler$d
3386
3406
  });
3387
3407
 
3388
3408
  /**
@@ -3553,17 +3573,17 @@ async function sendSourceResponse(proxyCtx, targetRes) {
3553
3573
  srcRes.body = targetRes.body;
3554
3574
  }
3555
3575
 
3556
- const code$b = "httpProxy";
3557
- async function handler$b(plugin, ctx, options) {
3576
+ const code$c = "httpProxy";
3577
+ async function handler$c(plugin, ctx, options) {
3558
3578
  const { logger } = ctx;
3559
- logger.debug(`Running ${code$b} handler...`);
3579
+ logger.debug(`Running ${code$c} handler...`);
3560
3580
  await doProxy(ctx.routerContext, options);
3561
3581
  }
3562
3582
 
3563
3583
  var httpProxy = /*#__PURE__*/Object.freeze({
3564
3584
  __proto__: null,
3565
- code: code$b,
3566
- handler: handler$b
3585
+ code: code$c,
3586
+ handler: handler$c
3567
3587
  });
3568
3588
 
3569
3589
  /**
@@ -3802,8 +3822,8 @@ async function generateSn$2(server, input) {
3802
3822
  return sequenceNumbers;
3803
3823
  }
3804
3824
 
3805
- const code$a = "generateSn";
3806
- async function handler$a(plugin, ctx, options) {
3825
+ const code$b = "generateSn";
3826
+ async function handler$b(plugin, ctx, options) {
3807
3827
  const { server, routerContext } = ctx;
3808
3828
  const input = ctx.input;
3809
3829
  if (options?.ruleCode) {
@@ -3820,11 +3840,11 @@ async function handler$a(plugin, ctx, options) {
3820
3840
 
3821
3841
  var generateSn$1 = /*#__PURE__*/Object.freeze({
3822
3842
  __proto__: null,
3823
- code: code$a,
3824
- handler: handler$a
3843
+ code: code$b,
3844
+ handler: handler$b
3825
3845
  });
3826
3846
 
3827
- var pluginActionHandlers$3 = [
3847
+ var pluginActionHandlers$4 = [
3828
3848
  generateSn$1,
3829
3849
  ];
3830
3850
 
@@ -3936,7 +3956,7 @@ var generateSn = {
3936
3956
  ],
3937
3957
  };
3938
3958
 
3939
- var pluginRoutes$3 = [
3959
+ var pluginRoutes$4 = [
3940
3960
  generateSn,
3941
3961
  ];
3942
3962
 
@@ -3960,7 +3980,7 @@ class SequencePlugin {
3960
3980
  return [];
3961
3981
  }
3962
3982
  async registerActionHandlers(server) {
3963
- for (const actionHandler of pluginActionHandlers$3) {
3983
+ for (const actionHandler of pluginActionHandlers$4) {
3964
3984
  server.registerActionHandler(this, actionHandler);
3965
3985
  }
3966
3986
  }
@@ -3968,7 +3988,7 @@ class SequencePlugin {
3968
3988
  server.appendApplicationConfig({ models: pluginModels$2 });
3969
3989
  }
3970
3990
  async configureRoutes(server, applicationConfig) {
3971
- server.appendApplicationConfig({ routes: pluginRoutes$3 });
3991
+ server.appendApplicationConfig({ routes: pluginRoutes$4 });
3972
3992
  }
3973
3993
  async onApplicationLoaded(server, applicationConfig) {
3974
3994
  const models = server.getApplicationConfig().models;
@@ -4210,8 +4230,8 @@ class WebhooksPlugin {
4210
4230
  }
4211
4231
  }
4212
4232
 
4213
- const code$9 = "changePassword";
4214
- async function handler$9(plugin, ctx, options) {
4233
+ const code$a = "changePassword";
4234
+ async function handler$a(plugin, ctx, options) {
4215
4235
  const { server, input, routerContext } = ctx;
4216
4236
  const { id, oldPassword, newPassword } = input;
4217
4237
  const userId = routerContext.state.userId;
@@ -4253,12 +4273,12 @@ async function handler$9(plugin, ctx, options) {
4253
4273
 
4254
4274
  var changePassword$1 = /*#__PURE__*/Object.freeze({
4255
4275
  __proto__: null,
4256
- code: code$9,
4257
- handler: handler$9
4276
+ code: code$a,
4277
+ handler: handler$a
4258
4278
  });
4259
4279
 
4260
- const code$8 = "createSession";
4261
- async function handler$8(plugin, ctx, options) {
4280
+ const code$9 = "createSession";
4281
+ async function handler$9(plugin, ctx, options) {
4262
4282
  const { server, input, routerContext } = ctx;
4263
4283
  const { response } = routerContext;
4264
4284
  const { account, password } = input;
@@ -4301,12 +4321,12 @@ async function handler$8(plugin, ctx, options) {
4301
4321
 
4302
4322
  var createSession = /*#__PURE__*/Object.freeze({
4303
4323
  __proto__: null,
4304
- code: code$8,
4305
- handler: handler$8
4324
+ code: code$9,
4325
+ handler: handler$9
4306
4326
  });
4307
4327
 
4308
- const code$7 = "deleteSession";
4309
- async function handler$7(plugin, ctx, options) {
4328
+ const code$8 = "deleteSession";
4329
+ async function handler$8(plugin, ctx, options) {
4310
4330
  const { server, input, routerContext } = ctx;
4311
4331
  const { response } = routerContext;
4312
4332
  setCookie(response.headers, {
@@ -4319,12 +4339,12 @@ async function handler$7(plugin, ctx, options) {
4319
4339
 
4320
4340
  var deleteSession = /*#__PURE__*/Object.freeze({
4321
4341
  __proto__: null,
4322
- code: code$7,
4323
- handler: handler$7
4342
+ code: code$8,
4343
+ handler: handler$8
4324
4344
  });
4325
4345
 
4326
- const code$6 = "getMyProfile";
4327
- async function handler$6(plugin, ctx, options) {
4346
+ const code$7 = "getMyProfile";
4347
+ async function handler$7(plugin, ctx, options) {
4328
4348
  const { server, input, routerContext } = ctx;
4329
4349
  const userId = routerContext.state.userId;
4330
4350
  if (!userId) {
@@ -4354,12 +4374,12 @@ async function handler$6(plugin, ctx, options) {
4354
4374
 
4355
4375
  var getMyProfile$2 = /*#__PURE__*/Object.freeze({
4356
4376
  __proto__: null,
4357
- code: code$6,
4358
- handler: handler$6
4377
+ code: code$7,
4378
+ handler: handler$7
4359
4379
  });
4360
4380
 
4361
- const code$5 = "resetPassword";
4362
- async function handler$5(plugin, ctx, options) {
4381
+ const code$6 = "resetPassword";
4382
+ async function handler$6(plugin, ctx, options) {
4363
4383
  const { server, input, routerContext } = ctx;
4364
4384
  const { userId, password } = input;
4365
4385
  const userDataAccessor = server.getDataAccessor({
@@ -4387,11 +4407,11 @@ async function handler$5(plugin, ctx, options) {
4387
4407
 
4388
4408
  var resetPassword$1 = /*#__PURE__*/Object.freeze({
4389
4409
  __proto__: null,
4390
- code: code$5,
4391
- handler: handler$5
4410
+ code: code$6,
4411
+ handler: handler$6
4392
4412
  });
4393
4413
 
4394
- var pluginActionHandlers$2 = [
4414
+ var pluginActionHandlers$3 = [
4395
4415
  changePassword$1,
4396
4416
  createSession,
4397
4417
  deleteSession,
@@ -4528,7 +4548,7 @@ var signout$1 = {
4528
4548
  ],
4529
4549
  };
4530
4550
 
4531
- var pluginRoutes$2 = [
4551
+ var pluginRoutes$3 = [
4532
4552
  changePassword,
4533
4553
  getMyProfile$1,
4534
4554
  resetPassword,
@@ -4556,7 +4576,7 @@ class AuthPlugin {
4556
4576
  return [];
4557
4577
  }
4558
4578
  async registerActionHandlers(server) {
4559
- for (const actionHandler of pluginActionHandlers$2) {
4579
+ for (const actionHandler of pluginActionHandlers$3) {
4560
4580
  server.registerActionHandler(this, actionHandler);
4561
4581
  }
4562
4582
  }
@@ -4564,7 +4584,7 @@ class AuthPlugin {
4564
4584
  server.appendApplicationConfig({ models: pluginModels$1 });
4565
4585
  }
4566
4586
  async configureRoutes(server, applicationConfig) {
4567
- server.appendApplicationConfig({ routes: pluginRoutes$2 });
4587
+ server.appendApplicationConfig({ routes: pluginRoutes$3 });
4568
4588
  }
4569
4589
  async onPrepareRouteContext(server, routeContext) {
4570
4590
  const request = routeContext.request;
@@ -4620,8 +4640,8 @@ async function appendFile(path, data) {
4620
4640
  });
4621
4641
  }
4622
4642
 
4623
- const code$4 = "downloadDocument";
4624
- async function handler$4(plugin, ctx, options) {
4643
+ const code$5 = "downloadDocument";
4644
+ async function handler$5(plugin, ctx, options) {
4625
4645
  const { server, applicationConfig, routerContext, input } = ctx;
4626
4646
  const { request, response } = routerContext;
4627
4647
  const documentDataAccessor = ctx.server.getDataAccessor({
@@ -4649,12 +4669,12 @@ async function handler$4(plugin, ctx, options) {
4649
4669
 
4650
4670
  var downloadDocumentActionHandler = /*#__PURE__*/Object.freeze({
4651
4671
  __proto__: null,
4652
- code: code$4,
4653
- handler: handler$4
4672
+ code: code$5,
4673
+ handler: handler$5
4654
4674
  });
4655
4675
 
4656
- const code$3 = "downloadFile";
4657
- async function handler$3(plugin, ctx, options) {
4676
+ const code$4 = "downloadFile";
4677
+ async function handler$4(plugin, ctx, options) {
4658
4678
  const { server, applicationConfig, routerContext, input } = ctx;
4659
4679
  const { request, response } = routerContext;
4660
4680
  const dataAccessor = ctx.server.getDataAccessor({
@@ -4674,12 +4694,12 @@ async function handler$3(plugin, ctx, options) {
4674
4694
 
4675
4695
  var downloadFileActionHandler = /*#__PURE__*/Object.freeze({
4676
4696
  __proto__: null,
4677
- code: code$3,
4678
- handler: handler$3
4697
+ code: code$4,
4698
+ handler: handler$4
4679
4699
  });
4680
4700
 
4681
- const code$2 = "uploadFile";
4682
- async function handler$2(plugin, ctx, options) {
4701
+ const code$3 = "uploadFile";
4702
+ async function handler$3(plugin, ctx, options) {
4683
4703
  const { server, applicationConfig, routerContext, input } = ctx;
4684
4704
  let file = input.file || input.files;
4685
4705
  if (lodash.isArray(file)) {
@@ -4700,8 +4720,8 @@ async function handler$2(plugin, ctx, options) {
4700
4720
 
4701
4721
  var uploadFileActionHandler = /*#__PURE__*/Object.freeze({
4702
4722
  __proto__: null,
4703
- code: code$2,
4704
- handler: handler$2
4723
+ code: code$3,
4724
+ handler: handler$3
4705
4725
  });
4706
4726
 
4707
4727
  var getMyProfile = {
@@ -4746,7 +4766,7 @@ var signout = {
4746
4766
  ],
4747
4767
  };
4748
4768
 
4749
- var pluginRoutes$1 = [
4769
+ var pluginRoutes$2 = [
4750
4770
  getMyProfile,
4751
4771
  signin,
4752
4772
  signout,
@@ -4777,23 +4797,23 @@ class FileManager {
4777
4797
  server.registerActionHandler(this, uploadFileActionHandler);
4778
4798
  }
4779
4799
  async configureRoutes(server, applicationConfig) {
4780
- server.appendApplicationConfig({ routes: pluginRoutes$1 });
4800
+ server.appendApplicationConfig({ routes: pluginRoutes$2 });
4781
4801
  }
4782
4802
  }
4783
4803
 
4784
- const code$1 = "runServerOperation";
4785
- async function handler$1(plugin, ctx, options) {
4804
+ const code$2 = "runServerOperation";
4805
+ async function handler$2(plugin, ctx, options) {
4786
4806
  const { operation } = options;
4787
4807
  await operation(ctx);
4788
4808
  }
4789
4809
 
4790
4810
  var runServerOperation = /*#__PURE__*/Object.freeze({
4791
4811
  __proto__: null,
4792
- code: code$1,
4793
- handler: handler$1
4812
+ code: code$2,
4813
+ handler: handler$2
4794
4814
  });
4795
4815
 
4796
- var pluginActionHandlers$1 = [
4816
+ var pluginActionHandlers$2 = [
4797
4817
  runServerOperation,
4798
4818
  ];
4799
4819
 
@@ -4822,7 +4842,7 @@ class ServerOperationPlugin {
4822
4842
  async registerMiddlewares(server) {
4823
4843
  }
4824
4844
  async registerActionHandlers(server) {
4825
- for (const actionHandler of pluginActionHandlers$1) {
4845
+ for (const actionHandler of pluginActionHandlers$2) {
4826
4846
  server.registerActionHandler(this, actionHandler);
4827
4847
  }
4828
4848
  }
@@ -4866,6 +4886,137 @@ class ServerOperationPlugin {
4866
4886
  }
4867
4887
  }
4868
4888
 
4889
+ const code$1 = "runCronJob";
4890
+ async function handler$1(plugin, ctx, options) {
4891
+ const { server, routerContext } = ctx;
4892
+ const { response } = routerContext;
4893
+ const input = ctx.input;
4894
+ if (options.code) {
4895
+ input.code = options.code;
4896
+ }
4897
+ if (!input.code) {
4898
+ throw new Error(`Cron job code is required.`);
4899
+ }
4900
+ const job = plugin.getJobConfigurationByCode(input.code);
4901
+ if (!job) {
4902
+ throw new Error(`Cron job with code '${input.code}' was not found.`);
4903
+ }
4904
+ await plugin.executeJob(server, job);
4905
+ response.json({});
4906
+ }
4907
+
4908
+ var runCronJob$1 = /*#__PURE__*/Object.freeze({
4909
+ __proto__: null,
4910
+ code: code$1,
4911
+ handler: handler$1
4912
+ });
4913
+
4914
+ var pluginActionHandlers$1 = [
4915
+ runCronJob$1,
4916
+ ];
4917
+
4918
+ var runCronJob = {
4919
+ namespace: "svc",
4920
+ name: "svc.runCronJob",
4921
+ code: "svc.runCronJob",
4922
+ type: "RESTful",
4923
+ method: "POST",
4924
+ endpoint: "/svc/runCronJob",
4925
+ actions: [
4926
+ {
4927
+ code: "runCronJob",
4928
+ },
4929
+ ],
4930
+ };
4931
+
4932
+ var pluginRoutes$1 = [
4933
+ runCronJob,
4934
+ ];
4935
+
4936
+ class CronJobPlugin {
4937
+ #jobs;
4938
+ constructor(options) {
4939
+ this.#jobs = options.jobs || [];
4940
+ }
4941
+ get code() {
4942
+ return "cronJob";
4943
+ }
4944
+ get description() {
4945
+ return "";
4946
+ }
4947
+ get extendingAbilities() {
4948
+ return [];
4949
+ }
4950
+ get configurableTargets() {
4951
+ return [];
4952
+ }
4953
+ get configurations() {
4954
+ return [];
4955
+ }
4956
+ async initPlugin(server) {
4957
+ }
4958
+ async registerMiddlewares(server) {
4959
+ }
4960
+ async registerActionHandlers(server) {
4961
+ for (const actionHandler of pluginActionHandlers$1) {
4962
+ server.registerActionHandler(this, actionHandler);
4963
+ }
4964
+ }
4965
+ async registerEventHandlers(server) {
4966
+ }
4967
+ async registerMessageHandlers(server) {
4968
+ }
4969
+ async registerTaskProcessors(server) {
4970
+ }
4971
+ async onLoadingApplication(server, applicationConfig) {
4972
+ }
4973
+ async configureModels(server, applicationConfig) {
4974
+ }
4975
+ async configureModelProperties(server, applicationConfig) {
4976
+ }
4977
+ async configureRoutes(server, applicationConfig) {
4978
+ server.appendApplicationConfig({ routes: pluginRoutes$1 });
4979
+ }
4980
+ async onApplicationLoaded(server, applicationConfig) {
4981
+ }
4982
+ async onApplicationReady(server, applicationConfig) {
4983
+ for (const job of this.#jobs) {
4984
+ cron__namespace.CronJob.from({
4985
+ cronTime: job.cronTime,
4986
+ onTick: async () => {
4987
+ await this.executeJob(server, job);
4988
+ },
4989
+ });
4990
+ }
4991
+ }
4992
+ getJobConfigurationByCode(code) {
4993
+ return lodash.find(this.#jobs, (job) => job.code === code);
4994
+ }
4995
+ async executeJob(server, job) {
4996
+ const logger = server.getLogger();
4997
+ try {
4998
+ let handlerContext = {
4999
+ logger,
5000
+ routerContext: null,
5001
+ next: null,
5002
+ server,
5003
+ applicationConfig: null,
5004
+ input: null,
5005
+ };
5006
+ if (job.actionHandlerCode) {
5007
+ const actionHandler = server.getActionHandlerByCode(job.code);
5008
+ await actionHandler(handlerContext, job.handleOptions);
5009
+ }
5010
+ else {
5011
+ await job.handler(handlerContext, job.handleOptions);
5012
+ }
5013
+ }
5014
+ catch (ex) {
5015
+ logger.error("Cron job execution error: " + ex.message);
5016
+ }
5017
+ }
5018
+ }
5019
+
4869
5020
  async function getStateMachineNextSnapshot(server, options) {
4870
5021
  debugger;
4871
5022
  const { machineConfig, currentState, event } = options;
@@ -5311,6 +5462,7 @@ class EntityAccessControlPlugin {
5311
5462
  fixBigIntJSONSerialize();
5312
5463
 
5313
5464
  exports.AuthPlugin = AuthPlugin;
5465
+ exports.CronJobPlugin = CronJobPlugin;
5314
5466
  exports.DataManagePlugin = DataManager;
5315
5467
  exports.EntityAccessControlPlugin = EntityAccessControlPlugin;
5316
5468
  exports.EntityWatchPlugin = EntityWatchPlugin;
@@ -0,0 +1,27 @@
1
+ import type { RpdApplicationConfig } from "../../types";
2
+ import { CronJobConfiguration, CronJobPluginInitOptions } from "./CronJobPluginTypes";
3
+ import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "../../core/server";
4
+ declare class CronJobPlugin implements RapidPlugin {
5
+ #private;
6
+ constructor(options: CronJobPluginInitOptions);
7
+ get code(): string;
8
+ get description(): string;
9
+ get extendingAbilities(): RpdServerPluginExtendingAbilities[];
10
+ get configurableTargets(): RpdServerPluginConfigurableTargetOptions[];
11
+ get configurations(): RpdConfigurationItemOptions[];
12
+ initPlugin(server: IRpdServer): Promise<any>;
13
+ registerMiddlewares(server: IRpdServer): Promise<any>;
14
+ registerActionHandlers(server: IRpdServer): Promise<any>;
15
+ registerEventHandlers(server: IRpdServer): Promise<any>;
16
+ registerMessageHandlers(server: IRpdServer): Promise<any>;
17
+ registerTaskProcessors(server: IRpdServer): Promise<any>;
18
+ onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
19
+ configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
20
+ configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
21
+ configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
22
+ onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
23
+ onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
24
+ getJobConfigurationByCode(code: string): CronJobConfiguration;
25
+ executeJob(server: IRpdServer, job: CronJobConfiguration): Promise<void>;
26
+ }
27
+ export default CronJobPlugin;
@@ -0,0 +1,39 @@
1
+ import { ActionHandlerContext } from "../../core/actionHandler";
2
+ export interface CronJobConfiguration {
3
+ /**
4
+ * 定时任务编号
5
+ */
6
+ code: string;
7
+ /**
8
+ * 定时任务描述
9
+ */
10
+ description?: string;
11
+ /**
12
+ * crontab 表达式
13
+ */
14
+ cronTime: string;
15
+ /**
16
+ * 任务处理程序编号。当指定处理程序编号时,忽略 handler 配置。
17
+ */
18
+ actionHandlerCode?: string;
19
+ /**
20
+ * 定时任务处理程序
21
+ * @param ctx
22
+ * @param options
23
+ * @returns
24
+ */
25
+ handler?: (ctx: ActionHandlerContext, options: any) => Promise<void>;
26
+ /**
27
+ * 处理定时任务时的设置选项
28
+ */
29
+ handleOptions?: any;
30
+ }
31
+ export interface CronJobPluginInitOptions {
32
+ jobs: CronJobConfiguration[];
33
+ }
34
+ export type RunCronJobActionHandlerOptions = {
35
+ code?: string;
36
+ };
37
+ export type RunCronJobInput = {
38
+ code?: string;
39
+ };
@@ -0,0 +1,3 @@
1
+ import * as runCronJob from "./runCronJob";
2
+ declare const _default: (typeof runCronJob)[];
3
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RunCronJobActionHandlerOptions } from "../CronJobPluginTypes";
3
+ import type CronJobPlugin from "../CronJobPlugin";
4
+ export declare const code = "runCronJob";
5
+ export declare function handler(plugin: CronJobPlugin, ctx: ActionHandlerContext, options: RunCronJobActionHandlerOptions): Promise<void>;
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ namespace: string;
3
+ name: string;
4
+ code: string;
5
+ type: "RESTful";
6
+ method: "POST";
7
+ endpoint: string;
8
+ actions: {
9
+ code: string;
10
+ }[];
11
+ }[];
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ namespace: string;
3
+ name: string;
4
+ code: string;
5
+ type: "RESTful";
6
+ method: "POST";
7
+ endpoint: string;
8
+ actions: {
9
+ code: string;
10
+ }[];
11
+ };
12
+ export default _default;
@@ -1,5 +1,5 @@
1
1
  import { IRpdServer } from "../../core/server";
2
- import { SequenceSegmentConfig } from "../../types";
2
+ import { SequenceSegmentConfig } from "./SequencePluginTypes";
3
3
  export interface GenerateSequenceNumbersInput {
4
4
  ruleCode: string;
5
5
  parameters: Record<string, string>;
@@ -1,5 +1,5 @@
1
- import { SequenceAutoIncrementSegmentConfig } from "../../../types";
2
1
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
2
  import { IRpdServer } from "../../../core/server";
3
+ import { SequenceAutoIncrementSegmentConfig } from "../SequencePluginTypes";
4
4
  export declare const segmentType = "autoIncrement";
5
5
  export declare function resolveSegmentValue(server: IRpdServer, ruleCode: string, config: SequenceAutoIncrementSegmentConfig, input: GenerateSequenceNumbersInput): Promise<string>;
@@ -1,4 +1,4 @@
1
- import { SequenceDayOfMonthSegmentConfig } from "../../../types";
1
+ import { SequenceDayOfMonthSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { IRpdServer } from "../../../core/server";
4
4
  export declare const segmentType = "dayOfMonth";
@@ -1,4 +1,4 @@
1
- import { SequenceLiteralSegmentConfig } from "../../../types";
1
+ import { SequenceLiteralSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { IRpdServer } from "../../../core/server";
4
4
  export declare const segmentType = "literal";
@@ -1,4 +1,4 @@
1
- import { SequenceMonthSegmentConfig } from "../../../types";
1
+ import { SequenceMonthSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { IRpdServer } from "../../../core/server";
4
4
  export declare const segmentType = "month";
@@ -1,4 +1,4 @@
1
- import { SequenceParameterSegmentConfig } from "../../../types";
1
+ import { SequenceParameterSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { IRpdServer } from "../../../core/server";
4
4
  export declare const segmentType = "parameter";
@@ -1,4 +1,4 @@
1
- import { SequenceYearSegmentConfig } from "../../../types";
1
+ import { SequenceYearSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { IRpdServer } from "../../../core/server";
4
4
  export declare const segmentType = "year";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "bcrypt": "^5.1.1",
22
+ "cron": "^3.1.7",
22
23
  "dayjs": "^1.11.7",
23
24
  "jsonwebtoken": "^9.0.2",
24
25
  "koa-tree-router": "^0.12.1",
package/src/index.ts CHANGED
@@ -32,6 +32,9 @@ export { default as FileManagePlugin } from "./plugins/fileManage/FileManagePlug
32
32
  export { default as ServerOperationPlugin } from "./plugins/serverOperation/ServerOperationPlugin";
33
33
  export * from "./plugins/serverOperation/ServerOperationPluginTypes";
34
34
 
35
+ export { default as CronJobPlugin } from "./plugins/cronJob/CronJobPlugin";
36
+ export * from "./plugins/cronJob/CronJobPluginTypes";
37
+
35
38
  export { default as StateMachinePlugin } from "./plugins/stateMachine/StateMachinePlugin";
36
39
  export * from "./plugins/stateMachine/StateMachinePluginTypes";
37
40
 
@@ -0,0 +1,113 @@
1
+ import * as cron from 'cron';
2
+ import type { RpdApplicationConfig } from "~/types";
3
+ import pluginActionHandlers from "./actionHandlers";
4
+ import pluginRoutes from "./routes";
5
+ import { CronJobConfiguration, CronJobPluginInitOptions } from "./CronJobPluginTypes";
6
+ import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
7
+ import { ActionHandlerContext } from '~/core/actionHandler';
8
+ import { find } from 'lodash';
9
+
10
+ class CronJobPlugin implements RapidPlugin {
11
+ #jobs: CronJobConfiguration[];
12
+
13
+ constructor(options: CronJobPluginInitOptions) {
14
+ this.#jobs = options.jobs || [];
15
+ }
16
+
17
+ get code(): string {
18
+ return "cronJob";
19
+ }
20
+
21
+ get description(): string {
22
+ return "";
23
+ }
24
+
25
+ get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
26
+ return [];
27
+ }
28
+
29
+ get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
30
+ return [];
31
+ }
32
+
33
+ get configurations(): RpdConfigurationItemOptions[] {
34
+ return [];
35
+ }
36
+
37
+ async initPlugin(server: IRpdServer): Promise<any> {
38
+ }
39
+
40
+ async registerMiddlewares(server: IRpdServer): Promise<any> {
41
+ }
42
+
43
+ async registerActionHandlers(server: IRpdServer): Promise<any> {
44
+ for (const actionHandler of pluginActionHandlers) {
45
+ server.registerActionHandler(this, actionHandler);
46
+ }
47
+ }
48
+
49
+ async registerEventHandlers(server: IRpdServer): Promise<any> {
50
+ }
51
+
52
+ async registerMessageHandlers(server: IRpdServer): Promise<any> {
53
+ }
54
+
55
+ async registerTaskProcessors(server: IRpdServer): Promise<any> {
56
+ }
57
+
58
+ async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
59
+ }
60
+
61
+ async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
62
+ }
63
+
64
+ async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
65
+ }
66
+
67
+ async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
68
+ server.appendApplicationConfig({ routes: pluginRoutes });
69
+ }
70
+
71
+ async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
72
+ }
73
+
74
+ async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
75
+ for (const job of this.#jobs) {
76
+ const jobInstance = cron.CronJob.from({
77
+ cronTime: job.cronTime,
78
+ onTick: async () => {
79
+ await this.executeJob(server, job);
80
+ },
81
+ });
82
+ }
83
+ }
84
+
85
+ getJobConfigurationByCode(code: string) {
86
+ return find(this.#jobs, (job) => job.code === code);
87
+ }
88
+
89
+ async executeJob(server: IRpdServer, job: CronJobConfiguration) {
90
+ const logger = server.getLogger();
91
+ try {
92
+ let handlerContext: ActionHandlerContext = {
93
+ logger,
94
+ routerContext: null,
95
+ next: null,
96
+ server,
97
+ applicationConfig: null,
98
+ input: null,
99
+ };
100
+
101
+ if (job.actionHandlerCode) {
102
+ const actionHandler = server.getActionHandlerByCode(job.code);
103
+ await actionHandler(handlerContext, job.handleOptions);
104
+ } else {
105
+ await job.handler(handlerContext, job.handleOptions);
106
+ }
107
+ } catch (ex) {
108
+ logger.error("Cron job execution error: " + ex.message);
109
+ }
110
+ }
111
+ }
112
+
113
+ export default CronJobPlugin;
@@ -0,0 +1,49 @@
1
+ import { ActionHandlerContext } from "~/core/actionHandler";
2
+ import { RpdHttpMethod } from "~/types";
3
+
4
+ export interface CronJobConfiguration {
5
+ /**
6
+ * 定时任务编号
7
+ */
8
+ code: string;
9
+
10
+ /**
11
+ * 定时任务描述
12
+ */
13
+ description?: string;
14
+
15
+ /**
16
+ * crontab 表达式
17
+ */
18
+ cronTime: string;
19
+
20
+ /**
21
+ * 任务处理程序编号。当指定处理程序编号时,忽略 handler 配置。
22
+ */
23
+ actionHandlerCode?: string;
24
+
25
+ /**
26
+ * 定时任务处理程序
27
+ * @param ctx
28
+ * @param options
29
+ * @returns
30
+ */
31
+ handler?: (ctx: ActionHandlerContext, options: any) => Promise<void>;
32
+
33
+ /**
34
+ * 处理定时任务时的设置选项
35
+ */
36
+ handleOptions?: any;
37
+ }
38
+
39
+ export interface CronJobPluginInitOptions {
40
+ jobs: CronJobConfiguration[];
41
+ }
42
+
43
+ export type RunCronJobActionHandlerOptions = {
44
+ code?: string;
45
+ }
46
+
47
+ export type RunCronJobInput = {
48
+ code?: string;
49
+ }
@@ -0,0 +1,6 @@
1
+ import { IPluginActionHandler } from "~/core/actionHandler";
2
+ import * as runCronJob from "./runCronJob";
3
+
4
+ export default [
5
+ runCronJob,
6
+ ] satisfies IPluginActionHandler[];
@@ -0,0 +1,34 @@
1
+ import { ActionHandlerContext } from "~/core/actionHandler";
2
+ import { RunCronJobActionHandlerOptions, RunCronJobInput } from "../CronJobPluginTypes";
3
+ import type CronJobPlugin from "../CronJobPlugin";
4
+
5
+ export const code = "runCronJob";
6
+
7
+ export async function handler(
8
+ plugin: CronJobPlugin,
9
+ ctx: ActionHandlerContext,
10
+ options: RunCronJobActionHandlerOptions,
11
+ ) {
12
+ const { server, routerContext } = ctx;
13
+ const { response } = routerContext;
14
+
15
+ const input: RunCronJobInput = ctx.input;
16
+
17
+ if (options.code) {
18
+ input.code = options.code;
19
+ }
20
+
21
+ if (!input.code) {
22
+ throw new Error(`Cron job code is required.`);
23
+ }
24
+
25
+ const job = plugin.getJobConfigurationByCode(input.code);
26
+ if (!job) {
27
+ throw new Error(`Cron job with code '${input.code}' was not found.`);
28
+ }
29
+
30
+ await plugin.executeJob(server, job);
31
+
32
+ response.json({
33
+ });
34
+ }
@@ -0,0 +1,5 @@
1
+ import runCronJob from "./runCronJob";
2
+
3
+ export default [
4
+ runCronJob,
5
+ ]
@@ -0,0 +1,15 @@
1
+ import { RpdRoute } from "~/types";
2
+
3
+ export default {
4
+ namespace: "svc",
5
+ name: "svc.runCronJob",
6
+ code: "svc.runCronJob",
7
+ type: "RESTful",
8
+ method: "POST",
9
+ endpoint: "/svc/runCronJob",
10
+ actions: [
11
+ {
12
+ code: "runCronJob",
13
+ },
14
+ ],
15
+ } satisfies RpdRoute;
@@ -1,8 +1,7 @@
1
1
  import { IRpdServer } from "~/core/server";
2
- import { SequenceSegmentConfig } from "~/types";
3
2
  import segmentResolvers from "./segments";
4
3
  import { find } from "lodash";
5
- import { SequenceRuleConfig } from "./SequencePluginTypes";
4
+ import { SequenceRuleConfig, SequenceSegmentConfig } from "./SequencePluginTypes";
6
5
 
7
6
  export interface GenerateSequenceNumbersInput {
8
7
  ruleCode: string;
@@ -1,9 +1,9 @@
1
- import { SequenceAutoIncrementSegmentConfig } from "~/types";
2
1
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
2
  import { padSegment } from "../segment-utility";
4
3
  import { IRpdServer } from "~/core/server";
5
4
  import { get } from "lodash";
6
5
  import dayjs from "dayjs";
6
+ import { SequenceAutoIncrementSegmentConfig } from "../SequencePluginTypes";
7
7
 
8
8
  export const segmentType = "autoIncrement";
9
9
 
@@ -1,4 +1,4 @@
1
- import { SequenceDayOfMonthSegmentConfig } from "~/types";
1
+ import { SequenceDayOfMonthSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { padSegment } from "../segment-utility";
4
4
  import { IRpdServer } from "~/core/server";
@@ -1,4 +1,4 @@
1
- import { SequenceLiteralSegmentConfig } from "~/types";
1
+ import { SequenceLiteralSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { IRpdServer } from "~/core/server";
4
4
 
@@ -1,4 +1,4 @@
1
- import { SequenceMonthSegmentConfig } from "~/types";
1
+ import { SequenceMonthSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { padSegment } from "../segment-utility";
4
4
  import { IRpdServer } from "~/core/server";
@@ -1,4 +1,4 @@
1
- import { SequenceParameterSegmentConfig } from "~/types";
1
+ import { SequenceParameterSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { padSegment } from "../segment-utility";
4
4
  import { get } from "lodash";
@@ -1,4 +1,4 @@
1
- import { SequenceYearSegmentConfig } from "~/types";
1
+ import { SequenceYearSegmentConfig } from "../SequencePluginTypes";
2
2
  import { GenerateSequenceNumbersInput } from "../SequenceService";
3
3
  import { padSegment } from "../segment-utility";
4
4
  import { IRpdServer } from "~/core/server";