@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.
Files changed (120) hide show
  1. package/.env.example +109 -0
  2. package/.github/workflows/ci.yml +31 -0
  3. package/LICENSE +21 -0
  4. package/README.md +892 -0
  5. package/architecture.md +652 -0
  6. package/bun.lock +70 -0
  7. package/dist/cli/index.js +3233 -0
  8. package/dist/index.js +9014 -0
  9. package/package.json +77 -0
  10. package/src/cache/index.ts +795 -0
  11. package/src/cli/ARCHITECTURE.md +837 -0
  12. package/src/cli/bin.ts +10 -0
  13. package/src/cli/commands/build.ts +425 -0
  14. package/src/cli/commands/dev.ts +248 -0
  15. package/src/cli/commands/generate.ts +541 -0
  16. package/src/cli/commands/help.ts +55 -0
  17. package/src/cli/commands/index.ts +112 -0
  18. package/src/cli/commands/migration.ts +355 -0
  19. package/src/cli/commands/new.ts +804 -0
  20. package/src/cli/commands/start.ts +208 -0
  21. package/src/cli/core/args.ts +283 -0
  22. package/src/cli/core/console.ts +349 -0
  23. package/src/cli/core/index.ts +60 -0
  24. package/src/cli/core/prompt.ts +424 -0
  25. package/src/cli/core/spinner.ts +265 -0
  26. package/src/cli/index.ts +135 -0
  27. package/src/cli/templates/deploy.ts +295 -0
  28. package/src/cli/templates/docker.ts +307 -0
  29. package/src/cli/templates/index.ts +24 -0
  30. package/src/cli/utils/fs.ts +428 -0
  31. package/src/cli/utils/index.ts +8 -0
  32. package/src/cli/utils/strings.ts +197 -0
  33. package/src/config/env.ts +408 -0
  34. package/src/config/index.ts +506 -0
  35. package/src/config/loader.ts +329 -0
  36. package/src/config/merge.ts +285 -0
  37. package/src/config/types.ts +320 -0
  38. package/src/config/validation.ts +441 -0
  39. package/src/container/forward-ref.ts +143 -0
  40. package/src/container/index.ts +386 -0
  41. package/src/context/index.ts +360 -0
  42. package/src/database/index.ts +1142 -0
  43. package/src/database/migrations/index.ts +371 -0
  44. package/src/database/schema/index.ts +619 -0
  45. package/src/frontend/api-routes.ts +640 -0
  46. package/src/frontend/bundler.ts +643 -0
  47. package/src/frontend/console-client.ts +419 -0
  48. package/src/frontend/console-stream.ts +587 -0
  49. package/src/frontend/dev-server.ts +846 -0
  50. package/src/frontend/file-router.ts +611 -0
  51. package/src/frontend/frameworks/index.ts +106 -0
  52. package/src/frontend/frameworks/react.ts +85 -0
  53. package/src/frontend/frameworks/solid.ts +104 -0
  54. package/src/frontend/frameworks/svelte.ts +110 -0
  55. package/src/frontend/frameworks/vue.ts +92 -0
  56. package/src/frontend/hmr-client.ts +663 -0
  57. package/src/frontend/hmr.ts +728 -0
  58. package/src/frontend/index.ts +342 -0
  59. package/src/frontend/islands.ts +552 -0
  60. package/src/frontend/isr.ts +555 -0
  61. package/src/frontend/layout.ts +475 -0
  62. package/src/frontend/ssr/react.ts +446 -0
  63. package/src/frontend/ssr/solid.ts +523 -0
  64. package/src/frontend/ssr/svelte.ts +546 -0
  65. package/src/frontend/ssr/vue.ts +504 -0
  66. package/src/frontend/ssr.ts +699 -0
  67. package/src/frontend/types.ts +2274 -0
  68. package/src/health/index.ts +604 -0
  69. package/src/index.ts +410 -0
  70. package/src/lock/index.ts +587 -0
  71. package/src/logger/index.ts +444 -0
  72. package/src/logger/transports/index.ts +969 -0
  73. package/src/metrics/index.ts +494 -0
  74. package/src/middleware/built-in.ts +360 -0
  75. package/src/middleware/index.ts +94 -0
  76. package/src/modules/filters.ts +458 -0
  77. package/src/modules/guards.ts +405 -0
  78. package/src/modules/index.ts +1256 -0
  79. package/src/modules/interceptors.ts +574 -0
  80. package/src/modules/lazy.ts +418 -0
  81. package/src/modules/lifecycle.ts +478 -0
  82. package/src/modules/metadata.ts +90 -0
  83. package/src/modules/pipes.ts +626 -0
  84. package/src/router/index.ts +339 -0
  85. package/src/router/linear.ts +371 -0
  86. package/src/router/regex.ts +292 -0
  87. package/src/router/tree.ts +562 -0
  88. package/src/rpc/index.ts +1263 -0
  89. package/src/security/index.ts +436 -0
  90. package/src/ssg/index.ts +631 -0
  91. package/src/storage/index.ts +456 -0
  92. package/src/telemetry/index.ts +1097 -0
  93. package/src/testing/index.ts +1586 -0
  94. package/src/types/index.ts +236 -0
  95. package/src/types/optional-deps.d.ts +219 -0
  96. package/src/validation/index.ts +276 -0
  97. package/src/websocket/index.ts +1004 -0
  98. package/tests/integration/cli.test.ts +1016 -0
  99. package/tests/integration/fullstack.test.ts +234 -0
  100. package/tests/unit/cache.test.ts +174 -0
  101. package/tests/unit/cli-commands.test.ts +892 -0
  102. package/tests/unit/cli.test.ts +1258 -0
  103. package/tests/unit/container.test.ts +279 -0
  104. package/tests/unit/context.test.ts +221 -0
  105. package/tests/unit/database.test.ts +183 -0
  106. package/tests/unit/linear-router.test.ts +280 -0
  107. package/tests/unit/lock.test.ts +336 -0
  108. package/tests/unit/middleware.test.ts +184 -0
  109. package/tests/unit/modules.test.ts +142 -0
  110. package/tests/unit/pubsub.test.ts +257 -0
  111. package/tests/unit/regex-router.test.ts +265 -0
  112. package/tests/unit/router.test.ts +373 -0
  113. package/tests/unit/rpc.test.ts +1248 -0
  114. package/tests/unit/security.test.ts +174 -0
  115. package/tests/unit/telemetry.test.ts +371 -0
  116. package/tests/unit/test-cache.test.ts +110 -0
  117. package/tests/unit/test-database.test.ts +282 -0
  118. package/tests/unit/tree-router.test.ts +325 -0
  119. package/tests/unit/validation.test.ts +794 -0
  120. 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
+ }