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