tinny-backend 1.0.1 → 1.0.2

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.
@@ -0,0 +1,3 @@
1
+ import Server from "./Server.js";
2
+ import type { ServerReq } from "./types.js";
3
+ export default function RequestParser(req: ServerReq, server: Server): ServerReq;
@@ -0,0 +1,3 @@
1
+ import Server from "./Server.js";
2
+ import type { ServerRes, ServerReq } from "./types.js";
3
+ export default function ResponseParser(res: ServerRes, req: ServerReq, server: Server): ServerRes;
@@ -0,0 +1,33 @@
1
+ import type { ServerOptions, ServerRes, Handlers, AddOption, HandlerFun, Decorator, Logs, DirFiles } from "./types.js";
2
+ export default class Server {
3
+ private PORT;
4
+ private hostname;
5
+ private methodHandler;
6
+ private decorators;
7
+ private server;
8
+ private sessions;
9
+ private uptime;
10
+ private reqCount;
11
+ private logs;
12
+ private ServerName;
13
+ private defaultHandler;
14
+ getMethodHandlers(): Handlers[];
15
+ getDecorators(): Decorator[];
16
+ getUpTime(): number;
17
+ getReqCount(): number;
18
+ getLogs(): Logs[];
19
+ private generateKey;
20
+ private generateSession;
21
+ private getSession;
22
+ getHost(): string;
23
+ getPort(): number;
24
+ add(opt: AddOption): void;
25
+ decorate(name: string, data: any): void;
26
+ useDecorator(name: string): Decorator | null | undefined;
27
+ readDir(DIR: string, prefix: string): Promise<DirFiles | null>;
28
+ servDir(DIR: string, pref: string, middelWares?: HandlerFun[]): Promise<void>;
29
+ SendFile(res: ServerRes, FILE: string, status: number): Promise<void>;
30
+ log(message: string, type?: "error" | "message"): void;
31
+ constructor(args: ServerOptions);
32
+ listen(enableMon?: boolean, callback?: () => void): void;
33
+ }
@@ -0,0 +1,88 @@
1
+ import * as http from "http";
2
+ import Server from "./Server.js";
3
+ export type HandlerFun = (req: ServerReq, res: ServerRes) => void | Promise<void>;
4
+ export type AddOption = {
5
+ method: Methods;
6
+ path: string;
7
+ handler: HandlerFun;
8
+ middelWares?: HandlerFun[] | undefined;
9
+ next?: HandlerFun;
10
+ };
11
+ export type Logs = {
12
+ message: string;
13
+ type: "message" | "error";
14
+ date: string;
15
+ };
16
+ export type Headers = {
17
+ key: string;
18
+ value: string;
19
+ };
20
+ export type Cookie = {
21
+ key: string;
22
+ value: string;
23
+ };
24
+ export type ServerOptions = {
25
+ port?: number;
26
+ hostname?: string;
27
+ reqPerMinute?: number;
28
+ DefaultHandler?: HandlerFun;
29
+ ServerName?: string;
30
+ };
31
+ export type ServerReq = http.IncomingMessage & {
32
+ ReqUrl: URL | null;
33
+ Query: URLSearchParams;
34
+ queries: object;
35
+ body?: any;
36
+ ip: string;
37
+ server: Server;
38
+ params: Record<string, string>;
39
+ };
40
+ export type ServFiles = {
41
+ FileName: string;
42
+ prefix: string;
43
+ };
44
+ export type DirFiles = {
45
+ files: ServFiles[];
46
+ };
47
+ export type ServerRes = http.ServerResponse & {
48
+ body?: any;
49
+ ip: string;
50
+ send: (status: number, data?: any, headers?: object) => void;
51
+ sendFile: (status: number, ContentType: string, data?: any, headers?: object) => void;
52
+ isClosed: boolean;
53
+ server: Server;
54
+ coockie: (key: string, value: string) => string;
55
+ getAllCookies: () => string[];
56
+ setCookie: (name: string, value: string) => void;
57
+ getCookie: (name: string) => Cookie | null;
58
+ addCookie: (name: string, value: string) => void;
59
+ };
60
+ export type Methods = "POST" | "GET" | "PUT" | "DELETE";
61
+ export type Handlers = {
62
+ method: Methods;
63
+ path: string;
64
+ paramNames: string[];
65
+ handler: Function;
66
+ regex: RegExp;
67
+ middelWares?: HandlerFun[] | undefined;
68
+ next?: HandlerFun | undefined;
69
+ };
70
+ export type Decorator = {
71
+ name: string;
72
+ data: any;
73
+ };
74
+ export type Session = {
75
+ ip: string;
76
+ lastReq: number;
77
+ reqCount: number;
78
+ key: string;
79
+ banInterval: number;
80
+ };
81
+ export type AdminSessions = {
82
+ id: string;
83
+ ip: string;
84
+ userAgent: string;
85
+ creation: number;
86
+ isValid: boolean;
87
+ request: number;
88
+ };
@@ -0,0 +1,7 @@
1
+ import Server from "./core/Server.js";
2
+ import type { ServerOptions } from "./core/types.js";
3
+ export { Server };
4
+ export default Server;
5
+ export declare function createServer(options?: ServerOptions): Server;
6
+ export { VERSION } from "./utils/version.js";
7
+ export type { ServerOptions, ServerReq, ServerRes, AddOption, HandlerFun, Methods, Headers, Cookie, Logs, Session, AdminSessions, Decorator, DirFiles, ServFiles } from "./core/types.js";
@@ -0,0 +1,11 @@
1
+ export declare const colors: {
2
+ reset: string;
3
+ black: string;
4
+ red: string;
5
+ green: string;
6
+ yellow: string;
7
+ blue: string;
8
+ magenta: string;
9
+ cyan: string;
10
+ white: string;
11
+ };
@@ -0,0 +1 @@
1
+ export declare const VERSION = "1.0.2";
@@ -1 +1 @@
1
- export const VERSION = "1.0.1";
1
+ export const VERSION = "1.0.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinny-backend",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A lightweight and flexible backend framework built on Node.js.",
5
5
  "license": "MIT",
6
6
  "author": {