@ruiapp/rapid-core 0.11.0 → 0.11.1

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,11 @@
1
+ import { ActionHandlerContext, IPluginActionHandler } from "../../core/actionHandler";
2
+ import { RpdRouteActionConfig } from "../../types";
3
+ export declare const code = "if";
4
+ export type IfActionHandlerConfig = {
5
+ condition: string;
6
+ then: RpdRouteActionConfig[];
7
+ otherwise: RpdRouteActionConfig[];
8
+ };
9
+ export declare function handler(_plugin: any, ctx: ActionHandlerContext, options: IfActionHandlerConfig): Promise<void>;
10
+ declare const _default: IPluginActionHandler;
11
+ export default _default;
package/dist/index.js CHANGED
@@ -4504,9 +4504,9 @@ var healthz = {
4504
4504
  type: "RESTful",
4505
4505
  method: "GET",
4506
4506
  endpoint: "/healthz",
4507
- handler: handler$y,
4507
+ handler: handler$z,
4508
4508
  };
4509
- async function handler$y(ctx) {
4509
+ async function handler$z(ctx) {
4510
4510
  ctx.output = {};
4511
4511
  }
4512
4512
 
@@ -4549,6 +4549,19 @@ function interpreteConfigExpressions(config, vars) {
4549
4549
  }
4550
4550
  }
4551
4551
 
4552
+ const code$y = "if";
4553
+ async function handler$y(_plugin, ctx, options) {
4554
+ const { server, input, routerContext: routeContext } = ctx;
4555
+ const { condition, then, otherwise } = options;
4556
+ const conditionResult = interpreteExpression(condition, ctx.vars);
4557
+ const actions = conditionResult ? then : otherwise;
4558
+ if (!actions || !actions.length) {
4559
+ return;
4560
+ }
4561
+ await server.runActionHandlers(ctx, actions);
4562
+ }
4563
+ var ifActionHandler = { code: code$y, handler: handler$y };
4564
+
4552
4565
  class RapidServer {
4553
4566
  #logger;
4554
4567
  #facilityFactories;
@@ -4785,6 +4798,8 @@ class RapidServer {
4785
4798
  }
4786
4799
  async start() {
4787
4800
  this.#logger.info("Starting rapid server...");
4801
+ // register core action handlers
4802
+ this.registerActionHandler(null, ifActionHandler);
4788
4803
  const pluginManager = this.#pluginManager;
4789
4804
  await pluginManager.loadPlugins(this.#plugins);
4790
4805
  await pluginManager.initPlugins();
@@ -4916,7 +4931,7 @@ class RapidServer {
4916
4931
  return response.getResponse();
4917
4932
  }
4918
4933
  async runActionHandlers(handlerContext, actions) {
4919
- if (!actions) {
4934
+ if (!actions || !actions.length) {
4920
4935
  return;
4921
4936
  }
4922
4937
  for (const action of actions) {
@@ -4927,8 +4942,7 @@ class RapidServer {
4927
4942
  throw new Error("Unknown handler: " + actionCode);
4928
4943
  }
4929
4944
  await this.beforeRunActionHandler(handlerContext, action);
4930
- const result = await handler(handlerContext, action.config);
4931
- handlerContext.results.push(result);
4945
+ await handler(handlerContext, action.config);
4932
4946
  }
4933
4947
  }
4934
4948
  async beforeRunRouteActions(handlerContext) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,27 @@
1
+ import { ActionHandler, ActionHandlerContext, IPluginActionHandler } from "~/core/actionHandler";
2
+ import { generatePasswordHash, validatePassword } from "~/utilities/passwordUtility";
3
+ import { interpreteConfigExpressions, interpreteExpression } from "../ExpressionInterpreter";
4
+ import { RpdRouteActionConfig } from "~/types";
5
+
6
+ export const code = "if";
7
+
8
+ export type IfActionHandlerConfig = {
9
+ condition: string;
10
+ then: RpdRouteActionConfig[];
11
+ otherwise: RpdRouteActionConfig[];
12
+ };
13
+
14
+ export async function handler(_plugin: any, ctx: ActionHandlerContext, options: IfActionHandlerConfig) {
15
+ const { server, input, routerContext: routeContext } = ctx;
16
+ const { response } = routeContext;
17
+ const { condition, then, otherwise } = options;
18
+
19
+ const conditionResult = interpreteExpression(condition, ctx.vars);
20
+ const actions: RpdRouteActionConfig[] = conditionResult ? then : otherwise;
21
+ if (!actions || !actions.length) {
22
+ return;
23
+ }
24
+ await server.runActionHandlers(ctx, actions);
25
+ }
26
+
27
+ export default { code, handler } as IPluginActionHandler;
package/src/server.ts CHANGED
@@ -38,6 +38,7 @@ import { FacilityFactory } from "./core/facility";
38
38
  import { CronJobConfiguration } from "./types/cron-job-types";
39
39
  import coreRoutes from "./core/routes";
40
40
  import { interpreteConfigExpressions } from "./core/ExpressionInterpreter";
41
+ import ifActionHandler from "./core/actionHandlers/ifActionHandler";
41
42
 
42
43
  export interface InitServerOptions {
43
44
  logger: Logger;
@@ -336,6 +337,10 @@ export class RapidServer implements IRpdServer {
336
337
 
337
338
  async start() {
338
339
  this.#logger.info("Starting rapid server...");
340
+
341
+ // register core action handlers
342
+ this.registerActionHandler(null, ifActionHandler);
343
+
339
344
  const pluginManager = this.#pluginManager;
340
345
  await pluginManager.loadPlugins(this.#plugins);
341
346
 
@@ -477,9 +482,10 @@ export class RapidServer implements IRpdServer {
477
482
  }
478
483
 
479
484
  async runActionHandlers(handlerContext: ActionHandlerContext, actions: RpdRouteActionConfig[]) {
480
- if (!actions) {
485
+ if (!actions || !actions.length) {
481
486
  return;
482
487
  }
488
+
483
489
  for (const action of actions) {
484
490
  const actionCode = action.code;
485
491
  interpreteConfigExpressions(action.config, handlerContext.vars);
@@ -490,9 +496,7 @@ export class RapidServer implements IRpdServer {
490
496
  }
491
497
 
492
498
  await this.beforeRunActionHandler(handlerContext, action);
493
-
494
- const result = await handler(handlerContext, action.config);
495
- handlerContext.results.push(result);
499
+ await handler(handlerContext, action.config);
496
500
  }
497
501
  }
498
502