@c9up/ream 0.1.25 → 0.1.27
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/README.md +65 -0
- package/dist/ConfigLoader.d.ts +46 -5
- package/dist/ConfigLoader.d.ts.map +1 -1
- package/dist/ConfigLoader.js +60 -9
- package/dist/ConfigLoader.js.map +1 -1
- package/dist/HttpKernel.d.ts.map +1 -1
- package/dist/HttpKernel.js +46 -6
- package/dist/HttpKernel.js.map +1 -1
- package/dist/Ignitor.d.ts +115 -7
- package/dist/Ignitor.d.ts.map +1 -1
- package/dist/Ignitor.js +254 -40
- package/dist/Ignitor.js.map +1 -1
- package/dist/console/BaseCommand.d.ts +217 -0
- package/dist/console/BaseCommand.d.ts.map +1 -0
- package/dist/console/BaseCommand.js +340 -0
- package/dist/console/BaseCommand.js.map +1 -0
- package/dist/console/Console.d.ts +86 -0
- package/dist/console/Console.d.ts.map +1 -0
- package/dist/console/Console.js +134 -0
- package/dist/console/Console.js.map +1 -0
- package/dist/console/ExceptionHandler.d.ts +28 -0
- package/dist/console/ExceptionHandler.d.ts.map +1 -0
- package/dist/console/ExceptionHandler.js +76 -0
- package/dist/console/ExceptionHandler.js.map +1 -0
- package/dist/console/HelpCommand.d.ts +16 -0
- package/dist/console/HelpCommand.d.ts.map +1 -0
- package/dist/console/HelpCommand.js +40 -0
- package/dist/console/HelpCommand.js.map +1 -0
- package/dist/console/IndexGenerator.d.ts +24 -0
- package/dist/console/IndexGenerator.d.ts.map +1 -0
- package/dist/console/IndexGenerator.js +65 -0
- package/dist/console/IndexGenerator.js.map +1 -0
- package/dist/console/Kernel.d.ts +298 -0
- package/dist/console/Kernel.d.ts.map +1 -0
- package/dist/console/Kernel.js +1120 -0
- package/dist/console/Kernel.js.map +1 -0
- package/dist/console/ListCommand.d.ts +18 -0
- package/dist/console/ListCommand.d.ts.map +1 -0
- package/dist/console/ListCommand.js +60 -0
- package/dist/console/ListCommand.js.map +1 -0
- package/dist/console/assertions.d.ts +20 -0
- package/dist/console/assertions.d.ts.map +1 -0
- package/dist/console/assertions.js +84 -0
- package/dist/console/assertions.js.map +1 -0
- package/dist/console/cliui.d.ts +248 -0
- package/dist/console/cliui.d.ts.map +1 -0
- package/dist/console/cliui.js +587 -0
- package/dist/console/cliui.js.map +1 -0
- package/dist/console/decorators.d.ts +90 -0
- package/dist/console/decorators.d.ts.map +1 -0
- package/dist/console/decorators.js +142 -0
- package/dist/console/decorators.js.map +1 -0
- package/dist/console/index.d.ts +32 -0
- package/dist/console/index.d.ts.map +1 -0
- package/dist/console/index.js +24 -0
- package/dist/console/index.js.map +1 -0
- package/dist/console/loaders.d.ts +52 -0
- package/dist/console/loaders.d.ts.map +1 -0
- package/dist/console/loaders.js +131 -0
- package/dist/console/loaders.js.map +1 -0
- package/dist/console/parser.d.ts +86 -0
- package/dist/console/parser.d.ts.map +1 -0
- package/dist/console/parser.js +440 -0
- package/dist/console/parser.js.map +1 -0
- package/dist/console/prompts.d.ts +124 -0
- package/dist/console/prompts.d.ts.map +1 -0
- package/dist/console/prompts.js +356 -0
- package/dist/console/prompts.js.map +1 -0
- package/dist/console/tracing.d.ts +17 -0
- package/dist/console/tracing.d.ts.map +1 -0
- package/dist/console/tracing.js +11 -0
- package/dist/console/tracing.js.map +1 -0
- package/dist/console/types.d.ts +255 -0
- package/dist/console/types.d.ts.map +1 -0
- package/dist/console/types.js +25 -0
- package/dist/console/types.js.map +1 -0
- package/dist/console/ui.d.ts +20 -0
- package/dist/console/ui.d.ts.map +1 -0
- package/dist/console/ui.js +31 -0
- package/dist/console/ui.js.map +1 -0
- package/dist/console/utils.d.ts +27 -0
- package/dist/console/utils.d.ts.map +1 -0
- package/dist/console/utils.js +56 -0
- package/dist/console/utils.js.map +1 -0
- package/dist/container/Container.d.ts +23 -3
- package/dist/container/Container.d.ts.map +1 -1
- package/dist/container/Container.js +177 -70
- package/dist/container/Container.js.map +1 -1
- package/dist/container/types.d.ts +14 -2
- package/dist/container/types.d.ts.map +1 -1
- package/dist/decorators/Service.d.ts +7 -0
- package/dist/decorators/Service.d.ts.map +1 -1
- package/dist/decorators/Service.js +23 -3
- package/dist/decorators/Service.js.map +1 -1
- package/dist/env/Env.d.ts +29 -4
- package/dist/env/Env.d.ts.map +1 -1
- package/dist/env/Env.js +27 -4
- package/dist/env/Env.js.map +1 -1
- package/dist/env/Secret.d.ts +11 -0
- package/dist/env/Secret.d.ts.map +1 -0
- package/dist/env/Secret.js +36 -0
- package/dist/env/Secret.js.map +1 -0
- package/dist/env/interpolate.d.ts +26 -0
- package/dist/env/interpolate.d.ts.map +1 -0
- package/dist/env/interpolate.js +48 -0
- package/dist/env/interpolate.js.map +1 -0
- package/dist/env/loadEnvFiles.d.ts.map +1 -1
- package/dist/env/loadEnvFiles.js +14 -4
- package/dist/env/loadEnvFiles.js.map +1 -1
- package/dist/env/schema.d.ts +23 -6
- package/dist/env/schema.d.ts.map +1 -1
- package/dist/env/schema.js +67 -33
- package/dist/env/schema.js.map +1 -1
- package/dist/errors/ReamError.d.ts +25 -0
- package/dist/errors/ReamError.d.ts.map +1 -1
- package/dist/errors/ReamError.js +5 -0
- package/dist/errors/ReamError.js.map +1 -1
- package/dist/errors/prettyPrintError.d.ts +9 -0
- package/dist/errors/prettyPrintError.d.ts.map +1 -0
- package/dist/errors/prettyPrintError.js +22 -0
- package/dist/errors/prettyPrintError.js.map +1 -0
- package/dist/events/Emitter.d.ts +1 -1
- package/dist/events/Emitter.d.ts.map +1 -1
- package/dist/events/Emitter.js +1 -1
- package/dist/events/Emitter.js.map +1 -1
- package/dist/events/EventsProvider.d.ts +2 -2
- package/dist/events/EventsProvider.d.ts.map +1 -1
- package/dist/events/EventsProvider.js +3 -3
- package/dist/events/EventsProvider.js.map +1 -1
- package/dist/graphql/GraphQLEngine.d.ts +1 -1
- package/dist/graphql/GraphQLEngine.d.ts.map +1 -1
- package/dist/graphql/GraphQLEngine.js +2 -2
- package/dist/graphql/GraphQLEngine.js.map +1 -1
- package/dist/graphql/GraphQLProvider.d.ts.map +1 -1
- package/dist/graphql/GraphQLProvider.js +7 -3
- package/dist/graphql/GraphQLProvider.js.map +1 -1
- package/dist/http/Exception.d.ts +63 -1
- package/dist/http/Exception.d.ts.map +1 -1
- package/dist/http/Exception.js +185 -48
- package/dist/http/Exception.js.map +1 -1
- package/dist/http/HttpContext.d.ts +53 -7
- package/dist/http/HttpContext.d.ts.map +1 -1
- package/dist/http/HttpContext.js +56 -15
- package/dist/http/HttpContext.js.map +1 -1
- package/dist/http/RedirectBuilder.d.ts.map +1 -1
- package/dist/http/RedirectBuilder.js +4 -1
- package/dist/http/RedirectBuilder.js.map +1 -1
- package/dist/http/Request.d.ts +141 -10
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +244 -34
- package/dist/http/Request.js.map +1 -1
- package/dist/http/Response.d.ts +176 -9
- package/dist/http/Response.d.ts.map +1 -1
- package/dist/http/Response.js +404 -16
- package/dist/http/Response.js.map +1 -1
- package/dist/index.d.ts +19 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/dist/middleware/Pipeline.d.ts +29 -8
- package/dist/middleware/Pipeline.d.ts.map +1 -1
- package/dist/middleware/Pipeline.js +40 -2
- package/dist/middleware/Pipeline.js.map +1 -1
- package/dist/openapi/OpenApiProvider.js +4 -4
- package/dist/openapi/OpenApiProvider.js.map +1 -1
- package/dist/router/Router.d.ts +223 -31
- package/dist/router/Router.d.ts.map +1 -1
- package/dist/router/Router.js +520 -102
- package/dist/router/Router.js.map +1 -1
- package/dist/rpc/RpcProvider.d.ts +1 -0
- package/dist/rpc/RpcProvider.d.ts.map +1 -1
- package/dist/rpc/RpcProvider.js +7 -3
- package/dist/rpc/RpcProvider.js.map +1 -1
- package/dist/rpc/RpcRouter.d.ts +2 -2
- package/dist/rpc/RpcRouter.d.ts.map +1 -1
- package/dist/rpc/RpcRouter.js +17 -5
- package/dist/rpc/RpcRouter.js.map +1 -1
- package/dist/scheduler/ScheduleProvider.d.ts.map +1 -1
- package/dist/scheduler/ScheduleProvider.js +7 -15
- package/dist/scheduler/ScheduleProvider.js.map +1 -1
- package/dist/server/Server.d.ts +17 -4
- package/dist/server/Server.d.ts.map +1 -1
- package/dist/server/Server.js +41 -7
- package/dist/server/Server.js.map +1 -1
- package/dist/services/app.d.ts +1 -1
- package/dist/services/app.js +1 -1
- package/dist/services/console.d.ts +21 -0
- package/dist/services/console.d.ts.map +1 -0
- package/dist/services/console.js +35 -0
- package/dist/services/console.js.map +1 -0
- package/dist/session/SessionMiddleware.js +3 -3
- package/dist/session/SessionMiddleware.js.map +1 -1
- package/dist/storage/StaticProvider.js +1 -1
- package/dist/storage/StaticProvider.js.map +1 -1
- package/dist/testing/ApiResponse.d.ts +218 -0
- package/dist/testing/ApiResponse.d.ts.map +1 -0
- package/dist/testing/ApiResponse.js +576 -0
- package/dist/testing/ApiResponse.js.map +1 -0
- package/dist/testing/RequestBuilder.d.ts +155 -35
- package/dist/testing/RequestBuilder.d.ts.map +1 -1
- package/dist/testing/RequestBuilder.js +455 -109
- package/dist/testing/RequestBuilder.js.map +1 -1
- package/dist/testing/TestClient.d.ts +53 -37
- package/dist/testing/TestClient.d.ts.map +1 -1
- package/dist/testing/TestClient.js +84 -52
- package/dist/testing/TestClient.js.map +1 -1
- package/dist/utils/Macroable.d.ts +30 -0
- package/dist/utils/Macroable.d.ts.map +1 -0
- package/dist/utils/Macroable.js +43 -0
- package/dist/utils/Macroable.js.map +1 -0
- package/dist/utils/inflect.d.ts +17 -0
- package/dist/utils/inflect.d.ts.map +1 -0
- package/dist/utils/inflect.js +32 -0
- package/dist/utils/inflect.js.map +1 -0
- package/dist/utils/objectPath.d.ts +57 -0
- package/dist/utils/objectPath.d.ts.map +1 -0
- package/dist/utils/objectPath.js +141 -0
- package/dist/utils/objectPath.js.map +1 -0
- package/events.darwin-arm64.node +0 -0
- package/events.darwin-x64.node +0 -0
- package/events.linux-arm64-gnu.node +0 -0
- package/events.linux-x64-gnu.node +0 -0
- package/events.win32-x64-msvc.node +0 -0
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +20 -2
- package/scheduler.darwin-arm64.node +0 -0
- package/scheduler.darwin-x64.node +0 -0
- package/scheduler.linux-arm64-gnu.node +0 -0
- package/scheduler.linux-x64-gnu.node +0 -0
- package/scheduler.win32-x64-msvc.node +0 -0
- package/src/ConfigLoader.ts +72 -9
- package/src/HttpKernel.ts +53 -15
- package/src/Ignitor.ts +364 -45
- package/src/console/BaseCommand.ts +467 -0
- package/src/console/Console.ts +174 -0
- package/src/console/ExceptionHandler.ts +91 -0
- package/src/console/HelpCommand.ts +37 -0
- package/src/console/IndexGenerator.ts +79 -0
- package/src/console/Kernel.ts +1382 -0
- package/src/console/ListCommand.ts +55 -0
- package/src/console/assertions.ts +114 -0
- package/src/console/cliui.ts +756 -0
- package/src/console/decorators.ts +199 -0
- package/src/console/index.ts +67 -0
- package/src/console/loaders.ts +145 -0
- package/src/console/parser.ts +598 -0
- package/src/console/prompts.ts +548 -0
- package/src/console/tracing.ts +22 -0
- package/src/console/types.ts +280 -0
- package/src/console/ui.ts +37 -0
- package/src/console/utils.ts +69 -0
- package/src/container/Container.ts +198 -72
- package/src/container/types.ts +15 -2
- package/src/decorators/Service.ts +28 -3
- package/src/env/Env.ts +49 -5
- package/src/env/Secret.ts +41 -0
- package/src/env/interpolate.ts +54 -0
- package/src/env/loadEnvFiles.ts +12 -4
- package/src/env/schema.ts +109 -35
- package/src/errors/ReamError.ts +31 -0
- package/src/errors/prettyPrintError.ts +20 -0
- package/src/events/Emitter.ts +2 -2
- package/src/events/EventsProvider.ts +5 -5
- package/src/graphql/GraphQLEngine.ts +4 -4
- package/src/graphql/GraphQLProvider.ts +7 -3
- package/src/http/Exception.ts +214 -37
- package/src/http/HttpContext.ts +87 -18
- package/src/http/RedirectBuilder.ts +4 -1
- package/src/http/Request.ts +264 -34
- package/src/http/Response.ts +478 -27
- package/src/index.ts +41 -6
- package/src/middleware/Pipeline.ts +77 -6
- package/src/openapi/OpenApiProvider.ts +4 -4
- package/src/router/Router.ts +631 -113
- package/src/rpc/RpcProvider.ts +6 -2
- package/src/rpc/RpcRouter.ts +22 -7
- package/src/scheduler/ScheduleProvider.ts +7 -15
- package/src/server/Server.ts +49 -10
- package/src/services/app.ts +1 -1
- package/src/services/console.ts +42 -0
- package/src/session/SessionMiddleware.ts +4 -4
- package/src/storage/StaticProvider.ts +1 -1
- package/src/testing/ApiResponse.ts +691 -0
- package/src/testing/RequestBuilder.ts +577 -137
- package/src/testing/TestClient.ts +110 -77
- package/src/utils/Macroable.ts +54 -0
- package/src/utils/inflect.ts +29 -0
- package/src/utils/objectPath.ts +142 -0
- package/dist/console/CommandRunner.d.ts +0 -18
- package/dist/console/CommandRunner.d.ts.map +0 -1
- package/dist/console/CommandRunner.js +0 -65
- package/dist/console/CommandRunner.js.map +0 -1
- package/dist/decorators/Lazy.d.ts +0 -19
- package/dist/decorators/Lazy.d.ts.map +0 -1
- package/dist/decorators/Lazy.js +0 -53
- package/dist/decorators/Lazy.js.map +0 -1
- package/src/console/CommandRunner.ts +0 -82
- package/src/decorators/Lazy.ts +0 -57
package/dist/index.js
CHANGED
|
@@ -6,17 +6,19 @@
|
|
|
6
6
|
import 'reflect-metadata';
|
|
7
7
|
// ─── Core ───────────────────────────────────────────────────
|
|
8
8
|
export { Application } from './Application.js';
|
|
9
|
-
export { ConfigStore, defineModuleConfig, env } from './ConfigLoader.js';
|
|
9
|
+
export { ConfigStore, configProvider, defineModuleConfig, env } from './ConfigLoader.js';
|
|
10
10
|
export { Container } from './container/Container.js';
|
|
11
11
|
export { Env, EnvValidationException } from './env/Env.js';
|
|
12
12
|
export { loadEnvFiles } from './env/loadEnvFiles.js';
|
|
13
|
+
export { Secret } from './env/Secret.js';
|
|
13
14
|
export { EnvVarError, } from './env/schema.js';
|
|
14
15
|
// ─── HTTP (new — AdonisJS-compatible) ───────────────────────
|
|
15
|
-
export { E_FORBIDDEN, E_HTTP_EXCEPTION, E_ROUTE_NOT_FOUND, E_ROW_NOT_FOUND, E_UNAUTHORIZED, E_VALIDATION_ERROR, Exception, ExceptionHandler, } from './http/Exception.js';
|
|
16
|
+
export { createError, E_FORBIDDEN, E_HTTP_EXCEPTION, E_ROUTE_NOT_FOUND, E_ROW_NOT_FOUND, E_UNAUTHORIZED, E_VALIDATION_ERROR, Exception, ExceptionHandler, InvalidArgumentsException, RuntimeException, } from './http/Exception.js';
|
|
16
17
|
export { HttpContext } from './http/HttpContext.js';
|
|
17
18
|
export { RedirectBuilder } from './http/RedirectBuilder.js';
|
|
18
19
|
export { Request } from './http/Request.js';
|
|
19
20
|
export { Response } from './http/Response.js';
|
|
21
|
+
export { Macroable } from './utils/Macroable.js';
|
|
20
22
|
// ─── Session ────────────────────────────────────────────────
|
|
21
23
|
export { CookieDriver as SessionCookieDriver } from './session/drivers/CookieDriver.js';
|
|
22
24
|
export { MemoryDriver as SessionMemoryDriver } from './session/drivers/MemoryDriver.js';
|
|
@@ -39,13 +41,26 @@ export { CookieSigner } from './security/CookieSigner.js';
|
|
|
39
41
|
export { constantTimeEq, hasNativeCrypto, hmacSign, hmacVerify, randomBytesBase64, randomHex, setNapi, } from './security/crypto.js';
|
|
40
42
|
export { SignedUrl } from './security/SignedUrl.js';
|
|
41
43
|
// ─── Decorators ─────────────────────────────────────────────
|
|
42
|
-
export { createLazyProxy, getLazyParams, Lazy } from './decorators/Lazy.js';
|
|
43
44
|
export { clearServiceRegistry, getServiceMetadata, getServiceRegistry, Inject, inject, Service, } from './decorators/Service.js';
|
|
44
45
|
export { GroupBuilder, matchers, OnRouteBuilder, RouteBuilder, Router } from './router/Router.js';
|
|
45
46
|
export { compose, MiddlewareRegistry } from './middleware/Pipeline.js';
|
|
46
47
|
export { createHttpKernel } from './HttpKernel.js';
|
|
47
48
|
export { resolveMiddlewareEntry, Server } from './server/Server.js';
|
|
48
|
-
|
|
49
|
+
// ─── Ignitor ────────────────────────────────────────────────
|
|
50
|
+
export { BaseCommand } from './console/BaseCommand.js';
|
|
51
|
+
export { Logger, Ui } from './console/cliui.js';
|
|
52
|
+
export { args, flags } from './console/decorators.js';
|
|
53
|
+
// Renamed at the root: Ream already exports an HTTP `ExceptionHandler`, and
|
|
54
|
+
// two different things under one name is worse than a longer one. It keeps its
|
|
55
|
+
// Console name on the console entry point.
|
|
56
|
+
export { ExceptionHandler as ConsoleExceptionHandler } from './console/ExceptionHandler.js';
|
|
57
|
+
export { default as HelpCommand } from './console/HelpCommand.js';
|
|
58
|
+
export { IndexGenerator } from './console/IndexGenerator.js';
|
|
59
|
+
export { Kernel } from './console/Kernel.js';
|
|
60
|
+
export { default as ListCommand } from './console/ListCommand.js';
|
|
61
|
+
export { FsLoader, ListLoader } from './console/loaders.js';
|
|
62
|
+
export { Parser } from './console/parser.js';
|
|
63
|
+
export { Prompt, PromptTrap } from './console/prompts.js';
|
|
49
64
|
export { ConsoleKernel, defineConfig, Ignitor, prettyPrintError } from './Ignitor.js';
|
|
50
65
|
export { Provider } from './Provider.js';
|
|
51
66
|
export { createCodemods } from './Codemods.js';
|
|
@@ -53,7 +68,7 @@ export { ErrorBoundary } from './ErrorBoundary.js';
|
|
|
53
68
|
export { didYouMean, findClosestMatches, levenshtein } from './errors/FuzzyMatcher.js';
|
|
54
69
|
export { AtlasError, ContainerError, EventsError, ForgeError, PipelineError, RouterError, RuneError, WardenError, } from './errors/ModuleErrors.js';
|
|
55
70
|
export { createPipelineError, PIPELINE_STAGES, validatePipelineConfig, } from './errors/PipelineStageError.js';
|
|
56
|
-
export { ReamError } from './errors/ReamError.js';
|
|
71
|
+
export { isReamError, ReamError } from './errors/ReamError.js';
|
|
57
72
|
export { installGracefulShutdown } from './GracefulShutdown.js';
|
|
58
73
|
export { HealthCheck } from './HealthCheck.js';
|
|
59
74
|
export { startHotReload } from './HotReload.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,kBAAkB,CAAA;AAEzB,+DAA+D;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,kBAAkB,CAAA;AAEzB,+DAA+D;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAAE,GAAG,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EACL,WAAW,GAMZ,MAAM,iBAAiB,CAAA;AAExB,+DAA+D;AAE/D,OAAO,EACL,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,SAAS,EAGT,gBAAgB,EAChB,yBAAyB,EACzB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,Q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MAAM,eAAe,CAAA;AAK9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtF,OAAO,EACL,UAAU,EACV,cAAc,EACd,WAAW,EACX,UAAU,EACV,aAAa,EACb,WAAW,EACX,SAAS,EACT,WAAW,GACZ,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,sBAAsB,GACvB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAK9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAgB/C,+DAA+D;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAShD,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EACL,SAAS,EAET,OAAO,GAER,MAAM,qBAAqB,CAAA;AAkB5B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACT,YAAY,GACb,MAAM,sBAAsB,CAAA;AAE7B,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
|
|
@@ -12,18 +12,39 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { HttpContext } from '../http/HttpContext.js';
|
|
14
14
|
export type MiddlewareFunction = (ctx: HttpContext, next: () => Promise<void>) => Promise<void> | void;
|
|
15
|
+
/** What a route validator must hand back, whichever method it exposes. */
|
|
16
|
+
export interface RuntimeValidationResult {
|
|
17
|
+
valid: boolean;
|
|
18
|
+
errors: unknown[];
|
|
19
|
+
data?: unknown;
|
|
20
|
+
}
|
|
15
21
|
/**
|
|
16
|
-
* Structural contract for a route validator.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
22
|
+
* Structural contract for a route validator. ream stays decoupled from the
|
|
23
|
+
* validation engine — any object exposing a result-returning check works.
|
|
24
|
+
*
|
|
25
|
+
* Three spellings are accepted because `@c9up/rune` follows VineJS: `validate()`
|
|
26
|
+
* is async and throws, `validateResult()` is synchronous and never throws, and
|
|
27
|
+
* `validateResultAsync()` is the async result-based form.
|
|
28
|
+
*
|
|
29
|
+
* `validateResultAsync` is preferred. The synchronous `validateResult()` cannot
|
|
30
|
+
* run async rules — with `unique`, `exists` or `useAsync` in the schema it
|
|
31
|
+
* throws a plain Error, which would surface as a 500 instead of a 422.
|
|
19
32
|
*/
|
|
20
33
|
export interface RuntimeValidator {
|
|
21
|
-
validate(data: unknown):
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
data?: unknown;
|
|
25
|
-
};
|
|
34
|
+
validate?(data: unknown): RuntimeValidationResult | Promise<unknown>;
|
|
35
|
+
validateResult?(data: unknown): RuntimeValidationResult;
|
|
36
|
+
validateResultAsync?(data: unknown): Promise<RuntimeValidationResult>;
|
|
26
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Run a validator whatever contract it exposes, and always come back with a
|
|
40
|
+
* result object.
|
|
41
|
+
*
|
|
42
|
+
* Order matters: the async result form first (it is the only one that can run
|
|
43
|
+
* `unique` / `exists`), then the synchronous one, then VineJS's throwing
|
|
44
|
+
* `validate()` — awaited, and with its `E_VALIDATION_ERROR` translated back
|
|
45
|
+
* into a result so callers keep a single shape to handle.
|
|
46
|
+
*/
|
|
47
|
+
export declare function runValidator(validator: RuntimeValidator, data: unknown): Promise<RuntimeValidationResult>;
|
|
27
48
|
/** Named middleware registry. */
|
|
28
49
|
export declare class MiddlewareRegistry {
|
|
29
50
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pipeline.d.ts","sourceRoot":"","sources":["../../src/middleware/Pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEzD,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KACtB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAEzB
|
|
1
|
+
{"version":3,"file":"Pipeline.d.ts","sourceRoot":"","sources":["../../src/middleware/Pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEzD,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KACtB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAEzB,0EAA0E;AAC1E,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,OAAO,EAAE,CAAA;IACjB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACpE,cAAc,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,uBAAuB,CAAA;IACvD,mBAAmB,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;CACtE;AAiBD;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,gBAAgB,EAC3B,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,uBAAuB,CAAC,CA0BlC;AAED,iCAAiC;AACjC,qBAAa,kBAAkB;;IAI7B,4DAA4D;IAC5D,GAAG,CAAC,UAAU,EAAE,kBAAkB,GAAG,IAAI;IAIzC,mCAAmC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,IAAI;IAI5D,8BAA8B;IAC9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAIjD,iCAAiC;IACjC,SAAS,IAAI,kBAAkB,EAAE;IAIjC,+CAA+C;IAC/C,UAAU,CACR,eAAe,EAAE,MAAM,EAAE,EACzB,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;QACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;QAChB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;QACtB,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAA;KAChC,GACA,kBAAkB;CAoCtB;AAED,gEAAgE;AAChE,iBAAS,OAAO,CAAC,UAAU,EAAE,kBAAkB,EAAE,GAAG,kBAAkB,CAoBrE;AA8DD,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -12,6 +12,44 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { ReamError } from '../errors/ReamError.js';
|
|
14
14
|
import { E_FORBIDDEN, E_UNAUTHORIZED, E_VALIDATION_ERROR } from '../http/Exception.js';
|
|
15
|
+
function isThrownValidationFailure(value) {
|
|
16
|
+
return (value instanceof Error && 'messages' in value && Array.isArray(Reflect.get(value, 'messages')));
|
|
17
|
+
}
|
|
18
|
+
function isValidationResult(value) {
|
|
19
|
+
return typeof value === 'object' && value !== null && 'valid' in value;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Run a validator whatever contract it exposes, and always come back with a
|
|
23
|
+
* result object.
|
|
24
|
+
*
|
|
25
|
+
* Order matters: the async result form first (it is the only one that can run
|
|
26
|
+
* `unique` / `exists`), then the synchronous one, then VineJS's throwing
|
|
27
|
+
* `validate()` — awaited, and with its `E_VALIDATION_ERROR` translated back
|
|
28
|
+
* into a result so callers keep a single shape to handle.
|
|
29
|
+
*/
|
|
30
|
+
export async function runValidator(validator, data) {
|
|
31
|
+
if (typeof validator.validateResultAsync === 'function') {
|
|
32
|
+
return validator.validateResultAsync(data);
|
|
33
|
+
}
|
|
34
|
+
if (typeof validator.validateResult === 'function') {
|
|
35
|
+
return validator.validateResult(data);
|
|
36
|
+
}
|
|
37
|
+
if (typeof validator.validate === 'function') {
|
|
38
|
+
try {
|
|
39
|
+
const outcome = await validator.validate(data);
|
|
40
|
+
// A result-returning `validate()` (not the VineJS contract) is honoured
|
|
41
|
+
// as-is; the throwing contract resolves to the validated payload.
|
|
42
|
+
return isValidationResult(outcome) ? outcome : { valid: true, errors: [], data: outcome };
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
if (isThrownValidationFailure(err)) {
|
|
46
|
+
return { valid: false, errors: err.messages };
|
|
47
|
+
}
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throw new TypeError('Route validator exposes none of validateResultAsync(), validateResult() or validate().');
|
|
52
|
+
}
|
|
15
53
|
/** Named middleware registry. */
|
|
16
54
|
export class MiddlewareRegistry {
|
|
17
55
|
#global = [];
|
|
@@ -93,7 +131,7 @@ function compose(middleware) {
|
|
|
93
131
|
function createGuardMiddleware(guards, roles, permissions) {
|
|
94
132
|
return async (ctx, next) => {
|
|
95
133
|
const needsAuth = guards.length > 0 || (roles && roles.length > 0) || (permissions && permissions.length > 0);
|
|
96
|
-
if (needsAuth && !ctx.auth.
|
|
134
|
+
if (needsAuth && !ctx.auth.isAuthenticated) {
|
|
97
135
|
throw new E_UNAUTHORIZED();
|
|
98
136
|
}
|
|
99
137
|
// Auth providers may expose roles/permissions at the top level OR nested
|
|
@@ -125,7 +163,7 @@ function createGuardMiddleware(guards, roles, permissions) {
|
|
|
125
163
|
function createValidationMiddleware(validators) {
|
|
126
164
|
return async (ctx, next) => {
|
|
127
165
|
for (const validator of validators) {
|
|
128
|
-
const result = validator
|
|
166
|
+
const result = await runValidator(validator, ctx.request.body());
|
|
129
167
|
if (!result.valid) {
|
|
130
168
|
throw new E_VALIDATION_ERROR(result.errors);
|
|
131
169
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pipeline.js","sourceRoot":"","sources":["../../src/middleware/Pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"Pipeline.js","sourceRoot":"","sources":["../../src/middleware/Pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAsCtF,SAAS,yBAAyB,CAAC,KAAc;IAC/C,OAAO,CACL,KAAK,YAAY,KAAK,IAAI,UAAU,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAC/F,CAAA;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,CAAA;AACxE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,SAA2B,EAC3B,IAAa;IAEb,IAAI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AA;IACd,CAAC,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,0BAA0B,CAAC,UAA8B;IAChE,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;YAChE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBAClB,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAC7C,CAAC;YACD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC9B,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;QACD,MAAM,IAAI,EAAE,CAAA;IACd,CAAC,CAAA;AACH,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -22,8 +22,8 @@ export class OpenApiProvider extends Provider {
|
|
|
22
22
|
const config = this.app.config.get('openapi') ?? {};
|
|
23
23
|
if (config.enabled === false)
|
|
24
24
|
return;
|
|
25
|
-
const generator = this.#override ?? this.#buildGenerator(config);
|
|
26
|
-
const server = this.app.container.make('server');
|
|
25
|
+
const generator = this.#override ?? (await this.#buildGenerator(config));
|
|
26
|
+
const server = await this.app.container.make('server');
|
|
27
27
|
const middleware = new OpenApiMiddleware({
|
|
28
28
|
specPath: config.specPath,
|
|
29
29
|
docsPath: config.docsPath,
|
|
@@ -31,8 +31,8 @@ export class OpenApiProvider extends Provider {
|
|
|
31
31
|
});
|
|
32
32
|
server.use([(ctx, next) => middleware.handle(ctx, next)]);
|
|
33
33
|
}
|
|
34
|
-
#buildGenerator(config) {
|
|
35
|
-
const router = this.app.container.make('router');
|
|
34
|
+
async #buildGenerator(config) {
|
|
35
|
+
const router = await this.app.container.make('router');
|
|
36
36
|
return new OpenApiGenerator(router, {
|
|
37
37
|
title: config.title ?? 'API',
|
|
38
38
|
version: config.version ?? '1.0.0',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiProvider.js","sourceRoot":"","sources":["../../src/openapi/OpenApiProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAoB1D,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAClC,SAAS,CAAmB;IAErC,YAAY,GAAe,EAAE,UAAkC,EAAE;QAC/D,KAAK,CAAC,GAAG,CAAC,CAAA;QACV,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACpC,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAoB,SAAS,CAAC,IAAI,EAAE,CAAA;QACtE,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK;YAAE,OAAM;QAEpC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"OpenApiProvider.js","sourceRoot":"","sources":["../../src/openapi/OpenApiProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAoB1D,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAClC,SAAS,CAAmB;IAErC,YAAY,GAAe,EAAE,UA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ts
CHANGED
|
@@ -5,7 +5,18 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { HttpContext } from '../http/HttpContext.js';
|
|
7
7
|
import type { MiddlewareFunction } from '../middleware/Pipeline.js';
|
|
8
|
+
import type { SignedUrl } from '../security/SignedUrl.js';
|
|
8
9
|
import type { MiddlewareEntry } from '../server/Server.js';
|
|
10
|
+
import { Macroable } from '../utils/Macroable.js';
|
|
11
|
+
/** Options for {@link Router.makeSignedUrl}. */
|
|
12
|
+
export interface SignedUrlOptions {
|
|
13
|
+
/** Extra query-string params folded into the signature. */
|
|
14
|
+
qs?: Record<string, string>;
|
|
15
|
+
/** Lifetime before the link expires — seconds (number) or a `'30m'`/`'2h'`/`'1d'` string. */
|
|
16
|
+
expiresIn?: string | number;
|
|
17
|
+
/** Namespaces the signature so a URL signed for one purpose can't be reused for another. */
|
|
18
|
+
purpose?: string;
|
|
19
|
+
}
|
|
9
20
|
export type RouteHandlerFunction = (ctx: HttpContext) => Promise<void> | void;
|
|
10
21
|
/**
|
|
11
22
|
* Controller tuple: [ControllerClass, 'methodName'].
|
|
@@ -13,8 +24,20 @@ export type RouteHandlerFunction = (ctx: HttpContext) => Promise<void> | void;
|
|
|
13
24
|
* same pattern as AdonisJS (@poppinss/utils Constructor type).
|
|
14
25
|
*/
|
|
15
26
|
export type ControllerAction = [target: new (...args: any[]) => any, method: string];
|
|
16
|
-
/**
|
|
17
|
-
export type
|
|
27
|
+
/** Any controller class (derived from {@link ControllerAction} — no fresh `any`). */
|
|
28
|
+
export type ControllerConstructor = ControllerAction[0];
|
|
29
|
+
/** A lazy controller import: `() => import('#controllers/users_controller')`. */
|
|
30
|
+
export type LazyControllerImport = () => Promise<{
|
|
31
|
+
default: ControllerConstructor;
|
|
32
|
+
}>;
|
|
33
|
+
/** Lazy controller tuple: [() => import(...), 'methodName']. */
|
|
34
|
+
export type LazyControllerAction = [loader: LazyControllerImport, method: string];
|
|
35
|
+
/**
|
|
36
|
+
* A route handler is a closure, a controller tuple, a lazy-import tuple, or a
|
|
37
|
+
* magic string reference `'ControllerName.method'` resolved through the
|
|
38
|
+
* router's controller registry ({@link Router.controllers}).
|
|
39
|
+
*/
|
|
40
|
+
export type RouteHandler = RouteHandlerFunction | ControllerAction | LazyControllerAction | string;
|
|
18
41
|
/** Param matcher — regex or predefined matcher. */
|
|
19
42
|
export type ParamMatcher = RegExp | {
|
|
20
43
|
pattern: RegExp;
|
|
@@ -41,6 +64,33 @@ export interface RouteDefinition {
|
|
|
41
64
|
version: string;
|
|
42
65
|
sunset?: string;
|
|
43
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Soft-delete flag (AdonisJS `route.markAsDeleted()`). A resource's
|
|
69
|
+
* `.only()`/`.except()`/`.apiOnly()` mark filtered-out routes deleted rather
|
|
70
|
+
* than splicing them, so the builder chain stays intact. Deleted routes are
|
|
71
|
+
* skipped by the match index and `getRoutes()`.
|
|
72
|
+
*/
|
|
73
|
+
deleted?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Lazily-imported controller (from a `[() => import(...), 'method']` tuple or
|
|
76
|
+
* a resolved string reference). The HttpKernel awaits the loader on first
|
|
77
|
+
* request and promotes it to {@link controller}, so @Guard metadata + DI
|
|
78
|
+
* resolution flow through the normal controller path.
|
|
79
|
+
*/
|
|
80
|
+
lazyController?: {
|
|
81
|
+
loader: LazyControllerImport;
|
|
82
|
+
method: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Unresolved `'ControllerName.method'` string reference. Resolved to
|
|
86
|
+
* {@link lazyController} against the router's controller registry when the
|
|
87
|
+
* route index is (re)built — a reference to an unregistered controller is a
|
|
88
|
+
* hard error there.
|
|
89
|
+
*/
|
|
90
|
+
stringRef?: {
|
|
91
|
+
controller: string;
|
|
92
|
+
method: string;
|
|
93
|
+
};
|
|
44
94
|
}
|
|
45
95
|
export interface MatchResult {
|
|
46
96
|
route: RouteDefinition;
|
|
@@ -54,12 +104,19 @@ export declare const matchers: {
|
|
|
54
104
|
/** Match slug params only (lowercase alphanumeric + hyphens). */
|
|
55
105
|
slug(): ParamMatcher;
|
|
56
106
|
};
|
|
57
|
-
/**
|
|
58
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Fluent route builder — mutates the already-registered route definition(s).
|
|
109
|
+
* Backed by an array so a multi-verb `router.route(['GET','POST'], …)` returns
|
|
110
|
+
* ONE builder that fans every mutation across all its verbs; the single-verb
|
|
111
|
+
* helpers (`get`/`post`/…) back it with a one-element array.
|
|
112
|
+
*/
|
|
113
|
+
export declare class RouteBuilder extends Macroable {
|
|
59
114
|
#private;
|
|
60
|
-
constructor(
|
|
115
|
+
constructor(routes: RouteDefinition | RouteDefinition[]);
|
|
61
116
|
/** Name this route (for URL generation and redirects). */
|
|
62
117
|
as(name: string): this;
|
|
118
|
+
/** Prepend a URL prefix to this single route (AdonisJS route-level `prefix`). */
|
|
119
|
+
prefix(prefix: string): this;
|
|
63
120
|
/** Add named middleware. */
|
|
64
121
|
middleware(...names: string[]): this;
|
|
65
122
|
/** Add inline middleware functions. */
|
|
@@ -70,8 +127,8 @@ export declare class RouteBuilder {
|
|
|
70
127
|
role(...roles: string[]): this;
|
|
71
128
|
/** Require specific permissions. */
|
|
72
129
|
permission(...permissions: string[]): this;
|
|
73
|
-
/** Add a param constraint. */
|
|
74
|
-
where(param: string, matcher: ParamMatcher | RegExp): this;
|
|
130
|
+
/** Add a param constraint — RegExp, predefined matcher, or a string pattern. */
|
|
131
|
+
where(param: string, matcher: ParamMatcher | RegExp | string): this;
|
|
75
132
|
/**
|
|
76
133
|
* Validate the request body against a named validator. At request time the
|
|
77
134
|
* kernel resolves the validator from the IoC container under the token
|
|
@@ -96,11 +153,21 @@ export declare class RouteBuilder {
|
|
|
96
153
|
deprecates(version: string, options?: {
|
|
97
154
|
sunset?: string;
|
|
98
155
|
}): this;
|
|
99
|
-
/**
|
|
156
|
+
/** The route's name, or undefined when unnamed (AdonisJS `route.getName`). */
|
|
157
|
+
getName(): string | undefined;
|
|
158
|
+
/** The route's URL pattern (AdonisJS `route.getPattern`). */
|
|
159
|
+
getPattern(): string;
|
|
160
|
+
/** Replace the route's URL pattern (AdonisJS `route.setPattern`). */
|
|
161
|
+
setPattern(pattern: string): this;
|
|
162
|
+
/** Soft-delete this route so it stops matching (AdonisJS `route.markAsDeleted`). */
|
|
163
|
+
markAsDeleted(): this;
|
|
164
|
+
/** True when the route has been soft-deleted (AdonisJS `route.isDeleted`). */
|
|
165
|
+
isDeleted(): boolean;
|
|
166
|
+
/** @internal Get the underlying (primary) definition. */
|
|
100
167
|
getDefinition(): RouteDefinition;
|
|
101
168
|
}
|
|
102
169
|
/** Fluent group builder — returned by router.group(callback). */
|
|
103
|
-
export declare class GroupBuilder {
|
|
170
|
+
export declare class GroupBuilder extends Macroable {
|
|
104
171
|
#private;
|
|
105
172
|
constructor(routes: RouteDefinition[]);
|
|
106
173
|
/** Set URL prefix for all routes in the group. */
|
|
@@ -111,26 +178,88 @@ export declare class GroupBuilder {
|
|
|
111
178
|
use(...mw: MiddlewareFunction[]): this;
|
|
112
179
|
/** Add guards to all routes in the group. */
|
|
113
180
|
guard(...guards: string[]): this;
|
|
114
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* Prefix route names for all routes in the group (AdonisJS `group.as`).
|
|
183
|
+
* Every route MUST already be named — prefixing an unnamed route is
|
|
184
|
+
* meaningless, so it throws rather than silently skipping (AdonisJS parity).
|
|
185
|
+
*/
|
|
115
186
|
as(namePrefix: string): this;
|
|
116
187
|
/** Set domain for all routes in the group. */
|
|
117
188
|
domain(d: string): this;
|
|
118
189
|
/** Add param matcher to all routes in the group. */
|
|
119
|
-
where(param: string, matcher: ParamMatcher | RegExp): this;
|
|
190
|
+
where(param: string, matcher: ParamMatcher | RegExp | string): this;
|
|
120
191
|
}
|
|
121
|
-
/**
|
|
192
|
+
/** Resourceful action names (AdonisJS resource). */
|
|
193
|
+
export type ResourceAction = 'index' | 'create' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
|
|
194
|
+
/** Middleware accepted per-action on a resource: a named string or an inline fn. */
|
|
195
|
+
type ResourceMiddleware = string | MiddlewareFunction;
|
|
196
|
+
/**
|
|
197
|
+
* Resourceful route builder — returned by `router.resource()` /
|
|
198
|
+
* `router.shallowResource()` (AdonisJS `RouteResource` parity).
|
|
199
|
+
*
|
|
200
|
+
* Generates the seven RESTful routes (index, create, store, show, edit,
|
|
201
|
+
* update, destroy — `update` registered for both PUT and PATCH) and exposes
|
|
202
|
+
* the fluent filtering/config API: `only`/`except`/`apiOnly`/`params`/`tap`/
|
|
203
|
+
* `where`/`use`/`middleware`/`as`. Nested resources use dot-notation
|
|
204
|
+
* (`posts.comments` → `/posts/:post_id/comments/:id`).
|
|
205
|
+
*/
|
|
206
|
+
export declare class RouteResource extends Macroable {
|
|
207
|
+
#private;
|
|
208
|
+
/** The generated routes, in declaration order (AdonisJS `resource.routes`). */
|
|
209
|
+
readonly routes: RouteBuilder[];
|
|
210
|
+
constructor(options: {
|
|
211
|
+
resource: string;
|
|
212
|
+
controller: ControllerAction[0];
|
|
213
|
+
shallow: boolean;
|
|
214
|
+
register: (def: RouteDefinition) => void;
|
|
215
|
+
markDirty: () => void;
|
|
216
|
+
});
|
|
217
|
+
/** Keep only the given actions; soft-delete the rest (AdonisJS `only`). */
|
|
218
|
+
only(names: ResourceAction[]): this;
|
|
219
|
+
/** Register all actions except the given ones (AdonisJS `except`). */
|
|
220
|
+
except(names: ResourceAction[]): this;
|
|
221
|
+
/** Drop the form-rendering `create` + `edit` actions (AdonisJS `apiOnly`). */
|
|
222
|
+
apiOnly(): this;
|
|
223
|
+
/** Constrain a param across every action route (AdonisJS `resource.where`). */
|
|
224
|
+
where(key: string, matcher: ParamMatcher | RegExp | string): this;
|
|
225
|
+
/**
|
|
226
|
+
* Configure the resource's routes. `tap(cb)` runs `cb` for every non-deleted
|
|
227
|
+
* route; `tap(actions, cb)` only for routes matching `actions` (AdonisJS `tap`).
|
|
228
|
+
*/
|
|
229
|
+
tap(callback: (route: RouteBuilder) => void): this;
|
|
230
|
+
tap(actions: ResourceAction | ResourceAction[], callback: (route: RouteBuilder) => void): this;
|
|
231
|
+
/** Rename the `:id` param of one or more resources (AdonisJS `params`). */
|
|
232
|
+
params(resources: Record<string, string>): this;
|
|
233
|
+
/**
|
|
234
|
+
* Attach middleware to specific actions (or `'*'` for all) — AdonisJS `use`.
|
|
235
|
+
* Named middleware are strings; inline middleware are functions.
|
|
236
|
+
*/
|
|
237
|
+
use(actions: ResourceAction | ResourceAction[] | '*', middleware: ResourceMiddleware | ResourceMiddleware[]): this;
|
|
238
|
+
/** Alias for {@link RouteResource.use} (AdonisJS `middleware`). */
|
|
239
|
+
middleware(actions: ResourceAction | ResourceAction[] | '*', middleware: ResourceMiddleware | ResourceMiddleware[]): this;
|
|
240
|
+
/**
|
|
241
|
+
* Rename the base of every route name (AdonisJS `as`). `normalizeName`
|
|
242
|
+
* snake_cases the new base by default.
|
|
243
|
+
*/
|
|
244
|
+
as(name: string, normalizeName?: boolean): this;
|
|
245
|
+
}
|
|
246
|
+
/** Builder for on(path).render(view) and on(path).redirect(namedRoute). */
|
|
122
247
|
export declare class OnRouteBuilder {
|
|
123
248
|
#private;
|
|
124
249
|
constructor(router: Router, path: string);
|
|
125
250
|
/** Render a view (requires Photon/view provider). */
|
|
126
251
|
render(view: string, data?: Record<string, unknown>): RouteBuilder;
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Redirect to a NAMED route (AdonisJS brisk `redirect`). Mirrors AdonisJS:
|
|
254
|
+
* the first argument is a route name, not a path — use {@link redirectToPath}
|
|
255
|
+
* for a fixed URL.
|
|
256
|
+
*/
|
|
257
|
+
redirect(name: string, params?: Record<string, string>, status?: number): RouteBuilder;
|
|
258
|
+
/** Redirect to a fixed path/URL (AdonisJS brisk `redirectToPath`). */
|
|
259
|
+
redirectToPath(target: string, status?: number): RouteBuilder;
|
|
131
260
|
}
|
|
132
261
|
/** Main Router. */
|
|
133
|
-
export declare class Router {
|
|
262
|
+
export declare class Router extends Macroable {
|
|
134
263
|
#private;
|
|
135
264
|
/** Predefined param matchers. */
|
|
136
265
|
readonly matchers: {
|
|
@@ -147,18 +276,42 @@ export declare class Router {
|
|
|
147
276
|
*/
|
|
148
277
|
use(middleware: MiddlewareEntry[]): this;
|
|
149
278
|
/**
|
|
150
|
-
* Register named middleware collection
|
|
279
|
+
* Register a named middleware collection and return per-name FACTORIES
|
|
280
|
+
* (AdonisJS `defineNamedMiddleware`). Call a factory to bind per-route
|
|
281
|
+
* arguments, then attach the result inline:
|
|
282
|
+
*
|
|
151
283
|
* export const middleware = router.named({
|
|
152
284
|
* auth: () => import('#middleware/auth_middleware'),
|
|
153
285
|
* })
|
|
286
|
+
* router.get('/admin', [AdminController, 'index']).use([middleware.auth({ guards: ['web'] })])
|
|
287
|
+
*
|
|
288
|
+
* By-name usage (`route.middleware('auth')`) still runs the middleware with
|
|
289
|
+
* no arguments — the factory form is only needed to pass `args` to `handle`.
|
|
290
|
+
*/
|
|
291
|
+
named(collection: Record<string, MiddlewareEntry>): Record<string, (args?: unknown) => MiddlewareFunction>;
|
|
292
|
+
/**
|
|
293
|
+
* Register controllers for magic string handler references (AdonisJS lazy
|
|
294
|
+
* controller pattern). Each entry maps a controller name to a lazy import:
|
|
295
|
+
*
|
|
296
|
+
* router.controllers({ UsersController: () => import('#controllers/users_controller') })
|
|
297
|
+
* router.get('/users', 'UsersController.index')
|
|
298
|
+
*
|
|
299
|
+
* The class is imported on first request and resolved through the IoC
|
|
300
|
+
* container (so @inject + @Guard/@Role decorators work). A string reference
|
|
301
|
+
* to a name that was never registered fails loudly when the route index is
|
|
302
|
+
* built.
|
|
154
303
|
*/
|
|
155
|
-
|
|
304
|
+
controllers(map: Record<string, LazyControllerImport>): this;
|
|
156
305
|
/** Get the router-level middleware stack. */
|
|
157
306
|
getRouterMiddleware(): MiddlewareFunction[];
|
|
158
307
|
/** Get a named middleware by name. */
|
|
159
308
|
getNamedMiddleware(name: string): MiddlewareFunction | undefined;
|
|
160
|
-
/**
|
|
161
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Register a route for one verb or several (AdonisJS `route(pattern, methods)`
|
|
311
|
+
* accepts an array). A multi-verb call returns a single builder that
|
|
312
|
+
* configures every verb at once.
|
|
313
|
+
*/
|
|
314
|
+
route(method: string | string[], path: string, handler: RouteHandler): RouteBuilder;
|
|
162
315
|
get(path: string, handler: RouteHandler): RouteBuilder;
|
|
163
316
|
post(path: string, handler: RouteHandler): RouteBuilder;
|
|
164
317
|
put(path: string, handler: RouteHandler): RouteBuilder;
|
|
@@ -169,18 +322,28 @@ export declare class Router {
|
|
|
169
322
|
/** Register a route for all HTTP methods. */
|
|
170
323
|
any(path: string, handler: RouteHandler): RouteBuilder;
|
|
171
324
|
/**
|
|
172
|
-
* Register resourceful routes for a controller.
|
|
173
|
-
*
|
|
325
|
+
* Register resourceful routes for a controller (AdonisJS `resource`).
|
|
326
|
+
*
|
|
327
|
+
* Generates index / create / store / show / edit / update / destroy —
|
|
328
|
+
* `update` for both PUT and PATCH. Returns a {@link RouteResource} for
|
|
329
|
+
* fluent filtering: `.only()`, `.except()`, `.apiOnly()`, `.params()`,
|
|
330
|
+
* `.tap()`, `.where()`, `.use()`, `.as()`.
|
|
331
|
+
*
|
|
332
|
+
* Nested resources use dot-notation (`posts.comments` →
|
|
333
|
+
* `/posts/:post_id/comments/:id`).
|
|
174
334
|
*
|
|
175
335
|
* Usage:
|
|
176
336
|
* router.resource('posts', PostsController)
|
|
177
|
-
*
|
|
178
|
-
* // POST /posts → PostsController.store
|
|
179
|
-
* // GET /posts/:id → PostsController.show
|
|
180
|
-
* // PUT /posts/:id → PostsController.update
|
|
181
|
-
* // DELETE /posts/:id → PostsController.destroy
|
|
337
|
+
* router.resource('posts', PostsController).apiOnly()
|
|
182
338
|
*/
|
|
183
|
-
resource(path: string, controller:
|
|
339
|
+
resource(path: string, controller: ControllerAction[0]): RouteResource;
|
|
340
|
+
/**
|
|
341
|
+
* Register a shallow resource (AdonisJS `shallowResource`). Member routes
|
|
342
|
+
* (show/edit/update/destroy) drop the parent prefix, since the record id
|
|
343
|
+
* alone identifies it: `posts.comments` → `/comments/:id` for members but
|
|
344
|
+
* `/posts/:post_id/comments` for the collection.
|
|
345
|
+
*/
|
|
346
|
+
shallowResource(path: string, controller: ControllerAction[0]): RouteResource;
|
|
184
347
|
/**
|
|
185
348
|
* Create a route group with shared configuration.
|
|
186
349
|
*
|
|
@@ -205,7 +368,7 @@ export declare class Router {
|
|
|
205
368
|
/** Create a view/redirect route shortcut. */
|
|
206
369
|
on(path: string): OnRouteBuilder;
|
|
207
370
|
/** Set a global param matcher (applied to all routes). */
|
|
208
|
-
where(param: string, matcher: ParamMatcher | RegExp): this;
|
|
371
|
+
where(param: string, matcher: ParamMatcher | RegExp | string): this;
|
|
209
372
|
/** Find a matching route, extracting :param values and validating matchers. */
|
|
210
373
|
match(method: string, path: string, host?: string): MatchResult | undefined;
|
|
211
374
|
/**
|
|
@@ -219,6 +382,17 @@ export declare class Router {
|
|
|
219
382
|
* Retained as a thin alias so existing callers keep working.
|
|
220
383
|
*/
|
|
221
384
|
makeUrl(name: string, params?: Record<string, string>): string;
|
|
385
|
+
/** @internal Inject the APP_KEY-backed signed-URL helper (wired by the Ignitor). */
|
|
386
|
+
setSignedUrl(signedUrl: SignedUrl): void;
|
|
387
|
+
/**
|
|
388
|
+
* Generate a tamper-proof signed URL for a named route (AdonisJS
|
|
389
|
+
* `makeSignedUrl`). Delegates to the {@link SignedUrl} helper: appends an HMAC
|
|
390
|
+
* `signature`, plus a signed `expires` timestamp when `expiresIn` is given.
|
|
391
|
+
* Verified on the request side by `request.hasValidSignature()`.
|
|
392
|
+
*
|
|
393
|
+
* Requires an APP_KEY-backed signer (registered when `APP_KEY` is set).
|
|
394
|
+
*/
|
|
395
|
+
makeSignedUrl(name: string, params?: Record<string, string>, options?: SignedUrlOptions): string;
|
|
222
396
|
/**
|
|
223
397
|
* Map of every NAMED route's `name` → path pattern, e.g.
|
|
224
398
|
* `{ 'users.show': '/users/:id' }`. Serialize this into a page so a
|
|
@@ -227,7 +401,24 @@ export declare class Router {
|
|
|
227
401
|
* the server. Powers the aurora client URL helper.
|
|
228
402
|
*/
|
|
229
403
|
namedManifest(): Record<string, string>;
|
|
230
|
-
/**
|
|
404
|
+
/**
|
|
405
|
+
* Generate a TypeScript source string typing every named route and its
|
|
406
|
+
* params (AdonisJS `generateTypes`) — a `RouteName` union plus a
|
|
407
|
+
* `RouteParams` map inferred from each pattern's `:param` segments. Write it
|
|
408
|
+
* to a `.d.ts` so `urlFor(name, params)` is type-checked. Returns the source;
|
|
409
|
+
* the caller decides where to persist it.
|
|
410
|
+
*/
|
|
411
|
+
generateTypes(): string;
|
|
412
|
+
/**
|
|
413
|
+
* Find a registered route by name or exact pattern (AdonisJS `router.find`).
|
|
414
|
+
* Returns null when nothing matches. Soft-deleted routes are ignored.
|
|
415
|
+
*/
|
|
416
|
+
find(identifier: string): RouteDefinition | null;
|
|
417
|
+
/** Like {@link find} but throws when the route is absent (AdonisJS `findOrFail`). */
|
|
418
|
+
findOrFail(identifier: string): RouteDefinition;
|
|
419
|
+
/** True when a route with the given name or pattern exists (AdonisJS `router.has`). */
|
|
420
|
+
has(identifier: string): boolean;
|
|
421
|
+
/** Get all registered (non-deleted) routes (for OpenAPI generation, introspection). */
|
|
231
422
|
getRoutes(): RouteDefinition[];
|
|
232
423
|
/**
|
|
233
424
|
* Clear all registered routes AND registries (used by hot-reload). Router
|
|
@@ -238,4 +429,5 @@ export declare class Router {
|
|
|
238
429
|
clear(): void;
|
|
239
430
|
get routeCount(): number;
|
|
240
431
|
}
|
|
432
|
+
export {};
|
|
241
433
|
//# sourceMappingURL=Router.d.ts.map
|