-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7248bf
commit ee4d40b
Showing
17 changed files
with
741 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { | ||
ArrayFiler, | ||
funRouterOptions, | ||
ParamsMethod, | ||
RequestFunction, | ||
} from "../../types.ts"; | ||
import badMethod from "../../components/util/badMethod.ts"; | ||
import notFound from "../../components/util/notFound.ts"; | ||
|
||
type InnerObj = [string, RequestFunction] | []; | ||
type InnerObjEmpty = [string, RequestFunction]; | ||
type Map = Record<number, Record<number, InnerObj[]>>; | ||
|
||
export type Atlas = [ | ||
ParamsMethod[], | ||
number[][], | ||
string[][][], | ||
RequestFunction[], | ||
ArrayFiler[1], | ||
]; | ||
export default (_o?: funRouterOptions) => (a: ArrayFiler): Atlas => | ||
( | ||
(am) => | ||
( | ||
(ob) => | ||
( | ||
(il) => | ||
( | ||
(al) => | ||
( | ||
(ul) => [am, il, al, ul, a[1]] | ||
)( | ||
il.map( | ||
(x, i) => | ||
x.map( | ||
(y) => | ||
ob[i][y].map( | ||
(z) => [z[1]], | ||
), | ||
) as [RequestFunction][][], | ||
) | ||
.flat(3) | ||
.concat(a[1].map(([_, _a, x]) => x)) | ||
.concat(notFound) | ||
.concat(badMethod), | ||
) | ||
)( | ||
il.map( | ||
(x, i) => | ||
x.map( | ||
(y) => ob[i][y].map((x) => x[0]), | ||
), | ||
) as string[][][], | ||
) | ||
)( | ||
Object.keys(ob) | ||
.map((x) => Number(x)) | ||
.map( | ||
(x) => | ||
Object | ||
.keys(ob[Number(x)]) | ||
.map((y) => Number(y)), | ||
) as [number[]], | ||
) | ||
)( | ||
Object.fromEntries( | ||
am.map((x) => a[0].filter((y) => x === y[2])) | ||
.map( | ||
(x) => | ||
((p) => | ||
Object.fromEntries( | ||
p.map( | ||
(y) => [ | ||
y, | ||
( | ||
(za) => | ||
za[0][0] === "" | ||
? za | ||
.slice(1) | ||
.reduceRight( | ||
(acc, z) => acc.concat([z]), | ||
[za[0]], | ||
) | ||
.reverse() | ||
: za | ||
)( | ||
x | ||
.reduce( | ||
(acc, z) => | ||
z[0] === y | ||
? [...acc, [z[1], z[3]]] as InnerObjEmpty[] | ||
: acc, | ||
[] as InnerObjEmpty[], | ||
), | ||
), | ||
], | ||
), | ||
))( | ||
x.map((y) => y[0]) | ||
.reduce( | ||
(acc, y) => acc.includes(y) ? acc : acc.concat([y]), | ||
[] as number[], | ||
) as number[], | ||
), | ||
) | ||
.map( | ||
(x, i) => [i, x], | ||
), | ||
) as Map, | ||
) | ||
)( | ||
a[0] | ||
.reduce((acc: ParamsMethod[], am) => | ||
acc | ||
.includes(am[2]) | ||
? acc | ||
: [...acc, am[2]], []) as ParamsMethod[], | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
ArrayFiler, | ||
funRouterOptions, | ||
RouteTypes, | ||
} from "../../types.ts"; | ||
|
||
export default (o?: funRouterOptions) => (a: RouteTypes[]): ArrayFiler => | ||
( | ||
(fl) => | ||
( | ||
(sp) => [ | ||
fl.map ( | ||
x => [x[1].split("/").length - 1,x[1],x[0],x[2]] | ||
) , | ||
sp, | ||
] | ||
)( | ||
a.filter((x) => typeof x[3] === "string") as RouteTypes[], | ||
) | ||
)( | ||
a.filter((x) => x[3] === false), | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { funRouterOptions } from "../../types.ts"; | ||
import { Atlas } from "../atlas.ts" | ||
import parser from "./parser.ts" | ||
import position from "../position.ts" | ||
|
||
|
||
export default (o?:funRouterOptions) => (atlas:Atlas) => | ||
( | ||
position => | ||
atlas[0] | ||
.map( | ||
(_,i) => | ||
o && "hasName" in o && typeof o.hasName === "string" | ||
? (p => (s:string) => p(s.slice(o!.hasName!.length -1)))(parser(o)(atlas[2][i])(position[i])(atlas[1][i])(atlas[3].length - 2)) | ||
: ( p => | ||
( | ||
n => | ||
(s:string)=> n !== -1 ? p(s.slice(n)) : p(s.slice( | ||
n = s | ||
.split("/") | ||
.filter((x) => x !== "") | ||
.reduce((acc, x, u) => u <= 1 ? acc + x.length : acc, 3) - 1) ) | ||
)( | ||
-1 | ||
) | ||
)( | ||
parser(o)(atlas[2][i])(position[i])(atlas[1][i])(atlas[3].length - 2) | ||
) | ||
) as [(s:string) => number] | ||
)( | ||
position(o) (atlas[1])(atlas[2]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
import { funRouterOptions, RouteTypes } from "../../types.ts"; | ||
|
||
export default (o?: funRouterOptions) => (max: number) => (ar: RouteTypes[]) => | ||
( | ||
(nar) => | ||
( | ||
p => | ||
( | ||
(f) => ( | ||
fa =>(s:string) => fa(p(s)) | ||
)( | ||
f(nar) | ||
) | ||
)( | ||
(ar: string[]) => | ||
(new Function(`return s=>${ | ||
ar.reduceRight( | ||
(acc, v, i) => `s.indexOf("${v}")===0?${i + max - 2}:` + acc, | ||
"-1", | ||
) | ||
}`))() as (s: string) => number, | ||
) | ||
)( | ||
o && "hasName" in o && typeof o.hasName === "string" | ||
? (s:string) => s.slice(o!.hasName!.length -1) | ||
: | ||
( | ||
n => | ||
(s:string)=> n !== -1 ? s.slice(n) : s.slice( | ||
n = s | ||
.split("/") | ||
.filter((x) => x !== "") | ||
.reduce((acc, x, u) => u <= 1 ? acc + x.length : acc, 3) - 1) | ||
)( | ||
-1 | ||
) | ||
|
||
) | ||
)( | ||
ar.map(([_, a]) => a) | ||
.sort((a, b) => b.length - a.length), | ||
); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { funRouterOptions, Atlas, RouteTypes} from "../types.ts"; | ||
import solver from "./composer/methods.ts" | ||
import specialString from "./composer/specialString.ts"; | ||
|
||
export default | ||
(o?:funRouterOptions) => | ||
(atlas:Atlas) => ( | ||
me => ( | ||
solve => | ||
atlas[4].length === 0 | ||
? (r:Request) => | ||
me(r.method) !== -1 | ||
? solve[me(r.method)](r.url) | ||
: atlas[3].length - 1 | ||
: ( | ||
(sc) => | ||
(r: Request) => | ||
( | ||
(w) => | ||
w === -1 | ||
? | ||
me(r.method) !== -1 | ||
? solve[me(r.method)](r.url) | ||
: atlas[3].length - 1 | ||
: w | ||
)( | ||
sc(r.url), | ||
) | ||
)( | ||
specialString({})(atlas[3].length - 1)( | ||
atlas[4].map((x) => [x[0], x[3], x[2], x[1]] as RouteTypes), | ||
), | ||
) | ||
)( | ||
solver (o) (atlas) | ||
) | ||
)( | ||
((a: string[]) => ((o) => (s: string) => o.indexOf(s[0]))(a.map((x) => x[0])))(atlas[0]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts"; | ||
import atlas from "../../../builder/atlas.ts"; | ||
import optimize from "../../../optimizer/optimize.ts"; | ||
import paths from "../../util/paths.ts"; | ||
import split from "../../../builder/atlas/split.ts" | ||
|
||
Deno.test( | ||
"Atlas", | ||
(_) => | ||
assertEquals( | ||
((r) => [r[0], r[1], r[2]])( | ||
atlas()(split()(optimize()(paths))), | ||
), | ||
[ | ||
[ | ||
"GET", | ||
"POST", | ||
"HEAD", | ||
"DELETE", | ||
], | ||
[ | ||
[ | ||
1, | ||
2, | ||
4, | ||
], | ||
[ | ||
1, | ||
], | ||
[ | ||
1, | ||
], | ||
[ | ||
1, | ||
], | ||
], | ||
[ | ||
[ | ||
["/", "/test"], | ||
["/test/"], | ||
["/test/:id/:name/"], | ||
], | ||
[ | ||
["/"], | ||
], | ||
[ | ||
["/"], | ||
], | ||
[ | ||
["/"], | ||
], | ||
], | ||
], | ||
), | ||
); | ||
|
||
|
Oops, something went wrong.