@ruiapp/rapid-core 0.1.7 → 0.1.9

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 (63) hide show
  1. package/dist/core/actionHandler.d.ts +1 -1
  2. package/dist/core/eventManager.d.ts +1 -1
  3. package/dist/core/pluginManager.d.ts +8 -8
  4. package/dist/core/routesBuilder.d.ts +2 -2
  5. package/dist/core/server.d.ts +3 -1
  6. package/dist/dataAccess/dataAccessor.d.ts +2 -2
  7. package/dist/dataAccess/entityManager.d.ts +14 -6
  8. package/dist/dataAccess/entityMapper.d.ts +1 -1
  9. package/dist/dataAccess/filterHelper.d.ts +1 -1
  10. package/dist/dataAccess/propertyMapper.d.ts +1 -1
  11. package/dist/helpers/runCollectionEntityActionHandler.d.ts +5 -4
  12. package/dist/index.js +667 -622
  13. package/dist/plugins/auth/AuthPlugin.d.ts +3 -3
  14. package/dist/plugins/auth/actionHandlers/createSession.d.ts +2 -2
  15. package/dist/plugins/auth/actionHandlers/deleteSession.d.ts +2 -2
  16. package/dist/plugins/auth/actionHandlers/getMyProfile.d.ts +2 -2
  17. package/dist/plugins/auth/models/AccessToken.d.ts +1 -1
  18. package/dist/plugins/dataManage/DataManagePlugin.d.ts +2 -2
  19. package/dist/plugins/dataManage/actionHandlers/addEntityRelations.d.ts +3 -3
  20. package/dist/plugins/dataManage/actionHandlers/countCollectionEntities.d.ts +3 -3
  21. package/dist/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.d.ts +3 -3
  22. package/dist/plugins/dataManage/actionHandlers/createCollectionEntity.d.ts +3 -3
  23. package/dist/plugins/dataManage/actionHandlers/deleteCollectionEntityById.d.ts +3 -3
  24. package/dist/plugins/dataManage/actionHandlers/findCollectionEntities.d.ts +3 -3
  25. package/dist/plugins/dataManage/actionHandlers/findCollectionEntityById.d.ts +3 -3
  26. package/dist/plugins/dataManage/actionHandlers/queryDatabase.d.ts +3 -3
  27. package/dist/plugins/dataManage/actionHandlers/removeEntityRelations.d.ts +3 -3
  28. package/dist/plugins/dataManage/actionHandlers/updateCollectionEntityById.d.ts +3 -3
  29. package/dist/plugins/fileManage/FileManagePlugin.d.ts +2 -2
  30. package/dist/plugins/fileManage/actionHandlers/downloadDocument.d.ts +2 -2
  31. package/dist/plugins/fileManage/actionHandlers/downloadFile.d.ts +2 -2
  32. package/dist/plugins/fileManage/actionHandlers/uploadFile.d.ts +2 -2
  33. package/dist/plugins/metaManage/MetaManagePlugin.d.ts +2 -2
  34. package/dist/plugins/metaManage/actionHandlers/getMetaModelDetail.d.ts +2 -2
  35. package/dist/plugins/metaManage/actionHandlers/listMetaModels.d.ts +2 -2
  36. package/dist/plugins/metaManage/actionHandlers/listMetaRoutes.d.ts +2 -2
  37. package/dist/plugins/routeManage/RouteManagePlugin.d.ts +2 -2
  38. package/dist/plugins/routeManage/actionHandlers/httpProxy.d.ts +3 -3
  39. package/dist/plugins/webhooks/WebhooksPlugin.d.ts +2 -2
  40. package/dist/proxy/mod.d.ts +1 -1
  41. package/dist/proxy/types.d.ts +2 -2
  42. package/dist/server.d.ts +2 -0
  43. package/dist/types.d.ts +3 -0
  44. package/package.json +2 -2
  45. package/rollup.config.js +19 -2
  46. package/src/core/pluginManager.ts +7 -14
  47. package/src/core/server.ts +2 -0
  48. package/src/dataAccess/entityManager.ts +57 -6
  49. package/src/helpers/runCollectionEntityActionHandler.ts +6 -5
  50. package/src/plugins/auth/AuthPlugin.ts +7 -3
  51. package/src/plugins/auth/actionHandlers/getMyProfile.ts +2 -6
  52. package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +2 -2
  53. package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +2 -3
  54. package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +2 -3
  55. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +4 -4
  56. package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +3 -4
  57. package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +4 -13
  58. package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +4 -5
  59. package/src/plugins/metaManage/MetaManagePlugin.ts +3 -7
  60. package/src/plugins/routeManage/RouteManagePlugin.ts +2 -7
  61. package/src/plugins/webhooks/WebhooksPlugin.ts +2 -7
  62. package/src/server.ts +32 -8
  63. package/src/types.ts +4 -0
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Auth manager plugin
3
3
  */
4
- import { RpdApplicationConfig } from "~/types";
5
- import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
6
- import { RouteContext } from "~/core/routeContext";
4
+ import { RpdApplicationConfig } from "../../types";
5
+ import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "../../core/server";
6
+ import { RouteContext } from "../../core/routeContext";
7
7
  declare class AuthPlugin implements RapidPlugin {
8
8
  get code(): string;
9
9
  get description(): string;
@@ -1,5 +1,5 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export interface UserAccessToken {
4
4
  sub: "userAccessToken";
5
5
  aud: string;
@@ -1,4 +1,4 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export declare const code = "deleteSession";
4
4
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export declare const code = "getMyProfile";
4
4
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,3 +1,3 @@
1
- import { RpdDataModel } from "~/types";
1
+ import { RpdDataModel } from "../../../types";
2
2
  declare const _default: RpdDataModel;
3
3
  export default _default;
@@ -3,8 +3,8 @@
3
3
  * This plugin provide:
4
4
  * - routes for manage data in database.
5
5
  */
6
- import { RpdApplicationConfig } from "~/types";
7
- import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "~/core/server";
6
+ import { RpdApplicationConfig } from "../../types";
7
+ import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "../../core/server";
8
8
  declare class DataManager implements RapidPlugin {
9
9
  get code(): string;
10
10
  get description(): string;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "addEntityRelations";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "countCollectionEntities";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "createCollectionEntitiesBatch";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "createCollectionEntity";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "deleteCollectionEntityById";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "findCollectionEntities";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "findCollectionEntityById";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunQueryDatabaseHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunQueryDatabaseHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "queryDatabase";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunQueryDatabaseHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "removeEntityRelations";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunEntityActionHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "updateCollectionEntityById";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions): Promise<void>;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * File manager plugin
3
3
  */
4
- import { RpdApplicationConfig } from "~/types";
5
- import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
4
+ import { RpdApplicationConfig } from "../../types";
5
+ import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "../../core/server";
6
6
  declare class FileManager implements RapidPlugin {
7
7
  get code(): string;
8
8
  get description(): string;
@@ -1,4 +1,4 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export declare const code = "downloadDocument";
4
4
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export declare const code = "downloadFile";
4
4
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export declare const code = "uploadFile";
4
4
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Meta manager plugin
3
3
  */
4
- import { RpdApplicationConfig } from "~/types";
5
- import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
4
+ import { RpdApplicationConfig } from "../../types";
5
+ import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "../../core/server";
6
6
  declare class MetaManager implements RapidPlugin {
7
7
  get code(): string;
8
8
  get description(): string;
@@ -1,4 +1,4 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export declare const code = "getMetaModelDetail";
4
4
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export declare const code = "listMetaModels";
4
4
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ActionHandlerContext } from "~/core/actionHandler";
2
- import { RapidPlugin } from "~/core/server";
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
3
  export declare const code = "listMetaRoutes";
4
4
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Route manager plugin
3
3
  */
4
- import { RpdApplicationConfig } from "~/types";
5
- import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "~/core/server";
4
+ import { RpdApplicationConfig } from "../../types";
5
+ import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "../../core/server";
6
6
  declare class RouteManager implements RapidPlugin {
7
7
  get code(): string;
8
8
  get description(): string;
@@ -1,5 +1,5 @@
1
- import { RunProxyHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
1
+ import { RunProxyHandlerOptions } from "../../../types";
2
+ import { ActionHandlerContext } from "../../../core/actionHandler";
3
+ import { RapidPlugin } from "../../../core/server";
4
4
  export declare const code = "httpProxy";
5
5
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunProxyHandlerOptions): Promise<void>;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Webhooks plugin
3
3
  */
4
- import { RpdApplicationConfig, RpdEntityCreateEventPayload, RpdEntityDeleteEventPayload, RpdEntityUpdateEventPayload, RpdServerEventTypes } from "~/types";
5
- import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "~/core/server";
4
+ import { RpdApplicationConfig, RpdEntityCreateEventPayload, RpdEntityDeleteEventPayload, RpdEntityUpdateEventPayload, RpdServerEventTypes } from "../../types";
5
+ import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "../../core/server";
6
6
  export interface Webhook {
7
7
  name: string;
8
8
  url: string;
@@ -1,5 +1,5 @@
1
1
  import { ProxyContext, ProxyOptions } from "./types";
2
- import { RouteContext } from "~/core/routeContext";
2
+ import { RouteContext } from "../core/routeContext";
3
3
  export declare function doProxy(sourceRouterCtx: RouteContext, options: ProxyOptions): Promise<void>;
4
4
  export declare function createProxyContext(sourceRouterCtx: RouteContext, options: ProxyOptions): {
5
5
  sourceContext: {
@@ -1,6 +1,6 @@
1
- import { RapidRequest } from "~/core/request";
1
+ import { RapidRequest } from "../core/request";
2
2
  import { RunProxyHandlerOptions } from "../types";
3
- import { RapidResponse } from "~/core/response";
3
+ import { RapidResponse } from "../core/response";
4
4
  export interface ProxyContext {
5
5
  sourceContext: ProxySourceContext;
6
6
  targetContext: ProxyTargetContext;
package/dist/server.d.ts CHANGED
@@ -2,6 +2,7 @@ import { GetDataAccessorOptions, GetModelOptions, IDatabaseAccessor, IDatabaseCo
2
2
  import { ActionHandler, IPluginActionHandler } from "./core/actionHandler";
3
3
  import { IRpdServer, RapidPlugin } from "./core/server";
4
4
  import { Next } from "./core/routeContext";
5
+ import EntityManager from "./dataAccess/entityManager";
5
6
  export interface InitServerOptions {
6
7
  databaseAccessor: IDatabaseAccessor;
7
8
  databaseConfig: IDatabaseConfig;
@@ -22,6 +23,7 @@ export declare class RapidServer implements IRpdServer {
22
23
  registerMiddleware(middleware: any): void;
23
24
  getDataAccessor<T = any>(options: GetDataAccessorOptions): IRpdDataAccessor<T>;
24
25
  getModel(options: GetModelOptions): RpdDataModel | undefined;
26
+ getEntityManager(singularCode: string): EntityManager;
25
27
  registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void): this;
26
28
  emitEvent<K extends keyof RpdServerEventTypes>(eventName: K, sender: RapidPlugin, payload: RpdServerEventTypes[K][1]): Promise<void>;
27
29
  start(): Promise<void>;
package/dist/types.d.ts CHANGED
@@ -309,6 +309,9 @@ export interface FindEntityOrderByOptions {
309
309
  export interface CountEntityOptions {
310
310
  filters?: EntityFilterOptions[];
311
311
  }
312
+ export interface CountEntityResult {
313
+ count: number;
314
+ }
312
315
  export interface CreateEntityOptions {
313
316
  entity: any;
314
317
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [],
@@ -12,8 +12,8 @@
12
12
  "@types/node": "^20.11.16",
13
13
  "rimraf": "^3.0.2",
14
14
  "rollup": "^2.79.1",
15
- "rollup-plugin-tsconfig-paths": "^1.5.2",
16
15
  "rollup-plugin-typescript2": "^0.34.1",
16
+ "tsc-alias": "^1.8.8",
17
17
  "typescript": "^4.8.4"
18
18
  },
19
19
  "dependencies": {
package/rollup.config.js CHANGED
@@ -1,5 +1,22 @@
1
+ import { exec } from "child_process";
1
2
  import typescript from 'rollup-plugin-typescript2';
2
- // import tsConfigPaths from "rollup-plugin-tsconfig-paths"
3
+
4
+ const tscAlias = () => {
5
+ return {
6
+ name: "tsAlias",
7
+ writeBundle: () => {
8
+ return new Promise((resolve, reject) => {
9
+ exec("tsc-alias", function callback(error, stdout, stderr) {
10
+ if (stderr || error) {
11
+ reject(stderr || error);
12
+ } else {
13
+ resolve(stdout);
14
+ }
15
+ });
16
+ });
17
+ },
18
+ };
19
+ };
3
20
 
4
21
  export default {
5
22
  input: ["src/index.ts"],
@@ -13,7 +30,7 @@ export default {
13
30
  ],
14
31
  plugins: [
15
32
  typescript(),
16
- // tsConfigPaths(),
33
+ tscAlias(),
17
34
  ],
18
35
  external: [
19
36
  ]
@@ -71,84 +71,77 @@ class PluginManager {
71
71
 
72
72
  /** 在加载应用前调用。 */
73
73
  async onLoadingApplication(
74
- server: IRpdServer,
75
74
  applicationConfig: RpdApplicationConfig,
76
75
  ) {
77
76
  for (const plugin of this.#plugins) {
78
77
  if (plugin.onLoadingApplication) {
79
- await plugin.onLoadingApplication(server, applicationConfig);
78
+ await plugin.onLoadingApplication(this.#server, applicationConfig);
80
79
  }
81
80
  }
82
81
  }
83
82
 
84
83
  /** 配置数据模型 */
85
84
  async configureModels(
86
- server: IRpdServer,
87
85
  applicationConfig: RpdApplicationConfig,
88
86
  ) {
89
87
  for (const plugin of this.#plugins) {
90
88
  if (plugin.configureModels) {
91
- await plugin.configureModels(server, applicationConfig);
89
+ await plugin.configureModels(this.#server, applicationConfig);
92
90
  }
93
91
  }
94
92
  }
95
93
 
96
94
  /** 配置模型属性 */
97
95
  async configureModelProperties(
98
- server: IRpdServer,
99
96
  applicationConfig: RpdApplicationConfig,
100
97
  ) {
101
98
  for (const plugin of this.#plugins) {
102
99
  if (plugin.configureModelProperties) {
103
- await plugin.configureModelProperties(server, applicationConfig);
100
+ await plugin.configureModelProperties(this.#server, applicationConfig);
104
101
  }
105
102
  }
106
103
  }
107
104
 
108
105
  /** 配置路由 */
109
106
  async configureRoutes(
110
- server: IRpdServer,
111
107
  applicationConfig: RpdApplicationConfig,
112
108
  ) {
113
109
  for (const plugin of this.#plugins) {
114
110
  if (plugin.configureRoutes) {
115
- await plugin.configureRoutes(server, applicationConfig);
111
+ await plugin.configureRoutes(this.#server, applicationConfig);
116
112
  }
117
113
  }
118
114
  }
119
115
 
120
116
  /** 在应用配置加载完成后调用。此时插件可以进行一些数据的初始化工作。 */
121
117
  async onApplicationLoaded(
122
- server: IRpdServer,
123
118
  applicationConfig: RpdApplicationConfig,
124
119
  ) {
125
120
  for (const plugin of this.#plugins) {
126
121
  if (plugin.onApplicationLoaded) {
127
- await plugin.onApplicationLoaded(server, applicationConfig);
122
+ await plugin.onApplicationLoaded(this.#server, applicationConfig);
128
123
  }
129
124
  }
130
125
  }
131
126
 
132
127
  /** 在应用准备完成后调用。此时服务器已经可以处理网络请求。 */
133
128
  async onApplicationReady(
134
- server: IRpdServer,
135
129
  applicationConfig: RpdApplicationConfig,
136
130
  ) {
137
131
  for (const plugin of this.#plugins) {
138
132
  if (plugin.onApplicationReady) {
139
- await plugin.onApplicationReady(server, applicationConfig);
133
+ await plugin.onApplicationReady(this.#server, applicationConfig);
140
134
  }
141
135
  }
142
136
  }
143
137
 
144
138
  /** 在接收到HTTP请求,准备路由上下文时调用。 */
145
139
  async onPrepareRouteContext(
146
- server: IRpdServer,
147
140
  routeContext: RouteContext,
148
141
  ) {
149
142
  for (const plugin of this.#plugins) {
150
143
  if (plugin.onPrepareRouteContext) {
151
- await plugin.onPrepareRouteContext(server, routeContext);
144
+ await plugin.onPrepareRouteContext(this.#server, routeContext);
152
145
  }
153
146
  }
154
147
  }
@@ -1,6 +1,7 @@
1
1
  import { GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdServerEventTypes } from "~/types";
2
2
  import { IPluginActionHandler, ActionHandler } from "./actionHandler";
3
3
  import { Next, RouteContext } from "./routeContext";
4
+ import EntityManager from "~/dataAccess/entityManager";
4
5
 
5
6
  export interface IRpdServer {
6
7
  config: RapidServerConfig;
@@ -23,6 +24,7 @@ export interface IRpdServer {
23
24
  getDataAccessor<T = any>(
24
25
  options: GetDataAccessorOptions,
25
26
  ): IRpdDataAccessor<T>;
27
+ getEntityManager<TEntity = any>(singularCode: string): EntityManager<TEntity>;
26
28
  getApplicationConfig(): RpdApplicationConfig;
27
29
  appendApplicationConfig(config: Partial<RpdApplicationConfig>);
28
30
  getModel(options: GetModelOptions): RpdDataModel | undefined;
@@ -1,5 +1,7 @@
1
1
  import * as _ from "lodash";
2
2
  import {
3
+ CountEntityOptions,
4
+ CountEntityResult,
3
5
  CreateEntityOptions,
4
6
  EntityFilterOperators,
5
7
  EntityFilterOptions,
@@ -29,7 +31,7 @@ function convertToDataAccessOrderBy(model: RpdDataModel, orderByList?: FindEntit
29
31
  })
30
32
  }
31
33
 
32
- export async function findEntities(
34
+ async function findEntities(
33
35
  server: IRpdServer,
34
36
  dataAccessor: IRpdDataAccessor,
35
37
  options: FindEntityOptions,
@@ -159,7 +161,7 @@ export async function findEntities(
159
161
  return entities.map(item => mapDbRowToEntity(model, item));
160
162
  }
161
163
 
162
- export async function findEntity(
164
+ async function findEntity(
163
165
  server: IRpdServer,
164
166
  dataAccessor: IRpdDataAccessor,
165
167
  options: FindEntityOptions,
@@ -396,7 +398,7 @@ function findOneRelatedEntitiesViaIdPropertyCode(
396
398
  return dataAccessor.find(findEntityOptions);
397
399
  }
398
400
 
399
- export async function createEntity(
401
+ async function createEntity(
400
402
  server: IRpdServer,
401
403
  dataAccessor: IRpdDataAccessor,
402
404
  options: CreateEntityOptions,
@@ -527,8 +529,7 @@ export async function createEntity(
527
529
  return newEntity;
528
530
  }
529
531
 
530
-
531
- export async function updateEntityById(
532
+ async function updateEntityById(
532
533
  server: IRpdServer,
533
534
  dataAccessor: IRpdDataAccessor,
534
535
  options: UpdateEntityByIdOptions,
@@ -648,4 +649,54 @@ export async function updateEntityById(
648
649
  }
649
650
 
650
651
  return updatedEntity;
651
- }
652
+ }
653
+
654
+ export default class EntityManager<TEntity=any> {
655
+ #server: IRpdServer;
656
+ #dataAccessor: IRpdDataAccessor;
657
+
658
+ constructor(server: IRpdServer, dataAccessor: IRpdDataAccessor) {
659
+ this.#server = server;
660
+ this.#dataAccessor = dataAccessor;
661
+ }
662
+
663
+ async findEntities(options: FindEntityOptions): Promise<TEntity[]> {
664
+ return await findEntities(this.#server, this.#dataAccessor, options);
665
+ }
666
+
667
+ async findEntity(options: FindEntityOptions): Promise<TEntity | null> {
668
+ return await findEntity(this.#server, this.#dataAccessor, options);
669
+ }
670
+
671
+ async findById(id: any): Promise<TEntity | null> {
672
+ return await this.findEntity({
673
+ filters: [
674
+ {
675
+ operator: "eq",
676
+ field: "id",
677
+ value: id,
678
+ }
679
+ ]
680
+ });
681
+ }
682
+
683
+ async createEntity(options: CreateEntityOptions): Promise<TEntity> {
684
+ return await createEntity(this.#server, this.#dataAccessor, options);
685
+ }
686
+
687
+ async updateEntityById(options: UpdateEntityByIdOptions): Promise<TEntity> {
688
+ return await updateEntityById(this.#server, this.#dataAccessor, options);
689
+ }
690
+
691
+ async count(options: CountEntityOptions): Promise<CountEntityResult> {
692
+ return await this.#dataAccessor.count(options);
693
+ }
694
+
695
+ async deleteById(id: any): Promise<void> {
696
+ return await this.#dataAccessor.deleteById(id);
697
+ }
698
+
699
+ getModel(): RpdDataModel {
700
+ return this.#dataAccessor.getModel();
701
+ }
702
+ }
@@ -2,9 +2,10 @@ import * as _ from "lodash";
2
2
  import { IRpdDataAccessor, RunEntityActionHandlerOptions } from "~/types";
3
3
  import { mergeInput } from "./inputHelper";
4
4
  import { ActionHandlerContext } from "~/core/actionHandler";
5
+ import EntityManager from "~/dataAccess/entityManager";
5
6
 
6
- type DataAccessHandler = (
7
- dataAccessor: IRpdDataAccessor,
7
+ type EntityActionHandler = (
8
+ entityManager: EntityManager,
8
9
  input: any,
9
10
  ) => Promise<any>;
10
11
 
@@ -12,7 +13,7 @@ export default async function runCollectionEntityActionHandler(
12
13
  ctx: ActionHandlerContext,
13
14
  options: RunEntityActionHandlerOptions,
14
15
  code: string,
15
- handleDataAccess: DataAccessHandler,
16
+ handleEntityAction: EntityActionHandler,
16
17
  ) {
17
18
  const { server, input } = ctx;
18
19
  const { defaultInput, fixedInput } = options;
@@ -24,8 +25,8 @@ export default async function runCollectionEntityActionHandler(
24
25
  console.debug(`fixedInput: ${JSON.stringify(fixedInput)}`);
25
26
  console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
26
27
 
27
- const dataAccessor = server.getDataAccessor(options);
28
- const result = handleDataAccess(dataAccessor, mergedInput);
28
+ const entityManager = server.getEntityManager(options.singularCode);
29
+ const result = handleEntityAction(entityManager, mergedInput);
29
30
  if (result instanceof Promise) {
30
31
  ctx.output = await result;
31
32
  } else {
@@ -96,9 +96,13 @@ class AuthPlugin implements RapidPlugin {
96
96
  token = request.cookies[server.config.sessionCookieName];
97
97
  }
98
98
 
99
- const tokenPayload = verifyJwt(token, server.config.jwtKey);
100
- routeContext.state.userId = tokenPayload.aud as string;
101
- routeContext.state.userLogin = tokenPayload.act as string;
99
+ try {
100
+ const tokenPayload = verifyJwt(token, server.config.jwtKey);
101
+ routeContext.state.userId = tokenPayload.aud as string;
102
+ routeContext.state.userLogin = tokenPayload.act as string;
103
+ } catch (err) {
104
+ console.warn(err);
105
+ }
102
106
  }
103
107
  }
104
108