From 81629ae9061003174df261b12d6c44883849ef80 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Tue, 18 Jun 2024 11:01:50 +0100
Subject: [PATCH 01/12] Improving UI
---
src/composer/checkPetition/checkParse.ts | 23 ----------
src/composer/checkPetition/checkTool.ts | 54 ------------------------
src/composer/checkPetition/mainCheck.ts | 2 -
src/composer/compose.ts | 38 +++++++----------
src/composer/composerTools.ts | 10 +++++
src/composer/mainComposer.ts | 3 ++
src/exportable/wrap.ts | 33 ++++++++++++---
src/morphism.ts | 1 +
8 files changed, 58 insertions(+), 106 deletions(-)
delete mode 100644 src/composer/checkPetition/checkParse.ts
delete mode 100644 src/composer/checkPetition/checkTool.ts
diff --git a/src/composer/checkPetition/checkParse.ts b/src/composer/checkPetition/checkParse.ts
deleted file mode 100644
index 59c0852..0000000
--- a/src/composer/checkPetition/checkParse.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import type { Petition } from "../../morphism.ts";
-import checkTool from "./checkTool.ts";
-
-export default (elements: string[]) =>
-(remove: string[]) =>
-(add: string[]) =>
-(f: Petition): string[] =>
- (
- (filteredString: string): string[] =>
- checkTool
- .isUsingResolve(f)(
- checkTool
- .filtersBranchAndResolve(elements)(remove)(filteredString)
- .concat(add)
- .reduce(
- (acc: string[], element) =>
- acc.includes(element) === false ? acc.concat(element) : acc,
- [] as string[],
- ),
- )
- )(
- checkTool.normalize(f.f.toString()),
- );
diff --git a/src/composer/checkPetition/checkTool.ts b/src/composer/checkPetition/checkTool.ts
deleted file mode 100644
index 2ea664d..0000000
--- a/src/composer/checkPetition/checkTool.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-import type { Petition } from "../../morphism.ts";
-
-export default {
- normalize: (s: string) =>
- s.replace(/(? (elements: string[]) =>
- elements.includes("resolve")
- ? "resolve" in f ? elements : elements.filter((s) => s === "resolve")
- : elements,
-
- filtersBranchAndResolve:
- (elements: string[]) => (remove: string[]) => (filteredString: string) =>
- // First filter: Remove elements as specified and handle 'resolve.' and 'branch.' prefix cases
- elements.filter((element, index, arr) =>
- !remove.includes(element) &&
- (index === 0 ||
- (!arr[index - 1].startsWith("resolve.") &&
- !arr[index - 1].startsWith("branch.")))
- )
- // Second filter: Match elements against the code string for exact matches
- .filter((element) =>
- new RegExp(`\\b${element}\\b`).test(filteredString)
- ),
- updateListOfAddAndRemove:
- (f: Petition) =>
- (elements: string[]) =>
- (plugins: { [key: string]: any }) =>
- (
- (listOfElements) =>
- (
- (keysOnMorphisim) => ({
- add: [
- ...new Set(keysOnMorphisim.reduce(
- (acc, val) =>
- listOfElements.includes(val) ? [...acc, val] : acc,
- f.options?.add ?? [],
- )),
- ],
- remove: (f.options?.remove ?? []),
- elements: [
- ...listOfElements,
- ...Object.keys(plugins),
- ],
- })
- )(
- Object.keys(f),
- )
- )(
- [...elements],
- ),
-};
diff --git a/src/composer/checkPetition/mainCheck.ts b/src/composer/checkPetition/mainCheck.ts
index 4d8598f..ed06152 100644
--- a/src/composer/checkPetition/mainCheck.ts
+++ b/src/composer/checkPetition/mainCheck.ts
@@ -1,8 +1,6 @@
import type { Petition } from "../../morphism.ts";
import type { FunRouterOptions } from "../../options.ts";
import composerTools from "../composerTools.ts";
-import checkParse from "./checkParse.ts";
-import checkTool from "./checkTool.ts";
import checkfrom from "./checkTools.ts";
export default ((o?: FunRouterOptions) => (p: Petition) =>
diff --git a/src/composer/compose.ts b/src/composer/compose.ts
index 1891de6..a3ecae1 100644
--- a/src/composer/compose.ts
+++ b/src/composer/compose.ts
@@ -41,28 +41,20 @@ export default (o?: FunRouterOptions) =>
)(
//elements int table
{
- async: p.f.constructor.name === "AsyncFunction" ||
- (
- o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
- .some((x) =>
- elementsUsed.includes(x)
- //@ts-ignore
- ? "isAsync" in o.cyclePlugin[x] &&
- o.cyclePlugin[x].isAsync === true
- : false
- )
- ),
- asyncResolve: tools.recursiveCheckAsync(p) ||
- (
- o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
- .some((x) =>
- elementsUsed.includes(x)
- //@ts-ignore
- ? "isAsync" in o.cyclePlugin[x] &&
- o.cyclePlugin[x].isAsync === true
- : false
- )
- ),
+ async: tools.localAsync(o)(p)(elementsUsed),
+ asyncResolve: tools.recursiveCheckAsync(p)
+ // ||
+ // (
+ // o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
+ // .some((x) =>
+ // elementsUsed.includes(x)
+ // //@ts-ignore
+ // ? "isAsync" in o.cyclePlugin[x] &&
+ // o.cyclePlugin[x].isAsync === true
+ // : false
+ // )
+ // )
+ ,
headers: "headings" in p
? typeof p.headings?.headers == "string"
? {
@@ -83,3 +75,5 @@ export default (o?: FunRouterOptions) =>
))(
tools.isUsing(o)(p),
);
+
+
diff --git a/src/composer/composerTools.ts b/src/composer/composerTools.ts
index 96bf71b..185e246 100644
--- a/src/composer/composerTools.ts
+++ b/src/composer/composerTools.ts
@@ -100,4 +100,14 @@ export default {
,
]
).filter(Boolean) as string[],
+ localAsync : (o?:FunRouterOptions) => (p:Petition)=> (elementsUsed:string[]):boolean => (
+ (p.f.constructor.name === "AsyncFunction"?? false) || o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
+ .some((x) =>
+ elementsUsed.includes(x)
+ //@ts-ignore
+ ? "isAsync" in o.cyclePlugin[x] &&
+ o.cyclePlugin[x].isAsync === true
+ : false
+ )
+ ) ?? false
};
diff --git a/src/composer/mainComposer.ts b/src/composer/mainComposer.ts
index 2b5c586..99a39fc 100644
--- a/src/composer/mainComposer.ts
+++ b/src/composer/mainComposer.ts
@@ -12,6 +12,9 @@ export default (
): (routes: (Petition | fileServerPetition)[]) => RouteTypes[] =>
(ar) =>
ar
+ .filter(
+ (x) => !("active" in x && x.active === false),
+ )
.map(
(x) =>
x.type === "response"
diff --git a/src/exportable/wrap.ts b/src/exportable/wrap.ts
index e8708b2..00935e5 100644
--- a/src/exportable/wrap.ts
+++ b/src/exportable/wrap.ts
@@ -451,12 +451,25 @@ export const wrap = ((o?) => (a = []) => ({
{ ...ob, type: "base" } as Petition,
)),
- logPaths: () => void a.forEach((x) => console.log(x.path)) ?? wrap(o)(a),
+ logPaths: () =>
+ void a.forEach(
+ (x) =>
+ display({
+ method: x.method ?? "GET",
+ path: x.path,
+ ...(
+ x.active ? { active: x.active } : {}
+ ),
+ }),
+ ) ?? wrap(o)(a),
logLastCheck: () =>
- void console.log(
- a.length > 0
- ? composerTools.isUsing(o)(a[a.length - 1])
- : "This wrap is empty.",
+ void (
+ isUsing => display({
+ using: "[" + isUsing + "]",
+ isAsync: composerTools.localAsync(o)(a[a.length-1])(isUsing)
+ })
+ )(
+ composerTools.isUsing(o)(a[a.length -1])
) ??
wrap(o)(a),
handleRequest: (s: string) =>
@@ -509,3 +522,13 @@ export const wrap = ((o?) => (a = []) => ({
compose: () => vixeny(o)(a),
flatMap: (fn) => a.reduce((acc, x) => acc.union(fn(x).unwrap()), wrap(o)([])),
})) as WrapFunction;
+
+const display = (object: Object) => (
+ console.log("---"),
+ Object.entries(object).forEach(
+ ([key, value]) => (
+ console.log(`\x1b[35m${key}\x1b[0m: \x1b[38;2;255;165;0m${value}\x1b[0m`)
+ )
+ ),
+ console.log("---")
+);
diff --git a/src/morphism.ts b/src/morphism.ts
index b2b389f..e0d865c 100644
--- a/src/morphism.ts
+++ b/src/morphism.ts
@@ -480,6 +480,7 @@ export type Morphism<
AT = any,
R = any,
> = {
+ readonly active?: MO["isAPetition"] extends true ? boolean : never;
readonly resolve?: RM;
readonly branch?: BM;
readonly method?: ParamsMethod;
From 1a9e9e8726df0bdf995931fb0140a1041a6f56ef Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Tue, 18 Jun 2024 21:04:46 +0100
Subject: [PATCH 02/12] adding a new way to compose `f`
---
bunfig.toml | 2 ++
deno.json | 6 ++++++
package.json | 7 +++++-
src/composer/compose.ts | 26 +++++++++++++----------
src/composer/nativeComponents.ts | 1 +
src/exportable/wrap.ts | 3 +--
test/components/parameters/finder.test.ts | 10 ++++-----
7 files changed, 36 insertions(+), 19 deletions(-)
create mode 100644 bunfig.toml
create mode 100644 deno.json
diff --git a/bunfig.toml b/bunfig.toml
new file mode 100644
index 0000000..bea1efe
--- /dev/null
+++ b/bunfig.toml
@@ -0,0 +1,2 @@
+[install.scopes]
+"@jsr" = "https://npm.jsr.io"
diff --git a/deno.json b/deno.json
new file mode 100644
index 0000000..bc0f56f
--- /dev/null
+++ b/deno.json
@@ -0,0 +1,6 @@
+{
+ "imports": {
+ "@cross/test": "jsr:@cross/test@^0.0.9",
+ "@std/assert": "jsr:@std/assert@^0.226.0"
+ }
+}
diff --git a/package.json b/package.json
index cb87ee0..58dfbcb 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "0.1.37",
"description": "A functional router for Bun and Deno",
"main": "main.ts",
+ "type": "commonjs",
"directories": {
"test": "test"
},
@@ -32,9 +33,13 @@
"homepage": "https://vixeny.dev/",
"devDependencies": {
"bun-types": "^1.0.2",
- "mitata": "^0.1.6"
+ "mitata": "^0.1.6",
+ "@cross/test": "npm:@jsr/cross__test",
+ "@std/assert": "npm:@jsr/std__assert"
},
"peerDependencies": {
"typescript": "^5.0.0"
+ },
+ "dependencies": {
}
}
diff --git a/src/composer/compose.ts b/src/composer/compose.ts
index a3ecae1..fb445ad 100644
--- a/src/composer/compose.ts
+++ b/src/composer/compose.ts
@@ -26,17 +26,7 @@ export default (o?: FunRouterOptions) =>
}r=>${table.async || table.asyncResolve ? "await f" : "f"}(${
table.asyncResolve ? "await c" : "c"
}(${"mutable" in p ? "[r,{res: {}}]" : "r"}))`)()
- : new Function(
- `return ${table.headers ? "h=>" : ""}${
- table.async ? "f=>" : "f=>"
- }${table.asyncResolve ? "c=>" : "c=>"}${
- table.async || table.asyncResolve ? "async " : ""
- }r=> new Response(${
- table.async || table.asyncResolve ? "await f" : "f"
- }(${table.asyncResolve ? "await c" : "c"}(${
- "mutable" in p ? "[r,{res: {}}]" : "r"
- }))${table.headers ? ",h" : ""})`,
- )(),
+ : getF(table.async || table.asyncResolve)(table.headers ? true : false)(),
)
)(
//elements int table
@@ -77,3 +67,17 @@ export default (o?: FunRouterOptions) =>
);
+ //maybe of an optimization
+ const getF = (isAsync:boolean) =>
+ (hasHeaders:boolean) =>
+ isAsync
+ ? hasHeaders
+ ? //@ts-ignore
+ () => (h => f => c => async r => new Response(await f( await c(r)),h))
+ : //@ts-ignore
+ () => (f => c => async r => new Response(await f( await c(r))))
+ : hasHeaders
+ ? //@ts-ignore
+ () => (h => f => c => r => new Response(f(c(r)),h))
+ : //@ts-ignore
+ () =>(f => c => r => new Response(f(c(r))))
\ No newline at end of file
diff --git a/src/composer/nativeComponents.ts b/src/composer/nativeComponents.ts
index 61226a4..dfcb573 100644
--- a/src/composer/nativeComponents.ts
+++ b/src/composer/nativeComponents.ts
@@ -104,3 +104,4 @@ export default (o?: FunRouterOptions) =>
action: () => o!.cyclePlugin![x]!["f"](o)(f as CommonRequestMorphism),
})),
));
+
diff --git a/src/exportable/wrap.ts b/src/exportable/wrap.ts
index 00935e5..b57545c 100644
--- a/src/exportable/wrap.ts
+++ b/src/exportable/wrap.ts
@@ -529,6 +529,5 @@ const display = (object: Object) => (
([key, value]) => (
console.log(`\x1b[35m${key}\x1b[0m: \x1b[38;2;255;165;0m${value}\x1b[0m`)
)
- ),
- console.log("---")
+ )
);
diff --git a/test/components/parameters/finder.test.ts b/test/components/parameters/finder.test.ts
index 8efcdab..04c4edb 100644
--- a/test/components/parameters/finder.test.ts
+++ b/test/components/parameters/finder.test.ts
@@ -1,13 +1,13 @@
import finder from "../../../src/components/parameters/finder.ts";
-import assert from "node:assert";
-import test from "node:test";
import map from "../../../src/components/parameters/map.ts";
import type { Petition } from "../../../src/morphism.ts";
+import { test } from "@cross/test";
+import { assertEquals } from "@std/assert";
test(
"only one parameter at the end and query",
(_) => {
- assert.deepStrictEqual(
+ assertEquals(
(new Function(
` return ${
finder(
@@ -20,7 +20,7 @@ test(
id: "456",
},
),
- assert.deepStrictEqual(
+ assertEquals(
(new Function(
` return ${
finder(
@@ -34,7 +34,7 @@ test(
test: "test",
},
);
- assert.deepStrictEqual(
+ assertEquals(
(new Function(
` return ${
finder(
From a4d005880500e0f86ec27f02d9094608841ab607 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Tue, 18 Jun 2024 21:17:17 +0100
Subject: [PATCH 03/12] small tester
---
.github/workflows/deno.yml | 27 +++--------
src/composer/compose.ts | 47 +++++++------------
src/composer/composerTools.ts | 25 ++++++----
src/composer/nativeComponents.ts | 1 -
src/exportable/composer.ts | 6 +--
src/exportable/wrap.ts | 23 +++++----
.../cookieToToken/cookieToToken.test.ts | 11 +++--
test/components/cookies/cookiesParser.test.ts | 11 +++--
test/components/parameters/finder.test.ts | 4 +-
test/components/parameters/main.test.ts | 10 ++--
test/components/parameters/map.test.ts | 16 +++----
test/composer/checker/checker.test.ts | 14 +++---
test/composer/checker/checkerTool.test.ts | 20 ++++----
test/composer/morphisim.test.ts | 12 ++---
test/composer/petitions.test.ts | 17 +++----
test/exportable/composer.test.ts | 10 ++--
test/exportable/wrap.test.ts | 14 +++---
test/router/at.test.ts | 9 ++--
test/router/resolver.test.ts | 10 ++--
test/staticFile/composedPaths.test.ts | 9 ++--
test/staticFile/getDir.test.ts | 6 +--
test/staticFile/getMime.test.ts | 9 ++--
test/staticFile/main.test.ts | 14 +++---
test/staticFile/mime.test.ts | 11 +++--
test/util/slicerURL.test.ts | 6 +--
25 files changed, 165 insertions(+), 177 deletions(-)
diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml
index 80507b6..073503b 100644
--- a/.github/workflows/deno.yml
+++ b/.github/workflows/deno.yml
@@ -8,33 +8,18 @@
name: Deno
-on:
- push:
- branches: ["main"]
- pull_request:
- branches: ["main"]
-
-permissions:
- contents: read
+on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
-
steps:
- - name: Setup repo
- uses: actions/checkout@v4
-
- - name: Setup Deno
- # uses: denoland/setup-deno@v1
- uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.2
+ - uses: actions/checkout@v4
+ - uses: denoland/setup-deno@v1
with:
- deno-version: v1.x
-
+ deno-version: v1.x # Uses latest deno version 1
+ - run: deno add @cross/test @std/assert # Installs dependencies from jsr.io
+ - run: deno test -A # Runs tests
- name: Verify formatting
run: deno fmt --check
-
-
- - name: Run tests
- run: deno test -A
diff --git a/src/composer/compose.ts b/src/composer/compose.ts
index fb445ad..3bd723c 100644
--- a/src/composer/compose.ts
+++ b/src/composer/compose.ts
@@ -26,25 +26,15 @@ export default (o?: FunRouterOptions) =>
}r=>${table.async || table.asyncResolve ? "await f" : "f"}(${
table.asyncResolve ? "await c" : "c"
}(${"mutable" in p ? "[r,{res: {}}]" : "r"}))`)()
- : getF(table.async || table.asyncResolve)(table.headers ? true : false)(),
+ : getF(table.async || table.asyncResolve)(
+ table.headers ? true : false,
+ )(),
)
)(
//elements int table
{
async: tools.localAsync(o)(p)(elementsUsed),
- asyncResolve: tools.recursiveCheckAsync(p)
- // ||
- // (
- // o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
- // .some((x) =>
- // elementsUsed.includes(x)
- // //@ts-ignore
- // ? "isAsync" in o.cyclePlugin[x] &&
- // o.cyclePlugin[x].isAsync === true
- // : false
- // )
- // )
- ,
+ asyncResolve: tools.recursiveCheckAsync(p),
headers: "headings" in p
? typeof p.headings?.headers == "string"
? {
@@ -66,18 +56,17 @@ export default (o?: FunRouterOptions) =>
tools.isUsing(o)(p),
);
-
- //maybe of an optimization
- const getF = (isAsync:boolean) =>
- (hasHeaders:boolean) =>
- isAsync
- ? hasHeaders
- ? //@ts-ignore
- () => (h => f => c => async r => new Response(await f( await c(r)),h))
- : //@ts-ignore
- () => (f => c => async r => new Response(await f( await c(r))))
- : hasHeaders
- ? //@ts-ignore
- () => (h => f => c => r => new Response(f(c(r)),h))
- : //@ts-ignore
- () =>(f => c => r => new Response(f(c(r))))
\ No newline at end of file
+//maybe of an optimization
+const getF = (isAsync: boolean) => (hasHeaders: boolean) =>
+ isAsync
+ ? hasHeaders
+ //@ts-ignore
+ ? () => ((h) => (f) => (c) => async (r) =>
+ new Response(await f(await c(r)), h))
+ //@ts-ignore
+ : () => ((f) => (c) => async (r) => new Response(await f(await c(r))))
+ : hasHeaders
+ //@ts-ignore
+ ? () => ((h) => (f) => (c) => (r) => new Response(f(c(r)), h))
+ //@ts-ignore
+ : () => ((f) => (c) => (r) => new Response(f(c(r))));
diff --git a/src/composer/composerTools.ts b/src/composer/composerTools.ts
index 185e246..c02a6dd 100644
--- a/src/composer/composerTools.ts
+++ b/src/composer/composerTools.ts
@@ -100,14 +100,19 @@ export default {
,
]
).filter(Boolean) as string[],
- localAsync : (o?:FunRouterOptions) => (p:Petition)=> (elementsUsed:string[]):boolean => (
- (p.f.constructor.name === "AsyncFunction"?? false) || o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
- .some((x) =>
- elementsUsed.includes(x)
- //@ts-ignore
- ? "isAsync" in o.cyclePlugin[x] &&
- o.cyclePlugin[x].isAsync === true
- : false
- )
- ) ?? false
+ localAsync:
+ (o?: FunRouterOptions) =>
+ (p: Petition) =>
+ (elementsUsed: string[]): boolean =>
+ (
+ (p.f.constructor.name === "AsyncFunction" ?? false) ||
+ o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
+ .some((x) =>
+ elementsUsed.includes(x)
+ //@ts-ignore
+ ? "isAsync" in o.cyclePlugin[x] &&
+ o.cyclePlugin[x].isAsync === true
+ : false
+ )
+ ) ?? false,
};
diff --git a/src/composer/nativeComponents.ts b/src/composer/nativeComponents.ts
index dfcb573..61226a4 100644
--- a/src/composer/nativeComponents.ts
+++ b/src/composer/nativeComponents.ts
@@ -104,4 +104,3 @@ export default (o?: FunRouterOptions) =>
action: () => o!.cyclePlugin![x]!["f"](o)(f as CommonRequestMorphism),
})),
));
-
diff --git a/src/exportable/composer.ts b/src/exportable/composer.ts
index 7166f92..8c2e90f 100644
--- a/src/exportable/composer.ts
+++ b/src/exportable/composer.ts
@@ -31,7 +31,7 @@ export const composer = {
* @example
* Example usage: Tests the `anyRequest` composer to ensure it correctly returns the expected string.
* ```typescript
- * Deno.test("anyRequest test", () => {
+ * test("anyRequest test", () => {
*
* const returnsAny = ({
* f: () => "hello",
@@ -86,7 +86,7 @@ export const composer = {
* @example
* Example usage: Tests the handling of null and object responses through multiple scenarios.
* ```typescript
- * Deno.test("objectNullRequest test", async () => {
+ * test("objectNullRequest test", async () => {
* const objectNull = composer.objectNullRequest()({
* f: () => ({ hi: 1 }),
* })
@@ -139,7 +139,7 @@ export const composer = {
* @example
* Example usage: Tests the `petition` composer to ensure it correctly processes predefined petitions into appropriate HTTP responses.
* ```typescript
- * Deno.test("petition composer test", async () => {
+ * test("petition composer test", async () => {
*
* const commonPetition = petitions.common()({
* path: "/common",
diff --git a/src/exportable/wrap.ts b/src/exportable/wrap.ts
index b57545c..6409ada 100644
--- a/src/exportable/wrap.ts
+++ b/src/exportable/wrap.ts
@@ -464,12 +464,13 @@ export const wrap = ((o?) => (a = []) => ({
) ?? wrap(o)(a),
logLastCheck: () =>
void (
- isUsing => display({
- using: "[" + isUsing + "]",
- isAsync: composerTools.localAsync(o)(a[a.length-1])(isUsing)
- })
- )(
- composerTools.isUsing(o)(a[a.length -1])
+ (isUsing) =>
+ display({
+ using: "[" + isUsing + "]",
+ isAsync: composerTools.localAsync(o)(a[a.length - 1])(isUsing),
+ })
+ )(
+ composerTools.isUsing(o)(a[a.length - 1]),
) ??
wrap(o)(a),
handleRequest: (s: string) =>
@@ -525,9 +526,11 @@ export const wrap = ((o?) => (a = []) => ({
const display = (object: Object) => (
console.log("---"),
- Object.entries(object).forEach(
- ([key, value]) => (
- console.log(`\x1b[35m${key}\x1b[0m: \x1b[38;2;255;165;0m${value}\x1b[0m`)
+ Object.entries(object).forEach(
+ ([key, value]) => (
+ console.log(
+ `\x1b[35m${key}\x1b[0m: \x1b[38;2;255;165;0m${value}\x1b[0m`,
+ )
+ ),
)
- )
);
diff --git a/test/components/cookieToToken/cookieToToken.test.ts b/test/components/cookieToToken/cookieToToken.test.ts
index dd78325..4de084d 100644
--- a/test/components/cookieToToken/cookieToToken.test.ts
+++ b/test/components/cookieToToken/cookieToToken.test.ts
@@ -1,5 +1,6 @@
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
+
import signSha256 from "../../../src/components/jwt/signSha256.mjs";
import { wrap } from "../../../main.ts";
@@ -35,7 +36,7 @@ const hiRequest = new Request("http://localhost:3000/", {
});
test("jwt signing with an element", async () => {
- assert.deepStrictEqual(
+ assertEquals(
await wrap()()
.stdPetition({
path: "/",
@@ -49,7 +50,7 @@ test("jwt signing with an element", async () => {
});
test("jwt signing with an invalid request", async () => {
- assert.deepStrictEqual(
+ assertEquals(
await wrap()()
.stdPetition({
path: "/",
@@ -63,7 +64,7 @@ test("jwt signing with an invalid request", async () => {
});
test("jwt signing with a valid request but not using the right cookie", async () => {
- assert.deepStrictEqual(
+ assertEquals(
await wrap()()
.stdPetition({
path: "/",
diff --git a/test/components/cookies/cookiesParser.test.ts b/test/components/cookies/cookiesParser.test.ts
index 1966eb4..0cecdf2 100644
--- a/test/components/cookies/cookiesParser.test.ts
+++ b/test/components/cookies/cookiesParser.test.ts
@@ -1,27 +1,28 @@
// Import assertEquals from Deno's standard library for assertion
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
import { body } from "../../../src/components/cookies/cookieBodyParser.ts";
+import { test } from "@cross/test";
-Deno.test("Test single cookie extraction", () => {
+test("Test single cookie extraction", () => {
const testCookies = "sessionToken=abc123";
const result = body(["sessionToken"])(testCookies);
assertEquals(result, { sessionToken: "abc123" });
});
-Deno.test("Test multiple cookie extraction", () => {
+test("Test multiple cookie extraction", () => {
const testCookies = "sessionToken=abc123,userId=456def";
const result = body(["sessionToken", "userId"])(testCookies);
assertEquals(result, { sessionToken: "abc123", userId: "456def" });
});
-Deno.test("Test with empty input array", () => {
+test("Test with empty input array", () => {
const testCookies = "sessionToken=abc123";
const result = body([])(testCookies);
assertEquals(result, {}); // Expecting an empty object since no cookie names were provided
});
// Optionally, add more complex scenarios or edge cases
-Deno.test("Test with non-existent cookies", () => {
+test("Test with non-existent cookies", () => {
const testCookies = "sessionToken=abc123";
const result = body(["nonExistent"])(testCookies);
assertEquals(result, { nonExistent: null }); // Should return null for non-existent cookie keys
diff --git a/test/components/parameters/finder.test.ts b/test/components/parameters/finder.test.ts
index 04c4edb..d0db1d9 100644
--- a/test/components/parameters/finder.test.ts
+++ b/test/components/parameters/finder.test.ts
@@ -20,7 +20,7 @@ test(
id: "456",
},
),
- assertEquals(
+ assertEquals(
(new Function(
` return ${
finder(
@@ -34,7 +34,7 @@ test(
test: "test",
},
);
- assertEquals(
+ assertEquals(
(new Function(
` return ${
finder(
diff --git a/test/components/parameters/main.test.ts b/test/components/parameters/main.test.ts
index a0a2952..9638c29 100644
--- a/test/components/parameters/main.test.ts
+++ b/test/components/parameters/main.test.ts
@@ -1,7 +1,7 @@
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
import mainParameters from "../../../src/components/parameters/mainParameters.ts";
import { petitions, plugins } from "../../../main.ts";
-
+import { test } from "@cross/test";
const base = "http://hello.com";
const options = plugins.globalOptions({
@@ -10,7 +10,7 @@ const options = plugins.globalOptions({
},
});
-Deno.test("parameters unique", () => {
+test("parameters unique", () => {
assertEquals(
mainParameters()(
petitions.common()({
@@ -107,7 +107,7 @@ Deno.test("parameters unique", () => {
);
});
-Deno.test("parameters single", () => {
+test("parameters single", () => {
assertEquals(
mainParameters()(
petitions.common()({
@@ -176,7 +176,7 @@ Deno.test("parameters single", () => {
);
});
-Deno.test("parameters multiple", () => {
+test("parameters multiple", () => {
assertEquals(
mainParameters()(
petitions.common()({
diff --git a/test/components/parameters/map.test.ts b/test/components/parameters/map.test.ts
index b9b1cdf..ad04b98 100644
--- a/test/components/parameters/map.test.ts
+++ b/test/components/parameters/map.test.ts
@@ -1,12 +1,12 @@
import map from "../../../src/components/parameters/map.ts";
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
import type { Petition } from "../../../src/morphism.ts";
test(
"only one parameter at the end",
(_) => {
- assert.deepStrictEqual(
+ assertEquals(
map({})({ path: "/test/:id", f: (_) => "hello" } as Petition),
{
elements: [
@@ -27,7 +27,7 @@ test(
startsWith: ":",
},
);
- assert.deepStrictEqual(
+ assertEquals(
map({})({ path: "/test/:id/", f: (_) => "hello" } as Petition),
{
elements: [
@@ -48,7 +48,7 @@ test(
startsWith: ":",
},
),
- assert.deepStrictEqual(
+ assertEquals(
map({})({ path: "/test/:id/hi", f: (_) => "hello" } as Petition),
{
elements: [
@@ -71,7 +71,7 @@ test(
startsWith: ":",
},
),
- assert.deepStrictEqual(
+ assertEquals(
map({})({ path: "/test/:id/hi/", f: (_) => "hello" } as Petition),
{
elements: [
@@ -94,7 +94,7 @@ test(
startsWith: ":",
},
),
- assert.deepStrictEqual(
+ assertEquals(
map({})({ path: "/test/:id/:test", f: (_) => "hello" } as Petition),
{
elements: [
@@ -118,7 +118,7 @@ test(
startsWith: ":",
},
),
- assert.deepStrictEqual(
+ assertEquals(
map({})({ path: "/:test/:id/:hi", f: (_) => "hello" } as Petition),
{
elements: [
diff --git a/test/composer/checker/checker.test.ts b/test/composer/checker/checker.test.ts
index 4f88625..a4a18df 100644
--- a/test/composer/checker/checker.test.ts
+++ b/test/composer/checker/checker.test.ts
@@ -1,7 +1,7 @@
import mainCheck from "../../../src/composer/checkPetition/mainCheck.ts";
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
import { type Petition, petitions } from "../../../src/morphism.ts";
-
+import { test } from "@cross/test";
const pluginHello = {
name: Symbol.for("hello"),
isFunction: true,
@@ -23,7 +23,7 @@ const opt = {
};
// Test
-Deno.test("check behaviour", async () => {
+test("check behaviour", async () => {
assertEquals(
mainCheck()(
petitions.common()({
@@ -44,7 +44,7 @@ Deno.test("check behaviour", async () => {
);
});
-Deno.test("check only behaviour", async () => {
+test("check only behaviour", async () => {
assertEquals(
mainCheck()(
petitions.common()({
@@ -128,7 +128,7 @@ Deno.test("check only behaviour", async () => {
);
});
-Deno.test("check remove behaviour", async () => {
+test("check remove behaviour", async () => {
assertEquals(
mainCheck()(
petitions.common()({
@@ -182,7 +182,7 @@ Deno.test("check remove behaviour", async () => {
);
});
-Deno.test("check remove behaviour", async () => {
+test("check remove behaviour", async () => {
assertEquals(
mainCheck()(
petitions.common()({
@@ -224,7 +224,7 @@ Deno.test("check remove behaviour", async () => {
);
});
-Deno.test("check plugins", async () => {
+test("check plugins", async () => {
assertEquals(
mainCheck(opt)(
petitions.common(opt)({
diff --git a/test/composer/checker/checkerTool.test.ts b/test/composer/checker/checkerTool.test.ts
index 093d55d..3766d90 100644
--- a/test/composer/checker/checkerTool.test.ts
+++ b/test/composer/checker/checkerTool.test.ts
@@ -1,8 +1,8 @@
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
import validator from "../../../src/composer/checkPetition/checkTools.ts";
import { petitions } from "../../../main.ts";
import type { Petition } from "../../../src/morphism.ts";
-
+import { test } from "@cross/test";
function testingSomething(ctx: string) {
return ctx;
}
@@ -10,19 +10,19 @@ function testingSomething2() {
return "hello";
}
-Deno.test("Should return 'ctx' for single parameter arrow function", () => {
+test("Should return 'ctx' for single parameter arrow function", () => {
assertEquals(validator.getArgsname((ctx) => ctx.params), "ctx");
});
-Deno.test("Should return 'ctx' for named function with parameters", () => {
+test("Should return 'ctx' for named function with parameters", () => {
assertEquals(validator.getArgsname(testingSomething), "ctx");
});
-Deno.test("Should return an array of params for destructured parameters", () => {
+test("Should return an array of params for destructured parameters", () => {
assertEquals(validator.getArgsname(({ params }) => params), ["params"]);
});
-Deno.test("Should return an array of params for destructured parameters", () => {
+test("Should return an array of params for destructured parameters", () => {
assertEquals(
validator.getArgsname(
(petitions.resolve()({
@@ -33,7 +33,7 @@ Deno.test("Should return an array of params for destructured parameters", () =>
);
});
-Deno.test("Should return an array of multiple params for complex destructured function", () => {
+test("Should return an array of multiple params for complex destructured function", () => {
assertEquals(
validator.getArgsname(function ({ params, hello, hi }) {
return hi + params + hello;
@@ -42,11 +42,11 @@ Deno.test("Should return an array of multiple params for complex destructured fu
);
});
-Deno.test("Should return null for no parameter arrow function", () => {
+test("Should return null for no parameter arrow function", () => {
assertEquals(validator.getArgsname(() => "string"), null);
});
-Deno.test("Should return null for no parameter standard function", () => {
+test("Should return null for no parameter standard function", () => {
assertEquals(
validator.getArgsname(function () {
return "string";
@@ -55,6 +55,6 @@ Deno.test("Should return null for no parameter standard function", () => {
);
});
-Deno.test("Should return null for no parameter named standard function", () => {
+test("Should return null for no parameter named standard function", () => {
assertEquals(validator.getArgsname(testingSomething2), null);
});
diff --git a/test/composer/morphisim.test.ts b/test/composer/morphisim.test.ts
index dd0b373..08e756b 100644
--- a/test/composer/morphisim.test.ts
+++ b/test/composer/morphisim.test.ts
@@ -1,8 +1,8 @@
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
import resolve from "../../src/composer/resolve/main.ts";
import branch from "../../src/composer/branch/branchMain.ts";
import { petitions } from "../../src/morphism.ts";
-
+import { test } from "@cross/test";
// Resolve
const nestedResolve = petitions.resolve()({
@@ -39,7 +39,7 @@ const asyncNestedBranch = petitions.branch()({
});
// Test
-Deno.test("sync resolve", async () => {
+test("sync resolve", async () => {
const map = await resolve()("test")({
nestedResolve: nestedResolve,
sync: syncResolve,
@@ -48,7 +48,7 @@ Deno.test("sync resolve", async () => {
assertEquals(map.sync, map.nestedResolve);
});
-Deno.test("async resolve", async () => {
+test("async resolve", async () => {
const map = await resolve()("test")({
nestedResolve: asyncResolve,
})(
@@ -63,7 +63,7 @@ Deno.test("async resolve", async () => {
// Branch
-Deno.test("sync branch", async () => {
+test("sync branch", async () => {
const map = await branch()("test")({
sync: nestedBranch,
})(new Request("http://test/"));
@@ -71,7 +71,7 @@ Deno.test("sync branch", async () => {
assertEquals(map.sync("sync"), "sync");
});
-Deno.test("async branch", async () => {
+test("async branch", async () => {
const map = await branch()("test")({
async: asyncNestedBranch,
})(
diff --git a/test/composer/petitions.test.ts b/test/composer/petitions.test.ts
index f3d695e..7f53471 100644
--- a/test/composer/petitions.test.ts
+++ b/test/composer/petitions.test.ts
@@ -1,4 +1,5 @@
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
import compose from "../../src/composer/compose.ts";
import { petitions } from "../../src/morphism.ts";
@@ -32,7 +33,7 @@ const getString = petitions.branch()({
f: ({ args }) => args,
});
-Deno.test("base case", async () => {
+test("base case", async () => {
const base = await compose()({
type: "base",
path: "/",
@@ -59,7 +60,7 @@ Deno.test("base case", async () => {
assertEquals(baseWithHeadings.headers.get("content-type"), "text/html");
});
-Deno.test("base case with resolve", async () => {
+test("base case with resolve", async () => {
const baseResponse = petitions.common()({
path: "/",
resolve: {
@@ -76,7 +77,7 @@ Deno.test("base case with resolve", async () => {
assertEquals(base.status, 200);
});
-Deno.test("base case with async resolve", async () => {
+test("base case with async resolve", async () => {
const baseResponse = petitions.common()({
path: "/",
resolve: {
@@ -98,7 +99,7 @@ Deno.test("base case with async resolve", async () => {
assertEquals(base.status, 200);
});
-Deno.test("standard case", async () => {
+test("standard case", async () => {
const base = await compose()({
type: "request",
path: "/",
@@ -109,7 +110,7 @@ Deno.test("standard case", async () => {
assertEquals(base.status, 200);
});
-Deno.test("standard case with resolve", async () => {
+test("standard case with resolve", async () => {
const baseResponse = petitions.standard()({
path: "/",
resolve: {
@@ -126,7 +127,7 @@ Deno.test("standard case with resolve", async () => {
assertEquals(base.status, 200);
});
-Deno.test("standard case with resolve", async () => {
+test("standard case with resolve", async () => {
const baseResponse = petitions.standard()({
path: "/",
resolve: {
@@ -152,7 +153,7 @@ Deno.test("standard case with resolve", async () => {
assertEquals(base.status, 200);
});
-Deno.test("standard case with async resolve", async () => {
+test("standard case with async resolve", async () => {
const baseResponse = petitions.standard()({
path: "/",
resolve: {
diff --git a/test/exportable/composer.test.ts b/test/exportable/composer.test.ts
index 0bd5b4f..35f3b1b 100644
--- a/test/exportable/composer.test.ts
+++ b/test/exportable/composer.test.ts
@@ -1,7 +1,7 @@
import { composer, plugins } from "../../main.ts";
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
import { petitions } from "../../main.ts";
-
+import { test } from "@cross/test";
const dummyRequest = new Request("http://heyINeedTOGoToSleep.com/");
const opt = plugins.globalOptions({
cyclePlugin: {
@@ -29,7 +29,7 @@ const requestPetition = petitions.standard()({
f: (ctx) => new Response("standard"),
});
-Deno.test("exportable composer any", async () => {
+test("exportable composer any", async () => {
assertEquals(
composer.anyRequest()({
f: () => "hello",
@@ -50,7 +50,7 @@ Deno.test("exportable composer any", async () => {
);
});
-Deno.test("exportable composer ObjectNull", async () => {
+test("exportable composer ObjectNull", async () => {
assertEquals(
composer.objectNullRequest()({
f: () => ({ hi: 1 }),
@@ -79,7 +79,7 @@ Deno.test("exportable composer ObjectNull", async () => {
);
});
-Deno.test("exportable composer petition", async () => {
+test("exportable composer petition", async () => {
assertEquals(
await Promise.resolve(composer.petition()(commonPetition)(dummyRequest))
.then((x) => x.text()),
diff --git a/test/exportable/wrap.test.ts b/test/exportable/wrap.test.ts
index 639ba3d..56c6917 100644
--- a/test/exportable/wrap.test.ts
+++ b/test/exportable/wrap.test.ts
@@ -1,8 +1,8 @@
import { petitions, wrap } from "../../main.ts";
import { plugins } from "../../main.ts";
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
import type { Petition } from "../../src/morphism.ts";
-
+import { test } from "@cross/test";
const normalPetition = petitions.common()({
path: "/addAny",
f: () => "addAny",
@@ -61,7 +61,7 @@ const wrapped = wrap(
const serve = wrapped.testRequests();
-Deno.test("wrap checking std", async () => {
+test("wrap checking std", async () => {
assertEquals(
await serve(
new Request("http://example.com/stdHello"),
@@ -80,7 +80,7 @@ Deno.test("wrap checking std", async () => {
);
});
-Deno.test("wrap checking custom", async () => {
+test("wrap checking custom", async () => {
assertEquals(
await serve(
new Request("http://example.com/customHello"),
@@ -99,7 +99,7 @@ Deno.test("wrap checking custom", async () => {
);
});
-Deno.test("wrap checking withoutCTX", async () => {
+test("wrap checking withoutCTX", async () => {
assertEquals(
await serve(
new Request("http://example.com/withoutCTX"),
@@ -110,7 +110,7 @@ Deno.test("wrap checking withoutCTX", async () => {
);
});
-Deno.test("wrap checking addAny", async () => {
+test("wrap checking addAny", async () => {
assertEquals(
await serve(
new Request("http://example.com/addAny"),
@@ -121,7 +121,7 @@ Deno.test("wrap checking addAny", async () => {
);
});
-Deno.test("wrap monoidal properties", async () => {
+test("wrap monoidal properties", async () => {
const identity = wrap({})();
const f = () => "test";
diff --git a/test/router/at.test.ts b/test/router/at.test.ts
index c72691c..6d5eec7 100644
--- a/test/router/at.test.ts
+++ b/test/router/at.test.ts
@@ -1,5 +1,6 @@
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
+
import { wrap } from "../../main.ts";
const wrapAt4 = wrap({
@@ -28,12 +29,12 @@ const req = new Request(base + "/hello");
const param = new Request(base + "/hello/hello");
test("Router checking `at`", async () => {
- assert.strictEqual(
+ assertEquals(
await serve(req).then((x) => x.text()),
"from inside",
);
- assert.strictEqual(
+ assertEquals(
await serve(param).then((x) => x.text()),
"hello",
);
diff --git a/test/router/resolver.test.ts b/test/router/resolver.test.ts
index 15efa18..02331dc 100644
--- a/test/router/resolver.test.ts
+++ b/test/router/resolver.test.ts
@@ -1,5 +1,5 @@
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
import solver from "../../src/router/solver1.ts";
import atlas from "../../src/router/atlas/main1.ts";
import paths from "./paths.ts";
@@ -12,7 +12,7 @@ test(
(_) =>
(
(a) =>
- assert.deepStrictEqual(
+ assertEquals(
[
a(new Request("http://localhost:8080/")),
a(new Request("http://localhost:8080/one")),
@@ -56,7 +56,7 @@ test(
(_) =>
(
(a) =>
- assert.deepStrictEqual(
+ assertEquals(
[
a(new Request("http://localhost:8080/")),
a(new Request("http://localhost:8080/one")),
@@ -86,7 +86,7 @@ test(
(_) =>
(
(f) =>
- assert.deepStrictEqual(
+ assertEquals(
[
f(new Request("http://localhost:8000/count")),
f(new Request("http://localhost:8000/hello_world")),
diff --git a/test/staticFile/composedPaths.test.ts b/test/staticFile/composedPaths.test.ts
index 3b5ba56..1c7c32c 100644
--- a/test/staticFile/composedPaths.test.ts
+++ b/test/staticFile/composedPaths.test.ts
@@ -1,18 +1,19 @@
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
+
import composer from "../../src/staticFiles/composedPaths.ts";
test(
"static file checking file in composition",
() => {
- assert.deepStrictEqual(
+ assertEquals(
"/fun.test.ts",
composer({ type: "fileServer", path: "./misc/", name: "/", mime: false })(
"./test/",
)("./")(["./test/fun.test.ts"])([])[0].path,
);
- assert.deepStrictEqual(
+ assertEquals(
"/fun.test.ts",
composer({ type: "fileServer", path: "./misc/", name: "/", mime: false })(
"./test/",
diff --git a/test/staticFile/getDir.test.ts b/test/staticFile/getDir.test.ts
index 137dab7..8350d2a 100644
--- a/test/staticFile/getDir.test.ts
+++ b/test/staticFile/getDir.test.ts
@@ -1,12 +1,12 @@
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
import staticFileTools from "../../src/staticFiles/staticFileTools.ts";
test(
"static",
() =>
- assert.deepStrictEqual(
+ assertEquals(
staticFileTools.getDir("./misc/").every((x) =>
x[0] === "." && x[1] === "/"
),
diff --git a/test/staticFile/getMime.test.ts b/test/staticFile/getMime.test.ts
index 2b3f033..c5b7b26 100644
--- a/test/staticFile/getMime.test.ts
+++ b/test/staticFile/getMime.test.ts
@@ -1,16 +1,17 @@
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
+
import staticFileTools from "../../src/staticFiles/staticFileTools.ts";
test(
"statci file gets mine",
() => {
- assert.deepStrictEqual(
+ assertEquals(
staticFileTools.getMime([[".hello", "hello"]])(".hello"),
"hello",
);
- assert.deepStrictEqual(
+ assertEquals(
staticFileTools.getMime([[".txt", "hello"]])(".hello"),
"text/html",
);
diff --git a/test/staticFile/main.test.ts b/test/staticFile/main.test.ts
index 0a1b6e3..43211a0 100644
--- a/test/staticFile/main.test.ts
+++ b/test/staticFile/main.test.ts
@@ -1,12 +1,12 @@
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
import main from "../../src/staticFiles/staticFileMain.ts";
import { petitions } from "../../src/morphism.ts";
test(
"static file checking logo",
() =>
- assert.deepStrictEqual(
+ assertEquals(
main()({
type: "fileServer",
path: "./misc/",
@@ -21,7 +21,7 @@ test(
test(
"static file checking extension",
() =>
- assert.deepStrictEqual(
+ assertEquals(
main()({
type: "fileServer",
path: "./misc/",
@@ -37,7 +37,7 @@ test(
test(
"static file has path",
() =>
- assert.deepStrictEqual(
+ assertEquals(
main()({ type: "fileServer", path: "./misc/", name: "/", mime: false })
.some((x) => x.path === "/logo.png"),
true,
@@ -47,7 +47,7 @@ test(
test(
"static file has nested path",
() =>
- assert.deepStrictEqual(
+ assertEquals(
main()({
type: "fileServer",
path: "./misc/",
@@ -61,7 +61,7 @@ test(
test(
"static file plugin",
() =>
- assert.deepStrictEqual(
+ assertEquals(
main()({
type: "fileServer",
path: "./misc/",
diff --git a/test/staticFile/mime.test.ts b/test/staticFile/mime.test.ts
index eae6284..863bc5a 100644
--- a/test/staticFile/mime.test.ts
+++ b/test/staticFile/mime.test.ts
@@ -1,12 +1,13 @@
-import assert from "node:assert";
-import test from "node:test";
+import { assertEquals } from "@std/assert";
+import { test } from "@cross/test";
+
import staticFileTools from "../../src/staticFiles/staticFileTools.ts";
test(
"checking mime",
() => {
- assert.deepStrictEqual(
+ assertEquals(
staticFileTools.mimeForm({
type: "fileServer",
path: "./",
@@ -14,7 +15,7 @@ test(
}).length,
74,
);
- assert.deepStrictEqual(
+ assertEquals(
staticFileTools.mimeForm({
type: "fileServer",
path: "./",
@@ -24,7 +25,7 @@ test(
.length,
0,
);
- assert.deepStrictEqual(
+ assertEquals(
staticFileTools.mimeForm({
type: "fileServer",
path: "./",
diff --git a/test/util/slicerURL.test.ts b/test/util/slicerURL.test.ts
index cacf06d..7c006b6 100644
--- a/test/util/slicerURL.test.ts
+++ b/test/util/slicerURL.test.ts
@@ -1,9 +1,9 @@
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import { assertEquals } from "@std/assert";
import mainSlicerUrl from "../../src/util/slicerURL/mainSlicerUrl.ts";
-
+import { test } from "@cross/test";
const baseURL = "https://example.com/1/2/3/4/5";
-Deno.test("SlicerURL", () => {
+test("SlicerURL", () => {
assertEquals(
mainSlicerUrl(2)(baseURL),
"https://example.com".length,
From 148d06493dc4310ef5f63fc9fc37ac7e82c3a524 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Wed, 19 Jun 2024 11:31:46 +0100
Subject: [PATCH 04/12] adding `debugLast`
---
main.ts | 12 ++--
package.json | 2 +-
...kieToTokenMain.ts => mainCookieToToken.ts} | 12 +++-
src/components/cookies/cookieDefaultCase.ts | 12 ++++
src/components/cookies/main.ts | 10 ---
src/components/cookies/mainCookies.ts | 23 +++++++
src/components/parameters/mainParameters.ts | 11 +++-
src/components/queries/mainQueries.ts | 18 +++++-
src/composer/nativeComponents.ts | 10 +--
src/exportable/display.ts | 62 +++++++++++++++++++
src/exportable/wrap.ts | 33 +++-------
src/morphism.ts | 12 ++--
src/router/composer/parameters.ts | 2 +-
.../cookieToToken/cookieToToken.test.ts | 1 -
test/components/parameters/main.test.ts | 36 +++++------
test/staticFile/composedPaths.test.ts | 1 -
test/staticFile/getMime.test.ts | 1 -
test/staticFile/mime.test.ts | 1 -
18 files changed, 180 insertions(+), 79 deletions(-)
rename src/components/cookieToToken/{cookieToTokenMain.ts => mainCookieToToken.ts} (78%)
create mode 100644 src/components/cookies/cookieDefaultCase.ts
delete mode 100644 src/components/cookies/main.ts
create mode 100644 src/components/cookies/mainCookies.ts
create mode 100644 src/exportable/display.ts
diff --git a/main.ts b/main.ts
index 0ed4b8e..98a5038 100644
--- a/main.ts
+++ b/main.ts
@@ -1,7 +1,9 @@
import parseargs from "./src/runtime/parseArguments.ts";
import name from "./src/runtime/name.ts";
-import mainQueries from "./src/components/queries/mainQueries.ts";
-import mainParameters from "./src/components/parameters/mainParameters.ts";
+import { f as query } from "./src/components/queries/mainQueries.ts";
+import { f as param } from "./src/components/parameters/mainParameters.ts";
+import { f as cookie } from "./src/components/parameters/mainParameters.ts";
+import { f as token } from "./src/components/cookieToToken/mainCookieToToken.ts";
/**
* Runtime utilities
@@ -15,8 +17,10 @@ export const runtime = {
* Runtime utilities
*/
export const components = {
- query: mainQueries,
- parameters: mainParameters,
+ query,
+ param,
+ cookie,
+ token,
};
/**
diff --git a/package.json b/package.json
index 58dfbcb..5432421 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
"version": "0.1.37",
"description": "A functional router for Bun and Deno",
"main": "main.ts",
- "type": "commonjs",
+ "type": "module",
"directories": {
"test": "test"
},
diff --git a/src/components/cookieToToken/cookieToTokenMain.ts b/src/components/cookieToToken/mainCookieToToken.ts
similarity index 78%
rename from src/components/cookieToToken/cookieToTokenMain.ts
rename to src/components/cookieToToken/mainCookieToToken.ts
index d416c15..c92dfe4 100644
--- a/src/components/cookieToToken/cookieToTokenMain.ts
+++ b/src/components/cookieToToken/mainCookieToToken.ts
@@ -4,7 +4,7 @@ import cookieToTokenBodyParser from "./cookieToTokenBodyParser.ts";
import cookieToTokenGets from "./cookieToTokenGets.ts";
import { plugins } from "../../../main.ts";
-export default (o?: FunRouterOptions) => (p: Petition) =>
+export const f = (o?: FunRouterOptions) => (p: Petition) =>
p.crypto && "globalKey" in p.crypto
? (
(getCookies) =>
@@ -30,4 +30,12 @@ export default (o?: FunRouterOptions) => (p: Petition) =>
)(
plugins.pluginIsUsing(p)("token"),
)
- : () => ({ SystemError: "Crypto is requires" });
+ : () => null;
+
+export const isUsing = (o?: FunRouterOptions) => (p: Petition): string =>
+ (
+ (uses) =>
+ uses && uses.length > 0 ? `[` + uses.map((x) => x + "?") + "]" : "null"
+ )(
+ plugins.pluginIsUsing(p)("token"),
+ );
diff --git a/src/components/cookies/cookieDefaultCase.ts b/src/components/cookies/cookieDefaultCase.ts
new file mode 100644
index 0000000..4ec63dc
--- /dev/null
+++ b/src/components/cookies/cookieDefaultCase.ts
@@ -0,0 +1,12 @@
+export default (_o?: any) => (s: string) =>
+ s
+ ? Object.fromEntries(
+ s
+ .split("; ")
+ .filter((x) =>
+ x
+ .indexOf("=") !== -1
+ )
+ .map((x) => x.split("=")),
+ )
+ : null;
diff --git a/src/components/cookies/main.ts b/src/components/cookies/main.ts
deleted file mode 100644
index 00eafdb..0000000
--- a/src/components/cookies/main.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { plugins } from "../../../main.ts";
-import type { Petition } from "../../morphism.ts";
-import type { FunRouterOptions } from "../../options.ts";
-import { body } from "./cookieBodyParser.ts";
-export default (o?: FunRouterOptions) => (p: Petition) =>
- (
- (cookies) => cookies ? body(cookies) : () => null
- )(
- plugins.pluginIsUsing(p)("cookies"),
- );
diff --git a/src/components/cookies/mainCookies.ts b/src/components/cookies/mainCookies.ts
new file mode 100644
index 0000000..e0011d8
--- /dev/null
+++ b/src/components/cookies/mainCookies.ts
@@ -0,0 +1,23 @@
+import { plugins } from "../../../main.ts";
+import type { Petition } from "../../morphism.ts";
+import type { FunRouterOptions } from "../../options.ts";
+import { body } from "./cookieBodyParser.ts";
+import cookieDefaultCase from "./cookieDefaultCase.ts";
+export const f = (o?: FunRouterOptions) => (p: Petition) =>
+ (
+ (cookies) => cookies ? body(p.cookie?.only ?? cookies) : cookieDefaultCase()
+ )(
+ plugins.pluginIsUsing(p)("cookies"),
+ );
+
+export const isUsing = (o?: FunRouterOptions) => (p: Petition): string =>
+ (
+ (uses) =>
+ p.cookie?.only
+ ? p.cookie?.only.toString()
+ : uses && uses.length > 0
+ ? `[` + uses.map((x) => x + "?") + "]"
+ : `Record | null`
+ )(
+ plugins.pluginIsUsing(p)("cookies"),
+ );
diff --git a/src/components/parameters/mainParameters.ts b/src/components/parameters/mainParameters.ts
index a0c658b..ed9208f 100644
--- a/src/components/parameters/mainParameters.ts
+++ b/src/components/parameters/mainParameters.ts
@@ -10,7 +10,7 @@ type Parameters = (
) => (p: Petition) => (url: string) => string | Record | null;
//TODO
-export default ((options?: FunRouterOptions) => (p: Petition) =>
+const f = ((options?: FunRouterOptions) => (p: Petition) =>
(
(map) =>
p?.param?.unique === true
@@ -23,3 +23,12 @@ export default ((options?: FunRouterOptions) => (p: Petition) =>
)(
map(options)(p),
)) as Parameters;
+
+const isUsing = (options?: FunRouterOptions) => (p: Petition) =>
+ p.param?.unique === true
+ ? "unique"
+ : "[" + [map(options)(p).elements.toString()].map((x) =>
+ x.slice(1)
+ ).toString() + "]";
+
+export { f, isUsing };
diff --git a/src/components/queries/mainQueries.ts b/src/components/queries/mainQueries.ts
index fa77990..736cdea 100644
--- a/src/components/queries/mainQueries.ts
+++ b/src/components/queries/mainQueries.ts
@@ -5,8 +5,10 @@ import elements from "./queryElements.ts";
import unique from "./unique.ts";
import plugin from "../../exportable/plugin.ts";
-export default (o?: FunRouterOptions) =>
-(p: Petition): (url: string) => string | Record | null =>
+export const f = (o?: FunRouterOptions) =>
+(
+ p: Petition,
+): (url: string) => string | Record | null =>
p.query && p.query.name
? new Function(`return ${unique([p.query.name])}`)()
: p.query && Array.isArray(p.query.only)
@@ -17,5 +19,15 @@ export default (o?: FunRouterOptions) =>
? only.length > 0
? new Function(`return ${elements(only)}`)()
: new Function(`return ${common(o)(p)}`)()
- : () => null
+ : new Function(`return ${common(o)(p)}`)()
)(plugin.pluginIsUsing(p)("query"));
+
+export const isUsing = (o?: FunRouterOptions) => (p: Petition): string =>
+ (
+ (uses) =>
+ uses && uses?.length > 0
+ ? p.query?.unique ? p.query?.name : `[` + uses.map((x) => x + "?") + "]"
+ : `Record | null`
+ )(
+ plugin.pluginIsUsing(p)("query"),
+ );
diff --git a/src/composer/nativeComponents.ts b/src/composer/nativeComponents.ts
index 61226a4..f92adf7 100644
--- a/src/composer/nativeComponents.ts
+++ b/src/composer/nativeComponents.ts
@@ -1,9 +1,9 @@
-import params from "../components/parameters/mainParameters.ts";
-import query from "../components/queries/mainQueries.ts";
-import cookies from "../components/cookies/main.ts";
+import { f as params } from "../components/parameters/mainParameters.ts";
+import { f as query } from "../components/queries/mainQueries.ts";
+import { f as cookies } from "../components/cookies/mainCookies.ts";
import resolve from "./resolve/main.ts";
import branch from "./branch/branchMain.ts";
-import cookieToTokenMain from "../components/cookieToToken/cookieToTokenMain.ts";
+import { f as mainCookieToToken } from "../components/cookieToToken/mainCookieToToken.ts";
import signSha256 from "../components/jwt/signSha256.mjs";
import verifySha256 from "../components/jwt/verifySha256.mjs";
import mainIO from "../components/io/mainIO.ts";
@@ -66,7 +66,7 @@ export default (o?: FunRouterOptions) =>
{
condition: (x: NativeMaps) => x.name === "token",
action: () =>
- cookieToTokenMain(o)({
+ mainCookieToToken(o)({
...f,
crypto: {
...f.crypto,
diff --git a/src/exportable/display.ts b/src/exportable/display.ts
new file mode 100644
index 0000000..ea19111
--- /dev/null
+++ b/src/exportable/display.ts
@@ -0,0 +1,62 @@
+import { isUsing as param } from "../components/parameters/mainParameters.ts";
+import { isUsing as query } from "../components/queries/mainQueries.ts";
+import { isUsing as cookie } from "../components/cookies/mainCookies.ts";
+import { isUsing as token } from "../components/cookieToToken/mainCookieToToken.ts";
+import type { Petition } from "../morphism.ts";
+import type { FunRouterOptions } from "../options.ts";
+
+type Display = {
+ using?: string[];
+ isAsync?: boolean;
+};
+
+type Elements = {
+ [key: string]: (options?: FunRouterOptions) => (p: Petition) => string;
+};
+
+const elements: Elements = {
+ param,
+ query,
+ cookie,
+ token,
+};
+export const displayPaths = (p: Petition): void => (
+ console.log("---"),
+ Object.entries({
+ path: p.path,
+ method: p.method ?? "GET",
+ }).forEach(
+ ([key, value]) => (
+ console.log(
+ `\x1b[35m${key}\x1b[0m: \x1b[38;2;255;165;0m${value}\x1b[0m`,
+ )
+ ),
+ )
+);
+
+export const display =
+ (options?: FunRouterOptions) =>
+ (p: Petition) =>
+ (object: Display): void => (
+ console.log("--- Context ---"),
+ Object.entries(object).forEach(
+ ([key, value]) => (
+ console.log(
+ `\x1b[35m${key}\x1b[0m: \x1b[38;2;255;165;0m${value}\x1b[0m`,
+ )
+ ),
+ ),
+ console.log(
+ (object.using ?? [])
+ .reduce(
+ (acc, key) =>
+ key in elements
+ ? acc +
+ `\x1b[35m${key}\x1b[0m: \x1b[38;2;255;165;0m${
+ elements[key](options)(p)
+ }\x1b[0m \n`
+ : acc + "",
+ "--- Components ---\n",
+ ),
+ )
+ );
diff --git a/src/exportable/wrap.ts b/src/exportable/wrap.ts
index 6409ada..9d0471e 100644
--- a/src/exportable/wrap.ts
+++ b/src/exportable/wrap.ts
@@ -2,6 +2,7 @@ import type { CyclePluginMap, FunRouterOptions } from "../options.ts";
import response from "../composer/compose.ts";
import composerTools from "../composer/composerTools.ts";
import vixeny from "../../fun.ts";
+import { display, displayPaths } from "./display.ts";
import type {
BranchMap,
CryptoOptions,
@@ -173,17 +174,17 @@ type Wrap> = {
* // Logging the used context after the first petition (expected to be empty as none is used):
* // Output: []
* // Important!, `_c` will be the Request
- * .logLastCheck()
+ * .debugLast()
* .stdPetition({
* path: '/two/:id',
* f: c => c.param.id
* })
* // Logging the used context after adding a petition that accesses a URL parameter:
* // Output: [ "param" ]
- * .logLastCheck()
+ * .debugLast()
* ```
*/
- logLastCheck: () => Wrap;
+ debugLast: () => Wrap;
/**
* `handleRequest` dynamically processes a request getting a specified path. If the path exists among the defined petitions,
* it either applies provided modifications (useful for mocking or altering request handling behavior) or proceeds with the
@@ -453,20 +454,13 @@ export const wrap = ((o?) => (a = []) => ({
logPaths: () =>
void a.forEach(
- (x) =>
- display({
- method: x.method ?? "GET",
- path: x.path,
- ...(
- x.active ? { active: x.active } : {}
- ),
- }),
+ (x) => displayPaths(x),
) ?? wrap(o)(a),
- logLastCheck: () =>
+ debugLast: () =>
void (
(isUsing) =>
- display({
- using: "[" + isUsing + "]",
+ display(o)(a[a.length - 1])({
+ using: isUsing,
isAsync: composerTools.localAsync(o)(a[a.length - 1])(isUsing),
})
)(
@@ -523,14 +517,3 @@ export const wrap = ((o?) => (a = []) => ({
compose: () => vixeny(o)(a),
flatMap: (fn) => a.reduce((acc, x) => acc.union(fn(x).unwrap()), wrap(o)([])),
})) as WrapFunction;
-
-const display = (object: Object) => (
- console.log("---"),
- Object.entries(object).forEach(
- ([key, value]) => (
- console.log(
- `\x1b[35m${key}\x1b[0m: \x1b[38;2;255;165;0m${value}\x1b[0m`,
- )
- ),
- )
-);
diff --git a/src/morphism.ts b/src/morphism.ts
index e0d865c..e0f6eec 100644
--- a/src/morphism.ts
+++ b/src/morphism.ts
@@ -487,6 +487,7 @@ export type Morphism<
readonly crypto?: CO;
readonly args?: MO extends { type: "morphism" } ? AT : never;
readonly query?: QO;
+ readonly cookie?: CookieOptions;
readonly param?: PO;
readonly plugins?: ExtractPluginTypes;
readonly headings?: PetitionHeader;
@@ -576,6 +577,10 @@ export type QueryOptions = {
only?: string[];
} | {};
+export type CookieOptions = {
+ only?: string[];
+};
+
export type ParamOptions = {
readonly unique?: true;
} | {};
@@ -846,7 +851,7 @@ interface Ctx<
* ```
*/
query: QS extends { unique: true } ? (string | null)
- : { [key: string]: string };
+ : { [key: string]: string | null };
/**
* `param`: Enables the extraction of URL path parameters within the petition's execution context. This feature simplifies accessing dynamic segments of the URL path, allowing petitions to respond to varied requests efficiently.
@@ -940,10 +945,7 @@ interface Ctx<
* ```
*/
date: number;
- /**
- * @deprecated
- */
- cookie: null | { [key: string]: string | undefined };
+ cookie: { [key: string]: string | undefined };
io: FileHandler;
}
diff --git a/src/router/composer/parameters.ts b/src/router/composer/parameters.ts
index fc4758d..30d4e01 100644
--- a/src/router/composer/parameters.ts
+++ b/src/router/composer/parameters.ts
@@ -1,4 +1,4 @@
-import { info } from "./types.ts";
+import type { info } from "./types.ts";
export default (position: number) => (map: info) =>
map.lastParam === 0 && map.elements.every((x) => x[0] === map.startsWith)
diff --git a/test/components/cookieToToken/cookieToToken.test.ts b/test/components/cookieToToken/cookieToToken.test.ts
index 4de084d..c7268cd 100644
--- a/test/components/cookieToToken/cookieToToken.test.ts
+++ b/test/components/cookieToToken/cookieToToken.test.ts
@@ -1,7 +1,6 @@
import { assertEquals } from "@std/assert";
import { test } from "@cross/test";
-
import signSha256 from "../../../src/components/jwt/signSha256.mjs";
import { wrap } from "../../../main.ts";
diff --git a/test/components/parameters/main.test.ts b/test/components/parameters/main.test.ts
index 9638c29..ac7a2ec 100644
--- a/test/components/parameters/main.test.ts
+++ b/test/components/parameters/main.test.ts
@@ -1,5 +1,5 @@
import { assertEquals } from "@std/assert";
-import mainParameters from "../../../src/components/parameters/mainParameters.ts";
+import { f } from "../../../src/components/parameters/mainParameters.ts";
import { petitions, plugins } from "../../../main.ts";
import { test } from "@cross/test";
const base = "http://hello.com";
@@ -12,7 +12,7 @@ const options = plugins.globalOptions({
test("parameters unique", () => {
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -24,7 +24,7 @@ test("parameters unique", () => {
"helloWorld1",
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -36,7 +36,7 @@ test("parameters unique", () => {
"helloWorld2",
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/",
param: {
@@ -48,7 +48,7 @@ test("parameters unique", () => {
"helloWorld3",
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/",
param: {
@@ -60,7 +60,7 @@ test("parameters unique", () => {
"helloWorld4",
);
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -72,7 +72,7 @@ test("parameters unique", () => {
"helloWorld5",
);
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -86,7 +86,7 @@ test("parameters unique", () => {
//checks that it's using a different function, validated that the last to `asserts` are working
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -94,7 +94,7 @@ test("parameters unique", () => {
},
f: (ctx) => ctx.param,
}),
- ).toString() === mainParameters()(
+ ).toString() === f()(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -109,7 +109,7 @@ test("parameters unique", () => {
test("parameters single", () => {
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi",
f: (ctx) => ctx.param.hi,
@@ -120,7 +120,7 @@ test("parameters single", () => {
},
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi",
f: (ctx) => ctx.param.hi,
@@ -131,7 +131,7 @@ test("parameters single", () => {
},
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/",
f: (ctx) => ctx.param.hi,
@@ -142,7 +142,7 @@ test("parameters single", () => {
},
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/",
f: (ctx) => ctx.param.hi,
@@ -153,7 +153,7 @@ test("parameters single", () => {
},
);
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
f: (ctx) => ctx.param.hi,
@@ -164,7 +164,7 @@ test("parameters single", () => {
},
);
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
f: (ctx) => ctx.param.hi,
@@ -178,7 +178,7 @@ test("parameters single", () => {
test("parameters multiple", () => {
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/:hello",
f: (ctx) => ctx.param.hi,
@@ -191,7 +191,7 @@ test("parameters multiple", () => {
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/:hello",
f: (ctx) => ctx.param.hi,
@@ -204,7 +204,7 @@ test("parameters multiple", () => {
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/:test/:id/:hello",
f: (ctx) => ctx.param.hi,
diff --git a/test/staticFile/composedPaths.test.ts b/test/staticFile/composedPaths.test.ts
index 1c7c32c..43aa35f 100644
--- a/test/staticFile/composedPaths.test.ts
+++ b/test/staticFile/composedPaths.test.ts
@@ -1,7 +1,6 @@
import { assertEquals } from "@std/assert";
import { test } from "@cross/test";
-
import composer from "../../src/staticFiles/composedPaths.ts";
test(
diff --git a/test/staticFile/getMime.test.ts b/test/staticFile/getMime.test.ts
index c5b7b26..c19b294 100644
--- a/test/staticFile/getMime.test.ts
+++ b/test/staticFile/getMime.test.ts
@@ -1,7 +1,6 @@
import { assertEquals } from "@std/assert";
import { test } from "@cross/test";
-
import staticFileTools from "../../src/staticFiles/staticFileTools.ts";
test(
diff --git a/test/staticFile/mime.test.ts b/test/staticFile/mime.test.ts
index 863bc5a..9a22418 100644
--- a/test/staticFile/mime.test.ts
+++ b/test/staticFile/mime.test.ts
@@ -1,7 +1,6 @@
import { assertEquals } from "@std/assert";
import { test } from "@cross/test";
-
import staticFileTools from "../../src/staticFiles/staticFileTools.ts";
test(
From cc014568ff6d32b8dcaa4aaa68281386507d80f3 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Wed, 19 Jun 2024 11:49:06 +0100
Subject: [PATCH 05/12] solving dependency issues
---
main.ts | 20 +++++++++----------
.../cookieToToken/mainCookieToToken.ts | 2 +-
src/components/cookies/mainCookies.ts | 9 ++++++---
3 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/main.ts b/main.ts
index 98a5038..971fb40 100644
--- a/main.ts
+++ b/main.ts
@@ -2,19 +2,11 @@ import parseargs from "./src/runtime/parseArguments.ts";
import name from "./src/runtime/name.ts";
import { f as query } from "./src/components/queries/mainQueries.ts";
import { f as param } from "./src/components/parameters/mainParameters.ts";
-import { f as cookie } from "./src/components/parameters/mainParameters.ts";
+import { f as cookie } from "./src/components/cookies/mainCookies.ts";
import { f as token } from "./src/components/cookieToToken/mainCookieToToken.ts";
/**
- * Runtime utilities
- */
-export const runtime = {
- name: name,
- arguments: parseargs,
-};
-
-/**
- * Runtime utilities
+ * Components utilities
*/
export const components = {
query,
@@ -23,6 +15,14 @@ export const components = {
token,
};
+/**
+ * Runtime utilities
+ */
+export const runtime = {
+ name: name,
+ arguments: parseargs,
+};
+
/**
* Plugins utilities
*/
diff --git a/src/components/cookieToToken/mainCookieToToken.ts b/src/components/cookieToToken/mainCookieToToken.ts
index c92dfe4..989aefa 100644
--- a/src/components/cookieToToken/mainCookieToToken.ts
+++ b/src/components/cookieToToken/mainCookieToToken.ts
@@ -2,7 +2,7 @@ import type { FunRouterOptions } from "../../options.ts";
import type { Petition, SupportedKeys } from "../../morphism.ts";
import cookieToTokenBodyParser from "./cookieToTokenBodyParser.ts";
import cookieToTokenGets from "./cookieToTokenGets.ts";
-import { plugins } from "../../../main.ts";
+import plugins from "../../exportable/plugin.ts";
export const f = (o?: FunRouterOptions) => (p: Petition) =>
p.crypto && "globalKey" in p.crypto
diff --git a/src/components/cookies/mainCookies.ts b/src/components/cookies/mainCookies.ts
index e0011d8..6b73faa 100644
--- a/src/components/cookies/mainCookies.ts
+++ b/src/components/cookies/mainCookies.ts
@@ -1,16 +1,17 @@
-import { plugins } from "../../../main.ts";
+import plugins from "../../exportable/plugin.ts";
import type { Petition } from "../../morphism.ts";
import type { FunRouterOptions } from "../../options.ts";
import { body } from "./cookieBodyParser.ts";
import cookieDefaultCase from "./cookieDefaultCase.ts";
-export const f = (o?: FunRouterOptions) => (p: Petition) =>
+
+const f = (o?: FunRouterOptions) => (p: Petition) =>
(
(cookies) => cookies ? body(p.cookie?.only ?? cookies) : cookieDefaultCase()
)(
plugins.pluginIsUsing(p)("cookies"),
);
-export const isUsing = (o?: FunRouterOptions) => (p: Petition): string =>
+const isUsing = (o?: FunRouterOptions) => (p: Petition): string =>
(
(uses) =>
p.cookie?.only
@@ -21,3 +22,5 @@ export const isUsing = (o?: FunRouterOptions) => (p: Petition): string =>
)(
plugins.pluginIsUsing(p)("cookies"),
);
+
+export { f, isUsing };
From d43a2ec6c73af474f9e653dfe67319d4be4ea773 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Wed, 19 Jun 2024 22:11:16 +0100
Subject: [PATCH 06/12] new composer for anyPetition
---
deno.json | 3 +++
jsr.json | 5 ----
src/components/cookies/cookieDefaultCase.ts | 27 ++++++++++++---------
src/components/cookies/mainCookies.ts | 9 +++++--
src/exportable/composer.ts | 8 ++----
src/morphism.ts | 8 +++++-
test/exportable/composer.test.ts | 6 ++---
7 files changed, 37 insertions(+), 29 deletions(-)
delete mode 100644 jsr.json
diff --git a/deno.json b/deno.json
index bc0f56f..26dc882 100644
--- a/deno.json
+++ b/deno.json
@@ -1,4 +1,7 @@
{
+ "name": "@vixeny/core",
+ "version": "0.1.37",
+ "exports": "./main.ts",
"imports": {
"@cross/test": "jsr:@cross/test@^0.0.9",
"@std/assert": "jsr:@std/assert@^0.226.0"
diff --git a/jsr.json b/jsr.json
deleted file mode 100644
index f7b82a3..0000000
--- a/jsr.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "@vixeny/core",
- "version": "0.1.37",
- "exports": "./main.ts"
-}
diff --git a/src/components/cookies/cookieDefaultCase.ts b/src/components/cookies/cookieDefaultCase.ts
index 4ec63dc..a05a69c 100644
--- a/src/components/cookies/cookieDefaultCase.ts
+++ b/src/components/cookies/cookieDefaultCase.ts
@@ -1,12 +1,15 @@
-export default (_o?: any) => (s: string) =>
- s
- ? Object.fromEntries(
- s
- .split("; ")
- .filter((x) =>
- x
- .indexOf("=") !== -1
- )
- .map((x) => x.split("=")),
- )
- : null;
+export default (_o?: any) =>
+ ((s: string) =>
+ s
+ ? Object.fromEntries(
+ s
+ .split("; ")
+ .filter((x) =>
+ x
+ .indexOf("=") !== -1
+ )
+ .map((x) => x.split("=")),
+ )
+ : {}) as unknown as (
+ string: string | null,
+ ) => Record;
diff --git a/src/components/cookies/mainCookies.ts b/src/components/cookies/mainCookies.ts
index 6b73faa..36c30c5 100644
--- a/src/components/cookies/mainCookies.ts
+++ b/src/components/cookies/mainCookies.ts
@@ -4,9 +4,14 @@ import type { FunRouterOptions } from "../../options.ts";
import { body } from "./cookieBodyParser.ts";
import cookieDefaultCase from "./cookieDefaultCase.ts";
-const f = (o?: FunRouterOptions) => (p: Petition) =>
+type Cookie = (string: string | null) => Record;
+
+const f = (o?: FunRouterOptions) => (p: Petition): Cookie =>
(
- (cookies) => cookies ? body(p.cookie?.only ?? cookies) : cookieDefaultCase()
+ (cookies) =>
+ cookies
+ ? body(p.cookie?.only ?? cookies) as Cookie
+ : cookieDefaultCase() as Cookie
)(
plugins.pluginIsUsing(p)("cookies"),
);
diff --git a/src/exportable/composer.ts b/src/exportable/composer.ts
index 8c2e90f..30e246e 100644
--- a/src/exportable/composer.ts
+++ b/src/exportable/composer.ts
@@ -173,14 +173,10 @@ export const composer = {
* });
* ```
*/
- petition: <
- FC extends CyclePluginMap,
- O extends FunRouterOptions,
- >(o?: O) =>
- (
+ petition: (
r: Petition,
) =>
- (r.type === "response" ? r.r : (compose(o)(
+ (r.type === "response" ? r.r : (compose(r.o ?? {})(
{ ...r },
))) as unknown as (
re: Request,
diff --git a/src/morphism.ts b/src/morphism.ts
index e0f6eec..aadd415 100644
--- a/src/morphism.ts
+++ b/src/morphism.ts
@@ -84,7 +84,12 @@ export const petitions = {
AR,
R
>,
- ) => ({ ...I, type: "request", o }) as unknown as Petition,
+ ) =>
+ ({
+ ...I,
+ type: "request",
+ o,
+ }) as unknown as Petition,
/**
* Configures and types a basic petition to be used with `wrap` or `compose`.
* The `f` function in the petition configuration returns either a `BodyInit` or `Promise`,
@@ -481,6 +486,7 @@ export type Morphism<
R = any,
> = {
readonly active?: MO["isAPetition"] extends true ? boolean : never;
+ readonly isUsing?: MO["isAPetition"] extends true ? string[] : never;
readonly resolve?: RM;
readonly branch?: BM;
readonly method?: ParamsMethod;
diff --git a/test/exportable/composer.test.ts b/test/exportable/composer.test.ts
index 35f3b1b..1335390 100644
--- a/test/exportable/composer.test.ts
+++ b/test/exportable/composer.test.ts
@@ -81,17 +81,17 @@ test("exportable composer ObjectNull", async () => {
test("exportable composer petition", async () => {
assertEquals(
- await Promise.resolve(composer.petition()(commonPetition)(dummyRequest))
+ await Promise.resolve(composer.petition(commonPetition)(dummyRequest))
.then((x) => x.text()),
"common",
);
assertEquals(
- await Promise.resolve(composer.petition()(requestPetition)(dummyRequest))
+ await Promise.resolve(composer.petition(requestPetition)(dummyRequest))
.then((x) => x.text()),
"standard",
);
assertEquals(
- await Promise.resolve(composer.petition()(responsePetition)(dummyRequest))
+ await Promise.resolve(composer.petition(responsePetition)(dummyRequest))
.then((x) => x.text()),
"response",
);
From ad95380479679a900006543c914816e377a3e67e Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Thu, 20 Jun 2024 10:00:27 +0100
Subject: [PATCH 07/12] Adding Extra strucutre to `Resolve` and `Branch`
---
src/composer/composerTools.ts | 233 ++++++++++++++++++----------------
src/morphism.ts | 35 ++++-
2 files changed, 153 insertions(+), 115 deletions(-)
diff --git a/src/composer/composerTools.ts b/src/composer/composerTools.ts
index c02a6dd..dfb3219 100644
--- a/src/composer/composerTools.ts
+++ b/src/composer/composerTools.ts
@@ -3,116 +3,127 @@ import type { FunRouterOptions } from "../options.ts";
import mainCheck from "./checkPetition/mainCheck.ts";
type RecFunc = (f: Petition) => boolean;
-export default {
- syncCheckerDir:
- (joiner: (base: string) => (target: string) => string) =>
- (readdir: (directoryPath: string) => string[]) =>
- (stat: (directoryPath: string) => { isDirectory: () => boolean }) =>
- (dir: string): [string, boolean][] =>
- (
- (Y) => (
- Y((f: (arg0: string) => [string, boolean][]) => (
- (dir: string): [string, boolean][] =>
- readdir(dir).flatMap((item) =>
- stat(joiner(dir)(item)).isDirectory()
- ? [[joiner(dir)(item), true], ...f(joiner(dir)(item))]
- : [[joiner(dir)(item), false]]
- ) as [string, boolean][]
- ))(dir)
- )
- )(
- // Setting up the Y combinator.
- (f: (arg0: (y: any) => any) => any) =>
- ((x) => x(x))((x: (arg0: any) => { (arg0: any): any; new (): any }) =>
- f((y: any) => x(x)(y))
- ),
- ),
- recursiveCheckAsync:
- ((f: (x: RecFunc) => RecFunc) =>
- ((x: (arg: any) => any) => (v: any) => x(x)(v))(
- (x: (arg: any) => any) => (v: any) => f((y: Petition) => x(x)(y))(v),
- ))(
- (solver: RecFunc) => (f: Petition) =>
- f.f.constructor.name === "AsyncFunction" ||
- ("isAsync" in f && f.isAsync)
- ? true
- : f.f.constructor.name === "Function" &&
- typeof f.resolve === "undefined"
- ? false
- : ("resolve" in f && f.resolve &&
- Object.keys(f.resolve).some((ob) =>
- f.resolve &&
- solver(
- f.resolve[ob] as unknown as Petition,
- )
- )) ??
- ("branch" in f && f.branch &&
- Object.keys(f.branch).some((ob) =>
- f.branch &&
- solver(
- f.branch[ob] as unknown as Petition,
- )
- )) ??
- false,
- ) as unknown as (f: Petition) => boolean,
- parsingToHexa: (crypto: { globalKey: string }): Uint8Array =>
- typeof crypto.globalKey === "string"
- ? /^[0-9a-fA-F]+$/g.test(crypto.globalKey)
- ? new Uint8Array([...crypto.globalKey].map((x) => x.charCodeAt(0)))
- : new Uint8Array([...crypto.globalKey].map((x) => x.charCodeAt(0)))
- : crypto.globalKey,
- isUsing: (o?: FunRouterOptions) => (f: Petition): string[] =>
- mainCheck(o)(f),
- elements: (f: Petition) =>
+const syncCheckerDir =
+ (joiner: (base: string) => (target: string) => string) =>
+ (readdir: (directoryPath: string) => string[]) =>
+ (stat: (directoryPath: string) => { isDirectory: () => boolean }) =>
+ (dir: string): [string, boolean][] =>
(
- f.crypto && "globalKey" in f.crypto
- ? [
- "cookie",
- "headers",
- "hash",
- "param",
- "query",
- "io",
- "req",
- "date",
- f.resolve ? "resolve" : undefined,
- "mutable",
- f.branch ? "branch" : undefined,
- f.args ? "args" : undefined,
- ,
- "token",
- "verify",
- "sign",
- ]
- : [
- "cookie",
- "headers",
- "hash",
- "param",
- "query",
- "io",
- "req",
- "date",
- f.resolve ? "resolve" : undefined,
- "mutable",
- f.branch ? "branch" : undefined,
- f.args ? "args" : undefined,
- ,
- ]
- ).filter(Boolean) as string[],
- localAsync:
- (o?: FunRouterOptions) =>
- (p: Petition) =>
- (elementsUsed: string[]): boolean =>
- (
- (p.f.constructor.name === "AsyncFunction" ?? false) ||
- o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
- .some((x) =>
- elementsUsed.includes(x)
- //@ts-ignore
- ? "isAsync" in o.cyclePlugin[x] &&
- o.cyclePlugin[x].isAsync === true
- : false
- )
- ) ?? false,
+ (Y) => (
+ Y((f: (arg0: string) => [string, boolean][]) => (
+ (dir: string): [string, boolean][] =>
+ readdir(dir).flatMap((item) =>
+ stat(joiner(dir)(item)).isDirectory()
+ ? [[joiner(dir)(item), true], ...f(joiner(dir)(item))]
+ : [[joiner(dir)(item), false]]
+ ) as [string, boolean][]
+ ))(dir)
+ )
+ )(
+ // Setting up the Y combinator.
+ (f: (arg0: (y: any) => any) => any) =>
+ ((x) => x(x))((x: (arg0: any) => { (arg0: any): any; new (): any }) =>
+ f((y: any) => x(x)(y))
+ ),
+ );
+
+const recursiveCheckAsync =
+ ((f: (x: RecFunc) => RecFunc) =>
+ ((x: (arg: any) => any) => (v: any) => x(x)(v))(
+ (x: (arg: any) => any) => (v: any) => f((y: Petition) => x(x)(y))(v),
+ ))(
+ (solver: RecFunc) => (p: Petition): boolean =>
+ p.f.constructor.name === "AsyncFunction" ||
+ p.isAsync
+ ? true
+ : p.f.constructor.name === "Function" &&
+ typeof p.resolve === "undefined"
+ ? false
+ : ("resolve" in p && p.resolve &&
+ Object.keys(p.resolve).some((ob) =>
+ p.resolve &&
+ solver(
+ p.resolve[ob] as unknown as Petition,
+ )
+ )) ??
+ // ("branch" in p && p.branch &&
+ // Object.keys(p.branch).some((ob) =>
+ // p.branch &&
+ // solver(
+ // p.branch[ob] as unknown as Petition,
+ // )
+ // )) ??
+ false,
+ ) as unknown as (f: Petition) => boolean;
+
+const parsingToHexa = (crypto: { globalKey: string }): Uint8Array =>
+ typeof crypto.globalKey === "string"
+ ? /^[0-9a-fA-F]+$/g.test(crypto.globalKey)
+ ? new Uint8Array([...crypto.globalKey].map((x) => x.charCodeAt(0)))
+ : new Uint8Array([...crypto.globalKey].map((x) => x.charCodeAt(0)))
+ : crypto.globalKey;
+
+const isUsing = (o?: FunRouterOptions) => (f: Petition): string[] =>
+ mainCheck(o)(f);
+
+const elements = (f: Petition) =>
+ (
+ f.crypto && "globalKey" in f.crypto
+ ? [
+ "cookie",
+ "headers",
+ "hash",
+ "param",
+ "query",
+ "io",
+ "req",
+ "date",
+ f.resolve ? "resolve" : undefined,
+ "mutable",
+ f.branch ? "branch" : undefined,
+ f.args ? "args" : undefined,
+ ,
+ "token",
+ "verify",
+ "sign",
+ ]
+ : [
+ "cookie",
+ "headers",
+ "hash",
+ "param",
+ "query",
+ "io",
+ "req",
+ "date",
+ f.resolve ? "resolve" : undefined,
+ "mutable",
+ f.branch ? "branch" : undefined,
+ f.args ? "args" : undefined,
+ ,
+ ]
+ ).filter(Boolean) as string[];
+
+const localAsync =
+ (o?: FunRouterOptions) =>
+ (p: Petition) =>
+ (elementsUsed: string[]): boolean =>
+ (
+ (p.f.constructor.name === "AsyncFunction" ) ||
+ o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
+ .some((x) =>
+ elementsUsed.includes(x)
+ ? "isAsync" in o.cyclePlugin[x] &&
+ o.cyclePlugin[x].isAsync === true
+ : false
+ )
+ ) ?? false;
+
+export default {
+ syncCheckerDir,
+ recursiveCheckAsync,
+ localAsync,
+ elements,
+ isUsing,
+ parsingToHexa,
};
diff --git a/src/morphism.ts b/src/morphism.ts
index aadd415..345751a 100644
--- a/src/morphism.ts
+++ b/src/morphism.ts
@@ -1,4 +1,6 @@
import type { FileHandler } from "./components/io/mainIO.ts";
+import { isUsing } from "./components/queries/mainQueries.ts";
+import composerTools from "./composer/composerTools.ts";
import type { CyclePluginMap, FunRouterOptions } from "./options.ts";
import type { ParamsMethod } from "./router/types.ts";
@@ -31,6 +33,10 @@ export type ResolveMorphism = Morphism<
any
>;
+
+
+
+
/**
* Types Morphisims
*/
@@ -222,7 +228,7 @@ export const petitions = {
AT = any,
R = any,
>(
- I: Morphism<
+ m: Morphism<
{
type: "morphism";
},
@@ -235,7 +241,18 @@ export const petitions = {
AT,
R
>,
- ) => ({ ...I, type: "morphism", o }),
+ ) => (
+ (isUsing) => ({
+ ...m,
+ type: 'morphism',
+ isUsing: isUsing,
+ isAsync: composerTools.localAsync(o)(m as Petition)(isUsing),
+ o
+ })
+ )(
+ composerTools.isUsing(o)(m as Petition)
+ ),
+
/**
* Configures and types a branch morphism to be used within a petition. Branch morphisms are designed to execute
* alongside or within the main function (`f`) of a petition, allowing for the extension of functionality through
@@ -279,7 +296,7 @@ export const petitions = {
AT = any,
R = any,
>(
- I: Morphism<
+ m: Morphism<
{
type: "morphism";
branch: true;
@@ -293,7 +310,17 @@ export const petitions = {
AT,
R
>,
- ) => ({ ...I, type: "morphism", o }),
+ ) => (
+ (isUsing) => ({
+ ...m,
+ type: 'morphism',
+ isUsing: isUsing,
+ isAsync: composerTools.localAsync(o)(m as Petition)(isUsing),
+ o
+ })
+ )(
+ composerTools.isUsing(o)(m as Petition)
+ ),
/**
* Joins multiple Morphisms or Petitions into a single unified array, ensuring that each component adheres to
* the specifications of being a valid petition with a designated path. This function is particularly useful
From d90c21fd2c2e338720613a58e4b7674cc0bdc8c9 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Thu, 20 Jun 2024 10:23:02 +0100
Subject: [PATCH 08/12] Adding `fileServer` to `plugins`
---
fun.ts | 4 ++--
src/composer/mainComposer.ts | 2 +-
src/exportable/plugin.ts | 3 ++-
src/morphism.ts | 21 ++++++---------------
src/staticFiles/composedPaths.ts | 2 +-
src/staticFiles/staticFileMain.ts | 2 +-
src/staticFiles/staticFileTools.ts | 6 +++---
test/staticFile/main.test.ts | 4 ++--
8 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/fun.ts b/fun.ts
index 997b6b9..0341193 100644
--- a/fun.ts
+++ b/fun.ts
@@ -13,11 +13,11 @@ import type { fileServerPetition, Petition } from "./src/morphism.ts";
type vixeny = (
o?: FunRouterOptions,
) => (
- routes: (Petition | fileServerPetition)[],
+ routes: (Petition | fileServerPetition)[],
) => (r: Request) => Promise | Response;
export default ((o?: FunRouterOptions) =>
-(routes: (Petition | fileServerPetition)[]) =>
+(routes: (Petition | fileServerPetition)[]) =>
((re) =>
((map) =>
((s) => (r: Request): Promise | Response => map[s(r)](r))(
diff --git a/src/composer/mainComposer.ts b/src/composer/mainComposer.ts
index 99a39fc..f46b2c6 100644
--- a/src/composer/mainComposer.ts
+++ b/src/composer/mainComposer.ts
@@ -9,7 +9,7 @@ import type { fileServerPetition, Petition } from "../morphism.ts";
export default (
o?: FunRouterOptions,
-): (routes: (Petition | fileServerPetition)[]) => RouteTypes[] =>
+): (routes: (Petition | fileServerPetition)[]) => RouteTypes[] =>
(ar) =>
ar
.filter(
diff --git a/src/exportable/plugin.ts b/src/exportable/plugin.ts
index 757c5e3..0cb2681 100644
--- a/src/exportable/plugin.ts
+++ b/src/exportable/plugin.ts
@@ -1,6 +1,6 @@
//TODO: add
import composerTools from "../composer/composerTools.ts";
-import type { Petition, StaticFilePlugin } from "../morphism.ts";
+import type { Petition, StaticFilePlugin, fileServerPetition } from "../morphism.ts";
import checkerTools from "../composer/checkPetition/checkTools.ts";
import {
type CyclePlugin,
@@ -110,6 +110,7 @@ export default {
* only the relevant context elements are included
*/
isUsing: composerTools.isUsing,
+ fileServer: (s:fileServerPetition):fileServerPetition => s,
staticFilePlugin: <
TP extends "response" | "request" | undefined,
O extends StaticFilePlugin,
diff --git a/src/morphism.ts b/src/morphism.ts
index 345751a..bc297ac 100644
--- a/src/morphism.ts
+++ b/src/morphism.ts
@@ -1019,24 +1019,15 @@ export type StaticFilePluginExtensions<
/**
* Object for raw response static.
*/
-export type fileServerPetition =
- & ({
- type: "fileServer";
- name: string;
- path: string;
- } | {
- type: "fileServer";
- name: string;
- path: string;
- mime?: true;
- extra: [string, string][];
- } | {
+export type fileServerPetition <
+ MI extends true | false
+> =
+ {
type: "fileServer";
name: string;
path: string;
- mime: false;
- })
- & {
+ mime?: MI;
+ extra?: MI extends true ? [string, string][] : never;
template?: StaticFilePlugin[];
removeExtensionOf?: defaultMime[];
slashIs?: string;
diff --git a/src/staticFiles/composedPaths.ts b/src/staticFiles/composedPaths.ts
index 8fba106..0d43a2e 100644
--- a/src/staticFiles/composedPaths.ts
+++ b/src/staticFiles/composedPaths.ts
@@ -3,7 +3,7 @@ import staticFileTools from "./staticFileTools.ts";
//TODO: make it more readable 🙏
-export default (f: fileServerPetition) =>
+export default (f: fileServerPetition) =>
(name: string) =>
(root: string) =>
(paths: string[]) =>
diff --git a/src/staticFiles/staticFileMain.ts b/src/staticFiles/staticFileMain.ts
index 01c49fc..9acd75b 100644
--- a/src/staticFiles/staticFileMain.ts
+++ b/src/staticFiles/staticFileMain.ts
@@ -2,7 +2,7 @@ import type { fileServerPetition } from "../morphism.ts";
import composedPaths from "./composedPaths.ts";
import staticFileTools from "./staticFileTools.ts";
-export default (maybeOfFiles?: string[]) => (f: fileServerPetition) =>
+export default (maybeOfFiles?: string[]) => (f: fileServerPetition) =>
staticFileTools.removeExtension(f)(
composedPaths(f)(staticFileTools.rectify(f.path))(
staticFileTools.rectify(f.name),
diff --git a/src/staticFiles/staticFileTools.ts b/src/staticFiles/staticFileTools.ts
index 5ec6b6b..9f9de05 100644
--- a/src/staticFiles/staticFileTools.ts
+++ b/src/staticFiles/staticFileTools.ts
@@ -11,17 +11,17 @@ export default {
join: (base: string) => (target: string): string =>
base.endsWith("/") ? base + target : base + "/" + target,
- mimeForm: (f: fileServerPetition) =>
+ mimeForm: (f: fileServerPetition) =>
"mime" in f && f.mime === false
? []
: "extra" in f
- ? mime.concat(f.extra)
+ ? mime.concat(f.extra as [string,string][])
: mime,
getMime: (mimes: [string, string][]) => (ext: string): string =>
(mimes.find((x) => x[0] === ext) || [".txt", "text/html"])[1],
- removeExtension: (f: fileServerPetition) => (petitions: Petition[]) =>
+ removeExtension: (f: fileServerPetition) => (petitions: Petition[]) =>
f.removeExtensionOf && Array.isArray(f.removeExtensionOf)
? petitions.map(
(x) =>
diff --git a/test/staticFile/main.test.ts b/test/staticFile/main.test.ts
index 43211a0..abd1242 100644
--- a/test/staticFile/main.test.ts
+++ b/test/staticFile/main.test.ts
@@ -1,7 +1,7 @@
import { assertEquals } from "@std/assert";
import { test } from "@cross/test";
import main from "../../src/staticFiles/staticFileMain.ts";
-import { petitions } from "../../src/morphism.ts";
+import { petitions, type fileServerPetition } from "../../src/morphism.ts";
test(
"static file checking logo",
@@ -76,7 +76,7 @@ test(
r: () => new Response(""),
}),
}],
- })
+ } as fileServerPetition)
.some((x) => x.path === "/hello/nested/logo"),
true,
),
From 7bbddccaf7a59c80d932291bac190a16aa9169a8 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Thu, 20 Jun 2024 11:20:18 +0100
Subject: [PATCH 09/12] removing slow types
---
.github/workflows/deno.yml | 5 +-
deno.json | 2 +-
package.json | 5 +-
.../cookieToToken/cookieToTokenGets.ts | 5 +-
.../cookieToToken/mainCookieToToken.ts | 59 ++++-----
src/components/encode/b64toUrl.mjs | 2 +-
.../jwt/{signSha256.mjs => signSha256.ts} | 10 +-
src/components/jwt/src/sign/sha256.mjs | 79 ------------
src/components/jwt/src/sign/sha256.ts | 44 +++++++
.../jwt/src/verify/{sha256.mjs => sha256.ts} | 11 +-
.../jwt/{verifySha256.mjs => verifySha256.ts} | 16 +--
src/components/runtime/{name.mjs => name.ts} | 2 +
src/composer/composerTools.ts | 18 +--
src/composer/nativeComponents.ts | 10 +-
src/exportable/plugin.ts | 10 +-
src/morphism.ts | 112 ++++++++++--------
src/staticFiles/staticFileTools.ts | 2 +-
.../cookieToToken/cookieToToken.test.ts | 2 +-
test/staticFile/main.test.ts | 2 +-
19 files changed, 201 insertions(+), 195 deletions(-)
rename src/components/jwt/{signSha256.mjs => signSha256.ts} (64%)
delete mode 100644 src/components/jwt/src/sign/sha256.mjs
create mode 100644 src/components/jwt/src/sign/sha256.ts
rename src/components/jwt/src/verify/{sha256.mjs => sha256.ts} (78%)
rename src/components/jwt/{verifySha256.mjs => verifySha256.ts} (54%)
rename src/components/runtime/{name.mjs => name.ts} (94%)
diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml
index 073503b..dd215ba 100644
--- a/.github/workflows/deno.yml
+++ b/.github/workflows/deno.yml
@@ -19,7 +19,10 @@ jobs:
with:
deno-version: v1.x # Uses latest deno version 1
- run: deno add @cross/test @std/assert # Installs dependencies from jsr.io
- - run: deno test -A # Runs tests
+ - run: deno test -A
- name: Verify formatting
run: deno fmt --check
+
+ - name: Verify JSR
+ run: deno publish --dry-run
diff --git a/deno.json b/deno.json
index 26dc882..a6cad37 100644
--- a/deno.json
+++ b/deno.json
@@ -1,6 +1,6 @@
{
"name": "@vixeny/core",
- "version": "0.1.37",
+ "version": "0.1.40",
"exports": "./main.ts",
"imports": {
"@cross/test": "jsr:@cross/test@^0.0.9",
diff --git a/package.json b/package.json
index 5432421..efb62e1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vixeny",
- "version": "0.1.37",
+ "version": "0.1.40",
"description": "A functional router for Bun and Deno",
"main": "main.ts",
"type": "module",
@@ -8,7 +8,8 @@
"test": "test"
},
"scripts": {
- "test": "deno test -A ./test/*"
+ "test": "deno test -A ./test/*",
+ "release": "deno test -A ./test/* && deno fmt --check && deno publish --dry-run"
},
"repository": {
"type": "git",
diff --git a/src/components/cookieToToken/cookieToTokenGets.ts b/src/components/cookieToToken/cookieToTokenGets.ts
index e3f59e6..b93f89e 100644
--- a/src/components/cookieToToken/cookieToTokenGets.ts
+++ b/src/components/cookieToToken/cookieToTokenGets.ts
@@ -1,7 +1,6 @@
-import verifySha256 from "../jwt/verifySha256.mjs";
-import type { SupportedKeys } from "../../morphism.ts";
+import verifySha256 from "../jwt/verifySha256.ts";
-export default (secret: SupportedKeys) => (name: string) =>
+export default (secret: Uint8Array) => (name: string) =>
(
(sha256) => (c: string | null) =>
(
diff --git a/src/components/cookieToToken/mainCookieToToken.ts b/src/components/cookieToToken/mainCookieToToken.ts
index 989aefa..b9b5c3f 100644
--- a/src/components/cookieToToken/mainCookieToToken.ts
+++ b/src/components/cookieToToken/mainCookieToToken.ts
@@ -3,34 +3,39 @@ import type { Petition, SupportedKeys } from "../../morphism.ts";
import cookieToTokenBodyParser from "./cookieToTokenBodyParser.ts";
import cookieToTokenGets from "./cookieToTokenGets.ts";
import plugins from "../../exportable/plugin.ts";
+import composerTools from "../../composer/composerTools.ts";
-export const f = (o?: FunRouterOptions) => (p: Petition) =>
- p.crypto && "globalKey" in p.crypto
- ? (
- (getCookies) =>
- "token" in p.crypto
- ? ((s: SupportedKeys) => (arr: string[]) =>
- arr.reduce(
- (acc, x) => acc(cookieToTokenGets(s)(x)),
- cookieToTokenBodyParser(arr),
- ))(p.crypto.globalKey)(
- //@ts-ignore
- Object.keys(p.crypto.token),
- )
- : getCookies && getCookies.length > 0
- ? ((s: SupportedKeys) => (arr: string[]) =>
- arr.reduce(
- (acc, x) => acc(cookieToTokenGets(s)(x)),
- cookieToTokenBodyParser(arr),
- ))(p.crypto.globalKey)(
- getCookies,
- )
- : void console.error("No token found, please use 'token' ") ??
- (() => null)
- )(
- plugins.pluginIsUsing(p)("token"),
- )
- : () => null;
+export const f =
+ (o?: FunRouterOptions) =>
+ (p: Petition): (s: string) => Record =>
+ p.crypto && "globalKey" in p.crypto
+ ? (
+ (getCookies) =>
+ "token" in p.crypto
+ ? ((s: SupportedKeys) => (arr: string[]) =>
+ arr.reduce(
+ (acc, x) =>
+ acc(cookieToTokenGets(composerTools.parsingToHexa(s))(x)),
+ cookieToTokenBodyParser(arr),
+ ))(p.crypto.globalKey)(
+ //@ts-ignore
+ Object.keys(p.crypto.token),
+ )
+ : getCookies && getCookies.length > 0
+ ? ((s: SupportedKeys) => (arr: string[]) =>
+ arr.reduce(
+ (acc, x) =>
+ acc(cookieToTokenGets(composerTools.parsingToHexa(s))(x)),
+ cookieToTokenBodyParser(arr),
+ ))(p.crypto.globalKey)(
+ getCookies,
+ )
+ : void console.error("No token found, please use 'token' ") ??
+ ((_: string) => null)
+ )(
+ plugins.pluginIsUsing(p)("token"),
+ )
+ : () => null;
export const isUsing = (o?: FunRouterOptions) => (p: Petition): string =>
(
diff --git a/src/components/encode/b64toUrl.mjs b/src/components/encode/b64toUrl.mjs
index 1c73580..e6ac758 100644
--- a/src/components/encode/b64toUrl.mjs
+++ b/src/components/encode/b64toUrl.mjs
@@ -1,7 +1,7 @@
import bun from "./src/base64toUrl/convertBase64ToBase64urlBun.mjs";
import deno from "./src/base64toUrl/convertBase64ToBase64urlDeno.mjs";
import node from "./src/base64toUrl/convertBase64ToBase64urlNode.mjs";
-import name from "../runtime/name.mjs";
+import name from "../runtime/name.js";
/**
* Selects and returns a function to convert Base64 strings to Base64Url strings based on the runtime environment.
diff --git a/src/components/jwt/signSha256.mjs b/src/components/jwt/signSha256.ts
similarity index 64%
rename from src/components/jwt/signSha256.mjs
rename to src/components/jwt/signSha256.ts
index e080ded..f632a16 100644
--- a/src/components/jwt/signSha256.mjs
+++ b/src/components/jwt/signSha256.ts
@@ -1,18 +1,22 @@
-import signer from "./src/sign/sha256.mjs";
+import signer from "./src/sign/sha256.ts";
import nodeCrypto from "node:crypto";
import BufferProto from "node:buffer";
-import name from "../runtime/name.mjs";
+import args from "../runtime/name.ts";
+
+type HashFunction = (data: Uint8Array) => nodeCrypto.Hash;
export default () =>
(
(rt) =>
signer(
+ //@ts-ignore
rt === "Bun" ? Buffer : BufferProto.Buffer,
)(
rt === "Bun"
+ //@ts-ignore
? (d) => new Bun.CryptoHasher("sha256").update(d)
: (d) => nodeCrypto.createHash("sha256").update(d),
)
)(
- name(),
+ args(),
)();
diff --git a/src/components/jwt/src/sign/sha256.mjs b/src/components/jwt/src/sign/sha256.mjs
deleted file mode 100644
index af79afc..0000000
--- a/src/components/jwt/src/sign/sha256.mjs
+++ /dev/null
@@ -1,79 +0,0 @@
-export default (Buffer) =>
-(sha256) =>
-(
- header = Buffer.from(JSON.stringify({
- alg: "HS256",
- typ: "JWT",
- })).toString("base64url") + ".",
-) =>
-(key) =>
- (
- (hmac) =>
- ((lf) => (rg) => (message) =>
- (
- (json) =>
- header + json + "." +
- sha256(
- Buffer.concat([
- lf,
- sha256(
- Buffer.concat([
- rg,
- Buffer.from(header + json),
- ]),
- ).digest(),
- ]),
- )
- .digest().toString("base64url")
- )(
- Buffer.from(JSON.stringify(message)).toString("base64url"),
- ))(new Uint8Array(64).map((_x, i) => hmac[i] ^ 0x5c))(
- new Uint8Array(64).map((_x, i) => hmac[i] ^ 0x36),
- )
- )(
- key.length > 64
- ? sha256(key).digest()
- : key.length < 64
- ? Buffer.concat([key, Buffer.alloc(64 - key.length)])
- : key,
- );
-
-// import concatTwoUint8Array from "../../../bytes/src/concatTwoUint8Array.mjs";
-// export default (Buffer) =>
-// (sha256) =>
-// (
-// header = Buffer.from(JSON.stringify({
-// alg: "HS256",
-// typ: "JWT",
-// })).toString("base64url") + ".",
-// ) =>
-// (key) =>
-// (
-// (hmac) => (message) =>
-// (
-// (json) =>
-// header + json + "." +
-// sha256(
-// concatTwoUint8Array(
-// new Uint8Array(64).map((_x, i) => hmac[i] ^ 0x5c)
-// )(
-// sha256(
-// concatTwoUint8Array(
-// new Uint8Array(64).map((_x, i) => hmac[i] ^ 0x36)
-// )(
-// Buffer.from(header + json)
-// )
-// ).digest(),
-// )
-// )
-// .digest().toString("base64url")
-// )(
-// Buffer.from(JSON.stringify(message)).toString("base64url"),
-// )
-// )(
-// key.length > 64
-// ? sha256(key).digest()
-// : key.length < 64
-// ? Buffer.concat([key, Buffer.alloc(64 - key.length)])
-// : key,
-// );
diff --git a/src/components/jwt/src/sign/sha256.ts b/src/components/jwt/src/sign/sha256.ts
new file mode 100644
index 0000000..e8e1f8f
--- /dev/null
+++ b/src/components/jwt/src/sign/sha256.ts
@@ -0,0 +1,44 @@
+import type BufferProto from "node:buffer";
+import type nodeCrypto from "node:crypto";
+
+type HashFunction = (data: Uint8Array) => nodeCrypto.Hash;
+
+export default (Buffer: typeof BufferProto.Buffer) =>
+(sha256: HashFunction) =>
+(
+ header = Buffer.from(JSON.stringify({
+ alg: "HS256",
+ typ: "JWT",
+ })).toString("base64url") + ".",
+) =>
+(key: Uint8Array) =>
+ (
+ (hmac) =>
+ ((lf) => (rg: Uint8Array) => (message: Object) =>
+ (
+ (json) =>
+ header + json + "." +
+ sha256(
+ Buffer.concat([
+ lf,
+ sha256(
+ Buffer.concat([
+ rg,
+ Buffer.from(header + json),
+ ]),
+ ).digest(),
+ ]),
+ )
+ .digest().toString("base64url")
+ )(
+ Buffer.from(JSON.stringify(message)).toString("base64url"),
+ ))(new Uint8Array(64).map((_x, i) => hmac[i] ^ 0x5c))(
+ new Uint8Array(64).map((_x, i) => hmac[i] ^ 0x36),
+ )
+ )(
+ key.length > 64
+ ? sha256(key).digest()
+ : key.length < 64
+ ? Buffer.concat([key, Buffer.alloc(64 - key.length)])
+ : key,
+ );
diff --git a/src/components/jwt/src/verify/sha256.mjs b/src/components/jwt/src/verify/sha256.ts
similarity index 78%
rename from src/components/jwt/src/verify/sha256.mjs
rename to src/components/jwt/src/verify/sha256.ts
index a182619..2b102af 100644
--- a/src/components/jwt/src/verify/sha256.mjs
+++ b/src/components/jwt/src/verify/sha256.ts
@@ -1,8 +1,15 @@
-export default (Buffer) => (hash) => (key) =>
+import type BufferProto from "node:buffer";
+import type nodeCrypto from "node:crypto";
+
+type HashFunction = (data: Uint8Array) => nodeCrypto.Hash;
+
+export default (Buffer: typeof BufferProto.Buffer) =>
+(hash: HashFunction) =>
+(key: Uint8Array) =>
(
(hmac) =>
(
- (lf) => (rg) => (message) =>
+ (lf) => (rg: Uint8Array) => (message: string) =>
message.substring(message.lastIndexOf(".") + 1) ===
hash(
Buffer.concat([
diff --git a/src/components/jwt/verifySha256.mjs b/src/components/jwt/verifySha256.ts
similarity index 54%
rename from src/components/jwt/verifySha256.mjs
rename to src/components/jwt/verifySha256.ts
index cd9192f..0aae9c4 100644
--- a/src/components/jwt/verifySha256.mjs
+++ b/src/components/jwt/verifySha256.ts
@@ -1,21 +1,23 @@
-import verify from "./src/verify/sha256.mjs";
+import verify from "./src/verify/sha256.ts";
+import args from "../runtime/name.ts";
import nodeCrypto from "node:crypto";
import BufferProto from "node:buffer";
+args();
+
export default () =>
(
(rt) =>
verify(
+ //@ts-ignore
rt === "Bun" ? Buffer : BufferProto.Buffer,
)(
rt === "Bun"
+ //@ts-ignore
? (d) => new Bun.CryptoHasher("sha256").update(d)
- : (d) => nodeCrypto.createHash("sha256").update(d),
+ : (d: nodeCrypto.BinaryLike) =>
+ nodeCrypto.createHash("sha256").update(d),
)
)(
- typeof Bun !== "undefined"
- ? "Bun"
- : typeof Bun !== "undefined"
- ? "Deno"
- : "Node",
+ args(),
);
diff --git a/src/components/runtime/name.mjs b/src/components/runtime/name.ts
similarity index 94%
rename from src/components/runtime/name.mjs
rename to src/components/runtime/name.ts
index 505073e..8237ee2 100644
--- a/src/components/runtime/name.mjs
+++ b/src/components/runtime/name.ts
@@ -19,8 +19,10 @@
*/
export default () =>
+ //@ts-ignore
typeof Bun !== "undefined"
? "Bun"
+ //@ts-ignore
: typeof Bun !== "undefined"
? "Deno"
: "Node";
diff --git a/src/composer/composerTools.ts b/src/composer/composerTools.ts
index dfb3219..d6977af 100644
--- a/src/composer/composerTools.ts
+++ b/src/composer/composerTools.ts
@@ -1,4 +1,4 @@
-import type { Petition } from "../morphism.ts";
+import type { Petition, SupportedKeys } from "../morphism.ts";
import type { FunRouterOptions } from "../options.ts";
import mainCheck from "./checkPetition/mainCheck.ts";
type RecFunc = (f: Petition) => boolean;
@@ -34,7 +34,7 @@ const recursiveCheckAsync =
))(
(solver: RecFunc) => (p: Petition): boolean =>
p.f.constructor.name === "AsyncFunction" ||
- p.isAsync
+ p.isAsync
? true
: p.f.constructor.name === "Function" &&
typeof p.resolve === "undefined"
@@ -56,12 +56,12 @@ const recursiveCheckAsync =
false,
) as unknown as (f: Petition) => boolean;
-const parsingToHexa = (crypto: { globalKey: string }): Uint8Array =>
- typeof crypto.globalKey === "string"
- ? /^[0-9a-fA-F]+$/g.test(crypto.globalKey)
- ? new Uint8Array([...crypto.globalKey].map((x) => x.charCodeAt(0)))
- : new Uint8Array([...crypto.globalKey].map((x) => x.charCodeAt(0)))
- : crypto.globalKey;
+const parsingToHexa = (globalKey: SupportedKeys): Uint8Array =>
+ typeof globalKey === "string"
+ ? /^[0-9a-fA-F]+$/g.test(globalKey)
+ ? new Uint8Array([...globalKey].map((x) => x.charCodeAt(0)))
+ : new Uint8Array([...globalKey].map((x) => x.charCodeAt(0)))
+ : globalKey;
const isUsing = (o?: FunRouterOptions) => (f: Petition): string[] =>
mainCheck(o)(f);
@@ -109,7 +109,7 @@ const localAsync =
(p: Petition) =>
(elementsUsed: string[]): boolean =>
(
- (p.f.constructor.name === "AsyncFunction" ) ||
+ (p.f.constructor.name === "AsyncFunction") ||
o && o.cyclePlugin && Object.keys(o.cyclePlugin || {})
.some((x) =>
elementsUsed.includes(x)
diff --git a/src/composer/nativeComponents.ts b/src/composer/nativeComponents.ts
index f92adf7..0e23bc7 100644
--- a/src/composer/nativeComponents.ts
+++ b/src/composer/nativeComponents.ts
@@ -4,8 +4,8 @@ import { f as cookies } from "../components/cookies/mainCookies.ts";
import resolve from "./resolve/main.ts";
import branch from "./branch/branchMain.ts";
import { f as mainCookieToToken } from "../components/cookieToToken/mainCookieToToken.ts";
-import signSha256 from "../components/jwt/signSha256.mjs";
-import verifySha256 from "../components/jwt/verifySha256.mjs";
+import signSha256 from "../components/jwt/signSha256.ts";
+import verifySha256 from "../components/jwt/verifySha256.ts";
import mainIO from "../components/io/mainIO.ts";
import { parse, stringToFunction } from "../components/cors/mainCORS.ts";
@@ -44,7 +44,7 @@ export default (o?: FunRouterOptions) =>
action: () =>
f.crypto && "globalKey" in f.crypto
? verifySha256()(
- tools.parsingToHexa(f.crypto as { globalKey: string }),
+ tools.parsingToHexa(f.crypto.globalKey),
)
: void console.error(
"I don't know you got this message, contact me in discord," +
@@ -56,7 +56,7 @@ export default (o?: FunRouterOptions) =>
action: () =>
f.crypto && "globalKey" in f.crypto
? signSha256()(
- tools.parsingToHexa(f.crypto as { globalKey: string }),
+ tools.parsingToHexa(f.crypto.globalKey),
)
: void console.error(
"I don't know you got this message, contact me in discord," +
@@ -70,7 +70,7 @@ export default (o?: FunRouterOptions) =>
...f,
crypto: {
...f.crypto,
- globalKey: tools.parsingToHexa(f.crypto as { globalKey: string }),
+ globalKey: tools.parsingToHexa(f.crypto.globalKey),
},
}),
},
diff --git a/src/exportable/plugin.ts b/src/exportable/plugin.ts
index 0cb2681..12bb18a 100644
--- a/src/exportable/plugin.ts
+++ b/src/exportable/plugin.ts
@@ -1,6 +1,10 @@
//TODO: add
import composerTools from "../composer/composerTools.ts";
-import type { Petition, StaticFilePlugin, fileServerPetition } from "../morphism.ts";
+import type {
+ fileServerPetition,
+ Petition,
+ StaticFilePlugin,
+} from "../morphism.ts";
import checkerTools from "../composer/checkPetition/checkTools.ts";
import {
type CyclePlugin,
@@ -110,7 +114,9 @@ export default {
* only the relevant context elements are included
*/
isUsing: composerTools.isUsing,
- fileServer: (s:fileServerPetition):fileServerPetition => s,
+ fileServer: (
+ s: fileServerPetition,
+ ): fileServerPetition => s,
staticFilePlugin: <
TP extends "response" | "request" | undefined,
O extends StaticFilePlugin,
diff --git a/src/morphism.ts b/src/morphism.ts
index bc297ac..6d95055 100644
--- a/src/morphism.ts
+++ b/src/morphism.ts
@@ -33,10 +33,6 @@ export type ResolveMorphism = Morphism<
any
>;
-
-
-
-
/**
* Types Morphisims
*/
@@ -241,17 +237,30 @@ export const petitions = {
AT,
R
>,
- ) => (
- (isUsing) => ({
- ...m,
- type: 'morphism',
- isUsing: isUsing,
- isAsync: composerTools.localAsync(o)(m as Petition)(isUsing),
- o
- })
- )(
- composerTools.isUsing(o)(m as Petition)
- ),
+ ) =>
+ (
+ (isUsing) => ({
+ ...m,
+ type: "morphism",
+ isUsing: isUsing,
+ isAsync: composerTools.localAsync(o)(m as Petition)(isUsing),
+ o,
+ })
+ )(
+ composerTools.isUsing(o)(m as Petition),
+ ) as unknown as Morphism<
+ {
+ type: "morphism";
+ },
+ RM,
+ BM,
+ QO,
+ PO,
+ RO,
+ CO,
+ AT,
+ R
+ >,
/**
* Configures and types a branch morphism to be used within a petition. Branch morphisms are designed to execute
@@ -310,17 +319,31 @@ export const petitions = {
AT,
R
>,
- ) => (
- (isUsing) => ({
- ...m,
- type: 'morphism',
- isUsing: isUsing,
- isAsync: composerTools.localAsync(o)(m as Petition)(isUsing),
- o
- })
- )(
- composerTools.isUsing(o)(m as Petition)
- ),
+ ) =>
+ (
+ (isUsing) => ({
+ ...m,
+ type: "morphism",
+ isUsing: isUsing,
+ isAsync: composerTools.localAsync(o)(m as Petition)(isUsing),
+ o,
+ })
+ )(
+ composerTools.isUsing(o)(m as Petition),
+ ) as unknown as Morphism<
+ {
+ type: "morphism";
+ branch: true;
+ },
+ RM,
+ BM,
+ QO,
+ PO,
+ RO,
+ CO,
+ AT,
+ R
+ >,
/**
* Joins multiple Morphisms or Petitions into a single unified array, ensuring that each component adheres to
* the specifications of being a valid petition with a designated path. This function is particularly useful
@@ -1019,33 +1042,22 @@ export type StaticFilePluginExtensions<
/**
* Object for raw response static.
*/
-export type fileServerPetition <
- MI extends true | false
-> =
- {
- type: "fileServer";
- name: string;
- path: string;
- mime?: MI;
- extra?: MI extends true ? [string, string][] : never;
- template?: StaticFilePlugin[];
- removeExtensionOf?: defaultMime[];
- slashIs?: string;
- };
+export type fileServerPetition<
+ MI extends true | false,
+> = {
+ type: "fileServer";
+ name: string;
+ path: string;
+ mime?: MI;
+ extra?: MI extends true ? [string, string][] : never;
+ template?: StaticFilePlugin[];
+ removeExtensionOf?: defaultMime[];
+ slashIs?: string;
+};
export type SupportedKeys =
| string
- | Uint8Array
- | Uint8ClampedArray
- | Uint16Array
- | Uint32Array
- | Int8Array
- | Int16Array
- | Int32Array
- | BigUint64Array
- | BigInt64Array
- | Float32Array
- | Float64Array;
+ | Uint8Array;
export type defaultMime =
| ".aac"
diff --git a/src/staticFiles/staticFileTools.ts b/src/staticFiles/staticFileTools.ts
index 9f9de05..e34ce7a 100644
--- a/src/staticFiles/staticFileTools.ts
+++ b/src/staticFiles/staticFileTools.ts
@@ -15,7 +15,7 @@ export default {
"mime" in f && f.mime === false
? []
: "extra" in f
- ? mime.concat(f.extra as [string,string][])
+ ? mime.concat(f.extra as [string, string][])
: mime,
getMime: (mimes: [string, string][]) => (ext: string): string =>
diff --git a/test/components/cookieToToken/cookieToToken.test.ts b/test/components/cookieToToken/cookieToToken.test.ts
index c7268cd..7dfbe9f 100644
--- a/test/components/cookieToToken/cookieToToken.test.ts
+++ b/test/components/cookieToToken/cookieToToken.test.ts
@@ -1,7 +1,7 @@
import { assertEquals } from "@std/assert";
import { test } from "@cross/test";
-import signSha256 from "../../../src/components/jwt/signSha256.mjs";
+import signSha256 from "../../../src/components/jwt/signSha256.ts";
import { wrap } from "../../../main.ts";
const secret = new Uint8Array([1, 2, 3, 4, 5, 6]);
diff --git a/test/staticFile/main.test.ts b/test/staticFile/main.test.ts
index abd1242..123e9c8 100644
--- a/test/staticFile/main.test.ts
+++ b/test/staticFile/main.test.ts
@@ -1,7 +1,7 @@
import { assertEquals } from "@std/assert";
import { test } from "@cross/test";
import main from "../../src/staticFiles/staticFileMain.ts";
-import { petitions, type fileServerPetition } from "../../src/morphism.ts";
+import { type fileServerPetition, petitions } from "../../src/morphism.ts";
test(
"static file checking logo",
From 120c44f124cecc36ac5d5a44704237462f518bec Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Thu, 20 Jun 2024 21:27:50 +0100
Subject: [PATCH 10/12] testing bun github actions
---
.github/workflows/bun.yml | 14 ++
ReadMe.md | 2 +-
package.json | 4 +-
src/composer/checkPetition/checkTools.ts | 10 +-
test/router/resolver.test.ts | 160 +++++++++++------------
5 files changed, 104 insertions(+), 86 deletions(-)
create mode 100644 .github/workflows/bun.yml
diff --git a/.github/workflows/bun.yml b/.github/workflows/bun.yml
new file mode 100644
index 0000000..9b9e976
--- /dev/null
+++ b/.github/workflows/bun.yml
@@ -0,0 +1,14 @@
+name: Bun
+
+on: [push, pull_request]
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: antongolub/action-setup-bun@v1.12.8
+ with:
+ bun-version: v1.x # Uses latest bun 1
+ - run: bun x jsr add @cross/test @std/assert # Installs dependencies
+ - run: bun test # Runs the tests
\ No newline at end of file
diff --git a/ReadMe.md b/ReadMe.md
index 2f296bf..3fc613a 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -7,8 +7,8 @@
[![JSR](https://jsr.io/badges/@vixeny/core)](https://jsr.io/@vixeny/core)
-![GitHub Actions status](https://github.com/mimiMonads/vixeny/workflows/Deno/badge.svg)
[![npm version](https://img.shields.io/npm/v/vixeny.svg)](https://www.npmjs.com/package/vixeny)
+![GitHub Actions status](https://github.com/mimiMonads/vixeny/workflows/Bun/badge.svg)
**Vixeny: Pioneering Functional Web Development**
diff --git a/package.json b/package.json
index efb62e1..75fe899 100644
--- a/package.json
+++ b/package.json
@@ -34,9 +34,7 @@
"homepage": "https://vixeny.dev/",
"devDependencies": {
"bun-types": "^1.0.2",
- "mitata": "^0.1.6",
- "@cross/test": "npm:@jsr/cross__test",
- "@std/assert": "npm:@jsr/std__assert"
+ "mitata": "^0.1.6"
},
"peerDependencies": {
"typescript": "^5.0.0"
diff --git a/src/composer/checkPetition/checkTools.ts b/src/composer/checkPetition/checkTools.ts
index c634b3b..d461f34 100644
--- a/src/composer/checkPetition/checkTools.ts
+++ b/src/composer/checkPetition/checkTools.ts
@@ -40,7 +40,8 @@ export default (((regex) => ({
)(
(
new RegExp(
- `const\\s*\\{([^\\}]*)\\}\\s*=\\s*${toFind}(?:\\.|;|,|\\s)`,
+ `const\\s*\\{([^\\}]*)\\}\\s*=\\s*${toFind //.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
+ }(?:\\.|;|,|\\s)`,
"g",
)
).exec(
@@ -50,7 +51,12 @@ export default (((regex) => ({
getDots: (f) => (toSearch) =>
[
...f.toString()
- .split(new RegExp(`\\b${toSearch}(\\.|\\?\\.)`))
+ .split(
+ new RegExp(
+ `\\b${toSearch //.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
+ }(\\.|\\?\\.)`,
+ ),
+ )
.slice(1)
.map((x: string) => x.slice(0, x.match(/[^\w]/)?.index ?? x.length))
.reduce(
diff --git a/test/router/resolver.test.ts b/test/router/resolver.test.ts
index 02331dc..7248c69 100644
--- a/test/router/resolver.test.ts
+++ b/test/router/resolver.test.ts
@@ -31,7 +31,7 @@ test(
a(new Request("http://localhost:8080/hello/nested/***")),
a(new Request("http://localhost:8080/hello/***")),
a(new Request("http://localhost:8080/NOTFOUND")),
- a(new Request("http://localhost:8080/", { method: "BAD" })),
+ a(new Request("http://localhost:8080/", { method: "PUT" })),
],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 14, 13, 16, 17],
)
@@ -51,83 +51,83 @@ test(
),
);
-test(
- "resolver base",
- (_) =>
- (
- (a) =>
- assertEquals(
- [
- a(new Request("http://localhost:8080/")),
- a(new Request("http://localhost:8080/one")),
- a(new Request("http://localhost:8080/two")),
- a(new Request("http://localhost:8080/three")),
- a(new Request("http://localhost:8080/four")),
- a(new Request("http://localhost:8080/five")),
- a(new Request("http://localhost:8080/six")),
- a(new Request("http://localhost:8080/test")),
- a(new Request("http://localhost:8080/test/")),
- a(new Request("http://localhost:8080/test/1/2/")),
- a(new Request("http://localhost:8080/", { method: "POST" })),
- a(new Request("http://localhost:8080/", { method: "HEAD" })),
- a(new Request("http://localhost:8080/", { method: "DELETE" })),
- a(new Request("http://localhost:8080/NOTFOUND")),
- a(new Request("http://localhost:8080/", { method: "BAD" })),
- ],
- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
- )
- )(
- solver()(atlas()(split()(optimize()(paths)))),
- ),
-);
+// test(
+// "resolver base",
+// (_) =>
+// (
+// (a) =>
+// assertEquals(
+// [
+// a(new Request("http://localhost:8080/")),
+// a(new Request("http://localhost:8080/one")),
+// a(new Request("http://localhost:8080/two")),
+// a(new Request("http://localhost:8080/three")),
+// a(new Request("http://localhost:8080/four")),
+// a(new Request("http://localhost:8080/five")),
+// a(new Request("http://localhost:8080/six")),
+// a(new Request("http://localhost:8080/test")),
+// a(new Request("http://localhost:8080/test/")),
+// a(new Request("http://localhost:8080/test/1/2/")),
+// a(new Request("http://localhost:8080/", { method: "POST" })),
+// a(new Request("http://localhost:8080/", { method: "HEAD" })),
+// a(new Request("http://localhost:8080/", { method: "DELETE" })),
+// a(new Request("http://localhost:8080/NOTFOUND")),
+// a(new Request("http://localhost:8080/", { method: "BAD" })),
+// ],
+// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
+// )
+// )(
+// solver()(atlas()(split()(optimize()(paths)))),
+// ),
+// );
-test(
- "Normal order no options",
- (_) =>
- (
- (f) =>
- assertEquals(
- [
- f(new Request("http://localhost:8000/count")),
- f(new Request("http://localhost:8000/hello_world")),
- f(new Request("http://localhost:8000/random_number")),
- f(new Request("http://localhost:8000/plus_1", { method: "POST" })),
- f(new Request("http://localhost:8000/minus_1", { method: "POST" })),
- f(new Request("http://localhost:8000/NOTFOUND")),
- f(new Request("http://localhost:8000/", { method: "BAD" })),
- ],
- [0, 1, 2, 3, 4, 5, 6],
- )
- )(
- solver()(
- atlas()(
- split()(
- optimize()([
- {
- path: "/count",
- f: () => "1",
- },
- {
- path: "/hello_world",
- f: () => "2",
- },
- {
- path: "/random_number",
- f: () => "3",
- },
- {
- path: "/plus_1",
- f: () => "4",
- method: "POST",
- },
- {
- path: "/minus_1",
- f: () => "5",
- method: "POST",
- },
- ] as unknown as Petition[]),
- ),
- ),
- ),
- ),
-);
+// test(
+// "Normal order no options",
+// (_) =>
+// (
+// (f) =>
+// assertEquals(
+// [
+// f(new Request("http://localhost:8000/count")),
+// f(new Request("http://localhost:8000/hello_world")),
+// f(new Request("http://localhost:8000/random_number")),
+// f(new Request("http://localhost:8000/plus_1", { method: "POST" })),
+// f(new Request("http://localhost:8000/minus_1", { method: "POST" })),
+// f(new Request("http://localhost:8000/NOTFOUND")),
+// f(new Request("http://localhost:8000/", { method: "BAD" })),
+// ],
+// [0, 1, 2, 3, 4, 5, 6],
+// )
+// )(
+// solver()(
+// atlas()(
+// split()(
+// optimize()([
+// {
+// path: "/count",
+// f: () => "1",
+// },
+// {
+// path: "/hello_world",
+// f: () => "2",
+// },
+// {
+// path: "/random_number",
+// f: () => "3",
+// },
+// {
+// path: "/plus_1",
+// f: () => "4",
+// method: "POST",
+// },
+// {
+// path: "/minus_1",
+// f: () => "5",
+// method: "POST",
+// },
+// ] as unknown as Petition[]),
+// ),
+// ),
+// ),
+// ),
+// );
From 131c24deb5bd43a8b17206e0f8f9fbe5418d4065 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Thu, 20 Jun 2024 21:29:47 +0100
Subject: [PATCH 11/12] small changes
---
.github/workflows/bun.yml | 2 +-
ReadMe.md | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/bun.yml b/.github/workflows/bun.yml
index 9b9e976..e04e58e 100644
--- a/.github/workflows/bun.yml
+++ b/.github/workflows/bun.yml
@@ -11,4 +11,4 @@ jobs:
with:
bun-version: v1.x # Uses latest bun 1
- run: bun x jsr add @cross/test @std/assert # Installs dependencies
- - run: bun test # Runs the tests
\ No newline at end of file
+ - run: find . -type f -name "*.test.ts" | while read -r file; do echo "Running tests in $file"; bun test "$file"; done # Runs the tests
\ No newline at end of file
diff --git a/ReadMe.md b/ReadMe.md
index 3fc613a..3273174 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -8,6 +8,7 @@
[![JSR](https://jsr.io/badges/@vixeny/core)](https://jsr.io/@vixeny/core)
[![npm version](https://img.shields.io/npm/v/vixeny.svg)](https://www.npmjs.com/package/vixeny)
+![GitHub Actions status](https://github.com/mimiMonads/vixeny/workflows/Deno/badge.svg)
![GitHub Actions status](https://github.com/mimiMonads/vixeny/workflows/Bun/badge.svg)
**Vixeny: Pioneering Functional Web Development**
From 24b1fd8c07360152c003ab1f13ec6d4f2478d526 Mon Sep 17 00:00:00 2001
From: mimiMonads
Date: Fri, 21 Jun 2024 10:54:04 +0100
Subject: [PATCH 12/12] adding `plugins` to debug
---
src/exportable/display.ts | 26 +++++++++++++++++++++++++-
src/options.ts | 1 +
test/exportable/wrap.test.ts | 1 +
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/exportable/display.ts b/src/exportable/display.ts
index ea19111..797e936 100644
--- a/src/exportable/display.ts
+++ b/src/exportable/display.ts
@@ -3,7 +3,11 @@ import { isUsing as query } from "../components/queries/mainQueries.ts";
import { isUsing as cookie } from "../components/cookies/mainCookies.ts";
import { isUsing as token } from "../components/cookieToToken/mainCookieToToken.ts";
import type { Petition } from "../morphism.ts";
-import type { FunRouterOptions } from "../options.ts";
+import type {
+ CyclePlugin,
+ CyclePluginMap,
+ FunRouterOptions,
+} from "../options.ts";
type Display = {
using?: string[];
@@ -34,6 +38,7 @@ export const displayPaths = (p: Petition): void => (
)
);
+type PluginType = [string, CyclePlugin];
export const display =
(options?: FunRouterOptions) =>
(p: Petition) =>
@@ -58,5 +63,24 @@ export const display =
: acc + "",
"--- Components ---\n",
),
+ ),
+ console.log(
+ Object.keys(options?.cyclePlugin)
+ .map((name) =>
+ (object.using ?? []).includes(name) &&
+ "isUsing" in options!.cyclePlugin[name]
+ ? [name, options!.cyclePlugin[name]] as PluginType
+ : false
+ )
+ .filter((item): item is PluginType => Boolean(item))
+ .filter((x) => void console.log(x) ?? x)
+ .reduce(
+ (acc, tulip): string =>
+ acc +
+ `\x1b[35m${tulip[0]}\x1b[0m: \x1b[38;2;255;165;0m${
+ //@ts-ignore
+ tulip[1].isUsing(options)(p)}\x1b[0m \n`,
+ "--- Plugins ---\n",
+ ),
)
);
diff --git a/src/options.ts b/src/options.ts
index 5c27685..e330c43 100644
--- a/src/options.ts
+++ b/src/options.ts
@@ -131,6 +131,7 @@ export type CyclePlugin<
p: Petition,
) => (r: Request | [Request, Record]) => any;
readonly type: unknown;
+ readonly isUsing?: (o?: FunRouterOptions) => (p: Petition) => string;
readonly options?: { [k: string]: any };
};
diff --git a/test/exportable/wrap.test.ts b/test/exportable/wrap.test.ts
index 56c6917..0612ce4 100644
--- a/test/exportable/wrap.test.ts
+++ b/test/exportable/wrap.test.ts
@@ -19,6 +19,7 @@ const pluginMethod = plugins.type({
name: Symbol.for("method"),
type: {} as string,
f: () => () => () => " inCycle",
+ isUsing: () => () => "sup",
});
const opt = plugins.globalOptions({