Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2800fe1
feat(core): integrating http server
vinayak25 Nov 18, 2024
ea36cf1
feat(core): http server integration
vinayak25 Nov 22, 2024
29c976e
feat(core): http server integration
vinayak25 Nov 22, 2024
781ac41
feat(core): hyper-express integration
vinayak25 Nov 23, 2024
ce63cd1
feat(core): global guards support
vinayak25 Nov 23, 2024
2e73517
feat(core): added support for multiple parsers, request and response,…
vinayak25 Nov 24, 2024
0e3eb06
chore(core): remove unused dependency of express
vinayak25 Nov 24, 2024
f42ad5a
fix(core): fixed the imports and removed the unused references of exp…
vinayak25 Nov 24, 2024
b66e70d
fix(core): bug fixes in http-server
vinayak25 Nov 24, 2024
d7c7ccc
fix(core): http-server bugs
vinayak25 Nov 24, 2024
4f168b7
fix(core): circular dependency issues
vinayak25 Nov 27, 2024
8fb2ee2
fix(core): middleware bugs
vinayak25 Nov 27, 2024
975df2a
fix(core): remove file
vinayak25 Nov 27, 2024
21817c8
fix(core): remove unused dependency
vinayak25 Nov 27, 2024
3b41206
feat(hyper-express): add custom flavour of hyper-express server
vinayak25 Nov 30, 2024
7810c2e
fix(core): custom param decorator bug
vinayak25 Nov 30, 2024
1f950c9
fix(core): route param decorator bugs
vinayak25 Nov 30, 2024
4e67323
fix(core): response related bugs
vinayak25 Nov 30, 2024
0a3ad16
fix(core): validation and dto related bugs
vinayak25 Nov 30, 2024
c8bde06
fix(core): response class import
vinayak25 Nov 30, 2024
3c29f10
feat(core): static serve
vinayak25 Nov 30, 2024
a388d96
fix(core): bugs
vinayak25 Nov 30, 2024
1f2c520
fix(core): bugs
vinayak25 Nov 30, 2024
af1e425
feat(hyper-express): add utility methods in request
vinayak25 Dec 1, 2024
1eaa303
feat(hyper-express): add utility methods in request
vinayak25 Dec 1, 2024
8692ef8
fix(core): renamed useguard decorator to usegaurds
vinayak25 Dec 1, 2024
66e40a0
fix(core): bugs
vinayak25 Dec 1, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ storage/**/*.log
packages/**/*.d.ts
packages/**/*.js

!packages/hyper-express/**/*.js
!packages/hyper-express/**/*.d.ts

#yarn
.pnp.*
.yarn/*
Expand Down
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
npm run build
53 changes: 0 additions & 53 deletions integrations/sample-app/.env.example

This file was deleted.

9 changes: 3 additions & 6 deletions integrations/sample-app/app/boot/sp/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
IntentApplication,
IntentApplicationContext,
ServiceProvider,
} from '@intentjs/core';
import { IntentApplicationContext, ServiceProvider } from '@intentjs/core';
import { IntentController } from 'app/http/controllers/icon';
import { QueueJobs } from 'app/jobs/job';
import { UserDbRepository } from 'app/repositories/userDbRepository';
import { UserService } from 'app/services';
Expand Down Expand Up @@ -35,5 +32,5 @@ export class AppServiceProvider extends ServiceProvider {
/**
* Bootstrap any application service here.
*/
boot(app: IntentApplication | IntentApplicationContext) {}
boot(app: IntentApplicationContext) {}
}
8 changes: 2 additions & 6 deletions integrations/sample-app/app/boot/sp/console.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
IntentApplication,
IntentApplicationContext,
ServiceProvider,
} from '@intentjs/core';
import { IntentApplicationContext, ServiceProvider } from '@intentjs/core';
import { TestCacheConsoleCommand } from 'app/console/cache';
import { GreetingCommand } from 'app/console/greeting';
import { TestLogConsoleCommand } from 'app/console/log';
Expand All @@ -27,5 +23,5 @@ export class ConsoleServiceProvider extends ServiceProvider {
*
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
boot(app: IntentApplication | IntentApplicationContext) {}
boot(app: IntentApplicationContext) {}
}
28 changes: 8 additions & 20 deletions integrations/sample-app/app/errors/filter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
Catch,
ConfigService,
ExecutionContext,
HttpException,
HttpStatus,
IntentExceptionFilter,
Request,
Response,
Type,
ValidationFailed,
} from '@intentjs/core';

@Catch()
export class ApplicationExceptionFilter extends IntentExceptionFilter {
constructor(private config: ConfigService) {
super();
}

doNotReport(): Array<Type<HttpException>> {
return [];
}
Expand All @@ -19,19 +19,7 @@ export class ApplicationExceptionFilter extends IntentExceptionFilter {
return '*';
}

handleHttp(exception: any, req: Request, res: Response) {
if (exception instanceof ValidationFailed) {
return res
.status(422)
.json({ message: 'validation failed', errors: exception.getErrors() });
}

return res.status(this.getStatus(exception)).json(exception);
}

getStatus(exception: any): HttpStatus {
return exception instanceof HttpException
? exception.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR;
handleHttp(context: ExecutionContext, exception: any) {
return super.handleHttp(context, exception);
}
}
10 changes: 7 additions & 3 deletions integrations/sample-app/app/http/controllers/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Req, Request } from '@intentjs/core';
import { Controller, Get, Req } from '@intentjs/core';
import { UserService } from 'app/services';

@Controller()
Expand All @@ -7,7 +7,11 @@ export class UserController {

@Get()
async getHello(@Req() req: Request) {
console.log(req.all());
return this.service.getHello();
return { hello: 'Intent' };
}

@Get('hello')
async getHello2(@Req() req: Request) {
return { hello: 'Intent' };
}
}
163 changes: 163 additions & 0 deletions integrations/sample-app/app/http/controllers/icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import {
Accepts,
BufferBody,
Controller,
Dto,
File,
findProjectRoot,
Get,
Header,
Host,
IP,
Param,
Post,
Query,
Req,
Res,
Response,
StreamableFile,
UseGuards,
UserAgent,
Validate,
} from '@intentjs/core';
import { CustomGuard } from '../guards/custom';
import { Request, UploadedFile } from '@intentjs/hyper-express';
import { createReadStream } from 'fs';
import { join } from 'path';
import { LoginDto } from 'app/validators/auth';

@Controller('/icon')
@UseGuards(CustomGuard)
export class IntentController {
public service: any;

constructor() {
this.service = null;
}

@Get('/:name')
@UseGuards(CustomGuard)
async getHello(
// @Req() req: Request,
// @Param('name') name: string,
// @Query() query: Record<string, any>,
// @Query('b') bQuery: string,
// @Param() pathParams: string,
// @Host() hostname: string,
// @IP() ips: string,
// @Accepts() accepts: string,
// @BufferBody() bufferBody: Promise<Buffer>,
// @UserAgent() userAgent: string,
// @Header() headers: Record<string, any>,
@Res() res: Response,
) {
// console.log(
// 'query ==> ',
// query,
// 'bQuyery ==> ',
// bQuery,
// 'name ===> ',
// name,
// bufferBody,
// pathParams,
// 'hostname===> ',
// hostname,
// 'accepts ===> ',
// accepts,
// 'ips ===> ',
// ips,
// 'inside get method',
// 'user agent ===> ',
// userAgent,
// );
// console.log('all headers ===> ', headers);
// throw new Error('hello there');
// return { hello: 'world' };
// const readStream = createReadStream(
// join(findProjectRoot(), 'storage/uploads/sample-image.jpg'),
// );
// return new StreamableFile(readStream, { type: 'image/jpeg' });
}

@Get('/plain-with-query-param')
@UseGuards(CustomGuard)
async plainWithQueryParam(@Req() req: Request) {
console.log(req);
return { hello: 'world' };
}

@Get('/:id')
@UseGuards(CustomGuard)
async plainWithPathParam(@Req() req: Request) {
console.log(req);
return { hello: 'world' };
}

@Post('/json')
@Validate(LoginDto)
async postJson(
@Req() req: Request,
@Dto() dto: LoginDto,
@Param('name') name: string,
@Query() query: Record<string, any>,
@Query('b') bQuery: string,
@Param() pathParams: string,
@Host() hostname: string,
@IP() ips: string,
@Accepts() accepts: string,
@BufferBody() bufferBody: Promise<Buffer>,
@UserAgent() userAgent: string,
@Header() headers: Record<string, any>,
@File('file') file: UploadedFile,
@Res() res: Response,
) {
// console.log(
// 'query ==> ',
// query,
// 'bQuyery ==> ',
// bQuery,
// 'name ===> ',
// name,
// bufferBody,
// pathParams,
// 'hostname===> ',
// hostname,
// 'accepts ===> ',
// accepts,
// 'ips ===> ',
// ips,
// 'inside get method',
// 'user agent ===> ',
// userAgent,
// );

// console.log('all headers ===> ', headers);
console.log('uploaded files ==> ', req.dto(), dto);

const readStream = createReadStream(
join(findProjectRoot(), 'storage/uploads/sample-image.jpg'),
);

return new StreamableFile(readStream, { type: 'image/jpeg' });

return { hello: 'world from POST /json' };
}

@Post('/multipart')
@UseGuards(CustomGuard)
async postHello(@Req() req: Request) {
return { hello: 'world' };
}

@Post('/form-data')
@UseGuards(CustomGuard)
async postFormData(@Req() req: Request) {
return { hello: 'world' };
}

@Post('/binary')
@UseGuards(CustomGuard)
async postBinary(@Req() req: Request) {
return { hello: 'world' };
}
}
7 changes: 7 additions & 0 deletions integrations/sample-app/app/http/decorators/custom-param.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createParamDecorator, ExecutionContext } from '@intentjs/core';

export const CustomParam = createParamDecorator(
(data: any, ctx: ExecutionContext, argIndex: number) => {
return 'data from custom decorator param';
},
);
8 changes: 8 additions & 0 deletions integrations/sample-app/app/http/guards/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ExecutionContext, Injectable, IntentGuard } from '@intentjs/core';

@Injectable()
export class CustomGuard extends IntentGuard {
async guard(ctx: ExecutionContext): Promise<boolean> {
return true;
}
}
8 changes: 8 additions & 0 deletions integrations/sample-app/app/http/guards/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ExecutionContext, Injectable, IntentGuard } from '@intentjs/core';

@Injectable()
export class GlobalGuard extends IntentGuard {
async guard(ctx: ExecutionContext): Promise<boolean> {
return true;
}
}
Loading