From 54a21c4159d98e343cd055aae90bc974a35bb359 Mon Sep 17 00:00:00 2001 From: mimiMonads Date: Fri, 3 Feb 2023 00:00:58 +0000 Subject: [PATCH] Alpha --- ReadMe.md | 23 +-- builder/arraySwap.ts | 48 ------ components/util/badMethod.ts | 2 +- fun.ts | 2 +- optimizer/staticFiles.ts | 2 - test/builder/arraySwap.test.ts | 79 ---------- test/builder/atlas.test.ts | 57 ------- test/builder/atlas/split.test.ts | 2 - test/builder/composer/specialString.test.ts | 2 +- test/builder/resolver.test.ts | 32 ---- test/builder/sComposer.test.ts | 2 - test/builder/sResolver.test.ts | 19 --- test/builder/stringParser.test.ts | 166 -------------------- test/optimizer/optimize1.test.ts | 51 ------ test/optimizer/response1.test.ts | 21 --- test/optimizer/static.test.ts | 19 --- 16 files changed, 8 insertions(+), 519 deletions(-) delete mode 100644 builder/arraySwap.ts delete mode 100644 test/builder/arraySwap.test.ts delete mode 100644 test/builder/atlas.test.ts delete mode 100644 test/builder/resolver.test.ts delete mode 100644 test/builder/sComposer.test.ts delete mode 100644 test/builder/sResolver.test.ts delete mode 100644 test/builder/stringParser.test.ts delete mode 100644 test/optimizer/optimize1.test.ts delete mode 100644 test/optimizer/static.test.ts diff --git a/ReadMe.md b/ReadMe.md index cad52f1..b56c7e4 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,14 +1,6 @@ # Endofunctor -Do you have any ideas? Go to discussions and tell me what you need - - -| in-progress | next | -|---------- |---------- | -| Coverage | Documentation | -| Debugging | | - - +Alpha ## About @@ -21,6 +13,7 @@ Endofunctor is: - Functional ## Benchmark + Faster than Hono / [Endofunctor vs. Hono](https://github.com/mimiMonads/hono-functor-benchmark) @@ -54,7 +47,7 @@ await serve( ## Add parameters, a query, a status, or a header! ```typescript -// the router auto-detect if you are using (parameters, querries, or Request ) unless you send the arguments out of the scope +// the router auto-detect if you are using (parameters, queries, or Request ) unless you send the arguments out of the scope // r: (arguments) => outOfScope(arguments), // you can add or remove them with "add", "delete" @@ -76,19 +69,13 @@ await serve( ## Parameters -Parameters must be chained, without gaps. - ```typescript -// valid (It is important to note that the following routes are different) + "/hello/:id" "/hello/:id/" "/hello/:id/:page/:time" "/hello/:id/:page/:time/" - -// invalid - "/hello/:id/page/:time" - "/hello/:id/page/:time/" - + "/hi/:id/page/:time" ``` diff --git a/builder/arraySwap.ts b/builder/arraySwap.ts deleted file mode 100644 index 88347aa..0000000 --- a/builder/arraySwap.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { - ArrayFiler, - ArraySwap, - funRouterOptions, - RouteTypes, -} from "../types.ts"; - -export default (o?: funRouterOptions) => (a: RouteTypes[]): ArrayFiler => - ( - (fl) => - ( - (sp) => [ - fl - .map((x) => [x[1].split("/"), x[0], x[1], x[2]]) - .map((x) => - [x[0].length - 1, x[0], x[1], x[2], x[3]] as [ - number, - string[], - RouteTypes[0], - RouteTypes[1], - RouteTypes[2], - ] - ) - .map((x) => - [ - x[0], - ((y) => - ((a) => - a.length <= 1 ? a.join("") : a[0] + a.slice(1).join("/"))( - x[1] - .filter((z) => z[0] !== y), - ))( - typeof o?.paramsStartsWith === "string" - ? o?.paramsStartsWith - : ":", - ), - x[2], - x[4], - ] as ArraySwap - ), - sp, - ] - )( - a.filter((x) => typeof x[3] === "string") as RouteTypes[], - ) - )( - a.filter((x) => x[3] === false), - ); diff --git a/components/util/badMethod.ts b/components/util/badMethod.ts index 51a2660..c7d13f9 100644 --- a/components/util/badMethod.ts +++ b/components/util/badMethod.ts @@ -1,2 +1,2 @@ export default (_: Request) => - ((re) => re)(new Response(" Method Not Allowed ", { status: 405 })); + ((re) => re)(new Response("Method Not Allowed", { status: 405 })); diff --git a/fun.ts b/fun.ts index d695988..7452da9 100644 --- a/fun.ts +++ b/fun.ts @@ -2,7 +2,7 @@ import { funRouterOptions } from "./types.ts"; import { ObjectRawResponse } from "./optimizer/types.ts"; import optimizer from "./optimizer/optimize.ts"; import atlas from "./builder/atlas.ts"; -import arraySwap from "./builder/arraySwap.ts"; + import solver from "./builder/solver.ts"; import split from "./builder/atlas/split.ts"; diff --git a/optimizer/staticFiles.ts b/optimizer/staticFiles.ts index 86a91bf..b882284 100644 --- a/optimizer/staticFiles.ts +++ b/optimizer/staticFiles.ts @@ -2,8 +2,6 @@ import { funRouterOptions } from "../types.ts"; import { ObjectRawResponseStatic } from "./types.ts"; import syncCheckDir from "./syncCheckDir.ts"; import atlas from "../builder/atlas.ts"; -import arraySwap from "../builder/arraySwap.ts"; -import resolver from "../builder/resolver.ts"; import staticPaths from "./staticPaths.ts"; import mime from "../components/util/mime.ts"; diff --git a/test/builder/arraySwap.test.ts b/test/builder/arraySwap.test.ts deleted file mode 100644 index 7e08c0a..0000000 --- a/test/builder/arraySwap.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; -import arraySwap from "../../builder/arraySwap.ts"; -import paths from "../util/paths.ts"; -import optimize from "../../optimizer/optimize.ts"; -import { funRouterOptions } from "../../types.ts"; - -Deno.test( - "arraySwap", - (_) => - assertEquals( - arraySwap()(optimize()(paths))[0].map((x) => [x[0], x[1], x[2]]), - [ - [1, "", "GET"], - [1, "test", "GET"], - [2, "test/", "GET"], - [4, "test/", "GET"], - [1, "", "POST"], - [1, "", "HEAD"], - [1, "", "DELETE"], - ], - ), -); - -Deno.test( - "arraySwap", - (_) => - assertEquals( - arraySwap({ - paramsStartsWith: "!", - })(optimize()(paths))[0].map((x) => [x[0], x[1], x[2]]), - [ - [1, "", "GET"], - [1, "test", "GET"], - [2, "test/", "GET"], - [4, "test/:id/:name/", "GET"], - [1, "", "POST"], - [1, "", "HEAD"], - [1, "", "DELETE"], - ], - ), -); -Deno.test( - "arraySwap", - ((o: funRouterOptions) => (_) => - assertEquals( - arraySwap(o)(optimize(o)(paths))[0].map((x) => [x[0], x[1], x[2]]), - [ - [1, "", "GET"], - [1, "test", "GET"], - [2, "test/", "GET"], - [4, "test/", "GET"], - [1, "", "POST"], - [1, "", "HEAD"], - [1, "", "DELETE"], - ], - ))( - { - - }, - ), -); -Deno.test( - "arraySwap", - (_) => - assertEquals( - arraySwap({ - paramsStartsWith: "!", - })(optimize()(paths))[0].map((x) => [x[0], x[1], x[2]]), - [ - [1, "", "GET"], - [1, "test", "GET"], - [2, "test/", "GET"], - [4, "test/:id/:name/", "GET"], - [1, "", "POST"], - [1, "", "HEAD"], - [1, "", "DELETE"], - ], - ), -); diff --git a/test/builder/atlas.test.ts b/test/builder/atlas.test.ts deleted file mode 100644 index 355100c..0000000 --- a/test/builder/atlas.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; -import arraySwap from "../../builder/arraySwap.ts"; -import atlas from "../../builder/atlas.ts"; -import optimize from "../../optimizer/optimize.ts"; -import paths from "../util/paths.ts"; - -Deno.test( - "Atlas", - (_) => - assertEquals( - ((r) => [r[0], r[1], r[2]])( - atlas()(arraySwap()(optimize()(paths))), - ), - [ - [ - "GET", - "POST", - "HEAD", - "DELETE", - ], - [ - [ - 1, - 2, - 4, - ], - [ - 1, - ], - [ - 1, - ], - [ - 1, - ], - ], - [ - [ - ["test", ""], - ["test/"], - ["test/"], - ], - [ - [""], - ], - [ - [""], - ], - [ - [""], - ], - ], - ], - ), -); - - \ No newline at end of file diff --git a/test/builder/atlas/split.test.ts b/test/builder/atlas/split.test.ts index a595930..4f3beb5 100644 --- a/test/builder/atlas/split.test.ts +++ b/test/builder/atlas/split.test.ts @@ -1,8 +1,6 @@ import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; -import arraySwap from "../../../builder/arraySwap.ts"; import paths from "../../util/paths.ts"; import optimize from "../../../optimizer/optimize.ts"; -import { funRouterOptions } from "../../../types.ts"; import split from "../../../builder/atlas/split.ts" Deno.test( diff --git a/test/builder/composer/specialString.test.ts b/test/builder/composer/specialString.test.ts index 205d40a..2b028c0 100644 --- a/test/builder/composer/specialString.test.ts +++ b/test/builder/composer/specialString.test.ts @@ -9,6 +9,6 @@ Deno.test( specialString({hasName: "http://localhost:8080/"})(12)([ ["GET","/",_ => new Response(),false] ])("http://localhost:8080/"), - null + 10 ) ) \ No newline at end of file diff --git a/test/builder/resolver.test.ts b/test/builder/resolver.test.ts deleted file mode 100644 index d2fb76b..0000000 --- a/test/builder/resolver.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -// import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; -// import resolver from "../../builder/resolver.ts"; -// import atlas from "../../builder/atlas.ts"; -// import paths from "../util/paths.ts"; -// import arraySwap from "../../builder/arraySwap.ts"; -// import optimize from "../../optimizer/optimize.ts"; - -// Deno.test( -// "resolver", -// _ => -// ( -// a => -// assertEquals( -// [ -// a(new Request("http://localhost:8080/notFound/")), -// a(new Request("http://localhost:8080/test")), -// a(new Request("http://localhost:8080/")), -// a(new Request("http://localhost:8080/test/2")) -// ], -// [ -// 7, -// 0, -// 1, -// 2 -// ], -// ) - -// )( -// resolver()(atlas()(arraySwap()(optimize()(paths)))), -// ) -// ) - diff --git a/test/builder/sComposer.test.ts b/test/builder/sComposer.test.ts deleted file mode 100644 index b06e4c8..0000000 --- a/test/builder/sComposer.test.ts +++ /dev/null @@ -1,2 +0,0 @@ -// import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; -// import sComposer from "../../builder/sComposer.ts" diff --git a/test/builder/sResolver.test.ts b/test/builder/sResolver.test.ts deleted file mode 100644 index 330b030..0000000 --- a/test/builder/sResolver.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -// import sResolver from "../../builder/sResolver.ts" -// import url from "../util/url.ts" -// import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; - -// // Deno.test( -// // "hello", _ => -// // assertEquals( -// // sResolver(url)[0][0](""), -// // 1 -// // ) -// // ) - -// Deno.test( -// "hello", _ => -// assertEquals( -// sResolver(url)[0][0]("test/"), -// 0 -// ) -// ) diff --git a/test/builder/stringParser.test.ts b/test/builder/stringParser.test.ts deleted file mode 100644 index 373fe44..0000000 --- a/test/builder/stringParser.test.ts +++ /dev/null @@ -1,166 +0,0 @@ -// import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; -// import stringParser from "../../builder/stringParser.ts"; -// import arraySwap from "../../builder/arraySwap.ts"; -// import atlas from "../../builder/atlas.ts"; -// import optimize from "../../optimizer/optimize.ts"; -// import paths from "../util/paths.ts"; -// import { funRouterOptions } from "../../types.ts"; - -// Deno.test( -// "StringParser", -// (_) => -// ( -// (r) => -// assertEquals( -// stringParser()(r[1])("http://localhost:8080/"), -// [1, ""], -// ) -// )( -// atlas()(arraySwap()(optimize()(paths))), -// ), -// ); -// Deno.test( -// "StringParser", -// (_) => -// ( -// (o: funRouterOptions) => -// ( -// (r) => -// assertEquals( -// stringParser(o)(r[1])("http://localhost:8080/"), -// [1, ""], -// ) -// )( -// atlas(o)(arraySwap(o)(optimize(o)(paths))), -// ) -// )( -// {} -// ), -// ); -// Deno.test( -// "StringParser", -// (_) => -// ( -// (o: funRouterOptions) => -// ( -// (r) => -// assertEquals( -// stringParser(o)(r[1])("http://localhost:8080/"), -// [1, ""], -// ) -// )( -// atlas(o)(arraySwap(o)(optimize(o)(paths))), -// ) -// )( -// { hasName: "http://localhost:8080/" }, -// ), -// ); -// Deno.test( -// "StringParser", -// (_) => -// ( -// (o: funRouterOptions) => -// ( -// (r) => -// assertEquals( -// stringParser()(r[1])("http://localhost:8080/hello"), -// [1, "hello"], -// ) -// )( -// atlas(o)(arraySwap(o)(optimize(o)(paths))), -// ) -// )( -// {}, -// ), -// ); -// Deno.test( -// "StringParser", -// (_) => -// ( -// (o: funRouterOptions) => -// ( -// (r) => -// assertEquals( -// stringParser()(r[1])("http://localhost:8080/hello"), -// [1, "hello"], -// ) -// )( -// atlas(o)(arraySwap(o)(optimize(o)(paths))), -// ) -// )( -// { hasName: "http://localhost:8080/hello" }, -// ), -// ); -// Deno.test( -// "StringParser", -// (_) => -// ( -// (o: funRouterOptions) => -// ( -// (r) => -// assertEquals( -// stringParser()(r[1])("http://localhost:8080/hello"), -// [1, "hello"], -// ) -// )( -// atlas(o)(arraySwap(o)(optimize(o)(paths))), -// ) -// )( -// {}, -// ), -// ); -// Deno.test( -// "StringParser", -// (_) => -// ( -// (o: funRouterOptions) => -// ( -// (r) => -// assertEquals( -// stringParser(o)(r[1])("http://localhost:8080/test/id/num/"), -// [4, "test/id/num/"], -// ) -// )( -// atlas(o)(arraySwap(o)(optimize(o)(paths))), -// ) -// )( -// {}, -// ), -// ); -// Deno.test( -// "StringParser", -// (_) => -// ( -// (o: funRouterOptions) => -// ( -// (r) => -// assertEquals( -// stringParser(o)(r[1])("http://localhost:8080/test/id/num/"), -// [4, "test/id/num/"], -// ) -// )( -// atlas(o)(arraySwap(o)(optimize(o)(paths))), -// ) -// )( -// {}, -// ), -// ); - -// Deno.test( -// "StringParser", -// (_) => -// ( -// (o: funRouterOptions) => -// ( -// (r) => -// assertEquals( -// stringParser(o)(r[1])("http://localhost:8080/test/id/num/"), -// [4, "test/id/num/"], -// ) -// )( -// atlas(o)(arraySwap(o)(optimize(o)(paths))), -// ) -// )( -// { hasName: "http://localhost:8080/" }, -// ), -// ); diff --git a/test/optimizer/optimize1.test.ts b/test/optimizer/optimize1.test.ts deleted file mode 100644 index 7a6ace9..0000000 --- a/test/optimizer/optimize1.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -// import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; -// import optimizer from "../../optimizer/optimize1.ts"; - -// Deno.test( -// "Params", -// (_) => -// assertEquals( -// optimizer({})([ -// { type: "response", path: "/", r: (_) => new Response("hello world") }, -// { -// type: "response", -// path: "/a/b/c/d/e/f/g/", -// r: (_) => new Response("hello world2"), -// }, -// { - -// path: "/test/:id", -// f: (f) => f.param.id, -// }, -// { - -// path: "/test", -// f: (f) => (f.query?.hello || ""), -// }, -// { - -// path: "/test/both/:id", - -// f: (f) => f.param.id + " " + (f.query?.hello || ""), -// }, -// { - -// path: "/test/mul/:a/:b/:c", - -// f: (f) => f.param.b, -// }, -// { - -// path: "/test/mul2/:a/:b/:c", - -// f: (f) => f.param.b + " " + (f.query?.e || ""), -// }, -// { - -// path: "/q", -// f: (f) => (f.query?.e || ""), -// }, -// ]), -// null -// ), -// ); diff --git a/test/optimizer/response1.test.ts b/test/optimizer/response1.test.ts index a6cd1ce..5ea7c44 100644 --- a/test/optimizer/response1.test.ts +++ b/test/optimizer/response1.test.ts @@ -1,16 +1,6 @@ import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; import response from "../../optimizer/response1.ts"; -// Deno.test( -// "Response response", -// async (_) => -// assertEquals( -// await (await (response()({ path: "/", f: (_) => "got it" })( -// new Request("http://localhost:8080/"), -// ))).text(), -// "got it", -// ), -// ); Deno.test( "Response response", @@ -24,14 +14,3 @@ Deno.test( ), ); -// Deno.test( -// "Response response", -// async (_) => -// assertEquals( -// await (await (response()({ -// path: "/hello/:id", -// r: (f) => JSON.stringify({...f.param,...f?.query}), -// })(new Request("http://localhost:8080/hello/hello?ho=hi")))).text(), -// `{"id":"hello"}`, -// ), -// ); diff --git a/test/optimizer/static.test.ts b/test/optimizer/static.test.ts deleted file mode 100644 index 8feca71..0000000 --- a/test/optimizer/static.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -// import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; -// import staticFiles from "../../optimizer/staticFiles.ts"; - -// Deno.test( -// "staticFiles", -// async (_) => -// assertEquals( -// JSON.parse( -// await (staticFiles({})({ type: "static", name: "/s", path: "./" })( -// new Request("http://localhost:8080/s/people.json"), -// )) as unknown as string, -// ), -// [ -// { "id": 1, "name": "John", "age": 23 }, -// { "id": 2, "name": "Sandra", "age": 51 }, -// { "id": 5, "name": "Devika", "age": 11 }, -// ], -// ), -// );