@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,91 @@
|
|
|
1
|
+
import { BaseObject, type ActionPattern } from '@lakutata/core';
|
|
2
|
+
import { BaseContext, ContextType } from '../context/BaseContext.js';
|
|
3
|
+
import { CLIActionInfo, HTTPActionInfo, ServiceActionInfo } from '../Entrypoint.js';
|
|
4
|
+
import type { ActionInfo } from './ControllerEntrypoint.js';
|
|
5
|
+
/**
|
|
6
|
+
* An action's own access rule (the `rule` action option): resolve `true` to allow the request, `false` to deny it with
|
|
7
|
+
* an `AccessDeniedException`; a thrown error denies it with that error.
|
|
8
|
+
* @param context The request's context.
|
|
9
|
+
* @param input The action's validated input.
|
|
10
|
+
* @returns Whether the request is allowed.
|
|
11
|
+
*/
|
|
12
|
+
export type AccessControlRuleHandler<T extends BaseContext<Record<string, any>>> = (context: T, input?: ActionPattern<any>) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* An access control rule, checked for the actions declared with `acl: true`: give the rule classes to the
|
|
15
|
+
* entrypoint's `rules` option. For each request to such an action, every rule supporting the request's context type
|
|
16
|
+
* is created in the request's container (its dependencies injected) and its {@link AccessControlRule.rule} called, in
|
|
17
|
+
* the order of the option; the first one resolving `false` denies the request with an `AccessDeniedException`, the
|
|
18
|
+
* first one throwing denies it with its error. A request no rule denies is allowed.
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import {Application} from 'lakutata'
|
|
22
|
+
* import {AccessControlRule, buildEntrypoints, ContextType, Controller, type HTTPContext} from 'lakutata/com/entrypoint'
|
|
23
|
+
* import {DELETE} from 'lakutata/decorator/ctrl'
|
|
24
|
+
*
|
|
25
|
+
* //Only the requests of an administrator reach the actions of the "admin" group
|
|
26
|
+
* class AdminRule extends AccessControlRule<HTTPContext> {
|
|
27
|
+
* public get supportContextTypes(): ContextType[] {
|
|
28
|
+
* return [ContextType.HTTP]
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* public async rule(): Promise<boolean> {
|
|
32
|
+
* if (!this.targetAction.groups.includes('admin')) return true
|
|
33
|
+
* return this.context.request.headers['x-role'] === 'admin'
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* class UserController extends Controller {
|
|
38
|
+
* @DELETE('/users/:id', {acl: true, groups: ['admin']})
|
|
39
|
+
* public async remove(input: {id: string}): Promise<void> {
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* Application.run(() => ({
|
|
44
|
+
* id: 'admin.app',
|
|
45
|
+
* name: 'Admin',
|
|
46
|
+
* components: {
|
|
47
|
+
* entrypoint: buildEntrypoints({
|
|
48
|
+
* controllers: [UserController],
|
|
49
|
+
* rules: [AdminRule],
|
|
50
|
+
* httpActionGroups: {admin: 'Administration'}
|
|
51
|
+
* })
|
|
52
|
+
* }
|
|
53
|
+
* }))
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare abstract class AccessControlRule<T extends BaseContext<Record<string, any>> = BaseContext<Record<string, any>>> extends BaseObject {
|
|
57
|
+
/**
|
|
58
|
+
* The request's context.
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
protected readonly context: T;
|
|
62
|
+
/**
|
|
63
|
+
* The action's validated input.
|
|
64
|
+
* @protected
|
|
65
|
+
*/
|
|
66
|
+
protected readonly input: ActionPattern<any>;
|
|
67
|
+
/**
|
|
68
|
+
* The descriptions of every action of the request's channel (to check the permissions an action requires against
|
|
69
|
+
* the others).
|
|
70
|
+
* @protected
|
|
71
|
+
*/
|
|
72
|
+
protected readonly actions: HTTPActionInfo[] | ServiceActionInfo[] | CLIActionInfo[];
|
|
73
|
+
/**
|
|
74
|
+
* The requested action: its `id`, `name`, `description`, `groups`, `acl`, `rule` and `action`
|
|
75
|
+
* (`ControllerClass:method`). Its channel's fields (`route`, `command`, `pattern`), `controller`, `method` and
|
|
76
|
+
* `jsonSchema` are in {@link AccessControlRule.actions}, found by `id`.
|
|
77
|
+
* @protected
|
|
78
|
+
*/
|
|
79
|
+
protected readonly targetAction: ActionInfo;
|
|
80
|
+
/**
|
|
81
|
+
* The context types of the requests the rule checks (`ContextType.HTTP`…, or the context type of another channel);
|
|
82
|
+
* for the other requests the rule is created but its {@link AccessControlRule.rule} is not called.
|
|
83
|
+
*/
|
|
84
|
+
abstract get supportContextTypes(): ContextType[];
|
|
85
|
+
/**
|
|
86
|
+
* Check the request.
|
|
87
|
+
* @returns `true` to let the next rules check the request, `false` to deny it with an `AccessDeniedException`.
|
|
88
|
+
* @throws {Error} Any error, to deny the request with it.
|
|
89
|
+
*/
|
|
90
|
+
abstract rule(): Promise<boolean>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AccessControlRule = void 0;
|
|
13
|
+
const core_1 = require("@lakutata/core");
|
|
14
|
+
const di_1 = require("@lakutata/core/decorator/di");
|
|
15
|
+
/**
|
|
16
|
+
* An access control rule, checked for the actions declared with `acl: true`: give the rule classes to the
|
|
17
|
+
* entrypoint's `rules` option. For each request to such an action, every rule supporting the request's context type
|
|
18
|
+
* is created in the request's container (its dependencies injected) and its {@link AccessControlRule.rule} called, in
|
|
19
|
+
* the order of the option; the first one resolving `false` denies the request with an `AccessDeniedException`, the
|
|
20
|
+
* first one throwing denies it with its error. A request no rule denies is allowed.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import {Application} from 'lakutata'
|
|
24
|
+
* import {AccessControlRule, buildEntrypoints, ContextType, Controller, type HTTPContext} from 'lakutata/com/entrypoint'
|
|
25
|
+
* import {DELETE} from 'lakutata/decorator/ctrl'
|
|
26
|
+
*
|
|
27
|
+
* //Only the requests of an administrator reach the actions of the "admin" group
|
|
28
|
+
* class AdminRule extends AccessControlRule<HTTPContext> {
|
|
29
|
+
* public get supportContextTypes(): ContextType[] {
|
|
30
|
+
* return [ContextType.HTTP]
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* public async rule(): Promise<boolean> {
|
|
34
|
+
* if (!this.targetAction.groups.includes('admin')) return true
|
|
35
|
+
* return this.context.request.headers['x-role'] === 'admin'
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* class UserController extends Controller {
|
|
40
|
+
* @DELETE('/users/:id', {acl: true, groups: ['admin']})
|
|
41
|
+
* public async remove(input: {id: string}): Promise<void> {
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* Application.run(() => ({
|
|
46
|
+
* id: 'admin.app',
|
|
47
|
+
* name: 'Admin',
|
|
48
|
+
* components: {
|
|
49
|
+
* entrypoint: buildEntrypoints({
|
|
50
|
+
* controllers: [UserController],
|
|
51
|
+
* rules: [AdminRule],
|
|
52
|
+
* httpActionGroups: {admin: 'Administration'}
|
|
53
|
+
* })
|
|
54
|
+
* }
|
|
55
|
+
* }))
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
class AccessControlRule extends core_1.BaseObject {
|
|
59
|
+
}
|
|
60
|
+
exports.AccessControlRule = AccessControlRule;
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, di_1.Configurable)(),
|
|
63
|
+
__metadata("design:type", Object)
|
|
64
|
+
], AccessControlRule.prototype, "context", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, di_1.Configurable)(),
|
|
67
|
+
__metadata("design:type", Object)
|
|
68
|
+
], AccessControlRule.prototype, "input", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, di_1.Configurable)(),
|
|
71
|
+
__metadata("design:type", Array)
|
|
72
|
+
], AccessControlRule.prototype, "actions", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, di_1.Configurable)(),
|
|
75
|
+
__metadata("design:type", Object)
|
|
76
|
+
], AccessControlRule.prototype, "targetAction", void 0);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DTO } from '@lakutata/core';
|
|
2
|
+
import type { AccessControlRuleHandler } from './AccessControlRule.js';
|
|
3
|
+
import { BaseContext } from '../context/BaseContext.js';
|
|
4
|
+
import type { MiddlewareDefinition } from './Middleware.js';
|
|
5
|
+
/**
|
|
6
|
+
* The options of a controller action, the last argument of the action decorators (`@GET`, `@CLIAction`,
|
|
7
|
+
* `@ServiceAction`, `@Schedule`…).
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {Controller, type HTTPContext} from 'lakutata/com/entrypoint'
|
|
11
|
+
* import {type ActionOptions} from '@lakutata/entrypoint/channel'
|
|
12
|
+
* import {GET} from 'lakutata/decorator/ctrl'
|
|
13
|
+
*
|
|
14
|
+
* //Only the requests carrying the admin token reach the action
|
|
15
|
+
* const adminOnly: ActionOptions<HTTPContext> = {
|
|
16
|
+
* acl: true,
|
|
17
|
+
* name: 'listUsers',
|
|
18
|
+
* description: 'List the users',
|
|
19
|
+
* groups: ['admin'],
|
|
20
|
+
* rule: async (context: HTTPContext): Promise<boolean> => context.request.headers.authorization === 'Bearer admin'
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* class UserController extends Controller {
|
|
24
|
+
* @GET('/users', adminOnly)
|
|
25
|
+
* public async list(): Promise<string[]> {
|
|
26
|
+
* return []
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class ActionOptions<T extends BaseContext<Record<string, any>>> extends DTO {
|
|
32
|
+
/**
|
|
33
|
+
* Whether the entrypoint's access control rules are checked for the action; a request they deny fails with an
|
|
34
|
+
* `AccessDeniedException`. With no rule (or none supporting the request's context type), the access is
|
|
35
|
+
* allowed.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
acl?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The action's name, unique within its channel among the controller methods (the addresses of one method may
|
|
41
|
+
* share it): `ControllerClass:method` when empty.
|
|
42
|
+
* @default ''
|
|
43
|
+
*/
|
|
44
|
+
name?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The action's description, listed with the action.
|
|
47
|
+
* @default ''
|
|
48
|
+
*/
|
|
49
|
+
description?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The ids of the action's groups; for HTTP, CLI and service actions each id must be a key of the entrypoint's
|
|
52
|
+
* action groups option (`httpActionGroups`…), or the entrypoint fails to initialize.
|
|
53
|
+
* @default []
|
|
54
|
+
*/
|
|
55
|
+
groups?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* The action's own access rule, checked after the entrypoint's rules when `acl` is on, and alone when it is off:
|
|
58
|
+
* resolving `false` denies the request (`AccessDeniedException`), throwing denies it with the thrown error.
|
|
59
|
+
*/
|
|
60
|
+
rule?: AccessControlRuleHandler<T>;
|
|
61
|
+
/**
|
|
62
|
+
* The action's middlewares, run after the ones of the controller class and before the ones added to the method
|
|
63
|
+
* by `@UseMiddlewares`.
|
|
64
|
+
* @default []
|
|
65
|
+
*/
|
|
66
|
+
middlewares?: MiddlewareDefinition[];
|
|
67
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ActionOptions = void 0;
|
|
13
|
+
const core_1 = require("@lakutata/core");
|
|
14
|
+
const dto_1 = require("@lakutata/core/decorator/dto");
|
|
15
|
+
/**
|
|
16
|
+
* The options of a controller action, the last argument of the action decorators (`@GET`, `@CLIAction`,
|
|
17
|
+
* `@ServiceAction`, `@Schedule`…).
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {Controller, type HTTPContext} from 'lakutata/com/entrypoint'
|
|
21
|
+
* import {type ActionOptions} from '@lakutata/entrypoint/channel'
|
|
22
|
+
* import {GET} from 'lakutata/decorator/ctrl'
|
|
23
|
+
*
|
|
24
|
+
* //Only the requests carrying the admin token reach the action
|
|
25
|
+
* const adminOnly: ActionOptions<HTTPContext> = {
|
|
26
|
+
* acl: true,
|
|
27
|
+
* name: 'listUsers',
|
|
28
|
+
* description: 'List the users',
|
|
29
|
+
* groups: ['admin'],
|
|
30
|
+
* rule: async (context: HTTPContext): Promise<boolean> => context.request.headers.authorization === 'Bearer admin'
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* class UserController extends Controller {
|
|
34
|
+
* @GET('/users', adminOnly)
|
|
35
|
+
* public async list(): Promise<string[]> {
|
|
36
|
+
* return []
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
class ActionOptions extends core_1.DTO {
|
|
42
|
+
}
|
|
43
|
+
exports.ActionOptions = ActionOptions;
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, dto_1.Expect)(core_1.DTO.Boolean().optional().default(false)),
|
|
46
|
+
__metadata("design:type", Boolean)
|
|
47
|
+
], ActionOptions.prototype, "acl", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, dto_1.Expect)(core_1.DTO.String().allow('').optional().default('')),
|
|
50
|
+
__metadata("design:type", String)
|
|
51
|
+
], ActionOptions.prototype, "name", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, dto_1.Expect)(core_1.DTO.String().allow('').optional().default('')),
|
|
54
|
+
__metadata("design:type", String)
|
|
55
|
+
], ActionOptions.prototype, "description", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, dto_1.Expect)(core_1.DTO.Array(core_1.DTO.String()).optional().default([])),
|
|
58
|
+
__metadata("design:type", Array)
|
|
59
|
+
], ActionOptions.prototype, "groups", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, dto_1.Expect)(core_1.DTO.Function().optional()),
|
|
62
|
+
__metadata("design:type", Function)
|
|
63
|
+
], ActionOptions.prototype, "rule", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, dto_1.Expect)(core_1.DTO.Array(core_1.DTO.Function()).optional().default([])),
|
|
66
|
+
__metadata("design:type", Array)
|
|
67
|
+
], ActionOptions.prototype, "middlewares", void 0);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base of the results an action returns to describe its output beyond its data (a status, headers, a file, an
|
|
3
|
+
* event stream): {@link StatusResult}, {@link FileResult}, {@link EventsResult}, built with `Result`. The HTTP and CLI
|
|
4
|
+
* adapters output the results they support, and the `data` of the others; the service adapters (Socket.IO, JSON-RPC,
|
|
5
|
+
* Electron IPC, the HTTP service, gRPC, NATS) send the `data` of a `StatusResult` and answer a `FileResult` or an
|
|
6
|
+
* `EventsResult` with an error.
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {ActionResult} from 'lakutata/com/entrypoint'
|
|
10
|
+
*
|
|
11
|
+
* //A result carrying a page of items, an adapter of its own may output its paging
|
|
12
|
+
* export class PageResult<T> extends ActionResult {
|
|
13
|
+
* constructor(public readonly items: T[], public readonly next?: string) {
|
|
14
|
+
* super()
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* public get data(): T[] {
|
|
18
|
+
* return this.items
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class ActionResult {
|
|
24
|
+
/**
|
|
25
|
+
* The result's data: what the adapters not supporting the result output.
|
|
26
|
+
*/
|
|
27
|
+
abstract get data(): unknown;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionResult = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The base of the results an action returns to describe its output beyond its data (a status, headers, a file, an
|
|
6
|
+
* event stream): {@link StatusResult}, {@link FileResult}, {@link EventsResult}, built with `Result`. The HTTP and CLI
|
|
7
|
+
* adapters output the results they support, and the `data` of the others; the service adapters (Socket.IO, JSON-RPC,
|
|
8
|
+
* Electron IPC, the HTTP service, gRPC, NATS) send the `data` of a `StatusResult` and answer a `FileResult` or an
|
|
9
|
+
* `EventsResult` with an error.
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import {ActionResult} from 'lakutata/com/entrypoint'
|
|
13
|
+
*
|
|
14
|
+
* //A result carrying a page of items, an adapter of its own may output its paging
|
|
15
|
+
* export class PageResult<T> extends ActionResult {
|
|
16
|
+
* constructor(public readonly items: T[], public readonly next?: string) {
|
|
17
|
+
* super()
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* public get data(): T[] {
|
|
21
|
+
* return this.items
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
class ActionResult {
|
|
27
|
+
}
|
|
28
|
+
exports.ActionResult = ActionResult;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applicationOf = applicationOf;
|
|
4
|
+
const core_1 = require("@lakutata/core");
|
|
5
|
+
/**
|
|
6
|
+
* The application a module belongs to (undefined out of an application: a container of the tests)
|
|
7
|
+
* @param module
|
|
8
|
+
*/
|
|
9
|
+
function applicationOf(module) {
|
|
10
|
+
let target = module;
|
|
11
|
+
while (target && !(target instanceof core_1.Application))
|
|
12
|
+
target = target.getParent?.();
|
|
13
|
+
return target;
|
|
14
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Provider } from '@lakutata/core';
|
|
2
|
+
import { CLIContext } from '../context/CLIContext.js';
|
|
3
|
+
import { HTTPContext } from '../context/HTTPContext.js';
|
|
4
|
+
import { ServiceContext } from '../context/ServiceContext.js';
|
|
5
|
+
import { BaseContext } from '../context/BaseContext.js';
|
|
6
|
+
/**
|
|
7
|
+
* The names of a controller's own members (the ones {@link Controller} does not declare): the methods an action
|
|
8
|
+
* decorator may be applied to.
|
|
9
|
+
*/
|
|
10
|
+
export type ControllerProperty<ClassPrototype extends Controller> = Exclude<keyof ClassPrototype, keyof Controller>;
|
|
11
|
+
/**
|
|
12
|
+
* The base class of the controllers: classes whose methods, decorated with the action decorators (`@GET`, `@POST`…,
|
|
13
|
+
* `@CLIAction`, `@ServiceAction`, `@Schedule`), serve the entrypoint's requests. Give the controller classes to the
|
|
14
|
+
* entrypoint's `controllers` option.
|
|
15
|
+
*
|
|
16
|
+
* A controller is scoped: each request creates its own instance in the request's container, with the request's
|
|
17
|
+
* context and abort signal, and destroys it when the request ends; its injected providers are scoped to the request
|
|
18
|
+
* too. An action method receives its input (the request's data merged with the address parameters, validated by the
|
|
19
|
+
* action's DTO, its defaults applied) and returns the result the adapter outputs; the actions declared in a parent
|
|
20
|
+
* class are served by the registered subclasses.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import {DTO} from 'lakutata'
|
|
24
|
+
* import {Controller, HTTPContext} from 'lakutata/com/entrypoint'
|
|
25
|
+
* import {CLIAction, GET, ServiceAction} from 'lakutata/decorator/ctrl'
|
|
26
|
+
* import {Expect} from 'lakutata/decorator/dto'
|
|
27
|
+
*
|
|
28
|
+
* class FindUserDTO extends DTO {
|
|
29
|
+
* @Expect(DTO.String().required())
|
|
30
|
+
* public id: string
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* class UserController extends Controller {
|
|
34
|
+
* //The same action over HTTP (GET /users/:id), the CLI (user-get --id 1) and the services ({act: 'user.get', id})
|
|
35
|
+
* @GET('/users/:id', FindUserDTO)
|
|
36
|
+
* @CLIAction('user-get', FindUserDTO)
|
|
37
|
+
* @ServiceAction({act: 'user.get'}, FindUserDTO)
|
|
38
|
+
* public async get(input: FindUserDTO): Promise<{id: string, via: string}> {
|
|
39
|
+
* this.signal?.throwIfAborted()
|
|
40
|
+
* const via: string = this.context instanceof HTTPContext ? this.context.request.headers['user-agent'] ?? 'http' : this.context.type
|
|
41
|
+
* return {id: input.id, via: via}
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class Controller extends Provider {
|
|
47
|
+
/**
|
|
48
|
+
* The request's context: an {@link HTTPContext}, {@link CLIContext}, {@link ServiceContext}, or the context of
|
|
49
|
+
* another channel (`ScheduleContext`…); check its `type` or its class to tell them apart.
|
|
50
|
+
* @protected
|
|
51
|
+
*/
|
|
52
|
+
protected readonly context: CLIContext | HTTPContext | ServiceContext | BaseContext;
|
|
53
|
+
/**
|
|
54
|
+
* Aborts when the request is aborted: its client gone (the HTTP connection closed, the gRPC call cancelled), its
|
|
55
|
+
* deadline passed, or the entrypoint stopping. Long-running actions should stop then: their result is dropped.
|
|
56
|
+
* @protected
|
|
57
|
+
*/
|
|
58
|
+
protected readonly signal?: AbortSignal;
|
|
59
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Controller = void 0;
|
|
13
|
+
const core_1 = require("@lakutata/core");
|
|
14
|
+
const di_1 = require("@lakutata/core/decorator/di");
|
|
15
|
+
const BaseContext_js_1 = require("../context/BaseContext.js");
|
|
16
|
+
/**
|
|
17
|
+
* The base class of the controllers: classes whose methods, decorated with the action decorators (`@GET`, `@POST`…,
|
|
18
|
+
* `@CLIAction`, `@ServiceAction`, `@Schedule`), serve the entrypoint's requests. Give the controller classes to the
|
|
19
|
+
* entrypoint's `controllers` option.
|
|
20
|
+
*
|
|
21
|
+
* A controller is scoped: each request creates its own instance in the request's container, with the request's
|
|
22
|
+
* context and abort signal, and destroys it when the request ends; its injected providers are scoped to the request
|
|
23
|
+
* too. An action method receives its input (the request's data merged with the address parameters, validated by the
|
|
24
|
+
* action's DTO, its defaults applied) and returns the result the adapter outputs; the actions declared in a parent
|
|
25
|
+
* class are served by the registered subclasses.
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import {DTO} from 'lakutata'
|
|
29
|
+
* import {Controller, HTTPContext} from 'lakutata/com/entrypoint'
|
|
30
|
+
* import {CLIAction, GET, ServiceAction} from 'lakutata/decorator/ctrl'
|
|
31
|
+
* import {Expect} from 'lakutata/decorator/dto'
|
|
32
|
+
*
|
|
33
|
+
* class FindUserDTO extends DTO {
|
|
34
|
+
* @Expect(DTO.String().required())
|
|
35
|
+
* public id: string
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* class UserController extends Controller {
|
|
39
|
+
* //The same action over HTTP (GET /users/:id), the CLI (user-get --id 1) and the services ({act: 'user.get', id})
|
|
40
|
+
* @GET('/users/:id', FindUserDTO)
|
|
41
|
+
* @CLIAction('user-get', FindUserDTO)
|
|
42
|
+
* @ServiceAction({act: 'user.get'}, FindUserDTO)
|
|
43
|
+
* public async get(input: FindUserDTO): Promise<{id: string, via: string}> {
|
|
44
|
+
* this.signal?.throwIfAborted()
|
|
45
|
+
* const via: string = this.context instanceof HTTPContext ? this.context.request.headers['user-agent'] ?? 'http' : this.context.type
|
|
46
|
+
* return {id: input.id, via: via}
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
let Controller = class Controller extends core_1.Provider {
|
|
52
|
+
};
|
|
53
|
+
exports.Controller = Controller;
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, di_1.Configurable)(core_1.DTO.InstanceOf(BaseContext_js_1.BaseContext).required()),
|
|
56
|
+
__metadata("design:type", Object)
|
|
57
|
+
], Controller.prototype, "context", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
(0, di_1.Configurable)(core_1.DTO.InstanceOf(AbortSignal).optional()),
|
|
60
|
+
__metadata("design:type", AbortSignal)
|
|
61
|
+
], Controller.prototype, "signal", void 0);
|
|
62
|
+
exports.Controller = Controller = __decorate([
|
|
63
|
+
(0, di_1.Scoped)(true)
|
|
64
|
+
], Controller);
|