ioserver 1.4.2 → 2.0.1
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.
- package/README.md +244 -287
- package/dist/BaseClasses.d.ts +301 -0
- package/dist/BaseClasses.d.ts.map +1 -0
- package/dist/BaseClasses.js +281 -0
- package/dist/BaseClasses.js.map +1 -0
- package/dist/IOServer.d.ts +260 -0
- package/dist/IOServer.d.ts.map +1 -0
- package/dist/IOServer.js +656 -0
- package/dist/IOServer.js.map +1 -0
- package/dist/IOServerError.d.ts +80 -0
- package/dist/IOServerError.d.ts.map +1 -0
- package/dist/IOServerError.js +85 -0
- package/dist/IOServerError.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/package.json +68 -49
- package/build/ioserver.js +0 -580
- package/build/ioserver.js.map +0 -13
@@ -0,0 +1,80 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview IOServerError - Custom error class for IOServer framework
|
3
|
+
*
|
4
|
+
* Provides structured error handling with HTTP status codes and detailed messages.
|
5
|
+
* Extends the native Error class with additional properties for better debugging
|
6
|
+
* and API error responses.
|
7
|
+
*
|
8
|
+
* @author Ben Mz <0x42en@users.noreply.github.com>
|
9
|
+
* @version 2.0.0
|
10
|
+
* @since 1.0.0
|
11
|
+
*/
|
12
|
+
/**
|
13
|
+
* Custom error class for IOServer framework
|
14
|
+
*
|
15
|
+
* Provides structured error handling with HTTP-compatible status codes
|
16
|
+
* and consistent error formatting across the application.
|
17
|
+
*
|
18
|
+
* @class IOServerError
|
19
|
+
* @extends {Error}
|
20
|
+
*
|
21
|
+
* @example
|
22
|
+
* ```typescript
|
23
|
+
* // Basic error
|
24
|
+
* throw new IOServerError('User not found', 404);
|
25
|
+
*
|
26
|
+
* // Validation error
|
27
|
+
* throw new IOServerError('Invalid email format', 400);
|
28
|
+
*
|
29
|
+
* // Server error
|
30
|
+
* throw new IOServerError('Database connection failed', 500);
|
31
|
+
*
|
32
|
+
* // Using in service
|
33
|
+
* class UserService extends BaseService {
|
34
|
+
* async getUser(socket: any, data: any, callback?: Function) {
|
35
|
+
* if (!data.userId) {
|
36
|
+
* throw new IOServerError('User ID is required', 400);
|
37
|
+
* }
|
38
|
+
*
|
39
|
+
* const user = await this.appHandle.database.findUser(data.userId);
|
40
|
+
* if (!user) {
|
41
|
+
* throw new IOServerError('User not found', 404);
|
42
|
+
* }
|
43
|
+
*
|
44
|
+
* if (callback) callback(user);
|
45
|
+
* }
|
46
|
+
* }
|
47
|
+
* ```
|
48
|
+
*/
|
49
|
+
export declare class IOServerError extends Error {
|
50
|
+
/**
|
51
|
+
* HTTP status code associated with this error
|
52
|
+
* @type {number}
|
53
|
+
*/
|
54
|
+
statusCode: number;
|
55
|
+
/**
|
56
|
+
* Creates a new IOServerError instance
|
57
|
+
* @param {string} message - Error message describing what went wrong
|
58
|
+
* @param {number} statusCode - HTTP status code (default: 500)
|
59
|
+
*
|
60
|
+
* @example
|
61
|
+
* ```typescript
|
62
|
+
* // Client error (4xx)
|
63
|
+
* throw new IOServerError('Invalid request parameters', 400);
|
64
|
+
*
|
65
|
+
* // Authentication error
|
66
|
+
* throw new IOServerError('Access token expired', 401);
|
67
|
+
*
|
68
|
+
* // Authorization error
|
69
|
+
* throw new IOServerError('Insufficient permissions', 403);
|
70
|
+
*
|
71
|
+
* // Not found error
|
72
|
+
* throw new IOServerError('Resource not found', 404);
|
73
|
+
*
|
74
|
+
* // Server error (5xx)
|
75
|
+
* throw new IOServerError('Internal server error', 500);
|
76
|
+
* ```
|
77
|
+
*/
|
78
|
+
constructor(message: string, statusCode?: number);
|
79
|
+
}
|
80
|
+
//# sourceMappingURL=IOServerError.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"IOServerError.d.ts","sourceRoot":"","sources":["../src/IOServerError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC;;;OAGG;IACI,UAAU,EAAE,MAAM,CAAC;IAE1B;;;;;;;;;;;;;;;;;;;;;;OAsBG;gBACS,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY;CAQtD"}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* @fileoverview IOServerError - Custom error class for IOServer framework
|
4
|
+
*
|
5
|
+
* Provides structured error handling with HTTP status codes and detailed messages.
|
6
|
+
* Extends the native Error class with additional properties for better debugging
|
7
|
+
* and API error responses.
|
8
|
+
*
|
9
|
+
* @author Ben Mz <0x42en@users.noreply.github.com>
|
10
|
+
* @version 2.0.0
|
11
|
+
* @since 1.0.0
|
12
|
+
*/
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
14
|
+
exports.IOServerError = void 0;
|
15
|
+
/**
|
16
|
+
* Custom error class for IOServer framework
|
17
|
+
*
|
18
|
+
* Provides structured error handling with HTTP-compatible status codes
|
19
|
+
* and consistent error formatting across the application.
|
20
|
+
*
|
21
|
+
* @class IOServerError
|
22
|
+
* @extends {Error}
|
23
|
+
*
|
24
|
+
* @example
|
25
|
+
* ```typescript
|
26
|
+
* // Basic error
|
27
|
+
* throw new IOServerError('User not found', 404);
|
28
|
+
*
|
29
|
+
* // Validation error
|
30
|
+
* throw new IOServerError('Invalid email format', 400);
|
31
|
+
*
|
32
|
+
* // Server error
|
33
|
+
* throw new IOServerError('Database connection failed', 500);
|
34
|
+
*
|
35
|
+
* // Using in service
|
36
|
+
* class UserService extends BaseService {
|
37
|
+
* async getUser(socket: any, data: any, callback?: Function) {
|
38
|
+
* if (!data.userId) {
|
39
|
+
* throw new IOServerError('User ID is required', 400);
|
40
|
+
* }
|
41
|
+
*
|
42
|
+
* const user = await this.appHandle.database.findUser(data.userId);
|
43
|
+
* if (!user) {
|
44
|
+
* throw new IOServerError('User not found', 404);
|
45
|
+
* }
|
46
|
+
*
|
47
|
+
* if (callback) callback(user);
|
48
|
+
* }
|
49
|
+
* }
|
50
|
+
* ```
|
51
|
+
*/
|
52
|
+
class IOServerError extends Error {
|
53
|
+
/**
|
54
|
+
* Creates a new IOServerError instance
|
55
|
+
* @param {string} message - Error message describing what went wrong
|
56
|
+
* @param {number} statusCode - HTTP status code (default: 500)
|
57
|
+
*
|
58
|
+
* @example
|
59
|
+
* ```typescript
|
60
|
+
* // Client error (4xx)
|
61
|
+
* throw new IOServerError('Invalid request parameters', 400);
|
62
|
+
*
|
63
|
+
* // Authentication error
|
64
|
+
* throw new IOServerError('Access token expired', 401);
|
65
|
+
*
|
66
|
+
* // Authorization error
|
67
|
+
* throw new IOServerError('Insufficient permissions', 403);
|
68
|
+
*
|
69
|
+
* // Not found error
|
70
|
+
* throw new IOServerError('Resource not found', 404);
|
71
|
+
*
|
72
|
+
* // Server error (5xx)
|
73
|
+
* throw new IOServerError('Internal server error', 500);
|
74
|
+
* ```
|
75
|
+
*/
|
76
|
+
constructor(message, statusCode = 500) {
|
77
|
+
super(message);
|
78
|
+
this.name = 'IOServerError';
|
79
|
+
this.statusCode = statusCode;
|
80
|
+
// Ensure proper prototype chain for instanceof checks
|
81
|
+
Object.setPrototypeOf(this, IOServerError.prototype);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
exports.IOServerError = IOServerError;
|
85
|
+
//# sourceMappingURL=IOServerError.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"IOServerError.js","sourceRoot":"","sources":["../src/IOServerError.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAa,aAAc,SAAQ,KAAK;IAOtC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,YAAY,OAAe,EAAE,aAAqB,GAAG;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,sDAAsD;QACtD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;CACF;AAtCD,sCAsCC"}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview IOServer Framework - TypeScript Socket.IO Server Framework
|
3
|
+
*
|
4
|
+
* A comprehensive framework for building real-time applications with TypeScript,
|
5
|
+
* combining Fastify HTTP server with Socket.IO WebSocket support.
|
6
|
+
*
|
7
|
+
* Features:
|
8
|
+
* - Modular architecture with Services, Controllers, Managers, and Watchers
|
9
|
+
* - Type-safe development with full TypeScript support
|
10
|
+
* - Built-in error handling and logging
|
11
|
+
* - Middleware support for HTTP and WebSocket routes
|
12
|
+
* - Production-ready with security best practices
|
13
|
+
*
|
14
|
+
* @author Ben Mz <0x42en@users.noreply.github.com>
|
15
|
+
* @version 2.0.0
|
16
|
+
* @since 1.0.0
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
* ```typescript
|
20
|
+
* import { IOServer, BaseService } from 'ioserver';
|
21
|
+
*
|
22
|
+
* class ChatService extends BaseService {
|
23
|
+
* async sendMessage(socket: any, data: any, callback?: Function) {
|
24
|
+
* socket.broadcast.emit('new_message', data);
|
25
|
+
* if (callback) callback({ status: 'sent' });
|
26
|
+
* }
|
27
|
+
* }
|
28
|
+
*
|
29
|
+
* const server = new IOServer({ port: 3000 });
|
30
|
+
* server.addService({ service: ChatService });
|
31
|
+
* await server.start();
|
32
|
+
* ```
|
33
|
+
*/
|
34
|
+
export { IOServer as default, IOServer } from './IOServer';
|
35
|
+
export { IOServerError } from './IOServerError';
|
36
|
+
export { BaseService, BaseController, BaseManager, BaseWatcher, BaseMiddleware, } from './BaseClasses';
|
37
|
+
export type { IOServerOptions, ServiceOptions, ControllerOptions, ManagerOptions, WatcherOptions, SendToOptions, AppHandle, LogLevel, TransportMode, } from './IOServer';
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EACL,WAAW,EACX,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,eAAe,CAAC;AAGvB,YAAY,EACV,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,aAAa,EACb,SAAS,EACT,QAAQ,EACR,aAAa,GACd,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* @fileoverview IOServer Framework - TypeScript Socket.IO Server Framework
|
4
|
+
*
|
5
|
+
* A comprehensive framework for building real-time applications with TypeScript,
|
6
|
+
* combining Fastify HTTP server with Socket.IO WebSocket support.
|
7
|
+
*
|
8
|
+
* Features:
|
9
|
+
* - Modular architecture with Services, Controllers, Managers, and Watchers
|
10
|
+
* - Type-safe development with full TypeScript support
|
11
|
+
* - Built-in error handling and logging
|
12
|
+
* - Middleware support for HTTP and WebSocket routes
|
13
|
+
* - Production-ready with security best practices
|
14
|
+
*
|
15
|
+
* @author Ben Mz <0x42en@users.noreply.github.com>
|
16
|
+
* @version 2.0.0
|
17
|
+
* @since 1.0.0
|
18
|
+
*
|
19
|
+
* @example
|
20
|
+
* ```typescript
|
21
|
+
* import { IOServer, BaseService } from 'ioserver';
|
22
|
+
*
|
23
|
+
* class ChatService extends BaseService {
|
24
|
+
* async sendMessage(socket: any, data: any, callback?: Function) {
|
25
|
+
* socket.broadcast.emit('new_message', data);
|
26
|
+
* if (callback) callback({ status: 'sent' });
|
27
|
+
* }
|
28
|
+
* }
|
29
|
+
*
|
30
|
+
* const server = new IOServer({ port: 3000 });
|
31
|
+
* server.addService({ service: ChatService });
|
32
|
+
* await server.start();
|
33
|
+
* ```
|
34
|
+
*/
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
36
|
+
exports.BaseMiddleware = exports.BaseWatcher = exports.BaseManager = exports.BaseController = exports.BaseService = exports.IOServerError = exports.IOServer = exports.default = void 0;
|
37
|
+
// Main framework exports
|
38
|
+
var IOServer_1 = require("./IOServer");
|
39
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return IOServer_1.IOServer; } });
|
40
|
+
Object.defineProperty(exports, "IOServer", { enumerable: true, get: function () { return IOServer_1.IOServer; } });
|
41
|
+
var IOServerError_1 = require("./IOServerError");
|
42
|
+
Object.defineProperty(exports, "IOServerError", { enumerable: true, get: function () { return IOServerError_1.IOServerError; } });
|
43
|
+
// Base classes for extending
|
44
|
+
var BaseClasses_1 = require("./BaseClasses");
|
45
|
+
Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return BaseClasses_1.BaseService; } });
|
46
|
+
Object.defineProperty(exports, "BaseController", { enumerable: true, get: function () { return BaseClasses_1.BaseController; } });
|
47
|
+
Object.defineProperty(exports, "BaseManager", { enumerable: true, get: function () { return BaseClasses_1.BaseManager; } });
|
48
|
+
Object.defineProperty(exports, "BaseWatcher", { enumerable: true, get: function () { return BaseClasses_1.BaseWatcher; } });
|
49
|
+
Object.defineProperty(exports, "BaseMiddleware", { enumerable: true, get: function () { return BaseClasses_1.BaseMiddleware; } });
|
50
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;;AAEH,yBAAyB;AACzB,uCAA2D;AAAlD,mGAAA,QAAQ,OAAW;AAAE,oGAAA,QAAQ,OAAA;AACtC,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAEtB,6BAA6B;AAC7B,6CAMuB;AALrB,0GAAA,WAAW,OAAA;AACX,6GAAA,cAAc,OAAA;AACd,0GAAA,WAAW,OAAA;AACX,0GAAA,WAAW,OAAA;AACX,6GAAA,cAAc,OAAA"}
|
package/package.json
CHANGED
@@ -1,59 +1,78 @@
|
|
1
1
|
{
|
2
2
|
"name": "ioserver",
|
3
|
-
"version": "
|
4
|
-
"description": "Damn simple
|
5
|
-
"main": "
|
6
|
-
"
|
7
|
-
"build/"
|
8
|
-
],
|
9
|
-
"directories": {
|
10
|
-
"test": "test"
|
11
|
-
},
|
12
|
-
"dependencies": {
|
13
|
-
"@fastify/cors": "^8.2.0",
|
14
|
-
"@fastify/sensible": "^5.2.0",
|
15
|
-
"colors": "^1.4.0",
|
16
|
-
"fastify": "^4.13.0",
|
17
|
-
"fastify-socket.io": "^4.0.0",
|
18
|
-
"socket.io": "^4.6.0"
|
19
|
-
},
|
20
|
-
"devDependencies": {
|
21
|
-
"@snyk/protect": "^1.1105.0",
|
22
|
-
"chai": "^4.3.3",
|
23
|
-
"chai-http": "^4.3.0",
|
24
|
-
"coffeescript": "^2.7.0",
|
25
|
-
"mocha": "^10.2.0",
|
26
|
-
"socket.io-client": "^4.5.0"
|
27
|
-
},
|
28
|
-
"scripts": {
|
29
|
-
"prepare": "npm run snyk-protect",
|
30
|
-
"snyk-protect": "snyk-protect",
|
31
|
-
"dev": "$(npm bin)/coffee --no-header --map --watch --output build/ --compile src/",
|
32
|
-
"build": "$(npm bin)/coffee --no-header --map --output build/ --compile src/",
|
33
|
-
"test": "$(npm bin)/coffee --no-header -c ./test && mocha --exit",
|
34
|
-
"gpr-setup": "node scripts/gpr.js"
|
35
|
-
},
|
36
|
-
"repository": {
|
37
|
-
"type": "git",
|
38
|
-
"url": "git+https://github.com/x42en/IOServer.git"
|
39
|
-
},
|
40
|
-
"publishConfig": {
|
41
|
-
"registry": "https://registry.npmjs.org"
|
42
|
-
},
|
3
|
+
"version": "2.0.1",
|
4
|
+
"description": "Damn simple Fastify & Socket.io server framework with TypeScript support",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"types": "dist/index.d.ts",
|
43
7
|
"keywords": [
|
44
8
|
"socket.io",
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
48
|
-
"
|
49
|
-
"
|
9
|
+
"fastify",
|
10
|
+
"typescript",
|
11
|
+
"websocket",
|
12
|
+
"server",
|
13
|
+
"framework",
|
14
|
+
"real-time"
|
50
15
|
],
|
51
|
-
"author": "Ben Mz",
|
16
|
+
"author": "Ben Mz <0x42en@users.noreply.github.com>",
|
52
17
|
"license": "Apache-2.0",
|
18
|
+
"repository": {
|
19
|
+
"type": "git",
|
20
|
+
"url": "https://github.com/x42en/IOServer.git"
|
21
|
+
},
|
53
22
|
"bugs": {
|
54
23
|
"url": "https://github.com/x42en/IOServer/issues"
|
55
24
|
},
|
56
25
|
"homepage": "https://github.com/x42en/IOServer#readme",
|
57
|
-
"
|
58
|
-
|
59
|
-
|
26
|
+
"files": [
|
27
|
+
"dist/**/*",
|
28
|
+
"README.md",
|
29
|
+
"LICENSE"
|
30
|
+
],
|
31
|
+
"engines": {
|
32
|
+
"node": ">=18.0.0"
|
33
|
+
},
|
34
|
+
"dependencies": {
|
35
|
+
"@fastify/cors": "^10.1.0",
|
36
|
+
"@fastify/sensible": "^6.0.3",
|
37
|
+
"fastify": "^5.3.3",
|
38
|
+
"socket.io": "^4.8.1"
|
39
|
+
},
|
40
|
+
"devDependencies": {
|
41
|
+
"@eslint/js": "^9.28.0",
|
42
|
+
"@types/jest": "^29.5.14",
|
43
|
+
"@types/node": "^22.15.30",
|
44
|
+
"@types/supertest": "^6.0.3",
|
45
|
+
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
46
|
+
"@typescript-eslint/parser": "^8.33.1",
|
47
|
+
"eslint": "^9.28.0",
|
48
|
+
"jest": "^29.7.0",
|
49
|
+
"socket.io-client": "^4.8.1",
|
50
|
+
"supertest": "^7.1.1",
|
51
|
+
"ts-jest": "^29.3.4",
|
52
|
+
"ts-node": "^10.9.2",
|
53
|
+
"typedoc": "^0.28.5",
|
54
|
+
"typescript": "^5.8.3"
|
55
|
+
},
|
56
|
+
"peerDependencies": {
|
57
|
+
"typescript": ">=5.0.0"
|
58
|
+
},
|
59
|
+
"scripts": {
|
60
|
+
"build": "tsc",
|
61
|
+
"build:watch": "tsc --watch",
|
62
|
+
"dev": "ts-node",
|
63
|
+
"dev:chat": "ts-node examples/chat-app/app.ts",
|
64
|
+
"dev:simple": "ts-node examples/simple-example.ts",
|
65
|
+
"test": "jest",
|
66
|
+
"test:watch": "jest --watch",
|
67
|
+
"test:coverage": "jest --coverage",
|
68
|
+
"test:unit": "jest --testPathPattern=unit",
|
69
|
+
"test:integration": "jest --testPathPattern=integration",
|
70
|
+
"test:e2e": "jest --testPathPattern=e2e",
|
71
|
+
"test:performance": "jest --testPathPattern=performance",
|
72
|
+
"lint": "eslint .",
|
73
|
+
"lint:fix": "eslint . --fix",
|
74
|
+
"docs:build": "cd docs && make html",
|
75
|
+
"docs:api": "typedoc --options typedoc.json",
|
76
|
+
"docs:serve": "cd docs/build/html && python -m http.server 8000"
|
77
|
+
}
|
78
|
+
}
|