@buenojs/bueno 0.8.3 → 0.8.5

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 (218) hide show
  1. package/README.md +136 -16
  2. package/dist/cli/{index.js → bin.js} +3036 -1421
  3. package/dist/container/index.js +250 -0
  4. package/dist/context/index.js +219 -0
  5. package/dist/database/index.js +493 -0
  6. package/dist/frontend/index.js +7697 -0
  7. package/dist/health/index.js +364 -0
  8. package/dist/i18n/index.js +345 -0
  9. package/dist/index.js +11043 -6482
  10. package/dist/jobs/index.js +819 -0
  11. package/dist/lock/index.js +367 -0
  12. package/dist/logger/index.js +281 -0
  13. package/dist/metrics/index.js +289 -0
  14. package/dist/middleware/index.js +77 -0
  15. package/dist/migrations/index.js +571 -0
  16. package/dist/modules/index.js +3346 -0
  17. package/dist/notification/index.js +484 -0
  18. package/dist/observability/index.js +331 -0
  19. package/dist/openapi/index.js +776 -0
  20. package/dist/orm/index.js +1356 -0
  21. package/dist/router/index.js +886 -0
  22. package/dist/rpc/index.js +691 -0
  23. package/dist/schema/index.js +400 -0
  24. package/dist/telemetry/index.js +595 -0
  25. package/dist/template/index.js +640 -0
  26. package/dist/templates/index.js +640 -0
  27. package/dist/testing/index.js +1111 -0
  28. package/dist/types/index.js +60 -0
  29. package/package.json +121 -27
  30. package/src/cache/index.ts +2 -1
  31. package/src/cli/bin.ts +2 -2
  32. package/src/cli/commands/build.ts +183 -165
  33. package/src/cli/commands/dev.ts +96 -89
  34. package/src/cli/commands/generate.ts +142 -111
  35. package/src/cli/commands/help.ts +20 -16
  36. package/src/cli/commands/index.ts +3 -6
  37. package/src/cli/commands/migration.ts +124 -105
  38. package/src/cli/commands/new.ts +392 -438
  39. package/src/cli/commands/start.ts +81 -79
  40. package/src/cli/core/args.ts +68 -50
  41. package/src/cli/core/console.ts +89 -95
  42. package/src/cli/core/index.ts +4 -4
  43. package/src/cli/core/prompt.ts +65 -62
  44. package/src/cli/core/spinner.ts +23 -20
  45. package/src/cli/index.ts +46 -38
  46. package/src/cli/templates/database/index.ts +61 -0
  47. package/src/cli/templates/database/mysql.ts +14 -0
  48. package/src/cli/templates/database/none.ts +16 -0
  49. package/src/cli/templates/database/postgresql.ts +14 -0
  50. package/src/cli/templates/database/sqlite.ts +14 -0
  51. package/src/cli/templates/deploy.ts +29 -26
  52. package/src/cli/templates/docker.ts +41 -30
  53. package/src/cli/templates/frontend/index.ts +63 -0
  54. package/src/cli/templates/frontend/none.ts +17 -0
  55. package/src/cli/templates/frontend/react.ts +140 -0
  56. package/src/cli/templates/frontend/solid.ts +134 -0
  57. package/src/cli/templates/frontend/svelte.ts +131 -0
  58. package/src/cli/templates/frontend/vue.ts +130 -0
  59. package/src/cli/templates/generators/index.ts +339 -0
  60. package/src/cli/templates/generators/types.ts +56 -0
  61. package/src/cli/templates/index.ts +35 -2
  62. package/src/cli/templates/project/api.ts +81 -0
  63. package/src/cli/templates/project/default.ts +140 -0
  64. package/src/cli/templates/project/fullstack.ts +111 -0
  65. package/src/cli/templates/project/index.ts +95 -0
  66. package/src/cli/templates/project/minimal.ts +45 -0
  67. package/src/cli/templates/project/types.ts +94 -0
  68. package/src/cli/templates/project/website.ts +263 -0
  69. package/src/cli/utils/fs.ts +55 -41
  70. package/src/cli/utils/index.ts +3 -2
  71. package/src/cli/utils/strings.ts +47 -33
  72. package/src/cli/utils/version.ts +47 -0
  73. package/src/config/env-validation.ts +100 -0
  74. package/src/config/env.ts +169 -41
  75. package/src/config/index.ts +28 -20
  76. package/src/config/loader.ts +25 -16
  77. package/src/config/merge.ts +21 -10
  78. package/src/config/types.ts +545 -25
  79. package/src/config/validation.ts +215 -7
  80. package/src/container/forward-ref.ts +22 -22
  81. package/src/container/index.ts +34 -12
  82. package/src/context/index.ts +11 -1
  83. package/src/database/index.ts +7 -190
  84. package/src/database/orm/builder.ts +457 -0
  85. package/src/database/orm/casts/index.ts +130 -0
  86. package/src/database/orm/casts/types.ts +25 -0
  87. package/src/database/orm/compiler.ts +304 -0
  88. package/src/database/orm/hooks/index.ts +114 -0
  89. package/src/database/orm/index.ts +61 -0
  90. package/src/database/orm/model-registry.ts +59 -0
  91. package/src/database/orm/model.ts +821 -0
  92. package/src/database/orm/relationships/base.ts +146 -0
  93. package/src/database/orm/relationships/belongs-to-many.ts +179 -0
  94. package/src/database/orm/relationships/belongs-to.ts +56 -0
  95. package/src/database/orm/relationships/has-many.ts +45 -0
  96. package/src/database/orm/relationships/has-one.ts +41 -0
  97. package/src/database/orm/relationships/index.ts +11 -0
  98. package/src/database/orm/scopes/index.ts +55 -0
  99. package/src/events/__tests__/event-system.test.ts +235 -0
  100. package/src/events/config.ts +238 -0
  101. package/src/events/example-usage.ts +185 -0
  102. package/src/events/index.ts +278 -0
  103. package/src/events/manager.ts +385 -0
  104. package/src/events/registry.ts +182 -0
  105. package/src/events/types.ts +124 -0
  106. package/src/frontend/api-routes.ts +65 -23
  107. package/src/frontend/bundler.ts +76 -34
  108. package/src/frontend/console-client.ts +2 -2
  109. package/src/frontend/console-stream.ts +94 -38
  110. package/src/frontend/dev-server.ts +94 -46
  111. package/src/frontend/file-router.ts +61 -19
  112. package/src/frontend/frameworks/index.ts +37 -10
  113. package/src/frontend/frameworks/react.ts +10 -8
  114. package/src/frontend/frameworks/solid.ts +11 -9
  115. package/src/frontend/frameworks/svelte.ts +15 -9
  116. package/src/frontend/frameworks/vue.ts +13 -11
  117. package/src/frontend/hmr-client.ts +12 -10
  118. package/src/frontend/hmr.ts +146 -103
  119. package/src/frontend/index.ts +14 -5
  120. package/src/frontend/islands.ts +41 -22
  121. package/src/frontend/isr.ts +59 -37
  122. package/src/frontend/layout.ts +36 -21
  123. package/src/frontend/ssr/react.ts +74 -27
  124. package/src/frontend/ssr/solid.ts +54 -20
  125. package/src/frontend/ssr/svelte.ts +48 -14
  126. package/src/frontend/ssr/vue.ts +50 -18
  127. package/src/frontend/ssr.ts +83 -39
  128. package/src/frontend/types.ts +91 -56
  129. package/src/health/index.ts +21 -9
  130. package/src/i18n/engine.ts +305 -0
  131. package/src/i18n/index.ts +38 -0
  132. package/src/i18n/loader.ts +218 -0
  133. package/src/i18n/middleware.ts +164 -0
  134. package/src/i18n/negotiator.ts +162 -0
  135. package/src/i18n/types.ts +158 -0
  136. package/src/index.ts +179 -27
  137. package/src/jobs/drivers/memory.ts +315 -0
  138. package/src/jobs/drivers/redis.ts +459 -0
  139. package/src/jobs/index.ts +30 -0
  140. package/src/jobs/queue.ts +281 -0
  141. package/src/jobs/types.ts +295 -0
  142. package/src/jobs/worker.ts +380 -0
  143. package/src/logger/index.ts +1 -3
  144. package/src/logger/transports/index.ts +62 -22
  145. package/src/metrics/index.ts +25 -16
  146. package/src/migrations/index.ts +9 -0
  147. package/src/modules/filters.ts +13 -17
  148. package/src/modules/guards.ts +49 -26
  149. package/src/modules/index.ts +409 -298
  150. package/src/modules/interceptors.ts +58 -20
  151. package/src/modules/lazy.ts +11 -19
  152. package/src/modules/lifecycle.ts +15 -7
  153. package/src/modules/metadata.ts +15 -5
  154. package/src/modules/pipes.ts +94 -72
  155. package/src/notification/channels/base.ts +68 -0
  156. package/src/notification/channels/email.ts +105 -0
  157. package/src/notification/channels/push.ts +104 -0
  158. package/src/notification/channels/sms.ts +105 -0
  159. package/src/notification/channels/whatsapp.ts +104 -0
  160. package/src/notification/index.ts +48 -0
  161. package/src/notification/service.ts +354 -0
  162. package/src/notification/types.ts +344 -0
  163. package/src/observability/__tests__/observability.test.ts +483 -0
  164. package/src/observability/breadcrumbs.ts +114 -0
  165. package/src/observability/index.ts +136 -0
  166. package/src/observability/interceptor.ts +85 -0
  167. package/src/observability/service.ts +303 -0
  168. package/src/observability/trace.ts +37 -0
  169. package/src/observability/types.ts +196 -0
  170. package/src/openapi/__tests__/decorators.test.ts +335 -0
  171. package/src/openapi/__tests__/document-builder.test.ts +285 -0
  172. package/src/openapi/__tests__/route-scanner.test.ts +334 -0
  173. package/src/openapi/__tests__/schema-generator.test.ts +275 -0
  174. package/src/openapi/decorators.ts +328 -0
  175. package/src/openapi/document-builder.ts +274 -0
  176. package/src/openapi/index.ts +112 -0
  177. package/src/openapi/metadata.ts +112 -0
  178. package/src/openapi/route-scanner.ts +289 -0
  179. package/src/openapi/schema-generator.ts +256 -0
  180. package/src/openapi/swagger-module.ts +166 -0
  181. package/src/openapi/types.ts +398 -0
  182. package/src/orm/index.ts +10 -0
  183. package/src/rpc/index.ts +3 -1
  184. package/src/schema/index.ts +9 -0
  185. package/src/security/index.ts +15 -6
  186. package/src/ssg/index.ts +9 -8
  187. package/src/telemetry/index.ts +76 -22
  188. package/src/template/index.ts +7 -0
  189. package/src/templates/engine.ts +224 -0
  190. package/src/templates/index.ts +9 -0
  191. package/src/templates/loader.ts +331 -0
  192. package/src/templates/renderers/markdown.ts +212 -0
  193. package/src/templates/renderers/simple.ts +269 -0
  194. package/src/templates/types.ts +154 -0
  195. package/src/testing/index.ts +100 -27
  196. package/src/types/optional-deps.d.ts +347 -187
  197. package/src/validation/index.ts +92 -2
  198. package/src/validation/schemas.ts +536 -0
  199. package/tests/integration/fullstack.test.ts +4 -4
  200. package/tests/unit/database.test.ts +2 -72
  201. package/tests/unit/env-validation.test.ts +166 -0
  202. package/tests/unit/events.test.ts +910 -0
  203. package/tests/unit/i18n.test.ts +455 -0
  204. package/tests/unit/jobs.test.ts +493 -0
  205. package/tests/unit/notification.test.ts +988 -0
  206. package/tests/unit/observability.test.ts +453 -0
  207. package/tests/unit/orm/builder.test.ts +323 -0
  208. package/tests/unit/orm/casts.test.ts +179 -0
  209. package/tests/unit/orm/compiler.test.ts +220 -0
  210. package/tests/unit/orm/eager-loading.test.ts +285 -0
  211. package/tests/unit/orm/hooks.test.ts +191 -0
  212. package/tests/unit/orm/model.test.ts +373 -0
  213. package/tests/unit/orm/relationships.test.ts +303 -0
  214. package/tests/unit/orm/scopes.test.ts +74 -0
  215. package/tests/unit/templates-simple.test.ts +53 -0
  216. package/tests/unit/templates.test.ts +454 -0
  217. package/tests/unit/validation.test.ts +18 -24
  218. package/tsconfig.json +11 -3
package/README.md CHANGED
@@ -2,19 +2,20 @@
2
2
 
3
3
  A Bun-Native Full-Stack Framework
4
4
 
5
- [![Build Status](https://img.shields.io/github/actions/workflow/status/buenojs/bueno/ci.yml?branch=main)](https://github.com/buenojs/bueno/actions)
6
- [![Test Coverage](https://img.shields.io/codecov/c/gh/buenojs/bueno)](https://codecov.io/gh/buenojs/bueno)
5
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/buenojs/bueno/ci.yml?branch=main&label=Tests)](https://github.com/buenojs/bueno/actions)
6
+ [![Test Coverage](https://img.shields.io/codecov/c/gh/buenojs/bueno?label=Coverage)](https://codecov.io/gh/buenojs/bueno)
7
7
  [![npm version](https://img.shields.io/npm/v/@buenojs/bueno)](https://www.npmjs.com/package/@buenojs/bueno)
8
- [![License](https://img.shields.io/npm/l/@buenojs/bueno)](https://github.com/buenojs/bueno/blob/main/LICENSE)
8
+ [![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/buenojs/bueno/blob/main/LICENSE)
9
9
  [![Bun Version](https://img.shields.io/badge/bun-%3E%3D1.3.0-black)](https://bun.sh)
10
10
  [![Activity](https://img.shields.io/github/commit-activity/m/buenojs/bueno)](https://github.com/buenojs/bueno/graphs/commit-activity)
11
- [![Last Commit](https://img.shields.io/github/last-commit/buenojs/bueno)](https://github.com/buenojs/bueno/commits/main)
11
+ [![Last Commit](https://img.shields.io/github/last-commit/buenojs/bueno/main)](https://github.com/buenojs/bueno/commits/main)
12
12
 
13
13
  ## Why Bueno?
14
14
 
15
15
  Bueno is a **Bun-native** full-stack framework designed from the ground up to leverage Bun's exceptional performance and modern JavaScript capabilities. Bueno embraces Bun's APIs, resulting in:
16
16
 
17
17
  - **Blazing Fast Performance**: Built on Bun's native HTTP server and optimized runtime
18
+ - **Zero Dependencies**: True zero-dependency framework with built-in validation, ORM, caching, and jobs
18
19
  - **Zero Configuration**: Sensible defaults that work out of the box
19
20
  - **Full-Stack Integration**: Seamless frontend and backend development
20
21
  - **Type Safety**: End-to-end TypeScript with full type inference
@@ -430,29 +431,145 @@ await schema.createTable('users', (table) => {
430
431
 
431
432
  ### Validation
432
433
 
433
- First-class support for popular validation libraries.
434
+ Bueno includes a **zero-dependency** built-in validation system for common use cases, with optional support for external libraries like Zod, Valibot, and ArkType via the Standard Schema adapter.
435
+
436
+ #### Built-in Validation (No Dependencies)
437
+
438
+ ```typescript
439
+ import { Schema, Fields, validate, validateBody } from '@buenojs/bueno/validation';
440
+
441
+ // Define schema with built-in validators
442
+ const UserSchema = Schema.object({
443
+ name: Fields.string({ min: 1, max: 100 }),
444
+ email: Fields.string({ email: true }),
445
+ age: Fields.number({ positive: true, optional: true }),
446
+ role: Fields.enum(['admin', 'user', 'guest']),
447
+ });
448
+
449
+ // Validate in route
450
+ router.post('/users', async (ctx) => {
451
+ const result = await validateBody(ctx, UserSchema);
452
+
453
+ if (!result.success) {
454
+ return ctx.status(400).json({
455
+ error: 'Validation failed',
456
+ issues: result.issues
457
+ });
458
+ }
459
+
460
+ const user = result.data; // Fully typed!
461
+ });
462
+ ```
463
+
464
+ #### Built-in Field Validators
465
+
466
+ ```typescript
467
+ import { Fields } from '@buenojs/bueno/validation';
468
+
469
+ Fields.string({
470
+ min: 1, // Minimum length
471
+ max: 255, // Maximum length
472
+ pattern: /regex/, // Regex validation
473
+ email: true, // Email format
474
+ url: true, // URL format
475
+ uuid: true, // UUID format
476
+ optional: true, // Allow undefined/null
477
+ })
478
+
479
+ Fields.number({
480
+ min: 0, // Minimum value
481
+ max: 100, // Maximum value
482
+ integer: true, // Must be integer
483
+ positive: true, // Must be > 0
484
+ optional: true, // Allow undefined/null
485
+ })
486
+
487
+ Fields.boolean({ optional: true })
488
+
489
+ Fields.array({
490
+ min: 1, // Minimum items
491
+ max: 10, // Maximum items
492
+ itemValidator: Fields.string(), // Validate each item
493
+ optional: true,
494
+ })
495
+
496
+ Fields.enum(['admin', 'user'], { optional: true })
497
+
498
+ Fields.custom(
499
+ (value) => typeof value === 'string' && value.length > 0,
500
+ 'Custom validation message'
501
+ )
502
+ ```
503
+
504
+ #### Middleware Validation
434
505
 
435
506
  ```typescript
436
- import { validate } from '@buenojs/bueno/validation';
437
- import { z } from 'zod'; // Zod
438
- import * as v from 'valibot'; // Valibot
439
- import { type } from 'arktype'; // ArkType
507
+ import { createValidator } from '@buenojs/bueno/validation';
508
+
509
+ const validateUserInput = createValidator({
510
+ body: UserSchema,
511
+ query: QuerySchema,
512
+ params: ParamsSchema,
513
+ headers: HeadersSchema,
514
+ });
515
+
516
+ router.post('/users/:id', validateUserInput, async (ctx) => {
517
+ const user = ctx.get('validatedBody');
518
+ const params = ctx.get('validatedParams');
519
+ // All validated and typed!
520
+ });
521
+ ```
522
+
523
+ #### Optional: Use External Validators (Zod, Valibot, ArkType)
440
524
 
441
- // Zod schema
525
+ Bueno supports **any Standard Schema-compatible library**. Install your preferred validator and use it with Bueno's validation functions:
526
+
527
+ ```bash
528
+ # Install your chosen validator (optional)
529
+ bun add zod
530
+ # or
531
+ bun add valibot
532
+ # or
533
+ bun add arktype
534
+ ```
535
+
536
+ ```typescript
537
+ import { validate, validateBody } from '@buenojs/bueno/validation';
538
+ import { z } from 'zod'; // Optional, use any Standard Schema library
539
+
540
+ // Use Zod schema (or Valibot, ArkType, Typia)
442
541
  const UserSchema = z.object({
443
542
  name: z.string().min(2),
444
543
  email: z.string().email(),
445
544
  age: z.number().int().positive().optional(),
446
545
  });
447
546
 
448
- // Validate in route
547
+ // Works seamlessly with Bueno validators
449
548
  router.post('/users', async (ctx) => {
450
- const body = await ctx.body();
451
- const user = validate(body, UserSchema);
452
- // user is fully typed!
549
+ const result = await validateBody(ctx, UserSchema);
550
+
551
+ if (!result.success) {
552
+ return ctx.status(400).json({
553
+ error: 'Validation failed',
554
+ issues: result.issues
555
+ });
556
+ }
557
+
558
+ const user = result.data;
453
559
  });
454
560
  ```
455
561
 
562
+ #### Supported External Libraries
563
+
564
+ | Library | Minimum Version | Status |
565
+ |---------|-----------------|--------|
566
+ | Zod | 4.0+ | ✅ Supported |
567
+ | Valibot | 1.0+ | ✅ Supported |
568
+ | ArkType | 2.0+ | ✅ Supported |
569
+ | Typia | 7.0+ | ✅ Supported |
570
+
571
+ All libraries using the **Standard Schema** interface are supported automatically.
572
+
456
573
  ### Security
457
574
 
458
575
  Comprehensive security features out of the box.
@@ -843,14 +960,17 @@ Bueno combines the best ideas from popular frameworks while being optimized for
843
960
  | Feature | Bueno | Hono | Express | NestJS | Next.js |
844
961
  |---------|-------|------|---------|--------|---------|
845
962
  | **Runtime** | Bun | Multi | Node | Node | Node |
963
+ | **Zero Dependencies** | ✅ | ✅ | ❌ | ❌ | ❌ |
846
964
  | **Router** | ✅ | ✅ | ✅ | ✅ | ✅ |
847
965
  | **DI Container** | ✅ | ❌ | ❌ | ✅ | ❌ |
848
966
  | **Decorators** | ✅ | ❌ | ❌ | ✅ | ❌ |
967
+ | **Built-in Validation** | ✅ | ❌ | ❌ | ❌ | ❌ |
968
+ | **Built-in ORM** | ✅ | ❌ | ❌ | ❌ | ❌ |
969
+ | **Built-in Caching** | ✅ | ❌ | ❌ | ❌ | ❌ |
970
+ | **Built-in Jobs** | ✅ | ❌ | ❌ | ❌ | ❌ |
849
971
  | **SSR** | ✅ | ❌ | ❌ | ❌ | ✅ |
850
972
  | **SSG** | ✅ | ❌ | ❌ | ❌ | ✅ |
851
- | **Database** | ✅ | ❌ | ❌ | ✅ | ❌ |
852
973
  | **WebSocket** | ✅ | ✅ | Plugin | ✅ | ❌ |
853
- | **Validation** | ✅ | ✅ | Plugin | ✅ | ❌ |
854
974
  | **CLI** | ✅ | ❌ | ❌ | ✅ | ✅ |
855
975
 
856
976
  **Migration Notes:**