@open-norantec/herbal 1.0.2-alpha.36 → 1.0.2-alpha.37
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/core.d.ts +0 -4
- package/dist/core.js +69 -76
- package/package.json +1 -1
package/dist/core.d.ts
CHANGED
|
@@ -8,14 +8,10 @@ import { Constructor } from 'type-fest';
|
|
|
8
8
|
import { AuthAdapter } from './abstracts/auth-adapter.abstract.class';
|
|
9
9
|
import { PathsObject } from 'zod-openapi/dist/openapi3-ts/dist/model/openapi31';
|
|
10
10
|
export * from '@nestjs/core';
|
|
11
|
-
declare const HANDLE_REQUEST_SYMBOL: unique symbol;
|
|
12
11
|
export type MethodHandler<IS extends z.Schema<any>, OS extends z.Schema<any>> = (request: Request, input: unknown, headers: ReturnType<typeof HeaderUtil.parse>) => Promise<{
|
|
13
12
|
request: z.infer<IS>;
|
|
14
13
|
response: z.infer<OS>;
|
|
15
14
|
}>;
|
|
16
|
-
export declare class HerbalController {
|
|
17
|
-
private [HANDLE_REQUEST_SYMBOL];
|
|
18
|
-
}
|
|
19
15
|
type ClientGroups = Array<string> | null | undefined;
|
|
20
16
|
type ClienttGroupsFactory = (defaultGroupName: string) => ClientGroups;
|
|
21
17
|
export interface MethodRegisterOptions<IS extends z.Schema<any>, OS extends z.Schema<any>> {
|
package/dist/core.js
CHANGED
|
@@ -86,7 +86,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
86
86
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
87
87
|
};
|
|
88
88
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
|
-
exports.ControllerUtil = exports.getMethodPool = exports.getControllerName = exports.isHerbalController =
|
|
89
|
+
exports.ControllerUtil = exports.getMethodPool = exports.getControllerName = exports.isHerbalController = void 0;
|
|
90
90
|
require("reflect-metadata");
|
|
91
91
|
var common_1 = require("@nestjs/common");
|
|
92
92
|
var header_util_class_1 = require("@open-norantec/utilities/dist/header-util.class");
|
|
@@ -108,70 +108,7 @@ var sequelize_typescript_1 = require("sequelize-typescript");
|
|
|
108
108
|
var decorators_1 = require("./decorators");
|
|
109
109
|
var zod_openapi_1 = require("zod-openapi");
|
|
110
110
|
__exportStar(require("@nestjs/core"), exports);
|
|
111
|
-
var HANDLE_REQUEST_SYMBOL = Symbol();
|
|
112
111
|
var HANDLE_REQUEST_INSTANCE_SYMBOL = '$handleRequestInstance';
|
|
113
|
-
var HerbalController = (function () {
|
|
114
|
-
function HerbalController() {
|
|
115
|
-
}
|
|
116
|
-
HerbalController.prototype[HANDLE_REQUEST_SYMBOL] = function (request) {
|
|
117
|
-
var _a, _b, _c, _d, _e, _f;
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var callFn, result, error_1;
|
|
120
|
-
var _g;
|
|
121
|
-
var _this = this;
|
|
122
|
-
return __generator(this, function (_h) {
|
|
123
|
-
switch (_h.label) {
|
|
124
|
-
case 0:
|
|
125
|
-
callFn = (_b = (_a = getMethodPool(this)) === null || _a === void 0 ? void 0 : _a.getCallFn) === null || _b === void 0 ? void 0 : _b.call(_a, request.methodName);
|
|
126
|
-
if (typeof callFn !== 'function')
|
|
127
|
-
throw new common_1.NotFoundException("Method ".concat(request.methodName, " not found"));
|
|
128
|
-
_h.label = 1;
|
|
129
|
-
case 1:
|
|
130
|
-
_h.trys.push([1, 4, , 6]);
|
|
131
|
-
_g = {};
|
|
132
|
-
return [4, callFn(this, {
|
|
133
|
-
authenticateResult: request.authenticateResult,
|
|
134
|
-
headers: header_util_class_1.HeaderUtil.parse((_c = request.headers) !== null && _c !== void 0 ? _c : {}),
|
|
135
|
-
methodName: request.methodName,
|
|
136
|
-
rawBody: request.rawBody,
|
|
137
|
-
traceId: request.traceId,
|
|
138
|
-
transaction: request.transaction,
|
|
139
|
-
url: request.originalUrl,
|
|
140
|
-
})];
|
|
141
|
-
case 2:
|
|
142
|
-
result = (_g.data = _h.sent(),
|
|
143
|
-
_g.token = string_util_class_1.StringUtil.isFalsyString((_d = request === null || request === void 0 ? void 0 : request.authenticateResult) === null || _d === void 0 ? void 0 : _d.nextToken)
|
|
144
|
-
? null
|
|
145
|
-
: request.authenticateResult.nextToken,
|
|
146
|
-
_g);
|
|
147
|
-
return [4, ((_f = (_e = request === null || request === void 0 ? void 0 : request.transaction) === null || _e === void 0 ? void 0 : _e.commit) === null || _f === void 0 ? void 0 : _f.call(_e))];
|
|
148
|
-
case 3:
|
|
149
|
-
_h.sent();
|
|
150
|
-
return [2, result];
|
|
151
|
-
case 4:
|
|
152
|
-
error_1 = _h.sent();
|
|
153
|
-
return [4, utilities_1.AttemptUtil.execPromise((function () { return __awaiter(_this, void 0, void 0, function () {
|
|
154
|
-
var _a, _b;
|
|
155
|
-
return __generator(this, function (_c) {
|
|
156
|
-
switch (_c.label) {
|
|
157
|
-
case 0: return [4, ((_b = (_a = request === null || request === void 0 ? void 0 : request.transaction) === null || _a === void 0 ? void 0 : _a.rollback) === null || _b === void 0 ? void 0 : _b.call(_a))];
|
|
158
|
-
case 1:
|
|
159
|
-
_c.sent();
|
|
160
|
-
return [2];
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}); })())];
|
|
164
|
-
case 5:
|
|
165
|
-
_h.sent();
|
|
166
|
-
throw error_1;
|
|
167
|
-
case 6: return [2];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
return HerbalController;
|
|
173
|
-
}());
|
|
174
|
-
exports.HerbalController = HerbalController;
|
|
175
112
|
var METHOD_POOL = Symbol();
|
|
176
113
|
var MethodConfig = (function () {
|
|
177
114
|
function MethodConfig(name, options, callback) {
|
|
@@ -182,7 +119,7 @@ var MethodConfig = (function () {
|
|
|
182
119
|
MethodConfig.prototype.call = function (controller, callContext) {
|
|
183
120
|
var _a, _b, _c, _d, _e, _f;
|
|
184
121
|
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
var inputSchema, outputSchema, parsedBody_1, input, rawResponse_1, response,
|
|
122
|
+
var inputSchema, outputSchema, parsedBody_1, input, rawResponse_1, response, error_1;
|
|
186
123
|
return __generator(this, function (_g) {
|
|
187
124
|
switch (_g.label) {
|
|
188
125
|
case 0:
|
|
@@ -215,8 +152,8 @@ var MethodConfig = (function () {
|
|
|
215
152
|
throw response;
|
|
216
153
|
return [2, response];
|
|
217
154
|
case 3:
|
|
218
|
-
|
|
219
|
-
throw
|
|
155
|
+
error_1 = _g.sent();
|
|
156
|
+
throw error_1;
|
|
220
157
|
case 4: return [2];
|
|
221
158
|
}
|
|
222
159
|
});
|
|
@@ -373,7 +310,7 @@ function HerbalGuard(options) {
|
|
|
373
310
|
var _a, e_1, _b, _c;
|
|
374
311
|
var _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
375
312
|
return __awaiter(this, void 0, void 0, function () {
|
|
376
|
-
var sequelizeInstance, transaction, request, response, traceId, chunks, _o, request_1, request_1_1, chunk, e_1_1, _p, parsedBody, rawHandlerName, handlerPropertype, handlerName, methodPool, authAdapters,
|
|
313
|
+
var sequelizeInstance, transaction, request, response, traceId, chunks, _o, request_1, request_1_1, chunk, e_1_1, _p, parsedBody, rawHandlerName, handlerPropertype, handlerName, methodPool, authAdapters, error_2, _i, authAdapters_1, AuthAdapterClass, adapter, authenticateResult, error_3, _q;
|
|
377
314
|
var _this = this;
|
|
378
315
|
return __generator(this, function (_r) {
|
|
379
316
|
switch (_r.label) {
|
|
@@ -460,9 +397,9 @@ function HerbalGuard(options) {
|
|
|
460
397
|
this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":transaction] Started transaction for route: ").concat(handlerName));
|
|
461
398
|
return [3, 19];
|
|
462
399
|
case 18:
|
|
463
|
-
|
|
464
|
-
if (
|
|
465
|
-
this.getLogger().error("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":transaction] Failed to start transaction: ").concat(
|
|
400
|
+
error_2 = _r.sent();
|
|
401
|
+
if (error_2 instanceof Error) {
|
|
402
|
+
this.getLogger().error("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":transaction] Failed to start transaction: ").concat(error_2 === null || error_2 === void 0 ? void 0 : error_2.message, "\n").concat(error_2 === null || error_2 === void 0 ? void 0 : error_2.stack));
|
|
466
403
|
}
|
|
467
404
|
return [3, 19];
|
|
468
405
|
case 19: return [3, 21];
|
|
@@ -495,12 +432,12 @@ function HerbalGuard(options) {
|
|
|
495
432
|
case 25: throw new common_3.UnauthorizedException();
|
|
496
433
|
case 26: return [3, 32];
|
|
497
434
|
case 27:
|
|
498
|
-
|
|
435
|
+
error_3 = _r.sent();
|
|
499
436
|
_r.label = 28;
|
|
500
437
|
case 28:
|
|
501
438
|
_r.trys.push([28, 30, , 31]);
|
|
502
|
-
if (
|
|
503
|
-
this.getLogger().error("Got error when handling route: ".concat(
|
|
439
|
+
if (error_3 instanceof Error) {
|
|
440
|
+
this.getLogger().error("Got error when handling route: ".concat(error_3 === null || error_3 === void 0 ? void 0 : error_3.message, " ").concat(error_3 === null || error_3 === void 0 ? void 0 : error_3.stack));
|
|
504
441
|
}
|
|
505
442
|
return [4, ((_m = transaction === null || transaction === void 0 ? void 0 : transaction.rollback) === null || _m === void 0 ? void 0 : _m.call(transaction))];
|
|
506
443
|
case 29:
|
|
@@ -509,7 +446,7 @@ function HerbalGuard(options) {
|
|
|
509
446
|
case 30:
|
|
510
447
|
_q = _r.sent();
|
|
511
448
|
return [3, 31];
|
|
512
|
-
case 31: throw
|
|
449
|
+
case 31: throw error_3;
|
|
513
450
|
case 32: return [2, true];
|
|
514
451
|
}
|
|
515
452
|
});
|
|
@@ -572,11 +509,67 @@ var ControllerUtil = (function () {
|
|
|
572
509
|
Reflect.defineMetadata(METHOD_POOL, methodPool, target.prototype);
|
|
573
510
|
if (typeof (options === null || options === void 0 ? void 0 : options.methods) === 'function')
|
|
574
511
|
options.methods(register);
|
|
512
|
+
function handleRequest(request) {
|
|
513
|
+
var _a, _b, _c, _d, _e, _f;
|
|
514
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
515
|
+
var callFn, result, error_4;
|
|
516
|
+
var _g;
|
|
517
|
+
var _this = this;
|
|
518
|
+
return __generator(this, function (_h) {
|
|
519
|
+
switch (_h.label) {
|
|
520
|
+
case 0:
|
|
521
|
+
callFn = (_b = (_a = getMethodPool(this)) === null || _a === void 0 ? void 0 : _a.getCallFn) === null || _b === void 0 ? void 0 : _b.call(_a, request.methodName);
|
|
522
|
+
if (typeof callFn !== 'function')
|
|
523
|
+
throw new common_1.NotFoundException("Method ".concat(request.methodName, " not found"));
|
|
524
|
+
_h.label = 1;
|
|
525
|
+
case 1:
|
|
526
|
+
_h.trys.push([1, 4, , 6]);
|
|
527
|
+
_g = {};
|
|
528
|
+
return [4, callFn(this, {
|
|
529
|
+
authenticateResult: request.authenticateResult,
|
|
530
|
+
headers: header_util_class_1.HeaderUtil.parse((_c = request.headers) !== null && _c !== void 0 ? _c : {}),
|
|
531
|
+
methodName: request.methodName,
|
|
532
|
+
rawBody: request.rawBody,
|
|
533
|
+
traceId: request.traceId,
|
|
534
|
+
transaction: request.transaction,
|
|
535
|
+
url: request.originalUrl,
|
|
536
|
+
})];
|
|
537
|
+
case 2:
|
|
538
|
+
result = (_g.data = _h.sent(),
|
|
539
|
+
_g.token = string_util_class_1.StringUtil.isFalsyString((_d = request === null || request === void 0 ? void 0 : request.authenticateResult) === null || _d === void 0 ? void 0 : _d.nextToken)
|
|
540
|
+
? null
|
|
541
|
+
: request.authenticateResult.nextToken,
|
|
542
|
+
_g);
|
|
543
|
+
return [4, ((_f = (_e = request === null || request === void 0 ? void 0 : request.transaction) === null || _e === void 0 ? void 0 : _e.commit) === null || _f === void 0 ? void 0 : _f.call(_e))];
|
|
544
|
+
case 3:
|
|
545
|
+
_h.sent();
|
|
546
|
+
return [2, result];
|
|
547
|
+
case 4:
|
|
548
|
+
error_4 = _h.sent();
|
|
549
|
+
return [4, utilities_1.AttemptUtil.execPromise((function () { return __awaiter(_this, void 0, void 0, function () {
|
|
550
|
+
var _a, _b;
|
|
551
|
+
return __generator(this, function (_c) {
|
|
552
|
+
switch (_c.label) {
|
|
553
|
+
case 0: return [4, ((_b = (_a = request === null || request === void 0 ? void 0 : request.transaction) === null || _a === void 0 ? void 0 : _a.rollback) === null || _b === void 0 ? void 0 : _b.call(_a))];
|
|
554
|
+
case 1:
|
|
555
|
+
_c.sent();
|
|
556
|
+
return [2];
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
}); })())];
|
|
560
|
+
case 5:
|
|
561
|
+
_h.sent();
|
|
562
|
+
throw error_4;
|
|
563
|
+
case 6: return [2];
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
}
|
|
575
568
|
Object.defineProperty(target.prototype, HANDLE_REQUEST_INSTANCE_SYMBOL, {
|
|
576
569
|
enumerable: false,
|
|
577
570
|
writable: false,
|
|
578
571
|
value: function (request) {
|
|
579
|
-
return
|
|
572
|
+
return handleRequest.call(this, request);
|
|
580
573
|
},
|
|
581
574
|
});
|
|
582
575
|
(0, common_1.Req)()(target.prototype, HANDLE_REQUEST_INSTANCE_SYMBOL, 0);
|