@razvan11/paladin 1.0.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.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/EnvValidator.d.ts +11 -0
- package/dist/app/app.d.ts +45 -0
- package/dist/components/LayoutView.d.ts +31 -0
- package/dist/container/container.d.ts +17 -0
- package/dist/functions/asset.d.ts +31 -0
- package/dist/functions/config.d.ts +1 -0
- package/dist/functions/controller.d.ts +59 -0
- package/dist/functions/database.d.ts +1 -0
- package/dist/functions/env.d.ts +1 -0
- package/dist/functions/inject.d.ts +1 -0
- package/dist/functions/render.d.ts +28 -0
- package/dist/functions/repository.d.ts +1 -0
- package/dist/functions/service.d.ts +1 -0
- package/dist/functions/validator.d.ts +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +33831 -0
- package/dist/logger/logger.d.ts +9 -0
- package/dist/types.d.ts +3 -0
- package/dist/utils/pretty-error.d.ts +2 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Razvan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# backend_framwork
|
|
2
|
+
|
|
3
|
+
To install dependencies:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun install
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
To run:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun run index.ts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This project was created using `bun init` in bun v1.3.5. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { Server } from 'bun';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
import '../container/container';
|
|
5
|
+
type ControllerClass = new (...args: any[]) => any;
|
|
6
|
+
export interface StaticOptions {
|
|
7
|
+
/** URL path prefix (e.g., '/static') */
|
|
8
|
+
path?: string;
|
|
9
|
+
/** Root directory for static files */
|
|
10
|
+
root?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class App {
|
|
13
|
+
private app;
|
|
14
|
+
name: string;
|
|
15
|
+
private container;
|
|
16
|
+
private validators?;
|
|
17
|
+
private cors;
|
|
18
|
+
private logger;
|
|
19
|
+
constructor(name: string, cors?: string[]);
|
|
20
|
+
init(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Serve static files from a directory
|
|
23
|
+
* @param options - Static serving options
|
|
24
|
+
*/
|
|
25
|
+
serveStatic(options?: StaticOptions): this;
|
|
26
|
+
/**
|
|
27
|
+
* Register a controller with the app
|
|
28
|
+
* Reads route metadata and binds handlers to Hono
|
|
29
|
+
*/
|
|
30
|
+
registerController(ControllerClass: ControllerClass): this;
|
|
31
|
+
/**
|
|
32
|
+
* Register multiple controllers at once
|
|
33
|
+
*/
|
|
34
|
+
registerControllers(...controllers: ControllerClass[]): this;
|
|
35
|
+
/**
|
|
36
|
+
* Normalize and combine path segments
|
|
37
|
+
*/
|
|
38
|
+
private normalizePath;
|
|
39
|
+
/**
|
|
40
|
+
* Get the underlying Hono instance for advanced usage
|
|
41
|
+
*/
|
|
42
|
+
getAppInstance(): Hono;
|
|
43
|
+
run(): Promise<Server<unknown> | null>;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LayoutView Component
|
|
3
|
+
* A base HTML layout for server-side rendering React apps
|
|
4
|
+
*/
|
|
5
|
+
import type { FC, ReactNode } from 'react';
|
|
6
|
+
export interface LayoutViewProps {
|
|
7
|
+
/** Page title */
|
|
8
|
+
title: string;
|
|
9
|
+
/** Meta description for SEO */
|
|
10
|
+
description?: string;
|
|
11
|
+
/** Array of CSS stylesheet URLs */
|
|
12
|
+
styles?: string[];
|
|
13
|
+
/** Array of JavaScript file URLs */
|
|
14
|
+
scripts?: string[];
|
|
15
|
+
/** Additional class names for the body */
|
|
16
|
+
className?: string;
|
|
17
|
+
/** Page content / children */
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
/** Additional head content (meta tags, etc.) */
|
|
20
|
+
head?: ReactNode;
|
|
21
|
+
/** Inline data to pass to the client */
|
|
22
|
+
clientData?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export declare const LayoutView: FC<LayoutViewProps>;
|
|
25
|
+
/**
|
|
26
|
+
* PageLoader Component
|
|
27
|
+
* A simple loading indicator shown while the React app hydrates
|
|
28
|
+
*/
|
|
29
|
+
export declare const PageLoader: FC<{
|
|
30
|
+
message?: string;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Container } from 'inversify';
|
|
2
|
+
export declare const CONTAINER_KEYS: {
|
|
3
|
+
readonly APP_NAME: symbol;
|
|
4
|
+
readonly APP_DATABASE_URL: symbol;
|
|
5
|
+
readonly APP_URL: symbol;
|
|
6
|
+
readonly APP_SECRET: symbol;
|
|
7
|
+
readonly APP_CWD: symbol;
|
|
8
|
+
readonly APP_PUBLIC_DIR: symbol;
|
|
9
|
+
readonly APP_IS_LOCAL: symbol;
|
|
10
|
+
readonly APP_IS_DEVELOPMENT: symbol;
|
|
11
|
+
readonly APP_IS_STAGING: symbol;
|
|
12
|
+
readonly APP_IS_PRODUCTION: symbol;
|
|
13
|
+
readonly APP_DEBUG: symbol;
|
|
14
|
+
readonly APP_ENV: symbol;
|
|
15
|
+
};
|
|
16
|
+
declare const container: Container;
|
|
17
|
+
export { container };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset helper function
|
|
3
|
+
* Generates URLs for static assets from the public directory
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Set the base path for assets
|
|
7
|
+
* @param basePath - The base URL path for static assets (e.g., '/static', '/assets')
|
|
8
|
+
*/
|
|
9
|
+
export declare function setAssetBasePath(basePath: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* Get the current asset base path
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAssetBasePath(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate a URL for a static asset
|
|
16
|
+
* @param folder - The folder within the public directory (e.g., 'dist', 'images')
|
|
17
|
+
* @param filename - The filename (e.g., 'app.js', 'style.css')
|
|
18
|
+
* @returns The full URL path to the asset
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* asset('dist', 'app.js') // returns '/static/dist/app.js'
|
|
22
|
+
* asset('dist', 'style.css') // returns '/static/dist/style.css'
|
|
23
|
+
* asset('images', 'logo.png') // returns '/static/images/logo.png'
|
|
24
|
+
*/
|
|
25
|
+
export declare function asset(folder: string, filename: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Generate a URL for an asset directly in the public root
|
|
28
|
+
* @param filename - The filename
|
|
29
|
+
* @returns The full URL path
|
|
30
|
+
*/
|
|
31
|
+
export declare function publicAsset(filename: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function config(): ClassDecorator;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Context, Next } from 'hono';
|
|
2
|
+
export declare const CONTROLLER_METADATA: unique symbol;
|
|
3
|
+
export declare const ROUTES_METADATA: unique symbol;
|
|
4
|
+
export interface RouteDefinition {
|
|
5
|
+
method: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'all';
|
|
6
|
+
path: string;
|
|
7
|
+
handlerName: string | symbol;
|
|
8
|
+
middlewares: MiddlewareHandler[];
|
|
9
|
+
}
|
|
10
|
+
export type MiddlewareHandler = (c: Context, next: Next) => Promise<Response | void> | Response | void;
|
|
11
|
+
/**
|
|
12
|
+
* @controller decorator
|
|
13
|
+
* Marks a class as a controller and registers it with the DI container
|
|
14
|
+
*
|
|
15
|
+
* @param prefix - The base path for all routes in this controller (e.g., '/users')
|
|
16
|
+
*/
|
|
17
|
+
export declare function controller(prefix?: string): <T extends new (...args: any[]) => any>(constructor: T) => T;
|
|
18
|
+
/**
|
|
19
|
+
* @get decorator - Handles GET requests
|
|
20
|
+
* @param path - Route path (e.g., '/:id')
|
|
21
|
+
* @param middlewares - Optional middleware functions
|
|
22
|
+
*/
|
|
23
|
+
export declare const get: (path?: string, ...middlewares: MiddlewareHandler[]) => MethodDecorator;
|
|
24
|
+
/**
|
|
25
|
+
* @post decorator - Handles POST requests
|
|
26
|
+
* @param path - Route path
|
|
27
|
+
* @param middlewares - Optional middleware functions
|
|
28
|
+
*/
|
|
29
|
+
export declare const post: (path?: string, ...middlewares: MiddlewareHandler[]) => MethodDecorator;
|
|
30
|
+
/**
|
|
31
|
+
* @put decorator - Handles PUT requests
|
|
32
|
+
* @param path - Route path
|
|
33
|
+
* @param middlewares - Optional middleware functions
|
|
34
|
+
*/
|
|
35
|
+
export declare const put: (path?: string, ...middlewares: MiddlewareHandler[]) => MethodDecorator;
|
|
36
|
+
/**
|
|
37
|
+
* @patch decorator - Handles PATCH requests
|
|
38
|
+
* @param path - Route path
|
|
39
|
+
* @param middlewares - Optional middleware functions
|
|
40
|
+
*/
|
|
41
|
+
export declare const patch: (path?: string, ...middlewares: MiddlewareHandler[]) => MethodDecorator;
|
|
42
|
+
/**
|
|
43
|
+
* @del decorator - Handles DELETE requests
|
|
44
|
+
* @param path - Route path
|
|
45
|
+
* @param middlewares - Optional middleware functions
|
|
46
|
+
*/
|
|
47
|
+
export declare const del: (path?: string, ...middlewares: MiddlewareHandler[]) => MethodDecorator;
|
|
48
|
+
/**
|
|
49
|
+
* @options decorator - Handles OPTIONS requests
|
|
50
|
+
* @param path - Route path
|
|
51
|
+
* @param middlewares - Optional middleware functions
|
|
52
|
+
*/
|
|
53
|
+
export declare const options: (path?: string, ...middlewares: MiddlewareHandler[]) => MethodDecorator;
|
|
54
|
+
/**
|
|
55
|
+
* @all decorator - Handles all HTTP methods
|
|
56
|
+
* @param path - Route path
|
|
57
|
+
* @param middlewares - Optional middleware functions
|
|
58
|
+
*/
|
|
59
|
+
export declare const all: (path?: string, ...middlewares: MiddlewareHandler[]) => MethodDecorator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function database(): <T extends Function>(constructor: T) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function inject(identifier: string | symbol | Function): ParameterDecorator;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render utilities for server-side React rendering
|
|
3
|
+
*/
|
|
4
|
+
import type { Context } from 'hono';
|
|
5
|
+
import type { FC, ReactElement } from 'react';
|
|
6
|
+
/**
|
|
7
|
+
* Render a React component to an HTML response
|
|
8
|
+
* @param c - Hono context
|
|
9
|
+
* @param Component - React component to render
|
|
10
|
+
* @param props - Props to pass to the component
|
|
11
|
+
* @returns HTML response
|
|
12
|
+
*/
|
|
13
|
+
export declare function render<P extends object>(c: Context, Component: FC<P>, props?: P): Response;
|
|
14
|
+
/**
|
|
15
|
+
* Render a React element directly
|
|
16
|
+
* @param c - Hono context
|
|
17
|
+
* @param element - React element to render
|
|
18
|
+
* @returns HTML response
|
|
19
|
+
*/
|
|
20
|
+
export declare function renderElement(c: Context, element: ReactElement): Response;
|
|
21
|
+
/**
|
|
22
|
+
* Create a render function bound to a context
|
|
23
|
+
* Useful for cleaner controller code
|
|
24
|
+
*/
|
|
25
|
+
export declare function createRenderer(c: Context): {
|
|
26
|
+
render: <P extends object>(Component: FC<P>, props?: P) => Response;
|
|
27
|
+
renderElement: (element: ReactElement) => Response;
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function repository(): <T extends Function>(constructor: T) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function service(): <T extends Function>(constructor: T) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function validator(): ClassDecorator;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @razvan/backend_framework
|
|
3
|
+
* A Bun-based backend framework with decorators, dependency injection, and controller registration
|
|
4
|
+
*/
|
|
5
|
+
import 'reflect-metadata';
|
|
6
|
+
export { App, type StaticOptions } from './app/app';
|
|
7
|
+
export { Logger, logger } from './logger/logger';
|
|
8
|
+
export { container, CONTAINER_KEYS } from './container/container';
|
|
9
|
+
export { default as inject } from './functions/inject';
|
|
10
|
+
export { controller, get, post, put, patch, del, options, all, CONTROLLER_METADATA, ROUTES_METADATA, type RouteDefinition, type MiddlewareHandler, } from './functions/controller';
|
|
11
|
+
export { service } from './functions/service';
|
|
12
|
+
export { repository } from './functions/repository';
|
|
13
|
+
export { database } from './functions/database';
|
|
14
|
+
export { default as config } from './functions/config';
|
|
15
|
+
export { default as validator } from './functions/validator';
|
|
16
|
+
export { render, renderElement, createRenderer } from './functions/render';
|
|
17
|
+
export { LayoutView, PageLoader, type LayoutViewProps } from './components/LayoutView';
|
|
18
|
+
export { asset, publicAsset, setAssetBasePath, getAssetBasePath } from './functions/asset';
|
|
19
|
+
export type { Validator } from './types';
|