@hono-di/core 0.0.7 → 0.0.9
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.cjs +420 -182
- package/dist/core.js +420 -182
- package/dist/decorators.cjs +76 -54
- package/dist/decorators.js +76 -54
- package/dist/index.cjs +417 -231
- package/dist/index.js +417 -231
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -5,14 +5,8 @@ var hono = require('hono');
|
|
|
5
5
|
var rxjs = require('rxjs');
|
|
6
6
|
var operators = require('rxjs/operators');
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
11
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
12
|
-
if (decorator = decorators[i])
|
|
13
|
-
result = (decorator(result)) || result;
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
16
10
|
|
|
17
11
|
// src/constants.ts
|
|
18
12
|
var METADATA_KEYS = {
|
|
@@ -42,15 +36,15 @@ var METADATA_KEYS = {
|
|
|
42
36
|
};
|
|
43
37
|
|
|
44
38
|
// src/injector/scope.ts
|
|
45
|
-
var Scope = /* @__PURE__ */ ((Scope2)
|
|
39
|
+
var Scope = /* @__PURE__ */ (function(Scope2) {
|
|
46
40
|
Scope2[Scope2["DEFAULT"] = 0] = "DEFAULT";
|
|
47
41
|
Scope2[Scope2["TRANSIENT"] = 1] = "TRANSIENT";
|
|
48
42
|
Scope2[Scope2["REQUEST"] = 2] = "REQUEST";
|
|
49
43
|
return Scope2;
|
|
50
|
-
})(
|
|
44
|
+
})({});
|
|
51
45
|
|
|
52
46
|
// src/interfaces.ts
|
|
53
|
-
var RequestMethod = /* @__PURE__ */ ((RequestMethod2)
|
|
47
|
+
var RequestMethod = /* @__PURE__ */ (function(RequestMethod2) {
|
|
54
48
|
RequestMethod2["GET"] = "get";
|
|
55
49
|
RequestMethod2["POST"] = "post";
|
|
56
50
|
RequestMethod2["PUT"] = "put";
|
|
@@ -60,7 +54,7 @@ var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => {
|
|
|
60
54
|
RequestMethod2["OPTIONS"] = "options";
|
|
61
55
|
RequestMethod2["HEAD"] = "head";
|
|
62
56
|
return RequestMethod2;
|
|
63
|
-
})(
|
|
57
|
+
})({});
|
|
64
58
|
|
|
65
59
|
// src/decorators.ts
|
|
66
60
|
function Global() {
|
|
@@ -68,22 +62,28 @@ function Global() {
|
|
|
68
62
|
Reflect.defineMetadata(METADATA_KEYS.GLOBAL, true, target);
|
|
69
63
|
};
|
|
70
64
|
}
|
|
65
|
+
__name(Global, "Global");
|
|
71
66
|
function Module(options) {
|
|
72
67
|
return (target) => {
|
|
73
68
|
Reflect.defineMetadata(METADATA_KEYS.MODULE, options, target);
|
|
74
69
|
};
|
|
75
70
|
}
|
|
71
|
+
__name(Module, "Module");
|
|
76
72
|
function Injectable(options) {
|
|
77
73
|
return (target) => {
|
|
78
|
-
Reflect.defineMetadata(METADATA_KEYS.SCOPE, options?.scope ??
|
|
74
|
+
Reflect.defineMetadata(METADATA_KEYS.SCOPE, options?.scope ?? Scope.DEFAULT, target);
|
|
79
75
|
};
|
|
80
76
|
}
|
|
77
|
+
__name(Injectable, "Injectable");
|
|
81
78
|
function Controller(prefix = "") {
|
|
82
79
|
return (target) => {
|
|
83
|
-
Reflect.defineMetadata(METADATA_KEYS.CONTROLLER, {
|
|
84
|
-
|
|
80
|
+
Reflect.defineMetadata(METADATA_KEYS.CONTROLLER, {
|
|
81
|
+
prefix
|
|
82
|
+
}, target);
|
|
83
|
+
Reflect.defineMetadata(METADATA_KEYS.SCOPE, Scope.DEFAULT, target);
|
|
85
84
|
};
|
|
86
85
|
}
|
|
86
|
+
__name(Controller, "Controller");
|
|
87
87
|
function createRouteDecorator(method) {
|
|
88
88
|
return (path = "/") => {
|
|
89
89
|
return (target, propertyKey, descriptor) => {
|
|
@@ -100,20 +100,22 @@ function createRouteDecorator(method) {
|
|
|
100
100
|
};
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
var
|
|
105
|
-
var
|
|
106
|
-
var
|
|
107
|
-
var
|
|
108
|
-
var
|
|
109
|
-
var
|
|
110
|
-
var
|
|
103
|
+
__name(createRouteDecorator, "createRouteDecorator");
|
|
104
|
+
var Get = createRouteDecorator(RequestMethod.GET);
|
|
105
|
+
var Post = createRouteDecorator(RequestMethod.POST);
|
|
106
|
+
var Put = createRouteDecorator(RequestMethod.PUT);
|
|
107
|
+
var Delete = createRouteDecorator(RequestMethod.DELETE);
|
|
108
|
+
var Patch = createRouteDecorator(RequestMethod.PATCH);
|
|
109
|
+
var Options = createRouteDecorator(RequestMethod.OPTIONS);
|
|
110
|
+
var Head = createRouteDecorator(RequestMethod.HEAD);
|
|
111
|
+
var All = createRouteDecorator(RequestMethod.ALL);
|
|
111
112
|
function Catch(...exceptions) {
|
|
112
113
|
return (target) => {
|
|
113
114
|
Reflect.defineMetadata(METADATA_KEYS.FILTER_CATCH, exceptions, target);
|
|
114
|
-
Reflect.defineMetadata(METADATA_KEYS.SCOPE,
|
|
115
|
+
Reflect.defineMetadata(METADATA_KEYS.SCOPE, Scope.DEFAULT, target);
|
|
115
116
|
};
|
|
116
117
|
}
|
|
118
|
+
__name(Catch, "Catch");
|
|
117
119
|
function UseFilters(...filters) {
|
|
118
120
|
return (target, propertyKey, descriptor) => {
|
|
119
121
|
if (descriptor) {
|
|
@@ -124,6 +126,7 @@ function UseFilters(...filters) {
|
|
|
124
126
|
return target;
|
|
125
127
|
};
|
|
126
128
|
}
|
|
129
|
+
__name(UseFilters, "UseFilters");
|
|
127
130
|
function Inject(token) {
|
|
128
131
|
return (target, propertyKey, parameterIndex) => {
|
|
129
132
|
if (parameterIndex !== void 0) {
|
|
@@ -132,11 +135,15 @@ function Inject(token) {
|
|
|
132
135
|
Reflect.defineMetadata(METADATA_KEYS.INJECTIONS, injections, target);
|
|
133
136
|
} else {
|
|
134
137
|
const properties = Reflect.getMetadata(METADATA_KEYS.PROPERTY_DEPS, target.constructor) || [];
|
|
135
|
-
properties.push({
|
|
138
|
+
properties.push({
|
|
139
|
+
key: propertyKey,
|
|
140
|
+
token
|
|
141
|
+
});
|
|
136
142
|
Reflect.defineMetadata(METADATA_KEYS.PROPERTY_DEPS, properties, target.constructor);
|
|
137
143
|
}
|
|
138
144
|
};
|
|
139
145
|
}
|
|
146
|
+
__name(Inject, "Inject");
|
|
140
147
|
function Optional() {
|
|
141
148
|
return (target, propertyKey, parameterIndex) => {
|
|
142
149
|
if (parameterIndex !== void 0) {
|
|
@@ -150,6 +157,7 @@ function Optional() {
|
|
|
150
157
|
}
|
|
151
158
|
};
|
|
152
159
|
}
|
|
160
|
+
__name(Optional, "Optional");
|
|
153
161
|
function UseGuards(...guards) {
|
|
154
162
|
return (target, propertyKey, descriptor) => {
|
|
155
163
|
if (descriptor) {
|
|
@@ -160,6 +168,7 @@ function UseGuards(...guards) {
|
|
|
160
168
|
return target;
|
|
161
169
|
};
|
|
162
170
|
}
|
|
171
|
+
__name(UseGuards, "UseGuards");
|
|
163
172
|
function UseInterceptors(...interceptors) {
|
|
164
173
|
return (target, propertyKey, descriptor) => {
|
|
165
174
|
if (descriptor) {
|
|
@@ -170,6 +179,7 @@ function UseInterceptors(...interceptors) {
|
|
|
170
179
|
return target;
|
|
171
180
|
};
|
|
172
181
|
}
|
|
182
|
+
__name(UseInterceptors, "UseInterceptors");
|
|
173
183
|
function UsePipes(...pipes) {
|
|
174
184
|
return (target, propertyKey, descriptor) => {
|
|
175
185
|
if (descriptor) {
|
|
@@ -180,7 +190,8 @@ function UsePipes(...pipes) {
|
|
|
180
190
|
return target;
|
|
181
191
|
};
|
|
182
192
|
}
|
|
183
|
-
|
|
193
|
+
__name(UsePipes, "UsePipes");
|
|
194
|
+
var RouteParamtypes = /* @__PURE__ */ (function(RouteParamtypes2) {
|
|
184
195
|
RouteParamtypes2[RouteParamtypes2["REQUEST"] = 0] = "REQUEST";
|
|
185
196
|
RouteParamtypes2[RouteParamtypes2["RESPONSE"] = 1] = "RESPONSE";
|
|
186
197
|
RouteParamtypes2[RouteParamtypes2["NEXT"] = 2] = "NEXT";
|
|
@@ -196,7 +207,7 @@ var RouteParamtypes = /* @__PURE__ */ ((RouteParamtypes2) => {
|
|
|
196
207
|
RouteParamtypes2[RouteParamtypes2["CONTEXT"] = 12] = "CONTEXT";
|
|
197
208
|
RouteParamtypes2[RouteParamtypes2["CUSTOM"] = 13] = "CUSTOM";
|
|
198
209
|
return RouteParamtypes2;
|
|
199
|
-
})(
|
|
210
|
+
})({});
|
|
200
211
|
function assignMetadata(args, paramtype, index, data, ...pipes) {
|
|
201
212
|
return {
|
|
202
213
|
...args,
|
|
@@ -208,53 +219,50 @@ function assignMetadata(args, paramtype, index, data, ...pipes) {
|
|
|
208
219
|
}
|
|
209
220
|
};
|
|
210
221
|
}
|
|
222
|
+
__name(assignMetadata, "assignMetadata");
|
|
211
223
|
function createRouteParamDecorator(paramtype) {
|
|
212
224
|
return (data) => {
|
|
213
225
|
return (target, key, index) => {
|
|
214
226
|
const args = Reflect.getMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, target.constructor, key) || {};
|
|
215
|
-
Reflect.defineMetadata(
|
|
216
|
-
METADATA_KEYS.ROUTE_ARGS_METADATA,
|
|
217
|
-
assignMetadata(args, paramtype, index, data),
|
|
218
|
-
target.constructor,
|
|
219
|
-
key
|
|
220
|
-
);
|
|
227
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, assignMetadata(args, paramtype, index, data), target.constructor, key);
|
|
221
228
|
};
|
|
222
229
|
};
|
|
223
230
|
}
|
|
231
|
+
__name(createRouteParamDecorator, "createRouteParamDecorator");
|
|
224
232
|
function createPipesRouteParamDecorator(paramtype) {
|
|
225
233
|
return (data, ...pipes) => {
|
|
226
234
|
return (target, key, index) => {
|
|
227
235
|
const args = Reflect.getMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, target.constructor, key) || {};
|
|
228
|
-
Reflect.defineMetadata(
|
|
229
|
-
METADATA_KEYS.ROUTE_ARGS_METADATA,
|
|
230
|
-
assignMetadata(args, paramtype, index, data, ...pipes),
|
|
231
|
-
target.constructor,
|
|
232
|
-
key
|
|
233
|
-
);
|
|
236
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, assignMetadata(args, paramtype, index, data, ...pipes), target.constructor, key);
|
|
234
237
|
};
|
|
235
238
|
};
|
|
236
239
|
}
|
|
237
|
-
|
|
238
|
-
var
|
|
239
|
-
var
|
|
240
|
-
var
|
|
241
|
-
var
|
|
242
|
-
var
|
|
243
|
-
var
|
|
244
|
-
var
|
|
245
|
-
var
|
|
240
|
+
__name(createPipesRouteParamDecorator, "createPipesRouteParamDecorator");
|
|
241
|
+
var Request = createRouteParamDecorator(0);
|
|
242
|
+
var Response2 = createRouteParamDecorator(1);
|
|
243
|
+
var Next = createRouteParamDecorator(2);
|
|
244
|
+
var Session = createRouteParamDecorator(7);
|
|
245
|
+
var FileParam = createRouteParamDecorator(8);
|
|
246
|
+
var Files = createRouteParamDecorator(9);
|
|
247
|
+
var Ip = createRouteParamDecorator(11);
|
|
248
|
+
var HostParam = createRouteParamDecorator(10);
|
|
249
|
+
var Ctx = createRouteParamDecorator(12);
|
|
246
250
|
function Body(property, ...pipes) {
|
|
247
|
-
return createPipesRouteParamDecorator(3
|
|
251
|
+
return createPipesRouteParamDecorator(3)(property, ...pipes);
|
|
248
252
|
}
|
|
253
|
+
__name(Body, "Body");
|
|
249
254
|
function Query(property, ...pipes) {
|
|
250
|
-
return createPipesRouteParamDecorator(4
|
|
255
|
+
return createPipesRouteParamDecorator(4)(property, ...pipes);
|
|
251
256
|
}
|
|
257
|
+
__name(Query, "Query");
|
|
252
258
|
function Param(property, ...pipes) {
|
|
253
|
-
return createPipesRouteParamDecorator(5
|
|
259
|
+
return createPipesRouteParamDecorator(5)(property, ...pipes);
|
|
254
260
|
}
|
|
261
|
+
__name(Param, "Param");
|
|
255
262
|
function Headers(property, ...pipes) {
|
|
256
|
-
return createPipesRouteParamDecorator(6
|
|
263
|
+
return createPipesRouteParamDecorator(6)(property, ...pipes);
|
|
257
264
|
}
|
|
265
|
+
__name(Headers, "Headers");
|
|
258
266
|
function SetMetadata(metadataKey, metadataValue) {
|
|
259
267
|
return (target, key, descriptor) => {
|
|
260
268
|
if (descriptor) {
|
|
@@ -265,26 +273,36 @@ function SetMetadata(metadataKey, metadataValue) {
|
|
|
265
273
|
return target;
|
|
266
274
|
};
|
|
267
275
|
}
|
|
276
|
+
__name(SetMetadata, "SetMetadata");
|
|
268
277
|
function HttpCode(statusCode) {
|
|
269
278
|
return (target, key, descriptor) => {
|
|
270
279
|
Reflect.defineMetadata(METADATA_KEYS.HTTP_CODE, statusCode, descriptor.value);
|
|
271
280
|
return descriptor;
|
|
272
281
|
};
|
|
273
282
|
}
|
|
283
|
+
__name(HttpCode, "HttpCode");
|
|
274
284
|
function Header(name, value) {
|
|
275
285
|
return (target, key, descriptor) => {
|
|
276
286
|
const headers = Reflect.getMetadata(METADATA_KEYS.HEADERS, descriptor.value) || [];
|
|
277
|
-
headers.push({
|
|
287
|
+
headers.push({
|
|
288
|
+
name,
|
|
289
|
+
value
|
|
290
|
+
});
|
|
278
291
|
Reflect.defineMetadata(METADATA_KEYS.HEADERS, headers, descriptor.value);
|
|
279
292
|
return descriptor;
|
|
280
293
|
};
|
|
281
294
|
}
|
|
295
|
+
__name(Header, "Header");
|
|
282
296
|
function Redirect(url, statusCode = 302) {
|
|
283
297
|
return (target, key, descriptor) => {
|
|
284
|
-
Reflect.defineMetadata(METADATA_KEYS.REDIRECT, {
|
|
298
|
+
Reflect.defineMetadata(METADATA_KEYS.REDIRECT, {
|
|
299
|
+
url,
|
|
300
|
+
statusCode
|
|
301
|
+
}, descriptor.value);
|
|
285
302
|
return descriptor;
|
|
286
303
|
};
|
|
287
304
|
}
|
|
305
|
+
__name(Redirect, "Redirect");
|
|
288
306
|
function applyDecorators(...decorators) {
|
|
289
307
|
return (target, propertyKey, descriptor) => {
|
|
290
308
|
for (const decorator of decorators) {
|
|
@@ -300,31 +318,33 @@ function applyDecorators(...decorators) {
|
|
|
300
318
|
}
|
|
301
319
|
};
|
|
302
320
|
}
|
|
321
|
+
__name(applyDecorators, "applyDecorators");
|
|
303
322
|
function createParamDecorator(factory) {
|
|
304
|
-
const paramtype = 13
|
|
323
|
+
const paramtype = 13;
|
|
305
324
|
return (data) => {
|
|
306
325
|
return (target, key, index) => {
|
|
307
326
|
const args = Reflect.getMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, target.constructor, key) || {};
|
|
308
|
-
Reflect.defineMetadata(
|
|
309
|
-
METADATA_KEYS.ROUTE_ARGS_METADATA,
|
|
310
|
-
assignMetadata(args, paramtype, index, data, factory),
|
|
311
|
-
target.constructor,
|
|
312
|
-
key
|
|
313
|
-
);
|
|
327
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, assignMetadata(args, paramtype, index, data, factory), target.constructor, key);
|
|
314
328
|
};
|
|
315
329
|
};
|
|
316
330
|
}
|
|
331
|
+
__name(createParamDecorator, "createParamDecorator");
|
|
317
332
|
|
|
318
333
|
// src/injector/module.ts
|
|
319
334
|
var Module2 = class {
|
|
320
|
-
|
|
321
|
-
this
|
|
322
|
-
this.token = token;
|
|
335
|
+
static {
|
|
336
|
+
__name(this, "Module");
|
|
323
337
|
}
|
|
338
|
+
metatype;
|
|
339
|
+
token;
|
|
324
340
|
_providers = /* @__PURE__ */ new Map();
|
|
325
341
|
_imports = /* @__PURE__ */ new Set();
|
|
326
342
|
_exports = /* @__PURE__ */ new Set();
|
|
327
343
|
_controllers = /* @__PURE__ */ new Map();
|
|
344
|
+
constructor(metatype, token) {
|
|
345
|
+
this.metatype = metatype;
|
|
346
|
+
this.token = token;
|
|
347
|
+
}
|
|
328
348
|
get providers() {
|
|
329
349
|
return this._providers;
|
|
330
350
|
}
|
|
@@ -359,6 +379,9 @@ var Module2 = class {
|
|
|
359
379
|
|
|
360
380
|
// src/injector/container.ts
|
|
361
381
|
var Container = class {
|
|
382
|
+
static {
|
|
383
|
+
__name(this, "Container");
|
|
384
|
+
}
|
|
362
385
|
modules = /* @__PURE__ */ new Map();
|
|
363
386
|
globalModules = /* @__PURE__ */ new Set();
|
|
364
387
|
addModule(moduleMeta, token) {
|
|
@@ -385,6 +408,9 @@ var Container = class {
|
|
|
385
408
|
|
|
386
409
|
// src/injector/context-id.ts
|
|
387
410
|
var ContextId = class _ContextId {
|
|
411
|
+
static {
|
|
412
|
+
__name(this, "ContextId");
|
|
413
|
+
}
|
|
388
414
|
static idCounter = 0;
|
|
389
415
|
id;
|
|
390
416
|
constructor() {
|
|
@@ -395,27 +421,37 @@ new ContextId();
|
|
|
395
421
|
|
|
396
422
|
// src/injector/module-ref.ts
|
|
397
423
|
var ModuleRef = class {
|
|
424
|
+
static {
|
|
425
|
+
__name(this, "ModuleRef");
|
|
426
|
+
}
|
|
398
427
|
};
|
|
399
428
|
var ModuleRefImpl = class extends ModuleRef {
|
|
429
|
+
static {
|
|
430
|
+
__name(this, "ModuleRefImpl");
|
|
431
|
+
}
|
|
432
|
+
container;
|
|
433
|
+
injector;
|
|
434
|
+
moduleRef;
|
|
400
435
|
constructor(container, injector, moduleRef) {
|
|
401
|
-
super();
|
|
402
|
-
this.container = container;
|
|
403
|
-
this.injector = injector;
|
|
404
|
-
this.moduleRef = moduleRef;
|
|
436
|
+
super(), this.container = container, this.injector = injector, this.moduleRef = moduleRef;
|
|
405
437
|
}
|
|
406
|
-
get(typeOrToken, options = {
|
|
438
|
+
get(typeOrToken, options = {
|
|
439
|
+
strict: true
|
|
440
|
+
}) {
|
|
407
441
|
const token = typeOrToken;
|
|
408
442
|
let wrapper = this.moduleRef.getProvider(token);
|
|
409
443
|
if (!wrapper && !options.strict) ;
|
|
410
444
|
if (!wrapper) {
|
|
411
445
|
throw new Error(`ModuleRef cannot find provider for ${token.toString()}`);
|
|
412
446
|
}
|
|
413
|
-
if (wrapper.scope !==
|
|
447
|
+
if (wrapper.scope !== Scope.DEFAULT) {
|
|
414
448
|
throw new Error(`Cannot use get() for scoped provider ${token.toString()}. Use resolve() instead.`);
|
|
415
449
|
}
|
|
416
450
|
return wrapper.instance;
|
|
417
451
|
}
|
|
418
|
-
async resolve(typeOrToken, contextId, options = {
|
|
452
|
+
async resolve(typeOrToken, contextId, options = {
|
|
453
|
+
strict: true
|
|
454
|
+
}) {
|
|
419
455
|
const token = typeOrToken;
|
|
420
456
|
const wrapper = this.moduleRef.getProvider(token);
|
|
421
457
|
if (!wrapper) {
|
|
@@ -427,17 +463,24 @@ var ModuleRefImpl = class extends ModuleRef {
|
|
|
427
463
|
|
|
428
464
|
// src/injector/injector.ts
|
|
429
465
|
var Injector = class {
|
|
466
|
+
static {
|
|
467
|
+
__name(this, "Injector");
|
|
468
|
+
}
|
|
469
|
+
container;
|
|
430
470
|
constructor(container) {
|
|
431
471
|
this.container = container;
|
|
432
472
|
}
|
|
433
473
|
async resolveConstructorParams(wrapper, module, inject, callback, contextId = new ContextId(), inquire = [], parentInquire = []) {
|
|
434
|
-
if (inquire.some((item) => item === wrapper) && wrapper.scope ===
|
|
474
|
+
if (inquire.some((item) => item === wrapper) && wrapper.scope === Scope.DEFAULT) {
|
|
435
475
|
throw new Error(`Circular dependency detected: ${wrapper.name}`);
|
|
436
476
|
}
|
|
437
477
|
const args = [];
|
|
438
478
|
for (const [index, token] of inject.entries()) {
|
|
439
479
|
const isOptional = wrapper.isOptional ? wrapper.isOptional[index] : false;
|
|
440
|
-
const paramWrapper = await this.resolveSingleParam(token, module, contextId, [
|
|
480
|
+
const paramWrapper = await this.resolveSingleParam(token, module, contextId, [
|
|
481
|
+
...inquire,
|
|
482
|
+
wrapper
|
|
483
|
+
], isOptional);
|
|
441
484
|
args.push(paramWrapper);
|
|
442
485
|
}
|
|
443
486
|
return args;
|
|
@@ -460,11 +503,11 @@ var Injector = class {
|
|
|
460
503
|
}
|
|
461
504
|
if (isForwardRef) {
|
|
462
505
|
return new Proxy({}, {
|
|
463
|
-
get: (target, prop) => {
|
|
506
|
+
get: /* @__PURE__ */ __name((target, prop) => {
|
|
464
507
|
if (prop === "then") return void 0;
|
|
465
508
|
if (!wrapper.instance) ;
|
|
466
509
|
return wrapper.instance?.[prop];
|
|
467
|
-
}
|
|
510
|
+
}, "get")
|
|
468
511
|
});
|
|
469
512
|
}
|
|
470
513
|
return this.loadInstance(wrapper, contextId, inquire);
|
|
@@ -497,17 +540,17 @@ var Injector = class {
|
|
|
497
540
|
return void 0;
|
|
498
541
|
}
|
|
499
542
|
async loadInstance(wrapper, contextId, inquire = []) {
|
|
500
|
-
if (wrapper.isResolved && wrapper.scope ===
|
|
543
|
+
if (wrapper.isResolved && wrapper.scope === Scope.DEFAULT) {
|
|
501
544
|
return wrapper.instance;
|
|
502
545
|
}
|
|
503
|
-
if (wrapper.scope ===
|
|
546
|
+
if (wrapper.scope === Scope.REQUEST) {
|
|
504
547
|
const existing = wrapper.getInstanceByContextId(contextId);
|
|
505
548
|
if (existing) return existing;
|
|
506
549
|
}
|
|
507
550
|
if (wrapper.isAlias) {
|
|
508
551
|
const targetToken = wrapper.useExisting;
|
|
509
552
|
const instance2 = await this.resolveSingleParam(targetToken, wrapper.host, contextId, inquire);
|
|
510
|
-
if (wrapper.scope ===
|
|
553
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
511
554
|
wrapper.instance = instance2;
|
|
512
555
|
wrapper.isResolved = true;
|
|
513
556
|
} else {
|
|
@@ -522,17 +565,10 @@ var Injector = class {
|
|
|
522
565
|
}
|
|
523
566
|
if (wrapper.useFactory) {
|
|
524
567
|
const dependencies2 = wrapper.inject || [];
|
|
525
|
-
const args = await this.resolveConstructorParams(
|
|
526
|
-
|
|
527
|
-
wrapper.host,
|
|
528
|
-
dependencies2,
|
|
529
|
-
(args2) => {
|
|
530
|
-
},
|
|
531
|
-
contextId,
|
|
532
|
-
inquire
|
|
533
|
-
);
|
|
568
|
+
const args = await this.resolveConstructorParams(wrapper, wrapper.host, dependencies2, (args2) => {
|
|
569
|
+
}, contextId, inquire);
|
|
534
570
|
const instance2 = await wrapper.useFactory(...args);
|
|
535
|
-
if (wrapper.scope ===
|
|
571
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
536
572
|
wrapper.instance = instance2;
|
|
537
573
|
wrapper.isResolved = true;
|
|
538
574
|
} else {
|
|
@@ -545,31 +581,18 @@ var Injector = class {
|
|
|
545
581
|
throw new Error("Invalid metatype");
|
|
546
582
|
}
|
|
547
583
|
let dependencies = wrapper.inject || [];
|
|
548
|
-
const constructorArgs = await this.resolveConstructorParams(
|
|
549
|
-
|
|
550
|
-
wrapper.host,
|
|
551
|
-
dependencies,
|
|
552
|
-
(args) => {
|
|
553
|
-
},
|
|
554
|
-
contextId,
|
|
555
|
-
inquire
|
|
556
|
-
);
|
|
584
|
+
const constructorArgs = await this.resolveConstructorParams(wrapper, wrapper.host, dependencies, (args) => {
|
|
585
|
+
}, contextId, inquire);
|
|
557
586
|
const instance = new metatype(...constructorArgs);
|
|
558
587
|
if (wrapper.properties) {
|
|
559
588
|
for (const prop of wrapper.properties) {
|
|
560
|
-
const propInstance = await this.resolveSingleParam(
|
|
561
|
-
prop.token,
|
|
562
|
-
wrapper.host,
|
|
563
|
-
contextId,
|
|
564
|
-
inquire,
|
|
565
|
-
prop.isOptional
|
|
566
|
-
);
|
|
589
|
+
const propInstance = await this.resolveSingleParam(prop.token, wrapper.host, contextId, inquire, prop.isOptional);
|
|
567
590
|
if (propInstance !== void 0) {
|
|
568
591
|
instance[prop.key] = propInstance;
|
|
569
592
|
}
|
|
570
593
|
}
|
|
571
594
|
}
|
|
572
|
-
if (wrapper.scope ===
|
|
595
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
573
596
|
wrapper.instance = instance;
|
|
574
597
|
wrapper.isResolved = true;
|
|
575
598
|
} else {
|
|
@@ -581,22 +604,22 @@ var Injector = class {
|
|
|
581
604
|
|
|
582
605
|
// src/injector/instance-wrapper.ts
|
|
583
606
|
var InstanceWrapper = class {
|
|
607
|
+
static {
|
|
608
|
+
__name(this, "InstanceWrapper");
|
|
609
|
+
}
|
|
584
610
|
id;
|
|
585
611
|
token;
|
|
586
612
|
name;
|
|
587
613
|
metatype;
|
|
588
|
-
scope =
|
|
614
|
+
scope = Scope.DEFAULT;
|
|
589
615
|
host;
|
|
590
|
-
// Generic logic
|
|
591
616
|
inject;
|
|
592
617
|
isOptional;
|
|
593
618
|
properties;
|
|
594
619
|
instance;
|
|
595
|
-
// Singleton instance
|
|
596
620
|
instancesPerContext = /* @__PURE__ */ new Map();
|
|
597
621
|
isResolved = false;
|
|
598
622
|
isPending = false;
|
|
599
|
-
// For circular dependency detection
|
|
600
623
|
isAlias = false;
|
|
601
624
|
useFactory;
|
|
602
625
|
useValue;
|
|
@@ -605,7 +628,7 @@ var InstanceWrapper = class {
|
|
|
605
628
|
this.token = metadata.token;
|
|
606
629
|
this.name = metadata.name;
|
|
607
630
|
this.metatype = metadata.metatype;
|
|
608
|
-
this.scope = metadata.scope ??
|
|
631
|
+
this.scope = metadata.scope ?? Scope.DEFAULT;
|
|
609
632
|
this.host = metadata.host;
|
|
610
633
|
this.instance = metadata.instance;
|
|
611
634
|
this.inject = metadata.inject;
|
|
@@ -617,18 +640,18 @@ var InstanceWrapper = class {
|
|
|
617
640
|
this.id = Math.random().toString(36).substring(7);
|
|
618
641
|
}
|
|
619
642
|
getInstanceByContextId(contextId) {
|
|
620
|
-
if (this.scope ===
|
|
643
|
+
if (this.scope === Scope.TRANSIENT) {
|
|
621
644
|
return void 0;
|
|
622
645
|
}
|
|
623
|
-
if (this.scope ===
|
|
646
|
+
if (this.scope === Scope.DEFAULT) {
|
|
624
647
|
return this.instance;
|
|
625
648
|
}
|
|
626
649
|
return this.instancesPerContext.get(contextId);
|
|
627
650
|
}
|
|
628
651
|
setInstanceByContextId(contextId, instance) {
|
|
629
|
-
if (this.scope ===
|
|
652
|
+
if (this.scope === Scope.DEFAULT) {
|
|
630
653
|
this.instance = instance;
|
|
631
|
-
} else if (this.scope ===
|
|
654
|
+
} else if (this.scope === Scope.REQUEST) {
|
|
632
655
|
this.instancesPerContext.set(contextId, instance);
|
|
633
656
|
}
|
|
634
657
|
}
|
|
@@ -642,6 +665,9 @@ var InstanceWrapper = class {
|
|
|
642
665
|
|
|
643
666
|
// src/services/logger.service.ts
|
|
644
667
|
var Logger = class _Logger {
|
|
668
|
+
static {
|
|
669
|
+
__name(this, "Logger");
|
|
670
|
+
}
|
|
645
671
|
static lastTimestamp;
|
|
646
672
|
static instance;
|
|
647
673
|
context;
|
|
@@ -696,10 +722,8 @@ var Logger = class _Logger {
|
|
|
696
722
|
red: "\x1B[31m",
|
|
697
723
|
green: "\x1B[32m",
|
|
698
724
|
yellow: "\x1B[33m"};
|
|
699
|
-
process.stdout.write(
|
|
700
|
-
|
|
701
|
-
`
|
|
702
|
-
);
|
|
725
|
+
process.stdout.write(`${C.green}[Hono] ${pid}${C.reset} - ${timestamp}${color}${level.toUpperCase().padStart(7)}${C.reset} ${C.yellow}${contextMessage}${C.reset}${C.green}${output}${C.reset} ${C.yellow}${timeDiff}${C.reset}
|
|
726
|
+
`);
|
|
703
727
|
if (trace) {
|
|
704
728
|
process.stdout.write(`${C.red}${trace}${C.reset}
|
|
705
729
|
`);
|
|
@@ -738,6 +762,10 @@ var Logger = class _Logger {
|
|
|
738
762
|
|
|
739
763
|
// src/scanner.ts
|
|
740
764
|
var HonoDiScanner = class {
|
|
765
|
+
static {
|
|
766
|
+
__name(this, "HonoDiScanner");
|
|
767
|
+
}
|
|
768
|
+
container;
|
|
741
769
|
constructor(container) {
|
|
742
770
|
this.container = container;
|
|
743
771
|
}
|
|
@@ -764,7 +792,7 @@ var HonoDiScanner = class {
|
|
|
764
792
|
name: moduleClass.name,
|
|
765
793
|
metatype: moduleClass,
|
|
766
794
|
host: moduleRef,
|
|
767
|
-
scope:
|
|
795
|
+
scope: Scope.DEFAULT
|
|
768
796
|
});
|
|
769
797
|
this.scanDependencies(moduleWrapper);
|
|
770
798
|
moduleRef.addProvider(moduleWrapper);
|
|
@@ -776,10 +804,22 @@ var HonoDiScanner = class {
|
|
|
776
804
|
const options = {
|
|
777
805
|
...decoratorOptions,
|
|
778
806
|
...dynamicMetadata,
|
|
779
|
-
imports: [
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
807
|
+
imports: [
|
|
808
|
+
...decoratorOptions.imports || [],
|
|
809
|
+
...dynamicMetadata.imports || []
|
|
810
|
+
],
|
|
811
|
+
providers: [
|
|
812
|
+
...decoratorOptions.providers || [],
|
|
813
|
+
...dynamicMetadata.providers || []
|
|
814
|
+
],
|
|
815
|
+
exports: [
|
|
816
|
+
...decoratorOptions.exports || [],
|
|
817
|
+
...dynamicMetadata.exports || []
|
|
818
|
+
],
|
|
819
|
+
controllers: [
|
|
820
|
+
...decoratorOptions.controllers || [],
|
|
821
|
+
...dynamicMetadata.controllers || []
|
|
822
|
+
]
|
|
783
823
|
};
|
|
784
824
|
if (options.imports) {
|
|
785
825
|
for (const importedModule of options.imports) {
|
|
@@ -787,7 +827,10 @@ var HonoDiScanner = class {
|
|
|
787
827
|
if (importedModule && typeof importedModule.forwardRef === "function") {
|
|
788
828
|
actualImport = importedModule.forwardRef();
|
|
789
829
|
}
|
|
790
|
-
const importedRef = await this.scanModule(actualImport, [
|
|
830
|
+
const importedRef = await this.scanModule(actualImport, [
|
|
831
|
+
...scope,
|
|
832
|
+
moduleClass
|
|
833
|
+
]);
|
|
791
834
|
if (importedRef) {
|
|
792
835
|
moduleRef.addImport(importedRef);
|
|
793
836
|
}
|
|
@@ -820,7 +863,7 @@ var HonoDiScanner = class {
|
|
|
820
863
|
name: token2.name,
|
|
821
864
|
metatype: provider,
|
|
822
865
|
host: moduleRef,
|
|
823
|
-
scope:
|
|
866
|
+
scope: Scope.DEFAULT
|
|
824
867
|
});
|
|
825
868
|
this.scanDependencies(wrapper2);
|
|
826
869
|
moduleRef.addProvider(wrapper2);
|
|
@@ -831,7 +874,7 @@ var HonoDiScanner = class {
|
|
|
831
874
|
token,
|
|
832
875
|
name: token && token.name ? token.name : typeof token === "string" ? token : "CustomProvider",
|
|
833
876
|
host: moduleRef,
|
|
834
|
-
scope: provider.scope ||
|
|
877
|
+
scope: provider.scope || Scope.DEFAULT
|
|
835
878
|
});
|
|
836
879
|
if (provider.useValue !== void 0) {
|
|
837
880
|
wrapper.useValue = provider.useValue;
|
|
@@ -854,7 +897,7 @@ var HonoDiScanner = class {
|
|
|
854
897
|
name: token.name,
|
|
855
898
|
metatype: controller,
|
|
856
899
|
host: moduleRef,
|
|
857
|
-
scope:
|
|
900
|
+
scope: Scope.DEFAULT
|
|
858
901
|
});
|
|
859
902
|
this.scanDependencies(wrapper);
|
|
860
903
|
moduleRef.addController(wrapper);
|
|
@@ -885,6 +928,9 @@ var HonoDiScanner = class {
|
|
|
885
928
|
|
|
886
929
|
// src/execution-context-host.ts
|
|
887
930
|
var ExecutionContextHost = class {
|
|
931
|
+
static {
|
|
932
|
+
__name(this, "ExecutionContextHost");
|
|
933
|
+
}
|
|
888
934
|
args;
|
|
889
935
|
constructorRef;
|
|
890
936
|
handler;
|
|
@@ -911,20 +957,24 @@ var ExecutionContextHost = class {
|
|
|
911
957
|
}
|
|
912
958
|
switchToHttp() {
|
|
913
959
|
return {
|
|
914
|
-
getRequest: () => this.context.req,
|
|
915
|
-
getResponse: () => this.context,
|
|
916
|
-
getNext: () => this.next ?? (() => Promise.resolve()),
|
|
917
|
-
getContext: () => this.context
|
|
960
|
+
getRequest: /* @__PURE__ */ __name(() => this.context.req, "getRequest"),
|
|
961
|
+
getResponse: /* @__PURE__ */ __name(() => this.context, "getResponse"),
|
|
962
|
+
getNext: /* @__PURE__ */ __name(() => this.next ?? (() => Promise.resolve()), "getNext"),
|
|
963
|
+
getContext: /* @__PURE__ */ __name(() => this.context, "getContext")
|
|
918
964
|
};
|
|
919
965
|
}
|
|
920
966
|
};
|
|
921
967
|
|
|
922
968
|
// src/middleware/builder.ts
|
|
923
969
|
var MiddlewareBuilder = class {
|
|
970
|
+
static {
|
|
971
|
+
__name(this, "MiddlewareBuilder");
|
|
972
|
+
}
|
|
973
|
+
module;
|
|
974
|
+
configs = [];
|
|
924
975
|
constructor(module) {
|
|
925
976
|
this.module = module;
|
|
926
977
|
}
|
|
927
|
-
configs = [];
|
|
928
978
|
apply(...middleware) {
|
|
929
979
|
return new MiddlewareConfigProxyImpl(this, middleware);
|
|
930
980
|
}
|
|
@@ -940,12 +990,17 @@ var MiddlewareBuilder = class {
|
|
|
940
990
|
return this.configs;
|
|
941
991
|
}
|
|
942
992
|
};
|
|
943
|
-
var MiddlewareConfigProxyImpl = class {
|
|
993
|
+
var MiddlewareConfigProxyImpl = class MiddlewareConfigProxyImpl2 {
|
|
994
|
+
static {
|
|
995
|
+
__name(this, "MiddlewareConfigProxyImpl");
|
|
996
|
+
}
|
|
997
|
+
builder;
|
|
998
|
+
middleware;
|
|
999
|
+
excludes = [];
|
|
944
1000
|
constructor(builder, middleware) {
|
|
945
1001
|
this.builder = builder;
|
|
946
1002
|
this.middleware = middleware;
|
|
947
1003
|
}
|
|
948
|
-
excludes = [];
|
|
949
1004
|
exclude(...routes) {
|
|
950
1005
|
this.excludes = routes;
|
|
951
1006
|
return this;
|
|
@@ -958,10 +1013,13 @@ var MiddlewareConfigProxyImpl = class {
|
|
|
958
1013
|
|
|
959
1014
|
// src/common/exceptions/http.exception.ts
|
|
960
1015
|
var HttpException = class extends Error {
|
|
1016
|
+
static {
|
|
1017
|
+
__name(this, "HttpException");
|
|
1018
|
+
}
|
|
1019
|
+
response;
|
|
1020
|
+
status;
|
|
961
1021
|
constructor(response, status) {
|
|
962
|
-
super();
|
|
963
|
-
this.response = response;
|
|
964
|
-
this.status = status;
|
|
1022
|
+
super(), this.response = response, this.status = status;
|
|
965
1023
|
this.message = typeof response === "string" ? response : JSON.stringify(response);
|
|
966
1024
|
}
|
|
967
1025
|
getResponse() {
|
|
@@ -972,89 +1030,144 @@ var HttpException = class extends Error {
|
|
|
972
1030
|
}
|
|
973
1031
|
static createBody(message, error, statusCode) {
|
|
974
1032
|
if (!message) {
|
|
975
|
-
return {
|
|
1033
|
+
return {
|
|
1034
|
+
statusCode,
|
|
1035
|
+
error
|
|
1036
|
+
};
|
|
976
1037
|
}
|
|
977
|
-
return typeof message === "object" && !Array.isArray(message) ? message : {
|
|
1038
|
+
return typeof message === "object" && !Array.isArray(message) ? message : {
|
|
1039
|
+
statusCode,
|
|
1040
|
+
error,
|
|
1041
|
+
message
|
|
1042
|
+
};
|
|
978
1043
|
}
|
|
979
1044
|
};
|
|
980
1045
|
|
|
981
1046
|
// src/common/exceptions/index.ts
|
|
982
1047
|
var BadRequestException = class extends HttpException {
|
|
1048
|
+
static {
|
|
1049
|
+
__name(this, "BadRequestException");
|
|
1050
|
+
}
|
|
983
1051
|
constructor(message, error = "Bad Request") {
|
|
984
1052
|
super(HttpException.createBody(message, error, 400), 400);
|
|
985
1053
|
}
|
|
986
1054
|
};
|
|
987
1055
|
var UnauthorizedException = class extends HttpException {
|
|
1056
|
+
static {
|
|
1057
|
+
__name(this, "UnauthorizedException");
|
|
1058
|
+
}
|
|
988
1059
|
constructor(message, error = "Unauthorized") {
|
|
989
1060
|
super(HttpException.createBody(message, error, 401), 401);
|
|
990
1061
|
}
|
|
991
1062
|
};
|
|
992
1063
|
var NotFoundException = class extends HttpException {
|
|
1064
|
+
static {
|
|
1065
|
+
__name(this, "NotFoundException");
|
|
1066
|
+
}
|
|
993
1067
|
constructor(message, error = "Not Found") {
|
|
994
1068
|
super(HttpException.createBody(message, error, 404), 404);
|
|
995
1069
|
}
|
|
996
1070
|
};
|
|
997
1071
|
var ForbiddenException = class extends HttpException {
|
|
1072
|
+
static {
|
|
1073
|
+
__name(this, "ForbiddenException");
|
|
1074
|
+
}
|
|
998
1075
|
constructor(message, error = "Forbidden") {
|
|
999
1076
|
super(HttpException.createBody(message, error, 403), 403);
|
|
1000
1077
|
}
|
|
1001
1078
|
};
|
|
1002
1079
|
var NotAcceptableException = class extends HttpException {
|
|
1080
|
+
static {
|
|
1081
|
+
__name(this, "NotAcceptableException");
|
|
1082
|
+
}
|
|
1003
1083
|
constructor(message, error = "Not Acceptable") {
|
|
1004
1084
|
super(HttpException.createBody(message, error, 406), 406);
|
|
1005
1085
|
}
|
|
1006
1086
|
};
|
|
1007
1087
|
var RequestTimeoutException = class extends HttpException {
|
|
1088
|
+
static {
|
|
1089
|
+
__name(this, "RequestTimeoutException");
|
|
1090
|
+
}
|
|
1008
1091
|
constructor(message, error = "Request Timeout") {
|
|
1009
1092
|
super(HttpException.createBody(message, error, 408), 408);
|
|
1010
1093
|
}
|
|
1011
1094
|
};
|
|
1012
1095
|
var ConflictException = class extends HttpException {
|
|
1096
|
+
static {
|
|
1097
|
+
__name(this, "ConflictException");
|
|
1098
|
+
}
|
|
1013
1099
|
constructor(message, error = "Conflict") {
|
|
1014
1100
|
super(HttpException.createBody(message, error, 409), 409);
|
|
1015
1101
|
}
|
|
1016
1102
|
};
|
|
1017
1103
|
var GoneException = class extends HttpException {
|
|
1104
|
+
static {
|
|
1105
|
+
__name(this, "GoneException");
|
|
1106
|
+
}
|
|
1018
1107
|
constructor(message, error = "Gone") {
|
|
1019
1108
|
super(HttpException.createBody(message, error, 410), 410);
|
|
1020
1109
|
}
|
|
1021
1110
|
};
|
|
1022
1111
|
var PayloadTooLargeException = class extends HttpException {
|
|
1112
|
+
static {
|
|
1113
|
+
__name(this, "PayloadTooLargeException");
|
|
1114
|
+
}
|
|
1023
1115
|
constructor(message, error = "Payload Too Large") {
|
|
1024
1116
|
super(HttpException.createBody(message, error, 413), 413);
|
|
1025
1117
|
}
|
|
1026
1118
|
};
|
|
1027
1119
|
var UnsupportedMediaTypeException = class extends HttpException {
|
|
1120
|
+
static {
|
|
1121
|
+
__name(this, "UnsupportedMediaTypeException");
|
|
1122
|
+
}
|
|
1028
1123
|
constructor(message, error = "Unsupported Media Type") {
|
|
1029
1124
|
super(HttpException.createBody(message, error, 415), 415);
|
|
1030
1125
|
}
|
|
1031
1126
|
};
|
|
1032
1127
|
var UnprocessableEntityException = class extends HttpException {
|
|
1128
|
+
static {
|
|
1129
|
+
__name(this, "UnprocessableEntityException");
|
|
1130
|
+
}
|
|
1033
1131
|
constructor(message, error = "Unprocessable Entity") {
|
|
1034
1132
|
super(HttpException.createBody(message, error, 422), 422);
|
|
1035
1133
|
}
|
|
1036
1134
|
};
|
|
1037
1135
|
var InternalServerErrorException = class extends HttpException {
|
|
1136
|
+
static {
|
|
1137
|
+
__name(this, "InternalServerErrorException");
|
|
1138
|
+
}
|
|
1038
1139
|
constructor(message, error = "Internal Server Error") {
|
|
1039
1140
|
super(HttpException.createBody(message, error, 500), 500);
|
|
1040
1141
|
}
|
|
1041
1142
|
};
|
|
1042
1143
|
var NotImplementedException = class extends HttpException {
|
|
1144
|
+
static {
|
|
1145
|
+
__name(this, "NotImplementedException");
|
|
1146
|
+
}
|
|
1043
1147
|
constructor(message, error = "Not Implemented") {
|
|
1044
1148
|
super(HttpException.createBody(message, error, 501), 501);
|
|
1045
1149
|
}
|
|
1046
1150
|
};
|
|
1047
1151
|
var BadGatewayException = class extends HttpException {
|
|
1152
|
+
static {
|
|
1153
|
+
__name(this, "BadGatewayException");
|
|
1154
|
+
}
|
|
1048
1155
|
constructor(message, error = "Bad Gateway") {
|
|
1049
1156
|
super(HttpException.createBody(message, error, 502), 502);
|
|
1050
1157
|
}
|
|
1051
1158
|
};
|
|
1052
1159
|
var ServiceUnavailableException = class extends HttpException {
|
|
1160
|
+
static {
|
|
1161
|
+
__name(this, "ServiceUnavailableException");
|
|
1162
|
+
}
|
|
1053
1163
|
constructor(message, error = "Service Unavailable") {
|
|
1054
1164
|
super(HttpException.createBody(message, error, 503), 503);
|
|
1055
1165
|
}
|
|
1056
1166
|
};
|
|
1057
1167
|
var GatewayTimeoutException = class extends HttpException {
|
|
1168
|
+
static {
|
|
1169
|
+
__name(this, "GatewayTimeoutException");
|
|
1170
|
+
}
|
|
1058
1171
|
constructor(message, error = "Gateway Timeout") {
|
|
1059
1172
|
super(HttpException.createBody(message, error, 504), 504);
|
|
1060
1173
|
}
|
|
@@ -1062,15 +1175,21 @@ var GatewayTimeoutException = class extends HttpException {
|
|
|
1062
1175
|
|
|
1063
1176
|
// src/application.ts
|
|
1064
1177
|
var HonoDiApplication = class {
|
|
1065
|
-
|
|
1066
|
-
this
|
|
1067
|
-
this.container = container;
|
|
1068
|
-
this.injector = injector;
|
|
1178
|
+
static {
|
|
1179
|
+
__name(this, "HonoDiApplication");
|
|
1069
1180
|
}
|
|
1181
|
+
app;
|
|
1182
|
+
container;
|
|
1183
|
+
injector;
|
|
1070
1184
|
globalFilters = [];
|
|
1071
1185
|
globalPipes = [];
|
|
1072
1186
|
globalGuards = [];
|
|
1073
1187
|
globalInterceptors = [];
|
|
1188
|
+
constructor(app, container, injector) {
|
|
1189
|
+
this.app = app;
|
|
1190
|
+
this.container = container;
|
|
1191
|
+
this.injector = injector;
|
|
1192
|
+
}
|
|
1074
1193
|
useGlobalFilters(...filters) {
|
|
1075
1194
|
this.globalFilters.push(...filters);
|
|
1076
1195
|
return this;
|
|
@@ -1155,7 +1274,9 @@ var HonoDiApplication = class {
|
|
|
1155
1274
|
const fullPath = this.combinePaths(globalPrefix, this.combinePaths(prefix, route.path));
|
|
1156
1275
|
app[route.requestMethod](fullPath, async (c) => {
|
|
1157
1276
|
const contextId = new ContextId();
|
|
1158
|
-
const executionContext = new ExecutionContextHost([
|
|
1277
|
+
const executionContext = new ExecutionContextHost([
|
|
1278
|
+
c
|
|
1279
|
+
], controllerClass, controllerClass.prototype[route.methodName]);
|
|
1159
1280
|
try {
|
|
1160
1281
|
const wrapper = moduleRef.getProvider(controllerClass) || moduleRef.controllers.get(controllerClass);
|
|
1161
1282
|
if (!wrapper) {
|
|
@@ -1163,49 +1284,33 @@ var HonoDiApplication = class {
|
|
|
1163
1284
|
}
|
|
1164
1285
|
const controllerInstance = await this.injector.loadInstance(wrapper, contextId);
|
|
1165
1286
|
const handler = controllerInstance[route.methodName].bind(controllerInstance);
|
|
1166
|
-
const guards = await this.resolveContextItems(
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
],
|
|
1172
|
-
moduleRef,
|
|
1173
|
-
contextId
|
|
1174
|
-
);
|
|
1287
|
+
const guards = await this.resolveContextItems([
|
|
1288
|
+
...this.globalGuards,
|
|
1289
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_GUARDS, controllerClass) || [],
|
|
1290
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_GUARDS, controllerInstance[route.methodName]) || []
|
|
1291
|
+
], moduleRef, contextId);
|
|
1175
1292
|
if (!await this.runGuards(guards, executionContext)) {
|
|
1176
1293
|
c.status(403);
|
|
1177
|
-
return c.json({
|
|
1294
|
+
return c.json({
|
|
1295
|
+
statusCode: 403,
|
|
1296
|
+
message: "Forbidden resource"
|
|
1297
|
+
});
|
|
1178
1298
|
}
|
|
1179
|
-
const interceptors = await this.resolveContextItems(
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
...this.globalPipes,
|
|
1191
|
-
...Reflect.getMetadata(METADATA_KEYS.USE_PIPES, controllerClass) || [],
|
|
1192
|
-
...Reflect.getMetadata(METADATA_KEYS.USE_PIPES, controllerInstance[route.methodName]) || []
|
|
1193
|
-
],
|
|
1194
|
-
moduleRef,
|
|
1195
|
-
contextId
|
|
1196
|
-
);
|
|
1197
|
-
const args = await this.resolveArgs(
|
|
1198
|
-
contextId,
|
|
1199
|
-
executionContext,
|
|
1200
|
-
controllerClass,
|
|
1201
|
-
route.methodName,
|
|
1202
|
-
moduleRef,
|
|
1203
|
-
pipes
|
|
1204
|
-
);
|
|
1299
|
+
const interceptors = await this.resolveContextItems([
|
|
1300
|
+
...this.globalInterceptors,
|
|
1301
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_INTERCEPTORS, controllerClass) || [],
|
|
1302
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_INTERCEPTORS, controllerInstance[route.methodName]) || []
|
|
1303
|
+
], moduleRef, contextId);
|
|
1304
|
+
const pipes = await this.resolveContextItems([
|
|
1305
|
+
...this.globalPipes,
|
|
1306
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_PIPES, controllerClass) || [],
|
|
1307
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_PIPES, controllerInstance[route.methodName]) || []
|
|
1308
|
+
], moduleRef, contextId);
|
|
1309
|
+
const args = await this.resolveArgs(contextId, executionContext, controllerClass, route.methodName, moduleRef, pipes);
|
|
1205
1310
|
if (args.length === 0 && !Reflect.hasMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, controllerClass, route.methodName)) {
|
|
1206
1311
|
args.push(c);
|
|
1207
1312
|
}
|
|
1208
|
-
const interceptorChain = async (index) => {
|
|
1313
|
+
const interceptorChain = /* @__PURE__ */ __name(async (index) => {
|
|
1209
1314
|
if (index >= interceptors.length) {
|
|
1210
1315
|
return new rxjs.Observable((subscriber) => {
|
|
1211
1316
|
try {
|
|
@@ -1225,9 +1330,9 @@ var HonoDiApplication = class {
|
|
|
1225
1330
|
});
|
|
1226
1331
|
}
|
|
1227
1332
|
return interceptors[index].intercept(executionContext, {
|
|
1228
|
-
handle: () => rxjs.from(interceptorChain(index + 1)).pipe(operators.mergeMap((obs2) => obs2))
|
|
1333
|
+
handle: /* @__PURE__ */ __name(() => rxjs.from(interceptorChain(index + 1)).pipe(operators.mergeMap((obs2) => obs2)), "handle")
|
|
1229
1334
|
});
|
|
1230
|
-
};
|
|
1335
|
+
}, "interceptorChain");
|
|
1231
1336
|
const obs = await interceptorChain(0);
|
|
1232
1337
|
const result = await rxjs.lastValueFrom(obs);
|
|
1233
1338
|
const httpCode = Reflect.getMetadata(METADATA_KEYS.HTTP_CODE, controllerInstance[route.methodName]);
|
|
@@ -1260,19 +1365,17 @@ var HonoDiApplication = class {
|
|
|
1260
1365
|
});
|
|
1261
1366
|
}
|
|
1262
1367
|
async handleException(exception, c, controllerClass, methodName, moduleRef, contextId) {
|
|
1263
|
-
const filters = await this.resolveContextItems(
|
|
1264
|
-
[
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
],
|
|
1269
|
-
moduleRef,
|
|
1270
|
-
contextId
|
|
1271
|
-
);
|
|
1368
|
+
const filters = await this.resolveContextItems([
|
|
1369
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_FILTERS, moduleRef.controllers.get(controllerClass)?.instance?.[methodName]) || [],
|
|
1370
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_FILTERS, controllerClass) || [],
|
|
1371
|
+
...this.globalFilters
|
|
1372
|
+
], moduleRef, contextId);
|
|
1272
1373
|
for (const filter of filters) {
|
|
1273
1374
|
const catchExceptions = Reflect.getMetadata(METADATA_KEYS.FILTER_CATCH, filter.constructor) || [];
|
|
1274
1375
|
if (catchExceptions.length === 0 || catchExceptions.some((e) => exception instanceof e)) {
|
|
1275
|
-
const host = new ExecutionContextHost([
|
|
1376
|
+
const host = new ExecutionContextHost([
|
|
1377
|
+
c
|
|
1378
|
+
], controllerClass, moduleRef.controllers.get(controllerClass)?.instance?.[methodName]);
|
|
1276
1379
|
return await filter.catch(exception, host);
|
|
1277
1380
|
}
|
|
1278
1381
|
}
|
|
@@ -1304,7 +1407,7 @@ var HonoDiApplication = class {
|
|
|
1304
1407
|
name: item.name,
|
|
1305
1408
|
metatype: item,
|
|
1306
1409
|
host: moduleRef,
|
|
1307
|
-
scope:
|
|
1410
|
+
scope: Scope.TRANSIENT
|
|
1308
1411
|
});
|
|
1309
1412
|
scanner.scanDependencies(wrapper);
|
|
1310
1413
|
}
|
|
@@ -1325,19 +1428,19 @@ var HonoDiApplication = class {
|
|
|
1325
1428
|
let value;
|
|
1326
1429
|
const { index, data, pipes, paramtype } = arg;
|
|
1327
1430
|
switch (paramtype) {
|
|
1328
|
-
case
|
|
1431
|
+
case RouteParamtypes.REQUEST:
|
|
1329
1432
|
value = c.req;
|
|
1330
1433
|
break;
|
|
1331
|
-
case
|
|
1434
|
+
case RouteParamtypes.RESPONSE:
|
|
1332
1435
|
value = c;
|
|
1333
1436
|
break;
|
|
1334
|
-
case
|
|
1437
|
+
case RouteParamtypes.NEXT:
|
|
1335
1438
|
value = context.getArgs()[1];
|
|
1336
1439
|
break;
|
|
1337
|
-
case
|
|
1440
|
+
case RouteParamtypes.CONTEXT:
|
|
1338
1441
|
value = c;
|
|
1339
1442
|
break;
|
|
1340
|
-
case
|
|
1443
|
+
case RouteParamtypes.BODY:
|
|
1341
1444
|
if (data && c.req.parseBody) {
|
|
1342
1445
|
const body = await c.req.parseBody();
|
|
1343
1446
|
value = body[data];
|
|
@@ -1350,19 +1453,19 @@ var HonoDiApplication = class {
|
|
|
1350
1453
|
}
|
|
1351
1454
|
}
|
|
1352
1455
|
break;
|
|
1353
|
-
case
|
|
1456
|
+
case RouteParamtypes.QUERY:
|
|
1354
1457
|
value = data ? c.req.query(data) : c.req.query();
|
|
1355
1458
|
break;
|
|
1356
|
-
case
|
|
1459
|
+
case RouteParamtypes.PARAM:
|
|
1357
1460
|
value = data ? c.req.param(data) : c.req.param();
|
|
1358
1461
|
break;
|
|
1359
|
-
case
|
|
1462
|
+
case RouteParamtypes.HEADERS:
|
|
1360
1463
|
value = data ? c.req.header(data) : c.req.header();
|
|
1361
1464
|
break;
|
|
1362
|
-
case
|
|
1465
|
+
case RouteParamtypes.IP:
|
|
1363
1466
|
value = c.req.header("x-forwarded-for") || "127.0.0.1";
|
|
1364
1467
|
break;
|
|
1365
|
-
case
|
|
1468
|
+
case RouteParamtypes.CUSTOM:
|
|
1366
1469
|
const factory = arg.pipes[0];
|
|
1367
1470
|
if (typeof factory === "function") {
|
|
1368
1471
|
value = factory(data, context);
|
|
@@ -1372,9 +1475,16 @@ var HonoDiApplication = class {
|
|
|
1372
1475
|
value = null;
|
|
1373
1476
|
}
|
|
1374
1477
|
const paramPipeInstances = await this.resolveContextItems(pipes || [], moduleRef, contextId);
|
|
1375
|
-
const allPipes = [
|
|
1478
|
+
const allPipes = [
|
|
1479
|
+
...methodPipes,
|
|
1480
|
+
...paramPipeInstances
|
|
1481
|
+
];
|
|
1376
1482
|
for (const pipe of allPipes) {
|
|
1377
|
-
value = await pipe.transform(value, {
|
|
1483
|
+
value = await pipe.transform(value, {
|
|
1484
|
+
type: "custom",
|
|
1485
|
+
metatype: null,
|
|
1486
|
+
data
|
|
1487
|
+
});
|
|
1378
1488
|
}
|
|
1379
1489
|
args[index] = value;
|
|
1380
1490
|
}
|
|
@@ -1412,7 +1522,7 @@ var HonoDiApplication = class {
|
|
|
1412
1522
|
token: m,
|
|
1413
1523
|
name: m.name,
|
|
1414
1524
|
metatype: m,
|
|
1415
|
-
scope:
|
|
1525
|
+
scope: Scope.TRANSIENT
|
|
1416
1526
|
});
|
|
1417
1527
|
const scanner = new HonoDiScanner(this.container);
|
|
1418
1528
|
scanner.scanDependencies(wrapper);
|
|
@@ -1422,7 +1532,10 @@ var HonoDiApplication = class {
|
|
|
1422
1532
|
instances.push(instance);
|
|
1423
1533
|
}
|
|
1424
1534
|
}
|
|
1425
|
-
resolvedConfigs.push({
|
|
1535
|
+
resolvedConfigs.push({
|
|
1536
|
+
...config,
|
|
1537
|
+
instances
|
|
1538
|
+
});
|
|
1426
1539
|
}
|
|
1427
1540
|
this.app.use("*", async (c, next) => {
|
|
1428
1541
|
const path = c.req.path;
|
|
@@ -1437,14 +1550,14 @@ var HonoDiApplication = class {
|
|
|
1437
1550
|
if (matchingMiddleware.length === 0) {
|
|
1438
1551
|
return await next();
|
|
1439
1552
|
}
|
|
1440
|
-
const executeChain = async (index, finalNext) => {
|
|
1553
|
+
const executeChain = /* @__PURE__ */ __name(async (index, finalNext) => {
|
|
1441
1554
|
if (index >= matchingMiddleware.length) {
|
|
1442
1555
|
return await finalNext();
|
|
1443
1556
|
}
|
|
1444
1557
|
const middleware = matchingMiddleware[index];
|
|
1445
1558
|
return new Promise((resolve, reject) => {
|
|
1446
1559
|
let nextCalled = false;
|
|
1447
|
-
const nextFn = async () => {
|
|
1560
|
+
const nextFn = /* @__PURE__ */ __name(async () => {
|
|
1448
1561
|
nextCalled = true;
|
|
1449
1562
|
try {
|
|
1450
1563
|
await executeChain(index + 1, finalNext);
|
|
@@ -1452,7 +1565,7 @@ var HonoDiApplication = class {
|
|
|
1452
1565
|
} catch (e) {
|
|
1453
1566
|
reject(e);
|
|
1454
1567
|
}
|
|
1455
|
-
};
|
|
1568
|
+
}, "nextFn");
|
|
1456
1569
|
try {
|
|
1457
1570
|
const useFn = middleware.use ? middleware.use.bind(middleware) : middleware;
|
|
1458
1571
|
const result = useFn(c, nextFn);
|
|
@@ -1467,7 +1580,7 @@ var HonoDiApplication = class {
|
|
|
1467
1580
|
reject(e);
|
|
1468
1581
|
}
|
|
1469
1582
|
});
|
|
1470
|
-
};
|
|
1583
|
+
}, "executeChain");
|
|
1471
1584
|
await executeChain(0, next);
|
|
1472
1585
|
});
|
|
1473
1586
|
}
|
|
@@ -1478,7 +1591,7 @@ var HonoDiApplication = class {
|
|
|
1478
1591
|
if (normalizedRoute === "*" || path.startsWith(normalizedRoute)) return true;
|
|
1479
1592
|
if (path === normalizedRoute) return true;
|
|
1480
1593
|
} else if (typeof route === "object" && route.path && route.method) {
|
|
1481
|
-
if (route.method !== -1 && route.method !==
|
|
1594
|
+
if (route.method !== -1 && route.method !== RequestMethod.ALL && route.method !== method.toLowerCase()) {
|
|
1482
1595
|
continue;
|
|
1483
1596
|
}
|
|
1484
1597
|
if (route.path === "*" || path === route.path) return true;
|
|
@@ -1535,6 +1648,9 @@ var HonoDiApplication = class {
|
|
|
1535
1648
|
|
|
1536
1649
|
// src/factory.ts
|
|
1537
1650
|
var HonoDiFactory = class {
|
|
1651
|
+
static {
|
|
1652
|
+
__name(this, "HonoDiFactory");
|
|
1653
|
+
}
|
|
1538
1654
|
static logger = new Logger("HonoDiFactory");
|
|
1539
1655
|
static async create(rootModule, appOrOptions) {
|
|
1540
1656
|
let app;
|
|
@@ -1569,12 +1685,12 @@ var HonoDiFactory = class {
|
|
|
1569
1685
|
const globalContextId = new ContextId();
|
|
1570
1686
|
for (const module of modules.values()) {
|
|
1571
1687
|
for (const wrapper of module.providers.values()) {
|
|
1572
|
-
if (wrapper.scope ===
|
|
1688
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
1573
1689
|
await injector.loadInstance(wrapper, globalContextId);
|
|
1574
1690
|
}
|
|
1575
1691
|
}
|
|
1576
1692
|
for (const wrapper of module.controllers.values()) {
|
|
1577
|
-
if (wrapper.scope ===
|
|
1693
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
1578
1694
|
await injector.loadInstance(wrapper, globalContextId);
|
|
1579
1695
|
}
|
|
1580
1696
|
}
|
|
@@ -1599,11 +1715,24 @@ var HonoDiFactory = class {
|
|
|
1599
1715
|
|
|
1600
1716
|
// src/utils.ts
|
|
1601
1717
|
function forwardRef(fn) {
|
|
1602
|
-
return {
|
|
1718
|
+
return {
|
|
1719
|
+
forwardRef: fn
|
|
1720
|
+
};
|
|
1603
1721
|
}
|
|
1722
|
+
__name(forwardRef, "forwardRef");
|
|
1604
1723
|
|
|
1605
1724
|
// src/services/reflector.service.ts
|
|
1725
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1726
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1727
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1728
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1729
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1730
|
+
}
|
|
1731
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
1606
1732
|
exports.Reflector = class Reflector {
|
|
1733
|
+
static {
|
|
1734
|
+
__name(this, "Reflector");
|
|
1735
|
+
}
|
|
1607
1736
|
get(metadataKey, target) {
|
|
1608
1737
|
return Reflect.getMetadata(metadataKey, target);
|
|
1609
1738
|
}
|
|
@@ -1631,12 +1760,22 @@ exports.Reflector = class Reflector {
|
|
|
1631
1760
|
return result;
|
|
1632
1761
|
}
|
|
1633
1762
|
};
|
|
1634
|
-
exports.Reflector =
|
|
1763
|
+
exports.Reflector = _ts_decorate([
|
|
1635
1764
|
Injectable()
|
|
1636
1765
|
], exports.Reflector);
|
|
1637
1766
|
|
|
1638
1767
|
// src/common/pipes/index.ts
|
|
1768
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1769
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1770
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1771
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1772
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1773
|
+
}
|
|
1774
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
1639
1775
|
exports.ParseIntPipe = class ParseIntPipe {
|
|
1776
|
+
static {
|
|
1777
|
+
__name(this, "ParseIntPipe");
|
|
1778
|
+
}
|
|
1640
1779
|
transform(value, metadata) {
|
|
1641
1780
|
const isNumeric = !isNaN(parseFloat(value)) && isFinite(value);
|
|
1642
1781
|
if (!isNumeric) {
|
|
@@ -1645,10 +1784,13 @@ exports.ParseIntPipe = class ParseIntPipe {
|
|
|
1645
1784
|
return parseInt(value, 10);
|
|
1646
1785
|
}
|
|
1647
1786
|
};
|
|
1648
|
-
exports.ParseIntPipe =
|
|
1787
|
+
exports.ParseIntPipe = _ts_decorate2([
|
|
1649
1788
|
Injectable()
|
|
1650
1789
|
], exports.ParseIntPipe);
|
|
1651
1790
|
exports.ParseFloatPipe = class ParseFloatPipe {
|
|
1791
|
+
static {
|
|
1792
|
+
__name(this, "ParseFloatPipe");
|
|
1793
|
+
}
|
|
1652
1794
|
transform(value, metadata) {
|
|
1653
1795
|
const isNumeric = !isNaN(parseFloat(value)) && isFinite(value);
|
|
1654
1796
|
if (!isNumeric) {
|
|
@@ -1657,10 +1799,13 @@ exports.ParseFloatPipe = class ParseFloatPipe {
|
|
|
1657
1799
|
return parseFloat(value);
|
|
1658
1800
|
}
|
|
1659
1801
|
};
|
|
1660
|
-
exports.ParseFloatPipe =
|
|
1802
|
+
exports.ParseFloatPipe = _ts_decorate2([
|
|
1661
1803
|
Injectable()
|
|
1662
1804
|
], exports.ParseFloatPipe);
|
|
1663
1805
|
exports.ParseBoolPipe = class ParseBoolPipe {
|
|
1806
|
+
static {
|
|
1807
|
+
__name(this, "ParseBoolPipe");
|
|
1808
|
+
}
|
|
1664
1809
|
transform(value, metadata) {
|
|
1665
1810
|
if (value === true || value === "true") {
|
|
1666
1811
|
return true;
|
|
@@ -1671,50 +1816,71 @@ exports.ParseBoolPipe = class ParseBoolPipe {
|
|
|
1671
1816
|
throw new BadRequestException("Validation failed (boolean string is expected)");
|
|
1672
1817
|
}
|
|
1673
1818
|
};
|
|
1674
|
-
exports.ParseBoolPipe =
|
|
1819
|
+
exports.ParseBoolPipe = _ts_decorate2([
|
|
1675
1820
|
Injectable()
|
|
1676
1821
|
], exports.ParseBoolPipe);
|
|
1677
1822
|
exports.ValidationPipe = class ValidationPipe {
|
|
1823
|
+
static {
|
|
1824
|
+
__name(this, "ValidationPipe");
|
|
1825
|
+
}
|
|
1678
1826
|
transform(value, metadata) {
|
|
1679
1827
|
return value;
|
|
1680
1828
|
}
|
|
1681
1829
|
};
|
|
1682
|
-
exports.ValidationPipe =
|
|
1830
|
+
exports.ValidationPipe = _ts_decorate2([
|
|
1683
1831
|
Injectable()
|
|
1684
1832
|
], exports.ValidationPipe);
|
|
1685
1833
|
|
|
1686
1834
|
// src/common/errors/AppError.ts
|
|
1687
1835
|
var AppError = class _AppError extends Error {
|
|
1836
|
+
static {
|
|
1837
|
+
__name(this, "AppError");
|
|
1838
|
+
}
|
|
1839
|
+
statusCode;
|
|
1840
|
+
message;
|
|
1841
|
+
isOperational;
|
|
1688
1842
|
constructor(statusCode, message, isOperational = true) {
|
|
1689
|
-
super(message);
|
|
1690
|
-
this.statusCode = statusCode;
|
|
1691
|
-
this.message = message;
|
|
1692
|
-
this.isOperational = isOperational;
|
|
1843
|
+
super(message), this.statusCode = statusCode, this.message = message, this.isOperational = isOperational;
|
|
1693
1844
|
Object.setPrototypeOf(this, _AppError.prototype);
|
|
1694
1845
|
Error.captureStackTrace(this, this.constructor);
|
|
1695
1846
|
}
|
|
1696
1847
|
};
|
|
1697
1848
|
var NotFoundError = class extends AppError {
|
|
1849
|
+
static {
|
|
1850
|
+
__name(this, "NotFoundError");
|
|
1851
|
+
}
|
|
1698
1852
|
constructor(message = "Resource not found") {
|
|
1699
1853
|
super(404, message);
|
|
1700
1854
|
}
|
|
1701
1855
|
};
|
|
1702
1856
|
var BadRequestError = class extends AppError {
|
|
1857
|
+
static {
|
|
1858
|
+
__name(this, "BadRequestError");
|
|
1859
|
+
}
|
|
1703
1860
|
constructor(message = "Bad request") {
|
|
1704
1861
|
super(400, message);
|
|
1705
1862
|
}
|
|
1706
1863
|
};
|
|
1707
1864
|
var UnauthorizedError = class extends AppError {
|
|
1865
|
+
static {
|
|
1866
|
+
__name(this, "UnauthorizedError");
|
|
1867
|
+
}
|
|
1708
1868
|
constructor(message = "Unauthorized") {
|
|
1709
1869
|
super(401, message);
|
|
1710
1870
|
}
|
|
1711
1871
|
};
|
|
1712
1872
|
var ForbiddenError = class extends AppError {
|
|
1873
|
+
static {
|
|
1874
|
+
__name(this, "ForbiddenError");
|
|
1875
|
+
}
|
|
1713
1876
|
constructor(message = "Forbidden") {
|
|
1714
1877
|
super(403, message);
|
|
1715
1878
|
}
|
|
1716
1879
|
};
|
|
1717
1880
|
var ConflictError = class extends AppError {
|
|
1881
|
+
static {
|
|
1882
|
+
__name(this, "ConflictError");
|
|
1883
|
+
}
|
|
1718
1884
|
constructor(message = "Resource already exists") {
|
|
1719
1885
|
super(409, message);
|
|
1720
1886
|
}
|
|
@@ -1722,10 +1888,13 @@ var ConflictError = class extends AppError {
|
|
|
1722
1888
|
|
|
1723
1889
|
// src/common/exceptions/HttpException.ts
|
|
1724
1890
|
var HttpException2 = class extends Error {
|
|
1891
|
+
static {
|
|
1892
|
+
__name(this, "HttpException");
|
|
1893
|
+
}
|
|
1894
|
+
response;
|
|
1895
|
+
status;
|
|
1725
1896
|
constructor(response, status) {
|
|
1726
|
-
super();
|
|
1727
|
-
this.response = response;
|
|
1728
|
-
this.status = status;
|
|
1897
|
+
super(), this.response = response, this.status = status;
|
|
1729
1898
|
this.message = typeof response === "string" ? response : JSON.stringify(response);
|
|
1730
1899
|
}
|
|
1731
1900
|
getResponse() {
|
|
@@ -1736,14 +1905,31 @@ var HttpException2 = class extends Error {
|
|
|
1736
1905
|
}
|
|
1737
1906
|
static createBody(message, error, statusCode) {
|
|
1738
1907
|
if (!message) {
|
|
1739
|
-
return {
|
|
1908
|
+
return {
|
|
1909
|
+
statusCode,
|
|
1910
|
+
error
|
|
1911
|
+
};
|
|
1740
1912
|
}
|
|
1741
|
-
return typeof message === "object" && !Array.isArray(message) ? message : {
|
|
1913
|
+
return typeof message === "object" && !Array.isArray(message) ? message : {
|
|
1914
|
+
statusCode,
|
|
1915
|
+
error,
|
|
1916
|
+
message
|
|
1917
|
+
};
|
|
1742
1918
|
}
|
|
1743
1919
|
};
|
|
1744
1920
|
|
|
1745
1921
|
// src/common/filters/BaseExceptionFilter.ts
|
|
1922
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
1923
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1924
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1925
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1926
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1927
|
+
}
|
|
1928
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
1746
1929
|
exports.BaseExceptionFilter = class BaseExceptionFilter {
|
|
1930
|
+
static {
|
|
1931
|
+
__name(this, "BaseExceptionFilter");
|
|
1932
|
+
}
|
|
1747
1933
|
catch(exception, host) {
|
|
1748
1934
|
const ctx = host.switchToHttp();
|
|
1749
1935
|
ctx.getResponse();
|
|
@@ -1762,7 +1948,7 @@ exports.BaseExceptionFilter = class BaseExceptionFilter {
|
|
|
1762
1948
|
});
|
|
1763
1949
|
}
|
|
1764
1950
|
};
|
|
1765
|
-
exports.BaseExceptionFilter =
|
|
1951
|
+
exports.BaseExceptionFilter = _ts_decorate3([
|
|
1766
1952
|
Catch()
|
|
1767
1953
|
], exports.BaseExceptionFilter);
|
|
1768
1954
|
|