tspace-spear 1.2.8 → 1.2.9-beta.1
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 +303 -82
- package/dist/cli/app.d.ts +1 -1
- package/dist/cli/app.js +3 -7
- package/dist/cli/app.js.map +1 -1
- package/dist/cli/controller.d.ts +1 -1
- package/dist/cli/controller.js +1 -12
- package/dist/cli/controller.js.map +1 -1
- package/dist/cli/generators/app/index.js +1 -1
- package/dist/cli/generators/app/index.js.map +1 -1
- package/dist/cli/generators/controller/template.d.ts +1 -1
- package/dist/cli/generators/controller/template.js +16 -7
- package/dist/cli/generators/controller/template.js.map +1 -1
- package/dist/cli/generators/dto/index.js +5 -3
- package/dist/cli/generators/dto/index.js.map +1 -1
- package/dist/cli/generators/module/index.js +3 -3
- package/dist/cli/generators/service/template.d.ts +1 -1
- package/dist/cli/generators/service/template.js +17 -17
- package/dist/cli/index.js +10 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/core/client/index.d.ts +13 -43
- package/dist/lib/core/client/index.js +70 -33
- package/dist/lib/core/client/index.js.map +1 -1
- package/dist/lib/core/client/types.d.ts +43 -0
- package/dist/lib/core/client/types.js +3 -0
- package/dist/lib/core/client/types.js.map +1 -0
- package/dist/lib/core/compiler/generator.d.ts +4 -6
- package/dist/lib/core/compiler/generator.js +172 -39
- package/dist/lib/core/compiler/generator.js.map +1 -1
- package/dist/lib/core/compiler/index.d.ts +2 -2
- package/dist/lib/core/compiler/index.js +2 -2
- package/dist/lib/core/compiler/index.js.map +1 -1
- package/dist/lib/core/compiler/pre-routes.d.ts +12 -130
- package/dist/lib/core/compiler/pre-routes.js +13 -35
- package/dist/lib/core/compiler/pre-routes.js.map +1 -1
- package/dist/lib/core/compiler/types.d.ts +25 -0
- package/dist/lib/core/decorators/context.js +23 -15
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/controller.js +2 -1
- package/dist/lib/core/decorators/controller.js.map +1 -1
- package/dist/lib/core/decorators/index.d.ts +1 -0
- package/dist/lib/core/decorators/index.js +1 -0
- package/dist/lib/core/decorators/index.js.map +1 -1
- package/dist/lib/core/decorators/methods.js +4 -3
- package/dist/lib/core/decorators/methods.js.map +1 -1
- package/dist/lib/core/decorators/middleware.d.ts +40 -2
- package/dist/lib/core/decorators/middleware.js +54 -9
- package/dist/lib/core/decorators/middleware.js.map +1 -1
- package/dist/lib/core/decorators/service.d.ts +28 -0
- package/dist/lib/core/decorators/service.js +36 -0
- package/dist/lib/core/decorators/service.js.map +1 -0
- package/dist/lib/core/decorators/statusCode.js +3 -1
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/decorators/swagger.js +4 -3
- package/dist/lib/core/decorators/swagger.js.map +1 -1
- package/dist/lib/core/exception/index.d.ts +68 -0
- package/dist/lib/core/exception/index.js +123 -0
- package/dist/lib/core/exception/index.js.map +1 -0
- package/dist/lib/core/metadata/index.d.ts +6 -0
- package/dist/lib/core/metadata/index.js +13 -0
- package/dist/lib/core/metadata/index.js.map +1 -0
- package/dist/lib/core/server/fast-router.d.ts +2 -2
- package/dist/lib/core/server/fast-router.js +17 -3
- package/dist/lib/core/server/fast-router.js.map +1 -1
- package/dist/lib/core/server/index.d.ts +32 -5
- package/dist/lib/core/server/index.js +188 -45
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/parser-factory.js +59 -10
- package/dist/lib/core/server/parser-factory.js.map +1 -1
- package/dist/lib/core/server/response.js +21 -1
- package/dist/lib/core/server/response.js.map +1 -1
- package/dist/lib/core/types/index.d.ts +42 -29
- package/package.json +14 -5
- package/dist/cli/client.d.ts +0 -1
- package/dist/cli/client.js +0 -30
- package/dist/cli/client.js.map +0 -1
- package/dist/cli/middleware.d.ts +0 -1
- package/dist/cli/middleware.js +0 -16
- package/dist/cli/middleware.js.map +0 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.js +0 -17
- package/dist/client.js.map +0 -1
- package/dist/common/middlewares/log.middleware.d.ts +0 -2
- package/dist/common/middlewares/log.middleware.js +0 -12
- package/dist/common/middlewares/log.middleware.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -32
- package/dist/index.js.map +0 -1
- package/dist/modules/cats/cat.controller.d.ts +0 -58
- package/dist/modules/cats/cat.controller.js +0 -90
- package/dist/modules/cats/cat.controller.js.map +0 -1
- package/dist/modules/cats/cat.dto.d.ts +0 -8
- package/dist/modules/cats/cat.dto.js +0 -44
- package/dist/modules/cats/cat.dto.js.map +0 -1
- package/dist/modules/cats/cat.service.d.ts +0 -23
- package/dist/modules/cats/cat.service.js +0 -56
- package/dist/modules/cats/cat.service.js.map +0 -1
- package/dist/tests/e2e..test.d.ts +0 -1
- package/dist/tests/e2e..test.js +0 -16
- package/dist/tests/e2e..test.js.map +0 -1
|
@@ -2,47 +2,25 @@
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
// AUTO GENERATED FILE
|
|
4
4
|
// DO NOT EDIT
|
|
5
|
+
// **Response values shown here are examples only.
|
|
6
|
+
// **The App is using the configuration:
|
|
7
|
+
// globalPrefix: 'api'
|
|
5
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
9
|
exports.appRoutes = void 0;
|
|
7
10
|
exports.appRoutes = {
|
|
8
11
|
"/cats": {
|
|
9
12
|
GET: {
|
|
10
|
-
params:
|
|
11
|
-
query: {
|
|
12
|
-
body:
|
|
13
|
-
files:
|
|
14
|
-
response: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
body: { "name": "string", "age": "number" },
|
|
20
|
-
files: null,
|
|
21
|
-
response: { "cat": { "name": "string", "age": "number", "id": "number" }, "message": "string" }
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"/cats/:id": {
|
|
25
|
-
GET: {
|
|
26
|
-
params: { "id": "number" },
|
|
27
|
-
query: null,
|
|
28
|
-
body: {},
|
|
29
|
-
files: null,
|
|
30
|
-
response: { "cat": { "id": "number", "name": "string", "age": "number" } }
|
|
31
|
-
},
|
|
32
|
-
PUT: {
|
|
33
|
-
params: { "id": "number" },
|
|
34
|
-
query: null,
|
|
35
|
-
body: { "name": "string | null", "age": "number | null" },
|
|
36
|
-
files: null,
|
|
37
|
-
response: { "$ref": "any" }
|
|
38
|
-
},
|
|
39
|
-
DELETE: {
|
|
40
|
-
params: { "id": "number" },
|
|
41
|
-
query: null,
|
|
42
|
-
body: {},
|
|
43
|
-
files: null,
|
|
44
|
-
response: { "message": "string" }
|
|
13
|
+
params: undefined,
|
|
14
|
+
query: { id: 123, name: "example" },
|
|
15
|
+
body: undefined,
|
|
16
|
+
files: undefined,
|
|
17
|
+
response: { req: { cat1: "example", cat2: "example" }, cats: [
|
|
18
|
+
{ id: 123, name: "example" },
|
|
19
|
+
{ id: 123, name: "example" },
|
|
20
|
+
{ id: 123, name: "example" }
|
|
21
|
+
] }
|
|
45
22
|
}
|
|
46
23
|
}
|
|
47
24
|
};
|
|
25
|
+
;
|
|
48
26
|
//# sourceMappingURL=pre-routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pre-routes.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/pre-routes.ts"],"names":[],"mappings":";AACA,cAAc;AACd,sBAAsB;AACtB,cAAc;;;
|
|
1
|
+
{"version":3,"file":"pre-routes.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/pre-routes.ts"],"names":[],"mappings":";AACA,cAAc;AACd,sBAAsB;AACtB,cAAc;AACd,kDAAkD;AAClD,wCAAwC;AACxC,sBAAsB;;;AAET,QAAA,SAAS,GAAG;IAEvB,OAAO,EAAE;QAEP,GAAG,EAAE;YACH,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;YACnC,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,SAAS;YAChB,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE;oBAC3D,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC5B,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC5B,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;iBAC7B,EAAE;SACJ;KACF;CACF,CAAC;AAcD,CAAC"}
|
|
@@ -12,3 +12,28 @@ export type RequestFiles<TRoutes extends AnyRoutes, TPath extends keyof TRoutes,
|
|
|
12
12
|
export type ResponseType<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = TRoutes[TPath][TMethod] extends {
|
|
13
13
|
response: infer R;
|
|
14
14
|
} ? Awaited<R> : never;
|
|
15
|
+
export type OptionalIfEmpty<T> = {} extends T ? [input?: T] : [input: T];
|
|
16
|
+
export type RequestInput<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = RequestParams<TRoutes, TPath, TMethod> extends never ? {
|
|
17
|
+
params?: never;
|
|
18
|
+
query?: RequestQuery<TRoutes, TPath, TMethod>;
|
|
19
|
+
body?: RequestBody<TRoutes, TPath, TMethod>;
|
|
20
|
+
files?: RequestFiles<TRoutes, TPath, TMethod>;
|
|
21
|
+
} : {
|
|
22
|
+
params: RequestParams<TRoutes, TPath, TMethod>;
|
|
23
|
+
query?: RequestQuery<TRoutes, TPath, TMethod>;
|
|
24
|
+
body?: RequestBody<TRoutes, TPath, TMethod>;
|
|
25
|
+
files?: RequestFiles<TRoutes, TPath, TMethod>;
|
|
26
|
+
};
|
|
27
|
+
export type SuccessStatus = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
|
|
28
|
+
export type ErrorStatus = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
29
|
+
export type ApiResponse<T, E = unknown> = {
|
|
30
|
+
ok: true;
|
|
31
|
+
status: SuccessStatus;
|
|
32
|
+
headers: Headers;
|
|
33
|
+
data: T;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
status: ErrorStatus;
|
|
37
|
+
headers: Headers;
|
|
38
|
+
data: E;
|
|
39
|
+
};
|
|
@@ -8,6 +8,17 @@ exports.createDtoDecorator = createDtoDecorator;
|
|
|
8
8
|
exports.createContextDecorator = createContextDecorator;
|
|
9
9
|
exports.ValidateDto = ValidateDto;
|
|
10
10
|
const package_1 = __importDefault(require("../package"));
|
|
11
|
+
class ValidateError extends Error {
|
|
12
|
+
issues;
|
|
13
|
+
status;
|
|
14
|
+
constructor(message, { issues = [], status = 400 } = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "ValidateError";
|
|
17
|
+
this.issues = issues;
|
|
18
|
+
this.status = status;
|
|
19
|
+
Object.setPrototypeOf(this, ValidateError.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
11
22
|
function createDtoDecorator(validator, onError) {
|
|
12
23
|
return (_target, _key, descriptor) => {
|
|
13
24
|
const original = descriptor.value;
|
|
@@ -22,7 +33,10 @@ function createDtoDecorator(validator, onError) {
|
|
|
22
33
|
}
|
|
23
34
|
let message = err?.message ?? "Bad Request";
|
|
24
35
|
let issues = err.issues ?? err.errors ?? [];
|
|
25
|
-
let status = 400;
|
|
36
|
+
let status = +(err.status ?? 400);
|
|
37
|
+
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
38
|
+
status = 400;
|
|
39
|
+
}
|
|
26
40
|
if (err.name === "ZodError") {
|
|
27
41
|
const zodIssues = err.issues
|
|
28
42
|
.map((i) => ({
|
|
@@ -33,7 +47,9 @@ function createDtoDecorator(validator, onError) {
|
|
|
33
47
|
issues = zodIssues;
|
|
34
48
|
status = 422;
|
|
35
49
|
}
|
|
36
|
-
return ctx.res
|
|
50
|
+
return ctx.res
|
|
51
|
+
.status(status)
|
|
52
|
+
.json({
|
|
37
53
|
message,
|
|
38
54
|
issues,
|
|
39
55
|
});
|
|
@@ -276,9 +292,9 @@ function ValidateDto(schema, options) {
|
|
|
276
292
|
ctx[target] = result.data;
|
|
277
293
|
return;
|
|
278
294
|
}
|
|
279
|
-
const
|
|
280
|
-
const
|
|
281
|
-
.values(
|
|
295
|
+
const errors = result.error?.issues;
|
|
296
|
+
const issues = Object
|
|
297
|
+
.values(errors.reduce((acc, issue) => {
|
|
282
298
|
const key = issue.path.join(".");
|
|
283
299
|
if (!acc[key]) {
|
|
284
300
|
acc[key] = {
|
|
@@ -295,10 +311,7 @@ function ValidateDto(schema, options) {
|
|
|
295
311
|
}
|
|
296
312
|
return acc;
|
|
297
313
|
}, {}));
|
|
298
|
-
|
|
299
|
-
message: message,
|
|
300
|
-
issues: errors
|
|
301
|
-
});
|
|
314
|
+
throw new ValidateError(message, { issues, status });
|
|
302
315
|
}
|
|
303
316
|
if (adaptor === "class-validator") {
|
|
304
317
|
const dto = package_1.default
|
|
@@ -319,12 +332,7 @@ function ValidateDto(schema, options) {
|
|
|
319
332
|
message: Object.values(constraints).join(","),
|
|
320
333
|
};
|
|
321
334
|
});
|
|
322
|
-
|
|
323
|
-
.status(status)
|
|
324
|
-
.json({
|
|
325
|
-
message: message,
|
|
326
|
-
issues: issues
|
|
327
|
-
});
|
|
335
|
+
throw new ValidateError(message, { issues, status });
|
|
328
336
|
}
|
|
329
337
|
throw new Error("Invalid validation adaptor specified");
|
|
330
338
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/context.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":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B,eAAe,CACZ,MAA0B,EAC1B,GAAG,CAAC,MAAM,CAAC,CACd,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,iBAAO;iBAC3B,cAAc;iBACd,QAAQ,CAAC,GAAG,CAAC,CAAC;YAEf,IAAG,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBAChB,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC;gBAClB,OAAO;YACX,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,KAAS,EAAE,EAAE;gBACxC,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC;gBAE5C,OAAO;oBACH,IAAI,EAAE,KAAK,CAAC,QAAQ;oBACpB,WAAW;oBACX,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;iBAChD,CAAC;YACN,CAAC,CAAC,CAAA;YAEF,MAAM,IAAI,aAAa,CAAC,OAAO,EAAE,EAAE,MAAM,EAAG,MAAM,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Controller = void 0;
|
|
4
|
+
const metadata_1 = require("../metadata");
|
|
4
5
|
/**
|
|
5
6
|
* Declares a class as a controller and assigns a base route path.
|
|
6
7
|
*
|
|
@@ -36,7 +37,7 @@ exports.Controller = void 0;
|
|
|
36
37
|
*/
|
|
37
38
|
const Controller = (path) => {
|
|
38
39
|
return (target) => {
|
|
39
|
-
return Reflect.defineMetadata(
|
|
40
|
+
return Reflect.defineMetadata(metadata_1.CONTROLLER_METADATA, path, target);
|
|
40
41
|
};
|
|
41
42
|
};
|
|
42
43
|
exports.Controller = Controller;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/controller.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACI,MAAM,UAAU,GAAG,CAAC,IAAkB,EAAkB,EAAE;IAC/D,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO,OAAO,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/controller.ts"],"names":[],"mappings":";;;AAAA,0CAAkD;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACI,MAAM,UAAU,GAAG,CAAC,IAAkB,EAAkB,EAAE;IAC/D,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO,OAAO,CAAC,cAAc,CAAC,8BAAmB,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC,CAAC;AACJ,CAAC,CAAA;AAJY,QAAA,UAAU,cAItB"}
|
|
@@ -23,4 +23,5 @@ __exportStar(require("./headers"), exports);
|
|
|
23
23
|
__exportStar(require("./statusCode"), exports);
|
|
24
24
|
__exportStar(require("./context"), exports);
|
|
25
25
|
__exportStar(require("./swagger"), exports);
|
|
26
|
+
__exportStar(require("./service"), exports);
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4BAAyB;AAEzB,4CAAyB;AACzB,4CAAyB;AACzB,+CAA4B;AAC5B,+CAA4B;AAC5B,4CAAyB;AACzB,+CAA4B;AAC5B,4CAAyB;AACzB,4CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4BAAyB;AAEzB,4CAAyB;AACzB,4CAAyB;AACzB,+CAA4B;AAC5B,+CAA4B;AAC5B,4CAAyB;AACzB,+CAA4B;AAC5B,4CAAyB;AACzB,4CAAyB;AACzB,4CAAyB"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Options = exports.Head = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = void 0;
|
|
4
|
+
const metadata_1 = require("../metadata");
|
|
4
5
|
const methodDecorator = (method) => {
|
|
5
6
|
return (path) => {
|
|
6
7
|
return (target, propertyKey) => {
|
|
7
8
|
const controller = target.constructor;
|
|
8
|
-
const routers = Reflect.hasMetadata(
|
|
9
|
-
? Reflect.getMetadata(
|
|
9
|
+
const routers = Reflect.hasMetadata(metadata_1.ROUTE_METADATA, controller)
|
|
10
|
+
? Reflect.getMetadata(metadata_1.ROUTE_METADATA, controller)
|
|
10
11
|
: [];
|
|
11
12
|
routers.push({
|
|
12
13
|
method,
|
|
13
14
|
path,
|
|
14
15
|
handler: propertyKey,
|
|
15
16
|
});
|
|
16
|
-
Reflect.defineMetadata(
|
|
17
|
+
Reflect.defineMetadata(metadata_1.ROUTE_METADATA, routers, controller);
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/methods.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/methods.ts"],"names":[],"mappings":";;;AAAA,0CAA6C;AAG7C,MAAM,eAAe,GAAG,CAAC,MAAgB,EAAE,EAAE;IAC3C,OAAO,CAAC,IAAkB,EAAmB,EAAE;QAC7C,OAAO,CAAC,MAAU,EAAE,WAAe,EAAE,EAAE;YACrC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;YAEtC,MAAM,OAAO,GAAe,OAAO,CAAC,WAAW,CAAC,yBAAc,EAAE,UAAU,CAAC;gBACzE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,yBAAc,EAAE,UAAU,CAAC;gBACjD,CAAC,CAAC,EAAE,CAAC;YAEP,OAAO,CAAC,IAAI,CAAC;gBACX,MAAM;gBACN,IAAI;gBACJ,OAAO,EAAE,WAAW;aACrB,CAAC,CAAC;YAEH,OAAO,CAAC,cAAc,CAAC,yBAAc,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;GAUG;AACU,QAAA,GAAG,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;AAE1C;;;;;;;;;;GAUG;AACU,QAAA,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;AAE5C;;;;;;;;;;GAUG;AACU,QAAA,GAAG,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;AAE1C;;;;;;;;;;GAUG;AACU,QAAA,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;AAE9C;;;;;;;;GAQG;AACU,QAAA,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;AAEhD;;;;;;;;;;GAUG;AACU,QAAA,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;AAE5C;;;;;;;;;;GAUG;AACU,QAAA,OAAO,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -33,7 +33,45 @@ import { T } from '../types';
|
|
|
33
33
|
* };
|
|
34
34
|
* ```
|
|
35
35
|
*
|
|
36
|
-
* @param {T.ContextHandler}
|
|
36
|
+
* @param {T.ContextHandler[]} middlewares - Middleware function to execute before the route handler.
|
|
37
37
|
* @returns {MethodDecorator}
|
|
38
38
|
*/
|
|
39
|
-
export declare const Middleware: (
|
|
39
|
+
export declare const Middleware: (...middlewares: (T.ContextHandler | T.ContextHandler[])[]) => MethodDecorator;
|
|
40
|
+
/**
|
|
41
|
+
* Attaches a middleware function to a controller method.
|
|
42
|
+
*
|
|
43
|
+
* The middleware will be executed **before the route handler**.
|
|
44
|
+
* If the middleware calls `next(err)`, the error will be forwarded
|
|
45
|
+
* to the framework's error handler. Otherwise, the original
|
|
46
|
+
* controller method will be executed.
|
|
47
|
+
*
|
|
48
|
+
* This decorator also stores middleware metadata using `Reflect.defineMetadata`
|
|
49
|
+
* so the framework can discover and execute it during the request lifecycle.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* class UserController {
|
|
54
|
+
*
|
|
55
|
+
* \@UseGuards(authMiddleware)
|
|
56
|
+
* async profile(ctx: T.Context) {
|
|
57
|
+
* return { user: ctx.user };
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* Example middleware:
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* const authMiddleware: T.ContextHandler = (ctx, next) => {
|
|
67
|
+
* if (!ctx.user) {
|
|
68
|
+
* return next(new Error("Unauthorized"));
|
|
69
|
+
* }
|
|
70
|
+
* next();
|
|
71
|
+
* };
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @param {T.ContextHandler[]} middlewares - Middleware function to execute before the route handler.
|
|
75
|
+
* @returns {MethodDecorator}
|
|
76
|
+
*/
|
|
77
|
+
export declare const UseGuards: (...middlewares: (T.ContextHandler | T.ContextHandler[])[]) => MethodDecorator;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Middleware = void 0;
|
|
3
|
+
exports.UseGuards = exports.Middleware = void 0;
|
|
4
|
+
const metadata_1 = require("../metadata");
|
|
4
5
|
/**
|
|
5
6
|
* Attaches a middleware function to a controller method.
|
|
6
7
|
*
|
|
@@ -35,21 +36,27 @@ exports.Middleware = void 0;
|
|
|
35
36
|
* };
|
|
36
37
|
* ```
|
|
37
38
|
*
|
|
38
|
-
* @param {T.ContextHandler}
|
|
39
|
+
* @param {T.ContextHandler[]} middlewares - Middleware function to execute before the route handler.
|
|
39
40
|
* @returns {MethodDecorator}
|
|
40
41
|
*/
|
|
41
|
-
const Middleware = (
|
|
42
|
-
return (target,
|
|
42
|
+
const Middleware = (...middlewares) => {
|
|
43
|
+
return (target, _, descriptor) => {
|
|
43
44
|
const originalMethod = descriptor.value;
|
|
44
45
|
descriptor.value = function (ctx, next) {
|
|
45
46
|
try {
|
|
46
|
-
Reflect.defineMetadata(
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
Reflect.defineMetadata(metadata_1.MIDDLEWARE_METADATA, descriptor, target);
|
|
48
|
+
let index = 0;
|
|
49
|
+
const nextMiddleware = (err) => {
|
|
50
|
+
if (err) {
|
|
49
51
|
return next(err);
|
|
50
52
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
const middleware = middlewares.flat()[index++];
|
|
54
|
+
if (!middleware) {
|
|
55
|
+
return originalMethod.call(this, ctx, next);
|
|
56
|
+
}
|
|
57
|
+
return middleware(ctx, nextMiddleware);
|
|
58
|
+
};
|
|
59
|
+
return nextMiddleware();
|
|
53
60
|
}
|
|
54
61
|
catch (error) {
|
|
55
62
|
return next(error);
|
|
@@ -58,4 +65,42 @@ const Middleware = (middleware) => {
|
|
|
58
65
|
};
|
|
59
66
|
};
|
|
60
67
|
exports.Middleware = Middleware;
|
|
68
|
+
/**
|
|
69
|
+
* Attaches a middleware function to a controller method.
|
|
70
|
+
*
|
|
71
|
+
* The middleware will be executed **before the route handler**.
|
|
72
|
+
* If the middleware calls `next(err)`, the error will be forwarded
|
|
73
|
+
* to the framework's error handler. Otherwise, the original
|
|
74
|
+
* controller method will be executed.
|
|
75
|
+
*
|
|
76
|
+
* This decorator also stores middleware metadata using `Reflect.defineMetadata`
|
|
77
|
+
* so the framework can discover and execute it during the request lifecycle.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* class UserController {
|
|
82
|
+
*
|
|
83
|
+
* \@UseGuards(authMiddleware)
|
|
84
|
+
* async profile(ctx: T.Context) {
|
|
85
|
+
* return { user: ctx.user };
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* Example middleware:
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* const authMiddleware: T.ContextHandler = (ctx, next) => {
|
|
95
|
+
* if (!ctx.user) {
|
|
96
|
+
* return next(new Error("Unauthorized"));
|
|
97
|
+
* }
|
|
98
|
+
* next();
|
|
99
|
+
* };
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @param {T.ContextHandler[]} middlewares - Middleware function to execute before the route handler.
|
|
103
|
+
* @returns {MethodDecorator}
|
|
104
|
+
*/
|
|
105
|
+
exports.UseGuards = exports.Middleware;
|
|
61
106
|
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;AAAA,0CAAkD;AAGlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACI,MAAM,UAAU,GAAG,CAAC,GAAG,WAAsD,EAAmB,EAAE;IAEvG,OAAO,CAAC,MAAW,EAAE,CAAM,EAAE,UAA8B,EAAE,EAAE;QAC7D,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,UAAU,GAAc,EAAE,IAAoB;YAC/D,IAAI,CAAC;gBAEH,OAAO,CAAC,cAAc,CAAC,8BAAmB,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;gBAEhE,IAAI,KAAK,GAAG,CAAC,CAAC;gBAEd,MAAM,cAAc,GAAG,CAAC,GAAS,EAAO,EAAE;oBACxC,IAAI,GAAG,EAAE,CAAC;wBACR,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;oBACnB,CAAC;oBAED,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;oBAE/C,IAAI,CAAC,UAAU,EAAE,CAAC;wBAChB,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;oBAC9C,CAAC;oBAED,OAAO,UAAU,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;gBACzC,CAAC,CAAC;gBAEF,OAAO,cAAc,EAAE,CAAC;YAE1B,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBAEpB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAlCW,QAAA,UAAU,cAkCrB;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACU,QAAA,SAAS,GAAG,kBAAU,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type ServiceClass = new () => unknown;
|
|
2
|
+
/**
|
|
3
|
+
* Registers service dependencies for a controller.
|
|
4
|
+
*
|
|
5
|
+
* The specified services will be available for dependency injection
|
|
6
|
+
* when the controller instance is created.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* \@Service([
|
|
11
|
+
* CatService,
|
|
12
|
+
* DogService
|
|
13
|
+
* ])
|
|
14
|
+
* \@Controller('/cats')
|
|
15
|
+
* class CatController {
|
|
16
|
+
*
|
|
17
|
+
* constructor(
|
|
18
|
+
* private dogService: DogService,
|
|
19
|
+
* private catService: CatService
|
|
20
|
+
* ) {}
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param services Array of service classes to register.
|
|
25
|
+
* @returns Class decorator.
|
|
26
|
+
*/
|
|
27
|
+
export declare const Service: (...services: (ServiceClass | ServiceClass[])[]) => ClassDecorator;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Service = void 0;
|
|
4
|
+
const metadata_1 = require("../metadata");
|
|
5
|
+
/**
|
|
6
|
+
* Registers service dependencies for a controller.
|
|
7
|
+
*
|
|
8
|
+
* The specified services will be available for dependency injection
|
|
9
|
+
* when the controller instance is created.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* \@Service([
|
|
14
|
+
* CatService,
|
|
15
|
+
* DogService
|
|
16
|
+
* ])
|
|
17
|
+
* \@Controller('/cats')
|
|
18
|
+
* class CatController {
|
|
19
|
+
*
|
|
20
|
+
* constructor(
|
|
21
|
+
* private dogService: DogService,
|
|
22
|
+
* private catService: CatService
|
|
23
|
+
* ) {}
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param services Array of service classes to register.
|
|
28
|
+
* @returns Class decorator.
|
|
29
|
+
*/
|
|
30
|
+
const Service = (...services) => {
|
|
31
|
+
return (target) => {
|
|
32
|
+
Reflect.defineMetadata(metadata_1.SERVICE_METADATA, services.flat(), target);
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.Service = Service;
|
|
36
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/service.ts"],"names":[],"mappings":";;;AAAA,0CAA+C;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACI,MAAM,OAAO,GAAG,CAAC,GAAG,QAA2C,EAAkB,EAAE;IACxF,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO,CAAC,cAAc,CAAC,2BAAgB,EAAC,QAAQ,CAAC,IAAI,EAAE,EAAC,MAAM,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC,CAAA;AAJY,QAAA,OAAO,WAInB"}
|
|
@@ -30,7 +30,9 @@ const StatusCode = (statusCode) => {
|
|
|
30
30
|
const originalMethod = descriptor.value;
|
|
31
31
|
const code = statusCode < 100 ? 100 : statusCode > 599 ? 599 : statusCode;
|
|
32
32
|
descriptor.value = async function (ctx, next) {
|
|
33
|
-
ctx.res.
|
|
33
|
+
if (!ctx.res.headersSent) {
|
|
34
|
+
ctx.res.writeHead(code, { 'Content-Type': 'application/json' });
|
|
35
|
+
}
|
|
34
36
|
return await originalMethod.call(this, ctx, next);
|
|
35
37
|
};
|
|
36
38
|
return descriptor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statusCode.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/statusCode.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,UAAU,GAAG,CAAC,UAAwB,EAAmB,EAAE;IACpE,OAAO,CAAC,MAAW,EAAE,GAAQ,EAAE,UAA8B,EAAE,EAAE;QAC7D,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,MAAM,IAAI,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC;QAE1E,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAc,EAAE,IAAoB;YACnE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"statusCode.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/statusCode.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,UAAU,GAAG,CAAC,UAAwB,EAAmB,EAAE;IACpE,OAAO,CAAC,MAAW,EAAE,GAAQ,EAAE,UAA8B,EAAE,EAAE;QAC7D,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,MAAM,IAAI,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC;QAE1E,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAc,EAAE,IAAoB;YACnE,IAAG,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;gBACtB,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC,CAAC;AAfW,QAAA,UAAU,cAerB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Swagger = void 0;
|
|
4
|
+
const metadata_1 = require("../metadata");
|
|
4
5
|
/**
|
|
5
6
|
* Attaches Swagger/OpenAPI specification metadata to a controller method.
|
|
6
7
|
*
|
|
@@ -38,14 +39,14 @@ exports.Swagger = void 0;
|
|
|
38
39
|
const Swagger = (data = {}) => {
|
|
39
40
|
return (target, propertyKey) => {
|
|
40
41
|
const controller = target.constructor;
|
|
41
|
-
const swaggers = Reflect.hasMetadata(
|
|
42
|
-
? Reflect.getMetadata(
|
|
42
|
+
const swaggers = Reflect.hasMetadata(metadata_1.SWAGGER_METADATA, controller)
|
|
43
|
+
? Reflect.getMetadata(metadata_1.SWAGGER_METADATA, controller)
|
|
43
44
|
: [];
|
|
44
45
|
swaggers.push({
|
|
45
46
|
handler: propertyKey,
|
|
46
47
|
...data,
|
|
47
48
|
});
|
|
48
|
-
Reflect.defineMetadata(
|
|
49
|
+
Reflect.defineMetadata(metadata_1.SWAGGER_METADATA, swaggers, controller);
|
|
49
50
|
};
|
|
50
51
|
};
|
|
51
52
|
exports.Swagger = Swagger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/swagger.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/swagger.ts"],"names":[],"mappings":";;;AAAA,0CAA+C;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,MAAM,OAAO,GAAG,CAAC,OAAuB,EAAE,EAAmB,EAAE;IACpE,OAAO,CAAC,MAAW,EAAE,WAAgB,EAAE,EAAE;QACvC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;QAEtC,MAAM,QAAQ,GAAU,OAAO,CAAC,WAAW,CAAC,2BAAgB,EAAE,UAAU,CAAC;YACvE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,2BAAgB,EAAE,UAAU,CAAC;YACnD,CAAC,CAAC,EAAE,CAAC;QAEP,QAAQ,CAAC,IAAI,CAAC;YACZ,OAAO,EAAE,WAAW;YACpB,GAAG,IAAI;SACR,CAAC,CAAC;QAEH,OAAO,CAAC,cAAc,CAAC,2BAAgB,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,OAAO,WAelB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export declare const HttpStatus: {
|
|
2
|
+
readonly BAD_REQUEST: 400;
|
|
3
|
+
readonly UNAUTHORIZED: 401;
|
|
4
|
+
readonly FORBIDDEN: 403;
|
|
5
|
+
readonly NOT_FOUND: 404;
|
|
6
|
+
readonly METHOD_NOT_ALLOWED: 405;
|
|
7
|
+
readonly CONFLICT: 409;
|
|
8
|
+
readonly GONE: 410;
|
|
9
|
+
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
|
10
|
+
readonly UNPROCESSABLE_ENTITY: 422;
|
|
11
|
+
readonly TOO_MANY_REQUESTS: 429;
|
|
12
|
+
readonly INTERNAL_SERVER_ERROR: 500;
|
|
13
|
+
readonly NOT_IMPLEMENTED: 501;
|
|
14
|
+
readonly BAD_GATEWAY: 502;
|
|
15
|
+
readonly SERVICE_UNAVAILABLE: 503;
|
|
16
|
+
readonly GATEWAY_TIMEOUT: 504;
|
|
17
|
+
};
|
|
18
|
+
declare class HttpException extends Error {
|
|
19
|
+
readonly statusCode: number;
|
|
20
|
+
readonly message: string;
|
|
21
|
+
constructor(statusCode: number, message: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class BadRequestException extends HttpException {
|
|
24
|
+
constructor(message?: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class UnauthorizedException extends HttpException {
|
|
27
|
+
constructor(message?: string);
|
|
28
|
+
}
|
|
29
|
+
export declare class ForbiddenException extends HttpException {
|
|
30
|
+
constructor(message?: string);
|
|
31
|
+
}
|
|
32
|
+
export declare class NotFoundException extends HttpException {
|
|
33
|
+
constructor(message?: string);
|
|
34
|
+
}
|
|
35
|
+
export declare class MethodNotAllowedException extends HttpException {
|
|
36
|
+
constructor(message?: string);
|
|
37
|
+
}
|
|
38
|
+
export declare class ConflictException extends HttpException {
|
|
39
|
+
constructor(message?: string);
|
|
40
|
+
}
|
|
41
|
+
export declare class GoneException extends HttpException {
|
|
42
|
+
constructor(message?: string);
|
|
43
|
+
}
|
|
44
|
+
export declare class UnsupportedMediaTypeException extends HttpException {
|
|
45
|
+
constructor(message?: string);
|
|
46
|
+
}
|
|
47
|
+
export declare class UnprocessableEntityException extends HttpException {
|
|
48
|
+
constructor(message?: string);
|
|
49
|
+
}
|
|
50
|
+
export declare class TooManyRequestsException extends HttpException {
|
|
51
|
+
constructor(message?: string);
|
|
52
|
+
}
|
|
53
|
+
export declare class InternalServerErrorException extends HttpException {
|
|
54
|
+
constructor(message?: string);
|
|
55
|
+
}
|
|
56
|
+
export declare class NotImplementedException extends HttpException {
|
|
57
|
+
constructor(message?: string);
|
|
58
|
+
}
|
|
59
|
+
export declare class BadGatewayException extends HttpException {
|
|
60
|
+
constructor(message?: string);
|
|
61
|
+
}
|
|
62
|
+
export declare class ServiceUnavailableException extends HttpException {
|
|
63
|
+
constructor(message?: string);
|
|
64
|
+
}
|
|
65
|
+
export declare class GatewayTimeoutException extends HttpException {
|
|
66
|
+
constructor(message?: string);
|
|
67
|
+
}
|
|
68
|
+
export {};
|