@tahminator/sapling 2.0.5 → 2.1.0-beta.a2de2fb9
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 +695 -299
- package/dist/index.d.cts +614 -86
- package/dist/index.d.mts +614 -86
- package/dist/index.mjs +655 -299
- package/package.json +8 -2
package/dist/index.d.cts
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,373 @@ 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";
|
|
408
448
|
}
|
|
409
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;
|
|
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;
|
|
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
|
+
path: string;
|
|
799
|
+
};
|
|
800
|
+
doc: {
|
|
801
|
+
openApiPath: string;
|
|
802
|
+
swaggerPath: string;
|
|
803
|
+
metadata: OpenAPIMetadata;
|
|
804
|
+
};
|
|
805
|
+
};
|
|
806
|
+
declare const _settings: Settings;
|
|
411
807
|
/**
|
|
412
808
|
* Collection of utility functions which are essential for Sapling to function.
|
|
413
809
|
*/
|
|
@@ -452,7 +848,8 @@ declare class Sapling {
|
|
|
452
848
|
* app.registerApp(app);
|
|
453
849
|
* ```
|
|
454
850
|
*/
|
|
455
|
-
static registerApp(app: e.Express):
|
|
851
|
+
static registerApp(app: e.Express): e.Express;
|
|
852
|
+
static onStartup(): void;
|
|
456
853
|
/**
|
|
457
854
|
* Serialize a value into a JSON string.
|
|
458
855
|
*
|
|
@@ -481,111 +878,242 @@ declare class Sapling {
|
|
|
481
878
|
* Replace the function used for `deserialize`
|
|
482
879
|
*/
|
|
483
880
|
static setDeserializeFn(this: void, fn: (value: string) => any): void;
|
|
881
|
+
/**
|
|
882
|
+
* Modify extra settings
|
|
883
|
+
*/
|
|
884
|
+
static Extras: {
|
|
885
|
+
/**
|
|
886
|
+
* Modify default settings applied to OpenAPI & Swagger
|
|
887
|
+
*/
|
|
888
|
+
swaggerAndOpenApi: {
|
|
889
|
+
/**
|
|
890
|
+
* Set base OpenAPI metadata values.
|
|
891
|
+
*
|
|
892
|
+
* @default { title: "API", version: "1.0.0" }
|
|
893
|
+
*/
|
|
894
|
+
setMetadata(metadata: OpenAPIMetadata): void;
|
|
895
|
+
/**
|
|
896
|
+
* change default endpoint that will serve OpenAPI spec.
|
|
897
|
+
* Swagger will also load this endpoint on load.
|
|
898
|
+
*
|
|
899
|
+
* @default `/openapi.json`
|
|
900
|
+
*/
|
|
901
|
+
setOpenApiPath(this: void, path: string): void;
|
|
902
|
+
/**
|
|
903
|
+
* change Swagger endpoint.
|
|
904
|
+
*
|
|
905
|
+
* @default `/swagger.html`
|
|
906
|
+
*/
|
|
907
|
+
setSwaggerPath(this: void, path: string): void;
|
|
908
|
+
};
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* This method can be used in a `@MiddlewareClass` to register any libraries
|
|
912
|
+
* that expect you to register multiple registers at once. An example is `swagger-ui-express`
|
|
913
|
+
*
|
|
914
|
+
* @example
|
|
915
|
+
* ```ts
|
|
916
|
+
* ⠀@MiddlewareClass()
|
|
917
|
+
* class Serve {
|
|
918
|
+
* // `swagger.serve` returns multiple Express handlers for all the assets and routes
|
|
919
|
+
* // that will be served
|
|
920
|
+
* private readonly handlers: RequestHandler[] = swagger.serve;
|
|
921
|
+
*
|
|
922
|
+
* ⠀@Middleware(_settings.doc.swaggerPath)
|
|
923
|
+
* handle(request: Request, response: Response, next: NextFunction) {
|
|
924
|
+
* return Sapling.chainHandlers(this.handlers, request, response, next);
|
|
925
|
+
* }
|
|
926
|
+
* }
|
|
927
|
+
* ```
|
|
928
|
+
*/
|
|
929
|
+
static chainHandlers(this: void, handlers: RequestHandler[], request: Request$1, response: Response$1, next: NextFunction, index?: number): void;
|
|
484
930
|
}
|
|
485
931
|
//#endregion
|
|
486
|
-
//#region src/annotation/
|
|
487
|
-
type
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
932
|
+
//#region src/annotation/validator.d.ts
|
|
933
|
+
type ValidatorSchema = {
|
|
934
|
+
requestBody?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
935
|
+
requestParam?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
936
|
+
requestQuery?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
937
|
+
responseBody?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
938
|
+
};
|
|
939
|
+
declare function ResponseBody(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
940
|
+
declare function RequestBody(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
941
|
+
declare function RequestParam(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
942
|
+
declare function RequestQuery(schema: StandardSchemaV1 & StandardJSONSchemaV1): MethodDecorator;
|
|
943
|
+
declare function _getOrCreateSchemaDefinition(ctor: Function, fnName: string): ValidatorSchema;
|
|
944
|
+
declare function _parseOrThrow<TSchema extends StandardSchemaV1>(schema: TSchema, input: unknown, location: ParserErrorLocation, fnName: string): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
945
|
+
declare function _saveValidatorSchema(def: ValidatorSchema, key: keyof ValidatorSchema, schema: StandardSchemaV1 & StandardJSONSchemaV1, fnName: string): void;
|
|
946
|
+
declare function _getValidatorSchema(ctor: Function, fnName: string): ValidatorSchema | undefined;
|
|
947
|
+
//#endregion
|
|
948
|
+
//#region src/annotation/schema.d.ts
|
|
949
|
+
type ResponseSchema = {
|
|
950
|
+
statusCode: HttpStatus;
|
|
951
|
+
description?: string;
|
|
952
|
+
schema?: StandardSchemaV1 & StandardJSONSchemaV1;
|
|
953
|
+
};
|
|
954
|
+
type RouteSchemaDefinition = {
|
|
955
|
+
summary?: string;
|
|
956
|
+
description?: string;
|
|
957
|
+
responses?: ResponseSchema[];
|
|
491
958
|
};
|
|
959
|
+
type ControllerSchemaDefinition = {
|
|
960
|
+
title?: string;
|
|
961
|
+
description?: string;
|
|
962
|
+
};
|
|
963
|
+
declare function ControllerSchema(options: {
|
|
964
|
+
title?: string;
|
|
965
|
+
description?: string;
|
|
966
|
+
}): ClassDecorator;
|
|
967
|
+
declare function RouteSchema(options: {
|
|
968
|
+
summary?: string;
|
|
969
|
+
description?: string;
|
|
970
|
+
responses?: ResponseSchema[];
|
|
971
|
+
}): MethodDecorator;
|
|
972
|
+
declare function _setRouteSchema(ctor: Function, fnName: string, options: RouteSchemaDefinition): void;
|
|
973
|
+
declare function _setControllerSchema(ctor: Function, options: ControllerSchemaDefinition): void;
|
|
974
|
+
declare function _getRouteSchema(ctor: Function, fnName: string): RouteSchemaDefinition | undefined;
|
|
975
|
+
declare function _getControllerSchema(ctor: Function): ControllerSchemaDefinition | undefined;
|
|
976
|
+
//#endregion
|
|
977
|
+
//#region src/middleware/default/error/base.d.ts
|
|
492
978
|
/**
|
|
493
|
-
*
|
|
979
|
+
* This should be registered last in the middleware chain.
|
|
494
980
|
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
981
|
+
* All exception messages are hidden from the request by default.
|
|
982
|
+
* If the default is not suitable, you may also easily write your own.
|
|
983
|
+
*/
|
|
984
|
+
declare class DefaultBaseErrorMiddleware {
|
|
985
|
+
handle(err: unknown, _request: Request$1, _response: Response$1, _next: NextFunction): ResponseEntity<{
|
|
986
|
+
message: string;
|
|
987
|
+
}>;
|
|
988
|
+
}
|
|
989
|
+
//#endregion
|
|
990
|
+
//#region src/middleware/default/error/parse.d.ts
|
|
991
|
+
/**
|
|
992
|
+
* Default error middleware that handles `ParserError`.
|
|
993
|
+
* If the default is not suitable, you may also easily write your own.
|
|
994
|
+
*/
|
|
995
|
+
declare class DefaultParserErrorMiddleware {
|
|
996
|
+
handle(err: unknown, _request: Request$1, _response: Response$1, next: NextFunction): ResponseEntity<{
|
|
997
|
+
message: string;
|
|
998
|
+
}> | undefined;
|
|
999
|
+
}
|
|
1000
|
+
//#endregion
|
|
1001
|
+
//#region src/middleware/default/error/responsestatus.d.ts
|
|
1002
|
+
/**
|
|
1003
|
+
* Default error middleware that handles `ResponseStatusError`.
|
|
1004
|
+
* If the default is not suitable, you may also easily write your own.
|
|
1005
|
+
*/
|
|
1006
|
+
declare class DefaultResponseStatusErrorMiddleware {
|
|
1007
|
+
handle(err: unknown, _request: Request$1, _response: Response$1, next: NextFunction): ResponseEntity<{
|
|
1008
|
+
message: string;
|
|
1009
|
+
}> | undefined;
|
|
1010
|
+
}
|
|
1011
|
+
//#endregion
|
|
1012
|
+
//#region src/middleware/default/openapi/index.d.ts
|
|
1013
|
+
/**
|
|
1014
|
+
* Enable the serving of the OpenAPI spec autogenerated by Sapling.
|
|
497
1015
|
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
* name: z.string(),
|
|
502
|
-
* description: z.string().optional(),
|
|
503
|
-
* });
|
|
1016
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
1017
|
+
*
|
|
1018
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
504
1019
|
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* >;
|
|
513
|
-
* }
|
|
514
|
-
* }
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* const middlewares = [
|
|
1022
|
+
* DefaultOpenApiMiddleware,
|
|
1023
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1024
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1025
|
+
* ];
|
|
1026
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
515
1027
|
* ```
|
|
516
1028
|
*/
|
|
517
|
-
declare
|
|
1029
|
+
declare class DefaultOpenApiMiddleware {
|
|
1030
|
+
handle(_request: Request$1, _response: Response$1, _next: NextFunction): ResponseEntity<OpenAPIV3.Document<{}>>;
|
|
1031
|
+
}
|
|
1032
|
+
//#endregion
|
|
1033
|
+
//#region src/middleware/default/swagger/index.d.ts
|
|
518
1034
|
/**
|
|
519
|
-
*
|
|
1035
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
520
1036
|
*
|
|
521
|
-
*
|
|
522
|
-
* You can then just simply cast `request.param` for your use
|
|
1037
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
523
1038
|
*
|
|
524
|
-
*
|
|
525
|
-
* ```ts
|
|
526
|
-
* const GET_BOOK_REQUEST_PARAM_SCHEMA = z.object({
|
|
527
|
-
* bookId: z.string(),
|
|
528
|
-
* });
|
|
1039
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
529
1040
|
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* >;
|
|
538
|
-
* }
|
|
539
|
-
* }
|
|
1041
|
+
* ```ts
|
|
1042
|
+
* const middlewares = [
|
|
1043
|
+
* DefaultOpenApiMiddleware,
|
|
1044
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1045
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1046
|
+
* ];
|
|
1047
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
540
1048
|
* ```
|
|
541
1049
|
*/
|
|
542
|
-
declare
|
|
1050
|
+
declare class Serve {
|
|
1051
|
+
private readonly handlers;
|
|
1052
|
+
handle(request: Request$1, response: Response$1, next: NextFunction): void;
|
|
1053
|
+
}
|
|
543
1054
|
/**
|
|
544
|
-
*
|
|
1055
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
545
1056
|
*
|
|
546
|
-
*
|
|
547
|
-
* You can then just simply cast `request.query` for your use
|
|
1057
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
548
1058
|
*
|
|
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
|
-
* });
|
|
1059
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
555
1060
|
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* >;
|
|
564
|
-
* }
|
|
565
|
-
* }
|
|
1061
|
+
* ```ts
|
|
1062
|
+
* const middlewares = [
|
|
1063
|
+
* DefaultOpenApiMiddleware,
|
|
1064
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1065
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1066
|
+
* ];
|
|
1067
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
566
1068
|
* ```
|
|
567
1069
|
*/
|
|
568
|
-
declare
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1070
|
+
declare class Setup {
|
|
1071
|
+
private readonly handler;
|
|
1072
|
+
constructor();
|
|
1073
|
+
handle(request: Request$1, response: Response$1, next: NextFunction): unknown;
|
|
1074
|
+
}
|
|
573
1075
|
/**
|
|
574
|
-
*
|
|
1076
|
+
* Enable the serving of the Swagger endpoint used to serve the OpenAPI spec generated by Sapling.
|
|
575
1077
|
*
|
|
576
|
-
*
|
|
1078
|
+
* Configure any middleware-specific settings with `Sapling.Extras.swaggerAndOpenApi`
|
|
1079
|
+
*
|
|
1080
|
+
* You must register `DefaultSwaggerMiddleware.Serve` & `DefaultSwaggerMiddleware.Setup` after `DefaultOpenApiMiddleware`
|
|
1081
|
+
*
|
|
1082
|
+
* ```ts
|
|
1083
|
+
* const middlewares = [
|
|
1084
|
+
* DefaultOpenApiMiddleware,
|
|
1085
|
+
* DefaultSwaggerMiddleware.Serve,
|
|
1086
|
+
* DefaultSwaggerMiddleware.Setup,
|
|
1087
|
+
* ];
|
|
1088
|
+
* middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
1089
|
+
* ```
|
|
577
1090
|
*/
|
|
578
|
-
declare
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
1091
|
+
declare const DefaultSwaggerMiddleware: {
|
|
1092
|
+
Serve: typeof Serve;
|
|
1093
|
+
Setup: typeof Setup;
|
|
1094
|
+
};
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region src/middleware/health/registrar.d.ts
|
|
1097
|
+
type HealthCheck = () => boolean | Promise<boolean>;
|
|
1098
|
+
declare class HealthRegistrar {
|
|
1099
|
+
private _checks;
|
|
1100
|
+
private _sealed;
|
|
1101
|
+
constructor();
|
|
1102
|
+
add(healthCheck: HealthCheck): void;
|
|
1103
|
+
/**
|
|
1104
|
+
* @internal used by Sapling library
|
|
1105
|
+
*/
|
|
1106
|
+
_seal(): void;
|
|
1107
|
+
check(): Promise<boolean>;
|
|
582
1108
|
}
|
|
583
1109
|
//#endregion
|
|
584
|
-
//#region src/middleware/default/
|
|
585
|
-
declare class
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
1110
|
+
//#region src/middleware/default/health/index.d.ts
|
|
1111
|
+
declare class DefaultHealthMiddleware {
|
|
1112
|
+
private readonly healthRegistrar;
|
|
1113
|
+
constructor(healthRegistrar: HealthRegistrar);
|
|
1114
|
+
serve(_request: Request, _response: Response, _next: NextFunction): Promise<ResponseEntity<{
|
|
1115
|
+
up: boolean;
|
|
1116
|
+
}>>;
|
|
589
1117
|
}
|
|
590
1118
|
//#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,
|
|
1119
|
+
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 };
|