-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
857 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# @wroud/api-logger | ||
|
||
[![ESM-only package][package]][esm-info-url] | ||
[![NPM version][npm]][npm-url] | ||
|
||
<!-- [![Install size][size]][size-url] --> | ||
|
||
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg | ||
[esm-info-url]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[npm]: https://img.shields.io/npm/v/@wroud/api-logger.svg | ||
[npm-url]: https://npmjs.com/package/@wroud/api-logger | ||
[size]: https://packagephobia.com/badge?p=@wroud/api-logger | ||
[size-url]: https://packagephobia.com/result?p=@wroud/api-logger | ||
|
||
@wroud/api-logger is a lightweight and flexible logging interface library for JavaScript and TypeScript applications. It provides a standardized way to implement logging across your projects, ensuring consistency and ease of maintenance. Designed with modern JavaScript features in mind, it seamlessly integrates with various logging implementations. | ||
|
||
## Features | ||
|
||
- **TypeScript Support**: Fully typed interfaces for enhanced developer experience. | ||
- **ESM-only Package**: Utilizes ES modules for optimal performance and compatibility. | ||
- **Flexible Logging Levels**: Supports `info`, `warn`, and `error` levels. | ||
- **Ease of Integration**: Easily implement the `ILogger` interface with your preferred logging libraries. | ||
|
||
## Installation | ||
|
||
Install via npm: | ||
|
||
```sh | ||
npm install @wroud/api-logger | ||
``` | ||
|
||
Install via yarn: | ||
|
||
```sh | ||
yarn add @wroud/api-logger | ||
``` | ||
|
||
## Documentation | ||
|
||
For detailed usage and API reference, visit the [documentation site](https://wroud.dev/). | ||
|
||
## Example | ||
|
||
```ts | ||
// Import the ILogger interface | ||
import { ILogger } from "@wroud/api-logger"; | ||
|
||
// Implement the ILogger interface | ||
class ConsoleLogger implements ILogger { | ||
info(...messages: any[]): void { | ||
console.info(...messages); | ||
} | ||
|
||
warn(...messages: any[]): void { | ||
console.warn(...messages); | ||
} | ||
|
||
error(...messages: any[]): void { | ||
console.error(...messages); | ||
} | ||
} | ||
|
||
// Usage example | ||
const logger: ILogger = new ConsoleLogger(); | ||
|
||
logger.info("This is an info message"); | ||
logger.warn("This is a warning message"); | ||
logger.error("This is an error message"); | ||
``` | ||
|
||
### Integrating with @wroud/di | ||
|
||
If you're using `@wroud/di` for dependency injection, you can easily inject your logger implementation: | ||
|
||
```ts | ||
import { ServiceContainerBuilder, injectable } from "@wroud/di"; | ||
import { ILogger } from "@wroud/api-logger"; | ||
|
||
@injectable() | ||
class ConsoleLogger implements ILogger { | ||
info(...messages: any[]): void { | ||
console.info(...messages); | ||
} | ||
|
||
warn(...messages: any[]): void { | ||
console.warn(...messages); | ||
} | ||
|
||
error(...messages: any[]): void { | ||
console.error(...messages); | ||
} | ||
} | ||
|
||
const builder = new ServiceContainerBuilder(); | ||
builder.addSingleton(ConsoleLogger); | ||
const provider = builder.build(); | ||
|
||
const logger = provider.getService(ConsoleLogger); | ||
logger.info("Hello world with DI!"); | ||
``` | ||
|
||
## Changelog | ||
|
||
All notable changes to this project will be documented in the [CHANGELOG](./CHANGELOG.md) file. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "@wroud/api-logger", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"description": "@wroud/api-logger is a lightweight, TypeScript-compatible logging interface for JavaScript applications. It provides standardized logging methods (`info`, `warn`, `error`) to ensure consistent and maintainable logging across your projects. Designed as an ESM-only package, it seamlessly integrates with modern JavaScript workflows and various logging implementations, making it an ideal choice for developers seeking flexibility and type safety in their logging solutions.", | ||
"sideEffects": [], | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./*": "./lib/*.js" | ||
}, | ||
"scripts": { | ||
"ci:release": "yarn ci release --prefix api-logger-v", | ||
"ci:git-tag": "yarn ci git-tag --prefix api-logger-v", | ||
"ci:release-github": "yarn ci release-github --prefix api-logger-v", | ||
"build": "tsc -b", | ||
"clear": "rimraf lib" | ||
}, | ||
"files": [ | ||
"package.json", | ||
"LICENSE", | ||
"README.md", | ||
"CHANGELOG.md", | ||
"lib", | ||
"!lib/**/*.d.ts.map", | ||
"!lib/**/*.test.js", | ||
"!lib/**/*.test.d.ts", | ||
"!lib/**/*.test.d.ts.map", | ||
"!lib/**/*.test.js.map", | ||
"!lib/tests", | ||
"!.tsbuildinfo" | ||
], | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@wroud/ci": "workspace:^", | ||
"@wroud/tsconfig": "workspace:^", | ||
"rimraf": "^6", | ||
"typescript": "^5" | ||
}, | ||
"keywords": [ | ||
"logger", | ||
"logging", | ||
"typescript", | ||
"javascript", | ||
"ESM", | ||
"interface", | ||
"lightweight", | ||
"logging-interface", | ||
"API-logger" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export interface ILogger { | ||
/** | ||
* Logs a message with the "info" level. | ||
* @param {any[]} messages - The messages to log. | ||
*/ | ||
info(...messages: any[]): void; | ||
|
||
/** | ||
* Logs a message with the "warn" level. | ||
* @param {any[]} messages - The messages to log. | ||
*/ | ||
warn(...messages: any[]): void; | ||
|
||
/** | ||
* Logs a message with the "error" level. | ||
* @param {any[]} messages - The messages to log. | ||
*/ | ||
error(...messages: any[]): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./ILogger.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "@wroud/tsconfig/tsconfig.json", | ||
"compilerOptions": { | ||
"tsBuildInfoFile": "./lib/.tsbuildinfo", | ||
"rootDir": "src", | ||
"rootDirs": [ | ||
"src" | ||
], | ||
"outDir": "lib", | ||
"incremental": true, | ||
"composite": true | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# @wroud/flow-middleware | ||
|
||
[![ESM-only package][package]][esm-info-url] | ||
[![NPM version][npm]][npm-url] | ||
|
||
<!-- [![Install size][size]][size-url] --> | ||
|
||
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg | ||
[esm-info-url]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[npm]: https://img.shields.io/npm/v/@wroud/flow-middleware.svg | ||
[npm-url]: https://npmjs.com/package/@wroud/flow-middleware | ||
[size]: https://packagephobia.com/badge?p=@wroud/flow-middleware | ||
[size-url]: https://packagephobia.com/result?p=@wroud/flow-middleware | ||
|
||
@wroud/flow-middleware is a lightweight middleware management library for JavaScript and TypeScript. It facilitates the creation and execution of middleware chains with support for re-runs, error handling, and disposability. Inspired by modern middleware patterns, it leverages TypeScript for type safety and ESM for optimal performance. | ||
|
||
## Features | ||
|
||
- **Modern JavaScript**: Utilizes ES modules and ESNext syntax for advanced performance optimizations. | ||
- **TypeScript**: Written in TypeScript for type safety and enhanced developer experience. | ||
- **Middleware Chains**: Easily create and manage middleware chains with support for asynchronous operations. | ||
- **Re-run Capabilities**: Middlewares can trigger re-execution of the middleware chain based on external events. | ||
- **Error Handling**: Dedicated error-handling middlewares to manage and respond to errors gracefully. | ||
- **Subscription Management**: Efficiently handle subscriptions with automatic cleanup to prevent memory leaks. | ||
- **Disposability**: Cleanly dispose of middleware requests and all associated subscriptions. | ||
|
||
## Installation | ||
|
||
Install via npm: | ||
|
||
```sh | ||
npm install @wroud/flow-middleware | ||
``` | ||
|
||
Install via yarn: | ||
|
||
```sh | ||
yarn add @wroud/flow-middleware | ||
``` | ||
|
||
## Documentation | ||
|
||
For detailed usage and API reference, visit the [documentation site](https://wroud.dev). | ||
|
||
## Example | ||
|
||
```ts | ||
import { FlowMiddleware } from "@wroud/flow-middleware"; | ||
import type { | ||
IMiddleware, | ||
IErrorMiddleware, | ||
} from "@wroud/flow-middleware/interfaces"; | ||
|
||
/** | ||
* Simple Middleware Example | ||
*/ | ||
const simpleMiddleware: IMiddleware<{ message: string }> = async ( | ||
req, | ||
next, | ||
triggerReRun, | ||
subscribe, | ||
) => { | ||
console.log("Middleware: Processing message:", req.message); | ||
await next(); | ||
}; | ||
|
||
/** | ||
* Simple Error Middleware Example | ||
*/ | ||
const simpleErrorMiddleware: IErrorMiddleware<{ message: string }> = async ( | ||
error, | ||
req, | ||
next, | ||
triggerReRun, | ||
subscribe, | ||
) => { | ||
console.error("ErrorMiddleware: An error occurred:", error.message); | ||
// Handle error, modify request data, or trigger re-run | ||
req.message = "Error handled"; | ||
triggerReRun(); | ||
}; | ||
|
||
const middleware = new FlowMiddleware(); | ||
|
||
// Register middlewares | ||
middleware.register(simpleMiddleware); | ||
middleware.registerErrorMiddleware(simpleErrorMiddleware); | ||
|
||
// Create a new request with initial data | ||
const request = middleware.createRequest({ message: "Hello, FlowMiddleware!" }); | ||
|
||
// Execute the middleware chain | ||
(async () => { | ||
try { | ||
await request.execute(); | ||
} catch (error) { | ||
console.error("Main: Error executing middleware chain:", error); | ||
} | ||
})(); | ||
``` | ||
|
||
## Changelog | ||
|
||
All notable changes to this project will be documented in the [CHANGELOG](./CHANGELOG.md) file. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "@wroud/flow-middleware", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"description": "A lightweight middleware management library for JavaScript and TypeScript, facilitating middleware chains with re-runs, error handling, and disposability.", | ||
"sideEffects": [], | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./*": "./lib/*.js" | ||
}, | ||
"scripts": { | ||
"ci:release": "yarn ci release --prefix api-logger-v", | ||
"ci:git-tag": "yarn ci git-tag --prefix api-logger-v", | ||
"ci:release-github": "yarn ci release-github --prefix api-logger-v", | ||
"build": "tsc -b", | ||
"clear": "rimraf lib" | ||
}, | ||
"files": [ | ||
"package.json", | ||
"LICENSE", | ||
"README.md", | ||
"CHANGELOG.md", | ||
"lib", | ||
"!lib/**/*.d.ts.map", | ||
"!lib/**/*.test.js", | ||
"!lib/**/*.test.d.ts", | ||
"!lib/**/*.test.d.ts.map", | ||
"!lib/**/*.test.js.map", | ||
"!lib/tests", | ||
"!.tsbuildinfo" | ||
], | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@wroud/api-logger": "workspace:^", | ||
"@wroud/ci": "workspace:^", | ||
"@wroud/tsconfig": "workspace:^", | ||
"rimraf": "^6", | ||
"typescript": "^5" | ||
}, | ||
"keywords": [ | ||
"middleware", | ||
"typescript", | ||
"javascript", | ||
"flow control", | ||
"error handling", | ||
"ESM", | ||
"asynchronous", | ||
"dependency management", | ||
"middleware chains", | ||
"re-run", | ||
"disposable", | ||
"flow middleware", | ||
"middleware library" | ||
] | ||
} |
Oops, something went wrong.