Skip to content

Commit

Permalink
Promoting v2 to main (#72)
Browse files Browse the repository at this point in the history
* chore: remove things related to fresh

* wip: replace oak with hono

- Have to cascade Response back

* feat: cascade up response from exception filter

* fix: return raw headers on @Header decorator

* test(middleware): use header instead of rewriting body

* wip: serve static asset

* feat: serve static assets

* feat: log error on error

* wip: add logger to debug starter

* debug for starter

* wip debug

* debug starter

* lint: remove debug log

* feat: next function now return void or response

* feat: cascade middleware return value

* fix: merge existing context.res with controller response

* feat: run middlewares as middlewares

* chore: fmt

* doc(README):cite Hono instead of oak

* lint: deno lint and fmt

* ci: upgrade deno version to v1.39.1

* ci: upgrade deno version to take latest

* ci: upgrade deno version to take 1.39.1

* ci: uuses: denoland/setup-deno@v1

* ci: uuses: denoland/setup-deno@v1
  • Loading branch information
Sorikairox authored Dec 28, 2023
1 parent dde9e28 commit d8212dc
Show file tree
Hide file tree
Showing 39 changed files with 594 additions and 692 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:

- name: Setup Deno
# uses: denoland/setup-deno@v1
uses: denoland/setup-deno@004814556e37c54a2f6e31384c9e18e983317366
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
deno-version: vx.x.x

# Uncomment this step to verify the use of 'deno fmt' on each commit.
# - name: Verify formatting
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# V2 is available in Alpha, it uses Hono instead of oak for (we hope), better performances
## This is V2 running on Hono, V1 using oak has it's own branch

<p align="center">
<img src="https://user-images.githubusercontent.com/38007824/205580360-fa032554-5e9e-4266-8ec9-c78ca9a233bc.svg" width="250" alt="Danet Logo" />
Expand All @@ -22,8 +22,7 @@ Nest, we wouldn't be developing Danet.
Danet is a framework for building efficient, scalable Deno server-side
applications. It is entirely built with Typescript.

Under the hood, Danet makes use of [Oak](https://github.com/oakserver/oak). We
might support other HTTP Web frameworks in the future !
Under the hood, Danet makes use of [Hono](https://hono.dev/).

We abstract a lot of things so you can focus on your core business and
architecture.
Expand Down Expand Up @@ -69,4 +68,4 @@ License
<br>

<p>
This project is Licensed under the <a href="./LICENSE">MIT License</a>. Please go through the License atleast once before making your contribution. </p>
This project is Licensed under the <a href="./LICENSE">MIT License</a>. Please go through the License at least once before making your contribution. </p>
49 changes: 26 additions & 23 deletions spec/auth-guard.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from '../src/deps_test.ts';
import { assertEquals, assertObjectMatch } from '../src/deps_test.ts';
import { DanetApplication } from '../src/app.ts';
import { GLOBAL_GUARD } from '../src/guard/constants.ts';
import { UseGuard } from '../src/guard/decorator.ts';
Expand Down Expand Up @@ -26,9 +26,10 @@ class GlobalGuard implements AuthGuard {

canActivate(context: ExecutionContext) {
this.simpleService.doSomething();
context.response.body = {
passedInglobalGuard: true,
};
if (!context.res) {
context.res = new Response();
}
context.res.headers.append('passedInglobalGuard', 'true');
return true;
}
}
Expand All @@ -40,15 +41,16 @@ class ControllerGuard implements AuthGuard {

canActivate(context: ExecutionContext) {
const controller = context.getClass();
const customMetadata = MetadataHelper.getMetadata(
const customMetadata = MetadataHelper.getMetadata<string>(
'customMetadata',
controller,
);
this.simpleService.doSomething();
context.response.body = {
passedIncontrollerGuard: true,
customMetadata,
};
if (!context.res) {
context.res = new Response();
}
context.res.headers.append('passedIncontrollerGuard', 'true');
context.res.headers.append('customMetadata', customMetadata);
return true;
}
}
Expand All @@ -61,11 +63,15 @@ class MethodGuard implements AuthGuard {
canActivate(context: ExecutionContext) {
this.simpleService.doSomething();
const method = context.getHandler();
const customMetadata = MetadataHelper.getMetadata('customMetadata', method);
context.response.body = {
passedInmethodGuard: true,
customMetadata,
};
const customMetadata = MetadataHelper.getMetadata<string>(
'customMetadata',
method,
);
if (!context.res) {
context.res = new Response();
}
context.res.headers.append('passedInmethodGuard', 'true');
context.res.headers.append('customMetadata', customMetadata);
return true;
}
}
Expand Down Expand Up @@ -110,11 +116,10 @@ for (const guardType of ['controller', 'method']) {
method: 'GET',
},
);
const json = await res.json();
assertEquals(json, {
[`passedIn${guardType}Guard`]: true,
customMetadata: 'customValue',
});
assertEquals(res.status, 200);
assertEquals(res.headers.get(`passedIn${guardType}guard`), 'true');
assertEquals(res.headers.get('custommetadata'), 'customValue');
await res?.body?.cancel();
await app.close();
});
}
Expand All @@ -139,10 +144,8 @@ Deno.test('Global guard', async () => {
const res = await fetch(`http://localhost:${listenEvent.port}/global-guard`, {
method: 'GET',
});
const json = await res.json();
assertEquals(json, {
[`passedInglobalGuard`]: true,
});
assertEquals(res.headers.get('passedinglobalguard'), 'true');
await res?.body?.cancel();
await app.close();
});

Expand Down
8 changes: 4 additions & 4 deletions spec/exception-filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class ErrorFilter implements ExceptionFilter {

catch(exception: any, context: HttpContext) {
this.simpleService.doSomething();
context.response.body = {
return context.json({
wePassedInFilterCatchingAllErrors: true,
};
});
}
}

Expand All @@ -43,9 +43,9 @@ class CustomErrorFilter implements ExceptionFilter {

catch(exception: any, context: HttpContext) {
this.simpleService.doSomething();
context.response.body = {
return context.json({
wePassedInFilterCatchingOnlySomeError: true,
};
});
}
}

Expand Down
86 changes: 0 additions & 86 deletions spec/fresh.spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions spec/fresh/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions spec/fresh/components/Button.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions spec/fresh/deno.json

This file was deleted.

Loading

0 comments on commit d8212dc

Please sign in to comment.