@ruiapp/rapid-core 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/actionHandler.d.ts +2 -0
- package/dist/core/pluginManager.d.ts +3 -0
- package/dist/core/request.d.ts +2 -1
- package/dist/core/routeContext.d.ts +4 -1
- package/dist/core/server.d.ts +8 -2
- package/dist/dataAccess/dataAccessor.d.ts +2 -1
- package/dist/facilities/log/LogFacility.d.ts +33 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +288 -264
- package/dist/plugins/auth/AuthPlugin.d.ts +0 -9
- package/dist/plugins/dataManage/DataManagePlugin.d.ts +0 -10
- package/dist/plugins/entityAccessControl/EntityAccessControlPlugin.d.ts +17 -0
- package/dist/plugins/fileManage/FileManagePlugin.d.ts +0 -10
- package/dist/plugins/metaManage/MetaManagePlugin.d.ts +0 -8
- package/dist/plugins/routeManage/RouteManagePlugin.d.ts +0 -9
- package/dist/plugins/webhooks/WebhooksPlugin.d.ts +0 -6
- package/dist/server.d.ts +8 -3
- package/dist/types.d.ts +11 -0
- package/dist/utilities/accessControlUtility.d.ts +5 -0
- package/package.json +5 -2
- package/rollup.config.js +1 -18
- package/src/core/actionHandler.ts +2 -0
- package/src/core/pluginManager.ts +12 -0
- package/src/core/request.ts +6 -2
- package/src/core/routeContext.ts +6 -1
- package/src/core/routesBuilder.ts +16 -6
- package/src/core/server.ts +8 -2
- package/src/dataAccess/dataAccessor.ts +13 -9
- package/src/dataAccess/entityManager.ts +24 -24
- package/src/facilities/log/LogFacility.ts +36 -0
- package/src/helpers/inputHelper.ts +3 -3
- package/src/helpers/runCollectionEntityActionHandler.ts +4 -9
- package/src/index.ts +2 -1
- package/src/plugins/auth/AuthPlugin.ts +3 -31
- package/src/plugins/dataManage/DataManagePlugin.ts +0 -32
- package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +2 -2
- package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +0 -1
- package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +2 -2
- package/src/plugins/dataManage/actionHandlers/queryDatabase.ts +5 -9
- package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +2 -6
- package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +3 -8
- package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +107 -0
- package/src/plugins/fileManage/FileManagePlugin.ts +0 -31
- package/src/plugins/metaManage/MetaManagePlugin.ts +16 -39
- package/src/plugins/routeManage/RouteManagePlugin.ts +4 -30
- package/src/plugins/routeManage/actionHandlers/httpProxy.ts +2 -1
- package/src/plugins/webhooks/WebhooksPlugin.ts +26 -36
- package/src/queryBuilder/queryBuilder.ts +3 -3
- package/src/server.ts +53 -17
- package/src/types.ts +13 -0
- package/src/utilities/accessControlUtility.ts +33 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { RpdApplicationConfig } from "../types";
|
|
2
2
|
import { IRpdServer, RapidPlugin } from "./server";
|
|
3
3
|
import { Next, RouteContext } from "./routeContext";
|
|
4
|
+
import { Logger } from "../facilities/log/LogFacility";
|
|
4
5
|
export interface ActionHandlerContext {
|
|
6
|
+
logger: Logger;
|
|
5
7
|
routerContext: RouteContext;
|
|
6
8
|
next: Next;
|
|
7
9
|
server: IRpdServer;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RpdApplicationConfig } from "../types";
|
|
2
2
|
import { IRpdServer, RapidPlugin } from "./server";
|
|
3
3
|
import { RouteContext } from "./routeContext";
|
|
4
|
+
import { ActionHandlerContext } from "./actionHandler";
|
|
4
5
|
declare class PluginManager {
|
|
5
6
|
#private;
|
|
6
7
|
constructor(server: IRpdServer);
|
|
@@ -31,5 +32,7 @@ declare class PluginManager {
|
|
|
31
32
|
onApplicationReady(applicationConfig: RpdApplicationConfig): Promise<void>;
|
|
32
33
|
/** 在接收到HTTP请求,准备路由上下文时调用。 */
|
|
33
34
|
onPrepareRouteContext(routeContext: RouteContext): Promise<void>;
|
|
35
|
+
/** 在接收到HTTP请求,执行 actions 前调用。 */
|
|
36
|
+
beforeRunRouteActions(handlerContext: ActionHandlerContext): Promise<void>;
|
|
34
37
|
}
|
|
35
38
|
export default PluginManager;
|
package/dist/core/request.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRpdServer } from "./server";
|
|
1
2
|
export declare const GlobalRequest: {
|
|
2
3
|
new (input: URL | RequestInfo, init?: RequestInit): Request;
|
|
3
4
|
prototype: Request;
|
|
@@ -10,7 +11,7 @@ export declare class RapidRequest {
|
|
|
10
11
|
#private;
|
|
11
12
|
method: string;
|
|
12
13
|
url: URL;
|
|
13
|
-
constructor(req: Request);
|
|
14
|
+
constructor(server: IRpdServer, req: Request);
|
|
14
15
|
parseBody(): Promise<void>;
|
|
15
16
|
get rawRequest(): Request;
|
|
16
17
|
get headers(): Headers;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { RapidRequest } from "./request";
|
|
2
2
|
import { RapidResponse } from "./response";
|
|
3
3
|
import { HttpStatus } from "./http-types";
|
|
4
|
+
import { IRpdServer } from "./server";
|
|
4
5
|
export type Next = () => Promise<void>;
|
|
5
6
|
export declare class RouteContext {
|
|
7
|
+
#private;
|
|
6
8
|
readonly request: RapidRequest;
|
|
7
9
|
readonly response: RapidResponse;
|
|
8
10
|
readonly state: Record<string, any>;
|
|
9
11
|
method: string;
|
|
10
12
|
path: string;
|
|
11
13
|
params: Record<string, string>;
|
|
12
|
-
|
|
14
|
+
routeConfig: any;
|
|
15
|
+
constructor(server: IRpdServer, request: RapidRequest);
|
|
13
16
|
set(headerName: string, headerValue: string): void;
|
|
14
17
|
json(obj: any, status?: HttpStatus, headers?: HeadersInit): void;
|
|
15
18
|
redirect(url: string, status?: HttpStatus): void;
|
package/dist/core/server.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdServerEventTypes } from "../types";
|
|
2
|
-
import { IPluginActionHandler, ActionHandler } from "./actionHandler";
|
|
1
|
+
import { GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty, RpdServerEventTypes } from "../types";
|
|
2
|
+
import { IPluginActionHandler, ActionHandler, ActionHandlerContext } from "./actionHandler";
|
|
3
3
|
import { Next, RouteContext } from "./routeContext";
|
|
4
4
|
import EntityManager from "../dataAccess/entityManager";
|
|
5
|
+
import { Logger } from "../facilities/log/LogFacility";
|
|
5
6
|
export interface IRpdServer {
|
|
6
7
|
config: RapidServerConfig;
|
|
7
8
|
databaseConfig: IDatabaseConfig;
|
|
8
9
|
queryBuilder: IQueryBuilder;
|
|
10
|
+
getLogger(): Logger;
|
|
9
11
|
queryDatabaseObject: (sql: string, params?: unknown[] | Record<string, unknown>) => Promise<any[]>;
|
|
10
12
|
tryQueryDatabaseObject: (sql: string, params?: unknown[] | Record<string, unknown>) => Promise<any[]>;
|
|
11
13
|
registerMiddleware(middleware: any): void;
|
|
@@ -15,10 +17,12 @@ export interface IRpdServer {
|
|
|
15
17
|
getEntityManager<TEntity = any>(singularCode: string): EntityManager<TEntity>;
|
|
16
18
|
getApplicationConfig(): RpdApplicationConfig;
|
|
17
19
|
appendApplicationConfig(config: Partial<RpdApplicationConfig>): any;
|
|
20
|
+
appendModelProperties(modelSingularCode: string, properties: RpdDataModelProperty[]): any;
|
|
18
21
|
getModel(options: GetModelOptions): RpdDataModel | undefined;
|
|
19
22
|
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void): this;
|
|
20
23
|
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K, sender: RapidPlugin, payload: RpdServerEventTypes[K][1]): void;
|
|
21
24
|
handleRequest(request: Request, next: Next): Promise<Response>;
|
|
25
|
+
beforeRunRouteActions(handlerContext: ActionHandlerContext): Promise<void>;
|
|
22
26
|
}
|
|
23
27
|
export type RpdConfigurationItemTypes = "integer" | "text" | "boolean" | "date" | "datetime" | "json";
|
|
24
28
|
export interface RpdConfigurationItemOptions {
|
|
@@ -85,4 +89,6 @@ export interface RapidPlugin {
|
|
|
85
89
|
onApplicationReady?: (server: IRpdServer, applicationConfig: RpdApplicationConfig) => Promise<any>;
|
|
86
90
|
/** 在接收到HTTP请求,准备路由上下文时调用。 */
|
|
87
91
|
onPrepareRouteContext?: (server: IRpdServer, routeContext: RouteContext) => Promise<any>;
|
|
92
|
+
/** 在接收到HTTP请求,执行 actions 前调用。 */
|
|
93
|
+
beforeRunRouteActions?: (server: IRpdServer, handlerContext: ActionHandlerContext) => Promise<any>;
|
|
88
94
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CountEntityOptions, FindEntityOptions, IRpdDataAccessor, RpdDataModel, IDatabaseAccessor } from "../types";
|
|
2
2
|
import QueryBuilder from "../queryBuilder/queryBuilder";
|
|
3
|
+
import { IRpdServer } from "../core/server";
|
|
3
4
|
export interface IDataAccessorOptions {
|
|
4
5
|
model: RpdDataModel;
|
|
5
6
|
queryBuilder: QueryBuilder;
|
|
6
7
|
}
|
|
7
8
|
export default class DataAccessor<T = any> implements IRpdDataAccessor<T> {
|
|
8
9
|
#private;
|
|
9
|
-
constructor(databaseAccessor: IDatabaseAccessor, options: IDataAccessorOptions);
|
|
10
|
+
constructor(server: IRpdServer, databaseAccessor: IDatabaseAccessor, options: IDataAccessorOptions);
|
|
10
11
|
getModel(): RpdDataModel;
|
|
11
12
|
create(entity: Partial<T>): Promise<T>;
|
|
12
13
|
updateById(id: any, entity: Partial<T>): Promise<{
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import winston from "winston";
|
|
2
|
+
export interface Logger {
|
|
3
|
+
log: winston.LogMethod;
|
|
4
|
+
/**
|
|
5
|
+
* The service/app is going to stop or become unusable now. An operator should definitely look into this immediately.
|
|
6
|
+
*/
|
|
7
|
+
emerg: winston.LeveledLogMethod;
|
|
8
|
+
/**
|
|
9
|
+
* Fatal for a particular service, but the app continues servicing other requests. An operator should look at this immediately.
|
|
10
|
+
*/
|
|
11
|
+
crit: winston.LeveledLogMethod;
|
|
12
|
+
/**
|
|
13
|
+
* Fatal for a particular request, but the service/app continues servicing other requests. An operator should look at this soon(ish).
|
|
14
|
+
*/
|
|
15
|
+
error: winston.LeveledLogMethod;
|
|
16
|
+
/**
|
|
17
|
+
* A note on something that should probably be looked at by an operator eventually.
|
|
18
|
+
*/
|
|
19
|
+
warn: winston.LeveledLogMethod;
|
|
20
|
+
/**
|
|
21
|
+
* Detail on regular operation.
|
|
22
|
+
*/
|
|
23
|
+
info: winston.LeveledLogMethod;
|
|
24
|
+
/**
|
|
25
|
+
* Anything else, i.e. too verbose to be included in "info" level.
|
|
26
|
+
*/
|
|
27
|
+
debug: winston.LeveledLogMethod;
|
|
28
|
+
/**
|
|
29
|
+
* Logging from external libraries used by your app or very detailed application logging.
|
|
30
|
+
*/
|
|
31
|
+
verbose: winston.LeveledLogMethod;
|
|
32
|
+
child(options: Object): Logger;
|
|
33
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +17,4 @@ export { default as ServerOperationPlugin } from "./plugins/serverOperation/Serv
|
|
|
17
17
|
export * from "./plugins/serverOperation/ServerOperationPluginTypes";
|
|
18
18
|
export { default as EntityWatchPlugin } from "./plugins/entityWatch/EntityWatchPlugin";
|
|
19
19
|
export * from "./plugins/entityWatch/EntityWatchPluginTypes";
|
|
20
|
+
export { default as EntityAccessControlPlugin } from "./plugins/entityAccessControl/EntityAccessControlPlugin";
|