@grupodiariodaregiao/bunstone 0.0.27
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 +91 -0
- package/bin/cli.ts +182 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +4316 -0
- package/dist/lib/adapters/cache-adapter.d.ts +19 -0
- package/dist/lib/adapters/form-data.d.ts +4 -0
- package/dist/lib/adapters/upload-adapter.d.ts +22 -0
- package/dist/lib/app-startup.d.ts +76 -0
- package/dist/lib/components/layout.d.ts +8 -0
- package/dist/lib/constants/index.d.ts +1 -0
- package/dist/lib/controller.d.ts +14 -0
- package/dist/lib/cqrs/command-bus.d.ts +19 -0
- package/dist/lib/cqrs/cqrs-module.d.ts +2 -0
- package/dist/lib/cqrs/decorators/command-handler.decorator.d.ts +7 -0
- package/dist/lib/cqrs/decorators/event-handler.decorator.d.ts +7 -0
- package/dist/lib/cqrs/decorators/query-handler.decorator.d.ts +7 -0
- package/dist/lib/cqrs/decorators/saga.decorator.d.ts +7 -0
- package/dist/lib/cqrs/event-bus.d.ts +38 -0
- package/dist/lib/cqrs/interfaces/command.interface.d.ts +5 -0
- package/dist/lib/cqrs/interfaces/event.interface.d.ts +5 -0
- package/dist/lib/cqrs/interfaces/query.interface.d.ts +5 -0
- package/dist/lib/cqrs/query-bus.d.ts +19 -0
- package/dist/lib/database/sql-module.d.ts +25 -0
- package/dist/lib/guard.d.ts +8 -0
- package/dist/lib/http-exceptions.d.ts +73 -0
- package/dist/lib/http-methods.d.ts +36 -0
- package/dist/lib/http-params.d.ts +28 -0
- package/dist/lib/injectable.d.ts +12 -0
- package/dist/lib/interfaces/class-constructor.d.ts +6 -0
- package/dist/lib/interfaces/guard-contract.d.ts +7 -0
- package/dist/lib/jwt/jwt-module.d.ts +13 -0
- package/dist/lib/jwt.d.ts +5 -0
- package/dist/lib/module.d.ts +18 -0
- package/dist/lib/openapi.d.ts +52 -0
- package/dist/lib/render.d.ts +7 -0
- package/dist/lib/schedule/cron/cron.d.ts +7 -0
- package/dist/lib/schedule/cron/mappers/map-providers-with-cron.d.ts +8 -0
- package/dist/lib/schedule/timeout/mappers/map-providers-with-timeouts.d.ts +9 -0
- package/dist/lib/schedule/timeout/timeout.d.ts +7 -0
- package/dist/lib/types/http-request.d.ts +13 -0
- package/dist/lib/types/module-config.d.ts +14 -0
- package/dist/lib/types/options.d.ts +24 -0
- package/dist/lib/utils/colors.d.ts +36 -0
- package/dist/lib/utils/dependency-injection.d.ts +25 -0
- package/dist/lib/utils/is-class.d.ts +1 -0
- package/dist/lib/utils/is-zod-schema.d.ts +2 -0
- package/dist/lib/utils/logger.d.ts +38 -0
- package/dist/lib/utils/map-providers.d.ts +14 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Bunstone Framework
|
|
2
|
+
|
|
3
|
+
Bunstone is a high-performance, decorator-based web framework for [Bun](https://bun.sh), inspired by NestJS and built on top of [ElysiaJS](https://elysiajs.com). It brings powerful Dependency Injection, CQRS, Sagas, and modular architecture to the Bun ecosystem.
|
|
4
|
+
|
|
5
|
+
## š Quick Start
|
|
6
|
+
|
|
7
|
+
Scaffold a new project in seconds:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @diariodaregiao/bunstone my-app
|
|
11
|
+
cd my-app
|
|
12
|
+
bun dev
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## šļø Core Concepts
|
|
16
|
+
|
|
17
|
+
### Modular Architecture
|
|
18
|
+
|
|
19
|
+
Organize your application into modules using the `@Module` decorator.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
@Module({
|
|
23
|
+
imports: [UserModule, AuthModule],
|
|
24
|
+
controllers: [AppController],
|
|
25
|
+
providers: [AppService],
|
|
26
|
+
})
|
|
27
|
+
export class AppModule {}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Dependency Injection
|
|
31
|
+
|
|
32
|
+
Bunstone features a recursive DI container that handles singletons and nested dependencies automatically.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
@Injectable()
|
|
36
|
+
export class AppService {
|
|
37
|
+
getHello() {
|
|
38
|
+
return "Hello World!";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Controller()
|
|
43
|
+
export class AppController {
|
|
44
|
+
constructor(private readonly appService: AppService) {}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## š ļø Features
|
|
49
|
+
|
|
50
|
+
- **CQRS**: Built-in Command, Query, and Event buses.
|
|
51
|
+
- **Sagas**: Reactive event-to-command streams.
|
|
52
|
+
- **Guards & JWT**: Easy route protection and JWT integration.
|
|
53
|
+
- **Zod Validation**: Automatic request body/param validation.
|
|
54
|
+
- **Scheduling**: Decorator-based Cron jobs and Timeouts.
|
|
55
|
+
- **Adapters**: Built-in support for Form-Data, File Uploads, and Caching.
|
|
56
|
+
|
|
57
|
+
## š Examples
|
|
58
|
+
|
|
59
|
+
We have a set of examples demonstrating various features of the framework:
|
|
60
|
+
|
|
61
|
+
| Example | Description |
|
|
62
|
+
| --------------------------------------------------------- | ------------------------------------ |
|
|
63
|
+
| [Basic App](./examples/01-basic-app/index.ts) | Modules, Controllers, and simple DI |
|
|
64
|
+
| [Routing & Params](./examples/02-routing-params/index.ts) | Extracting data and Zod validation |
|
|
65
|
+
| [Guards & Auth](./examples/03-guards-auth/index.ts) | JWT and custom Guard implementations |
|
|
66
|
+
| [CQRS](./examples/04-cqrs/index.ts) | Command Bus and Handlers |
|
|
67
|
+
| [SQL Database](./examples/05-database-sql/index.ts) | Database registration and usage |
|
|
68
|
+
| [Scheduling](./examples/06-scheduling/index.ts) | Periodic tasks and delayed execution |
|
|
69
|
+
| [Adapters](./examples/07-adapters/index.ts) | Cache and Form-Data handling |
|
|
70
|
+
| [OpenAPI](./examples/08-openapi/index.ts) | Swagger documentation setup |
|
|
71
|
+
|
|
72
|
+
## š Documentation
|
|
73
|
+
|
|
74
|
+
Visit our [Documentation Website](https://diariodaregiao.github.io/bunstone) (if hosted) or run it locally:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
bun run docs:dev
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Guide
|
|
81
|
+
|
|
82
|
+
- [Dependency Injection](./docs/dependency-injection.md)
|
|
83
|
+
- [Routing & Parameters](./docs/routing-params.md)
|
|
84
|
+
- [CQRS & Sagas](./docs/cqrs.md)
|
|
85
|
+
- [Guards & JWT](./docs/guards-jwt.md)
|
|
86
|
+
- [Scheduling (Cron/Timeout)](./docs/scheduling.md)
|
|
87
|
+
- [Adapters](./docs/adapters/form-data.md)
|
|
88
|
+
|
|
89
|
+
## š License
|
|
90
|
+
|
|
91
|
+
MIT
|
package/bin/cli.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
let command = args[0];
|
|
8
|
+
let projectName = args[1];
|
|
9
|
+
|
|
10
|
+
// Default to "new" command if only project name is provided
|
|
11
|
+
if (command && command !== "new" && !projectName) {
|
|
12
|
+
projectName = command;
|
|
13
|
+
command = "new";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Default project name if none provided
|
|
17
|
+
if (!projectName && command === "new") {
|
|
18
|
+
projectName = "my-bunstone-app";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const projectPath = join(process.cwd(), projectName || "");
|
|
22
|
+
|
|
23
|
+
async function scaffold() {
|
|
24
|
+
if (command !== "new" || !projectName) {
|
|
25
|
+
console.log("Usage: bunstone new <project-name>");
|
|
26
|
+
console.log(" or: bunstone <project-name>");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log(`š Scaffolding new Bunstone project in ${projectPath}...`);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
await mkdir(projectPath, { recursive: true });
|
|
34
|
+
await mkdir(join(projectPath, "src"), { recursive: true });
|
|
35
|
+
await mkdir(join(projectPath, "src/controllers"), { recursive: true });
|
|
36
|
+
await mkdir(join(projectPath, "src/services"), { recursive: true });
|
|
37
|
+
|
|
38
|
+
// package.json
|
|
39
|
+
const pkg = {
|
|
40
|
+
name: projectName,
|
|
41
|
+
version: "1.0.0",
|
|
42
|
+
main: "src/main.ts",
|
|
43
|
+
scripts: {
|
|
44
|
+
start: "bun run src/main.ts",
|
|
45
|
+
dev: "bun --watch src/main.ts",
|
|
46
|
+
test: "bun test",
|
|
47
|
+
},
|
|
48
|
+
dependencies: {
|
|
49
|
+
"@diariodaregiao/bunstone": "latest",
|
|
50
|
+
"reflect-metadata": "^0.2.2",
|
|
51
|
+
zod: "^4.3.2",
|
|
52
|
+
},
|
|
53
|
+
devDependencies: {
|
|
54
|
+
"@types/bun": "latest",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
await writeFile(
|
|
59
|
+
join(projectPath, "package.json"),
|
|
60
|
+
JSON.stringify(pkg, null, 2)
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// tsconfig.json
|
|
64
|
+
const tsconfig = {
|
|
65
|
+
compilerOptions: {
|
|
66
|
+
lib: ["ESNext"],
|
|
67
|
+
module: "esnext",
|
|
68
|
+
target: "esnext",
|
|
69
|
+
moduleResolution: "bundler",
|
|
70
|
+
moduleDetection: "force",
|
|
71
|
+
allowImportingTsExtensions: true,
|
|
72
|
+
noEmit: true,
|
|
73
|
+
composite: true,
|
|
74
|
+
strict: true,
|
|
75
|
+
downlevelIteration: true,
|
|
76
|
+
skipLibCheck: true,
|
|
77
|
+
jsx: "react-jsx",
|
|
78
|
+
allowSyntheticDefaultImports: true,
|
|
79
|
+
forceConsistentCasingInFileNames: true,
|
|
80
|
+
allowJs: true,
|
|
81
|
+
types: ["bun-types"],
|
|
82
|
+
experimentalDecorators: true,
|
|
83
|
+
emitDecoratorMetadata: true,
|
|
84
|
+
baseUrl: ".",
|
|
85
|
+
paths: {
|
|
86
|
+
"@/*": ["./src/*"],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
await writeFile(
|
|
92
|
+
join(projectPath, "tsconfig.json"),
|
|
93
|
+
JSON.stringify(tsconfig, null, 2)
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// src/main.ts
|
|
97
|
+
const mainTs = `import { AppStartup } from "@diariodaregiao/bunstone";
|
|
98
|
+
import { AppModule } from "@/app.module";
|
|
99
|
+
|
|
100
|
+
async function bootstrap() {
|
|
101
|
+
const app = AppStartup.create(AppModule);
|
|
102
|
+
app.listen(3000);
|
|
103
|
+
}
|
|
104
|
+
bootstrap();
|
|
105
|
+
`;
|
|
106
|
+
|
|
107
|
+
await writeFile(join(projectPath, "src/main.ts"), mainTs);
|
|
108
|
+
|
|
109
|
+
// src/app.module.ts
|
|
110
|
+
const appModuleTs = `import { Module } from "@diariodaregiao/bunstone";
|
|
111
|
+
import { AppController } from "@/controllers/app.controller";
|
|
112
|
+
import { AppService } from "@/services/app.service";
|
|
113
|
+
|
|
114
|
+
@Module({
|
|
115
|
+
controllers: [AppController],
|
|
116
|
+
providers: [AppService],
|
|
117
|
+
})
|
|
118
|
+
export class AppModule {}
|
|
119
|
+
`;
|
|
120
|
+
|
|
121
|
+
await writeFile(join(projectPath, "src/app.module.ts"), appModuleTs);
|
|
122
|
+
|
|
123
|
+
// src/controllers/app.controller.ts
|
|
124
|
+
const controllerTs = `import { Controller, Get } from "@diariodaregiao/bunstone";
|
|
125
|
+
import { AppService } from "@/services/app.service";
|
|
126
|
+
|
|
127
|
+
@Controller()
|
|
128
|
+
export class AppController {
|
|
129
|
+
constructor(private readonly appService: AppService) {}
|
|
130
|
+
|
|
131
|
+
@Get()
|
|
132
|
+
getHello() {
|
|
133
|
+
return this.appService.getHello();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
|
|
138
|
+
await writeFile(
|
|
139
|
+
join(projectPath, "src/controllers/app.controller.ts"),
|
|
140
|
+
controllerTs
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// src/services/app.service.ts
|
|
144
|
+
const serviceTs = `import { Injectable } from "@diariodaregiao/bunstone";
|
|
145
|
+
|
|
146
|
+
@Injectable()
|
|
147
|
+
export class AppService {
|
|
148
|
+
getHello() {
|
|
149
|
+
return {
|
|
150
|
+
message: "Hello from Bunstone!",
|
|
151
|
+
timestamp: new Date().toISOString()
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
`;
|
|
156
|
+
|
|
157
|
+
await writeFile(
|
|
158
|
+
join(projectPath, "src/services/app.service.ts"),
|
|
159
|
+
serviceTs
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// .gitignore
|
|
163
|
+
await writeFile(
|
|
164
|
+
join(projectPath, ".gitignore"),
|
|
165
|
+
"node_modules\n.DS_Store\ndist\n.env\n"
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
console.log("š¦ Installing dependencies...");
|
|
169
|
+
try {
|
|
170
|
+
execSync("bun install", { cwd: projectPath, stdio: "inherit" });
|
|
171
|
+
} catch (e) {
|
|
172
|
+
console.warn("ā ļø Could not run 'bun install'. Please run it manually.");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
console.log("\nā
Project created successfully!");
|
|
176
|
+
console.log("\nNext steps:\n cd " + projectName + "\n bun dev\n");
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error("ā Error scaffolding project:", error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
scaffold();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
export * from "./lib/adapters/cache-adapter";
|
|
3
|
+
export * from "./lib/adapters/form-data";
|
|
4
|
+
export * from "./lib/adapters/upload-adapter";
|
|
5
|
+
export * from "./lib/app-startup";
|
|
6
|
+
export * from "./lib/components/layout";
|
|
7
|
+
export * from "./lib/controller";
|
|
8
|
+
export * from "./lib/cqrs/command-bus";
|
|
9
|
+
export * from "./lib/cqrs/cqrs-module";
|
|
10
|
+
export * from "./lib/cqrs/decorators/command-handler.decorator";
|
|
11
|
+
export * from "./lib/cqrs/decorators/event-handler.decorator";
|
|
12
|
+
export * from "./lib/cqrs/decorators/query-handler.decorator";
|
|
13
|
+
export * from "./lib/cqrs/decorators/saga.decorator";
|
|
14
|
+
export * from "./lib/cqrs/event-bus";
|
|
15
|
+
export { map, ofType } from "./lib/cqrs/event-bus";
|
|
16
|
+
export * from "./lib/cqrs/interfaces/command.interface";
|
|
17
|
+
export * from "./lib/cqrs/interfaces/event.interface";
|
|
18
|
+
export * from "./lib/cqrs/interfaces/query.interface";
|
|
19
|
+
export * from "./lib/cqrs/query-bus";
|
|
20
|
+
export { SqlModule, SqlService } from "./lib/database/sql-module";
|
|
21
|
+
export * from "./lib/guard";
|
|
22
|
+
export * from "./lib/http-exceptions";
|
|
23
|
+
export * from "./lib/http-methods";
|
|
24
|
+
export * from "./lib/http-params";
|
|
25
|
+
export * from "./lib/injectable";
|
|
26
|
+
export * from "./lib/jwt";
|
|
27
|
+
export * from "./lib/jwt/jwt-module";
|
|
28
|
+
export * from "./lib/module";
|
|
29
|
+
export * from "./lib/openapi";
|
|
30
|
+
export * from "./lib/render";
|
|
31
|
+
export * from "./lib/schedule/cron/cron";
|
|
32
|
+
export * from "./lib/schedule/timeout/timeout";
|
|
33
|
+
export type { HttpRequest } from "./lib/types/http-request";
|
|
34
|
+
export type { ModuleConfig } from "./lib/types/module-config";
|
|
35
|
+
export type { Options } from "./lib/types/options";
|
|
36
|
+
export * from "./lib/utils/logger";
|