@tahminator/sapling 2.0.3 → 2.0.5-beta.2f539758
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 +94 -4
- package/dist/index.cjs +337 -137
- package/dist/index.d.cts +478 -13
- package/dist/index.d.mts +478 -13
- package/dist/index.mjs +322 -138
- package/package.json +4 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e, { ErrorRequestHandler, NextFunction, Request, Response, Router } from "express";
|
|
1
|
+
import e, { ErrorRequestHandler, NextFunction, Request, Response as Response$1, Router } from "express";
|
|
2
2
|
|
|
3
3
|
//#region src/html/404.d.ts
|
|
4
4
|
/**
|
|
@@ -26,7 +26,7 @@ type RouteDefinition = {
|
|
|
26
26
|
};
|
|
27
27
|
type Class<T> = new (...args: any[]) => T;
|
|
28
28
|
type HttpHeaders = Record<string, string>;
|
|
29
|
-
type ExpressMiddlewareFn = ($1: Request, $2: Response, $3: NextFunction) => void;
|
|
29
|
+
type ExpressMiddlewareFn = ($1: Request, $2: Response$1, $3: NextFunction) => void;
|
|
30
30
|
//#endregion
|
|
31
31
|
//#region src/annotation/controller.d.ts
|
|
32
32
|
declare const _ControllerRegistry: WeakMap<Function, Router | ErrorRequestHandler>;
|
|
@@ -230,6 +230,45 @@ declare namespace StandardSchemaV1 {
|
|
|
230
230
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
231
231
|
}
|
|
232
232
|
/** The Standard JSON Schema interface. */
|
|
233
|
+
interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
234
|
+
/** The Standard JSON Schema properties. */
|
|
235
|
+
readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
|
|
236
|
+
}
|
|
237
|
+
declare namespace StandardJSONSchemaV1 {
|
|
238
|
+
/** The Standard JSON Schema properties interface. */
|
|
239
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
240
|
+
/** Methods for generating the input/output JSON Schema. */
|
|
241
|
+
readonly jsonSchema: StandardJSONSchemaV1.Converter;
|
|
242
|
+
}
|
|
243
|
+
/** The Standard JSON Schema converter interface. */
|
|
244
|
+
interface Converter {
|
|
245
|
+
/** Converts the input type to JSON Schema. May throw if conversion is not supported. */
|
|
246
|
+
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
247
|
+
/** Converts the output type to JSON Schema. May throw if conversion is not supported. */
|
|
248
|
+
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The target version of the generated JSON Schema.
|
|
252
|
+
*
|
|
253
|
+
* It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
|
|
254
|
+
*
|
|
255
|
+
* The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
|
|
256
|
+
*/
|
|
257
|
+
type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
|
|
258
|
+
/** The options for the input/output methods. */
|
|
259
|
+
interface Options {
|
|
260
|
+
/** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
|
|
261
|
+
readonly target: Target;
|
|
262
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
263
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
264
|
+
}
|
|
265
|
+
/** The Standard types interface. */
|
|
266
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
267
|
+
/** Infers the input type of a Standard. */
|
|
268
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
269
|
+
/** Infers the output type of a Standard. */
|
|
270
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
271
|
+
}
|
|
233
272
|
//#endregion
|
|
234
273
|
//#region src/helper/redirect.d.ts
|
|
235
274
|
/**
|
|
@@ -481,37 +520,463 @@ declare class Sapling {
|
|
|
481
520
|
* Replace the function used for `deserialize`
|
|
482
521
|
*/
|
|
483
522
|
static setDeserializeFn(this: void, fn: (value: string) => any): void;
|
|
523
|
+
static setOpenApiPath(this: void, path: string): void;
|
|
484
524
|
}
|
|
485
525
|
//#endregion
|
|
526
|
+
//#region node_modules/.pnpm/openapi-types@12.1.3/node_modules/openapi-types/dist/index.d.ts
|
|
527
|
+
declare namespace OpenAPIV3 {
|
|
528
|
+
interface Document<T extends {} = {}> {
|
|
529
|
+
openapi: string;
|
|
530
|
+
info: InfoObject;
|
|
531
|
+
servers?: ServerObject[];
|
|
532
|
+
paths: PathsObject<T>;
|
|
533
|
+
components?: ComponentsObject;
|
|
534
|
+
security?: SecurityRequirementObject[];
|
|
535
|
+
tags?: TagObject[];
|
|
536
|
+
externalDocs?: ExternalDocumentationObject;
|
|
537
|
+
'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
538
|
+
'x-express-openapi-validation-strict'?: boolean;
|
|
539
|
+
}
|
|
540
|
+
interface InfoObject {
|
|
541
|
+
title: string;
|
|
542
|
+
description?: string;
|
|
543
|
+
termsOfService?: string;
|
|
544
|
+
contact?: ContactObject;
|
|
545
|
+
license?: LicenseObject;
|
|
546
|
+
version: string;
|
|
547
|
+
}
|
|
548
|
+
interface ContactObject {
|
|
549
|
+
name?: string;
|
|
550
|
+
url?: string;
|
|
551
|
+
email?: string;
|
|
552
|
+
}
|
|
553
|
+
interface LicenseObject {
|
|
554
|
+
name: string;
|
|
555
|
+
url?: string;
|
|
556
|
+
}
|
|
557
|
+
interface ServerObject {
|
|
558
|
+
url: string;
|
|
559
|
+
description?: string;
|
|
560
|
+
variables?: {
|
|
561
|
+
[variable: string]: ServerVariableObject;
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
interface ServerVariableObject {
|
|
565
|
+
enum?: string[];
|
|
566
|
+
default: string;
|
|
567
|
+
description?: string;
|
|
568
|
+
}
|
|
569
|
+
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
570
|
+
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
571
|
+
}
|
|
572
|
+
enum HttpMethods {
|
|
573
|
+
GET = "get",
|
|
574
|
+
PUT = "put",
|
|
575
|
+
POST = "post",
|
|
576
|
+
DELETE = "delete",
|
|
577
|
+
OPTIONS = "options",
|
|
578
|
+
HEAD = "head",
|
|
579
|
+
PATCH = "patch",
|
|
580
|
+
TRACE = "trace"
|
|
581
|
+
}
|
|
582
|
+
type PathItemObject<T extends {} = {}> = {
|
|
583
|
+
$ref?: string;
|
|
584
|
+
summary?: string;
|
|
585
|
+
description?: string;
|
|
586
|
+
servers?: ServerObject[];
|
|
587
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
588
|
+
} & { [method in HttpMethods]?: OperationObject<T> };
|
|
589
|
+
type OperationObject<T extends {} = {}> = {
|
|
590
|
+
tags?: string[];
|
|
591
|
+
summary?: string;
|
|
592
|
+
description?: string;
|
|
593
|
+
externalDocs?: ExternalDocumentationObject;
|
|
594
|
+
operationId?: string;
|
|
595
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
596
|
+
requestBody?: ReferenceObject | RequestBodyObject;
|
|
597
|
+
responses: ResponsesObject;
|
|
598
|
+
callbacks?: {
|
|
599
|
+
[callback: string]: ReferenceObject | CallbackObject;
|
|
600
|
+
};
|
|
601
|
+
deprecated?: boolean;
|
|
602
|
+
security?: SecurityRequirementObject[];
|
|
603
|
+
servers?: ServerObject[];
|
|
604
|
+
} & T;
|
|
605
|
+
interface ExternalDocumentationObject {
|
|
606
|
+
description?: string;
|
|
607
|
+
url: string;
|
|
608
|
+
}
|
|
609
|
+
interface ParameterObject extends ParameterBaseObject {
|
|
610
|
+
name: string;
|
|
611
|
+
in: string;
|
|
612
|
+
}
|
|
613
|
+
interface HeaderObject extends ParameterBaseObject {}
|
|
614
|
+
interface ParameterBaseObject {
|
|
615
|
+
description?: string;
|
|
616
|
+
required?: boolean;
|
|
617
|
+
deprecated?: boolean;
|
|
618
|
+
allowEmptyValue?: boolean;
|
|
619
|
+
style?: string;
|
|
620
|
+
explode?: boolean;
|
|
621
|
+
allowReserved?: boolean;
|
|
622
|
+
schema?: ReferenceObject | SchemaObject;
|
|
623
|
+
example?: any;
|
|
624
|
+
examples?: {
|
|
625
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
626
|
+
};
|
|
627
|
+
content?: {
|
|
628
|
+
[media: string]: MediaTypeObject;
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
|
|
632
|
+
type ArraySchemaObjectType = 'array';
|
|
633
|
+
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
634
|
+
interface ArraySchemaObject extends BaseSchemaObject {
|
|
635
|
+
type: ArraySchemaObjectType;
|
|
636
|
+
items: ReferenceObject | SchemaObject;
|
|
637
|
+
}
|
|
638
|
+
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
639
|
+
type?: NonArraySchemaObjectType;
|
|
640
|
+
}
|
|
641
|
+
interface BaseSchemaObject {
|
|
642
|
+
title?: string;
|
|
643
|
+
description?: string;
|
|
644
|
+
format?: string;
|
|
645
|
+
default?: any;
|
|
646
|
+
multipleOf?: number;
|
|
647
|
+
maximum?: number;
|
|
648
|
+
exclusiveMaximum?: boolean;
|
|
649
|
+
minimum?: number;
|
|
650
|
+
exclusiveMinimum?: boolean;
|
|
651
|
+
maxLength?: number;
|
|
652
|
+
minLength?: number;
|
|
653
|
+
pattern?: string;
|
|
654
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
655
|
+
maxItems?: number;
|
|
656
|
+
minItems?: number;
|
|
657
|
+
uniqueItems?: boolean;
|
|
658
|
+
maxProperties?: number;
|
|
659
|
+
minProperties?: number;
|
|
660
|
+
required?: string[];
|
|
661
|
+
enum?: any[];
|
|
662
|
+
properties?: {
|
|
663
|
+
[name: string]: ReferenceObject | SchemaObject;
|
|
664
|
+
};
|
|
665
|
+
allOf?: (ReferenceObject | SchemaObject)[];
|
|
666
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
667
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
668
|
+
not?: ReferenceObject | SchemaObject;
|
|
669
|
+
nullable?: boolean;
|
|
670
|
+
discriminator?: DiscriminatorObject;
|
|
671
|
+
readOnly?: boolean;
|
|
672
|
+
writeOnly?: boolean;
|
|
673
|
+
xml?: XMLObject;
|
|
674
|
+
externalDocs?: ExternalDocumentationObject;
|
|
675
|
+
example?: any;
|
|
676
|
+
deprecated?: boolean;
|
|
677
|
+
}
|
|
678
|
+
interface DiscriminatorObject {
|
|
679
|
+
propertyName: string;
|
|
680
|
+
mapping?: {
|
|
681
|
+
[value: string]: string;
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
interface XMLObject {
|
|
685
|
+
name?: string;
|
|
686
|
+
namespace?: string;
|
|
687
|
+
prefix?: string;
|
|
688
|
+
attribute?: boolean;
|
|
689
|
+
wrapped?: boolean;
|
|
690
|
+
}
|
|
691
|
+
interface ReferenceObject {
|
|
692
|
+
$ref: string;
|
|
693
|
+
}
|
|
694
|
+
interface ExampleObject {
|
|
695
|
+
summary?: string;
|
|
696
|
+
description?: string;
|
|
697
|
+
value?: any;
|
|
698
|
+
externalValue?: string;
|
|
699
|
+
}
|
|
700
|
+
interface MediaTypeObject {
|
|
701
|
+
schema?: ReferenceObject | SchemaObject;
|
|
702
|
+
example?: any;
|
|
703
|
+
examples?: {
|
|
704
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
705
|
+
};
|
|
706
|
+
encoding?: {
|
|
707
|
+
[media: string]: EncodingObject;
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
interface EncodingObject {
|
|
711
|
+
contentType?: string;
|
|
712
|
+
headers?: {
|
|
713
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
714
|
+
};
|
|
715
|
+
style?: string;
|
|
716
|
+
explode?: boolean;
|
|
717
|
+
allowReserved?: boolean;
|
|
718
|
+
}
|
|
719
|
+
interface RequestBodyObject {
|
|
720
|
+
description?: string;
|
|
721
|
+
content: {
|
|
722
|
+
[media: string]: MediaTypeObject;
|
|
723
|
+
};
|
|
724
|
+
required?: boolean;
|
|
725
|
+
}
|
|
726
|
+
interface ResponsesObject {
|
|
727
|
+
[code: string]: ReferenceObject | ResponseObject;
|
|
728
|
+
}
|
|
729
|
+
interface ResponseObject {
|
|
730
|
+
description: string;
|
|
731
|
+
headers?: {
|
|
732
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
733
|
+
};
|
|
734
|
+
content?: {
|
|
735
|
+
[media: string]: MediaTypeObject;
|
|
736
|
+
};
|
|
737
|
+
links?: {
|
|
738
|
+
[link: string]: ReferenceObject | LinkObject;
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
interface LinkObject {
|
|
742
|
+
operationRef?: string;
|
|
743
|
+
operationId?: string;
|
|
744
|
+
parameters?: {
|
|
745
|
+
[parameter: string]: any;
|
|
746
|
+
};
|
|
747
|
+
requestBody?: any;
|
|
748
|
+
description?: string;
|
|
749
|
+
server?: ServerObject;
|
|
750
|
+
}
|
|
751
|
+
interface CallbackObject {
|
|
752
|
+
[url: string]: PathItemObject;
|
|
753
|
+
}
|
|
754
|
+
interface SecurityRequirementObject {
|
|
755
|
+
[name: string]: string[];
|
|
756
|
+
}
|
|
757
|
+
interface ComponentsObject {
|
|
758
|
+
schemas?: {
|
|
759
|
+
[key: string]: ReferenceObject | SchemaObject;
|
|
760
|
+
};
|
|
761
|
+
responses?: {
|
|
762
|
+
[key: string]: ReferenceObject | ResponseObject;
|
|
763
|
+
};
|
|
764
|
+
parameters?: {
|
|
765
|
+
[key: string]: ReferenceObject | ParameterObject;
|
|
766
|
+
};
|
|
767
|
+
examples?: {
|
|
768
|
+
[key: string]: ReferenceObject | ExampleObject;
|
|
769
|
+
};
|
|
770
|
+
requestBodies?: {
|
|
771
|
+
[key: string]: ReferenceObject | RequestBodyObject;
|
|
772
|
+
};
|
|
773
|
+
headers?: {
|
|
774
|
+
[key: string]: ReferenceObject | HeaderObject;
|
|
775
|
+
};
|
|
776
|
+
securitySchemes?: {
|
|
777
|
+
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
778
|
+
};
|
|
779
|
+
links?: {
|
|
780
|
+
[key: string]: ReferenceObject | LinkObject;
|
|
781
|
+
};
|
|
782
|
+
callbacks?: {
|
|
783
|
+
[key: string]: ReferenceObject | CallbackObject;
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
787
|
+
interface HttpSecurityScheme {
|
|
788
|
+
type: 'http';
|
|
789
|
+
description?: string;
|
|
790
|
+
scheme: string;
|
|
791
|
+
bearerFormat?: string;
|
|
792
|
+
}
|
|
793
|
+
interface ApiKeySecurityScheme {
|
|
794
|
+
type: 'apiKey';
|
|
795
|
+
description?: string;
|
|
796
|
+
name: string;
|
|
797
|
+
in: string;
|
|
798
|
+
}
|
|
799
|
+
interface OAuth2SecurityScheme {
|
|
800
|
+
type: 'oauth2';
|
|
801
|
+
description?: string;
|
|
802
|
+
flows: {
|
|
803
|
+
implicit?: {
|
|
804
|
+
authorizationUrl: string;
|
|
805
|
+
refreshUrl?: string;
|
|
806
|
+
scopes: {
|
|
807
|
+
[scope: string]: string;
|
|
808
|
+
};
|
|
809
|
+
};
|
|
810
|
+
password?: {
|
|
811
|
+
tokenUrl: string;
|
|
812
|
+
refreshUrl?: string;
|
|
813
|
+
scopes: {
|
|
814
|
+
[scope: string]: string;
|
|
815
|
+
};
|
|
816
|
+
};
|
|
817
|
+
clientCredentials?: {
|
|
818
|
+
tokenUrl: string;
|
|
819
|
+
refreshUrl?: string;
|
|
820
|
+
scopes: {
|
|
821
|
+
[scope: string]: string;
|
|
822
|
+
};
|
|
823
|
+
};
|
|
824
|
+
authorizationCode?: {
|
|
825
|
+
authorizationUrl: string;
|
|
826
|
+
tokenUrl: string;
|
|
827
|
+
refreshUrl?: string;
|
|
828
|
+
scopes: {
|
|
829
|
+
[scope: string]: string;
|
|
830
|
+
};
|
|
831
|
+
};
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
interface OpenIdSecurityScheme {
|
|
835
|
+
type: 'openIdConnect';
|
|
836
|
+
description?: string;
|
|
837
|
+
openIdConnectUrl: string;
|
|
838
|
+
}
|
|
839
|
+
interface TagObject {
|
|
840
|
+
name: string;
|
|
841
|
+
description?: string;
|
|
842
|
+
externalDocs?: ExternalDocumentationObject;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
//#endregion
|
|
846
|
+
//#region src/helper/openapi.d.ts
|
|
847
|
+
type OpenAPIConfig = {
|
|
848
|
+
title: string;
|
|
849
|
+
version: string;
|
|
850
|
+
description?: string;
|
|
851
|
+
};
|
|
852
|
+
declare class OpenAPIGenerator {
|
|
853
|
+
private controllers;
|
|
854
|
+
private config;
|
|
855
|
+
setConfig(config: OpenAPIConfig): void;
|
|
856
|
+
registerController(controllerClass: Function, prefix: string): void;
|
|
857
|
+
generateSpec(): OpenAPIV3.Document;
|
|
858
|
+
private toJsonSchema;
|
|
859
|
+
}
|
|
860
|
+
declare const openApiGenerator: OpenAPIGenerator;
|
|
861
|
+
declare function _registerControllerClass(controllerClass: Function, prefix: string): void;
|
|
862
|
+
declare function setOpenApiConfig(config: OpenAPIConfig): void;
|
|
863
|
+
declare function generateOpenApiSpec(): OpenAPIV3.Document;
|
|
864
|
+
//#endregion
|
|
486
865
|
//#region src/annotation/request.d.ts
|
|
487
866
|
type RequestSchemaDefinition = {
|
|
488
|
-
body?: StandardSchemaV1;
|
|
489
|
-
param?: StandardSchemaV1;
|
|
490
|
-
query?: StandardSchemaV1;
|
|
867
|
+
body?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
868
|
+
param?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
869
|
+
query?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
491
870
|
};
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
871
|
+
/**
|
|
872
|
+
* Apply to a route method to have `request.body` be parsed by `schema`.
|
|
873
|
+
*
|
|
874
|
+
* This annotation will parse `request.body` & then override `request.body`.
|
|
875
|
+
* You can then just simply cast `request.body` for your use
|
|
876
|
+
*
|
|
877
|
+
* @example
|
|
878
|
+
* ```ts
|
|
879
|
+
* const CREATE_BOOK_REQUEST_BODY_SCHEMA = z.object({
|
|
880
|
+
* name: z.string(),
|
|
881
|
+
* description: z.string().optional(),
|
|
882
|
+
* });
|
|
883
|
+
*
|
|
884
|
+
* ⠀@Controller({ prefix: "/api/book" })
|
|
885
|
+
* class BookController {
|
|
886
|
+
* ⠀@RequestBody(CREATE_BOOK_REQUEST_BODY_SCHEMA)
|
|
887
|
+
* ⠀@POST()
|
|
888
|
+
* public createBook(request: e.Request) {
|
|
889
|
+
* const { name, description } = request.body as unknown as z.infer<
|
|
890
|
+
* typeof CREATE_BOOK_REQUEST_BODY_SCHEMA
|
|
891
|
+
* >;
|
|
892
|
+
* }
|
|
893
|
+
* }
|
|
894
|
+
* ```
|
|
895
|
+
*/
|
|
896
|
+
declare function RequestBody(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
897
|
+
/**
|
|
898
|
+
* Apply to a route method to have `request.param` be parsed by `schema`.
|
|
899
|
+
*
|
|
900
|
+
* This annotation will parse `request.param` & then override `request.param`.
|
|
901
|
+
* You can then just simply cast `request.param` for your use
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```ts
|
|
905
|
+
* const GET_BOOK_REQUEST_PARAM_SCHEMA = z.object({
|
|
906
|
+
* bookId: z.string(),
|
|
907
|
+
* });
|
|
908
|
+
*
|
|
909
|
+
* ⠀@Controller({ prefix: "/api/book" })
|
|
910
|
+
* class BookController {
|
|
911
|
+
* ⠀@RequestParam(GET_BOOK_REQUEST_PARAM_SCHEMA)
|
|
912
|
+
* ⠀@GET("/:bookId")
|
|
913
|
+
* public getBook(request: e.Request) {
|
|
914
|
+
* const { bookId } = request.param as unknown as z.infer<
|
|
915
|
+
* typeof GET_BOOK_REQUEST_PARAM_SCHEMA
|
|
916
|
+
* >;
|
|
917
|
+
* }
|
|
918
|
+
* }
|
|
919
|
+
* ```
|
|
920
|
+
*/
|
|
921
|
+
declare function RequestParam(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
922
|
+
/**
|
|
923
|
+
* Apply to a route method to have `request.query` be parsed by `schema`.
|
|
924
|
+
*
|
|
925
|
+
* This annotation will parse `request.query` & then override `request.query`.
|
|
926
|
+
* You can then just simply cast `request.query` for your use
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```ts
|
|
930
|
+
* const LIST_BOOKS_REQUEST_QUERY_SCHEMA = z.object({
|
|
931
|
+
* sort: z.enum(["name", "createdAt"]).optional(),
|
|
932
|
+
* q: z.string().optional(),
|
|
933
|
+
* });
|
|
934
|
+
*
|
|
935
|
+
* ⠀@Controller({ prefix: "/api/book" })
|
|
936
|
+
* class BookController {
|
|
937
|
+
* ⠀@RequestQuery(LIST_BOOKS_REQUEST_QUERY_SCHEMA)
|
|
938
|
+
* ⠀@GET()
|
|
939
|
+
* public listBooks(request: e.Request) {
|
|
940
|
+
* const { sort, q } = request.query as unknown as z.infer<
|
|
941
|
+
* typeof LIST_BOOKS_REQUEST_QUERY_SCHEMA
|
|
942
|
+
* >;
|
|
943
|
+
* }
|
|
944
|
+
* }
|
|
945
|
+
* ```
|
|
946
|
+
*/
|
|
947
|
+
declare function RequestQuery(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
495
948
|
declare function _getRequestSchemas(ctor: Function, fnName: string): RequestSchemaDefinition | undefined;
|
|
496
949
|
declare function _parseOrThrow<TSchema extends StandardSchemaV1>(schema: TSchema, input: unknown, kind: ParserErrorLocation): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
497
950
|
//#endregion
|
|
498
|
-
//#region src/middleware/default/base.d.ts
|
|
951
|
+
//#region src/middleware/default/error/base.d.ts
|
|
499
952
|
/**
|
|
500
953
|
* This should be registered last in the middleware chain.
|
|
501
954
|
*
|
|
502
955
|
* All exception messages are hidden from the request by default.
|
|
503
956
|
*/
|
|
504
957
|
declare class DefaultBaseErrorMiddleware {
|
|
505
|
-
handle(err: unknown, _request: Request, _response: Response, _next: NextFunction): ResponseEntity<{
|
|
958
|
+
handle(err: unknown, _request: Request, _response: Response$1, _next: NextFunction): ResponseEntity<{
|
|
506
959
|
message: string;
|
|
507
960
|
}>;
|
|
508
961
|
}
|
|
509
962
|
//#endregion
|
|
510
|
-
//#region src/middleware/default/
|
|
963
|
+
//#region src/middleware/default/error/parse.d.ts
|
|
964
|
+
declare class DefaultParserErrorMiddleware {
|
|
965
|
+
handle(err: unknown, _request: Request, _response: Response$1, next: NextFunction): ResponseEntity<{
|
|
966
|
+
message: string;
|
|
967
|
+
}> | undefined;
|
|
968
|
+
}
|
|
969
|
+
//#endregion
|
|
970
|
+
//#region src/middleware/default/error/responsestatus.d.ts
|
|
511
971
|
declare class DefaultResponseStatusErrorMiddleware {
|
|
512
|
-
handle(err: unknown, _request: Request, _response: Response, next: NextFunction): ResponseEntity<{
|
|
972
|
+
handle(err: unknown, _request: Request, _response: Response$1, next: NextFunction): ResponseEntity<{
|
|
513
973
|
message: string;
|
|
514
974
|
}> | undefined;
|
|
515
975
|
}
|
|
516
976
|
//#endregion
|
|
517
|
-
|
|
977
|
+
//#region src/middleware/default/openapi/index.d.ts
|
|
978
|
+
declare class DefaultOpenApiMiddleware {
|
|
979
|
+
handle(_request: Request, _response: Response$1, _next: NextFunction): ResponseEntity<OpenAPIV3.Document<{}>>;
|
|
980
|
+
}
|
|
981
|
+
//#endregion
|
|
982
|
+
export { Class, Controller, DELETE, DefaultBaseErrorMiddleware, DefaultOpenApiMiddleware, DefaultParserErrorMiddleware, DefaultResponseStatusErrorMiddleware, ExpressMiddlewareFn, ExpressRouterMethodKey, ExpressRouterMethods, GET, HEAD, Html404ErrorPage, HttpHeaders, HttpStatus, Injectable, Middleware, MiddlewareClass, OPTIONS, PATCH, POST, PUT, ParserError, ParserErrorLocation, RedirectView, RequestBody, RequestParam, RequestQuery, ResponseEntity, ResponseEntityBuilder, ResponseStatusError, RouteDefinition, Sapling, _ControllerRegistry, _InjectableDeps, _InjectableRegistry, _Route, _getRequestSchemas, _getRoutes, _parseOrThrow, _registerControllerClass, _resolve, generateOpenApiSpec, methodResolve, openApiGenerator, setOpenApiConfig };
|