reverts commit 5c8a4c1edc
.
This commit is contained in:
5
dist/container.d.ts
vendored
5
dist/container.d.ts
vendored
@ -1,10 +1,5 @@
|
||||
export default class Container {
|
||||
private services;
|
||||
<<<<<<< HEAD
|
||||
set<T>(type: new (...args: any[]) => T, instance: T): void;
|
||||
get<T>(type: new (...args: any[]) => T): T;
|
||||
=======
|
||||
register<T>(name: string, factory: () => T): void;
|
||||
resolve<T>(name: string): T;
|
||||
>>>>>>> 277f5a3 (test)
|
||||
}
|
||||
|
11
dist/container.js
vendored
11
dist/container.js
vendored
@ -2,7 +2,6 @@ export default class Container {
|
||||
constructor() {
|
||||
this.services = new Map();
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
set(type, instance) {
|
||||
this.services.set(type, instance);
|
||||
}
|
||||
@ -11,15 +10,5 @@ export default class Container {
|
||||
if (!instance)
|
||||
throw new Error(`Service of type "${type.name}" not found.`);
|
||||
return instance;
|
||||
=======
|
||||
register(name, factory) {
|
||||
this.services.set(name, factory);
|
||||
}
|
||||
resolve(name) {
|
||||
const factory = this.services.get(name);
|
||||
if (!factory)
|
||||
throw new Error(`Service "${name}" not found.`);
|
||||
return factory();
|
||||
>>>>>>> 277f5a3 (test)
|
||||
}
|
||||
}
|
||||
|
9
dist/index.d.ts
vendored
9
dist/index.d.ts
vendored
@ -3,17 +3,10 @@ import Tpl from "./template.js";
|
||||
export { Router, Tpl, Request, Response, Handler };
|
||||
export default class Flummpress {
|
||||
private server?;
|
||||
private container;
|
||||
private middleware;
|
||||
router: Router;
|
||||
constructor();
|
||||
<<<<<<< HEAD
|
||||
use<T>(plugin: new (...args: any[]) => T | Router | Handler, factory?: () => T): this;
|
||||
get<T>(type: new (...args: any[]) => T): T;
|
||||
=======
|
||||
use<T>(nameOrRouter: string | Router, factory?: () => T): this;
|
||||
resolve<T>(name: string): T;
|
||||
>>>>>>> 277f5a3 (test)
|
||||
use(plugin: Router | Handler): this;
|
||||
private processPipeline;
|
||||
listen(...args: any[]): this;
|
||||
private parseRequest;
|
||||
|
37
dist/index.js
vendored
37
dist/index.js
vendored
@ -11,49 +11,20 @@ import http from "node:http";
|
||||
import { URL } from "node:url";
|
||||
import querystring from "node:querystring";
|
||||
import Router from "./router.js";
|
||||
import Container from "./container.js";
|
||||
import Tpl from "./template.js";
|
||||
export { Router, Tpl };
|
||||
export default class Flummpress {
|
||||
constructor() {
|
||||
this.container = new Container();
|
||||
this.router = new Router();
|
||||
this.middleware = [];
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
use(plugin, factory) {
|
||||
if (typeof plugin === "function" && factory)
|
||||
this.container.set(plugin, factory());
|
||||
else if (plugin instanceof Router)
|
||||
use(plugin) {
|
||||
if (plugin instanceof Router)
|
||||
this.router.use(plugin);
|
||||
else if (typeof plugin === "function") {
|
||||
if (typeof plugin === "function" && plugin.length >= 2)
|
||||
this.middleware.push(plugin);
|
||||
else
|
||||
throw new TypeError("Invalid plugin provided to use()");
|
||||
}
|
||||
=======
|
||||
use(nameOrRouter, factory) {
|
||||
if (typeof nameOrRouter === "string" && factory)
|
||||
this.container.register(nameOrRouter, factory);
|
||||
else if (nameOrRouter instanceof Router)
|
||||
this.router.use(nameOrRouter);
|
||||
>>>>>>> 277f5a3 (test)
|
||||
else
|
||||
throw new TypeError("Invalid arguments provided to use()");
|
||||
else if (typeof plugin === "function")
|
||||
this.middleware.push(plugin);
|
||||
return this;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
get(type) {
|
||||
const instance = this.container.get(type);
|
||||
if (!instance)
|
||||
throw new Error(`Service of type "${type.name}" not found.`);
|
||||
return instance;
|
||||
=======
|
||||
resolve(name) {
|
||||
return this.container.resolve(name);
|
||||
>>>>>>> 277f5a3 (test)
|
||||
}
|
||||
processPipeline(handlers, req, res) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
for (const handler of handlers) {
|
||||
|
2
dist/router.d.ts
vendored
2
dist/router.d.ts
vendored
@ -17,7 +17,7 @@ export interface Response extends ServerResponse {
|
||||
body: string;
|
||||
}) => void;
|
||||
status: (code: number) => Response;
|
||||
json: (body: any, code?: number) => void;
|
||||
json: (body: JSON, code?: number) => void;
|
||||
html: (body: string, code?: number) => void;
|
||||
redirect: (target: string, code?: number) => void;
|
||||
}
|
||||
|
Reference in New Issue
Block a user