diff --git a/.github/workflows/bun.yml b/.github/workflows/bun.yml
new file mode 100644
index 0000000..e04e58e
--- /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: 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/.github/workflows/deno.yml b/.github/workflows/deno.yml
index 80507b6..dd215ba 100644
--- a/.github/workflows/deno.yml
+++ b/.github/workflows/deno.yml
@@ -8,33 +8,21 @@
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
- name: Verify formatting
run: deno fmt --check
-
- - name: Run tests
- run: deno test -A
+ - name: Verify JSR
+ run: deno publish --dry-run
diff --git a/ReadMe.md b/ReadMe.md
index 2f296bf..3273174 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -7,8 +7,9 @@
[![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/Deno/badge.svg)
+![GitHub Actions status](https://github.com/mimiMonads/vixeny/workflows/Bun/badge.svg)
**Vixeny: Pioneering Functional Web Development**
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..a6cad37
--- /dev/null
+++ b/deno.json
@@ -0,0 +1,9 @@
+{
+ "name": "@vixeny/core",
+ "version": "0.1.40",
+ "exports": "./main.ts",
+ "imports": {
+ "@cross/test": "jsr:@cross/test@^0.0.9",
+ "@std/assert": "jsr:@std/assert@^0.226.0"
+ }
+}
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/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/main.ts b/main.ts
index 0ed4b8e..971fb40 100644
--- a/main.ts
+++ b/main.ts
@@ -1,22 +1,26 @@
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/cookies/mainCookies.ts";
+import { f as token } from "./src/components/cookieToToken/mainCookieToToken.ts";
/**
- * Runtime utilities
+ * Components utilities
*/
-export const runtime = {
- name: name,
- arguments: parseargs,
+export const components = {
+ query,
+ param,
+ cookie,
+ token,
};
/**
* Runtime utilities
*/
-export const components = {
- query: mainQueries,
- parameters: mainParameters,
+export const runtime = {
+ name: name,
+ arguments: parseargs,
};
/**
diff --git a/package.json b/package.json
index cb87ee0..75fe899 100644
--- a/package.json
+++ b/package.json
@@ -1,13 +1,15 @@
{
"name": "vixeny",
- "version": "0.1.37",
+ "version": "0.1.40",
"description": "A functional router for Bun and Deno",
"main": "main.ts",
+ "type": "module",
"directories": {
"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",
@@ -36,5 +38,7 @@
},
"peerDependencies": {
"typescript": "^5.0.0"
+ },
+ "dependencies": {
}
}
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/cookieToTokenMain.ts b/src/components/cookieToToken/cookieToTokenMain.ts
deleted file mode 100644
index d416c15..0000000
--- a/src/components/cookieToToken/cookieToTokenMain.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-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";
-
-export default (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"),
- )
- : () => ({ SystemError: "Crypto is requires" });
diff --git a/src/components/cookieToToken/mainCookieToToken.ts b/src/components/cookieToToken/mainCookieToToken.ts
new file mode 100644
index 0000000..b9b5c3f
--- /dev/null
+++ b/src/components/cookieToToken/mainCookieToToken.ts
@@ -0,0 +1,46 @@
+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 "../../exportable/plugin.ts";
+import composerTools from "../../composer/composerTools.ts";
+
+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 =>
+ (
+ (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..a05a69c
--- /dev/null
+++ b/src/components/cookies/cookieDefaultCase.ts
@@ -0,0 +1,15 @@
+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/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..36c30c5
--- /dev/null
+++ b/src/components/cookies/mainCookies.ts
@@ -0,0 +1,31 @@
+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";
+
+type Cookie = (string: string | null) => Record;
+
+const f = (o?: FunRouterOptions) => (p: Petition): Cookie =>
+ (
+ (cookies) =>
+ cookies
+ ? body(p.cookie?.only ?? cookies) as Cookie
+ : cookieDefaultCase() as Cookie
+ )(
+ plugins.pluginIsUsing(p)("cookies"),
+ );
+
+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"),
+ );
+
+export { f, isUsing };
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/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/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/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/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/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..3bd723c 100644
--- a/src/composer/compose.ts
+++ b/src/composer/compose.ts
@@ -26,43 +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"}))`)()
- : 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
{
- 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),
headers: "headings" in p
? typeof p.headings?.headers == "string"
? {
@@ -83,3 +55,18 @@ 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))));
diff --git a/src/composer/composerTools.ts b/src/composer/composerTools.ts
index 96bf71b..d6977af 100644
--- a/src/composer/composerTools.ts
+++ b/src/composer/composerTools.ts
@@ -1,103 +1,129 @@
-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;
-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[],
+ (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 = (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);
+
+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/composer/mainComposer.ts b/src/composer/mainComposer.ts
index 2b5c586..f46b2c6 100644
--- a/src/composer/mainComposer.ts
+++ b/src/composer/mainComposer.ts
@@ -9,9 +9,12 @@ import type { fileServerPetition, Petition } from "../morphism.ts";
export default (
o?: FunRouterOptions,
-): (routes: (Petition | fileServerPetition)[]) => RouteTypes[] =>
+): (routes: (Petition | fileServerPetition)[]) => RouteTypes[] =>
(ar) =>
ar
+ .filter(
+ (x) => !("active" in x && x.active === false),
+ )
.map(
(x) =>
x.type === "response"
diff --git a/src/composer/nativeComponents.ts b/src/composer/nativeComponents.ts
index 61226a4..0e23bc7 100644
--- a/src/composer/nativeComponents.ts
+++ b/src/composer/nativeComponents.ts
@@ -1,11 +1,11 @@
-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 signSha256 from "../components/jwt/signSha256.mjs";
-import verifySha256 from "../components/jwt/verifySha256.mjs";
+import { f as mainCookieToToken } from "../components/cookieToToken/mainCookieToToken.ts";
+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," +
@@ -66,11 +66,11 @@ export default (o?: FunRouterOptions) =>
{
condition: (x: NativeMaps) => x.name === "token",
action: () =>
- cookieToTokenMain(o)({
+ mainCookieToToken(o)({
...f,
crypto: {
...f.crypto,
- globalKey: tools.parsingToHexa(f.crypto as { globalKey: string }),
+ globalKey: tools.parsingToHexa(f.crypto.globalKey),
},
}),
},
diff --git a/src/exportable/composer.ts b/src/exportable/composer.ts
index 7166f92..30e246e 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",
@@ -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/exportable/display.ts b/src/exportable/display.ts
new file mode 100644
index 0000000..797e936
--- /dev/null
+++ b/src/exportable/display.ts
@@ -0,0 +1,86 @@
+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 {
+ CyclePlugin,
+ CyclePluginMap,
+ 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`,
+ )
+ ),
+ )
+);
+
+type PluginType = [string, CyclePlugin];
+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",
+ ),
+ ),
+ 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/exportable/plugin.ts b/src/exportable/plugin.ts
index 757c5e3..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 } from "../morphism.ts";
+import type {
+ fileServerPetition,
+ Petition,
+ StaticFilePlugin,
+} from "../morphism.ts";
import checkerTools from "../composer/checkPetition/checkTools.ts";
import {
type CyclePlugin,
@@ -110,6 +114,9 @@ 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/exportable/wrap.ts b/src/exportable/wrap.ts
index e8708b2..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
@@ -451,12 +452,19 @@ export const wrap = ((o?) => (a = []) => ({
{ ...ob, type: "base" } as Petition,
)),
- logPaths: () => void a.forEach((x) => console.log(x.path)) ?? wrap(o)(a),
- logLastCheck: () =>
- void console.log(
- a.length > 0
- ? composerTools.isUsing(o)(a[a.length - 1])
- : "This wrap is empty.",
+ logPaths: () =>
+ void a.forEach(
+ (x) => displayPaths(x),
+ ) ?? wrap(o)(a),
+ debugLast: () =>
+ void (
+ (isUsing) =>
+ display(o)(a[a.length - 1])({
+ using: isUsing,
+ isAsync: composerTools.localAsync(o)(a[a.length - 1])(isUsing),
+ })
+ )(
+ composerTools.isUsing(o)(a[a.length - 1]),
) ??
wrap(o)(a),
handleRequest: (s: string) =>
diff --git a/src/morphism.ts b/src/morphism.ts
index b2b389f..6d95055 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";
@@ -84,7 +86,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`,
@@ -217,7 +224,7 @@ export const petitions = {
AT = any,
R = any,
>(
- I: Morphism<
+ m: Morphism<
{
type: "morphism";
},
@@ -230,7 +237,31 @@ 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),
+ ) 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
* alongside or within the main function (`f`) of a petition, allowing for the extension of functionality through
@@ -274,7 +305,32 @@ export const petitions = {
AT = any,
R = any,
>(
- I: Morphism<
+ m: Morphism<
+ {
+ type: "morphism";
+ branch: true;
+ },
+ RM,
+ BM,
+ QO,
+ PO,
+ RO,
+ CO,
+ AT,
+ R
+ >,
+ ) =>
+ (
+ (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;
@@ -288,7 +344,6 @@ export const petitions = {
AT,
R
>,
- ) => ({ ...I, type: "morphism", o }),
/**
* 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
@@ -480,12 +535,15 @@ export type Morphism<
AT = any,
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;
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;
@@ -575,6 +633,10 @@ export type QueryOptions = {
only?: string[];
} | {};
+export type CookieOptions = {
+ only?: string[];
+};
+
export type ParamOptions = {
readonly unique?: true;
} | {};
@@ -845,7 +907,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.
@@ -939,10 +1001,7 @@ interface Ctx<
* ```
*/
date: number;
- /**
- * @deprecated
- */
- cookie: null | { [key: string]: string | undefined };
+ cookie: { [key: string]: string | undefined };
io: FileHandler;
}
@@ -983,42 +1042,22 @@ 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][];
- } | {
- type: "fileServer";
- name: string;
- path: string;
- mime: false;
- })
- & {
- 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/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/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/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..e34ce7a 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/components/cookieToToken/cookieToToken.test.ts b/test/components/cookieToToken/cookieToToken.test.ts
index dd78325..7dfbe9f 100644
--- a/test/components/cookieToToken/cookieToToken.test.ts
+++ b/test/components/cookieToToken/cookieToToken.test.ts
@@ -1,7 +1,7 @@
-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 signSha256 from "../../../src/components/jwt/signSha256.ts";
import { wrap } from "../../../main.ts";
const secret = new Uint8Array([1, 2, 3, 4, 5, 6]);
@@ -35,7 +35,7 @@ const hiRequest = new Request("http://localhost:3000/", {
});
test("jwt signing with an element", async () => {
- assert.deepStrictEqual(
+ assertEquals(
await wrap()()
.stdPetition({
path: "/",
@@ -49,7 +49,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 +63,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 8efcdab..d0db1d9 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(
diff --git a/test/components/parameters/main.test.ts b/test/components/parameters/main.test.ts
index a0a2952..ac7a2ec 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 mainParameters from "../../../src/components/parameters/mainParameters.ts";
+import { assertEquals } from "@std/assert";
+import { f } 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,9 +10,9 @@ const options = plugins.globalOptions({
},
});
-Deno.test("parameters unique", () => {
+test("parameters unique", () => {
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -24,7 +24,7 @@ Deno.test("parameters unique", () => {
"helloWorld1",
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -36,7 +36,7 @@ Deno.test("parameters unique", () => {
"helloWorld2",
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/",
param: {
@@ -48,7 +48,7 @@ Deno.test("parameters unique", () => {
"helloWorld3",
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/",
param: {
@@ -60,7 +60,7 @@ Deno.test("parameters unique", () => {
"helloWorld4",
);
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -72,7 +72,7 @@ Deno.test("parameters unique", () => {
"helloWorld5",
);
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -86,7 +86,7 @@ Deno.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 @@ Deno.test("parameters unique", () => {
},
f: (ctx) => ctx.param,
}),
- ).toString() === mainParameters()(
+ ).toString() === f()(
petitions.common()({
path: "/hello/nested/:hi",
param: {
@@ -107,9 +107,9 @@ Deno.test("parameters unique", () => {
);
});
-Deno.test("parameters single", () => {
+test("parameters single", () => {
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi",
f: (ctx) => ctx.param.hi,
@@ -120,7 +120,7 @@ Deno.test("parameters single", () => {
},
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi",
f: (ctx) => ctx.param.hi,
@@ -131,7 +131,7 @@ Deno.test("parameters single", () => {
},
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/",
f: (ctx) => ctx.param.hi,
@@ -142,7 +142,7 @@ Deno.test("parameters single", () => {
},
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/",
f: (ctx) => ctx.param.hi,
@@ -153,7 +153,7 @@ Deno.test("parameters single", () => {
},
);
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
f: (ctx) => ctx.param.hi,
@@ -164,7 +164,7 @@ Deno.test("parameters single", () => {
},
);
assertEquals(
- mainParameters(options)(
+ f(options)(
petitions.common()({
path: "/hello/nested/:hi",
f: (ctx) => ctx.param.hi,
@@ -176,9 +176,9 @@ Deno.test("parameters single", () => {
);
});
-Deno.test("parameters multiple", () => {
+test("parameters multiple", () => {
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/:hello",
f: (ctx) => ctx.param.hi,
@@ -191,7 +191,7 @@ Deno.test("parameters multiple", () => {
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/hello/nested/:hi/:hello",
f: (ctx) => ctx.param.hi,
@@ -204,7 +204,7 @@ Deno.test("parameters multiple", () => {
);
assertEquals(
- mainParameters()(
+ f()(
petitions.common()({
path: "/:test/:id/:hello",
f: (ctx) => ctx.param.hi,
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..1335390 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,19 +79,19 @@ 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))
+ 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",
);
diff --git a/test/exportable/wrap.test.ts b/test/exportable/wrap.test.ts
index 639ba3d..0612ce4 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",
@@ -19,6 +19,7 @@ const pluginMethod = plugins.type({
name: Symbol.for("method"),
type: {} as string,
f: () => () => () => " inCycle",
+ isUsing: () => () => "sup",
});
const opt = plugins.globalOptions({
@@ -61,7 +62,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 +81,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 +100,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 +111,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 +122,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..7248c69 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")),
@@ -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) =>
- assert.deepStrictEqual(
- [
- 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) =>
- assert.deepStrictEqual(
- [
- 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[]),
+// ),
+// ),
+// ),
+// ),
+// );
diff --git a/test/staticFile/composedPaths.test.ts b/test/staticFile/composedPaths.test.ts
index 3b5ba56..43aa35f 100644
--- a/test/staticFile/composedPaths.test.ts
+++ b/test/staticFile/composedPaths.test.ts
@@ -1,18 +1,18 @@
-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..c19b294 100644
--- a/test/staticFile/getMime.test.ts
+++ b/test/staticFile/getMime.test.ts
@@ -1,16 +1,16 @@
-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..123e9c8 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";
+import { type fileServerPetition, 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/",
@@ -76,7 +76,7 @@ test(
r: () => new Response(""),
}),
}],
- })
+ } as fileServerPetition)
.some((x) => x.path === "/hello/nested/logo"),
true,
),
diff --git a/test/staticFile/mime.test.ts b/test/staticFile/mime.test.ts
index eae6284..9a22418 100644
--- a/test/staticFile/mime.test.ts
+++ b/test/staticFile/mime.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(
"checking mime",
() => {
- assert.deepStrictEqual(
+ assertEquals(
staticFileTools.mimeForm({
type: "fileServer",
path: "./",
@@ -14,7 +14,7 @@ test(
}).length,
74,
);
- assert.deepStrictEqual(
+ assertEquals(
staticFileTools.mimeForm({
type: "fileServer",
path: "./",
@@ -24,7 +24,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,