@tahminator/sapling 1.5.27 → 1.5.28-beta.7e624925
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/dist/index.cjs +755 -0
- package/dist/index.d.cts +521 -0
- package/dist/index.d.mts +521 -0
- package/dist/index.mjs +701 -0
- package/package.json +15 -10
- package/dist/eslint.config.d.ts +0 -2
- package/dist/eslint.config.js +0 -38
- package/dist/exclusions.d.ts +0 -5
- package/dist/exclusions.js +0 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/lib/weakmap.d.ts +0 -15
- package/dist/lib/weakmap.js +0 -77
- package/dist/src/__test__/first.d.ts +0 -6
- package/dist/src/__test__/first.js +0 -20
- package/dist/src/__test__/second.d.ts +0 -6
- package/dist/src/__test__/second.js +0 -20
- package/dist/src/annotation/controller.d.ts +0 -21
- package/dist/src/annotation/controller.js +0 -78
- package/dist/src/annotation/index.d.ts +0 -4
- package/dist/src/annotation/index.js +0 -4
- package/dist/src/annotation/injectable.d.ts +0 -25
- package/dist/src/annotation/injectable.js +0 -72
- package/dist/src/annotation/middleware.d.ts +0 -9
- package/dist/src/annotation/middleware.js +0 -11
- package/dist/src/annotation/route.d.ts +0 -47
- package/dist/src/annotation/route.js +0 -77
- package/dist/src/enum/http.d.ts +0 -68
- package/dist/src/enum/http.js +0 -71
- package/dist/src/enum/index.d.ts +0 -1
- package/dist/src/enum/index.js +0 -1
- package/dist/src/helper/error.d.ts +0 -10
- package/dist/src/helper/error.js +0 -19
- package/dist/src/helper/index.d.ts +0 -4
- package/dist/src/helper/index.js +0 -4
- package/dist/src/helper/redirect.d.ts +0 -14
- package/dist/src/helper/redirect.js +0 -19
- package/dist/src/helper/response.d.ts +0 -68
- package/dist/src/helper/response.js +0 -90
- package/dist/src/helper/sapling.d.ts +0 -101
- package/dist/src/helper/sapling.js +0 -153
- package/dist/src/html/404.d.ts +0 -4
- package/dist/src/html/404.js +0 -14
- package/dist/src/html/index.d.ts +0 -1
- package/dist/src/html/index.js +0 -1
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.js +0 -5
- package/dist/src/types.d.ts +0 -21
- package/dist/src/types.js +0 -11
- package/dist/vite.config.d.ts +0 -2
- package/dist/vite.config.js +0 -18
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import e, { NextFunction, Request, Response, Router } from "express";
|
|
2
|
+
|
|
3
|
+
//#region src/html/404.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Default Express.js 404 error page, as a string.
|
|
6
|
+
*/
|
|
7
|
+
declare const Html404ErrorPage: (error: string) => string;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/types.d.ts
|
|
10
|
+
type ExpressRouterMethodKey = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD" | "USE";
|
|
11
|
+
type ExpressRouterMethods = Lowercase<ExpressRouterMethodKey>;
|
|
12
|
+
declare const methodResolve: Record<ExpressRouterMethodKey, ExpressRouterMethods>;
|
|
13
|
+
type RouteDefinition = {
|
|
14
|
+
/**
|
|
15
|
+
* Express.js HTTP method.
|
|
16
|
+
*/
|
|
17
|
+
method: ExpressRouterMethodKey;
|
|
18
|
+
/**
|
|
19
|
+
* The path to define the route on. Can be a string or RegExp.
|
|
20
|
+
*/
|
|
21
|
+
path: string | RegExp;
|
|
22
|
+
/**
|
|
23
|
+
* The name of the function the `@Route` annotation was applied on.
|
|
24
|
+
*/
|
|
25
|
+
fnName: string;
|
|
26
|
+
};
|
|
27
|
+
type Class<T> = new (...args: any[]) => T;
|
|
28
|
+
type HttpHeaders = Record<string, string>;
|
|
29
|
+
type ExpressMiddlewareFn = ($1: Request, $2: Response, $3: NextFunction) => void;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/annotation/controller.d.ts
|
|
32
|
+
declare const _ControllerRegistry: WeakMap<Function, Router>;
|
|
33
|
+
type ControllerProps = {
|
|
34
|
+
/**
|
|
35
|
+
* Optional URL prefix applied to all routes in the controller. Defaults to "".
|
|
36
|
+
*/
|
|
37
|
+
prefix?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Optional array of dependencies to be injected into the constructor that are `@Injectable`
|
|
40
|
+
*/
|
|
41
|
+
deps?: Array<Class<any>>;
|
|
42
|
+
} | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Registers a class as an HTTP controller and registers its routes.
|
|
45
|
+
*
|
|
46
|
+
* @param [prefix] Optional URL prefix applied to all routes in the controller. Defaults to "".
|
|
47
|
+
* @param [deps] Optional array of dependencies to be injected into the constructor that are `@Injectable`
|
|
48
|
+
*/
|
|
49
|
+
declare function Controller({
|
|
50
|
+
prefix,
|
|
51
|
+
deps
|
|
52
|
+
}?: ControllerProps): ClassDecorator;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region lib/weakmap.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* WeakMap that is iterable.
|
|
57
|
+
*/
|
|
58
|
+
declare class IterableWeakMap<K extends object, V> {
|
|
59
|
+
#private;
|
|
60
|
+
constructor(iterable?: Iterable<[K, V]>);
|
|
61
|
+
set(key: K, value: V): this;
|
|
62
|
+
get(key: K): V | undefined;
|
|
63
|
+
delete(key: K): boolean;
|
|
64
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
65
|
+
entries(): IterableIterator<[K, V]>;
|
|
66
|
+
keys(): IterableIterator<K>;
|
|
67
|
+
values(): IterableIterator<V>;
|
|
68
|
+
forEach(callback: (value: V, key: K, map: this) => void, thisArg?: any): void;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/annotation/injectable.d.ts
|
|
72
|
+
declare const _InjectableRegistry: WeakMap<Class<any>, any>;
|
|
73
|
+
declare const _InjectableDeps: IterableWeakMap<Class<any>, Class<any>[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Mark the class as an injectable to be handled by Sapling. The class can now be
|
|
76
|
+
* be injected into other classes, as well as allow the class to inject other `@Injectable` classes.
|
|
77
|
+
*
|
|
78
|
+
* @argument deps - An optional array to define any dependencies that this class may require.
|
|
79
|
+
*/
|
|
80
|
+
declare function Injectable(deps?: Array<Class<any>>): ClassDecorator;
|
|
81
|
+
/**
|
|
82
|
+
* Resolves and instantiates a class along with all of it's transitive dependencies.
|
|
83
|
+
*
|
|
84
|
+
* Uses topological sort (Kahn's algorithm) to ensure that the dependency graph is created
|
|
85
|
+
* in a correct order.
|
|
86
|
+
*
|
|
87
|
+
* When `resolve` is first called (usually during controller registration),
|
|
88
|
+
* it will compute the dependency graph of all `@Injectable` classes and instantiates
|
|
89
|
+
* them in the correct order.
|
|
90
|
+
*
|
|
91
|
+
* Subsequent calls to dependencies that have already been resolved are cached, so they will
|
|
92
|
+
* re-use the created singletons instead of re-instantiation.
|
|
93
|
+
*/
|
|
94
|
+
declare function _resolve<T>(ctor: Class<T>): T;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/annotation/route.d.ts
|
|
97
|
+
type OptionalStrOrRegExp = string | RegExp | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Custom annotation that will store all routes inside of a map,
|
|
100
|
+
* which can then be used to initialize all the routes to the router.
|
|
101
|
+
*/
|
|
102
|
+
declare function _Route({
|
|
103
|
+
method,
|
|
104
|
+
path
|
|
105
|
+
}: {
|
|
106
|
+
method: ExpressRouterMethodKey;
|
|
107
|
+
path: OptionalStrOrRegExp;
|
|
108
|
+
}): MethodDecorator;
|
|
109
|
+
/**
|
|
110
|
+
* Register GET route on the given path (default "") for the given controller.
|
|
111
|
+
*/
|
|
112
|
+
declare const GET: (path?: OptionalStrOrRegExp) => MethodDecorator;
|
|
113
|
+
/**
|
|
114
|
+
* Register POST route on the given path (default "") for the given controller.
|
|
115
|
+
*/
|
|
116
|
+
declare const POST: (path?: OptionalStrOrRegExp) => MethodDecorator;
|
|
117
|
+
/**
|
|
118
|
+
* Register PUT route on the given path (default "") for the given controller.
|
|
119
|
+
*/
|
|
120
|
+
declare const PUT: (path?: OptionalStrOrRegExp) => MethodDecorator;
|
|
121
|
+
/**
|
|
122
|
+
* Register DELETE route on the given path (default "") for the given controller.
|
|
123
|
+
*/
|
|
124
|
+
declare const DELETE: (path?: OptionalStrOrRegExp) => MethodDecorator;
|
|
125
|
+
/**
|
|
126
|
+
* Register OPTIONS route on the given path (default "") for the given controller.
|
|
127
|
+
*/
|
|
128
|
+
declare const OPTIONS: (path?: OptionalStrOrRegExp) => MethodDecorator;
|
|
129
|
+
/**
|
|
130
|
+
* Register PATCH route on the given path (default "") for the given controller.
|
|
131
|
+
*/
|
|
132
|
+
declare const PATCH: (path?: OptionalStrOrRegExp) => MethodDecorator;
|
|
133
|
+
/**
|
|
134
|
+
* Register HEAD route on the given path (default "") for the given controller.
|
|
135
|
+
*/
|
|
136
|
+
declare const HEAD: (path?: OptionalStrOrRegExp) => MethodDecorator;
|
|
137
|
+
/**
|
|
138
|
+
* Register a middleware route on the given path (default "") for the given controller.
|
|
139
|
+
*/
|
|
140
|
+
declare const Middleware: (path?: OptionalStrOrRegExp) => MethodDecorator;
|
|
141
|
+
/**
|
|
142
|
+
* Given a class constructor, fetch all the routes attached.
|
|
143
|
+
*/
|
|
144
|
+
declare function _getRoutes(ctor: Function): readonly RouteDefinition[];
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/annotation/middleware.d.ts
|
|
147
|
+
/**
|
|
148
|
+
* Used to define a middleware-only class.
|
|
149
|
+
*
|
|
150
|
+
* __NOTE:__ `@MiddlewareClass` works exactly the same as `@Controller`. As such, you
|
|
151
|
+
* can still register `@Route` and `@Middleware` methods, though you very well should not
|
|
152
|
+
* for the sake of semantics.
|
|
153
|
+
*/
|
|
154
|
+
declare function MiddlewareClass(...args: Parameters<typeof Controller>): ClassDecorator;
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
157
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
158
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
159
|
+
/** The Standard properties. */
|
|
160
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
161
|
+
}
|
|
162
|
+
declare namespace StandardTypedV1 {
|
|
163
|
+
/** The Standard Typed properties interface. */
|
|
164
|
+
interface Props<Input = unknown, Output = Input> {
|
|
165
|
+
/** The version number of the standard. */
|
|
166
|
+
readonly version: 1;
|
|
167
|
+
/** The vendor name of the schema library. */
|
|
168
|
+
readonly vendor: string;
|
|
169
|
+
/** Inferred types associated with the schema. */
|
|
170
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
171
|
+
}
|
|
172
|
+
/** The Standard Typed types interface. */
|
|
173
|
+
interface Types<Input = unknown, Output = Input> {
|
|
174
|
+
/** The input type of the schema. */
|
|
175
|
+
readonly input: Input;
|
|
176
|
+
/** The output type of the schema. */
|
|
177
|
+
readonly output: Output;
|
|
178
|
+
}
|
|
179
|
+
/** Infers the input type of a Standard Typed. */
|
|
180
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
181
|
+
/** Infers the output type of a Standard Typed. */
|
|
182
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
183
|
+
}
|
|
184
|
+
/** The Standard Schema interface. */
|
|
185
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
186
|
+
/** The Standard Schema properties. */
|
|
187
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
188
|
+
}
|
|
189
|
+
declare namespace StandardSchemaV1 {
|
|
190
|
+
/** The Standard Schema properties interface. */
|
|
191
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
192
|
+
/** Validates unknown input values. */
|
|
193
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
194
|
+
}
|
|
195
|
+
/** The result interface of the validate function. */
|
|
196
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
197
|
+
/** The result interface if validation succeeds. */
|
|
198
|
+
interface SuccessResult<Output> {
|
|
199
|
+
/** The typed output value. */
|
|
200
|
+
readonly value: Output;
|
|
201
|
+
/** A falsy value for `issues` indicates success. */
|
|
202
|
+
readonly issues?: undefined;
|
|
203
|
+
}
|
|
204
|
+
interface Options {
|
|
205
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
206
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
207
|
+
}
|
|
208
|
+
/** The result interface if validation fails. */
|
|
209
|
+
interface FailureResult {
|
|
210
|
+
/** The issues of failed validation. */
|
|
211
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
212
|
+
}
|
|
213
|
+
/** The issue interface of the failure output. */
|
|
214
|
+
interface Issue {
|
|
215
|
+
/** The error message of the issue. */
|
|
216
|
+
readonly message: string;
|
|
217
|
+
/** The path of the issue, if any. */
|
|
218
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
219
|
+
}
|
|
220
|
+
/** The path segment interface of the issue. */
|
|
221
|
+
interface PathSegment {
|
|
222
|
+
/** The key representing a path segment. */
|
|
223
|
+
readonly key: PropertyKey;
|
|
224
|
+
}
|
|
225
|
+
/** The Standard types interface. */
|
|
226
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
227
|
+
/** Infers the input type of a Standard. */
|
|
228
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
229
|
+
/** Infers the output type of a Standard. */
|
|
230
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
231
|
+
}
|
|
232
|
+
/** The Standard JSON Schema interface. */
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/helper/redirect.d.ts
|
|
235
|
+
/**
|
|
236
|
+
* Generic HTTP redirect wrapped modeled after Spring's `RedirectView`.
|
|
237
|
+
*
|
|
238
|
+
* You can either return `new RedirectView(url)` or `RedirectView.redirect(url)` inside of a controller method.
|
|
239
|
+
*/
|
|
240
|
+
declare class RedirectView {
|
|
241
|
+
_url: string;
|
|
242
|
+
constructor(url: string);
|
|
243
|
+
getUrl(): string;
|
|
244
|
+
/**
|
|
245
|
+
* Instantiate `RedirectView` with the given `url`.
|
|
246
|
+
*/
|
|
247
|
+
static redirect(url: string): RedirectView;
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/helper/response.d.ts
|
|
251
|
+
/**
|
|
252
|
+
* Generic HTTP response wrapper modeled after Spring's `ResponseEntity`.
|
|
253
|
+
*
|
|
254
|
+
* Provides status code, headers, and an optional typed body.
|
|
255
|
+
* The body is serialized through `Sapling.serialize`.
|
|
256
|
+
*
|
|
257
|
+
* @typeParam T - the type of the response body
|
|
258
|
+
*/
|
|
259
|
+
declare class ResponseEntity<T> {
|
|
260
|
+
private readonly _statusCode;
|
|
261
|
+
private readonly _headers;
|
|
262
|
+
private readonly _body;
|
|
263
|
+
constructor(body: T, headers?: HttpHeaders, statusCode?: number);
|
|
264
|
+
/**
|
|
265
|
+
* Create a builder with a 200 status code.
|
|
266
|
+
*
|
|
267
|
+
* @example```ts
|
|
268
|
+
* return ResponseEntity.ok().body({ success: true });
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
static ok(): ResponseEntityBuilder;
|
|
272
|
+
/**
|
|
273
|
+
* Create a builder with a custom status code.
|
|
274
|
+
*
|
|
275
|
+
* @example```ts
|
|
276
|
+
* return ResponseEntity.status(HttpStatus.BAD_REQUEST).body({ success: false });
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @see {@link HttpStatus}
|
|
280
|
+
*/
|
|
281
|
+
static status(statusCode: number): ResponseEntityBuilder;
|
|
282
|
+
/**
|
|
283
|
+
* Return status code.
|
|
284
|
+
*/
|
|
285
|
+
getStatusCode(): number;
|
|
286
|
+
/**
|
|
287
|
+
* Return headers.
|
|
288
|
+
*/
|
|
289
|
+
getHeaders(): HttpHeaders;
|
|
290
|
+
/**
|
|
291
|
+
* Return the response body.
|
|
292
|
+
*/
|
|
293
|
+
getBody(): T;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Builder for {@link ResponseEntity}.
|
|
297
|
+
*
|
|
298
|
+
* Forces the status code to be set first, then headers and body,
|
|
299
|
+
* ensuring type safety when constructing the response.
|
|
300
|
+
*/
|
|
301
|
+
declare class ResponseEntityBuilder {
|
|
302
|
+
private readonly _statusCode;
|
|
303
|
+
private _headers;
|
|
304
|
+
constructor(statusCode: number);
|
|
305
|
+
/**
|
|
306
|
+
* Set all headers as an object with keys and values.
|
|
307
|
+
*/
|
|
308
|
+
headers(headers: HttpHeaders): this;
|
|
309
|
+
/**
|
|
310
|
+
* Add/override a single key and value to the headers.
|
|
311
|
+
*/
|
|
312
|
+
setHeader(key: string, value: string): this;
|
|
313
|
+
/**
|
|
314
|
+
* Set the response body.
|
|
315
|
+
*/
|
|
316
|
+
body<T>(body: T): ResponseEntity<T>;
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/enum/http.d.ts
|
|
320
|
+
/**
|
|
321
|
+
* Enum of every valid HTTP status code mapped to a specific enum member.
|
|
322
|
+
*
|
|
323
|
+
* @see {@link ResponseEntity}
|
|
324
|
+
*/
|
|
325
|
+
declare enum HttpStatus {
|
|
326
|
+
CONTINUE = 100,
|
|
327
|
+
SWITCHING_PROTOCOLS = 101,
|
|
328
|
+
PROCESSING = 102,
|
|
329
|
+
EARLY_HINTS = 103,
|
|
330
|
+
OK = 200,
|
|
331
|
+
CREATED = 201,
|
|
332
|
+
ACCEPTED = 202,
|
|
333
|
+
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
334
|
+
NO_CONTENT = 204,
|
|
335
|
+
RESET_CONTENT = 205,
|
|
336
|
+
PARTIAL_CONTENT = 206,
|
|
337
|
+
MULTI_STATUS = 207,
|
|
338
|
+
ALREADY_REPORTED = 208,
|
|
339
|
+
IM_USED = 226,
|
|
340
|
+
MULTIPLE_CHOICES = 300,
|
|
341
|
+
MOVED_PERMANENTLY = 301,
|
|
342
|
+
FOUND = 302,
|
|
343
|
+
SEE_OTHER = 303,
|
|
344
|
+
NOT_MODIFIED = 304,
|
|
345
|
+
TEMPORARY_REDIRECT = 307,
|
|
346
|
+
PERMANENT_REDIRECT = 308,
|
|
347
|
+
BAD_REQUEST = 400,
|
|
348
|
+
UNAUTHORIZED = 401,
|
|
349
|
+
PAYMENT_REQUIRED = 402,
|
|
350
|
+
FORBIDDEN = 403,
|
|
351
|
+
NOT_FOUND = 404,
|
|
352
|
+
METHOD_NOT_ALLOWED = 405,
|
|
353
|
+
NOT_ACCEPTABLE = 406,
|
|
354
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
355
|
+
REQUEST_TIMEOUT = 408,
|
|
356
|
+
CONFLICT = 409,
|
|
357
|
+
GONE = 410,
|
|
358
|
+
LENGTH_REQUIRED = 411,
|
|
359
|
+
PRECONDITION_FAILED = 412,
|
|
360
|
+
PAYLOAD_TOO_LARGE = 413,
|
|
361
|
+
URI_TOO_LONG = 414,
|
|
362
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
363
|
+
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
364
|
+
EXPECTATION_FAILED = 417,
|
|
365
|
+
I_AM_A_TEAPOT = 418,
|
|
366
|
+
UNPROCESSABLE_ENTITY = 422,
|
|
367
|
+
LOCKED = 423,
|
|
368
|
+
FAILED_DEPENDENCY = 424,
|
|
369
|
+
TOO_EARLY = 425,
|
|
370
|
+
UPGRADE_REQUIRED = 426,
|
|
371
|
+
PRECONDITION_REQUIRED = 428,
|
|
372
|
+
TOO_MANY_REQUESTS = 429,
|
|
373
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
374
|
+
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
375
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
376
|
+
NOT_IMPLEMENTED = 501,
|
|
377
|
+
BAD_GATEWAY = 502,
|
|
378
|
+
SERVICE_UNAVAILABLE = 503,
|
|
379
|
+
GATEWAY_TIMEOUT = 504,
|
|
380
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
381
|
+
VARIANT_ALSO_NEGOTIATES = 506,
|
|
382
|
+
INSUFFICIENT_STORAGE = 507,
|
|
383
|
+
LOOP_DETECTED = 508,
|
|
384
|
+
BANDWIDTH_LIMIT_EXCEEDED = 509,
|
|
385
|
+
NOT_EXTENDED = 510,
|
|
386
|
+
NETWORK_AUTHENTICATION_REQUIRED = 511
|
|
387
|
+
}
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/helper/error/responsestatus.d.ts
|
|
390
|
+
/**
|
|
391
|
+
* Ensure that you define a middleware that can handle this error.
|
|
392
|
+
*
|
|
393
|
+
* @see {@link Sapling.loadResponseStatusErrorMiddleware}
|
|
394
|
+
*/
|
|
395
|
+
declare class ResponseStatusError extends Error {
|
|
396
|
+
readonly status: HttpStatus;
|
|
397
|
+
constructor(status: HttpStatus, message?: string);
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/helper/sapling.d.ts
|
|
401
|
+
/**
|
|
402
|
+
* Collection of utility functions which are essential for Sapling to function.
|
|
403
|
+
*/
|
|
404
|
+
declare class Sapling {
|
|
405
|
+
/**
|
|
406
|
+
* If you would prefer to manually resolve your controllers instead, call resolve
|
|
407
|
+
* on the controller class.
|
|
408
|
+
*
|
|
409
|
+
* @example```ts
|
|
410
|
+
* import { Sapling } from "@tahminator/sapling";
|
|
411
|
+
* import TestController from "./path/to/test.controller";
|
|
412
|
+
*
|
|
413
|
+
* const app = express();
|
|
414
|
+
*
|
|
415
|
+
* const router = Sapling.resolve(TestController);
|
|
416
|
+
* app.use(router);
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
static resolve<TClass>(this: void, clazz: Class<TClass>): Router;
|
|
420
|
+
/**
|
|
421
|
+
* Register this function as a middleware in order to utilize Sapling's `deserialize` function.
|
|
422
|
+
*
|
|
423
|
+
* @example```ts
|
|
424
|
+
* import { Sapling } from "@tahminator/sapling";
|
|
425
|
+
* import express from "express";
|
|
426
|
+
*
|
|
427
|
+
* const app = express();
|
|
428
|
+
*
|
|
429
|
+
* app.use(Sapling.json());
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
static json(this: void): ExpressMiddlewareFn;
|
|
433
|
+
/**
|
|
434
|
+
* Register your application with all the necessary middlewares and logics for Sapling to function.
|
|
435
|
+
*
|
|
436
|
+
* @example```ts
|
|
437
|
+
* import { Sapling } from "@tahminator/sapling";
|
|
438
|
+
* import express from "express";
|
|
439
|
+
*
|
|
440
|
+
* const app = express();
|
|
441
|
+
*
|
|
442
|
+
* app.registerApp(app);
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
static registerApp(app: e.Express): void;
|
|
446
|
+
/**
|
|
447
|
+
* Register a middleware that will handle {@link ResponseStatusError}.
|
|
448
|
+
*
|
|
449
|
+
* This middleware will chain to the next middleware if it does not catch {@link ResponseStatusError}.
|
|
450
|
+
* You may still define middleware to handle all other errors in a separate `app.use` call.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```ts
|
|
454
|
+
* import express from "express";
|
|
455
|
+
* import { Sapling } from "@tahminator/sapling";
|
|
456
|
+
*
|
|
457
|
+
* const app = express();
|
|
458
|
+
*
|
|
459
|
+
* Sapling.loadResponseStatusErrorMiddleware(app, (err, req, res, next) => {
|
|
460
|
+
* // `err` is guaranteed to be of type ResponseStatusError
|
|
461
|
+
* res.status(err.status).json({
|
|
462
|
+
* success: false,
|
|
463
|
+
* message: err.message,
|
|
464
|
+
* });
|
|
465
|
+
* });
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
static loadResponseStatusErrorMiddleware(this: void, app: e.Express, fn: (err: ResponseStatusError, request: e.Request, response: e.Response, next: e.NextFunction) => void): void;
|
|
469
|
+
/**
|
|
470
|
+
* Serialize a value into a JSON string.
|
|
471
|
+
*
|
|
472
|
+
* This function is used in {@link ResponseEntity} to serialize the `body`.
|
|
473
|
+
*
|
|
474
|
+
* Use `setSerializeFn` to override underlying implementation.
|
|
475
|
+
*
|
|
476
|
+
* @defaultValue `JSON.stringify`
|
|
477
|
+
*/
|
|
478
|
+
static serialize(this: void, value: any): string;
|
|
479
|
+
/**
|
|
480
|
+
* Replace the function used for `serialize`.
|
|
481
|
+
*/
|
|
482
|
+
static setSerializeFn(this: void, fn: (value: any) => string): void;
|
|
483
|
+
/**
|
|
484
|
+
* De-serialize a JSON string back to a JavaScript object.
|
|
485
|
+
*
|
|
486
|
+
* This function is used to de-serialize a string into a `body`.
|
|
487
|
+
*
|
|
488
|
+
* Use `setDeserializeFn` to override underlying implementation.
|
|
489
|
+
*
|
|
490
|
+
* @defaultValue `JSON.parse`
|
|
491
|
+
*/
|
|
492
|
+
static deserialize<T = any>(this: void, value: string): T;
|
|
493
|
+
/**
|
|
494
|
+
* Replace the function used for `deserialize`
|
|
495
|
+
*/
|
|
496
|
+
static setDeserializeFn(this: void, fn: (value: string) => any): void;
|
|
497
|
+
}
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region src/helper/error/exception.d.ts
|
|
500
|
+
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery";
|
|
501
|
+
/**
|
|
502
|
+
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
503
|
+
*/
|
|
504
|
+
declare class ParserError extends ResponseStatusError {
|
|
505
|
+
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string);
|
|
506
|
+
private static formatMessage;
|
|
507
|
+
}
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/annotation/request.d.ts
|
|
510
|
+
type RequestSchemaDefinition = {
|
|
511
|
+
body?: StandardSchemaV1;
|
|
512
|
+
param?: StandardSchemaV1;
|
|
513
|
+
query?: StandardSchemaV1;
|
|
514
|
+
};
|
|
515
|
+
declare function RequestBody(schema: StandardSchemaV1): MethodDecorator;
|
|
516
|
+
declare function RequestParam(schema: StandardSchemaV1): MethodDecorator;
|
|
517
|
+
declare function RequestQuery(schema: StandardSchemaV1): MethodDecorator;
|
|
518
|
+
declare function _getRequestSchemas(ctor: Function, fnName: string): RequestSchemaDefinition | undefined;
|
|
519
|
+
declare function _parseOrThrow<TSchema extends StandardSchemaV1>(schema: TSchema, input: unknown, kind: ParserErrorLocation): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
520
|
+
//#endregion
|
|
521
|
+
export { Class, Controller, DELETE, 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, _resolve, methodResolve };
|