@buenojs/bueno 0.8.0
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/.env.example +109 -0
- package/.github/workflows/ci.yml +31 -0
- package/LICENSE +21 -0
- package/README.md +892 -0
- package/architecture.md +652 -0
- package/bun.lock +70 -0
- package/dist/cli/index.js +3233 -0
- package/dist/index.js +9014 -0
- package/package.json +77 -0
- package/src/cache/index.ts +795 -0
- package/src/cli/ARCHITECTURE.md +837 -0
- package/src/cli/bin.ts +10 -0
- package/src/cli/commands/build.ts +425 -0
- package/src/cli/commands/dev.ts +248 -0
- package/src/cli/commands/generate.ts +541 -0
- package/src/cli/commands/help.ts +55 -0
- package/src/cli/commands/index.ts +112 -0
- package/src/cli/commands/migration.ts +355 -0
- package/src/cli/commands/new.ts +804 -0
- package/src/cli/commands/start.ts +208 -0
- package/src/cli/core/args.ts +283 -0
- package/src/cli/core/console.ts +349 -0
- package/src/cli/core/index.ts +60 -0
- package/src/cli/core/prompt.ts +424 -0
- package/src/cli/core/spinner.ts +265 -0
- package/src/cli/index.ts +135 -0
- package/src/cli/templates/deploy.ts +295 -0
- package/src/cli/templates/docker.ts +307 -0
- package/src/cli/templates/index.ts +24 -0
- package/src/cli/utils/fs.ts +428 -0
- package/src/cli/utils/index.ts +8 -0
- package/src/cli/utils/strings.ts +197 -0
- package/src/config/env.ts +408 -0
- package/src/config/index.ts +506 -0
- package/src/config/loader.ts +329 -0
- package/src/config/merge.ts +285 -0
- package/src/config/types.ts +320 -0
- package/src/config/validation.ts +441 -0
- package/src/container/forward-ref.ts +143 -0
- package/src/container/index.ts +386 -0
- package/src/context/index.ts +360 -0
- package/src/database/index.ts +1142 -0
- package/src/database/migrations/index.ts +371 -0
- package/src/database/schema/index.ts +619 -0
- package/src/frontend/api-routes.ts +640 -0
- package/src/frontend/bundler.ts +643 -0
- package/src/frontend/console-client.ts +419 -0
- package/src/frontend/console-stream.ts +587 -0
- package/src/frontend/dev-server.ts +846 -0
- package/src/frontend/file-router.ts +611 -0
- package/src/frontend/frameworks/index.ts +106 -0
- package/src/frontend/frameworks/react.ts +85 -0
- package/src/frontend/frameworks/solid.ts +104 -0
- package/src/frontend/frameworks/svelte.ts +110 -0
- package/src/frontend/frameworks/vue.ts +92 -0
- package/src/frontend/hmr-client.ts +663 -0
- package/src/frontend/hmr.ts +728 -0
- package/src/frontend/index.ts +342 -0
- package/src/frontend/islands.ts +552 -0
- package/src/frontend/isr.ts +555 -0
- package/src/frontend/layout.ts +475 -0
- package/src/frontend/ssr/react.ts +446 -0
- package/src/frontend/ssr/solid.ts +523 -0
- package/src/frontend/ssr/svelte.ts +546 -0
- package/src/frontend/ssr/vue.ts +504 -0
- package/src/frontend/ssr.ts +699 -0
- package/src/frontend/types.ts +2274 -0
- package/src/health/index.ts +604 -0
- package/src/index.ts +410 -0
- package/src/lock/index.ts +587 -0
- package/src/logger/index.ts +444 -0
- package/src/logger/transports/index.ts +969 -0
- package/src/metrics/index.ts +494 -0
- package/src/middleware/built-in.ts +360 -0
- package/src/middleware/index.ts +94 -0
- package/src/modules/filters.ts +458 -0
- package/src/modules/guards.ts +405 -0
- package/src/modules/index.ts +1256 -0
- package/src/modules/interceptors.ts +574 -0
- package/src/modules/lazy.ts +418 -0
- package/src/modules/lifecycle.ts +478 -0
- package/src/modules/metadata.ts +90 -0
- package/src/modules/pipes.ts +626 -0
- package/src/router/index.ts +339 -0
- package/src/router/linear.ts +371 -0
- package/src/router/regex.ts +292 -0
- package/src/router/tree.ts +562 -0
- package/src/rpc/index.ts +1263 -0
- package/src/security/index.ts +436 -0
- package/src/ssg/index.ts +631 -0
- package/src/storage/index.ts +456 -0
- package/src/telemetry/index.ts +1097 -0
- package/src/testing/index.ts +1586 -0
- package/src/types/index.ts +236 -0
- package/src/types/optional-deps.d.ts +219 -0
- package/src/validation/index.ts +276 -0
- package/src/websocket/index.ts +1004 -0
- package/tests/integration/cli.test.ts +1016 -0
- package/tests/integration/fullstack.test.ts +234 -0
- package/tests/unit/cache.test.ts +174 -0
- package/tests/unit/cli-commands.test.ts +892 -0
- package/tests/unit/cli.test.ts +1258 -0
- package/tests/unit/container.test.ts +279 -0
- package/tests/unit/context.test.ts +221 -0
- package/tests/unit/database.test.ts +183 -0
- package/tests/unit/linear-router.test.ts +280 -0
- package/tests/unit/lock.test.ts +336 -0
- package/tests/unit/middleware.test.ts +184 -0
- package/tests/unit/modules.test.ts +142 -0
- package/tests/unit/pubsub.test.ts +257 -0
- package/tests/unit/regex-router.test.ts +265 -0
- package/tests/unit/router.test.ts +373 -0
- package/tests/unit/rpc.test.ts +1248 -0
- package/tests/unit/security.test.ts +174 -0
- package/tests/unit/telemetry.test.ts +371 -0
- package/tests/unit/test-cache.test.ts +110 -0
- package/tests/unit/test-database.test.ts +282 -0
- package/tests/unit/tree-router.test.ts +325 -0
- package/tests/unit/validation.test.ts +794 -0
- package/tsconfig.json +27 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bueno Framework
|
|
3
|
+
*
|
|
4
|
+
* A Bun-Native Full-Stack Framework
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Version
|
|
8
|
+
export const VERSION = "0.1.0";
|
|
9
|
+
|
|
10
|
+
// Core
|
|
11
|
+
export {
|
|
12
|
+
Container,
|
|
13
|
+
createToken,
|
|
14
|
+
Injectable,
|
|
15
|
+
Inject,
|
|
16
|
+
} from "./container";
|
|
17
|
+
export type { Provider, Token } from "./container";
|
|
18
|
+
export { Router, generateUrl } from "./router";
|
|
19
|
+
export { Context, createContext } from "./context";
|
|
20
|
+
export {
|
|
21
|
+
compose,
|
|
22
|
+
createPipeline,
|
|
23
|
+
type Middleware,
|
|
24
|
+
type Handler,
|
|
25
|
+
} from "./middleware";
|
|
26
|
+
|
|
27
|
+
// Built-in Middleware
|
|
28
|
+
export {
|
|
29
|
+
logger,
|
|
30
|
+
cors,
|
|
31
|
+
requestId,
|
|
32
|
+
timing,
|
|
33
|
+
securityHeaders,
|
|
34
|
+
rateLimit,
|
|
35
|
+
compression,
|
|
36
|
+
} from "./middleware/built-in";
|
|
37
|
+
|
|
38
|
+
// Modules
|
|
39
|
+
export {
|
|
40
|
+
Module,
|
|
41
|
+
Controller,
|
|
42
|
+
Injectable as ModuleInjectable,
|
|
43
|
+
Inject as ModuleInject,
|
|
44
|
+
Get,
|
|
45
|
+
Post,
|
|
46
|
+
Put,
|
|
47
|
+
Patch,
|
|
48
|
+
Delete,
|
|
49
|
+
Head,
|
|
50
|
+
Options,
|
|
51
|
+
AppModule,
|
|
52
|
+
Application,
|
|
53
|
+
createApp,
|
|
54
|
+
} from "./modules";
|
|
55
|
+
|
|
56
|
+
// Database
|
|
57
|
+
export {
|
|
58
|
+
Database,
|
|
59
|
+
createConnection,
|
|
60
|
+
detectDriver,
|
|
61
|
+
QueryBuilder,
|
|
62
|
+
table,
|
|
63
|
+
ReservedConnection,
|
|
64
|
+
type DatabaseConfig as DatabaseConfigType,
|
|
65
|
+
type DatabaseDriver,
|
|
66
|
+
type QueryResult,
|
|
67
|
+
type Transaction,
|
|
68
|
+
// Schema
|
|
69
|
+
SchemaBuilder,
|
|
70
|
+
createSchema,
|
|
71
|
+
defineTable,
|
|
72
|
+
generateCreateTable,
|
|
73
|
+
generateDropTable,
|
|
74
|
+
generateCreateIndex,
|
|
75
|
+
type ColumnType,
|
|
76
|
+
type ColumnOptions,
|
|
77
|
+
type TableSchema,
|
|
78
|
+
type IndexDefinition,
|
|
79
|
+
type ConstraintDefinition,
|
|
80
|
+
type TypeScriptType,
|
|
81
|
+
type InferType,
|
|
82
|
+
type InferInsertType,
|
|
83
|
+
// Migrations
|
|
84
|
+
MigrationRunner,
|
|
85
|
+
MigrationBuilder,
|
|
86
|
+
createMigration,
|
|
87
|
+
createMigrationRunner,
|
|
88
|
+
generateMigrationId,
|
|
89
|
+
type Migration,
|
|
90
|
+
type MigrationRecord,
|
|
91
|
+
type MigrationOptions,
|
|
92
|
+
} from "./database";
|
|
93
|
+
|
|
94
|
+
// Validation
|
|
95
|
+
export {
|
|
96
|
+
validate,
|
|
97
|
+
validateSync,
|
|
98
|
+
validateBody,
|
|
99
|
+
validateQuery,
|
|
100
|
+
validateParams,
|
|
101
|
+
validateHeaders,
|
|
102
|
+
createValidator,
|
|
103
|
+
WithBody,
|
|
104
|
+
WithQuery,
|
|
105
|
+
isStandardSchema,
|
|
106
|
+
assertStandardSchema,
|
|
107
|
+
type ValidationResult,
|
|
108
|
+
type ValidatorOptions,
|
|
109
|
+
} from "./validation";
|
|
110
|
+
|
|
111
|
+
// Security
|
|
112
|
+
export {
|
|
113
|
+
Password,
|
|
114
|
+
JWT,
|
|
115
|
+
CSRF,
|
|
116
|
+
createAuthMiddleware,
|
|
117
|
+
createRBACMiddleware,
|
|
118
|
+
createAPIKeyMiddleware,
|
|
119
|
+
} from "./security";
|
|
120
|
+
|
|
121
|
+
// RPC
|
|
122
|
+
export {
|
|
123
|
+
RPCClient,
|
|
124
|
+
createRPClient,
|
|
125
|
+
bc,
|
|
126
|
+
extractRouteTypes,
|
|
127
|
+
parseJSON,
|
|
128
|
+
parseText,
|
|
129
|
+
isOK,
|
|
130
|
+
isStatus,
|
|
131
|
+
throwIfNotOK,
|
|
132
|
+
} from "./rpc";
|
|
133
|
+
|
|
134
|
+
// Cache
|
|
135
|
+
export {
|
|
136
|
+
Cache,
|
|
137
|
+
SessionStore,
|
|
138
|
+
createCache,
|
|
139
|
+
createSessionStore,
|
|
140
|
+
} from "./cache";
|
|
141
|
+
|
|
142
|
+
// Distributed Lock
|
|
143
|
+
export {
|
|
144
|
+
DistributedLock,
|
|
145
|
+
LockAcquireError,
|
|
146
|
+
LockTimeoutError,
|
|
147
|
+
createDistributedLock,
|
|
148
|
+
createRedisLock,
|
|
149
|
+
createMemoryLock,
|
|
150
|
+
getDefaultLock,
|
|
151
|
+
setDefaultLock,
|
|
152
|
+
lock,
|
|
153
|
+
type LockConfig,
|
|
154
|
+
type LockOptions,
|
|
155
|
+
type Lock,
|
|
156
|
+
type LockHandle,
|
|
157
|
+
} from "./lock";
|
|
158
|
+
|
|
159
|
+
// SSG
|
|
160
|
+
export {
|
|
161
|
+
SSG,
|
|
162
|
+
createSSG,
|
|
163
|
+
parseMarkdown,
|
|
164
|
+
parseFrontmatter,
|
|
165
|
+
type Frontmatter,
|
|
166
|
+
type Page,
|
|
167
|
+
type SSGConfig,
|
|
168
|
+
type LayoutContext,
|
|
169
|
+
type SiteConfig,
|
|
170
|
+
} from "./ssg";
|
|
171
|
+
|
|
172
|
+
// Storage
|
|
173
|
+
export {
|
|
174
|
+
Storage,
|
|
175
|
+
createStorage,
|
|
176
|
+
Secrets,
|
|
177
|
+
type StorageConfig,
|
|
178
|
+
type UploadOptions,
|
|
179
|
+
type DownloadOptions,
|
|
180
|
+
type FileInfo,
|
|
181
|
+
type ListOptions,
|
|
182
|
+
type ListResult,
|
|
183
|
+
type PresignedURLOptions,
|
|
184
|
+
type SecretOptions,
|
|
185
|
+
type SetSecretOptions,
|
|
186
|
+
} from "./storage";
|
|
187
|
+
|
|
188
|
+
// Testing
|
|
189
|
+
export {
|
|
190
|
+
AppTester,
|
|
191
|
+
createTester,
|
|
192
|
+
createTestRequest,
|
|
193
|
+
createTestResponse,
|
|
194
|
+
createMockContext,
|
|
195
|
+
createMockContextWithParams,
|
|
196
|
+
assertStatus,
|
|
197
|
+
assertOK,
|
|
198
|
+
assertJSON,
|
|
199
|
+
assertBody,
|
|
200
|
+
assertHeader,
|
|
201
|
+
assertRedirect,
|
|
202
|
+
snapshotResponse,
|
|
203
|
+
FixtureFactory,
|
|
204
|
+
createFixtureFactory,
|
|
205
|
+
waitFor,
|
|
206
|
+
sleep,
|
|
207
|
+
type TestRequestOptions,
|
|
208
|
+
type TestResponse,
|
|
209
|
+
} from "./testing";
|
|
210
|
+
|
|
211
|
+
// WebSocket
|
|
212
|
+
export {
|
|
213
|
+
WebSocketServer,
|
|
214
|
+
WebSocketClient,
|
|
215
|
+
PubSub,
|
|
216
|
+
createWebSocketServer,
|
|
217
|
+
createWebSocketClient,
|
|
218
|
+
createPubSub,
|
|
219
|
+
createRedisPubSub,
|
|
220
|
+
createMemoryPubSub,
|
|
221
|
+
isWebSocketRequest,
|
|
222
|
+
generateConnectionId,
|
|
223
|
+
createWebSocketData,
|
|
224
|
+
type WebSocketData,
|
|
225
|
+
type WebSocketMessage,
|
|
226
|
+
type WebSocketOptions,
|
|
227
|
+
type WebSocketHandler,
|
|
228
|
+
type OpenHandler,
|
|
229
|
+
type CloseHandler,
|
|
230
|
+
type ErrorHandler,
|
|
231
|
+
type WebSocketServerOptions,
|
|
232
|
+
type WebSocketClientOptions,
|
|
233
|
+
type PubSubConfig,
|
|
234
|
+
type PubSubMessage,
|
|
235
|
+
type PubSubCallback,
|
|
236
|
+
} from "./websocket";
|
|
237
|
+
|
|
238
|
+
// Logger
|
|
239
|
+
export {
|
|
240
|
+
Logger,
|
|
241
|
+
PerformanceLogger,
|
|
242
|
+
createLogger,
|
|
243
|
+
createRequestLogger,
|
|
244
|
+
getLogger,
|
|
245
|
+
setLogger,
|
|
246
|
+
type LogLevel,
|
|
247
|
+
type LogEntry,
|
|
248
|
+
type LoggerConfig as LoggerConfigType,
|
|
249
|
+
type LoggerContext,
|
|
250
|
+
} from "./logger";
|
|
251
|
+
|
|
252
|
+
// Health Check
|
|
253
|
+
export {
|
|
254
|
+
HealthCheckManager,
|
|
255
|
+
createHealthMiddleware,
|
|
256
|
+
createHealthManager,
|
|
257
|
+
createDatabaseCheck,
|
|
258
|
+
createCacheCheck,
|
|
259
|
+
createCustomCheck,
|
|
260
|
+
createTCPCheck,
|
|
261
|
+
createHTTPCheck,
|
|
262
|
+
type HealthStatus,
|
|
263
|
+
type CheckResult,
|
|
264
|
+
type HealthCheckResult,
|
|
265
|
+
type HealthCheckFn,
|
|
266
|
+
type CheckOptions,
|
|
267
|
+
type HealthMiddlewareOptions,
|
|
268
|
+
type DatabaseLike,
|
|
269
|
+
type CacheLike,
|
|
270
|
+
} from "./health";
|
|
271
|
+
|
|
272
|
+
// Types
|
|
273
|
+
export type {
|
|
274
|
+
HTTPMethod,
|
|
275
|
+
StatusCode,
|
|
276
|
+
PathParams,
|
|
277
|
+
RouteHandler,
|
|
278
|
+
MiddlewareHandler,
|
|
279
|
+
RouteDefinition,
|
|
280
|
+
ModuleMetadata,
|
|
281
|
+
ContextVariableMap,
|
|
282
|
+
StandardSchema,
|
|
283
|
+
StandardIssue,
|
|
284
|
+
ServerConfig,
|
|
285
|
+
AppOptions,
|
|
286
|
+
BuenoError,
|
|
287
|
+
ValidationError,
|
|
288
|
+
NotFoundError,
|
|
289
|
+
StandardResult,
|
|
290
|
+
StandardTypes,
|
|
291
|
+
InferInput,
|
|
292
|
+
InferOutput,
|
|
293
|
+
} from "./types";
|
|
294
|
+
|
|
295
|
+
// Configuration
|
|
296
|
+
export {
|
|
297
|
+
ConfigManager,
|
|
298
|
+
defineConfig,
|
|
299
|
+
defineConfigFn,
|
|
300
|
+
createConfigManager,
|
|
301
|
+
createConfigManagerSync,
|
|
302
|
+
loadConfigDirect,
|
|
303
|
+
getConfigManager,
|
|
304
|
+
setConfigManager,
|
|
305
|
+
type ConfigManagerOptions,
|
|
306
|
+
type ConfigChangeCallback,
|
|
307
|
+
} from "./config";
|
|
308
|
+
export {
|
|
309
|
+
loadConfig,
|
|
310
|
+
loadConfigFile,
|
|
311
|
+
loadConfigFiles,
|
|
312
|
+
findConfigFile,
|
|
313
|
+
clearConfigCache,
|
|
314
|
+
getCachedConfig,
|
|
315
|
+
watchConfig,
|
|
316
|
+
validateConfigStructure,
|
|
317
|
+
getConfigPathFromArgs,
|
|
318
|
+
getConfigPathFromEnv,
|
|
319
|
+
type LoadedConfig,
|
|
320
|
+
} from "./config";
|
|
321
|
+
export {
|
|
322
|
+
loadEnv,
|
|
323
|
+
getEnvConfig,
|
|
324
|
+
getEnvValue,
|
|
325
|
+
setEnvValue,
|
|
326
|
+
envConfigMapping,
|
|
327
|
+
type EnvConfigMapping,
|
|
328
|
+
} from "./config";
|
|
329
|
+
export {
|
|
330
|
+
validateConfig,
|
|
331
|
+
validateConfigSync,
|
|
332
|
+
validateConfigDefaults,
|
|
333
|
+
validateWithSchema,
|
|
334
|
+
assertValidConfig,
|
|
335
|
+
formatValidationErrors,
|
|
336
|
+
createConfigError,
|
|
337
|
+
createCustomValidator,
|
|
338
|
+
isStandardSchema as isConfigStandardSchema,
|
|
339
|
+
type ConfigValidationResult,
|
|
340
|
+
type ConfigValidationError,
|
|
341
|
+
type ConfigValidationWarning,
|
|
342
|
+
} from "./config";
|
|
343
|
+
export {
|
|
344
|
+
deepMerge,
|
|
345
|
+
mergeConfigs,
|
|
346
|
+
isObject,
|
|
347
|
+
} from "./config";
|
|
348
|
+
export type {
|
|
349
|
+
BuenoConfig,
|
|
350
|
+
ServerConfig as BuenoServerConfig,
|
|
351
|
+
DatabaseConfig,
|
|
352
|
+
CacheConfig,
|
|
353
|
+
LoggerConfig,
|
|
354
|
+
HealthConfig,
|
|
355
|
+
MetricsConfig,
|
|
356
|
+
TelemetryConfig,
|
|
357
|
+
FrontendConfig,
|
|
358
|
+
DeepPartial,
|
|
359
|
+
UserConfig,
|
|
360
|
+
UserConfigFn,
|
|
361
|
+
InferConfig,
|
|
362
|
+
} from "./config";
|
|
363
|
+
|
|
364
|
+
import { Context } from "./context";
|
|
365
|
+
import { type Middleware, compose } from "./middleware";
|
|
366
|
+
// Quick Start Helper
|
|
367
|
+
import { Router } from "./router";
|
|
368
|
+
|
|
369
|
+
export function createServer(options?: {
|
|
370
|
+
port?: number;
|
|
371
|
+
hostname?: string;
|
|
372
|
+
}) {
|
|
373
|
+
const router = new Router();
|
|
374
|
+
|
|
375
|
+
return {
|
|
376
|
+
router,
|
|
377
|
+
async listen(
|
|
378
|
+
port = options?.port ?? 3000,
|
|
379
|
+
hostname = options?.hostname ?? "localhost",
|
|
380
|
+
) {
|
|
381
|
+
const server = Bun.serve({
|
|
382
|
+
port,
|
|
383
|
+
hostname,
|
|
384
|
+
fetch: async (request: Request): Promise<Response> => {
|
|
385
|
+
const url = new URL(request.url);
|
|
386
|
+
const match = router.match(request.method as "GET", url.pathname);
|
|
387
|
+
|
|
388
|
+
if (!match) {
|
|
389
|
+
return new Response("Not Found", { status: 404 });
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const context = new Context(request, match.params);
|
|
393
|
+
|
|
394
|
+
if (match.middleware && match.middleware.length > 0) {
|
|
395
|
+
const pipeline = compose(match.middleware as Middleware[]);
|
|
396
|
+
return pipeline(
|
|
397
|
+
context,
|
|
398
|
+
async () => match.handler(context) as Response,
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return match.handler(context) as Response;
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
console.log(`Bueno server running at http://${hostname}:${port}`);
|
|
407
|
+
return server;
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
}
|