@stacksjs/bun-router 0.0.15 → 0.0.17
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/auth.d.ts +22 -8
- package/dist/chunk-1ahs68ys.js +18 -0
- package/dist/{chunk-j0e7z7hd.js → chunk-cgptvjdf.js} +153 -75
- package/dist/chunk-g3ybefhg.js +1923 -0
- package/dist/cli.js +13 -11
- package/dist/container/container.d.ts +1 -0
- package/dist/container/contextual-binding.d.ts +0 -1
- package/dist/container/decorators.d.ts +2 -5
- package/dist/container/index.d.ts +16 -0
- package/dist/container/index.js +322 -0
- package/dist/file-serving/static-files.d.ts +16 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +1086 -1270
- package/dist/middleware/cors.d.ts +9 -0
- package/dist/middleware/csrf.d.ts +7 -0
- package/dist/middleware/ddos_protection.d.ts +16 -1
- package/dist/middleware/rate_limit.d.ts +7 -1
- package/dist/middleware/request_tracer.d.ts +15 -9
- package/dist/middleware/response_cache.d.ts +2 -1
- package/dist/request/context.d.ts +12 -1
- package/dist/request/macros.d.ts +40 -2
- package/dist/response/macros.d.ts +3 -3
- package/dist/router/fluent-routing.d.ts +50 -13
- package/dist/router/handler-resolver.d.ts +8 -0
- package/dist/router/index.d.ts +2 -0
- package/dist/router/route-compiler.d.ts +8 -10
- package/dist/router/route-trie.d.ts +7 -1
- package/dist/router/router.d.ts +13 -2
- package/dist/router/validation-integration.d.ts +10 -4
- package/dist/types/middleware-types.d.ts +1 -1
- package/dist/types/route-inference.d.ts +9 -2
- package/dist/types.d.ts +62 -9
- package/dist/utils.d.ts +1 -1
- package/package.json +11 -1
- package/src/auth.ts +32 -12
- package/src/container/container.ts +58 -12
- package/src/container/contextual-binding.ts +4 -1
- package/src/container/decorators.ts +16 -7
- package/src/container/index.ts +49 -0
- package/src/errors/circuit-breaker.ts +3 -2
- package/src/errors/graceful-degradation.ts +2 -0
- package/src/file-serving/static-files.ts +144 -7
- package/src/index.ts +53 -1
- package/src/middleware/cors.ts +76 -8
- package/src/middleware/csrf.ts +80 -22
- package/src/middleware/ddos_protection.ts +27 -3
- package/src/middleware/input_validation.ts +10 -6
- package/src/middleware/performance_alerting.ts +2 -0
- package/src/middleware/performance_monitor.ts +2 -0
- package/src/middleware/rate_limit.ts +7 -1
- package/src/middleware/request_signing.ts +2 -0
- package/src/middleware/request_tracer.ts +34 -17
- package/src/middleware/response_cache.ts +48 -13
- package/src/middleware/session.ts +3 -3
- package/src/observability/metrics.ts +1 -1
- package/src/request/context.ts +50 -3
- package/src/request/enhanced-request.ts +20 -1
- package/src/request/macros.ts +183 -49
- package/src/response/macros.ts +3 -3
- package/src/router/file-based-routing.ts +17 -10
- package/src/router/fluent-routing.ts +117 -48
- package/src/router/group-organization.ts +17 -1
- package/src/router/handler-resolver.ts +36 -0
- package/src/router/http-methods.ts +33 -3
- package/src/router/index.ts +6 -0
- package/src/router/middleware.ts +3 -0
- package/src/router/optimized-route-matching.ts +58 -9
- package/src/router/route-compiler.ts +62 -73
- package/src/router/route-matching.ts +19 -0
- package/src/router/route-trie.ts +34 -48
- package/src/router/router.ts +72 -60
- package/src/router/server.ts +361 -139
- package/src/router/validation-integration.ts +11 -5
- package/src/testing/auth-testing.ts +6 -4
- package/src/types/middleware-types.ts +7 -4
- package/src/types/route-inference.ts +29 -14
- package/src/types.ts +63 -7
- package/src/url.ts +7 -2
- package/src/utils.ts +107 -39
- package/src/validation/validator.ts +7 -4
- package/src/websocket/clustering.ts +8 -1
- package/dist/router/fluent-router.d.ts +0 -315
- package/src/router/fluent-router.ts +0 -927
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
middleware
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-cgptvjdf.js";
|
|
5
|
+
import"./chunk-1ahs68ys.js";
|
|
5
6
|
|
|
6
7
|
// src/cli/index.ts
|
|
7
8
|
import process15 from "process";
|
|
@@ -572,11 +573,9 @@ class Command {
|
|
|
572
573
|
isMatched(name) {
|
|
573
574
|
if (this.aliasNames.includes(name))
|
|
574
575
|
return true;
|
|
575
|
-
if (this.
|
|
576
|
-
return
|
|
577
|
-
|
|
578
|
-
return true;
|
|
579
|
-
return false;
|
|
576
|
+
if (this.namespace)
|
|
577
|
+
return `${this.namespace}:${this.name}` === name;
|
|
578
|
+
return this.name === name;
|
|
580
579
|
}
|
|
581
580
|
get isDefaultCommand() {
|
|
582
581
|
return this.name === "" || this.aliasNames.includes("!");
|
|
@@ -584,6 +583,9 @@ class Command {
|
|
|
584
583
|
get isGlobalCommand() {
|
|
585
584
|
return this instanceof GlobalCommand;
|
|
586
585
|
}
|
|
586
|
+
get displayName() {
|
|
587
|
+
return this.namespace ? `${this.namespace}:${this.name}` : this.name;
|
|
588
|
+
}
|
|
587
589
|
hasOption(name) {
|
|
588
590
|
name = name.split(".")[0];
|
|
589
591
|
return !!this.options.find((option) => {
|
|
@@ -649,7 +651,7 @@ class Command {
|
|
|
649
651
|
});
|
|
650
652
|
sections.push({
|
|
651
653
|
title: `For more info, run any command with the \`--help\` flag`,
|
|
652
|
-
body: commands.map((command) => ` $ ${name}${command.
|
|
654
|
+
body: commands.map((command) => ` $ ${name}${command.displayName === "" ? "" : ` ${command.displayName}`} --help`).join(`
|
|
653
655
|
`)
|
|
654
656
|
});
|
|
655
657
|
}
|
|
@@ -1004,8 +1006,8 @@ Received ${signal}, cleaning up...`);
|
|
|
1004
1006
|
if (this.enableDidYouMean) {
|
|
1005
1007
|
const allCommandNames = [];
|
|
1006
1008
|
for (const command of this.commands) {
|
|
1007
|
-
if (command.
|
|
1008
|
-
allCommandNames.push(command.
|
|
1009
|
+
if (command.displayName) {
|
|
1010
|
+
allCommandNames.push(command.displayName);
|
|
1009
1011
|
}
|
|
1010
1012
|
if (command.aliasNames) {
|
|
1011
1013
|
allCommandNames.push(...command.aliasNames);
|
|
@@ -1961,7 +1963,7 @@ class GroupMultiSelectPrompt extends Prompt {
|
|
|
1961
1963
|
this.value = [];
|
|
1962
1964
|
}
|
|
1963
1965
|
if (item.group === true) {
|
|
1964
|
-
const group = item.value;
|
|
1966
|
+
const group = String(item.value);
|
|
1965
1967
|
const groupedItems = this.getGroupItems(group);
|
|
1966
1968
|
if (this.isGroupSelected(group)) {
|
|
1967
1969
|
this.value = this.value.filter((v) => groupedItems.findIndex((i) => i.value === v) === -1);
|
|
@@ -2044,7 +2046,7 @@ function getPrefix() {
|
|
|
2044
2046
|
}
|
|
2045
2047
|
var prefix = getPrefix();
|
|
2046
2048
|
// package.json
|
|
2047
|
-
var version = "0.0.
|
|
2049
|
+
var version = "0.0.17";
|
|
2048
2050
|
|
|
2049
2051
|
// src/cli/middleware.ts
|
|
2050
2052
|
import fs2 from "fs/promises";
|
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
* Modern Dependency Injection Decorators
|
|
3
3
|
*/
|
|
4
4
|
import type { ResolutionContext } from './container';
|
|
5
|
-
import { Container } from './container';
|
|
6
|
-
export
|
|
7
|
-
export declare const INJECT_METADATA_KEY: unique symbol;
|
|
8
|
-
export declare const OPTIONAL_METADATA_KEY: unique symbol;
|
|
9
|
-
export declare const TAGGED_METADATA_KEY: unique symbol;
|
|
5
|
+
import { Container, INJECT_METADATA_KEY, INJECTABLE_METADATA_KEY, OPTIONAL_METADATA_KEY, TAGGED_METADATA_KEY } from './container';
|
|
6
|
+
export { INJECT_METADATA_KEY, INJECTABLE_METADATA_KEY, OPTIONAL_METADATA_KEY, TAGGED_METADATA_KEY };
|
|
10
7
|
export declare const CONTROLLER_METADATA_KEY: unique symbol;
|
|
11
8
|
export declare const ROUTE_METADATA_KEY: unique symbol;
|
|
12
9
|
export declare const MIDDLEWARE_METADATA_KEY: unique symbol;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency-injection container — public entry point.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { Container, createContainer, Inject, Injectable } from '@stacksjs/bun-router/container'
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* The core `Container` (and a few companions) are also re-exported from the
|
|
9
|
+
* package root; the decorators live only here because their names (`Get`,
|
|
10
|
+
* `Post`, `Controller`, …) would collide with the router's exports.
|
|
11
|
+
*/
|
|
12
|
+
export * from './container';
|
|
13
|
+
export { Body, Controller, CONTROLLER_METADATA_KEY, Cookie, decoratorContainer, DecoratorContainer, Delete, Get, Head, Header, Inject, Injectable, InjectParam, MetadataReader, MIDDLEWARE_METADATA_KEY, Optional, Options, Param, PARAM_METADATA_KEY, Patch, Post, Put, Query, ROUTE_METADATA_KEY, Tagged, UseMiddleware, } from './decorators';
|
|
14
|
+
export type { ControllerMetadata, ParamMetadata, RouteMetadata } from './decorators';
|
|
15
|
+
export * from './contextual-binding';
|
|
16
|
+
export * from './service-provider';
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
AuthGuard,
|
|
4
|
+
AuthService,
|
|
5
|
+
AuthServiceProvider,
|
|
6
|
+
BaseDeferredServiceProvider,
|
|
7
|
+
BaseServiceProvider,
|
|
8
|
+
BindingBuilder,
|
|
9
|
+
BindingConditions,
|
|
10
|
+
CacheManager,
|
|
11
|
+
CacheServiceProvider,
|
|
12
|
+
ConfigService,
|
|
13
|
+
ConfigServiceProvider,
|
|
14
|
+
ConsoleLogger,
|
|
15
|
+
Container,
|
|
16
|
+
ContextualContainer,
|
|
17
|
+
DatabaseConnection,
|
|
18
|
+
DatabaseServiceProvider,
|
|
19
|
+
DefaultContextualBindingBuilder,
|
|
20
|
+
DefaultServiceProviderManager,
|
|
21
|
+
EnvironmentManager,
|
|
22
|
+
EnvironmentPresets,
|
|
23
|
+
EventBus,
|
|
24
|
+
EventDispatcher,
|
|
25
|
+
EventServiceProvider,
|
|
26
|
+
FileLogger,
|
|
27
|
+
INJECTABLE_METADATA_KEY,
|
|
28
|
+
INJECT_METADATA_KEY,
|
|
29
|
+
JwtService,
|
|
30
|
+
Logger,
|
|
31
|
+
LoggingServiceProvider,
|
|
32
|
+
MemoryCache,
|
|
33
|
+
OPTIONAL_METADATA_KEY,
|
|
34
|
+
PostRepository,
|
|
35
|
+
RedisCache,
|
|
36
|
+
TAGGED_METADATA_KEY,
|
|
37
|
+
UserRepository,
|
|
38
|
+
ValidationPipe,
|
|
39
|
+
ValidationServiceProvider,
|
|
40
|
+
Validator,
|
|
41
|
+
createContainer,
|
|
42
|
+
getContainer,
|
|
43
|
+
setContainer
|
|
44
|
+
} from "../chunk-g3ybefhg.js";
|
|
45
|
+
import"../chunk-1ahs68ys.js";
|
|
46
|
+
// src/container/decorators.ts
|
|
47
|
+
var CONTROLLER_METADATA_KEY = Symbol("controller");
|
|
48
|
+
var ROUTE_METADATA_KEY = Symbol("route");
|
|
49
|
+
var MIDDLEWARE_METADATA_KEY = Symbol("middleware");
|
|
50
|
+
var PARAM_METADATA_KEY = Symbol("param");
|
|
51
|
+
function Injectable(metadata = {}) {
|
|
52
|
+
return (target) => {
|
|
53
|
+
target[INJECTABLE_METADATA_KEY] = metadata;
|
|
54
|
+
return target;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function Inject(token, options) {
|
|
58
|
+
return function(target, _propertyKey, parameterIndex) {
|
|
59
|
+
const classConstructor = target.constructor === Function ? target : target.constructor;
|
|
60
|
+
if (!classConstructor[INJECT_METADATA_KEY]) {
|
|
61
|
+
classConstructor[INJECT_METADATA_KEY] = [];
|
|
62
|
+
}
|
|
63
|
+
const metadata = {
|
|
64
|
+
token,
|
|
65
|
+
optional: options?.optional,
|
|
66
|
+
tags: options?.tags,
|
|
67
|
+
when: options?.when
|
|
68
|
+
};
|
|
69
|
+
classConstructor[INJECT_METADATA_KEY][parameterIndex] = metadata;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function Optional() {
|
|
73
|
+
return (target, _propertyKey, parameterIndex) => {
|
|
74
|
+
if (!target[OPTIONAL_METADATA_KEY]) {
|
|
75
|
+
target[OPTIONAL_METADATA_KEY] = [];
|
|
76
|
+
}
|
|
77
|
+
target[OPTIONAL_METADATA_KEY][parameterIndex] = true;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function Tagged(tag) {
|
|
81
|
+
return function(target, _propertyKey, parameterIndex) {
|
|
82
|
+
if (!target[TAGGED_METADATA_KEY]) {
|
|
83
|
+
target[TAGGED_METADATA_KEY] = [];
|
|
84
|
+
}
|
|
85
|
+
target[TAGGED_METADATA_KEY][parameterIndex] = tag;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function Controller(prefix, options) {
|
|
89
|
+
return function(target) {
|
|
90
|
+
const metadata = {
|
|
91
|
+
prefix: prefix || "",
|
|
92
|
+
middleware: options?.middleware || [],
|
|
93
|
+
tags: options?.tags || []
|
|
94
|
+
};
|
|
95
|
+
target[CONTROLLER_METADATA_KEY] = metadata;
|
|
96
|
+
return target;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function Get(path = "", options) {
|
|
100
|
+
return createRouteDecorator("GET", path, options);
|
|
101
|
+
}
|
|
102
|
+
function Post(path = "", options) {
|
|
103
|
+
return createRouteDecorator("POST", path, options);
|
|
104
|
+
}
|
|
105
|
+
function Put(path = "", options) {
|
|
106
|
+
return createRouteDecorator("PUT", path, options);
|
|
107
|
+
}
|
|
108
|
+
function Delete(path = "", options) {
|
|
109
|
+
return createRouteDecorator("DELETE", path, options);
|
|
110
|
+
}
|
|
111
|
+
function Patch(path = "", options) {
|
|
112
|
+
return createRouteDecorator("PATCH", path, options);
|
|
113
|
+
}
|
|
114
|
+
function Options(path = "", options) {
|
|
115
|
+
return createRouteDecorator("OPTIONS", path, options);
|
|
116
|
+
}
|
|
117
|
+
function Head(path = "", options) {
|
|
118
|
+
return createRouteDecorator("HEAD", path, options);
|
|
119
|
+
}
|
|
120
|
+
function createRouteDecorator(method, path, options) {
|
|
121
|
+
return function(target, propertyKey, descriptor) {
|
|
122
|
+
if (!target.constructor[ROUTE_METADATA_KEY]) {
|
|
123
|
+
target.constructor[ROUTE_METADATA_KEY] = [];
|
|
124
|
+
}
|
|
125
|
+
const metadata = {
|
|
126
|
+
method,
|
|
127
|
+
path,
|
|
128
|
+
middleware: options?.middleware || [],
|
|
129
|
+
tags: options?.tags || []
|
|
130
|
+
};
|
|
131
|
+
target.constructor[ROUTE_METADATA_KEY].push({
|
|
132
|
+
...metadata,
|
|
133
|
+
propertyKey,
|
|
134
|
+
handler: descriptor.value
|
|
135
|
+
});
|
|
136
|
+
return descriptor;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function UseMiddleware(...middleware) {
|
|
140
|
+
return function(target, propertyKey, descriptor) {
|
|
141
|
+
if (propertyKey && descriptor) {
|
|
142
|
+
if (!target.constructor[MIDDLEWARE_METADATA_KEY]) {
|
|
143
|
+
target.constructor[MIDDLEWARE_METADATA_KEY] = new Map;
|
|
144
|
+
}
|
|
145
|
+
target.constructor[MIDDLEWARE_METADATA_KEY].set(propertyKey, middleware);
|
|
146
|
+
} else {
|
|
147
|
+
target[MIDDLEWARE_METADATA_KEY] = middleware;
|
|
148
|
+
}
|
|
149
|
+
return descriptor || target;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function Param(key) {
|
|
153
|
+
return createParamDecorator("param", key);
|
|
154
|
+
}
|
|
155
|
+
function Query(key) {
|
|
156
|
+
return createParamDecorator("query", key);
|
|
157
|
+
}
|
|
158
|
+
function Body() {
|
|
159
|
+
return createParamDecorator("body");
|
|
160
|
+
}
|
|
161
|
+
function Header(key) {
|
|
162
|
+
return createParamDecorator("header", key);
|
|
163
|
+
}
|
|
164
|
+
function Cookie(key) {
|
|
165
|
+
return createParamDecorator("cookie", key);
|
|
166
|
+
}
|
|
167
|
+
function InjectParam(token) {
|
|
168
|
+
return createParamDecorator("param", undefined, token);
|
|
169
|
+
}
|
|
170
|
+
function createParamDecorator(type, key, token) {
|
|
171
|
+
return function(target, propertyKey, parameterIndex) {
|
|
172
|
+
if (!target.constructor[PARAM_METADATA_KEY]) {
|
|
173
|
+
target.constructor[PARAM_METADATA_KEY] = new Map;
|
|
174
|
+
}
|
|
175
|
+
if (!target.constructor[PARAM_METADATA_KEY].has(propertyKey)) {
|
|
176
|
+
target.constructor[PARAM_METADATA_KEY].set(propertyKey, []);
|
|
177
|
+
}
|
|
178
|
+
const metadata = {
|
|
179
|
+
type,
|
|
180
|
+
key,
|
|
181
|
+
token
|
|
182
|
+
};
|
|
183
|
+
target.constructor[PARAM_METADATA_KEY].get(propertyKey)[parameterIndex] = metadata;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
class MetadataReader {
|
|
188
|
+
static getInjectableMetadata(target) {
|
|
189
|
+
return target[INJECTABLE_METADATA_KEY];
|
|
190
|
+
}
|
|
191
|
+
static getInjectMetadata(target) {
|
|
192
|
+
return target[INJECT_METADATA_KEY] || [];
|
|
193
|
+
}
|
|
194
|
+
static getOptionalMetadata(target) {
|
|
195
|
+
return target[OPTIONAL_METADATA_KEY] || [];
|
|
196
|
+
}
|
|
197
|
+
static getTaggedMetadata(target) {
|
|
198
|
+
return target[TAGGED_METADATA_KEY] || [];
|
|
199
|
+
}
|
|
200
|
+
static getControllerMetadata(target) {
|
|
201
|
+
return target[CONTROLLER_METADATA_KEY];
|
|
202
|
+
}
|
|
203
|
+
static getAllRoutes(target) {
|
|
204
|
+
return target[ROUTE_METADATA_KEY] || [];
|
|
205
|
+
}
|
|
206
|
+
static getMiddlewareMetadata(target, propertyKey) {
|
|
207
|
+
if (propertyKey) {
|
|
208
|
+
const methodMiddleware = target[MIDDLEWARE_METADATA_KEY]?.get(propertyKey);
|
|
209
|
+
return methodMiddleware || [];
|
|
210
|
+
}
|
|
211
|
+
return target[MIDDLEWARE_METADATA_KEY] || [];
|
|
212
|
+
}
|
|
213
|
+
static getParamMetadata(target, propertyKey) {
|
|
214
|
+
return target[PARAM_METADATA_KEY]?.get(propertyKey) || [];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
class DecoratorContainer extends Container {
|
|
219
|
+
registerController(controllerClass) {
|
|
220
|
+
const metadata = MetadataReader.getControllerMetadata(controllerClass);
|
|
221
|
+
if (!metadata) {
|
|
222
|
+
throw new Error(`Class ${controllerClass.name} is not decorated with @Controller`);
|
|
223
|
+
}
|
|
224
|
+
this.singleton(controllerClass, controllerClass);
|
|
225
|
+
const routes = MetadataReader.getAllRoutes(controllerClass);
|
|
226
|
+
for (const _route of routes) {}
|
|
227
|
+
}
|
|
228
|
+
resolve(token, context) {
|
|
229
|
+
if (typeof token === "function") {
|
|
230
|
+
const metadata = MetadataReader.getInjectableMetadata(token);
|
|
231
|
+
if (metadata) {
|
|
232
|
+
try {
|
|
233
|
+
return super.resolve(token, context);
|
|
234
|
+
} catch {
|
|
235
|
+
const scope = metadata.scope || "transient";
|
|
236
|
+
switch (scope) {
|
|
237
|
+
case "singleton":
|
|
238
|
+
this.singleton(token, token);
|
|
239
|
+
break;
|
|
240
|
+
case "transient":
|
|
241
|
+
this.transient(token, token);
|
|
242
|
+
break;
|
|
243
|
+
default:
|
|
244
|
+
this.transient(token, token);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return super.resolve(token, context);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
var decoratorContainer = new DecoratorContainer;
|
|
253
|
+
export {
|
|
254
|
+
setContainer,
|
|
255
|
+
getContainer,
|
|
256
|
+
decoratorContainer,
|
|
257
|
+
createContainer,
|
|
258
|
+
Validator,
|
|
259
|
+
ValidationServiceProvider,
|
|
260
|
+
ValidationPipe,
|
|
261
|
+
UserRepository,
|
|
262
|
+
UseMiddleware,
|
|
263
|
+
Tagged,
|
|
264
|
+
TAGGED_METADATA_KEY,
|
|
265
|
+
RedisCache,
|
|
266
|
+
ROUTE_METADATA_KEY,
|
|
267
|
+
Query,
|
|
268
|
+
Put,
|
|
269
|
+
PostRepository,
|
|
270
|
+
Post,
|
|
271
|
+
Patch,
|
|
272
|
+
Param,
|
|
273
|
+
PARAM_METADATA_KEY,
|
|
274
|
+
Options,
|
|
275
|
+
Optional,
|
|
276
|
+
OPTIONAL_METADATA_KEY,
|
|
277
|
+
MetadataReader,
|
|
278
|
+
MemoryCache,
|
|
279
|
+
MIDDLEWARE_METADATA_KEY,
|
|
280
|
+
LoggingServiceProvider,
|
|
281
|
+
Logger,
|
|
282
|
+
JwtService,
|
|
283
|
+
Injectable,
|
|
284
|
+
InjectParam,
|
|
285
|
+
Inject,
|
|
286
|
+
INJECT_METADATA_KEY,
|
|
287
|
+
INJECTABLE_METADATA_KEY,
|
|
288
|
+
Header,
|
|
289
|
+
Head,
|
|
290
|
+
Get,
|
|
291
|
+
FileLogger,
|
|
292
|
+
EventServiceProvider,
|
|
293
|
+
EventDispatcher,
|
|
294
|
+
EventBus,
|
|
295
|
+
EnvironmentPresets,
|
|
296
|
+
EnvironmentManager,
|
|
297
|
+
Delete,
|
|
298
|
+
DefaultServiceProviderManager,
|
|
299
|
+
DefaultContextualBindingBuilder,
|
|
300
|
+
DecoratorContainer,
|
|
301
|
+
DatabaseServiceProvider,
|
|
302
|
+
DatabaseConnection,
|
|
303
|
+
Container as DIContainer,
|
|
304
|
+
Cookie,
|
|
305
|
+
Controller,
|
|
306
|
+
ContextualContainer,
|
|
307
|
+
Container,
|
|
308
|
+
ConsoleLogger,
|
|
309
|
+
ConfigServiceProvider,
|
|
310
|
+
ConfigService,
|
|
311
|
+
CacheServiceProvider,
|
|
312
|
+
CacheManager,
|
|
313
|
+
CONTROLLER_METADATA_KEY,
|
|
314
|
+
Body,
|
|
315
|
+
BindingConditions,
|
|
316
|
+
BindingBuilder,
|
|
317
|
+
BaseServiceProvider,
|
|
318
|
+
BaseDeferredServiceProvider,
|
|
319
|
+
AuthServiceProvider,
|
|
320
|
+
AuthService,
|
|
321
|
+
AuthGuard
|
|
322
|
+
};
|
|
@@ -17,6 +17,12 @@ export interface StaticFileConfig {
|
|
|
17
17
|
compressionThreshold?: number;
|
|
18
18
|
cacheControl?: string;
|
|
19
19
|
dotfiles?: 'allow' | 'deny' | 'ignore';
|
|
20
|
+
/**
|
|
21
|
+
* Files larger than this (bytes) are streamed straight from disk via
|
|
22
|
+
* `Bun.file()` instead of being buffered into the in-memory cache.
|
|
23
|
+
* Streamed responses support HTTP Range requests (206). Default: 5 MiB.
|
|
24
|
+
*/
|
|
25
|
+
maxCacheFileSize?: number;
|
|
20
26
|
}
|
|
21
27
|
export interface FileCache {
|
|
22
28
|
content: ArrayBuffer;
|
|
@@ -56,6 +62,11 @@ export declare class StaticFileServer {
|
|
|
56
62
|
* Serve cached file with proper headers
|
|
57
63
|
*/
|
|
58
64
|
private serveCachedFile;
|
|
65
|
+
/**
|
|
66
|
+
* Stream a file from disk without buffering it into memory.
|
|
67
|
+
* Supports single-range HTTP Range requests (RFC 9110 §14).
|
|
68
|
+
*/
|
|
69
|
+
private serveStreamedFile;
|
|
59
70
|
/**
|
|
60
71
|
* Resolve file path, handling index files and extensions
|
|
61
72
|
*/
|
|
@@ -88,6 +99,11 @@ export declare class StaticFileServer {
|
|
|
88
99
|
* Clear cache
|
|
89
100
|
*/
|
|
90
101
|
clearCache(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Invalidate a single cached file (e.g. from a file watcher), leaving
|
|
104
|
+
* the rest of the cache warm.
|
|
105
|
+
*/
|
|
106
|
+
invalidateFile(filePath: string): void;
|
|
91
107
|
/**
|
|
92
108
|
* Get cache size
|
|
93
109
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @stacksjs/bun-router — a fast, type-safe router for Bun.
|
|
3
|
+
*
|
|
4
|
+
* Main entry point. The most commonly used exports:
|
|
5
|
+
* - `Router` — the primary router class (from `./router`)
|
|
6
|
+
* - `FluentRouter` / `router` — chainable routing API
|
|
7
|
+
* - `Auth`, `JWT`, `ApiKeyManager`, `OAuth2Helper` — auth helpers
|
|
8
|
+
* - `Container`, `createContainer` — dependency-injection container
|
|
9
|
+
* - `url()` / `registerNamedRoute()` — named-route URL generation
|
|
10
|
+
* - `Errors` — namespaced error/exception types
|
|
11
|
+
*/
|
|
1
12
|
export { default as Auth } from './auth';
|
|
2
13
|
export * from './auth';
|
|
3
14
|
export * from './config';
|
|
15
|
+
export { BindingBuilder, Container, createContainer, getContainer, setContainer, } from './container/container';
|
|
16
|
+
export type { Binding, BindingScope, ContainerOptions, ResolutionContext, Token } from './container/container';
|
|
17
|
+
export { ContextualContainer, EnvironmentManager } from './container/contextual-binding';
|
|
18
|
+
export { DefaultServiceProviderManager } from './container/service-provider';
|
|
4
19
|
export * as Errors from './errors';
|
|
5
20
|
export * from './middleware';
|
|
6
|
-
export { getCurrentRequest, request, runWithRequest, setCurrentRequest } from './request/context';
|
|
21
|
+
export { enableRequestContext, getCurrentRequest, request, runWithRequest, setCurrentRequest } from './request/context';
|
|
7
22
|
export * from './session';
|
|
8
23
|
export * from './response/response-factory';
|
|
9
24
|
export * from './router';
|
|
10
25
|
export { MiddlewareGroupRegistry, middlewareGroups } from './router/middleware-groups';
|
|
11
26
|
export * from './testing';
|
|
12
27
|
export * from './types';
|
|
28
|
+
export * from './validation/validator';
|
|
13
29
|
export { clearNamedRoutes, getNamedRoutePath, getNamedRoutes, registerNamedRoute, url, type UrlOptions } from './url';
|
|
14
30
|
export * from './utils';
|