Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: benjamint08/probun
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.6
Choose a base ref
...
head repository: benjamint08/probun
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
10 changes: 10 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: curl -fsSL https://bun.sh/install | bash && source /home/gitpod/.bashrc && bun --version && bun i


35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# probun
# ⚠️ This is a work in progress! Expect many new features. ⚠️
# ProBun

## Official [ProBun Docs](https://probun.p3pr.co)
> [!WARNING]
> ProBun is a work in progress, expect many new features and changes in the future.
## A better web server for Bun.
ProBun, a better web server for Bun. ProBun aims to enhance your web development experience by providing a more efficient and flexible server solution.

Check out the template project [here](https://github.com/benjamint08/probun-example) to get started and also check out the routes folder for an example. This is where you can define your routes.
You can also add folders to the routes folder to create sub-routes. Go wild- probun loads all of them.
## Features

## Test the post requests in your terminal:
- **Fast**: ProBun is built on top of Bun.serve, a fast and efficient web server created by the Bun team. ProBun aims to be over `494.31%` better than Express. [view benchmark](https://probun.dev/docs/benchmark.html)
- **TypeScript Support**: ProBun is written in TypeScript, making it easier to write type-safe code.
- **File-based Routing**: ProBun uses the file system as the routing mechanism, making it easier to manage your routes. Example:

```bash
curl -X POST http://localhost:3000/ --data '{"data":"hi"}'
```

# Installation
```typescript
// routes/index.ts - This will handle localhost:3000/
import { Context } from "probun";

To install dependencies:
export async function GET(req: Request): Promise<Response> {
const c = Context(req)

```bash
bun install probun
return c.json({ hello: "world" });
}
```

# TODO
- Add support for MongoDB out of the box
## Getting Started

This project was created using `bun init` in bun v1.1.1. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
To get started with ProBun, we recommend you to read the [installation guide](https://probun.dev/docs/getting-started.html)
30 changes: 15 additions & 15 deletions build.ts
Original file line number Diff line number Diff line change
@@ -10,20 +10,6 @@ import {parseArgs} from "util";
const dir = './lib';
if (existsSync(dir)) rmSync(dir, { recursive: true });

// Build source files
Bun.build({
format: 'esm',
target: 'bun',
outdir: './lib',
entrypoints: ['./src/main'],
minify: {
whitespace: true
},
external: Object.keys(pkg.dependencies)
});

await $`bun x tsc`;

const { values, positionals } = parseArgs({
args: Bun.argv,
options: {
@@ -39,4 +25,18 @@ if(values.version) {
pkg.version = values.version;
Bun.write('package.json', JSON.stringify(pkg, null, 2));
console.log(`Updated version to ${values.version}`);
}
}

// Build source files
Bun.build({
format: 'esm',
target: 'bun',
outdir: './lib',
entrypoints: ['./src/main'],
minify: {
whitespace: true
},
external: Object.keys(pkg.dependencies)
});

await $`bun x tsc`;
Binary file modified bun.lockb
Binary file not shown.
17 changes: 17 additions & 0 deletions lib/helpers/context.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type ContextType = {
json: (json: object, status?: number) => Promise<Response>;
pretty: (json: object, status?: number) => Promise<Response>;
text: (text: string, status?: number) => Promise<Response>;
html: (html: string, status?: number) => Promise<Response>;
error: (message: string, status?: number) => Promise<Response>;
success: (message: string, status?: number) => Promise<Response>;
redirect: (url: string, status?: number) => Promise<Response>;
sendFile: (filePath: string, status?: number) => Promise<Response>;
readHtml: (filePath: string) => Promise<string>;
query: {
get: (key: string) => string | null;
};
req: Request;
};
declare function Context(request: Request): ContextType;
export { Context, type ContextType };
5 changes: 3 additions & 2 deletions lib/helpers/helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
declare function SendJSON(json: any, status?: number): Promise<Response>;
declare function SendJSON(json: object, status?: number): Promise<Response>;
declare function Success(message: string, status?: number): Promise<Response>;
declare function SendFile(filePath: any, status?: number): Promise<Response>;
declare function Failure(message: string, status?: number): Promise<Response>;
declare function ServerFailure(message: string, status?: number): Promise<Response>;
declare function Redirect(destination: string, status?: number): Response;
declare function Html(html: string, status?: number): Response;
export { SendJSON, Success, Failure, ServerFailure, Redirect, Html };
export { SendJSON, Success, Failure, ServerFailure, Redirect, Html, SendFile };
1 change: 1 addition & 0 deletions lib/helpers/json.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function json(req: Request): Promise<Object>;
5 changes: 4 additions & 1 deletion lib/instances/mongodb.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
declare class Mongo {
private client;
private isConnected;
private tryCount;
connect(url: string): Promise<void>;
getCollection(db: string, col: string): Promise<any>;
getDatabase(db: string): Promise<any>;
update(db: string, col: string, query: any, update: any): Promise<any>;
insert(db: string, col: string, data: any): Promise<any>;
find(db: string, col: string, query: any): Promise<any[]>;
find(db: string, col: string, query: any, options: any): Promise<any[]>;
findOne(db: string, col: string, query: any): Promise<any>;
delete(db: string, col: string, query: any): Promise<any>;
deleteMany(db: string, col: string, query: any): Promise<any>;
close(): Promise<void>;
}
declare class MongoService {
1 change: 1 addition & 0 deletions lib/instances/postgres.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare class Pg {
private pool;
private isConnected;
connect(config: object): Promise<void>;
endConnection(): Promise<void>;
query(text: string, params?: any[]): Promise<any>;
6 changes: 4 additions & 2 deletions lib/main/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { SendJSON, Success, Failure, ServerFailure, Redirect, Html } from "../helpers/helper.ts";
import { SendJSON, Success, Failure, ServerFailure, Redirect, Html, SendFile } from "../helpers/helper.ts";
import { Context, type ContextType } from "../helpers/context.ts";
import { query } from "../helpers/query.ts";
import { param } from "../helpers/param.ts";
import MongoService from "../instances/mongodb.ts";
import PgService from "../instances/postgres.ts";
import { json } from "../helpers/json.ts";
declare class ProBun {
private port;
private routes;
@@ -20,4 +22,4 @@ declare class ProBun {
definePreMiddleware(middleware: any): void;
definePostMiddleware(middleware: any): void;
}
export { ProBun, SendJSON, Success, Failure, ServerFailure, Redirect, Html, query, param, MongoService, PgService };
export { ProBun, SendJSON, Success, Failure, ServerFailure, Redirect, Html, query, param, MongoService, PgService, SendFile, json, Context, type ContextType, };
Loading