1.0.5 • Published 5 months ago
@yaagoub/decorators v1.0.5
decorators
Official Documentation
For detailed documentation, visit yaagoub.org.
Decoradores HTTP
ready
for setup please visit SETUP
### 501. `@Get` – Defines a GET request handler for a specific route.
### 502. `@Post` – Defines a POST request handler for a specific route.
### 503. `@Put` – Defines a PUT request handler for a specific route.
### 504. `@Delete` – Defines a DELETE request handler for a specific route.
### 505. `@Patch` – Defines a PATCH request handler for a specific route.
### 506. `@Head` – Defines a HEAD request handler for a specific route.
### 507. `@Options` – Defines an OPTIONS request handler for a specific route.
### 508. `@BasePath` - Defines a base endpoint
### 509. `@Path` - Defines a param
### 510. `@body` - Defines a body of the request
### 511. `@Res` - Defines a response of request
### 512. `@Getters` - Defines getters for class properties
### 513. `@Setters` - Defines setters for class properties
### 514. `@Mapper` - Maps properties from one type to another
### 515. `@ToString` - Converts an object to a string representation
for setup please visit SETUP
### 516. `@LogDebug` - Logs debug information to the server or to the console
### 517. `@LogError` - Logs error information to the server or to the console
### 518. `@LogInfo` - Logs informational messages to the server or to the console
### 519. `@LogWarn` - Logs warning messages to the server or to the console
### 520. `@Log` - Logs class general information to the server or to the console
Mapper Decorator
import { Mapper } from '@yaagoub/decorators';
interface DestinationType {
property1: string;
property2: number;
propertyC: string;
}
interface SourceType {
property1: string;
property2: number;
propertyC: string;
}
export class MapperToDestination {
@Mapper<DestinationType>()
static toDestination(source: SourceType): DestinationType {
return source as any;
}
}
const example = new ExampleClass();
const result = example.exampleMethod();
console.log(result); // Output: { propertyA: "example", propertyB: 42, propertyC: "example" }
HTTP Client Methods Decorator
import { Get, Path, BasePath } from '@yaagoub/decorators';
@BasePath('https://yaagoub.org/api')
export class TestClient {
@Get<User>({ path: '/users/{id}' })
getTest(@Path('id') id: number): void {
// Implementation here
}
}
Getters and Setters Decorator
import { Getters, Setters } from '@yaagoub/decorators';
@Getters()
@Setters()
class Example {
private _name: string = 'John';
private _age: number = 30;
}
const example = new Example();
console.log(example.getName()); // John
example.setAge(35);
console.log(example.getAge()); // 35