Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.1.40 #30

Merged
merged 12 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Bun

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: antongolub/[email protected]
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
28 changes: 8 additions & 20 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
</p>

[![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**

Expand Down
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install.scopes]
"@jsr" = "https://npm.jsr.io"
9 changes: 9 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
4 changes: 2 additions & 2 deletions fun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import type { fileServerPetition, Petition } from "./src/morphism.ts";
type vixeny = (
o?: FunRouterOptions<any>,
) => (
routes: (Petition | fileServerPetition)[],
routes: (Petition | fileServerPetition<any>)[],
) => (r: Request) => Promise<Response> | Response;

export default ((o?: FunRouterOptions<any>) =>
(routes: (Petition | fileServerPetition)[]) =>
(routes: (Petition | fileServerPetition<any>)[]) =>
((re) =>
((map) =>
((s) => (r: Request): Promise<Response> | Response => map[s(r)](r))(
Expand Down
5 changes: 0 additions & 5 deletions jsr.json

This file was deleted.

22 changes: 13 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
@@ -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,
};

/**
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -36,5 +38,7 @@
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
}
}
5 changes: 2 additions & 3 deletions src/components/cookieToToken/cookieToTokenGets.ts
Original file line number Diff line number Diff line change
@@ -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) =>
(
Expand Down
33 changes: 0 additions & 33 deletions src/components/cookieToToken/cookieToTokenMain.ts

This file was deleted.

46 changes: 46 additions & 0 deletions src/components/cookieToToken/mainCookieToToken.ts
Original file line number Diff line number Diff line change
@@ -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<any>) =>
(p: Petition): (s: string) => Record<string, string | undefined> =>
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<any>) => (p: Petition): string =>
(
(uses) =>
uses && uses.length > 0 ? `[` + uses.map((x) => x + "?") + "]" : "null"
)(
plugins.pluginIsUsing(p)("token"),
);
15 changes: 15 additions & 0 deletions src/components/cookies/cookieDefaultCase.ts
Original file line number Diff line number Diff line change
@@ -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<string, string | undefined>;
10 changes: 0 additions & 10 deletions src/components/cookies/main.ts

This file was deleted.

31 changes: 31 additions & 0 deletions src/components/cookies/mainCookies.ts
Original file line number Diff line number Diff line change
@@ -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<string, string | undefined>;

const f = (o?: FunRouterOptions<any>) => (p: Petition): Cookie =>
(
(cookies) =>
cookies
? body(p.cookie?.only ?? cookies) as Cookie
: cookieDefaultCase() as Cookie
)(
plugins.pluginIsUsing(p)("cookies"),
);

const isUsing = (o?: FunRouterOptions<any>) => (p: Petition): string =>
(
(uses) =>
p.cookie?.only
? p.cookie?.only.toString()
: uses && uses.length > 0
? `[` + uses.map((x) => x + "?") + "]"
: `Record<string, string|null> | null`
)(
plugins.pluginIsUsing(p)("cookies"),
);

export { f, isUsing };
2 changes: 1 addition & 1 deletion src/components/encode/b64toUrl.mjs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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(),
)();
Loading
Loading