riser-bob 1.0.0 → 1.1.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.
@@ -6,10 +6,18 @@ interface VerifiedUser {
6
6
  }
7
7
  type TokenVerifier = (token: string) => Promise<VerifiedUser | null> | VerifiedUser | null;
8
8
  export type AuthMode = 'cookie' | 'bearer' | 'both';
9
- export interface AuthMiddlewareOptions {
10
- mode?: AuthMode;
9
+ type CookieAuthOptions = {
10
+ mode: 'cookie';
11
+ cookieName: string;
12
+ };
13
+ type BearerAuthOptions = {
14
+ mode: 'bearer';
15
+ };
16
+ type BothAuthOptions = {
17
+ mode: 'both';
11
18
  cookieName?: string;
12
- }
19
+ };
20
+ export type AuthMiddlewareOptions = CookieAuthOptions | BearerAuthOptions | BothAuthOptions;
13
21
  export declare class AuthMiddleware {
14
22
  private readonly verifyToken;
15
23
  private readonly mode;
@@ -1,5 +1,6 @@
1
+ import type { ErrorMessages } from '../errors/errors-messages';
2
+ import type { SpongNext } from '../types/spong-middleware';
1
3
  import type { SpongRequest } from '../types/spong-request';
2
4
  import type { SpongResponse } from '../types/spong-response';
3
- type SpongNext = () => Promise<Response>;
5
+ export declare const createLoggerMiddleware: (errorMessages: ErrorMessages) => (spongReq: SpongRequest, spongRes: SpongResponse, spongNext: SpongNext) => Promise<Response>;
4
6
  export declare const loggerMiddleware: (spongReq: SpongRequest, spongRes: SpongResponse, spongNext: SpongNext) => Promise<Response>;
5
- export {};
@@ -1,8 +1,10 @@
1
- import type { SpongMiddleware } from '../types/spong-middleware';
1
+ import { ErrorMessages } from '../errors/errors-messages';
2
+ import type { SpongMiddleware, SpongNext } from '../types/spong-middleware';
2
3
  import type { SpongResponse } from '../types/spong-response';
3
- export type SpongNext = () => Promise<Response>;
4
4
  export declare class MiddlewarePipeline<Context = unknown> {
5
+ private readonly errorMessages;
5
6
  private readonly middlewares;
7
+ constructor(errorMessages?: ErrorMessages);
6
8
  use(middleware: SpongMiddleware<Context>): this;
7
9
  execute(context: Context, spongRes: SpongResponse, finalHandler: SpongNext): Promise<Response>;
8
10
  }
@@ -1,7 +1,10 @@
1
+ import type { ErrorMessages } from '../errors/errors-messages';
1
2
  import type { SpongHandler } from '../types/spong-handler';
2
3
  import { type HttpMethod } from '../types/spong-method';
3
4
  export declare class Router {
5
+ private readonly errorMessages;
4
6
  private routes;
7
+ constructor(errorMessages: ErrorMessages);
5
8
  register(method: HttpMethod, path: string, handler: SpongHandler): this;
6
9
  private matchPath;
7
10
  private compareRoutes;
@@ -1,3 +1,5 @@
1
+ import type { ErrorMessages } from '../errors/errors-messages';
1
2
  import type { Router } from '../routing/router';
3
+ import type { SocketIOIntegration } from '../types/socket-io-integration';
2
4
  import Bun from 'bun';
3
- export declare const HttpServer: (router: Router, port?: number, callback?: () => void) => Bun.Server<undefined>;
5
+ export declare const HttpServer: (router: Router, errorMessages: ErrorMessages, port?: number, callback?: () => void, socketIO?: SocketIOIntegration) => Bun.Server<import("@socket.io/bun-engine").WebSocketData>;
@@ -0,0 +1,3 @@
1
+ export interface RiserBobOptions {
2
+ funnyMode?: boolean;
3
+ }
@@ -0,0 +1,7 @@
1
+ import type { Server as SocketIOServer } from 'socket.io';
2
+ import type { Server as BunSocketEngine } from '@socket.io/bun-engine';
3
+ export type SocketIOIntegration = {
4
+ io: SocketIOServer;
5
+ engine: BunSocketEngine;
6
+ path: string;
7
+ };
@@ -1,9 +1,9 @@
1
1
  import type { SpongAuth } from './spong-auth';
2
- interface AuthenticationUser {
2
+ export interface AuthenticationUser {
3
3
  id: string;
4
4
  [key: string]: unknown;
5
5
  }
6
- export interface SpongRequest {
6
+ export interface SpongRequest<TUser extends AuthenticationUser = AuthenticationUser> {
7
7
  readonly request: Request;
8
8
  readonly method: string;
9
9
  readonly url: URL;
@@ -11,10 +11,9 @@ export interface SpongRequest {
11
11
  readonly params: Record<string, string>;
12
12
  readonly query: URLSearchParams;
13
13
  readonly headers: Headers;
14
- user?: AuthenticationUser;
14
+ user?: TUser;
15
15
  auth?: SpongAuth;
16
16
  json<T = unknown>(): Promise<T>;
17
17
  formData(): ReturnType<Response['formData']>;
18
18
  text(): Promise<string>;
19
19
  }
20
- export {};
@@ -1,5 +1,23 @@
1
- export type ValidationRule = 'required' | 'nullable' | 'string' | 'number' | 'boolean' | 'email' | 'confirmed' | `min:${number}` | `max:${number}` | `minLength:${number}` | `maxLength:${number}`;
2
- export type ValidationSchema = Record<string, ValidationRule[]>;
1
+ import { ErrorMessages } from '../errors/errors-messages';
2
+ export type ValidationRule = 'required' | 'nullable' | 'string' | 'number' | 'boolean' | 'email' | 'confirmed' | 'array' | 'url' | `enum:${string}` | `min:${number}` | `max:${number}` | `minLength:${number}` | `maxLength:${number}` | `minItems:${number}` | `maxItems:${number}`;
3
+ type BaseRule = 'required' | 'nullable';
4
+ type MinItemsRule = `minItems:${number}`;
5
+ type MaxItemsRule = `maxItems:${number}`;
6
+ type MinLengthRule = `minLength:${number}`;
7
+ type MaxLengthRule = `maxLength:${number}`;
8
+ type MinRule = `min:${number}`;
9
+ type MaxRule = `max:${number}`;
10
+ type WithConfirmed<T extends readonly unknown[]> = T | readonly [...T, 'confirmed'];
11
+ type StringRules = WithConfirmed<readonly ['string'] | readonly ['string', MinLengthRule] | readonly ['string', MaxLengthRule] | readonly ['string', MinLengthRule, MaxLengthRule] | readonly ['string', MaxLengthRule, MinLengthRule]>;
12
+ type NumberRules = WithConfirmed<readonly ['number'] | readonly ['number', MinRule] | readonly ['number', MaxRule] | readonly ['number', MinRule, MaxRule] | readonly ['number', MaxRule, MinRule]>;
13
+ type EmailRules = readonly ['email'];
14
+ type UrlRules = readonly ['url'];
15
+ type EnumRules = readonly [`enum:${string}`];
16
+ type BooleanRules = readonly ['boolean'];
17
+ type ArrayRules = readonly ['array', MinItemsRule] | readonly ['array', MaxItemsRule] | readonly ['array', MinItemsRule, MaxItemsRule] | readonly ['array', MaxItemsRule, MinItemsRule];
18
+ type TypedRules = StringRules | NumberRules | EmailRules | UrlRules | EnumRules | BooleanRules | ArrayRules;
19
+ export type FieldRules = TypedRules | readonly [BaseRule, ...TypedRules];
20
+ export type ValidationSchema = Record<string, FieldRules>;
3
21
  export type ValidationErrors = Record<string, string[]>;
4
22
  export type ValidationResult<T> = {
5
23
  valid: true;
@@ -10,6 +28,9 @@ export type ValidationResult<T> = {
10
28
  errors: ValidationErrors;
11
29
  };
12
30
  export declare class Validator {
31
+ private static errorMessages;
32
+ static configure(errorMessages: ErrorMessages): void;
13
33
  private static parseSchema;
14
34
  static validate<T>(data: Record<string, unknown>, schema: ValidationSchema): ValidationResult<T>;
15
35
  }
36
+ export {};
package/package.json CHANGED
@@ -1,58 +1,60 @@
1
- {
2
- "name": "riser-bob",
3
- "version": "1.0.0",
4
- "description": "A TypeScript backend framework built for Bun",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
13
- }
14
- },
15
- "files": [
16
- "dist",
17
- "README.md",
18
- "LICENSE"
19
- ],
20
- "bin": {
21
- "riser-bob": "./dist/cli.js"
22
- },
23
- "scripts": {
24
- "dev": "bun run --watch src/index.ts",
25
- "build": "bun run build:framework && bun run build:types && bun run build:cli",
26
- "build:framework": "bun build src/index.ts --outdir dist --target bun --minify",
27
- "build:cli": "bun build cli/index.ts --outfile dist/cli.js --target bun --minify",
28
- "build:types": "tsc -p tsconfig.build.json",
29
- "start": "bun run src/index.ts",
30
- "typecheck": "tsc --noEmit",
31
- "lint": "eslint test/",
32
- "lint:fix": "eslint test/ --fix"
33
- },
34
- "keywords": [
35
- "riser-bob",
36
- "bun",
37
- "typescript",
38
- "backend",
39
- "framework",
40
- "cli"
41
- ],
42
- "license": "MIT",
43
- "devDependencies": {
44
- "@eslint/js": "^10.0.1",
45
- "@types/bun": "^1.4.3",
46
- "eslint": "^10.13.0",
47
- "globals": "^17.13.0",
48
- "jiti": "^2.7.0",
49
- "typescript": "^5.9.3",
50
- "typescript-eslint": "^8.71.2"
51
- },
52
- "peerDependencies": {
53
- "typescript": "^5"
54
- },
55
- "dependencies": {
56
- "@riser-bob/cookie": "0.1.1"
57
- }
58
- }
1
+ {
2
+ "name": "riser-bob",
3
+ "version": "1.1.0",
4
+ "description": "A fun and fast framework powered by Bun and TypeScript, bringing simplicity and a fresh perspective to backend development. Stay in the Sponge Zone!",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "bin": {
21
+ "riser-bob": "./dist/cli.js"
22
+ },
23
+ "scripts": {
24
+ "dev": "bun run --watch src/index.ts",
25
+ "build": "bun run build:framework && bun run build:types && bun run build:cli",
26
+ "build:framework": "bun build src/index.ts --outdir dist --target bun --minify",
27
+ "build:cli": "bun build cli/index.ts --outfile dist/cli.js --target bun --minify",
28
+ "build:types": "tsc -p tsconfig.build.json",
29
+ "start": "bun run src/index.ts",
30
+ "typecheck": "tsc --noEmit",
31
+ "lint": "eslint test/",
32
+ "lint:fix": "eslint test/ --fix"
33
+ },
34
+ "keywords": [
35
+ "riser-bob",
36
+ "bun",
37
+ "typescript",
38
+ "backend",
39
+ "framework",
40
+ "cli"
41
+ ],
42
+ "license": "MIT",
43
+ "devDependencies": {
44
+ "@eslint/js": "^10.0.1",
45
+ "@types/bun": "^1.4.3",
46
+ "eslint": "^10.13.0",
47
+ "globals": "^17.13.0",
48
+ "jiti": "^2.7.0",
49
+ "typescript": "^5.9.3",
50
+ "typescript-eslint": "^8.71.2"
51
+ },
52
+ "peerDependencies": {
53
+ "typescript": "^5"
54
+ },
55
+ "dependencies": {
56
+ "@riser-bob/cookie": "0.1.1",
57
+ "@socket.io/bun-engine": "^0.1.2",
58
+ "socket.io": "^4.8.4"
59
+ }
60
+ }