zyket 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +137 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,139 @@
1
1
  # ZYKET - Easy Socket.io Framework
2
2
 
3
- Zyket is a framework inspired by Symfony.
3
+ Zyket is a framework inspired by Symfony that simplifies working with Socket.io by providing a structured approach.
4
+
5
+ # Getting Started
6
+
7
+ To use zyket we need to install it into our project:
8
+
9
+ ```javascript
10
+ npm i zyket
11
+ ```
12
+
13
+ Then we just need to import the Kernel and boot it:
14
+
15
+ ```javascript
16
+ const { Kernel } = require("zyket");
17
+ const kernel = new Kernel();
18
+
19
+ kernel.boot().then(() => console.log(`Kernel Booted`));
20
+ ```
21
+
22
+ After boot is done for fist time, project folders/files will be created if doesnt exists.
23
+
24
+ ## Handlers
25
+
26
+ Handlers are the way to interact with user messages on the socket:
27
+ ```javascript
28
+ const { Handler } = require("zyket");
29
+
30
+ module.exports = class MessageHandler extends Handler {
31
+ middlewares = ["default"];
32
+
33
+ async handle({ container, socket, data }) {
34
+ container.get("logger").info("Message handler");
35
+ }
36
+ };
37
+ ```
38
+
39
+ - middlewares: An array of middleware names that should be executed before the handler.
40
+
41
+ - handle(): The function that processes the event, receiving container, socket, and data.
42
+
43
+ ## Middlewares
44
+
45
+ Middlewares allow you to process data before it reaches the handler. They can be used for validation, authentication, logging, etc.
46
+
47
+ ```javascript
48
+ const { Middleware } = require("zyket");
49
+
50
+ module.exports = class DefaultMiddleware extends Middleware {
51
+ async handle({ container, socket }) {
52
+ container.get("logger").info("Default middleware");
53
+ }
54
+ };
55
+ ```
56
+
57
+ - handle(): The function that processes the event, receiving container, socket, and data.
58
+
59
+
60
+ ## Services
61
+ Services are reusable components specified in the kernel configuration. Each service must include a boot() function that is executed when the kernel starts.
62
+
63
+ ```javascript
64
+ module.exports = class LoggerService {
65
+ this.#container;
66
+
67
+ boot(container, enableLogging = true) {
68
+ this.#container = container;
69
+ console.log("LoggerService Booted");
70
+ }
71
+
72
+ info(message) {
73
+ if(!enableLogging) return;
74
+ console.log(`[INFO]: ${message}`);
75
+ }
76
+ };
77
+ ```
78
+
79
+ Then, when booting the kernel, specify the service:
80
+
81
+ ```javascript
82
+ const { Kernel } = require("zyket");
83
+ const LoggerService = require("./LoggerService");
84
+
85
+ const kernel = new Kernel({
86
+ services: [["logger", LoggerService, ['@service_container', true]],
87
+ });
88
+
89
+ kernel.boot().then(() => console.log(`Kernel Booted`));
90
+ ```
91
+
92
+ ## Default Services
93
+ Zyket includes some default services that provide essential functionality. These services can be overridden or extended if needed.
94
+
95
+ #### Cache Services
96
+ - **Name** `cache`
97
+ - **Description** Provides caching functionality using a Redis adapter.
98
+ - **Configuration** Add `CACHE_URL` in your `.env` file to activate caching.
99
+
100
+ #### Database Service
101
+ - **Name** `database`
102
+ - **Description** Manages database connections using a MariaDB/Sequelize adapter.
103
+ - **Configuration** Add `DATABASE_URL` in your `.env` file to enable the database connection.
104
+
105
+ #### S3 Service
106
+ - **Name** `s3`
107
+ - **Description** Provides S3-compatible object storage using MinIO.
108
+ - **Configuration** Add the following variables in your `.env` file to enable the service
109
+ - `S3_ENDPOINT`
110
+ - `S3_PORT`
111
+ - `S3_USE_SSL`
112
+ - `S3_ACCESS_KEY`
113
+ - `S3_SECRET_KEY`
114
+
115
+ #### Logger Service
116
+ - **Name** `logger`
117
+ - **Description** Handles logging for the application.
118
+ - **Configuration**
119
+ - Change `LOG_DIRECTORY` in `.env` file to set a custom log directory.
120
+ - Set `DEBUG` in `.env` file to enable or disable debug logging.
121
+
122
+ #### Socket.io Service
123
+ - **Name** `socketio`
124
+ - **Description** Manages the WebSocket server.
125
+ - **Configuration** Add `PORT` in your `.env` file to define the listening port for Socket.io.
126
+
127
+
128
+ ## Contributing
129
+
130
+ We welcome contributions from the community! If you'd like to improve Zyket, feel free to:
131
+
132
+ - Report issues and suggest features on GitHub Issues
133
+
134
+ - Submit pull requests with bug fixes or enhancements
135
+
136
+ - Improve the documentation
137
+
138
+ Let's build a better framework together! 🚀
139
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zyket",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"