@buenojs/bueno 0.8.4 → 0.8.6
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/README.md +264 -17
- package/dist/cli/{index.js → bin.js} +413 -332
- package/dist/container/index.js +273 -0
- package/dist/context/index.js +219 -0
- package/dist/database/index.js +493 -0
- package/dist/frontend/index.js +7697 -0
- package/dist/graphql/index.js +2156 -0
- package/dist/health/index.js +364 -0
- package/dist/i18n/index.js +345 -0
- package/dist/index.js +9694 -5047
- package/dist/jobs/index.js +819 -0
- package/dist/lock/index.js +367 -0
- package/dist/logger/index.js +281 -0
- package/dist/metrics/index.js +289 -0
- package/dist/middleware/index.js +77 -0
- package/dist/migrations/index.js +571 -0
- package/dist/modules/index.js +3411 -0
- package/dist/notification/index.js +484 -0
- package/dist/observability/index.js +331 -0
- package/dist/openapi/index.js +795 -0
- package/dist/orm/index.js +1356 -0
- package/dist/router/index.js +886 -0
- package/dist/rpc/index.js +691 -0
- package/dist/schema/index.js +400 -0
- package/dist/telemetry/index.js +595 -0
- package/dist/template/index.js +640 -0
- package/dist/templates/index.js +640 -0
- package/dist/testing/index.js +1111 -0
- package/dist/types/index.js +60 -0
- package/llms.txt +231 -0
- package/package.json +125 -27
- package/src/cache/index.ts +2 -1
- package/src/cli/ARCHITECTURE.md +3 -3
- package/src/cli/bin.ts +2 -2
- package/src/cli/commands/build.ts +183 -165
- package/src/cli/commands/dev.ts +96 -89
- package/src/cli/commands/generate.ts +142 -111
- package/src/cli/commands/help.ts +20 -16
- package/src/cli/commands/index.ts +3 -6
- package/src/cli/commands/migration.ts +124 -105
- package/src/cli/commands/new.ts +294 -232
- package/src/cli/commands/start.ts +81 -79
- package/src/cli/core/args.ts +68 -50
- package/src/cli/core/console.ts +89 -95
- package/src/cli/core/index.ts +4 -4
- package/src/cli/core/prompt.ts +65 -62
- package/src/cli/core/spinner.ts +23 -20
- package/src/cli/index.ts +46 -38
- package/src/cli/templates/database/index.ts +37 -18
- package/src/cli/templates/database/mysql.ts +3 -3
- package/src/cli/templates/database/none.ts +2 -2
- package/src/cli/templates/database/postgresql.ts +3 -3
- package/src/cli/templates/database/sqlite.ts +3 -3
- package/src/cli/templates/deploy.ts +29 -26
- package/src/cli/templates/docker.ts +41 -30
- package/src/cli/templates/frontend/index.ts +33 -15
- package/src/cli/templates/frontend/none.ts +2 -2
- package/src/cli/templates/frontend/react.ts +18 -18
- package/src/cli/templates/frontend/solid.ts +15 -15
- package/src/cli/templates/frontend/svelte.ts +17 -17
- package/src/cli/templates/frontend/vue.ts +15 -15
- package/src/cli/templates/generators/index.ts +29 -29
- package/src/cli/templates/generators/types.ts +21 -21
- package/src/cli/templates/index.ts +6 -6
- package/src/cli/templates/project/api.ts +37 -36
- package/src/cli/templates/project/default.ts +25 -25
- package/src/cli/templates/project/fullstack.ts +28 -26
- package/src/cli/templates/project/index.ts +55 -16
- package/src/cli/templates/project/minimal.ts +17 -12
- package/src/cli/templates/project/types.ts +10 -5
- package/src/cli/templates/project/website.ts +15 -15
- package/src/cli/utils/fs.ts +55 -41
- package/src/cli/utils/index.ts +3 -3
- package/src/cli/utils/strings.ts +47 -33
- package/src/cli/utils/version.ts +14 -8
- package/src/config/env-validation.ts +100 -0
- package/src/config/env.ts +169 -41
- package/src/config/index.ts +28 -20
- package/src/config/loader.ts +25 -16
- package/src/config/merge.ts +21 -10
- package/src/config/types.ts +566 -25
- package/src/config/validation.ts +215 -7
- package/src/container/forward-ref.ts +22 -22
- package/src/container/index.ts +34 -12
- package/src/context/index.ts +11 -1
- package/src/database/index.ts +7 -190
- package/src/database/orm/builder.ts +457 -0
- package/src/database/orm/casts/index.ts +130 -0
- package/src/database/orm/casts/types.ts +25 -0
- package/src/database/orm/compiler.ts +304 -0
- package/src/database/orm/hooks/index.ts +114 -0
- package/src/database/orm/index.ts +61 -0
- package/src/database/orm/model-registry.ts +59 -0
- package/src/database/orm/model.ts +821 -0
- package/src/database/orm/relationships/base.ts +146 -0
- package/src/database/orm/relationships/belongs-to-many.ts +179 -0
- package/src/database/orm/relationships/belongs-to.ts +56 -0
- package/src/database/orm/relationships/has-many.ts +45 -0
- package/src/database/orm/relationships/has-one.ts +41 -0
- package/src/database/orm/relationships/index.ts +11 -0
- package/src/database/orm/scopes/index.ts +55 -0
- package/src/events/__tests__/event-system.test.ts +235 -0
- package/src/events/config.ts +238 -0
- package/src/events/example-usage.ts +185 -0
- package/src/events/index.ts +278 -0
- package/src/events/manager.ts +385 -0
- package/src/events/registry.ts +182 -0
- package/src/events/types.ts +124 -0
- package/src/frontend/api-routes.ts +65 -23
- package/src/frontend/bundler.ts +76 -34
- package/src/frontend/console-client.ts +2 -2
- package/src/frontend/console-stream.ts +94 -38
- package/src/frontend/dev-server.ts +94 -46
- package/src/frontend/file-router.ts +61 -19
- package/src/frontend/frameworks/index.ts +37 -10
- package/src/frontend/frameworks/react.ts +10 -8
- package/src/frontend/frameworks/solid.ts +11 -9
- package/src/frontend/frameworks/svelte.ts +15 -9
- package/src/frontend/frameworks/vue.ts +13 -11
- package/src/frontend/hmr-client.ts +12 -10
- package/src/frontend/hmr.ts +146 -103
- package/src/frontend/index.ts +14 -5
- package/src/frontend/islands.ts +41 -22
- package/src/frontend/isr.ts +59 -37
- package/src/frontend/layout.ts +36 -21
- package/src/frontend/ssr/react.ts +74 -27
- package/src/frontend/ssr/solid.ts +54 -20
- package/src/frontend/ssr/svelte.ts +48 -14
- package/src/frontend/ssr/vue.ts +50 -18
- package/src/frontend/ssr.ts +83 -39
- package/src/frontend/types.ts +91 -56
- package/src/graphql/built-in-engine.ts +598 -0
- package/src/graphql/context-builder.ts +110 -0
- package/src/graphql/decorators.ts +358 -0
- package/src/graphql/execution-pipeline.ts +227 -0
- package/src/graphql/graphql-module.ts +563 -0
- package/src/graphql/index.ts +101 -0
- package/src/graphql/metadata.ts +237 -0
- package/src/graphql/schema-builder.ts +319 -0
- package/src/graphql/subscription-handler.ts +283 -0
- package/src/graphql/types.ts +324 -0
- package/src/health/index.ts +21 -9
- package/src/i18n/engine.ts +305 -0
- package/src/i18n/index.ts +38 -0
- package/src/i18n/loader.ts +218 -0
- package/src/i18n/middleware.ts +164 -0
- package/src/i18n/negotiator.ts +162 -0
- package/src/i18n/types.ts +158 -0
- package/src/index.ts +182 -27
- package/src/jobs/drivers/memory.ts +315 -0
- package/src/jobs/drivers/redis.ts +459 -0
- package/src/jobs/index.ts +30 -0
- package/src/jobs/queue.ts +281 -0
- package/src/jobs/types.ts +295 -0
- package/src/jobs/worker.ts +380 -0
- package/src/logger/index.ts +1 -3
- package/src/logger/transports/index.ts +62 -22
- package/src/metrics/index.ts +25 -16
- package/src/migrations/index.ts +9 -0
- package/src/modules/filters.ts +13 -17
- package/src/modules/guards.ts +49 -26
- package/src/modules/index.ts +457 -299
- package/src/modules/interceptors.ts +58 -20
- package/src/modules/lazy.ts +11 -19
- package/src/modules/lifecycle.ts +15 -7
- package/src/modules/metadata.ts +15 -5
- package/src/modules/pipes.ts +94 -72
- package/src/notification/channels/base.ts +68 -0
- package/src/notification/channels/email.ts +105 -0
- package/src/notification/channels/push.ts +104 -0
- package/src/notification/channels/sms.ts +105 -0
- package/src/notification/channels/whatsapp.ts +104 -0
- package/src/notification/index.ts +48 -0
- package/src/notification/service.ts +354 -0
- package/src/notification/types.ts +344 -0
- package/src/observability/__tests__/observability.test.ts +483 -0
- package/src/observability/breadcrumbs.ts +114 -0
- package/src/observability/index.ts +136 -0
- package/src/observability/interceptor.ts +85 -0
- package/src/observability/service.ts +303 -0
- package/src/observability/trace.ts +37 -0
- package/src/observability/types.ts +196 -0
- package/src/openapi/__tests__/decorators.test.ts +335 -0
- package/src/openapi/__tests__/document-builder.test.ts +285 -0
- package/src/openapi/__tests__/route-scanner.test.ts +334 -0
- package/src/openapi/__tests__/schema-generator.test.ts +275 -0
- package/src/openapi/decorators.ts +328 -0
- package/src/openapi/document-builder.ts +274 -0
- package/src/openapi/index.ts +112 -0
- package/src/openapi/metadata.ts +112 -0
- package/src/openapi/route-scanner.ts +289 -0
- package/src/openapi/schema-generator.ts +256 -0
- package/src/openapi/swagger-module.ts +166 -0
- package/src/openapi/types.ts +398 -0
- package/src/orm/index.ts +10 -0
- package/src/rpc/index.ts +3 -1
- package/src/schema/index.ts +9 -0
- package/src/security/index.ts +15 -6
- package/src/ssg/index.ts +9 -8
- package/src/telemetry/index.ts +76 -22
- package/src/template/index.ts +7 -0
- package/src/templates/engine.ts +224 -0
- package/src/templates/index.ts +9 -0
- package/src/templates/loader.ts +331 -0
- package/src/templates/renderers/markdown.ts +212 -0
- package/src/templates/renderers/simple.ts +269 -0
- package/src/templates/types.ts +154 -0
- package/src/testing/index.ts +100 -27
- package/src/types/optional-deps.d.ts +347 -187
- package/src/validation/index.ts +92 -2
- package/src/validation/schemas.ts +536 -0
- package/tests/integration/cli.test.ts +19 -19
- package/tests/integration/fullstack.test.ts +4 -4
- package/tests/unit/cli.test.ts +1 -1
- package/tests/unit/database.test.ts +2 -72
- package/tests/unit/env-validation.test.ts +166 -0
- package/tests/unit/events.test.ts +910 -0
- package/tests/unit/graphql.test.ts +991 -0
- package/tests/unit/i18n.test.ts +455 -0
- package/tests/unit/jobs.test.ts +493 -0
- package/tests/unit/notification.test.ts +988 -0
- package/tests/unit/observability.test.ts +453 -0
- package/tests/unit/orm/builder.test.ts +323 -0
- package/tests/unit/orm/casts.test.ts +179 -0
- package/tests/unit/orm/compiler.test.ts +220 -0
- package/tests/unit/orm/eager-loading.test.ts +285 -0
- package/tests/unit/orm/hooks.test.ts +191 -0
- package/tests/unit/orm/model.test.ts +373 -0
- package/tests/unit/orm/relationships.test.ts +303 -0
- package/tests/unit/orm/scopes.test.ts +74 -0
- package/tests/unit/templates-simple.test.ts +53 -0
- package/tests/unit/templates.test.ts +454 -0
- package/tests/unit/validation.test.ts +18 -24
- 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
|
-
[](https://github.com/buenojs/bueno/actions)
|
|
6
|
-
[](https://codecov.io/gh/buenojs/bueno)
|
|
5
|
+
[](https://github.com/buenojs/bueno/actions)
|
|
6
|
+
[](https://codecov.io/gh/buenojs/bueno)
|
|
7
7
|
[](https://www.npmjs.com/package/@buenojs/bueno)
|
|
8
|
-
[](https://github.com/buenojs/bueno/blob/main/LICENSE)
|
|
9
9
|
[](https://bun.sh)
|
|
10
10
|
[](https://github.com/buenojs/bueno/graphs/commit-activity)
|
|
11
|
-
[](https://github.com/buenojs/bueno/commits/main)
|
|
11
|
+
[](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
|
|
@@ -224,6 +225,133 @@ bueno generate --help
|
|
|
224
225
|
|
|
225
226
|
## Core Features
|
|
226
227
|
|
|
228
|
+
### Background Jobs
|
|
229
|
+
Job queue system with Redis and memory drivers.
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { JobQueue, createJobQueue, startWorker } from '@buenojs/bueno/jobs';
|
|
233
|
+
|
|
234
|
+
// Create a job queue
|
|
235
|
+
const queue = createJobQueue({
|
|
236
|
+
driver: 'redis',
|
|
237
|
+
redisUrl: 'redis://localhost:6379',
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Define a job handler
|
|
241
|
+
queue.registerHandler('send-email', async (job) => {
|
|
242
|
+
const { to, subject, body } = job.data;
|
|
243
|
+
await emailService.send(to, subject, body);
|
|
244
|
+
return { success: true };
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// Start a worker
|
|
248
|
+
startWorker(queue, { concurrency: 5 });
|
|
249
|
+
|
|
250
|
+
// Add a job to the queue
|
|
251
|
+
await queue.add('send-email', {
|
|
252
|
+
to: 'user@example.com',
|
|
253
|
+
subject: 'Welcome!',
|
|
254
|
+
body: 'Thank you for joining our platform.',
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Notifications
|
|
259
|
+
Multi-channel notification system with support for email, SMS, WhatsApp, and push notifications.
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
import { NotificationService, createNotificationService, EmailChannelService } from '@buenojs/bueno/notification';
|
|
263
|
+
|
|
264
|
+
// Create notification service
|
|
265
|
+
const notificationService = createNotificationService({
|
|
266
|
+
channels: [
|
|
267
|
+
new EmailChannelService({
|
|
268
|
+
smtp: {
|
|
269
|
+
host: 'smtp.gmail.com',
|
|
270
|
+
port: 587,
|
|
271
|
+
auth: {
|
|
272
|
+
user: 'your-email@gmail.com',
|
|
273
|
+
pass: 'your-password',
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
}),
|
|
277
|
+
],
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Send a notification
|
|
281
|
+
await notificationService.send({
|
|
282
|
+
to: 'user@example.com',
|
|
283
|
+
subject: 'Welcome!',
|
|
284
|
+
body: 'Thank you for joining our platform.',
|
|
285
|
+
channel: 'email',
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Observability
|
|
290
|
+
Structured error tracking and observability integration.
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
import { createApp } from '@buenojs/bueno';
|
|
294
|
+
import { ObservabilityModule } from '@buenojs/bueno/observability';
|
|
295
|
+
|
|
296
|
+
const app = createApp(AppModule);
|
|
297
|
+
|
|
298
|
+
// Wire observability with custom reporter (e.g., Sentry)
|
|
299
|
+
const obs = ObservabilityModule.setup(app, {
|
|
300
|
+
reporter: new MyReporter(),
|
|
301
|
+
breadcrumbsSize: 20,
|
|
302
|
+
ignoreStatusCodes: [404, 401],
|
|
303
|
+
tags: { environment: 'production' },
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
await app.listen(3000);
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Metrics
|
|
310
|
+
Runtime metrics collection for memory, CPU, and event loop lag.
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
import { MetricsCollector, createMetricsCollector, toPrometheusFormat } from '@buenojs/bueno/metrics';
|
|
314
|
+
|
|
315
|
+
// Create metrics collector
|
|
316
|
+
const collector = createMetricsCollector({
|
|
317
|
+
maxHistorySize: 100,
|
|
318
|
+
measureEventLoopLag: true,
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// Collect metrics periodically
|
|
322
|
+
collector.startPeriodicCollection(5000);
|
|
323
|
+
|
|
324
|
+
// Get metrics
|
|
325
|
+
const metrics = collector.getLatest();
|
|
326
|
+
console.log(toPrometheusFormat(metrics));
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### i18n
|
|
330
|
+
Internationalization support with translation loading and locale negotiation.
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
import { I18n, createI18n, i18nMiddleware } from '@buenojs/bueno/i18n';
|
|
334
|
+
|
|
335
|
+
// Create i18n instance
|
|
336
|
+
const i18n = createI18n({
|
|
337
|
+
defaultLocale: 'en',
|
|
338
|
+
locales: ['en', 'fr', 'es'],
|
|
339
|
+
translations: {
|
|
340
|
+
en: {
|
|
341
|
+
welcome: 'Welcome!',
|
|
342
|
+
goodbye: 'Goodbye!',
|
|
343
|
+
},
|
|
344
|
+
fr: {
|
|
345
|
+
welcome: 'Bienvenue!',
|
|
346
|
+
goodbye: 'Au revoir!',
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// Use middleware
|
|
352
|
+
server.use(i18nMiddleware(i18n));
|
|
353
|
+
```
|
|
354
|
+
|
|
227
355
|
### HTTP & Routing
|
|
228
356
|
|
|
229
357
|
Bueno provides a powerful and intuitive routing system with full HTTP method support.
|
|
@@ -430,29 +558,145 @@ await schema.createTable('users', (table) => {
|
|
|
430
558
|
|
|
431
559
|
### Validation
|
|
432
560
|
|
|
433
|
-
|
|
561
|
+
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.
|
|
562
|
+
|
|
563
|
+
#### Built-in Validation (No Dependencies)
|
|
564
|
+
|
|
565
|
+
```typescript
|
|
566
|
+
import { Schema, Fields, validate, validateBody } from '@buenojs/bueno/validation';
|
|
567
|
+
|
|
568
|
+
// Define schema with built-in validators
|
|
569
|
+
const UserSchema = Schema.object({
|
|
570
|
+
name: Fields.string({ min: 1, max: 100 }),
|
|
571
|
+
email: Fields.string({ email: true }),
|
|
572
|
+
age: Fields.number({ positive: true, optional: true }),
|
|
573
|
+
role: Fields.enum(['admin', 'user', 'guest']),
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
// Validate in route
|
|
577
|
+
router.post('/users', async (ctx) => {
|
|
578
|
+
const result = await validateBody(ctx, UserSchema);
|
|
579
|
+
|
|
580
|
+
if (!result.success) {
|
|
581
|
+
return ctx.status(400).json({
|
|
582
|
+
error: 'Validation failed',
|
|
583
|
+
issues: result.issues
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const user = result.data; // Fully typed!
|
|
588
|
+
});
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
#### Built-in Field Validators
|
|
592
|
+
|
|
593
|
+
```typescript
|
|
594
|
+
import { Fields } from '@buenojs/bueno/validation';
|
|
595
|
+
|
|
596
|
+
Fields.string({
|
|
597
|
+
min: 1, // Minimum length
|
|
598
|
+
max: 255, // Maximum length
|
|
599
|
+
pattern: /regex/, // Regex validation
|
|
600
|
+
email: true, // Email format
|
|
601
|
+
url: true, // URL format
|
|
602
|
+
uuid: true, // UUID format
|
|
603
|
+
optional: true, // Allow undefined/null
|
|
604
|
+
})
|
|
605
|
+
|
|
606
|
+
Fields.number({
|
|
607
|
+
min: 0, // Minimum value
|
|
608
|
+
max: 100, // Maximum value
|
|
609
|
+
integer: true, // Must be integer
|
|
610
|
+
positive: true, // Must be > 0
|
|
611
|
+
optional: true, // Allow undefined/null
|
|
612
|
+
})
|
|
613
|
+
|
|
614
|
+
Fields.boolean({ optional: true })
|
|
615
|
+
|
|
616
|
+
Fields.array({
|
|
617
|
+
min: 1, // Minimum items
|
|
618
|
+
max: 10, // Maximum items
|
|
619
|
+
itemValidator: Fields.string(), // Validate each item
|
|
620
|
+
optional: true,
|
|
621
|
+
})
|
|
622
|
+
|
|
623
|
+
Fields.enum(['admin', 'user'], { optional: true })
|
|
624
|
+
|
|
625
|
+
Fields.custom(
|
|
626
|
+
(value) => typeof value === 'string' && value.length > 0,
|
|
627
|
+
'Custom validation message'
|
|
628
|
+
)
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
#### Middleware Validation
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
import { createValidator } from '@buenojs/bueno/validation';
|
|
635
|
+
|
|
636
|
+
const validateUserInput = createValidator({
|
|
637
|
+
body: UserSchema,
|
|
638
|
+
query: QuerySchema,
|
|
639
|
+
params: ParamsSchema,
|
|
640
|
+
headers: HeadersSchema,
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
router.post('/users/:id', validateUserInput, async (ctx) => {
|
|
644
|
+
const user = ctx.get('validatedBody');
|
|
645
|
+
const params = ctx.get('validatedParams');
|
|
646
|
+
// All validated and typed!
|
|
647
|
+
});
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
#### Optional: Use External Validators (Zod, Valibot, ArkType)
|
|
651
|
+
|
|
652
|
+
Bueno supports **any Standard Schema-compatible library**. Install your preferred validator and use it with Bueno's validation functions:
|
|
653
|
+
|
|
654
|
+
```bash
|
|
655
|
+
# Install your chosen validator (optional)
|
|
656
|
+
bun add zod
|
|
657
|
+
# or
|
|
658
|
+
bun add valibot
|
|
659
|
+
# or
|
|
660
|
+
bun add arktype
|
|
661
|
+
```
|
|
434
662
|
|
|
435
663
|
```typescript
|
|
436
|
-
import { validate } from '@buenojs/bueno/validation';
|
|
437
|
-
import { z } from 'zod';
|
|
438
|
-
import * as v from 'valibot'; // Valibot
|
|
439
|
-
import { type } from 'arktype'; // ArkType
|
|
664
|
+
import { validate, validateBody } from '@buenojs/bueno/validation';
|
|
665
|
+
import { z } from 'zod'; // Optional, use any Standard Schema library
|
|
440
666
|
|
|
441
|
-
// Zod schema
|
|
667
|
+
// Use Zod schema (or Valibot, ArkType, Typia)
|
|
442
668
|
const UserSchema = z.object({
|
|
443
669
|
name: z.string().min(2),
|
|
444
670
|
email: z.string().email(),
|
|
445
671
|
age: z.number().int().positive().optional(),
|
|
446
672
|
});
|
|
447
673
|
|
|
448
|
-
//
|
|
674
|
+
// Works seamlessly with Bueno validators
|
|
449
675
|
router.post('/users', async (ctx) => {
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
676
|
+
const result = await validateBody(ctx, UserSchema);
|
|
677
|
+
|
|
678
|
+
if (!result.success) {
|
|
679
|
+
return ctx.status(400).json({
|
|
680
|
+
error: 'Validation failed',
|
|
681
|
+
issues: result.issues
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const user = result.data;
|
|
453
686
|
});
|
|
454
687
|
```
|
|
455
688
|
|
|
689
|
+
#### Supported External Libraries
|
|
690
|
+
|
|
691
|
+
| Library | Minimum Version | Status |
|
|
692
|
+
|---------|-----------------|--------|
|
|
693
|
+
| Zod | 4.0+ | ✅ Supported |
|
|
694
|
+
| Valibot | 1.0+ | ✅ Supported |
|
|
695
|
+
| ArkType | 2.0+ | ✅ Supported |
|
|
696
|
+
| Typia | 7.0+ | ✅ Supported |
|
|
697
|
+
|
|
698
|
+
All libraries using the **Standard Schema** interface are supported automatically.
|
|
699
|
+
|
|
456
700
|
### Security
|
|
457
701
|
|
|
458
702
|
Comprehensive security features out of the box.
|
|
@@ -843,14 +1087,17 @@ Bueno combines the best ideas from popular frameworks while being optimized for
|
|
|
843
1087
|
| Feature | Bueno | Hono | Express | NestJS | Next.js |
|
|
844
1088
|
|---------|-------|------|---------|--------|---------|
|
|
845
1089
|
| **Runtime** | Bun | Multi | Node | Node | Node |
|
|
1090
|
+
| **Zero Dependencies** | ✅ | ✅ | ❌ | ❌ | ❌ |
|
|
846
1091
|
| **Router** | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
847
1092
|
| **DI Container** | ✅ | ❌ | ❌ | ✅ | ❌ |
|
|
848
1093
|
| **Decorators** | ✅ | ❌ | ❌ | ✅ | ❌ |
|
|
1094
|
+
| **Built-in Validation** | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
1095
|
+
| **Built-in ORM** | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
1096
|
+
| **Built-in Caching** | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
1097
|
+
| **Built-in Jobs** | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
849
1098
|
| **SSR** | ✅ | ❌ | ❌ | ❌ | ✅ |
|
|
850
1099
|
| **SSG** | ✅ | ❌ | ❌ | ❌ | ✅ |
|
|
851
|
-
| **Database** | ✅ | ❌ | ❌ | ✅ | ❌ |
|
|
852
1100
|
| **WebSocket** | ✅ | ✅ | Plugin | ✅ | ❌ |
|
|
853
|
-
| **Validation** | ✅ | ✅ | Plugin | ✅ | ❌ |
|
|
854
1101
|
| **CLI** | ✅ | ❌ | ❌ | ✅ | ✅ |
|
|
855
1102
|
|
|
856
1103
|
**Migration Notes:**
|
|
@@ -882,7 +1129,7 @@ bun dev
|
|
|
882
1129
|
|
|
883
1130
|
## Links
|
|
884
1131
|
|
|
885
|
-
- **Documentation**: [https://buenojs.dev](https://
|
|
1132
|
+
- **Documentation**: [https://buenojs.dev](https://bueno.github.io)
|
|
886
1133
|
- **GitHub**: [https://github.com/buenojs/bueno](https://github.com/buenojs/bueno)
|
|
887
1134
|
- **Issues**: [https://github.com/buenojs/bueno/issues](https://github.com/buenojs/bueno/issues)
|
|
888
1135
|
- **npm**: [https://www.npmjs.com/package/@buenojs/bueno](https://www.npmjs.com/package/@buenojs/bueno)
|