@tahminator/sapling 2.0.5 → 2.1.0-beta.39c06f1e
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 +161 -12
- package/dist/index.cjs +729 -298
- package/dist/index.d.cts +653 -89
- package/dist/index.d.mts +653 -89
- package/dist/index.mjs +689 -298
- package/package.json +8 -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 as Request$1, RequestHandler, 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$1, $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
|
/**
|
|
@@ -398,16 +437,378 @@ declare class ResponseStatusError extends Error {
|
|
|
398
437
|
}
|
|
399
438
|
//#endregion
|
|
400
439
|
//#region src/helper/error/parse.d.ts
|
|
401
|
-
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery";
|
|
440
|
+
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery" | "resbody";
|
|
402
441
|
/**
|
|
403
|
-
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
442
|
+
* This error should be thrown when some data cannot be parsed by a given Standard Schema compatible schema.
|
|
404
443
|
*/
|
|
405
444
|
declare class ParserError extends ResponseStatusError {
|
|
406
|
-
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string);
|
|
445
|
+
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string, functionName: string);
|
|
407
446
|
private static formatMessage;
|
|
447
|
+
static getPrettyLocationString(location: ParserErrorLocation): "request body" | "request params" | "request query" | "response body";
|
|
448
|
+
}
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region node_modules/.pnpm/openapi-types@12.1.3/node_modules/openapi-types/dist/index.d.ts
|
|
451
|
+
declare namespace OpenAPIV3 {
|
|
452
|
+
interface Document<T extends {} = {}> {
|
|
453
|
+
openapi: string;
|
|
454
|
+
info: InfoObject;
|
|
455
|
+
servers?: ServerObject[];
|
|
456
|
+
paths: PathsObject<T>;
|
|
457
|
+
components?: ComponentsObject;
|
|
458
|
+
security?: SecurityRequirementObject[];
|
|
459
|
+
tags?: TagObject[];
|
|
460
|
+
externalDocs?: ExternalDocumentationObject;
|
|
461
|
+
'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
462
|
+
'x-express-openapi-validation-strict'?: boolean;
|
|
463
|
+
}
|
|
464
|
+
interface InfoObject {
|
|
465
|
+
title: string;
|
|
466
|
+
description?: string;
|
|
467
|
+
termsOfService?: string;
|
|
468
|
+
contact?: ContactObject;
|
|
469
|
+
license?: LicenseObject;
|
|
470
|
+
version: string;
|
|
471
|
+
}
|
|
472
|
+
interface ContactObject {
|
|
473
|
+
name?: string;
|
|
474
|
+
url?: string;
|
|
475
|
+
email?: string;
|
|
476
|
+
}
|
|
477
|
+
interface LicenseObject {
|
|
478
|
+
name: string;
|
|
479
|
+
url?: string;
|
|
480
|
+
}
|
|
481
|
+
interface ServerObject {
|
|
482
|
+
url: string;
|
|
483
|
+
description?: string;
|
|
484
|
+
variables?: {
|
|
485
|
+
[variable: string]: ServerVariableObject;
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
interface ServerVariableObject {
|
|
489
|
+
enum?: string[];
|
|
490
|
+
default: string;
|
|
491
|
+
description?: string;
|
|
492
|
+
}
|
|
493
|
+
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
494
|
+
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
495
|
+
}
|
|
496
|
+
enum HttpMethods {
|
|
497
|
+
GET = "get",
|
|
498
|
+
PUT = "put",
|
|
499
|
+
POST = "post",
|
|
500
|
+
DELETE = "delete",
|
|
501
|
+
OPTIONS = "options",
|
|
502
|
+
HEAD = "head",
|
|
503
|
+
PATCH = "patch",
|
|
504
|
+
TRACE = "trace"
|
|
505
|
+
}
|
|
506
|
+
type PathItemObject<T extends {} = {}> = {
|
|
507
|
+
$ref?: string;
|
|
508
|
+
summary?: string;
|
|
509
|
+
description?: string;
|
|
510
|
+
servers?: ServerObject[];
|
|
511
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
512
|
+
} & { [method in HttpMethods]?: OperationObject<T> };
|
|
513
|
+
type OperationObject<T extends {} = {}> = {
|
|
514
|
+
tags?: string[];
|
|
515
|
+
summary?: string;
|
|
516
|
+
description?: string;
|
|
517
|
+
externalDocs?: ExternalDocumentationObject;
|
|
518
|
+
operationId?: string;
|
|
519
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
520
|
+
requestBody?: ReferenceObject | RequestBodyObject;
|
|
521
|
+
responses: ResponsesObject;
|
|
522
|
+
callbacks?: {
|
|
523
|
+
[callback: string]: ReferenceObject | CallbackObject;
|
|
524
|
+
};
|
|
525
|
+
deprecated?: boolean;
|
|
526
|
+
security?: SecurityRequirementObject[];
|
|
527
|
+
servers?: ServerObject[];
|
|
528
|
+
} & T;
|
|
529
|
+
interface ExternalDocumentationObject {
|
|
530
|
+
description?: string;
|
|
531
|
+
url: string;
|
|
532
|
+
}
|
|
533
|
+
interface ParameterObject extends ParameterBaseObject {
|
|
534
|
+
name: string;
|
|
535
|
+
in: string;
|
|
536
|
+
}
|
|
537
|
+
interface HeaderObject extends ParameterBaseObject {}
|
|
538
|
+
interface ParameterBaseObject {
|
|
539
|
+
description?: string;
|
|
540
|
+
required?: boolean;
|
|
541
|
+
deprecated?: boolean;
|
|
542
|
+
allowEmptyValue?: boolean;
|
|
543
|
+
style?: string;
|
|
544
|
+
explode?: boolean;
|
|
545
|
+
allowReserved?: boolean;
|
|
546
|
+
schema?: ReferenceObject | SchemaObject;
|
|
547
|
+
example?: any;
|
|
548
|
+
examples?: {
|
|
549
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
550
|
+
};
|
|
551
|
+
content?: {
|
|
552
|
+
[media: string]: MediaTypeObject;
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
|
|
556
|
+
type ArraySchemaObjectType = 'array';
|
|
557
|
+
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
558
|
+
interface ArraySchemaObject extends BaseSchemaObject {
|
|
559
|
+
type: ArraySchemaObjectType;
|
|
560
|
+
items: ReferenceObject | SchemaObject;
|
|
561
|
+
}
|
|
562
|
+
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
563
|
+
type?: NonArraySchemaObjectType;
|
|
564
|
+
}
|
|
565
|
+
interface BaseSchemaObject {
|
|
566
|
+
title?: string;
|
|
567
|
+
description?: string;
|
|
568
|
+
format?: string;
|
|
569
|
+
default?: any;
|
|
570
|
+
multipleOf?: number;
|
|
571
|
+
maximum?: number;
|
|
572
|
+
exclusiveMaximum?: boolean;
|
|
573
|
+
minimum?: number;
|
|
574
|
+
exclusiveMinimum?: boolean;
|
|
575
|
+
maxLength?: number;
|
|
576
|
+
minLength?: number;
|
|
577
|
+
pattern?: string;
|
|
578
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
579
|
+
maxItems?: number;
|
|
580
|
+
minItems?: number;
|
|
581
|
+
uniqueItems?: boolean;
|
|
582
|
+
maxProperties?: number;
|
|
583
|
+
minProperties?: number;
|
|
584
|
+
required?: string[];
|
|
585
|
+
enum?: any[];
|
|
586
|
+
properties?: {
|
|
587
|
+
[name: string]: ReferenceObject | SchemaObject;
|
|
588
|
+
};
|
|
589
|
+
allOf?: (ReferenceObject | SchemaObject)[];
|
|
590
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
591
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
592
|
+
not?: ReferenceObject | SchemaObject;
|
|
593
|
+
nullable?: boolean;
|
|
594
|
+
discriminator?: DiscriminatorObject;
|
|
595
|
+
readOnly?: boolean;
|
|
596
|
+
writeOnly?: boolean;
|
|
597
|
+
xml?: XMLObject;
|
|
598
|
+
externalDocs?: ExternalDocumentationObject;
|
|
599
|
+
example?: any;
|
|
600
|
+
deprecated?: boolean;
|
|
601
|
+
}
|
|
602
|
+
interface DiscriminatorObject {
|
|
603
|
+
propertyName: string;
|
|
604
|
+
mapping?: {
|
|
605
|
+
[value: string]: string;
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
interface XMLObject {
|
|
609
|
+
name?: string;
|
|
610
|
+
namespace?: string;
|
|
611
|
+
prefix?: string;
|
|
612
|
+
attribute?: boolean;
|
|
613
|
+
wrapped?: boolean;
|
|
614
|
+
}
|
|
615
|
+
interface ReferenceObject {
|
|
616
|
+
$ref: string;
|
|
617
|
+
}
|
|
618
|
+
interface ExampleObject {
|
|
619
|
+
summary?: string;
|
|
620
|
+
description?: string;
|
|
621
|
+
value?: any;
|
|
622
|
+
externalValue?: string;
|
|
623
|
+
}
|
|
624
|
+
interface MediaTypeObject {
|
|
625
|
+
schema?: ReferenceObject | SchemaObject;
|
|
626
|
+
example?: any;
|
|
627
|
+
examples?: {
|
|
628
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
629
|
+
};
|
|
630
|
+
encoding?: {
|
|
631
|
+
[media: string]: EncodingObject;
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
interface EncodingObject {
|
|
635
|
+
contentType?: string;
|
|
636
|
+
headers?: {
|
|
637
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
638
|
+
};
|
|
639
|
+
style?: string;
|
|
640
|
+
explode?: boolean;
|
|
641
|
+
allowReserved?: boolean;
|
|
642
|
+
}
|
|
643
|
+
interface RequestBodyObject {
|
|
644
|
+
description?: string;
|
|
645
|
+
content: {
|
|
646
|
+
[media: string]: MediaTypeObject;
|
|
647
|
+
};
|
|
648
|
+
required?: boolean;
|
|
649
|
+
}
|
|
650
|
+
interface ResponsesObject {
|
|
651
|
+
[code: string]: ReferenceObject | ResponseObject;
|
|
652
|
+
}
|
|
653
|
+
interface ResponseObject {
|
|
654
|
+
description: string;
|
|
655
|
+
headers?: {
|
|
656
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
657
|
+
};
|
|
658
|
+
content?: {
|
|
659
|
+
[media: string]: MediaTypeObject;
|
|
660
|
+
};
|
|
661
|
+
links?: {
|
|
662
|
+
[link: string]: ReferenceObject | LinkObject;
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
interface LinkObject {
|
|
666
|
+
operationRef?: string;
|
|
667
|
+
operationId?: string;
|
|
668
|
+
parameters?: {
|
|
669
|
+
[parameter: string]: any;
|
|
670
|
+
};
|
|
671
|
+
requestBody?: any;
|
|
672
|
+
description?: string;
|
|
673
|
+
server?: ServerObject;
|
|
674
|
+
}
|
|
675
|
+
interface CallbackObject {
|
|
676
|
+
[url: string]: PathItemObject;
|
|
677
|
+
}
|
|
678
|
+
interface SecurityRequirementObject {
|
|
679
|
+
[name: string]: string[];
|
|
680
|
+
}
|
|
681
|
+
interface ComponentsObject {
|
|
682
|
+
schemas?: {
|
|
683
|
+
[key: string]: ReferenceObject | SchemaObject;
|
|
684
|
+
};
|
|
685
|
+
responses?: {
|
|
686
|
+
[key: string]: ReferenceObject | ResponseObject;
|
|
687
|
+
};
|
|
688
|
+
parameters?: {
|
|
689
|
+
[key: string]: ReferenceObject | ParameterObject;
|
|
690
|
+
};
|
|
691
|
+
examples?: {
|
|
692
|
+
[key: string]: ReferenceObject | ExampleObject;
|
|
693
|
+
};
|
|
694
|
+
requestBodies?: {
|
|
695
|
+
[key: string]: ReferenceObject | RequestBodyObject;
|
|
696
|
+
};
|
|
697
|
+
headers?: {
|
|
698
|
+
[key: string]: ReferenceObject | HeaderObject;
|
|
699
|
+
};
|
|
700
|
+
securitySchemes?: {
|
|
701
|
+
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
702
|
+
};
|
|
703
|
+
links?: {
|
|
704
|
+
[key: string]: ReferenceObject | LinkObject;
|
|
705
|
+
};
|
|
706
|
+
callbacks?: {
|
|
707
|
+
[key: string]: ReferenceObject | CallbackObject;
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
711
|
+
interface HttpSecurityScheme {
|
|
712
|
+
type: 'http';
|
|
713
|
+
description?: string;
|
|
714
|
+
scheme: string;
|
|
715
|
+
bearerFormat?: string;
|
|
716
|
+
}
|
|
717
|
+
interface ApiKeySecurityScheme {
|
|
718
|
+
type: 'apiKey';
|
|
719
|
+
description?: string;
|
|
720
|
+
name: string;
|
|
721
|
+
in: string;
|
|
722
|
+
}
|
|
723
|
+
interface OAuth2SecurityScheme {
|
|
724
|
+
type: 'oauth2';
|
|
725
|
+
description?: string;
|
|
726
|
+
flows: {
|
|
727
|
+
implicit?: {
|
|
728
|
+
authorizationUrl: string;
|
|
729
|
+
refreshUrl?: string;
|
|
730
|
+
scopes: {
|
|
731
|
+
[scope: string]: string;
|
|
732
|
+
};
|
|
733
|
+
};
|
|
734
|
+
password?: {
|
|
735
|
+
tokenUrl: string;
|
|
736
|
+
refreshUrl?: string;
|
|
737
|
+
scopes: {
|
|
738
|
+
[scope: string]: string;
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
clientCredentials?: {
|
|
742
|
+
tokenUrl: string;
|
|
743
|
+
refreshUrl?: string;
|
|
744
|
+
scopes: {
|
|
745
|
+
[scope: string]: string;
|
|
746
|
+
};
|
|
747
|
+
};
|
|
748
|
+
authorizationCode?: {
|
|
749
|
+
authorizationUrl: string;
|
|
750
|
+
tokenUrl: string;
|
|
751
|
+
refreshUrl?: string;
|
|
752
|
+
scopes: {
|
|
753
|
+
[scope: string]: string;
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
interface OpenIdSecurityScheme {
|
|
759
|
+
type: 'openIdConnect';
|
|
760
|
+
description?: string;
|
|
761
|
+
openIdConnectUrl: string;
|
|
762
|
+
}
|
|
763
|
+
interface TagObject {
|
|
764
|
+
name: string;
|
|
765
|
+
description?: string;
|
|
766
|
+
externalDocs?: ExternalDocumentationObject;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
//#endregion
|
|
770
|
+
//#region src/helper/openapi.d.ts
|
|
771
|
+
type OpenAPIMetadata = {
|
|
772
|
+
title: string;
|
|
773
|
+
version: string;
|
|
774
|
+
description?: string;
|
|
775
|
+
};
|
|
776
|
+
declare class OpenAPIGenerator {
|
|
777
|
+
private OPENAPI_VERSION;
|
|
778
|
+
private controllers;
|
|
779
|
+
registerController(controllerClass: Function, prefix: string): void;
|
|
780
|
+
/**
|
|
781
|
+
* visible for testing
|
|
782
|
+
*/
|
|
783
|
+
_clearControllers(): void;
|
|
784
|
+
private get metadata();
|
|
785
|
+
generateSpec(): OpenAPIV3.Document;
|
|
786
|
+
private toJsonSchema;
|
|
408
787
|
}
|
|
788
|
+
declare const openApiGenerator: OpenAPIGenerator;
|
|
789
|
+
declare function _registerController(controllerClass: Function, prefix: string): void;
|
|
790
|
+
declare function generateOpenApiSpec(): OpenAPIV3.Document;
|
|
791
|
+
declare function _clearOpenApiRegistry(): void;
|
|
409
792
|
//#endregion
|
|
410
793
|
//#region src/helper/sapling.d.ts
|
|
794
|
+
type Settings = {
|
|
795
|
+
serialize: (value: any) => string;
|
|
796
|
+
deserialize: (value: string) => any;
|
|
797
|
+
health: {
|
|
798
|
+
ready: {
|
|
799
|
+
path: string;
|
|
800
|
+
};
|
|
801
|
+
live: {
|
|
802
|
+
path: string;
|
|
803
|
+
};
|
|
804
|
+
};
|
|
805
|
+
doc: {
|
|
806
|
+
openApiPath: string;
|
|
807
|
+
swaggerPath: string;
|
|
808
|
+
metadata: OpenAPIMetadata;
|
|
809
|
+
};
|
|
810
|
+
};
|
|
811
|
+
declare const _settings: Settings;
|
|
411
812
|
/**
|
|
412
813
|
* Collection of utility functions which are essential for Sapling to function.
|
|
413
814
|
*/
|
|
@@ -447,12 +848,12 @@ declare class Sapling {
|
|
|
447
848
|
* import { Sapling } from "@tahminator/sapling";
|
|
448
849
|
* import express from "express";
|
|
449
850
|
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
* app.registerApp(app);
|
|
851
|
+
* // returns the exact same `express.App` type back to you!
|
|
852
|
+
* const app = Sapling.registerApp(express());
|
|
453
853
|
* ```
|
|
454
854
|
*/
|
|
455
|
-
static registerApp(app: e.Express):
|
|
855
|
+
static registerApp(app: e.Express): e.Express;
|
|
856
|
+
static onPostStartup(): void;
|
|
456
857
|
/**
|
|
457
858
|
* Serialize a value into a JSON string.
|
|
458
859
|
*
|
|
@@ -481,111 +882,274 @@ declare class Sapling {
|
|
|
481
882
|
* Replace the function used for `deserialize`
|
|
482
883
|
*/
|
|
483
884
|
static setDeserializeFn(this: void, fn: (value: string) => any): void;
|
|
885
|
+
/**
|
|
886
|
+
* Modify extra settings
|
|
887
|
+
*/
|
|
888
|
+
static Extras: {
|
|
889
|
+
/**
|
|
890
|
+
* Modify default settings applied to OpenAPI & Swagger
|
|
891
|
+
*/
|
|
892
|
+
swaggerAndOpenApi: {
|
|
893
|
+
/**
|
|
894
|
+
* Set base OpenAPI metadata values.
|
|
895
|
+
*
|
|
896
|
+
* @default { title: "API", version: "1.0.0" }
|
|
897
|
+
*/
|
|
898
|
+
setMetadata(metadata: OpenAPIMetadata): void;
|
|
899
|
+
/**
|
|
900
|
+
* change default endpoint that will serve OpenAPI spec.
|
|
901
|
+
* Swagger will also load this endpoint on load.
|
|
902
|
+
*
|
|
903
|
+
* @default `/openapi.json`
|
|
904
|
+
*/
|
|
905
|
+
setOpenApiPath(this: void, path: string): void;
|
|
906
|
+
/**
|
|
907
|
+
* change Swagger endpoint.
|
|
908
|
+
*
|
|
909
|
+
* @default `/swagger.html`
|
|
910
|
+
*/
|
|
911
|
+
setSwaggerPath(this: void, path: string): void;
|
|
912
|
+
};
|
|
913
|
+
/**
|
|
914
|
+
* Modify default settings applied to health / readiness / liveness.
|
|
915
|
+
*/
|
|
916
|
+
health: {
|
|
917
|
+
/**
|
|
918
|
+
* change default endpoint that ready endpoint will be served on.
|
|
919
|
+
*
|
|
920
|
+
* @default `/ready`
|
|
921
|
+
*/
|
|
922
|
+
setReadyPath(this: void, path: string): void;
|
|
923
|
+
/**
|
|
924
|
+
* change default endpoint that live endpoint will be served on.
|
|
925
|
+
*
|
|
926
|
+
* @default `/live`
|
|
927
|
+
*/
|
|
928
|
+
setLivePath(this: void, path: string): void;
|
|
929
|
+
};
|
|
930
|
+
};
|
|
931
|
+
/**
|
|
932
|
+
* This method can be used in a `@MiddlewareClass` to register any libraries
|
|
933
|
+
* that expect you to register multiple registers at once. An example is `swagger-ui-express`
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```ts
|
|
937
|
+
* ⠀@MiddlewareClass()
|
|
938
|
+
* class Serve {
|
|
939
|
+
* // `swagger.serve` returns multiple Express handlers for all the assets and routes
|
|
940
|
+
* // that will be served
|
|
941
|
+
* private readonly handlers: RequestHandler[] = swagger.serve;
|
|
942
|
+
*
|
|
943
|
+
* ⠀@Middleware(_settings.doc.swaggerPath)
|
|
944
|
+
* handle(request: Request, response: Response, next: NextFunction) {
|
|
945
|
+
* return Sapling.chainHandlers(this.handlers, request, response, next);
|
|
946
|
+
* }
|
|
947
|
+
* }
|
|
948
|
+
* ```
|
|
949
|
+
*/
|
|
950
|
+
static chainHandlers(this: void, handlers: RequestHandler[], request: Request$1, response: Response$1, next: NextFunction, index?: number): void;
|
|
484
951
|
}
|
|
485
952
|
//#endregion
|
|
486
|
-
//#region src/annotation/
|
|
487
|
-
type
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
953
|
+
//#region src/annotation/validator.d.ts
|
|
954
|
+
type ValidatorSchema = {
|
|
955
|
+
requestBody?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
956
|
+
requestParam?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
957
|
+
requestQuery?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
958
|
+
responseBody?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
959
|
+
};
|
|
960
|
+
declare function ResponseBody(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
961
|
+
declare function RequestBody(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
962
|
+
declare function RequestParam(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
963
|
+
declare function RequestQuery(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
964
|
+
declare function _getOrCreateSchemaDefinition(ctor: Function, fnName: string): ValidatorSchema;
|
|
965
|
+
declare function _parseOrThrow<TSchema extends StandardSchemaV1>(schema: TSchema, input: unknown, location: ParserErrorLocation, fnName: string): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
966
|
+
declare function _saveValidatorSchema(def: ValidatorSchema, key: keyof ValidatorSchema, schema: StandardSchemaV1 & StandardJSONSchemaV1, fnName: string): void;
|
|
967
|
+
declare function _getValidatorSchema(ctor: Function, fnName: string): ValidatorSchema | undefined;
|
|
968
|
+
//#endregion
|
|
969
|
+
//#region src/annotation/schema.d.ts
|
|
970
|
+
type ResponseSchema = {
|
|
971
|
+
statusCode: HttpStatus;
|
|
972
|
+
description?: string;
|
|
973
|
+
schema?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
974
|
+
};
|
|
975
|
+
type RouteSchemaDefinition = {
|
|
976
|
+
summary?: string;
|
|
977
|
+
description?: string;
|
|
978
|
+
responses?: ResponseSchema[];
|
|
491
979
|
};
|
|
980
|
+
type ControllerSchemaDefinition = {
|
|
981
|
+
title?: string;
|
|
982
|
+
description?: string;
|
|
983
|
+
};
|
|
984
|
+
declare function ControllerSchema(options: {
|
|
985
|
+
title?: string;
|
|
986
|
+
description?: string;
|
|
987
|
+
}): ClassDecorator;
|
|
988
|
+
declare function RouteSchema(options: {
|
|
989
|
+
summary?: string;
|
|
990
|
+
description?: string;
|
|
991
|
+
responses?: ResponseSchema[];
|
|
992
|
+
}): MethodDecorator;
|
|
993
|
+
declare function _setRouteSchema(ctor: Function, fnName: string, options: RouteSchemaDefinition): void;
|
|
994
|
+
declare function _setControllerSchema(ctor: Function, options: ControllerSchemaDefinition): void;
|
|
995
|
+
declare function _getRouteSchema(ctor: Function, fnName: string): RouteSchemaDefinition | undefined;
|
|
996
|
+
declare function _getControllerSchema(ctor: Function): ControllerSchemaDefinition | undefined;
|
|
997
|
+
//#endregion
|
|
998
|
+
//#region src/middleware/default/error/base.d.ts
|
|
492
999
|
/**
|
|
493
|
-
*
|
|
1000
|
+
* This should be registered last in the middleware chain.
|
|
494
1001
|
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
1002
|
+
* All exception messages are hidden from the request by default.
|
|
1003
|
+
* If the default is not suitable, you may also easily write your own.
|
|
1004
|
+
*/
|
|
1005
|
+
declare class DefaultBaseErrorMiddleware {
|
|
1006
|
+
handle(err: unknown, _request: Request$1, _response: Response$1, _next: NextFunction): ResponseEntity<{
|
|
1007
|
+
message: string;
|
|
1008
|
+
}>;
|
|
1009
|
+
}
|
|
1010
|
+
//#endregion
|
|
1011
|
+
//#region src/middleware/default/error/parse.d.ts
|
|
1012
|
+
/**
|
|
1013
|
+
* Default error middleware that handles `ParserError`.
|
|
1014
|
+
* If the default is not suitable, you may also easily write your own.
|
|
1015
|
+
*/
|
|
1016
|
+
declare class DefaultParserErrorMiddleware {
|
|
1017
|
+
handle(err: unknown, _request: Request$1, _response: Response$1, next: NextFunction): ResponseEntity<{
|
|
1018
|
+
message: string;
|
|
1019
|
+
}> | undefined;
|
|
1020
|
+
}
|
|
1021
|
+
//#endregion
|
|
1022
|
+
//#region src/middleware/default/error/responsestatus.d.ts
|
|
1023
|
+
/**
|
|
1024
|
+
* Default error middleware that handles `ResponseStatusError`.
|
|
1025
|
+
* If the default is not suitable, you may also easily write your own.
|
|
1026
|
+
*/
|
|
1027
|
+
declare class DefaultResponseStatusErrorMiddleware {
|
|
1028
|
+
handle(err: unknown, _request: Request$1, _response: Response$1, next: NextFunction): ResponseEntity<{
|
|
1029
|
+
message: string;
|
|
1030
|
+
}> | undefined;
|
|
1031
|
+
}
|
|
1032
|
+
//#endregion
|
|
1033
|
+
//#region src/middleware/default/openapi/index.d.ts
|
|
1034
|
+
/**
|
|
1035
|
+
* Enable the serving of the OpenAPI spec autogenerated by Sapling.
|
|
497
1036
|
*
|
|
498
|
-
*
|
|
499
|
-
* ```ts
|
|
500
|
-
* const CREATE_BOOK_REQUEST_BODY_SCHEMA = z.object({
|
|
501
|
-
* name: z.string(),
|
|
502
|
-
* description: z.string().optional(),
|
|
503
|
-
* });
|
|
1037
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
504
1038
|
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
* }
|
|
1039
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
1040
|
+
*
|
|
1041
|
+
* ```ts
|
|
1042
|
+
* const middlewares = [
|
|
1043
|
+
* DefaultOpenApiMiddleware,
|
|
1044
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1045
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1046
|
+
* ];
|
|
1047
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
515
1048
|
* ```
|
|
516
1049
|
*/
|
|
517
|
-
declare
|
|
1050
|
+
declare class DefaultOpenApiMiddleware {
|
|
1051
|
+
handle(_request: Request$1, _response: Response$1, _next: NextFunction): ResponseEntity<OpenAPIV3.Document<{}>>;
|
|
1052
|
+
}
|
|
1053
|
+
//#endregion
|
|
1054
|
+
//#region src/middleware/default/swagger/index.d.ts
|
|
518
1055
|
/**
|
|
519
|
-
*
|
|
1056
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
520
1057
|
*
|
|
521
|
-
*
|
|
522
|
-
* You can then just simply cast `request.param` for your use
|
|
1058
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
523
1059
|
*
|
|
524
|
-
*
|
|
525
|
-
* ```ts
|
|
526
|
-
* const GET_BOOK_REQUEST_PARAM_SCHEMA = z.object({
|
|
527
|
-
* bookId: z.string(),
|
|
528
|
-
* });
|
|
1060
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
529
1061
|
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* >;
|
|
538
|
-
* }
|
|
539
|
-
* }
|
|
1062
|
+
* ```ts
|
|
1063
|
+
* const middlewares = [
|
|
1064
|
+
* DefaultOpenApiMiddleware,
|
|
1065
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1066
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1067
|
+
* ];
|
|
1068
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
540
1069
|
* ```
|
|
541
1070
|
*/
|
|
542
|
-
declare
|
|
1071
|
+
declare class Serve {
|
|
1072
|
+
private readonly handlers;
|
|
1073
|
+
handle(request: Request$1, response: Response$1, next: NextFunction): void;
|
|
1074
|
+
}
|
|
543
1075
|
/**
|
|
544
|
-
*
|
|
1076
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
545
1077
|
*
|
|
546
|
-
*
|
|
547
|
-
* You can then just simply cast `request.query` for your use
|
|
1078
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
548
1079
|
*
|
|
549
|
-
*
|
|
550
|
-
* ```ts
|
|
551
|
-
* const LIST_BOOKS_REQUEST_QUERY_SCHEMA = z.object({
|
|
552
|
-
* sort: z.enum(["name", "createdAt"]).optional(),
|
|
553
|
-
* q: z.string().optional(),
|
|
554
|
-
* });
|
|
1080
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
555
1081
|
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* >;
|
|
564
|
-
* }
|
|
565
|
-
* }
|
|
1082
|
+
* ```ts
|
|
1083
|
+
* const middlewares = [
|
|
1084
|
+
* DefaultOpenApiMiddleware,
|
|
1085
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1086
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1087
|
+
* ];
|
|
1088
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
566
1089
|
* ```
|
|
567
1090
|
*/
|
|
568
|
-
declare
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1091
|
+
declare class Setup {
|
|
1092
|
+
private readonly handler;
|
|
1093
|
+
constructor();
|
|
1094
|
+
handle(request: Request$1, response: Response$1, next: NextFunction): unknown;
|
|
1095
|
+
}
|
|
573
1096
|
/**
|
|
574
|
-
*
|
|
1097
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
575
1098
|
*
|
|
576
|
-
*
|
|
1099
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
1100
|
+
*
|
|
1101
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
1102
|
+
*
|
|
1103
|
+
* ```ts
|
|
1104
|
+
* const middlewares = [
|
|
1105
|
+
* DefaultOpenApiMiddleware,
|
|
1106
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1107
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1108
|
+
* ];
|
|
1109
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
1110
|
+
* ```
|
|
577
1111
|
*/
|
|
578
|
-
declare
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
1112
|
+
declare const DefaultSwaggerMiddleware: {
|
|
1113
|
+
Serve: typeof Serve;
|
|
1114
|
+
Setup: typeof Setup;
|
|
1115
|
+
};
|
|
1116
|
+
//#endregion
|
|
1117
|
+
//#region src/middleware/health/registrar.d.ts
|
|
1118
|
+
type HealthCheck = () => boolean | Promise<boolean>;
|
|
1119
|
+
declare class HealthRegistrar {
|
|
1120
|
+
private _checks;
|
|
1121
|
+
private _ready;
|
|
1122
|
+
constructor();
|
|
1123
|
+
/**
|
|
1124
|
+
* Add a health check.
|
|
1125
|
+
*
|
|
1126
|
+
* Health checks will be used to determine whether service can service traffic or not (a.k.a `liveness`).
|
|
1127
|
+
*/
|
|
1128
|
+
add(healthCheck: HealthCheck): void;
|
|
1129
|
+
/**
|
|
1130
|
+
* @internal used by Sapling library, used to determine once all
|
|
1131
|
+
* checks have been registered and server is, at the very least, alive.
|
|
1132
|
+
*/
|
|
1133
|
+
_markReady(): void;
|
|
1134
|
+
check(): Promise<boolean>;
|
|
582
1135
|
}
|
|
583
1136
|
//#endregion
|
|
584
|
-
//#region src/middleware/default/
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
1137
|
+
//#region src/middleware/default/health/index.d.ts
|
|
1138
|
+
/**
|
|
1139
|
+
* Enable the serving of `ready` and `live` endpoints.
|
|
1140
|
+
*
|
|
1141
|
+
* Configure any middleware-specific settings with `Sapling.Extras.health`
|
|
1142
|
+
* ```
|
|
1143
|
+
*/
|
|
1144
|
+
declare class DefaultHealthMiddleware {
|
|
1145
|
+
private readonly healthRegistrar;
|
|
1146
|
+
constructor(healthRegistrar: HealthRegistrar);
|
|
1147
|
+
readiness(_request: Request, _response: Response, _next: NextFunction): Promise<ResponseEntity<{
|
|
1148
|
+
up: boolean;
|
|
1149
|
+
}>>;
|
|
1150
|
+
liveness(_request: Request, _response: Response, _next: NextFunction): Promise<ResponseEntity<{
|
|
1151
|
+
up: boolean;
|
|
1152
|
+
}>>;
|
|
589
1153
|
}
|
|
590
1154
|
//#endregion
|
|
591
|
-
export { Class, Controller, DELETE, DefaultBaseErrorMiddleware, 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,
|
|
1155
|
+
export { Class, Controller, ControllerSchema, ControllerSchemaDefinition, DELETE, DefaultBaseErrorMiddleware, DefaultHealthMiddleware, DefaultOpenApiMiddleware, DefaultParserErrorMiddleware, DefaultResponseStatusErrorMiddleware, DefaultSwaggerMiddleware, ExpressMiddlewareFn, ExpressRouterMethodKey, ExpressRouterMethods, GET, HEAD, HealthCheck, HealthRegistrar, Html404ErrorPage, HttpHeaders, HttpStatus, Injectable, Middleware, MiddlewareClass, OPTIONS, OpenAPIMetadata, PATCH, POST, PUT, ParserError, ParserErrorLocation, RedirectView, RequestBody, RequestParam, RequestQuery, ResponseBody, ResponseEntity, ResponseEntityBuilder, ResponseSchema, ResponseStatusError, RouteDefinition, RouteSchema, RouteSchemaDefinition, Sapling, ValidatorSchema, _ControllerRegistry, _InjectableDeps, _InjectableRegistry, _Route, _clearOpenApiRegistry, _getControllerSchema, _getOrCreateSchemaDefinition, _getRouteSchema, _getRoutes, _getValidatorSchema, _parseOrThrow, _registerController, _resolve, _saveValidatorSchema, _setControllerSchema, _setRouteSchema, _settings, generateOpenApiSpec, methodResolve, openApiGenerator };
|