@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/core.js
CHANGED
|
@@ -3,17 +3,11 @@ import { Hono } from 'hono';
|
|
|
3
3
|
import { Observable, from, lastValueFrom } from 'rxjs';
|
|
4
4
|
import { mergeMap } from 'rxjs/operators';
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
9
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
10
|
-
if (decorator = decorators[i])
|
|
11
|
-
result = (decorator(result)) || result;
|
|
12
|
-
return result;
|
|
13
|
-
};
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
8
|
|
|
15
9
|
// src/interfaces.ts
|
|
16
|
-
var RequestMethod = /* @__PURE__ */ ((RequestMethod2)
|
|
10
|
+
var RequestMethod = /* @__PURE__ */ (function(RequestMethod2) {
|
|
17
11
|
RequestMethod2["GET"] = "get";
|
|
18
12
|
RequestMethod2["POST"] = "post";
|
|
19
13
|
RequestMethod2["PUT"] = "put";
|
|
@@ -23,18 +17,23 @@ var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => {
|
|
|
23
17
|
RequestMethod2["OPTIONS"] = "options";
|
|
24
18
|
RequestMethod2["HEAD"] = "head";
|
|
25
19
|
return RequestMethod2;
|
|
26
|
-
})(
|
|
20
|
+
})({});
|
|
27
21
|
|
|
28
22
|
// src/injector/module.ts
|
|
29
23
|
var Module = class {
|
|
30
|
-
|
|
31
|
-
this
|
|
32
|
-
this.token = token;
|
|
24
|
+
static {
|
|
25
|
+
__name(this, "Module");
|
|
33
26
|
}
|
|
27
|
+
metatype;
|
|
28
|
+
token;
|
|
34
29
|
_providers = /* @__PURE__ */ new Map();
|
|
35
30
|
_imports = /* @__PURE__ */ new Set();
|
|
36
31
|
_exports = /* @__PURE__ */ new Set();
|
|
37
32
|
_controllers = /* @__PURE__ */ new Map();
|
|
33
|
+
constructor(metatype, token) {
|
|
34
|
+
this.metatype = metatype;
|
|
35
|
+
this.token = token;
|
|
36
|
+
}
|
|
38
37
|
get providers() {
|
|
39
38
|
return this._providers;
|
|
40
39
|
}
|
|
@@ -69,6 +68,9 @@ var Module = class {
|
|
|
69
68
|
|
|
70
69
|
// src/injector/container.ts
|
|
71
70
|
var Container = class {
|
|
71
|
+
static {
|
|
72
|
+
__name(this, "Container");
|
|
73
|
+
}
|
|
72
74
|
modules = /* @__PURE__ */ new Map();
|
|
73
75
|
globalModules = /* @__PURE__ */ new Set();
|
|
74
76
|
addModule(moduleMeta, token) {
|
|
@@ -95,6 +97,9 @@ var Container = class {
|
|
|
95
97
|
|
|
96
98
|
// src/injector/context-id.ts
|
|
97
99
|
var ContextId = class _ContextId {
|
|
100
|
+
static {
|
|
101
|
+
__name(this, "ContextId");
|
|
102
|
+
}
|
|
98
103
|
static idCounter = 0;
|
|
99
104
|
id;
|
|
100
105
|
constructor() {
|
|
@@ -103,29 +108,47 @@ var ContextId = class _ContextId {
|
|
|
103
108
|
};
|
|
104
109
|
new ContextId();
|
|
105
110
|
|
|
111
|
+
// src/injector/scope.ts
|
|
112
|
+
var Scope = /* @__PURE__ */ (function(Scope2) {
|
|
113
|
+
Scope2[Scope2["DEFAULT"] = 0] = "DEFAULT";
|
|
114
|
+
Scope2[Scope2["TRANSIENT"] = 1] = "TRANSIENT";
|
|
115
|
+
Scope2[Scope2["REQUEST"] = 2] = "REQUEST";
|
|
116
|
+
return Scope2;
|
|
117
|
+
})({});
|
|
118
|
+
|
|
106
119
|
// src/injector/module-ref.ts
|
|
107
120
|
var ModuleRef = class {
|
|
121
|
+
static {
|
|
122
|
+
__name(this, "ModuleRef");
|
|
123
|
+
}
|
|
108
124
|
};
|
|
109
125
|
var ModuleRefImpl = class extends ModuleRef {
|
|
126
|
+
static {
|
|
127
|
+
__name(this, "ModuleRefImpl");
|
|
128
|
+
}
|
|
129
|
+
container;
|
|
130
|
+
injector;
|
|
131
|
+
moduleRef;
|
|
110
132
|
constructor(container, injector, moduleRef) {
|
|
111
|
-
super();
|
|
112
|
-
this.container = container;
|
|
113
|
-
this.injector = injector;
|
|
114
|
-
this.moduleRef = moduleRef;
|
|
133
|
+
super(), this.container = container, this.injector = injector, this.moduleRef = moduleRef;
|
|
115
134
|
}
|
|
116
|
-
get(typeOrToken, options = {
|
|
135
|
+
get(typeOrToken, options = {
|
|
136
|
+
strict: true
|
|
137
|
+
}) {
|
|
117
138
|
const token = typeOrToken;
|
|
118
139
|
let wrapper = this.moduleRef.getProvider(token);
|
|
119
140
|
if (!wrapper && !options.strict) ;
|
|
120
141
|
if (!wrapper) {
|
|
121
142
|
throw new Error(`ModuleRef cannot find provider for ${token.toString()}`);
|
|
122
143
|
}
|
|
123
|
-
if (wrapper.scope !==
|
|
144
|
+
if (wrapper.scope !== Scope.DEFAULT) {
|
|
124
145
|
throw new Error(`Cannot use get() for scoped provider ${token.toString()}. Use resolve() instead.`);
|
|
125
146
|
}
|
|
126
147
|
return wrapper.instance;
|
|
127
148
|
}
|
|
128
|
-
async resolve(typeOrToken, contextId, options = {
|
|
149
|
+
async resolve(typeOrToken, contextId, options = {
|
|
150
|
+
strict: true
|
|
151
|
+
}) {
|
|
129
152
|
const token = typeOrToken;
|
|
130
153
|
const wrapper = this.moduleRef.getProvider(token);
|
|
131
154
|
if (!wrapper) {
|
|
@@ -137,17 +160,24 @@ var ModuleRefImpl = class extends ModuleRef {
|
|
|
137
160
|
|
|
138
161
|
// src/injector/injector.ts
|
|
139
162
|
var Injector = class {
|
|
163
|
+
static {
|
|
164
|
+
__name(this, "Injector");
|
|
165
|
+
}
|
|
166
|
+
container;
|
|
140
167
|
constructor(container) {
|
|
141
168
|
this.container = container;
|
|
142
169
|
}
|
|
143
170
|
async resolveConstructorParams(wrapper, module, inject, callback, contextId = new ContextId(), inquire = [], parentInquire = []) {
|
|
144
|
-
if (inquire.some((item) => item === wrapper) && wrapper.scope ===
|
|
171
|
+
if (inquire.some((item) => item === wrapper) && wrapper.scope === Scope.DEFAULT) {
|
|
145
172
|
throw new Error(`Circular dependency detected: ${wrapper.name}`);
|
|
146
173
|
}
|
|
147
174
|
const args = [];
|
|
148
175
|
for (const [index, token] of inject.entries()) {
|
|
149
176
|
const isOptional = wrapper.isOptional ? wrapper.isOptional[index] : false;
|
|
150
|
-
const paramWrapper = await this.resolveSingleParam(token, module, contextId, [
|
|
177
|
+
const paramWrapper = await this.resolveSingleParam(token, module, contextId, [
|
|
178
|
+
...inquire,
|
|
179
|
+
wrapper
|
|
180
|
+
], isOptional);
|
|
151
181
|
args.push(paramWrapper);
|
|
152
182
|
}
|
|
153
183
|
return args;
|
|
@@ -170,11 +200,11 @@ var Injector = class {
|
|
|
170
200
|
}
|
|
171
201
|
if (isForwardRef) {
|
|
172
202
|
return new Proxy({}, {
|
|
173
|
-
get: (target, prop) => {
|
|
203
|
+
get: /* @__PURE__ */ __name((target, prop) => {
|
|
174
204
|
if (prop === "then") return void 0;
|
|
175
205
|
if (!wrapper.instance) ;
|
|
176
206
|
return wrapper.instance?.[prop];
|
|
177
|
-
}
|
|
207
|
+
}, "get")
|
|
178
208
|
});
|
|
179
209
|
}
|
|
180
210
|
return this.loadInstance(wrapper, contextId, inquire);
|
|
@@ -207,17 +237,17 @@ var Injector = class {
|
|
|
207
237
|
return void 0;
|
|
208
238
|
}
|
|
209
239
|
async loadInstance(wrapper, contextId, inquire = []) {
|
|
210
|
-
if (wrapper.isResolved && wrapper.scope ===
|
|
240
|
+
if (wrapper.isResolved && wrapper.scope === Scope.DEFAULT) {
|
|
211
241
|
return wrapper.instance;
|
|
212
242
|
}
|
|
213
|
-
if (wrapper.scope ===
|
|
243
|
+
if (wrapper.scope === Scope.REQUEST) {
|
|
214
244
|
const existing = wrapper.getInstanceByContextId(contextId);
|
|
215
245
|
if (existing) return existing;
|
|
216
246
|
}
|
|
217
247
|
if (wrapper.isAlias) {
|
|
218
248
|
const targetToken = wrapper.useExisting;
|
|
219
249
|
const instance2 = await this.resolveSingleParam(targetToken, wrapper.host, contextId, inquire);
|
|
220
|
-
if (wrapper.scope ===
|
|
250
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
221
251
|
wrapper.instance = instance2;
|
|
222
252
|
wrapper.isResolved = true;
|
|
223
253
|
} else {
|
|
@@ -232,17 +262,10 @@ var Injector = class {
|
|
|
232
262
|
}
|
|
233
263
|
if (wrapper.useFactory) {
|
|
234
264
|
const dependencies2 = wrapper.inject || [];
|
|
235
|
-
const args = await this.resolveConstructorParams(
|
|
236
|
-
|
|
237
|
-
wrapper.host,
|
|
238
|
-
dependencies2,
|
|
239
|
-
(args2) => {
|
|
240
|
-
},
|
|
241
|
-
contextId,
|
|
242
|
-
inquire
|
|
243
|
-
);
|
|
265
|
+
const args = await this.resolveConstructorParams(wrapper, wrapper.host, dependencies2, (args2) => {
|
|
266
|
+
}, contextId, inquire);
|
|
244
267
|
const instance2 = await wrapper.useFactory(...args);
|
|
245
|
-
if (wrapper.scope ===
|
|
268
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
246
269
|
wrapper.instance = instance2;
|
|
247
270
|
wrapper.isResolved = true;
|
|
248
271
|
} else {
|
|
@@ -255,31 +278,18 @@ var Injector = class {
|
|
|
255
278
|
throw new Error("Invalid metatype");
|
|
256
279
|
}
|
|
257
280
|
let dependencies = wrapper.inject || [];
|
|
258
|
-
const constructorArgs = await this.resolveConstructorParams(
|
|
259
|
-
|
|
260
|
-
wrapper.host,
|
|
261
|
-
dependencies,
|
|
262
|
-
(args) => {
|
|
263
|
-
},
|
|
264
|
-
contextId,
|
|
265
|
-
inquire
|
|
266
|
-
);
|
|
281
|
+
const constructorArgs = await this.resolveConstructorParams(wrapper, wrapper.host, dependencies, (args) => {
|
|
282
|
+
}, contextId, inquire);
|
|
267
283
|
const instance = new metatype(...constructorArgs);
|
|
268
284
|
if (wrapper.properties) {
|
|
269
285
|
for (const prop of wrapper.properties) {
|
|
270
|
-
const propInstance = await this.resolveSingleParam(
|
|
271
|
-
prop.token,
|
|
272
|
-
wrapper.host,
|
|
273
|
-
contextId,
|
|
274
|
-
inquire,
|
|
275
|
-
prop.isOptional
|
|
276
|
-
);
|
|
286
|
+
const propInstance = await this.resolveSingleParam(prop.token, wrapper.host, contextId, inquire, prop.isOptional);
|
|
277
287
|
if (propInstance !== void 0) {
|
|
278
288
|
instance[prop.key] = propInstance;
|
|
279
289
|
}
|
|
280
290
|
}
|
|
281
291
|
}
|
|
282
|
-
if (wrapper.scope ===
|
|
292
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
283
293
|
wrapper.instance = instance;
|
|
284
294
|
wrapper.isResolved = true;
|
|
285
295
|
} else {
|
|
@@ -291,22 +301,22 @@ var Injector = class {
|
|
|
291
301
|
|
|
292
302
|
// src/injector/instance-wrapper.ts
|
|
293
303
|
var InstanceWrapper = class {
|
|
304
|
+
static {
|
|
305
|
+
__name(this, "InstanceWrapper");
|
|
306
|
+
}
|
|
294
307
|
id;
|
|
295
308
|
token;
|
|
296
309
|
name;
|
|
297
310
|
metatype;
|
|
298
|
-
scope =
|
|
311
|
+
scope = Scope.DEFAULT;
|
|
299
312
|
host;
|
|
300
|
-
// Generic logic
|
|
301
313
|
inject;
|
|
302
314
|
isOptional;
|
|
303
315
|
properties;
|
|
304
316
|
instance;
|
|
305
|
-
// Singleton instance
|
|
306
317
|
instancesPerContext = /* @__PURE__ */ new Map();
|
|
307
318
|
isResolved = false;
|
|
308
319
|
isPending = false;
|
|
309
|
-
// For circular dependency detection
|
|
310
320
|
isAlias = false;
|
|
311
321
|
useFactory;
|
|
312
322
|
useValue;
|
|
@@ -315,7 +325,7 @@ var InstanceWrapper = class {
|
|
|
315
325
|
this.token = metadata.token;
|
|
316
326
|
this.name = metadata.name;
|
|
317
327
|
this.metatype = metadata.metatype;
|
|
318
|
-
this.scope = metadata.scope ??
|
|
328
|
+
this.scope = metadata.scope ?? Scope.DEFAULT;
|
|
319
329
|
this.host = metadata.host;
|
|
320
330
|
this.instance = metadata.instance;
|
|
321
331
|
this.inject = metadata.inject;
|
|
@@ -327,18 +337,18 @@ var InstanceWrapper = class {
|
|
|
327
337
|
this.id = Math.random().toString(36).substring(7);
|
|
328
338
|
}
|
|
329
339
|
getInstanceByContextId(contextId) {
|
|
330
|
-
if (this.scope ===
|
|
340
|
+
if (this.scope === Scope.TRANSIENT) {
|
|
331
341
|
return void 0;
|
|
332
342
|
}
|
|
333
|
-
if (this.scope ===
|
|
343
|
+
if (this.scope === Scope.DEFAULT) {
|
|
334
344
|
return this.instance;
|
|
335
345
|
}
|
|
336
346
|
return this.instancesPerContext.get(contextId);
|
|
337
347
|
}
|
|
338
348
|
setInstanceByContextId(contextId, instance) {
|
|
339
|
-
if (this.scope ===
|
|
349
|
+
if (this.scope === Scope.DEFAULT) {
|
|
340
350
|
this.instance = instance;
|
|
341
|
-
} else if (this.scope ===
|
|
351
|
+
} else if (this.scope === Scope.REQUEST) {
|
|
342
352
|
this.instancesPerContext.set(contextId, instance);
|
|
343
353
|
}
|
|
344
354
|
}
|
|
@@ -379,6 +389,9 @@ var METADATA_KEYS = {
|
|
|
379
389
|
|
|
380
390
|
// src/services/logger.service.ts
|
|
381
391
|
var Logger = class _Logger {
|
|
392
|
+
static {
|
|
393
|
+
__name(this, "Logger");
|
|
394
|
+
}
|
|
382
395
|
static lastTimestamp;
|
|
383
396
|
static instance;
|
|
384
397
|
context;
|
|
@@ -433,10 +446,8 @@ var Logger = class _Logger {
|
|
|
433
446
|
red: "\x1B[31m",
|
|
434
447
|
green: "\x1B[32m",
|
|
435
448
|
yellow: "\x1B[33m"};
|
|
436
|
-
process.stdout.write(
|
|
437
|
-
|
|
438
|
-
`
|
|
439
|
-
);
|
|
449
|
+
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}
|
|
450
|
+
`);
|
|
440
451
|
if (trace) {
|
|
441
452
|
process.stdout.write(`${C.red}${trace}${C.reset}
|
|
442
453
|
`);
|
|
@@ -475,6 +486,10 @@ var Logger = class _Logger {
|
|
|
475
486
|
|
|
476
487
|
// src/scanner.ts
|
|
477
488
|
var HonoDiScanner = class {
|
|
489
|
+
static {
|
|
490
|
+
__name(this, "HonoDiScanner");
|
|
491
|
+
}
|
|
492
|
+
container;
|
|
478
493
|
constructor(container) {
|
|
479
494
|
this.container = container;
|
|
480
495
|
}
|
|
@@ -501,7 +516,7 @@ var HonoDiScanner = class {
|
|
|
501
516
|
name: moduleClass.name,
|
|
502
517
|
metatype: moduleClass,
|
|
503
518
|
host: moduleRef,
|
|
504
|
-
scope:
|
|
519
|
+
scope: Scope.DEFAULT
|
|
505
520
|
});
|
|
506
521
|
this.scanDependencies(moduleWrapper);
|
|
507
522
|
moduleRef.addProvider(moduleWrapper);
|
|
@@ -513,10 +528,22 @@ var HonoDiScanner = class {
|
|
|
513
528
|
const options = {
|
|
514
529
|
...decoratorOptions,
|
|
515
530
|
...dynamicMetadata,
|
|
516
|
-
imports: [
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
531
|
+
imports: [
|
|
532
|
+
...decoratorOptions.imports || [],
|
|
533
|
+
...dynamicMetadata.imports || []
|
|
534
|
+
],
|
|
535
|
+
providers: [
|
|
536
|
+
...decoratorOptions.providers || [],
|
|
537
|
+
...dynamicMetadata.providers || []
|
|
538
|
+
],
|
|
539
|
+
exports: [
|
|
540
|
+
...decoratorOptions.exports || [],
|
|
541
|
+
...dynamicMetadata.exports || []
|
|
542
|
+
],
|
|
543
|
+
controllers: [
|
|
544
|
+
...decoratorOptions.controllers || [],
|
|
545
|
+
...dynamicMetadata.controllers || []
|
|
546
|
+
]
|
|
520
547
|
};
|
|
521
548
|
if (options.imports) {
|
|
522
549
|
for (const importedModule of options.imports) {
|
|
@@ -524,7 +551,10 @@ var HonoDiScanner = class {
|
|
|
524
551
|
if (importedModule && typeof importedModule.forwardRef === "function") {
|
|
525
552
|
actualImport = importedModule.forwardRef();
|
|
526
553
|
}
|
|
527
|
-
const importedRef = await this.scanModule(actualImport, [
|
|
554
|
+
const importedRef = await this.scanModule(actualImport, [
|
|
555
|
+
...scope,
|
|
556
|
+
moduleClass
|
|
557
|
+
]);
|
|
528
558
|
if (importedRef) {
|
|
529
559
|
moduleRef.addImport(importedRef);
|
|
530
560
|
}
|
|
@@ -557,7 +587,7 @@ var HonoDiScanner = class {
|
|
|
557
587
|
name: token2.name,
|
|
558
588
|
metatype: provider,
|
|
559
589
|
host: moduleRef,
|
|
560
|
-
scope:
|
|
590
|
+
scope: Scope.DEFAULT
|
|
561
591
|
});
|
|
562
592
|
this.scanDependencies(wrapper2);
|
|
563
593
|
moduleRef.addProvider(wrapper2);
|
|
@@ -568,7 +598,7 @@ var HonoDiScanner = class {
|
|
|
568
598
|
token,
|
|
569
599
|
name: token && token.name ? token.name : typeof token === "string" ? token : "CustomProvider",
|
|
570
600
|
host: moduleRef,
|
|
571
|
-
scope: provider.scope ||
|
|
601
|
+
scope: provider.scope || Scope.DEFAULT
|
|
572
602
|
});
|
|
573
603
|
if (provider.useValue !== void 0) {
|
|
574
604
|
wrapper.useValue = provider.useValue;
|
|
@@ -591,7 +621,7 @@ var HonoDiScanner = class {
|
|
|
591
621
|
name: token.name,
|
|
592
622
|
metatype: controller,
|
|
593
623
|
host: moduleRef,
|
|
594
|
-
scope:
|
|
624
|
+
scope: Scope.DEFAULT
|
|
595
625
|
});
|
|
596
626
|
this.scanDependencies(wrapper);
|
|
597
627
|
moduleRef.addController(wrapper);
|
|
@@ -622,6 +652,9 @@ var HonoDiScanner = class {
|
|
|
622
652
|
|
|
623
653
|
// src/execution-context-host.ts
|
|
624
654
|
var ExecutionContextHost = class {
|
|
655
|
+
static {
|
|
656
|
+
__name(this, "ExecutionContextHost");
|
|
657
|
+
}
|
|
625
658
|
args;
|
|
626
659
|
constructorRef;
|
|
627
660
|
handler;
|
|
@@ -648,31 +681,100 @@ var ExecutionContextHost = class {
|
|
|
648
681
|
}
|
|
649
682
|
switchToHttp() {
|
|
650
683
|
return {
|
|
651
|
-
getRequest: () => this.context.req,
|
|
652
|
-
getResponse: () => this.context,
|
|
653
|
-
getNext: () => this.next ?? (() => Promise.resolve()),
|
|
654
|
-
getContext: () => this.context
|
|
684
|
+
getRequest: /* @__PURE__ */ __name(() => this.context.req, "getRequest"),
|
|
685
|
+
getResponse: /* @__PURE__ */ __name(() => this.context, "getResponse"),
|
|
686
|
+
getNext: /* @__PURE__ */ __name(() => this.next ?? (() => Promise.resolve()), "getNext"),
|
|
687
|
+
getContext: /* @__PURE__ */ __name(() => this.context, "getContext")
|
|
655
688
|
};
|
|
656
689
|
}
|
|
657
690
|
};
|
|
658
691
|
function Injectable(options) {
|
|
659
692
|
return (target) => {
|
|
660
|
-
Reflect.defineMetadata(METADATA_KEYS.SCOPE,
|
|
693
|
+
Reflect.defineMetadata(METADATA_KEYS.SCOPE, options?.scope ?? Scope.DEFAULT, target);
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
__name(Injectable, "Injectable");
|
|
697
|
+
function createRouteDecorator(method) {
|
|
698
|
+
return (path = "/") => {
|
|
699
|
+
return (target, propertyKey, descriptor) => {
|
|
700
|
+
if (!Reflect.hasMetadata(METADATA_KEYS.ROUTES, target.constructor)) {
|
|
701
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTES, [], target.constructor);
|
|
702
|
+
}
|
|
703
|
+
const routes = Reflect.getMetadata(METADATA_KEYS.ROUTES, target.constructor);
|
|
704
|
+
routes.push({
|
|
705
|
+
requestMethod: method,
|
|
706
|
+
path,
|
|
707
|
+
methodName: propertyKey
|
|
708
|
+
});
|
|
709
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTES, routes, target.constructor);
|
|
710
|
+
};
|
|
661
711
|
};
|
|
662
712
|
}
|
|
713
|
+
__name(createRouteDecorator, "createRouteDecorator");
|
|
714
|
+
createRouteDecorator(RequestMethod.GET);
|
|
715
|
+
createRouteDecorator(RequestMethod.POST);
|
|
716
|
+
createRouteDecorator(RequestMethod.PUT);
|
|
717
|
+
createRouteDecorator(RequestMethod.DELETE);
|
|
718
|
+
createRouteDecorator(RequestMethod.PATCH);
|
|
719
|
+
createRouteDecorator(RequestMethod.OPTIONS);
|
|
720
|
+
createRouteDecorator(RequestMethod.HEAD);
|
|
721
|
+
createRouteDecorator(RequestMethod.ALL);
|
|
663
722
|
function Catch(...exceptions) {
|
|
664
723
|
return (target) => {
|
|
665
724
|
Reflect.defineMetadata(METADATA_KEYS.FILTER_CATCH, exceptions, target);
|
|
666
|
-
Reflect.defineMetadata(METADATA_KEYS.SCOPE,
|
|
725
|
+
Reflect.defineMetadata(METADATA_KEYS.SCOPE, Scope.DEFAULT, target);
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
__name(Catch, "Catch");
|
|
729
|
+
var RouteParamtypes = /* @__PURE__ */ (function(RouteParamtypes2) {
|
|
730
|
+
RouteParamtypes2[RouteParamtypes2["REQUEST"] = 0] = "REQUEST";
|
|
731
|
+
RouteParamtypes2[RouteParamtypes2["RESPONSE"] = 1] = "RESPONSE";
|
|
732
|
+
RouteParamtypes2[RouteParamtypes2["NEXT"] = 2] = "NEXT";
|
|
733
|
+
RouteParamtypes2[RouteParamtypes2["BODY"] = 3] = "BODY";
|
|
734
|
+
RouteParamtypes2[RouteParamtypes2["QUERY"] = 4] = "QUERY";
|
|
735
|
+
RouteParamtypes2[RouteParamtypes2["PARAM"] = 5] = "PARAM";
|
|
736
|
+
RouteParamtypes2[RouteParamtypes2["HEADERS"] = 6] = "HEADERS";
|
|
737
|
+
RouteParamtypes2[RouteParamtypes2["SESSION"] = 7] = "SESSION";
|
|
738
|
+
RouteParamtypes2[RouteParamtypes2["FILE"] = 8] = "FILE";
|
|
739
|
+
RouteParamtypes2[RouteParamtypes2["FILES"] = 9] = "FILES";
|
|
740
|
+
RouteParamtypes2[RouteParamtypes2["HOST"] = 10] = "HOST";
|
|
741
|
+
RouteParamtypes2[RouteParamtypes2["IP"] = 11] = "IP";
|
|
742
|
+
RouteParamtypes2[RouteParamtypes2["CONTEXT"] = 12] = "CONTEXT";
|
|
743
|
+
RouteParamtypes2[RouteParamtypes2["CUSTOM"] = 13] = "CUSTOM";
|
|
744
|
+
return RouteParamtypes2;
|
|
745
|
+
})({});
|
|
746
|
+
function assignMetadata(args, paramtype, index, data, ...pipes) {
|
|
747
|
+
return {
|
|
748
|
+
...args,
|
|
749
|
+
[`${paramtype}:${index}`]: {
|
|
750
|
+
index,
|
|
751
|
+
data,
|
|
752
|
+
pipes,
|
|
753
|
+
paramtype
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
__name(assignMetadata, "assignMetadata");
|
|
758
|
+
function createRouteParamDecorator(paramtype) {
|
|
759
|
+
return (data) => {
|
|
760
|
+
return (target, key, index) => {
|
|
761
|
+
const args = Reflect.getMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, target.constructor, key) || {};
|
|
762
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, assignMetadata(args, paramtype, index, data), target.constructor, key);
|
|
763
|
+
};
|
|
667
764
|
};
|
|
668
765
|
}
|
|
766
|
+
__name(createRouteParamDecorator, "createRouteParamDecorator");
|
|
669
767
|
|
|
670
768
|
// src/middleware/builder.ts
|
|
671
769
|
var MiddlewareBuilder = class {
|
|
770
|
+
static {
|
|
771
|
+
__name(this, "MiddlewareBuilder");
|
|
772
|
+
}
|
|
773
|
+
module;
|
|
774
|
+
configs = [];
|
|
672
775
|
constructor(module) {
|
|
673
776
|
this.module = module;
|
|
674
777
|
}
|
|
675
|
-
configs = [];
|
|
676
778
|
apply(...middleware) {
|
|
677
779
|
return new MiddlewareConfigProxyImpl(this, middleware);
|
|
678
780
|
}
|
|
@@ -688,12 +790,17 @@ var MiddlewareBuilder = class {
|
|
|
688
790
|
return this.configs;
|
|
689
791
|
}
|
|
690
792
|
};
|
|
691
|
-
var MiddlewareConfigProxyImpl = class {
|
|
793
|
+
var MiddlewareConfigProxyImpl = class MiddlewareConfigProxyImpl2 {
|
|
794
|
+
static {
|
|
795
|
+
__name(this, "MiddlewareConfigProxyImpl");
|
|
796
|
+
}
|
|
797
|
+
builder;
|
|
798
|
+
middleware;
|
|
799
|
+
excludes = [];
|
|
692
800
|
constructor(builder, middleware) {
|
|
693
801
|
this.builder = builder;
|
|
694
802
|
this.middleware = middleware;
|
|
695
803
|
}
|
|
696
|
-
excludes = [];
|
|
697
804
|
exclude(...routes) {
|
|
698
805
|
this.excludes = routes;
|
|
699
806
|
return this;
|
|
@@ -706,10 +813,13 @@ var MiddlewareConfigProxyImpl = class {
|
|
|
706
813
|
|
|
707
814
|
// src/common/exceptions/http.exception.ts
|
|
708
815
|
var HttpException = class extends Error {
|
|
816
|
+
static {
|
|
817
|
+
__name(this, "HttpException");
|
|
818
|
+
}
|
|
819
|
+
response;
|
|
820
|
+
status;
|
|
709
821
|
constructor(response, status) {
|
|
710
|
-
super();
|
|
711
|
-
this.response = response;
|
|
712
|
-
this.status = status;
|
|
822
|
+
super(), this.response = response, this.status = status;
|
|
713
823
|
this.message = typeof response === "string" ? response : JSON.stringify(response);
|
|
714
824
|
}
|
|
715
825
|
getResponse() {
|
|
@@ -720,89 +830,144 @@ var HttpException = class extends Error {
|
|
|
720
830
|
}
|
|
721
831
|
static createBody(message, error, statusCode) {
|
|
722
832
|
if (!message) {
|
|
723
|
-
return {
|
|
833
|
+
return {
|
|
834
|
+
statusCode,
|
|
835
|
+
error
|
|
836
|
+
};
|
|
724
837
|
}
|
|
725
|
-
return typeof message === "object" && !Array.isArray(message) ? message : {
|
|
838
|
+
return typeof message === "object" && !Array.isArray(message) ? message : {
|
|
839
|
+
statusCode,
|
|
840
|
+
error,
|
|
841
|
+
message
|
|
842
|
+
};
|
|
726
843
|
}
|
|
727
844
|
};
|
|
728
845
|
|
|
729
846
|
// src/common/exceptions/index.ts
|
|
730
847
|
var BadRequestException = class extends HttpException {
|
|
848
|
+
static {
|
|
849
|
+
__name(this, "BadRequestException");
|
|
850
|
+
}
|
|
731
851
|
constructor(message, error = "Bad Request") {
|
|
732
852
|
super(HttpException.createBody(message, error, 400), 400);
|
|
733
853
|
}
|
|
734
854
|
};
|
|
735
855
|
var UnauthorizedException = class extends HttpException {
|
|
856
|
+
static {
|
|
857
|
+
__name(this, "UnauthorizedException");
|
|
858
|
+
}
|
|
736
859
|
constructor(message, error = "Unauthorized") {
|
|
737
860
|
super(HttpException.createBody(message, error, 401), 401);
|
|
738
861
|
}
|
|
739
862
|
};
|
|
740
863
|
var NotFoundException = class extends HttpException {
|
|
864
|
+
static {
|
|
865
|
+
__name(this, "NotFoundException");
|
|
866
|
+
}
|
|
741
867
|
constructor(message, error = "Not Found") {
|
|
742
868
|
super(HttpException.createBody(message, error, 404), 404);
|
|
743
869
|
}
|
|
744
870
|
};
|
|
745
871
|
var ForbiddenException = class extends HttpException {
|
|
872
|
+
static {
|
|
873
|
+
__name(this, "ForbiddenException");
|
|
874
|
+
}
|
|
746
875
|
constructor(message, error = "Forbidden") {
|
|
747
876
|
super(HttpException.createBody(message, error, 403), 403);
|
|
748
877
|
}
|
|
749
878
|
};
|
|
750
879
|
var NotAcceptableException = class extends HttpException {
|
|
880
|
+
static {
|
|
881
|
+
__name(this, "NotAcceptableException");
|
|
882
|
+
}
|
|
751
883
|
constructor(message, error = "Not Acceptable") {
|
|
752
884
|
super(HttpException.createBody(message, error, 406), 406);
|
|
753
885
|
}
|
|
754
886
|
};
|
|
755
887
|
var RequestTimeoutException = class extends HttpException {
|
|
888
|
+
static {
|
|
889
|
+
__name(this, "RequestTimeoutException");
|
|
890
|
+
}
|
|
756
891
|
constructor(message, error = "Request Timeout") {
|
|
757
892
|
super(HttpException.createBody(message, error, 408), 408);
|
|
758
893
|
}
|
|
759
894
|
};
|
|
760
895
|
var ConflictException = class extends HttpException {
|
|
896
|
+
static {
|
|
897
|
+
__name(this, "ConflictException");
|
|
898
|
+
}
|
|
761
899
|
constructor(message, error = "Conflict") {
|
|
762
900
|
super(HttpException.createBody(message, error, 409), 409);
|
|
763
901
|
}
|
|
764
902
|
};
|
|
765
903
|
var GoneException = class extends HttpException {
|
|
904
|
+
static {
|
|
905
|
+
__name(this, "GoneException");
|
|
906
|
+
}
|
|
766
907
|
constructor(message, error = "Gone") {
|
|
767
908
|
super(HttpException.createBody(message, error, 410), 410);
|
|
768
909
|
}
|
|
769
910
|
};
|
|
770
911
|
var PayloadTooLargeException = class extends HttpException {
|
|
912
|
+
static {
|
|
913
|
+
__name(this, "PayloadTooLargeException");
|
|
914
|
+
}
|
|
771
915
|
constructor(message, error = "Payload Too Large") {
|
|
772
916
|
super(HttpException.createBody(message, error, 413), 413);
|
|
773
917
|
}
|
|
774
918
|
};
|
|
775
919
|
var UnsupportedMediaTypeException = class extends HttpException {
|
|
920
|
+
static {
|
|
921
|
+
__name(this, "UnsupportedMediaTypeException");
|
|
922
|
+
}
|
|
776
923
|
constructor(message, error = "Unsupported Media Type") {
|
|
777
924
|
super(HttpException.createBody(message, error, 415), 415);
|
|
778
925
|
}
|
|
779
926
|
};
|
|
780
927
|
var UnprocessableEntityException = class extends HttpException {
|
|
928
|
+
static {
|
|
929
|
+
__name(this, "UnprocessableEntityException");
|
|
930
|
+
}
|
|
781
931
|
constructor(message, error = "Unprocessable Entity") {
|
|
782
932
|
super(HttpException.createBody(message, error, 422), 422);
|
|
783
933
|
}
|
|
784
934
|
};
|
|
785
935
|
var InternalServerErrorException = class extends HttpException {
|
|
936
|
+
static {
|
|
937
|
+
__name(this, "InternalServerErrorException");
|
|
938
|
+
}
|
|
786
939
|
constructor(message, error = "Internal Server Error") {
|
|
787
940
|
super(HttpException.createBody(message, error, 500), 500);
|
|
788
941
|
}
|
|
789
942
|
};
|
|
790
943
|
var NotImplementedException = class extends HttpException {
|
|
944
|
+
static {
|
|
945
|
+
__name(this, "NotImplementedException");
|
|
946
|
+
}
|
|
791
947
|
constructor(message, error = "Not Implemented") {
|
|
792
948
|
super(HttpException.createBody(message, error, 501), 501);
|
|
793
949
|
}
|
|
794
950
|
};
|
|
795
951
|
var BadGatewayException = class extends HttpException {
|
|
952
|
+
static {
|
|
953
|
+
__name(this, "BadGatewayException");
|
|
954
|
+
}
|
|
796
955
|
constructor(message, error = "Bad Gateway") {
|
|
797
956
|
super(HttpException.createBody(message, error, 502), 502);
|
|
798
957
|
}
|
|
799
958
|
};
|
|
800
959
|
var ServiceUnavailableException = class extends HttpException {
|
|
960
|
+
static {
|
|
961
|
+
__name(this, "ServiceUnavailableException");
|
|
962
|
+
}
|
|
801
963
|
constructor(message, error = "Service Unavailable") {
|
|
802
964
|
super(HttpException.createBody(message, error, 503), 503);
|
|
803
965
|
}
|
|
804
966
|
};
|
|
805
967
|
var GatewayTimeoutException = class extends HttpException {
|
|
968
|
+
static {
|
|
969
|
+
__name(this, "GatewayTimeoutException");
|
|
970
|
+
}
|
|
806
971
|
constructor(message, error = "Gateway Timeout") {
|
|
807
972
|
super(HttpException.createBody(message, error, 504), 504);
|
|
808
973
|
}
|
|
@@ -810,15 +975,21 @@ var GatewayTimeoutException = class extends HttpException {
|
|
|
810
975
|
|
|
811
976
|
// src/application.ts
|
|
812
977
|
var HonoDiApplication = class {
|
|
813
|
-
|
|
814
|
-
this
|
|
815
|
-
this.container = container;
|
|
816
|
-
this.injector = injector;
|
|
978
|
+
static {
|
|
979
|
+
__name(this, "HonoDiApplication");
|
|
817
980
|
}
|
|
981
|
+
app;
|
|
982
|
+
container;
|
|
983
|
+
injector;
|
|
818
984
|
globalFilters = [];
|
|
819
985
|
globalPipes = [];
|
|
820
986
|
globalGuards = [];
|
|
821
987
|
globalInterceptors = [];
|
|
988
|
+
constructor(app, container, injector) {
|
|
989
|
+
this.app = app;
|
|
990
|
+
this.container = container;
|
|
991
|
+
this.injector = injector;
|
|
992
|
+
}
|
|
822
993
|
useGlobalFilters(...filters) {
|
|
823
994
|
this.globalFilters.push(...filters);
|
|
824
995
|
return this;
|
|
@@ -903,7 +1074,9 @@ var HonoDiApplication = class {
|
|
|
903
1074
|
const fullPath = this.combinePaths(globalPrefix, this.combinePaths(prefix, route.path));
|
|
904
1075
|
app[route.requestMethod](fullPath, async (c) => {
|
|
905
1076
|
const contextId = new ContextId();
|
|
906
|
-
const executionContext = new ExecutionContextHost([
|
|
1077
|
+
const executionContext = new ExecutionContextHost([
|
|
1078
|
+
c
|
|
1079
|
+
], controllerClass, controllerClass.prototype[route.methodName]);
|
|
907
1080
|
try {
|
|
908
1081
|
const wrapper = moduleRef.getProvider(controllerClass) || moduleRef.controllers.get(controllerClass);
|
|
909
1082
|
if (!wrapper) {
|
|
@@ -911,49 +1084,33 @@ var HonoDiApplication = class {
|
|
|
911
1084
|
}
|
|
912
1085
|
const controllerInstance = await this.injector.loadInstance(wrapper, contextId);
|
|
913
1086
|
const handler = controllerInstance[route.methodName].bind(controllerInstance);
|
|
914
|
-
const guards = await this.resolveContextItems(
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
],
|
|
920
|
-
moduleRef,
|
|
921
|
-
contextId
|
|
922
|
-
);
|
|
1087
|
+
const guards = await this.resolveContextItems([
|
|
1088
|
+
...this.globalGuards,
|
|
1089
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_GUARDS, controllerClass) || [],
|
|
1090
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_GUARDS, controllerInstance[route.methodName]) || []
|
|
1091
|
+
], moduleRef, contextId);
|
|
923
1092
|
if (!await this.runGuards(guards, executionContext)) {
|
|
924
1093
|
c.status(403);
|
|
925
|
-
return c.json({
|
|
1094
|
+
return c.json({
|
|
1095
|
+
statusCode: 403,
|
|
1096
|
+
message: "Forbidden resource"
|
|
1097
|
+
});
|
|
926
1098
|
}
|
|
927
|
-
const interceptors = await this.resolveContextItems(
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
...this.globalPipes,
|
|
939
|
-
...Reflect.getMetadata(METADATA_KEYS.USE_PIPES, controllerClass) || [],
|
|
940
|
-
...Reflect.getMetadata(METADATA_KEYS.USE_PIPES, controllerInstance[route.methodName]) || []
|
|
941
|
-
],
|
|
942
|
-
moduleRef,
|
|
943
|
-
contextId
|
|
944
|
-
);
|
|
945
|
-
const args = await this.resolveArgs(
|
|
946
|
-
contextId,
|
|
947
|
-
executionContext,
|
|
948
|
-
controllerClass,
|
|
949
|
-
route.methodName,
|
|
950
|
-
moduleRef,
|
|
951
|
-
pipes
|
|
952
|
-
);
|
|
1099
|
+
const interceptors = await this.resolveContextItems([
|
|
1100
|
+
...this.globalInterceptors,
|
|
1101
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_INTERCEPTORS, controllerClass) || [],
|
|
1102
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_INTERCEPTORS, controllerInstance[route.methodName]) || []
|
|
1103
|
+
], moduleRef, contextId);
|
|
1104
|
+
const pipes = await this.resolveContextItems([
|
|
1105
|
+
...this.globalPipes,
|
|
1106
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_PIPES, controllerClass) || [],
|
|
1107
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_PIPES, controllerInstance[route.methodName]) || []
|
|
1108
|
+
], moduleRef, contextId);
|
|
1109
|
+
const args = await this.resolveArgs(contextId, executionContext, controllerClass, route.methodName, moduleRef, pipes);
|
|
953
1110
|
if (args.length === 0 && !Reflect.hasMetadata(METADATA_KEYS.ROUTE_ARGS_METADATA, controllerClass, route.methodName)) {
|
|
954
1111
|
args.push(c);
|
|
955
1112
|
}
|
|
956
|
-
const interceptorChain = async (index) => {
|
|
1113
|
+
const interceptorChain = /* @__PURE__ */ __name(async (index) => {
|
|
957
1114
|
if (index >= interceptors.length) {
|
|
958
1115
|
return new Observable((subscriber) => {
|
|
959
1116
|
try {
|
|
@@ -973,9 +1130,9 @@ var HonoDiApplication = class {
|
|
|
973
1130
|
});
|
|
974
1131
|
}
|
|
975
1132
|
return interceptors[index].intercept(executionContext, {
|
|
976
|
-
handle: () => from(interceptorChain(index + 1)).pipe(mergeMap((obs2) => obs2))
|
|
1133
|
+
handle: /* @__PURE__ */ __name(() => from(interceptorChain(index + 1)).pipe(mergeMap((obs2) => obs2)), "handle")
|
|
977
1134
|
});
|
|
978
|
-
};
|
|
1135
|
+
}, "interceptorChain");
|
|
979
1136
|
const obs = await interceptorChain(0);
|
|
980
1137
|
const result = await lastValueFrom(obs);
|
|
981
1138
|
const httpCode = Reflect.getMetadata(METADATA_KEYS.HTTP_CODE, controllerInstance[route.methodName]);
|
|
@@ -1008,19 +1165,17 @@ var HonoDiApplication = class {
|
|
|
1008
1165
|
});
|
|
1009
1166
|
}
|
|
1010
1167
|
async handleException(exception, c, controllerClass, methodName, moduleRef, contextId) {
|
|
1011
|
-
const filters = await this.resolveContextItems(
|
|
1012
|
-
[
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
],
|
|
1017
|
-
moduleRef,
|
|
1018
|
-
contextId
|
|
1019
|
-
);
|
|
1168
|
+
const filters = await this.resolveContextItems([
|
|
1169
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_FILTERS, moduleRef.controllers.get(controllerClass)?.instance?.[methodName]) || [],
|
|
1170
|
+
...Reflect.getMetadata(METADATA_KEYS.USE_FILTERS, controllerClass) || [],
|
|
1171
|
+
...this.globalFilters
|
|
1172
|
+
], moduleRef, contextId);
|
|
1020
1173
|
for (const filter of filters) {
|
|
1021
1174
|
const catchExceptions = Reflect.getMetadata(METADATA_KEYS.FILTER_CATCH, filter.constructor) || [];
|
|
1022
1175
|
if (catchExceptions.length === 0 || catchExceptions.some((e) => exception instanceof e)) {
|
|
1023
|
-
const host = new ExecutionContextHost([
|
|
1176
|
+
const host = new ExecutionContextHost([
|
|
1177
|
+
c
|
|
1178
|
+
], controllerClass, moduleRef.controllers.get(controllerClass)?.instance?.[methodName]);
|
|
1024
1179
|
return await filter.catch(exception, host);
|
|
1025
1180
|
}
|
|
1026
1181
|
}
|
|
@@ -1052,7 +1207,7 @@ var HonoDiApplication = class {
|
|
|
1052
1207
|
name: item.name,
|
|
1053
1208
|
metatype: item,
|
|
1054
1209
|
host: moduleRef,
|
|
1055
|
-
scope:
|
|
1210
|
+
scope: Scope.TRANSIENT
|
|
1056
1211
|
});
|
|
1057
1212
|
scanner.scanDependencies(wrapper);
|
|
1058
1213
|
}
|
|
@@ -1073,19 +1228,19 @@ var HonoDiApplication = class {
|
|
|
1073
1228
|
let value;
|
|
1074
1229
|
const { index, data, pipes, paramtype } = arg;
|
|
1075
1230
|
switch (paramtype) {
|
|
1076
|
-
case
|
|
1231
|
+
case RouteParamtypes.REQUEST:
|
|
1077
1232
|
value = c.req;
|
|
1078
1233
|
break;
|
|
1079
|
-
case
|
|
1234
|
+
case RouteParamtypes.RESPONSE:
|
|
1080
1235
|
value = c;
|
|
1081
1236
|
break;
|
|
1082
|
-
case
|
|
1237
|
+
case RouteParamtypes.NEXT:
|
|
1083
1238
|
value = context.getArgs()[1];
|
|
1084
1239
|
break;
|
|
1085
|
-
case
|
|
1240
|
+
case RouteParamtypes.CONTEXT:
|
|
1086
1241
|
value = c;
|
|
1087
1242
|
break;
|
|
1088
|
-
case
|
|
1243
|
+
case RouteParamtypes.BODY:
|
|
1089
1244
|
if (data && c.req.parseBody) {
|
|
1090
1245
|
const body = await c.req.parseBody();
|
|
1091
1246
|
value = body[data];
|
|
@@ -1098,19 +1253,19 @@ var HonoDiApplication = class {
|
|
|
1098
1253
|
}
|
|
1099
1254
|
}
|
|
1100
1255
|
break;
|
|
1101
|
-
case
|
|
1256
|
+
case RouteParamtypes.QUERY:
|
|
1102
1257
|
value = data ? c.req.query(data) : c.req.query();
|
|
1103
1258
|
break;
|
|
1104
|
-
case
|
|
1259
|
+
case RouteParamtypes.PARAM:
|
|
1105
1260
|
value = data ? c.req.param(data) : c.req.param();
|
|
1106
1261
|
break;
|
|
1107
|
-
case
|
|
1262
|
+
case RouteParamtypes.HEADERS:
|
|
1108
1263
|
value = data ? c.req.header(data) : c.req.header();
|
|
1109
1264
|
break;
|
|
1110
|
-
case
|
|
1265
|
+
case RouteParamtypes.IP:
|
|
1111
1266
|
value = c.req.header("x-forwarded-for") || "127.0.0.1";
|
|
1112
1267
|
break;
|
|
1113
|
-
case
|
|
1268
|
+
case RouteParamtypes.CUSTOM:
|
|
1114
1269
|
const factory = arg.pipes[0];
|
|
1115
1270
|
if (typeof factory === "function") {
|
|
1116
1271
|
value = factory(data, context);
|
|
@@ -1120,9 +1275,16 @@ var HonoDiApplication = class {
|
|
|
1120
1275
|
value = null;
|
|
1121
1276
|
}
|
|
1122
1277
|
const paramPipeInstances = await this.resolveContextItems(pipes || [], moduleRef, contextId);
|
|
1123
|
-
const allPipes = [
|
|
1278
|
+
const allPipes = [
|
|
1279
|
+
...methodPipes,
|
|
1280
|
+
...paramPipeInstances
|
|
1281
|
+
];
|
|
1124
1282
|
for (const pipe of allPipes) {
|
|
1125
|
-
value = await pipe.transform(value, {
|
|
1283
|
+
value = await pipe.transform(value, {
|
|
1284
|
+
type: "custom",
|
|
1285
|
+
metatype: null,
|
|
1286
|
+
data
|
|
1287
|
+
});
|
|
1126
1288
|
}
|
|
1127
1289
|
args[index] = value;
|
|
1128
1290
|
}
|
|
@@ -1160,7 +1322,7 @@ var HonoDiApplication = class {
|
|
|
1160
1322
|
token: m,
|
|
1161
1323
|
name: m.name,
|
|
1162
1324
|
metatype: m,
|
|
1163
|
-
scope:
|
|
1325
|
+
scope: Scope.TRANSIENT
|
|
1164
1326
|
});
|
|
1165
1327
|
const scanner = new HonoDiScanner(this.container);
|
|
1166
1328
|
scanner.scanDependencies(wrapper);
|
|
@@ -1170,7 +1332,10 @@ var HonoDiApplication = class {
|
|
|
1170
1332
|
instances.push(instance);
|
|
1171
1333
|
}
|
|
1172
1334
|
}
|
|
1173
|
-
resolvedConfigs.push({
|
|
1335
|
+
resolvedConfigs.push({
|
|
1336
|
+
...config,
|
|
1337
|
+
instances
|
|
1338
|
+
});
|
|
1174
1339
|
}
|
|
1175
1340
|
this.app.use("*", async (c, next) => {
|
|
1176
1341
|
const path = c.req.path;
|
|
@@ -1185,14 +1350,14 @@ var HonoDiApplication = class {
|
|
|
1185
1350
|
if (matchingMiddleware.length === 0) {
|
|
1186
1351
|
return await next();
|
|
1187
1352
|
}
|
|
1188
|
-
const executeChain = async (index, finalNext) => {
|
|
1353
|
+
const executeChain = /* @__PURE__ */ __name(async (index, finalNext) => {
|
|
1189
1354
|
if (index >= matchingMiddleware.length) {
|
|
1190
1355
|
return await finalNext();
|
|
1191
1356
|
}
|
|
1192
1357
|
const middleware = matchingMiddleware[index];
|
|
1193
1358
|
return new Promise((resolve, reject) => {
|
|
1194
1359
|
let nextCalled = false;
|
|
1195
|
-
const nextFn = async () => {
|
|
1360
|
+
const nextFn = /* @__PURE__ */ __name(async () => {
|
|
1196
1361
|
nextCalled = true;
|
|
1197
1362
|
try {
|
|
1198
1363
|
await executeChain(index + 1, finalNext);
|
|
@@ -1200,7 +1365,7 @@ var HonoDiApplication = class {
|
|
|
1200
1365
|
} catch (e) {
|
|
1201
1366
|
reject(e);
|
|
1202
1367
|
}
|
|
1203
|
-
};
|
|
1368
|
+
}, "nextFn");
|
|
1204
1369
|
try {
|
|
1205
1370
|
const useFn = middleware.use ? middleware.use.bind(middleware) : middleware;
|
|
1206
1371
|
const result = useFn(c, nextFn);
|
|
@@ -1215,7 +1380,7 @@ var HonoDiApplication = class {
|
|
|
1215
1380
|
reject(e);
|
|
1216
1381
|
}
|
|
1217
1382
|
});
|
|
1218
|
-
};
|
|
1383
|
+
}, "executeChain");
|
|
1219
1384
|
await executeChain(0, next);
|
|
1220
1385
|
});
|
|
1221
1386
|
}
|
|
@@ -1226,7 +1391,7 @@ var HonoDiApplication = class {
|
|
|
1226
1391
|
if (normalizedRoute === "*" || path.startsWith(normalizedRoute)) return true;
|
|
1227
1392
|
if (path === normalizedRoute) return true;
|
|
1228
1393
|
} else if (typeof route === "object" && route.path && route.method) {
|
|
1229
|
-
if (route.method !== -1 && route.method !==
|
|
1394
|
+
if (route.method !== -1 && route.method !== RequestMethod.ALL && route.method !== method.toLowerCase()) {
|
|
1230
1395
|
continue;
|
|
1231
1396
|
}
|
|
1232
1397
|
if (route.path === "*" || path === route.path) return true;
|
|
@@ -1283,6 +1448,9 @@ var HonoDiApplication = class {
|
|
|
1283
1448
|
|
|
1284
1449
|
// src/factory.ts
|
|
1285
1450
|
var HonoDiFactory = class {
|
|
1451
|
+
static {
|
|
1452
|
+
__name(this, "HonoDiFactory");
|
|
1453
|
+
}
|
|
1286
1454
|
static logger = new Logger("HonoDiFactory");
|
|
1287
1455
|
static async create(rootModule, appOrOptions) {
|
|
1288
1456
|
let app;
|
|
@@ -1317,12 +1485,12 @@ var HonoDiFactory = class {
|
|
|
1317
1485
|
const globalContextId = new ContextId();
|
|
1318
1486
|
for (const module of modules.values()) {
|
|
1319
1487
|
for (const wrapper of module.providers.values()) {
|
|
1320
|
-
if (wrapper.scope ===
|
|
1488
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
1321
1489
|
await injector.loadInstance(wrapper, globalContextId);
|
|
1322
1490
|
}
|
|
1323
1491
|
}
|
|
1324
1492
|
for (const wrapper of module.controllers.values()) {
|
|
1325
|
-
if (wrapper.scope ===
|
|
1493
|
+
if (wrapper.scope === Scope.DEFAULT) {
|
|
1326
1494
|
await injector.loadInstance(wrapper, globalContextId);
|
|
1327
1495
|
}
|
|
1328
1496
|
}
|
|
@@ -1347,11 +1515,24 @@ var HonoDiFactory = class {
|
|
|
1347
1515
|
|
|
1348
1516
|
// src/utils.ts
|
|
1349
1517
|
function forwardRef(fn) {
|
|
1350
|
-
return {
|
|
1518
|
+
return {
|
|
1519
|
+
forwardRef: fn
|
|
1520
|
+
};
|
|
1351
1521
|
}
|
|
1522
|
+
__name(forwardRef, "forwardRef");
|
|
1352
1523
|
|
|
1353
1524
|
// src/services/reflector.service.ts
|
|
1525
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1526
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1527
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1528
|
+
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;
|
|
1529
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1530
|
+
}
|
|
1531
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
1354
1532
|
var Reflector = class {
|
|
1533
|
+
static {
|
|
1534
|
+
__name(this, "Reflector");
|
|
1535
|
+
}
|
|
1355
1536
|
get(metadataKey, target) {
|
|
1356
1537
|
return Reflect.getMetadata(metadataKey, target);
|
|
1357
1538
|
}
|
|
@@ -1379,12 +1560,22 @@ var Reflector = class {
|
|
|
1379
1560
|
return result;
|
|
1380
1561
|
}
|
|
1381
1562
|
};
|
|
1382
|
-
Reflector =
|
|
1563
|
+
Reflector = _ts_decorate([
|
|
1383
1564
|
Injectable()
|
|
1384
1565
|
], Reflector);
|
|
1385
1566
|
|
|
1386
1567
|
// src/common/pipes/index.ts
|
|
1568
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1569
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1570
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1571
|
+
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;
|
|
1572
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1573
|
+
}
|
|
1574
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
1387
1575
|
var ParseIntPipe = class {
|
|
1576
|
+
static {
|
|
1577
|
+
__name(this, "ParseIntPipe");
|
|
1578
|
+
}
|
|
1388
1579
|
transform(value, metadata) {
|
|
1389
1580
|
const isNumeric = !isNaN(parseFloat(value)) && isFinite(value);
|
|
1390
1581
|
if (!isNumeric) {
|
|
@@ -1393,10 +1584,13 @@ var ParseIntPipe = class {
|
|
|
1393
1584
|
return parseInt(value, 10);
|
|
1394
1585
|
}
|
|
1395
1586
|
};
|
|
1396
|
-
ParseIntPipe =
|
|
1587
|
+
ParseIntPipe = _ts_decorate2([
|
|
1397
1588
|
Injectable()
|
|
1398
1589
|
], ParseIntPipe);
|
|
1399
1590
|
var ParseFloatPipe = class {
|
|
1591
|
+
static {
|
|
1592
|
+
__name(this, "ParseFloatPipe");
|
|
1593
|
+
}
|
|
1400
1594
|
transform(value, metadata) {
|
|
1401
1595
|
const isNumeric = !isNaN(parseFloat(value)) && isFinite(value);
|
|
1402
1596
|
if (!isNumeric) {
|
|
@@ -1405,10 +1599,13 @@ var ParseFloatPipe = class {
|
|
|
1405
1599
|
return parseFloat(value);
|
|
1406
1600
|
}
|
|
1407
1601
|
};
|
|
1408
|
-
ParseFloatPipe =
|
|
1602
|
+
ParseFloatPipe = _ts_decorate2([
|
|
1409
1603
|
Injectable()
|
|
1410
1604
|
], ParseFloatPipe);
|
|
1411
1605
|
var ParseBoolPipe = class {
|
|
1606
|
+
static {
|
|
1607
|
+
__name(this, "ParseBoolPipe");
|
|
1608
|
+
}
|
|
1412
1609
|
transform(value, metadata) {
|
|
1413
1610
|
if (value === true || value === "true") {
|
|
1414
1611
|
return true;
|
|
@@ -1419,50 +1616,71 @@ var ParseBoolPipe = class {
|
|
|
1419
1616
|
throw new BadRequestException("Validation failed (boolean string is expected)");
|
|
1420
1617
|
}
|
|
1421
1618
|
};
|
|
1422
|
-
ParseBoolPipe =
|
|
1619
|
+
ParseBoolPipe = _ts_decorate2([
|
|
1423
1620
|
Injectable()
|
|
1424
1621
|
], ParseBoolPipe);
|
|
1425
1622
|
var ValidationPipe = class {
|
|
1623
|
+
static {
|
|
1624
|
+
__name(this, "ValidationPipe");
|
|
1625
|
+
}
|
|
1426
1626
|
transform(value, metadata) {
|
|
1427
1627
|
return value;
|
|
1428
1628
|
}
|
|
1429
1629
|
};
|
|
1430
|
-
ValidationPipe =
|
|
1630
|
+
ValidationPipe = _ts_decorate2([
|
|
1431
1631
|
Injectable()
|
|
1432
1632
|
], ValidationPipe);
|
|
1433
1633
|
|
|
1434
1634
|
// src/common/errors/AppError.ts
|
|
1435
1635
|
var AppError = class _AppError extends Error {
|
|
1636
|
+
static {
|
|
1637
|
+
__name(this, "AppError");
|
|
1638
|
+
}
|
|
1639
|
+
statusCode;
|
|
1640
|
+
message;
|
|
1641
|
+
isOperational;
|
|
1436
1642
|
constructor(statusCode, message, isOperational = true) {
|
|
1437
|
-
super(message);
|
|
1438
|
-
this.statusCode = statusCode;
|
|
1439
|
-
this.message = message;
|
|
1440
|
-
this.isOperational = isOperational;
|
|
1643
|
+
super(message), this.statusCode = statusCode, this.message = message, this.isOperational = isOperational;
|
|
1441
1644
|
Object.setPrototypeOf(this, _AppError.prototype);
|
|
1442
1645
|
Error.captureStackTrace(this, this.constructor);
|
|
1443
1646
|
}
|
|
1444
1647
|
};
|
|
1445
1648
|
var NotFoundError = class extends AppError {
|
|
1649
|
+
static {
|
|
1650
|
+
__name(this, "NotFoundError");
|
|
1651
|
+
}
|
|
1446
1652
|
constructor(message = "Resource not found") {
|
|
1447
1653
|
super(404, message);
|
|
1448
1654
|
}
|
|
1449
1655
|
};
|
|
1450
1656
|
var BadRequestError = class extends AppError {
|
|
1657
|
+
static {
|
|
1658
|
+
__name(this, "BadRequestError");
|
|
1659
|
+
}
|
|
1451
1660
|
constructor(message = "Bad request") {
|
|
1452
1661
|
super(400, message);
|
|
1453
1662
|
}
|
|
1454
1663
|
};
|
|
1455
1664
|
var UnauthorizedError = class extends AppError {
|
|
1665
|
+
static {
|
|
1666
|
+
__name(this, "UnauthorizedError");
|
|
1667
|
+
}
|
|
1456
1668
|
constructor(message = "Unauthorized") {
|
|
1457
1669
|
super(401, message);
|
|
1458
1670
|
}
|
|
1459
1671
|
};
|
|
1460
1672
|
var ForbiddenError = class extends AppError {
|
|
1673
|
+
static {
|
|
1674
|
+
__name(this, "ForbiddenError");
|
|
1675
|
+
}
|
|
1461
1676
|
constructor(message = "Forbidden") {
|
|
1462
1677
|
super(403, message);
|
|
1463
1678
|
}
|
|
1464
1679
|
};
|
|
1465
1680
|
var ConflictError = class extends AppError {
|
|
1681
|
+
static {
|
|
1682
|
+
__name(this, "ConflictError");
|
|
1683
|
+
}
|
|
1466
1684
|
constructor(message = "Resource already exists") {
|
|
1467
1685
|
super(409, message);
|
|
1468
1686
|
}
|
|
@@ -1470,10 +1688,13 @@ var ConflictError = class extends AppError {
|
|
|
1470
1688
|
|
|
1471
1689
|
// src/common/exceptions/HttpException.ts
|
|
1472
1690
|
var HttpException2 = class extends Error {
|
|
1691
|
+
static {
|
|
1692
|
+
__name(this, "HttpException");
|
|
1693
|
+
}
|
|
1694
|
+
response;
|
|
1695
|
+
status;
|
|
1473
1696
|
constructor(response, status) {
|
|
1474
|
-
super();
|
|
1475
|
-
this.response = response;
|
|
1476
|
-
this.status = status;
|
|
1697
|
+
super(), this.response = response, this.status = status;
|
|
1477
1698
|
this.message = typeof response === "string" ? response : JSON.stringify(response);
|
|
1478
1699
|
}
|
|
1479
1700
|
getResponse() {
|
|
@@ -1484,14 +1705,31 @@ var HttpException2 = class extends Error {
|
|
|
1484
1705
|
}
|
|
1485
1706
|
static createBody(message, error, statusCode) {
|
|
1486
1707
|
if (!message) {
|
|
1487
|
-
return {
|
|
1708
|
+
return {
|
|
1709
|
+
statusCode,
|
|
1710
|
+
error
|
|
1711
|
+
};
|
|
1488
1712
|
}
|
|
1489
|
-
return typeof message === "object" && !Array.isArray(message) ? message : {
|
|
1713
|
+
return typeof message === "object" && !Array.isArray(message) ? message : {
|
|
1714
|
+
statusCode,
|
|
1715
|
+
error,
|
|
1716
|
+
message
|
|
1717
|
+
};
|
|
1490
1718
|
}
|
|
1491
1719
|
};
|
|
1492
1720
|
|
|
1493
1721
|
// src/common/filters/BaseExceptionFilter.ts
|
|
1722
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
1723
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1724
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1725
|
+
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;
|
|
1726
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1727
|
+
}
|
|
1728
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
1494
1729
|
var BaseExceptionFilter = class {
|
|
1730
|
+
static {
|
|
1731
|
+
__name(this, "BaseExceptionFilter");
|
|
1732
|
+
}
|
|
1495
1733
|
catch(exception, host) {
|
|
1496
1734
|
const ctx = host.switchToHttp();
|
|
1497
1735
|
ctx.getResponse();
|
|
@@ -1510,7 +1748,7 @@ var BaseExceptionFilter = class {
|
|
|
1510
1748
|
});
|
|
1511
1749
|
}
|
|
1512
1750
|
};
|
|
1513
|
-
BaseExceptionFilter =
|
|
1751
|
+
BaseExceptionFilter = _ts_decorate3([
|
|
1514
1752
|
Catch()
|
|
1515
1753
|
], BaseExceptionFilter);
|
|
1516
1754
|
|