@lakutata/entrypoint 3.0.0-beta.0
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/LICENSE +23 -0
- package/README.md +183 -0
- package/THIRD_PARTY_NOTICES.md +206 -0
- package/dist/cjs/Entrypoint.d.ts +868 -0
- package/dist/cjs/Entrypoint.js +998 -0
- package/dist/cjs/adapter/commander/CommanderCLIEntrypoint.d.ts +192 -0
- package/dist/cjs/adapter/commander/CommanderCLIEntrypoint.js +439 -0
- package/dist/cjs/adapter/commander/Prompt.d.ts +22 -0
- package/dist/cjs/adapter/commander/Prompt.js +164 -0
- package/dist/cjs/adapter/commander/Width.d.ts +12 -0
- package/dist/cjs/adapter/commander/Width.js +67 -0
- package/dist/cjs/adapter/electron/ElectronIPCServiceEntrypoint.d.ts +203 -0
- package/dist/cjs/adapter/electron/ElectronIPCServiceEntrypoint.js +249 -0
- package/dist/cjs/adapter/express/ExpressHTTPEntrypoint.d.ts +172 -0
- package/dist/cjs/adapter/express/ExpressHTTPEntrypoint.js +301 -0
- package/dist/cjs/adapter/express/Responders.d.ts +89 -0
- package/dist/cjs/adapter/express/Responders.js +71 -0
- package/dist/cjs/adapter/express/StaticUI.d.ts +83 -0
- package/dist/cjs/adapter/express/StaticUI.js +104 -0
- package/dist/cjs/adapter/fastify/FastifyHTTPEntrypoint.d.ts +156 -0
- package/dist/cjs/adapter/fastify/FastifyHTTPEntrypoint.js +339 -0
- package/dist/cjs/adapter/fastify/Responders.d.ts +88 -0
- package/dist/cjs/adapter/fastify/Responders.js +77 -0
- package/dist/cjs/adapter/http/HTTPServiceEntrypoint.d.ts +117 -0
- package/dist/cjs/adapter/http/HTTPServiceEntrypoint.js +257 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCProtocol.d.ts +194 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCProtocol.js +187 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCServiceEntrypoint.d.ts +154 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCServiceEntrypoint.js +397 -0
- package/dist/cjs/adapter/schedule/ScheduleEntrypoint.d.ts +86 -0
- package/dist/cjs/adapter/schedule/ScheduleEntrypoint.js +275 -0
- package/dist/cjs/adapter/socket.io/SocketIOServiceEntrypoint.d.ts +138 -0
- package/dist/cjs/adapter/socket.io/SocketIOServiceEntrypoint.js +216 -0
- package/dist/cjs/channel/BuiltinChannels.d.ts +18 -0
- package/dist/cjs/channel/BuiltinChannels.js +128 -0
- package/dist/cjs/channel/Channel.d.ts +196 -0
- package/dist/cjs/channel/Channel.js +106 -0
- package/dist/cjs/channel/EntrypointAdapter.d.ts +195 -0
- package/dist/cjs/channel/EntrypointAdapter.js +43 -0
- package/dist/cjs/context/BaseContext.d.ts +75 -0
- package/dist/cjs/context/BaseContext.js +90 -0
- package/dist/cjs/context/CLIContext.d.ts +38 -0
- package/dist/cjs/context/CLIContext.js +53 -0
- package/dist/cjs/context/HTTPContext.d.ts +52 -0
- package/dist/cjs/context/HTTPContext.js +78 -0
- package/dist/cjs/context/ScheduleContext.d.ts +47 -0
- package/dist/cjs/context/ScheduleContext.js +65 -0
- package/dist/cjs/context/ServiceContext.d.ts +47 -0
- package/dist/cjs/context/ServiceContext.js +62 -0
- package/dist/cjs/decorators/CLIAction.d.ts +120 -0
- package/dist/cjs/decorators/CLIAction.js +13 -0
- package/dist/cjs/decorators/HTTPAction.d.ts +178 -0
- package/dist/cjs/decorators/HTTPAction.js +14 -0
- package/dist/cjs/decorators/Prefix.d.ts +44 -0
- package/dist/cjs/decorators/Prefix.js +48 -0
- package/dist/cjs/decorators/Schedule.d.ts +120 -0
- package/dist/cjs/decorators/Schedule.js +64 -0
- package/dist/cjs/decorators/ServiceAction.d.ts +116 -0
- package/dist/cjs/decorators/ServiceAction.js +12 -0
- package/dist/cjs/decorators/UseMiddlewares.d.ts +52 -0
- package/dist/cjs/decorators/UseMiddlewares.js +58 -0
- package/dist/cjs/decorators/http/DELETE.d.ts +87 -0
- package/dist/cjs/decorators/http/DELETE.js +7 -0
- package/dist/cjs/decorators/http/GET.d.ts +89 -0
- package/dist/cjs/decorators/http/GET.js +7 -0
- package/dist/cjs/decorators/http/HEAD.d.ts +84 -0
- package/dist/cjs/decorators/http/HEAD.js +7 -0
- package/dist/cjs/decorators/http/OPTIONS.d.ts +80 -0
- package/dist/cjs/decorators/http/OPTIONS.js +7 -0
- package/dist/cjs/decorators/http/PATCH.d.ts +90 -0
- package/dist/cjs/decorators/http/PATCH.js +7 -0
- package/dist/cjs/decorators/http/POST.d.ts +91 -0
- package/dist/cjs/decorators/http/POST.js +7 -0
- package/dist/cjs/decorators/http/PUT.d.ts +92 -0
- package/dist/cjs/decorators/http/PUT.js +7 -0
- package/dist/cjs/exceptions/AccessDeniedException.d.ts +10 -0
- package/dist/cjs/exceptions/AccessDeniedException.js +17 -0
- package/dist/cjs/exceptions/ControllerActionNotFoundException.d.ts +9 -0
- package/dist/cjs/exceptions/ControllerActionNotFoundException.js +16 -0
- package/dist/cjs/exceptions/DuplicateActionNameException.d.ts +8 -0
- package/dist/cjs/exceptions/DuplicateActionNameException.js +15 -0
- package/dist/cjs/exceptions/EntrypointStoppedException.d.ts +9 -0
- package/dist/cjs/exceptions/EntrypointStoppedException.js +16 -0
- package/dist/cjs/exceptions/InvalidActionGroupException.d.ts +4 -0
- package/dist/cjs/exceptions/InvalidActionGroupException.js +11 -0
- package/dist/cjs/exceptions/InvalidChannelException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidChannelException.js +15 -0
- package/dist/cjs/exceptions/InvalidEntrypointAdapterException.d.ts +9 -0
- package/dist/cjs/exceptions/InvalidEntrypointAdapterException.js +16 -0
- package/dist/cjs/exceptions/InvalidMiddlewareException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidMiddlewareException.js +15 -0
- package/dist/cjs/exceptions/InvalidPrefixException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidPrefixException.js +15 -0
- package/dist/cjs/exceptions/MiddlewareNextCalledException.d.ts +8 -0
- package/dist/cjs/exceptions/MiddlewareNextCalledException.js +15 -0
- package/dist/cjs/exceptions/RouteNotFoundException.d.ts +9 -0
- package/dist/cjs/exceptions/RouteNotFoundException.js +16 -0
- package/dist/cjs/exceptions/ServiceInvokeException.d.ts +11 -0
- package/dist/cjs/exceptions/ServiceInvokeException.js +14 -0
- package/dist/cjs/exports/CTRLDecorators.d.ts +13 -0
- package/dist/cjs/exports/CTRLDecorators.js +38 -0
- package/dist/cjs/exports/Channel.d.ts +14 -0
- package/dist/cjs/exports/Channel.js +33 -0
- package/dist/cjs/exports/CommanderAdapter.d.ts +1 -0
- package/dist/cjs/exports/CommanderAdapter.js +8 -0
- package/dist/cjs/exports/ElectronAdapter.d.ts +1 -0
- package/dist/cjs/exports/ElectronAdapter.js +9 -0
- package/dist/cjs/exports/Entrypoint.d.ts +24 -0
- package/dist/cjs/exports/Entrypoint.js +55 -0
- package/dist/cjs/exports/ExpressAdapter.d.ts +4 -0
- package/dist/cjs/exports/ExpressAdapter.js +15 -0
- package/dist/cjs/exports/FastifyAdapter.d.ts +4 -0
- package/dist/cjs/exports/FastifyAdapter.js +14 -0
- package/dist/cjs/exports/JSONRPCAdapter.d.ts +2 -0
- package/dist/cjs/exports/JSONRPCAdapter.js +11 -0
- package/dist/cjs/exports/SocketIOAdapter.d.ts +1 -0
- package/dist/cjs/exports/SocketIOAdapter.js +9 -0
- package/dist/cjs/lib/AccessControl.d.ts +118 -0
- package/dist/cjs/lib/AccessControl.js +208 -0
- package/dist/cjs/lib/AccessControlRule.d.ts +91 -0
- package/dist/cjs/lib/AccessControlRule.js +76 -0
- package/dist/cjs/lib/ActionOptions.d.ts +67 -0
- package/dist/cjs/lib/ActionOptions.js +67 -0
- package/dist/cjs/lib/ActionResult.d.ts +28 -0
- package/dist/cjs/lib/ActionResult.js +28 -0
- package/dist/cjs/lib/ApplicationOf.d.ts +6 -0
- package/dist/cjs/lib/ApplicationOf.js +14 -0
- package/dist/cjs/lib/Controller.d.ts +59 -0
- package/dist/cjs/lib/Controller.js +64 -0
- package/dist/cjs/lib/ControllerEntrypoint.d.ts +168 -0
- package/dist/cjs/lib/ControllerEntrypoint.js +239 -0
- package/dist/cjs/lib/GetActionDTOAndOptions.d.ts +29 -0
- package/dist/cjs/lib/GetActionDTOAndOptions.js +49 -0
- package/dist/cjs/lib/HTTPErrors.d.ts +55 -0
- package/dist/cjs/lib/HTTPErrors.js +52 -0
- package/dist/cjs/lib/Middleware.d.ts +146 -0
- package/dist/cjs/lib/Middleware.js +144 -0
- package/dist/cjs/lib/Prefix.d.ts +98 -0
- package/dist/cjs/lib/Prefix.js +151 -0
- package/dist/cjs/lib/Result.d.ts +173 -0
- package/dist/cjs/lib/Result.js +153 -0
- package/dist/cjs/lib/ServiceResponseCodec.d.ts +82 -0
- package/dist/cjs/lib/ServiceResponseCodec.js +117 -0
- package/dist/cjs/lib/StringifyPattern.d.ts +7 -0
- package/dist/cjs/lib/StringifyPattern.js +58 -0
- package/dist/cjs/lib/UnsetValue.d.ts +12 -0
- package/dist/cjs/lib/UnsetValue.js +216 -0
- package/dist/cjs/lib/pattern/GlobPattern.d.ts +34 -0
- package/dist/cjs/lib/pattern/GlobPattern.js +68 -0
- package/dist/cjs/lib/pattern/PatternManager.d.ts +103 -0
- package/dist/cjs/lib/pattern/PatternManager.js +233 -0
- package/dist/cjs/lib/schedule/Cron.d.ts +56 -0
- package/dist/cjs/lib/schedule/Cron.js +282 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/CLIContextParams.d.ts +14 -0
- package/dist/cjs/types/CLIContextParams.js +2 -0
- package/dist/cjs/types/ErrorDescription.d.ts +14 -0
- package/dist/cjs/types/ErrorDescription.js +2 -0
- package/dist/cjs/types/HTTPContextParams.d.ts +27 -0
- package/dist/cjs/types/HTTPContextParams.js +2 -0
- package/dist/cjs/types/ScheduleContextParams.d.ts +21 -0
- package/dist/cjs/types/ScheduleContextParams.js +2 -0
- package/dist/cjs/types/ServiceContextParams.d.ts +16 -0
- package/dist/cjs/types/ServiceContextParams.js +2 -0
- package/dist/esm/Entrypoint.js +985 -0
- package/dist/esm/adapter/commander/CommanderCLIEntrypoint.js +433 -0
- package/dist/esm/adapter/commander/Prompt.js +127 -0
- package/dist/esm/adapter/commander/Width.js +63 -0
- package/dist/esm/adapter/electron/ElectronIPCServiceEntrypoint.js +212 -0
- package/dist/esm/adapter/express/ExpressHTTPEntrypoint.js +295 -0
- package/dist/esm/adapter/express/Responders.js +66 -0
- package/dist/esm/adapter/express/StaticUI.js +96 -0
- package/dist/esm/adapter/fastify/FastifyHTTPEntrypoint.js +333 -0
- package/dist/esm/adapter/fastify/Responders.js +73 -0
- package/dist/esm/adapter/http/HTTPServiceEntrypoint.js +253 -0
- package/dist/esm/adapter/jsonrpc/JSONRPCProtocol.js +182 -0
- package/dist/esm/adapter/jsonrpc/JSONRPCServiceEntrypoint.js +361 -0
- package/dist/esm/adapter/schedule/ScheduleEntrypoint.js +272 -0
- package/dist/esm/adapter/socket.io/SocketIOServiceEntrypoint.js +212 -0
- package/dist/esm/channel/BuiltinChannels.js +125 -0
- package/dist/esm/channel/Channel.js +100 -0
- package/dist/esm/channel/EntrypointAdapter.js +39 -0
- package/dist/esm/context/BaseContext.js +87 -0
- package/dist/esm/context/CLIContext.js +49 -0
- package/dist/esm/context/HTTPContext.js +74 -0
- package/dist/esm/context/ScheduleContext.js +61 -0
- package/dist/esm/context/ServiceContext.js +58 -0
- package/dist/esm/decorators/CLIAction.js +10 -0
- package/dist/esm/decorators/HTTPAction.js +11 -0
- package/dist/esm/decorators/Prefix.js +45 -0
- package/dist/esm/decorators/Schedule.js +61 -0
- package/dist/esm/decorators/ServiceAction.js +9 -0
- package/dist/esm/decorators/UseMiddlewares.js +55 -0
- package/dist/esm/decorators/http/DELETE.js +4 -0
- package/dist/esm/decorators/http/GET.js +4 -0
- package/dist/esm/decorators/http/HEAD.js +4 -0
- package/dist/esm/decorators/http/OPTIONS.js +4 -0
- package/dist/esm/decorators/http/PATCH.js +4 -0
- package/dist/esm/decorators/http/POST.js +4 -0
- package/dist/esm/decorators/http/PUT.js +4 -0
- package/dist/esm/exceptions/AccessDeniedException.js +13 -0
- package/dist/esm/exceptions/ControllerActionNotFoundException.js +12 -0
- package/dist/esm/exceptions/DuplicateActionNameException.js +11 -0
- package/dist/esm/exceptions/EntrypointStoppedException.js +12 -0
- package/dist/esm/exceptions/InvalidActionGroupException.js +7 -0
- package/dist/esm/exceptions/InvalidChannelException.js +11 -0
- package/dist/esm/exceptions/InvalidEntrypointAdapterException.js +12 -0
- package/dist/esm/exceptions/InvalidMiddlewareException.js +11 -0
- package/dist/esm/exceptions/InvalidPrefixException.js +11 -0
- package/dist/esm/exceptions/MiddlewareNextCalledException.js +11 -0
- package/dist/esm/exceptions/RouteNotFoundException.js +12 -0
- package/dist/esm/exceptions/ServiceInvokeException.js +10 -0
- package/dist/esm/exports/CTRLDecorators.js +19 -0
- package/dist/esm/exports/Channel.js +11 -0
- package/dist/esm/exports/CommanderAdapter.js +1 -0
- package/dist/esm/exports/ElectronAdapter.js +1 -0
- package/dist/esm/exports/Entrypoint.js +22 -0
- package/dist/esm/exports/ExpressAdapter.js +3 -0
- package/dist/esm/exports/FastifyAdapter.js +3 -0
- package/dist/esm/exports/JSONRPCAdapter.js +2 -0
- package/dist/esm/exports/SocketIOAdapter.js +1 -0
- package/dist/esm/lib/AccessControl.js +204 -0
- package/dist/esm/lib/AccessControlRule.js +72 -0
- package/dist/esm/lib/ActionOptions.js +63 -0
- package/dist/esm/lib/ActionResult.js +24 -0
- package/dist/esm/lib/ApplicationOf.js +11 -0
- package/dist/esm/lib/Controller.js +61 -0
- package/dist/esm/lib/ControllerEntrypoint.js +229 -0
- package/dist/esm/lib/GetActionDTOAndOptions.js +46 -0
- package/dist/esm/lib/HTTPErrors.js +48 -0
- package/dist/esm/lib/Middleware.js +134 -0
- package/dist/esm/lib/Prefix.js +143 -0
- package/dist/esm/lib/Result.js +147 -0
- package/dist/esm/lib/ServiceResponseCodec.js +113 -0
- package/dist/esm/lib/StringifyPattern.js +55 -0
- package/dist/esm/lib/UnsetValue.js +213 -0
- package/dist/esm/lib/pattern/GlobPattern.js +64 -0
- package/dist/esm/lib/pattern/PatternManager.js +229 -0
- package/dist/esm/lib/schedule/Cron.js +277 -0
- package/dist/esm/types/CLIContextParams.js +1 -0
- package/dist/esm/types/ErrorDescription.js +1 -0
- package/dist/esm/types/HTTPContextParams.js +1 -0
- package/dist/esm/types/ScheduleContextParams.js +1 -0
- package/dist/esm/types/ServiceContextParams.js +1 -0
- package/dist/types/Entrypoint.d.ts +868 -0
- package/dist/types/adapter/commander/CommanderCLIEntrypoint.d.ts +192 -0
- package/dist/types/adapter/commander/Prompt.d.ts +22 -0
- package/dist/types/adapter/commander/Width.d.ts +12 -0
- package/dist/types/adapter/electron/ElectronIPCServiceEntrypoint.d.ts +203 -0
- package/dist/types/adapter/express/ExpressHTTPEntrypoint.d.ts +172 -0
- package/dist/types/adapter/express/Responders.d.ts +89 -0
- package/dist/types/adapter/express/StaticUI.d.ts +83 -0
- package/dist/types/adapter/fastify/FastifyHTTPEntrypoint.d.ts +156 -0
- package/dist/types/adapter/fastify/Responders.d.ts +88 -0
- package/dist/types/adapter/http/HTTPServiceEntrypoint.d.ts +117 -0
- package/dist/types/adapter/jsonrpc/JSONRPCProtocol.d.ts +194 -0
- package/dist/types/adapter/jsonrpc/JSONRPCServiceEntrypoint.d.ts +154 -0
- package/dist/types/adapter/schedule/ScheduleEntrypoint.d.ts +86 -0
- package/dist/types/adapter/socket.io/SocketIOServiceEntrypoint.d.ts +138 -0
- package/dist/types/channel/BuiltinChannels.d.ts +18 -0
- package/dist/types/channel/Channel.d.ts +196 -0
- package/dist/types/channel/EntrypointAdapter.d.ts +195 -0
- package/dist/types/context/BaseContext.d.ts +75 -0
- package/dist/types/context/CLIContext.d.ts +38 -0
- package/dist/types/context/HTTPContext.d.ts +52 -0
- package/dist/types/context/ScheduleContext.d.ts +47 -0
- package/dist/types/context/ServiceContext.d.ts +47 -0
- package/dist/types/decorators/CLIAction.d.ts +120 -0
- package/dist/types/decorators/HTTPAction.d.ts +178 -0
- package/dist/types/decorators/Prefix.d.ts +44 -0
- package/dist/types/decorators/Schedule.d.ts +120 -0
- package/dist/types/decorators/ServiceAction.d.ts +116 -0
- package/dist/types/decorators/UseMiddlewares.d.ts +52 -0
- package/dist/types/decorators/http/DELETE.d.ts +87 -0
- package/dist/types/decorators/http/GET.d.ts +89 -0
- package/dist/types/decorators/http/HEAD.d.ts +84 -0
- package/dist/types/decorators/http/OPTIONS.d.ts +80 -0
- package/dist/types/decorators/http/PATCH.d.ts +90 -0
- package/dist/types/decorators/http/POST.d.ts +91 -0
- package/dist/types/decorators/http/PUT.d.ts +92 -0
- package/dist/types/exceptions/AccessDeniedException.d.ts +10 -0
- package/dist/types/exceptions/ControllerActionNotFoundException.d.ts +9 -0
- package/dist/types/exceptions/DuplicateActionNameException.d.ts +8 -0
- package/dist/types/exceptions/EntrypointStoppedException.d.ts +9 -0
- package/dist/types/exceptions/InvalidActionGroupException.d.ts +4 -0
- package/dist/types/exceptions/InvalidChannelException.d.ts +8 -0
- package/dist/types/exceptions/InvalidEntrypointAdapterException.d.ts +9 -0
- package/dist/types/exceptions/InvalidMiddlewareException.d.ts +8 -0
- package/dist/types/exceptions/InvalidPrefixException.d.ts +8 -0
- package/dist/types/exceptions/MiddlewareNextCalledException.d.ts +8 -0
- package/dist/types/exceptions/RouteNotFoundException.d.ts +9 -0
- package/dist/types/exceptions/ServiceInvokeException.d.ts +11 -0
- package/dist/types/exports/CTRLDecorators.d.ts +13 -0
- package/dist/types/exports/Channel.d.ts +14 -0
- package/dist/types/exports/CommanderAdapter.d.ts +1 -0
- package/dist/types/exports/ElectronAdapter.d.ts +1 -0
- package/dist/types/exports/Entrypoint.d.ts +24 -0
- package/dist/types/exports/ExpressAdapter.d.ts +4 -0
- package/dist/types/exports/FastifyAdapter.d.ts +4 -0
- package/dist/types/exports/JSONRPCAdapter.d.ts +2 -0
- package/dist/types/exports/SocketIOAdapter.d.ts +1 -0
- package/dist/types/lib/AccessControl.d.ts +118 -0
- package/dist/types/lib/AccessControlRule.d.ts +91 -0
- package/dist/types/lib/ActionOptions.d.ts +67 -0
- package/dist/types/lib/ActionResult.d.ts +28 -0
- package/dist/types/lib/ApplicationOf.d.ts +6 -0
- package/dist/types/lib/Controller.d.ts +59 -0
- package/dist/types/lib/ControllerEntrypoint.d.ts +168 -0
- package/dist/types/lib/GetActionDTOAndOptions.d.ts +29 -0
- package/dist/types/lib/HTTPErrors.d.ts +55 -0
- package/dist/types/lib/Middleware.d.ts +146 -0
- package/dist/types/lib/Prefix.d.ts +98 -0
- package/dist/types/lib/Result.d.ts +173 -0
- package/dist/types/lib/ServiceResponseCodec.d.ts +82 -0
- package/dist/types/lib/StringifyPattern.d.ts +7 -0
- package/dist/types/lib/UnsetValue.d.ts +12 -0
- package/dist/types/lib/pattern/GlobPattern.d.ts +34 -0
- package/dist/types/lib/pattern/PatternManager.d.ts +103 -0
- package/dist/types/lib/schedule/Cron.d.ts +56 -0
- package/dist/types/types/CLIContextParams.d.ts +14 -0
- package/dist/types/types/ErrorDescription.d.ts +14 -0
- package/dist/types/types/HTTPContextParams.d.ts +27 -0
- package/dist/types/types/ScheduleContextParams.d.ts +21 -0
- package/dist/types/types/ServiceContextParams.d.ts +16 -0
- package/package.json +152 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Controller, type ControllerProperty } from './Controller.js';
|
|
2
|
+
import { IBaseObjectConstructor, ActionPattern, JSONSchema, DTO, Component } from '@lakutata/core';
|
|
3
|
+
import { ActionOptions } from './ActionOptions.js';
|
|
4
|
+
import { CLIContext } from '../context/CLIContext.js';
|
|
5
|
+
import { ServiceContext } from '../context/ServiceContext.js';
|
|
6
|
+
import { HTTPContext } from '../context/HTTPContext.js';
|
|
7
|
+
import type { AccessControlRuleHandler } from './AccessControlRule.js';
|
|
8
|
+
import { MiddlewareDefinition } from './Middleware.js';
|
|
9
|
+
import { ChannelDefinition } from '../channel/Channel.js';
|
|
10
|
+
export type ActionPatternMap = Map<ActionPattern, ActionDetails>;
|
|
11
|
+
/**
|
|
12
|
+
* A registered controller action: its address in its channel, its controller and method, its input DTO and its
|
|
13
|
+
* options. The channels read it from {@link ChannelEntry.details}.
|
|
14
|
+
*/
|
|
15
|
+
export type ActionDetails<ClassPrototype extends Controller = Controller, DTOConstructor extends typeof DTO = typeof DTO> = {
|
|
16
|
+
/**
|
|
17
|
+
* The action's address in its channel (`{route, method}`, `{command}`, a service pattern…), with its
|
|
18
|
+
* controller prefix once bound to an entrypoint.
|
|
19
|
+
*/
|
|
20
|
+
pattern: ActionPattern;
|
|
21
|
+
/**
|
|
22
|
+
* The controller class serving the action: the registered controller, which may be a subclass of the class
|
|
23
|
+
* declaring the action.
|
|
24
|
+
*/
|
|
25
|
+
constructor: IBaseObjectConstructor<ClassPrototype>;
|
|
26
|
+
/**
|
|
27
|
+
* The controller method running the action.
|
|
28
|
+
*/
|
|
29
|
+
method: string | number | symbol;
|
|
30
|
+
/**
|
|
31
|
+
* The DTO validating the action's input.
|
|
32
|
+
*/
|
|
33
|
+
dtoConstructor: DTOConstructor;
|
|
34
|
+
/**
|
|
35
|
+
* The JSON schema of the action's input (its DTO).
|
|
36
|
+
*/
|
|
37
|
+
jsonSchema: JSONSchema;
|
|
38
|
+
/**
|
|
39
|
+
* The middlewares of the action's `middlewares` option.
|
|
40
|
+
*/
|
|
41
|
+
middlewares: MiddlewareDefinition[];
|
|
42
|
+
/**
|
|
43
|
+
* Get the action's options and identity, as given to the access control rules (`targetAction`).
|
|
44
|
+
* @returns The action's identity and options.
|
|
45
|
+
*/
|
|
46
|
+
getActionInfo: () => ActionInfo;
|
|
47
|
+
} & ActionInfo;
|
|
48
|
+
/**
|
|
49
|
+
* A controller action's identity and options.
|
|
50
|
+
*/
|
|
51
|
+
export type ActionInfo = {
|
|
52
|
+
/**
|
|
53
|
+
* The action's id: a UUID derived from the controller, the method and the address, stable across restarts.
|
|
54
|
+
*/
|
|
55
|
+
id: string;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the action is checked by the access control rules (its `acl` option).
|
|
58
|
+
*/
|
|
59
|
+
acl: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* The action's controller class and method, as `ControllerClass:method`.
|
|
62
|
+
*/
|
|
63
|
+
action: string;
|
|
64
|
+
/**
|
|
65
|
+
* The action's name: its `name` option, `ControllerClass:method` by default.
|
|
66
|
+
*/
|
|
67
|
+
name: string;
|
|
68
|
+
/**
|
|
69
|
+
* The action's description: its `description` option, empty by default.
|
|
70
|
+
*/
|
|
71
|
+
description: string;
|
|
72
|
+
/**
|
|
73
|
+
* The ids of the action's groups (its `groups` option).
|
|
74
|
+
*/
|
|
75
|
+
groups: string[];
|
|
76
|
+
/**
|
|
77
|
+
* The action's own access rule (its `rule` option).
|
|
78
|
+
*/
|
|
79
|
+
rule?: AccessControlRuleHandler<any>;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The channels of the actions of a controller, its parent classes included
|
|
83
|
+
* @param target
|
|
84
|
+
*/
|
|
85
|
+
export declare function getControllerChannels(target: IBaseObjectConstructor<Controller>): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Register an action of a controller on a channel
|
|
88
|
+
* @param channel
|
|
89
|
+
* @param target
|
|
90
|
+
* @param actionPattern
|
|
91
|
+
* @param details
|
|
92
|
+
* @constructor
|
|
93
|
+
*/
|
|
94
|
+
export declare function registerChannelAction(channel: ChannelDefinition, target: IBaseObjectConstructor<Controller>, actionPattern: ActionPattern, details: ActionDetails): void;
|
|
95
|
+
/**
|
|
96
|
+
* Register a controller method as an action of a channel, for the decorators of the packages providing a channel
|
|
97
|
+
* (the built-in `@HTTPAction`, `@CLIAction` and `@ServiceAction` call it). The action is served by the controller class
|
|
98
|
+
* and its subclasses registered in an entrypoint. Registering the same address again for the class replaces the
|
|
99
|
+
* previous action.
|
|
100
|
+
* @param channel The channel's definition (see {@link defineChannel}).
|
|
101
|
+
* @param controllerPrototype The prototype of the controller class (the decorator's target).
|
|
102
|
+
* @param propertyKey The name of the method running the action.
|
|
103
|
+
* @param actionPattern The action's address, checked by the channel's `validate`; at most 2 levels of nesting.
|
|
104
|
+
* @param dtoConstructor The DTO validating the action's input (`FlexibleDTO` to accept any input).
|
|
105
|
+
* @param actionOptions The action's options (name, description, groups, access control, middlewares); give them
|
|
106
|
+
* validated (as {@link getActionDTOAndOptions} returns them).
|
|
107
|
+
* @throws {InvalidActionPatternDepthException} When the address is nested more than 2 levels deep.
|
|
108
|
+
* @throws {InvalidMiddlewareException} When a middleware of the options is neither a function nor a `Middleware` subclass.
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import {DTO} from 'lakutata'
|
|
112
|
+
* import {Controller, type ControllerProperty} from 'lakutata/com/entrypoint'
|
|
113
|
+
* import {getActionDTOAndOptions, getChannel, registerControllerAction, type ActionOptions} from '@lakutata/entrypoint/channel'
|
|
114
|
+
*
|
|
115
|
+
* //A decorator declaring the actions of a "queue" channel defined by its package
|
|
116
|
+
* export function OnMessage(topic: string, dtoOrOptions?: typeof DTO | ActionOptions<any>, options?: ActionOptions<any>) {
|
|
117
|
+
* return <ClassPrototype extends Controller>(target: ClassPrototype, propertyKey: ControllerProperty<ClassPrototype>): void => {
|
|
118
|
+
* const [dtoConstructor, actionOptions] = getActionDTOAndOptions(dtoOrOptions, options)
|
|
119
|
+
* registerControllerAction(getChannel('queue'), target, propertyKey, {topic: topic}, dtoConstructor, actionOptions)
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function registerControllerAction<ClassPrototype extends Controller, DTOConstructor extends typeof DTO = typeof DTO>(channel: ChannelDefinition, controllerPrototype: ClassPrototype, propertyKey: ControllerProperty<ClassPrototype>, actionPattern: ActionPattern, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<any>): void;
|
|
125
|
+
/**
|
|
126
|
+
* Bind controller to component
|
|
127
|
+
* @param component
|
|
128
|
+
* @param controllerConstructor
|
|
129
|
+
* @constructor
|
|
130
|
+
*/
|
|
131
|
+
export declare function bindControllerToComponent(component: Component, controllerConstructor: IBaseObjectConstructor<Controller>): void;
|
|
132
|
+
/**
|
|
133
|
+
* Get module controller action map
|
|
134
|
+
* @constructor
|
|
135
|
+
* @param component
|
|
136
|
+
*/
|
|
137
|
+
export declare function getComponentControllerActionMap(component: Component): Map<string, ActionPatternMap>;
|
|
138
|
+
/**
|
|
139
|
+
* Register http action
|
|
140
|
+
* @param route
|
|
141
|
+
* @param methods
|
|
142
|
+
* @param controllerPrototype
|
|
143
|
+
* @param propertyKey
|
|
144
|
+
* @param dtoConstructor
|
|
145
|
+
* @param actionOptions
|
|
146
|
+
* @constructor
|
|
147
|
+
*/
|
|
148
|
+
export declare function registerHTTPAction<ClassPrototype extends Controller, DTOConstructor extends typeof DTO = typeof DTO>(route: string, methods: string[], controllerPrototype: ClassPrototype, propertyKey: ControllerProperty<ClassPrototype>, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<HTTPContext>): void;
|
|
149
|
+
/**
|
|
150
|
+
* Register cli action
|
|
151
|
+
* @param command
|
|
152
|
+
* @param controllerPrototype
|
|
153
|
+
* @param propertyKey
|
|
154
|
+
* @param dtoConstructor
|
|
155
|
+
* @param actionOptions
|
|
156
|
+
* @constructor
|
|
157
|
+
*/
|
|
158
|
+
export declare function registerCLIAction<ClassPrototype extends Controller, DTOConstructor extends typeof DTO = typeof DTO>(command: string, controllerPrototype: ClassPrototype, propertyKey: ControllerProperty<ClassPrototype>, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<CLIContext>): void;
|
|
159
|
+
/**
|
|
160
|
+
* Register service action
|
|
161
|
+
* @param pattern
|
|
162
|
+
* @param controllerPrototype
|
|
163
|
+
* @param propertyKey
|
|
164
|
+
* @param dtoConstructor
|
|
165
|
+
* @param actionOptions
|
|
166
|
+
* @constructor
|
|
167
|
+
*/
|
|
168
|
+
export declare function registerServiceAction<ClassPrototype extends Controller, DTOConstructor extends typeof DTO = typeof DTO>(pattern: ActionPattern, controllerPrototype: ClassPrototype, propertyKey: ControllerProperty<ClassPrototype>, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<ServiceContext>): void;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getControllerChannels = getControllerChannels;
|
|
4
|
+
exports.registerChannelAction = registerChannelAction;
|
|
5
|
+
exports.registerControllerAction = registerControllerAction;
|
|
6
|
+
exports.bindControllerToComponent = bindControllerToComponent;
|
|
7
|
+
exports.getComponentControllerActionMap = getComponentControllerActionMap;
|
|
8
|
+
exports.registerHTTPAction = registerHTTPAction;
|
|
9
|
+
exports.registerCLIAction = registerCLIAction;
|
|
10
|
+
exports.registerServiceAction = registerServiceAction;
|
|
11
|
+
const utils_1 = require("@lakutata/utils");
|
|
12
|
+
const core_1 = require("@lakutata/core");
|
|
13
|
+
const Middleware_js_1 = require("./Middleware.js");
|
|
14
|
+
const Prefix_js_1 = require("./Prefix.js");
|
|
15
|
+
const Channel_js_1 = require("../channel/Channel.js");
|
|
16
|
+
const BuiltinChannels_js_1 = require("../channel/BuiltinChannels.js");
|
|
17
|
+
//The channels of the actions declared by a controller class
|
|
18
|
+
const CONTROLLER_CHANNELS = Symbol('CONTROLLER.CHANNELS');
|
|
19
|
+
//The actions of the controllers bound to an entrypoint, by channel
|
|
20
|
+
const COMPONENT_CTRL_MAP = Symbol('COMPONENT.CTRL.MAP');
|
|
21
|
+
/**
|
|
22
|
+
* The metadata key of the actions of a channel
|
|
23
|
+
* @param channel
|
|
24
|
+
*/
|
|
25
|
+
function channelActionsKey(channel) {
|
|
26
|
+
return `ENTRYPOINT.CHANNEL.ACTIONS.${channel}`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get action info
|
|
30
|
+
* @param controllerPrototype
|
|
31
|
+
* @param propertyKey
|
|
32
|
+
* @param actionOptions
|
|
33
|
+
* @param extra
|
|
34
|
+
*/
|
|
35
|
+
function getActionInfo(controllerPrototype, propertyKey, actionOptions, extra) {
|
|
36
|
+
const action = `${(0, utils_1.As)((0, utils_1.objectConstructor)(controllerPrototype)).className}:${String(propertyKey)}`;
|
|
37
|
+
const id = utils_1.UUID.v5(`${action}:${extra}`, utils_1.UUID.NIL);
|
|
38
|
+
const name = actionOptions.name ? actionOptions.name : action;
|
|
39
|
+
const description = actionOptions.description ? actionOptions.description : '';
|
|
40
|
+
return {
|
|
41
|
+
id: id,
|
|
42
|
+
acl: !!actionOptions.acl,
|
|
43
|
+
action: action,
|
|
44
|
+
name: name,
|
|
45
|
+
description: description,
|
|
46
|
+
groups: actionOptions.groups ? actionOptions.groups : [],
|
|
47
|
+
rule: actionOptions.rule
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate action pattern definition
|
|
52
|
+
* @param actionPattern
|
|
53
|
+
*/
|
|
54
|
+
function validateActionPatternDefinition(actionPattern) {
|
|
55
|
+
const depth = (0, utils_1.getObjectNestingDepth)(actionPattern);
|
|
56
|
+
if (depth > 2)
|
|
57
|
+
throw new core_1.InvalidActionPatternDepthException('The maximum nesting depth of ActionPattern objects cannot be greater than 2 levels. The current nesting depth of the object is {0} levels', [depth]);
|
|
58
|
+
return actionPattern;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get controller's internal action pattern map of a channel
|
|
62
|
+
* @param channel
|
|
63
|
+
* @param target
|
|
64
|
+
* @constructor
|
|
65
|
+
*/
|
|
66
|
+
function getInternalControllerActionPatternMap(channel, target) {
|
|
67
|
+
const key = channelActionsKey(channel);
|
|
68
|
+
const internalActionPatternMap = new Map();
|
|
69
|
+
//From the farthest parent: the closest declaration of an action wins
|
|
70
|
+
(0, utils_1.objectParentConstructors)(target).reverse().forEach(parentConstructor => {
|
|
71
|
+
const parentActionPatternMap = Reflect.getOwnMetadata(key, parentConstructor) || new Map();
|
|
72
|
+
parentActionPatternMap.forEach((value, hash) => internalActionPatternMap.set(hash, value));
|
|
73
|
+
});
|
|
74
|
+
(0, utils_1.As)(Reflect.getOwnMetadata(key, target) || new Map()).forEach((value, hash) => internalActionPatternMap.set(hash, value));
|
|
75
|
+
return internalActionPatternMap;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The channels of the actions of a controller, its parent classes included
|
|
79
|
+
* @param target
|
|
80
|
+
*/
|
|
81
|
+
function getControllerChannels(target) {
|
|
82
|
+
const names = new Set();
|
|
83
|
+
for (const constructor of [target, ...(0, utils_1.objectParentConstructors)(target)]) {
|
|
84
|
+
const own = Reflect.getOwnMetadata(CONTROLLER_CHANNELS, constructor);
|
|
85
|
+
own?.forEach((name) => names.add(name));
|
|
86
|
+
}
|
|
87
|
+
return [...names];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Register an action of a controller on a channel
|
|
91
|
+
* @param channel
|
|
92
|
+
* @param target
|
|
93
|
+
* @param actionPattern
|
|
94
|
+
* @param details
|
|
95
|
+
* @constructor
|
|
96
|
+
*/
|
|
97
|
+
function registerChannelAction(channel, target, actionPattern, details) {
|
|
98
|
+
actionPattern = validateActionPatternDefinition(channel.validate ? channel.validate(actionPattern) : actionPattern);
|
|
99
|
+
const internalActionPatternMap = getInternalControllerActionPatternMap(channel.name, target);
|
|
100
|
+
internalActionPatternMap.set((0, utils_1.objectHash)(actionPattern), {
|
|
101
|
+
pattern: actionPattern,
|
|
102
|
+
details: { ...details, pattern: actionPattern }
|
|
103
|
+
});
|
|
104
|
+
Reflect.defineMetadata(channelActionsKey(channel.name), internalActionPatternMap, target);
|
|
105
|
+
const own = Reflect.getOwnMetadata(CONTROLLER_CHANNELS, target) || new Set();
|
|
106
|
+
Reflect.defineMetadata(CONTROLLER_CHANNELS, own.add(channel.name), target);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Register a controller method as an action of a channel, for the decorators of the packages providing a channel
|
|
110
|
+
* (the built-in `@HTTPAction`, `@CLIAction` and `@ServiceAction` call it). The action is served by the controller class
|
|
111
|
+
* and its subclasses registered in an entrypoint. Registering the same address again for the class replaces the
|
|
112
|
+
* previous action.
|
|
113
|
+
* @param channel The channel's definition (see {@link defineChannel}).
|
|
114
|
+
* @param controllerPrototype The prototype of the controller class (the decorator's target).
|
|
115
|
+
* @param propertyKey The name of the method running the action.
|
|
116
|
+
* @param actionPattern The action's address, checked by the channel's `validate`; at most 2 levels of nesting.
|
|
117
|
+
* @param dtoConstructor The DTO validating the action's input (`FlexibleDTO` to accept any input).
|
|
118
|
+
* @param actionOptions The action's options (name, description, groups, access control, middlewares); give them
|
|
119
|
+
* validated (as {@link getActionDTOAndOptions} returns them).
|
|
120
|
+
* @throws {InvalidActionPatternDepthException} When the address is nested more than 2 levels deep.
|
|
121
|
+
* @throws {InvalidMiddlewareException} When a middleware of the options is neither a function nor a `Middleware` subclass.
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import {DTO} from 'lakutata'
|
|
125
|
+
* import {Controller, type ControllerProperty} from 'lakutata/com/entrypoint'
|
|
126
|
+
* import {getActionDTOAndOptions, getChannel, registerControllerAction, type ActionOptions} from '@lakutata/entrypoint/channel'
|
|
127
|
+
*
|
|
128
|
+
* //A decorator declaring the actions of a "queue" channel defined by its package
|
|
129
|
+
* export function OnMessage(topic: string, dtoOrOptions?: typeof DTO | ActionOptions<any>, options?: ActionOptions<any>) {
|
|
130
|
+
* return <ClassPrototype extends Controller>(target: ClassPrototype, propertyKey: ControllerProperty<ClassPrototype>): void => {
|
|
131
|
+
* const [dtoConstructor, actionOptions] = getActionDTOAndOptions(dtoOrOptions, options)
|
|
132
|
+
* registerControllerAction(getChannel('queue'), target, propertyKey, {topic: topic}, dtoConstructor, actionOptions)
|
|
133
|
+
* }
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
function registerControllerAction(channel, controllerPrototype, propertyKey, actionPattern, dtoConstructor, actionOptions) {
|
|
138
|
+
const constructor = (0, utils_1.As)((0, utils_1.objectConstructor)(controllerPrototype));
|
|
139
|
+
const actionInfo = getActionInfo(controllerPrototype, propertyKey, actionOptions, channel.identify(actionPattern));
|
|
140
|
+
registerChannelAction(channel, constructor, actionPattern, {
|
|
141
|
+
...actionInfo,
|
|
142
|
+
pattern: actionPattern,
|
|
143
|
+
constructor: constructor,
|
|
144
|
+
method: propertyKey,
|
|
145
|
+
dtoConstructor: dtoConstructor,
|
|
146
|
+
jsonSchema: dtoConstructor.toJsonSchema(),
|
|
147
|
+
middlewares: (0, Middleware_js_1.validateMiddlewares)(actionOptions.middlewares ?? []),
|
|
148
|
+
getActionInfo: () => actionInfo
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Bind controller to component
|
|
153
|
+
* @param component
|
|
154
|
+
* @param controllerConstructor
|
|
155
|
+
* @constructor
|
|
156
|
+
*/
|
|
157
|
+
function bindControllerToComponent(component, controllerConstructor) {
|
|
158
|
+
const totalInternalActionPatternMap = Reflect.getOwnMetadata(COMPONENT_CTRL_MAP, component) || new Map();
|
|
159
|
+
const prefix = (0, Prefix_js_1.getPrefix)(controllerConstructor);
|
|
160
|
+
//The actions inherited from a parent controller are run by the registered controller
|
|
161
|
+
const bind = (channel, value) => {
|
|
162
|
+
const details = { ...value.details, constructor: controllerConstructor };
|
|
163
|
+
const prefixed = prefix && channel.prefix ? channel.prefix(prefix, value.pattern) : undefined;
|
|
164
|
+
if (prefixed === undefined)
|
|
165
|
+
return ['', { pattern: value.pattern, details: details }];
|
|
166
|
+
const pattern = validateActionPatternDefinition(channel.validate ? channel.validate(prefixed) : prefixed);
|
|
167
|
+
//A prefixed action is named after the registered controller, so the controllers sharing a parent have distinct actions
|
|
168
|
+
const action = `${controllerConstructor.className}:${String(details.method)}`;
|
|
169
|
+
details.name = details.name === details.action ? action : details.name;
|
|
170
|
+
details.action = action;
|
|
171
|
+
details.id = utils_1.UUID.v5(`${action}:${channel.identify(pattern)}`, utils_1.UUID.NIL);
|
|
172
|
+
details.pattern = pattern;
|
|
173
|
+
const actionInfo = { id: details.id, acl: details.acl, action: action, name: details.name, description: details.description, groups: details.groups, rule: details.rule };
|
|
174
|
+
details.getActionInfo = () => actionInfo;
|
|
175
|
+
return [(0, utils_1.objectHash)(pattern), { pattern: pattern, details: details }];
|
|
176
|
+
};
|
|
177
|
+
for (const name of getControllerChannels(controllerConstructor)) {
|
|
178
|
+
const channel = (0, Channel_js_1.getChannel)(name);
|
|
179
|
+
const map = totalInternalActionPatternMap.get(name) ?? new Map();
|
|
180
|
+
getInternalControllerActionPatternMap(name, controllerConstructor).forEach((value, hash) => {
|
|
181
|
+
const [prefixedHash, bound] = bind(channel, value);
|
|
182
|
+
map.set(prefixedHash || hash, bound);
|
|
183
|
+
});
|
|
184
|
+
totalInternalActionPatternMap.set(name, map);
|
|
185
|
+
}
|
|
186
|
+
Reflect.defineMetadata(COMPONENT_CTRL_MAP, totalInternalActionPatternMap, component);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get module controller action map
|
|
190
|
+
* @constructor
|
|
191
|
+
* @param component
|
|
192
|
+
*/
|
|
193
|
+
function getComponentControllerActionMap(component) {
|
|
194
|
+
const totalInternalActionPatternMap = Reflect.getOwnMetadata(COMPONENT_CTRL_MAP, component) || new Map();
|
|
195
|
+
const totalActionPatternMap = new Map();
|
|
196
|
+
totalInternalActionPatternMap.forEach((map, channel) => {
|
|
197
|
+
const actions = new Map();
|
|
198
|
+
map.forEach((value) => actions.set(value.pattern, value.details));
|
|
199
|
+
totalActionPatternMap.set(channel, actions);
|
|
200
|
+
});
|
|
201
|
+
return totalActionPatternMap;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Register http action
|
|
205
|
+
* @param route
|
|
206
|
+
* @param methods
|
|
207
|
+
* @param controllerPrototype
|
|
208
|
+
* @param propertyKey
|
|
209
|
+
* @param dtoConstructor
|
|
210
|
+
* @param actionOptions
|
|
211
|
+
* @constructor
|
|
212
|
+
*/
|
|
213
|
+
function registerHTTPAction(route, methods, controllerPrototype, propertyKey, dtoConstructor, actionOptions) {
|
|
214
|
+
methods.forEach((method) => registerControllerAction(BuiltinChannels_js_1.HTTPChannel, controllerPrototype, propertyKey, { route: route, method: method }, dtoConstructor, actionOptions));
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Register cli action
|
|
218
|
+
* @param command
|
|
219
|
+
* @param controllerPrototype
|
|
220
|
+
* @param propertyKey
|
|
221
|
+
* @param dtoConstructor
|
|
222
|
+
* @param actionOptions
|
|
223
|
+
* @constructor
|
|
224
|
+
*/
|
|
225
|
+
function registerCLIAction(command, controllerPrototype, propertyKey, dtoConstructor, actionOptions) {
|
|
226
|
+
registerControllerAction(BuiltinChannels_js_1.CLIChannel, controllerPrototype, propertyKey, { command: command }, dtoConstructor, actionOptions);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Register service action
|
|
230
|
+
* @param pattern
|
|
231
|
+
* @param controllerPrototype
|
|
232
|
+
* @param propertyKey
|
|
233
|
+
* @param dtoConstructor
|
|
234
|
+
* @param actionOptions
|
|
235
|
+
* @constructor
|
|
236
|
+
*/
|
|
237
|
+
function registerServiceAction(pattern, controllerPrototype, propertyKey, dtoConstructor, actionOptions) {
|
|
238
|
+
registerControllerAction(BuiltinChannels_js_1.ServiceChannel, controllerPrototype, propertyKey, pattern, dtoConstructor, actionOptions);
|
|
239
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DTO } from '@lakutata/core';
|
|
2
|
+
import { ActionOptions } from './ActionOptions.js';
|
|
3
|
+
import { FlexibleDTO } from '@lakutata/core/dtos';
|
|
4
|
+
/**
|
|
5
|
+
* Sort out the optional arguments of an action decorator (`(dto?)`, `(options?)` or `(dto, options)`): a function is
|
|
6
|
+
* the DTO, an object the options. The options are validated, their defaults applied.
|
|
7
|
+
* @param dtoConstructorOrOptions The DTO validating the action's input, or the action's options.
|
|
8
|
+
* @param options The action's options, when the first argument is the DTO.
|
|
9
|
+
* @returns The DTO (`FlexibleDTO`, accepting any input, when none is given) and the validated options.
|
|
10
|
+
* @throws {Error} When the options are invalid (the validation error of {@link ActionOptions}).
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import {DTO} from 'lakutata'
|
|
14
|
+
* import {FlexibleDTO} from 'lakutata/dtos'
|
|
15
|
+
* import {Expect} from 'lakutata/decorator/dto'
|
|
16
|
+
* import {getActionDTOAndOptions} from '@lakutata/entrypoint/channel'
|
|
17
|
+
*
|
|
18
|
+
* class SendDTO extends DTO {
|
|
19
|
+
* @Expect(DTO.String().required())
|
|
20
|
+
* public text: string
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* const [dto, options] = getActionDTOAndOptions(SendDTO, {name: 'send'})
|
|
24
|
+
* console.log(dto === SendDTO, options.groups) //true []
|
|
25
|
+
* const [anyInput] = getActionDTOAndOptions({acl: true})
|
|
26
|
+
* console.log(anyInput === FlexibleDTO) //true
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function getActionDTOAndOptions<DTOConstructor extends typeof DTO = typeof DTO>(dtoConstructorOrOptions?: DTOConstructor | ActionOptions<any>, options?: ActionOptions<any>): [DTOConstructor | typeof FlexibleDTO, ActionOptions<any>];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getActionDTOAndOptions = getActionDTOAndOptions;
|
|
4
|
+
const ActionOptions_js_1 = require("./ActionOptions.js");
|
|
5
|
+
const dtos_1 = require("@lakutata/core/dtos");
|
|
6
|
+
/**
|
|
7
|
+
* Sort out the optional arguments of an action decorator (`(dto?)`, `(options?)` or `(dto, options)`): a function is
|
|
8
|
+
* the DTO, an object the options. The options are validated, their defaults applied.
|
|
9
|
+
* @param dtoConstructorOrOptions The DTO validating the action's input, or the action's options.
|
|
10
|
+
* @param options The action's options, when the first argument is the DTO.
|
|
11
|
+
* @returns The DTO (`FlexibleDTO`, accepting any input, when none is given) and the validated options.
|
|
12
|
+
* @throws {Error} When the options are invalid (the validation error of {@link ActionOptions}).
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import {DTO} from 'lakutata'
|
|
16
|
+
* import {FlexibleDTO} from 'lakutata/dtos'
|
|
17
|
+
* import {Expect} from 'lakutata/decorator/dto'
|
|
18
|
+
* import {getActionDTOAndOptions} from '@lakutata/entrypoint/channel'
|
|
19
|
+
*
|
|
20
|
+
* class SendDTO extends DTO {
|
|
21
|
+
* @Expect(DTO.String().required())
|
|
22
|
+
* public text: string
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* const [dto, options] = getActionDTOAndOptions(SendDTO, {name: 'send'})
|
|
26
|
+
* console.log(dto === SendDTO, options.groups) //true []
|
|
27
|
+
* const [anyInput] = getActionDTOAndOptions({acl: true})
|
|
28
|
+
* console.log(anyInput === FlexibleDTO) //true
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function getActionDTOAndOptions(dtoConstructorOrOptions, options) {
|
|
32
|
+
let dtoConstructor = dtos_1.FlexibleDTO;
|
|
33
|
+
let actionOptions = {};
|
|
34
|
+
if (options) {
|
|
35
|
+
//The DTO may be omitted (undefined) before the options
|
|
36
|
+
if (dtoConstructorOrOptions)
|
|
37
|
+
dtoConstructor = dtoConstructorOrOptions;
|
|
38
|
+
actionOptions = options;
|
|
39
|
+
}
|
|
40
|
+
else if (dtoConstructorOrOptions) {
|
|
41
|
+
if (dtoConstructorOrOptions.constructor.name.toUpperCase() === 'FUNCTION') {
|
|
42
|
+
dtoConstructor = dtoConstructorOrOptions;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
actionOptions = dtoConstructorOrOptions;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [dtoConstructor, ActionOptions_js_1.ActionOptions.validate(actionOptions)];
|
|
49
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ErrorDescription } from '../types/ErrorDescription.js';
|
|
2
|
+
/**
|
|
3
|
+
* Where an error answered by an HTTP adapter comes from, given to the `error` of its responder: `'action'` when the
|
|
4
|
+
* request reached an action and its dispatch failed (the entrypoint's middlewares, the validation of the input, the
|
|
5
|
+
* access control, the action itself); `'request'` when it failed before (a middleware of the web framework such as an
|
|
6
|
+
* authenticator, a hook of fastify, a body too large) or matched no route.
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import type {Request, Response} from 'express'
|
|
10
|
+
* import {describeError, type ExpressResponder, type HTTPErrorOrigin, statusOfError} from 'lakutata/adapter/express'
|
|
11
|
+
*
|
|
12
|
+
* //The errors of the actions answered with 200, the others with their status
|
|
13
|
+
* export const responder: ExpressResponder = {
|
|
14
|
+
* success: (response: Response, data: unknown): void => void response.json({data: data}),
|
|
15
|
+
* error: (response: Response, error: unknown, _request: Request, origin?: HTTPErrorOrigin): void => {
|
|
16
|
+
* response.status(origin === 'action' ? 200 : statusOfError(error)).json(describeError(error))
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type HTTPErrorOrigin = 'action' | 'request';
|
|
22
|
+
/**
|
|
23
|
+
* Find the HTTP status of an error, read from its `statusCode` or `status`: the first client error (4xx) found on the
|
|
24
|
+
* error or along its `cause` chain, else the error's own status when it is between 400 and 599, else 500. A validation
|
|
25
|
+
* failure, wrapped in an exception whose cause is the 400 validation error, thus gives 400.
|
|
26
|
+
* @param error The error, any value.
|
|
27
|
+
* @returns The HTTP status, from 400 to 599.
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import {statusOfError} from 'lakutata/adapter/express'
|
|
31
|
+
*
|
|
32
|
+
* class NotFound extends Error {
|
|
33
|
+
* public readonly statusCode: number = 404
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* console.log(statusOfError(new NotFound('No such order'))) //404
|
|
37
|
+
* console.log(statusOfError(new Error('Failed', {cause: new NotFound('No such order')}))) //404
|
|
38
|
+
* console.log(statusOfError(new Error('Boom'))) //500
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function statusOfError(error: unknown): number;
|
|
42
|
+
/**
|
|
43
|
+
* Describe an error as the JSON responders send it: its `errno` (or `code`, `E_UNKNOWN` without either) and its
|
|
44
|
+
* `errMsg` (or `message`, or the error converted to a string).
|
|
45
|
+
* @param error The error, any value.
|
|
46
|
+
* @returns The error's number and message.
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import {describeError, type ErrorDescription} from 'lakutata/adapter/express'
|
|
50
|
+
*
|
|
51
|
+
* const description: ErrorDescription = describeError(new Error('Boom'))
|
|
52
|
+
* console.log(description) //{errno: 'E_UNKNOWN', errMsg: 'Boom'}
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function describeError(error: unknown): ErrorDescription;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.statusOfError = statusOfError;
|
|
4
|
+
exports.describeError = describeError;
|
|
5
|
+
/**
|
|
6
|
+
* Find the HTTP status of an error, read from its `statusCode` or `status`: the first client error (4xx) found on the
|
|
7
|
+
* error or along its `cause` chain, else the error's own status when it is between 400 and 599, else 500. A validation
|
|
8
|
+
* failure, wrapped in an exception whose cause is the 400 validation error, thus gives 400.
|
|
9
|
+
* @param error The error, any value.
|
|
10
|
+
* @returns The HTTP status, from 400 to 599.
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import {statusOfError} from 'lakutata/adapter/express'
|
|
14
|
+
*
|
|
15
|
+
* class NotFound extends Error {
|
|
16
|
+
* public readonly statusCode: number = 404
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* console.log(statusOfError(new NotFound('No such order'))) //404
|
|
20
|
+
* console.log(statusOfError(new Error('Failed', {cause: new NotFound('No such order')}))) //404
|
|
21
|
+
* console.log(statusOfError(new Error('Boom'))) //500
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function statusOfError(error) {
|
|
25
|
+
for (let current = error; current && typeof current === 'object'; current = current.cause) {
|
|
26
|
+
const status = current.statusCode ?? current.status;
|
|
27
|
+
if (typeof status === 'number' && status >= 400 && status < 500)
|
|
28
|
+
return status;
|
|
29
|
+
}
|
|
30
|
+
const status = error?.statusCode ?? error?.status;
|
|
31
|
+
return typeof status === 'number' && status >= 400 && status < 600 ? status : 500;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Describe an error as the JSON responders send it: its `errno` (or `code`, `E_UNKNOWN` without either) and its
|
|
35
|
+
* `errMsg` (or `message`, or the error converted to a string).
|
|
36
|
+
* @param error The error, any value.
|
|
37
|
+
* @returns The error's number and message.
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import {describeError, type ErrorDescription} from 'lakutata/adapter/express'
|
|
41
|
+
*
|
|
42
|
+
* const description: ErrorDescription = describeError(new Error('Boom'))
|
|
43
|
+
* console.log(description) //{errno: 'E_UNKNOWN', errMsg: 'Boom'}
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function describeError(error) {
|
|
47
|
+
const described = error ?? {};
|
|
48
|
+
return {
|
|
49
|
+
errno: described.errno ?? described.code ?? 'E_UNKNOWN',
|
|
50
|
+
errMsg: described.errMsg ?? described.message ?? String(error)
|
|
51
|
+
};
|
|
52
|
+
}
|