topsyde-utils 1.0.0

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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +192 -0
  3. package/dist/app.d.ts +11 -0
  4. package/dist/app.js +32 -0
  5. package/dist/app.js.map +1 -0
  6. package/dist/consts.d.ts +30 -0
  7. package/dist/consts.js +34 -0
  8. package/dist/consts.js.map +1 -0
  9. package/dist/enums.d.ts +13 -0
  10. package/dist/enums.js +19 -0
  11. package/dist/enums.js.map +1 -0
  12. package/dist/errors.d.ts +37 -0
  13. package/dist/errors.js +46 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/guards.d.ts +19 -0
  16. package/dist/guards.js +42 -0
  17. package/dist/guards.js.map +1 -0
  18. package/dist/index.d.ts +13 -0
  19. package/dist/index.js +75 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/initializable.d.ts +134 -0
  22. package/dist/initializable.js +311 -0
  23. package/dist/initializable.js.map +1 -0
  24. package/dist/lib.d.ts +67 -0
  25. package/dist/lib.js +488 -0
  26. package/dist/lib.js.map +1 -0
  27. package/dist/router/index.d.ts +5 -0
  28. package/dist/router/index.js +30 -0
  29. package/dist/router/index.js.map +1 -0
  30. package/dist/router/middleware.d.ts +21 -0
  31. package/dist/router/middleware.js +47 -0
  32. package/dist/router/middleware.js.map +1 -0
  33. package/dist/router/route.d.ts +14 -0
  34. package/dist/router/route.js +22 -0
  35. package/dist/router/route.js.map +1 -0
  36. package/dist/router/router.d.ts +20 -0
  37. package/dist/router/router.js +35 -0
  38. package/dist/router/router.js.map +1 -0
  39. package/dist/singleton.d.ts +97 -0
  40. package/dist/singleton.js +142 -0
  41. package/dist/singleton.js.map +1 -0
  42. package/dist/throwable.d.ts +42 -0
  43. package/dist/throwable.js +74 -0
  44. package/dist/throwable.js.map +1 -0
  45. package/dist/types.d.ts +9 -0
  46. package/dist/types.js +3 -0
  47. package/dist/types.js.map +1 -0
  48. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # topsyde-utils
2
+
3
+ A comprehensive bundle of TypeScript utility classes and functions designed to simplify common programming tasks.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install topsyde-utils
9
+ # or
10
+ yarn add topsyde-utils
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - **Error Handling**: Custom error classes like `Throwable` for expected errors that shouldn't trigger retries
16
+ - **Type Guards**: Robust type checking with the `Guards` class
17
+ - **Utility Functions**: Extensive collection of helper functions in the `Lib` class
18
+ - **Singleton Pattern**: Easy implementation of the singleton pattern
19
+ - **Application Utilities**: Response formatting for web applications
20
+ - **Type Definitions**: Useful TypeScript type definitions
21
+
22
+ ## Usage Examples
23
+
24
+ ### Throwable Error Handling
25
+
26
+ ```typescript
27
+ import { Throwable, Lib } from 'topsyde-utils';
28
+
29
+ // Basic usage
30
+ throw new Throwable("This operation failed but it's expected");
31
+
32
+ // With context
33
+ throw new Throwable("User not found", {
34
+ context: { userId: 123, operation: "fetch" }
35
+ });
36
+
37
+ // Using with RetryHandler
38
+ await Lib.RetryHandler(async () => {
39
+ // If this throws a Throwable, RetryHandler won't retry
40
+ const result = await someOperation();
41
+ if (!result) {
42
+ throw new Throwable("Expected failure condition");
43
+ }
44
+ return result;
45
+ });
46
+ ```
47
+
48
+ ### Type Guards
49
+
50
+ ```typescript
51
+ import { Guards } from 'topsyde-utils';
52
+
53
+ if (Guards.IsString(value)) {
54
+ // value is guaranteed to be a string
55
+ console.log(value.toUpperCase());
56
+ }
57
+
58
+ if (Guards.IsNumber(value, true)) {
59
+ // value is guaranteed to be a non-null number
60
+ console.log(value.toFixed(2));
61
+ }
62
+ ```
63
+
64
+ ### Utility Functions
65
+
66
+ ```typescript
67
+ import { Lib } from 'topsyde-utils';
68
+
69
+ // Date formatting
70
+ const formattedDate = Lib.FormatDate(new Date(), "DD/MM/YYYY");
71
+
72
+ // Retry mechanism
73
+ const result = await Lib.RetryHandler(
74
+ async () => await fetchData(),
75
+ 3 // number of retries
76
+ );
77
+
78
+ // UUID generation
79
+ const id = Lib.UUID();
80
+ ```
81
+
82
+ ### Singleton Pattern
83
+
84
+ ```typescript
85
+ import { Singleton } from 'topsyde-utils';
86
+
87
+ class Database extends Singleton {
88
+ connect() {
89
+ // Connect to database
90
+ }
91
+ }
92
+
93
+ // Get the singleton instance
94
+ const db = Database.getInstance();
95
+ db.connect();
96
+ ```
97
+
98
+ ### Using Modules from Subdirectories
99
+
100
+ The package organizes related functionality into modules. For example, the router module:
101
+
102
+ ```typescript
103
+ // Import the entire Router module
104
+ import { Router } from 'topsyde-utils';
105
+
106
+ // Create a new router
107
+ const router = new Router.Router();
108
+
109
+ // Add a route
110
+ router.addRoute(new Router.Route('/users', 'GET', async (req, res) => {
111
+ // Handle request
112
+ }));
113
+
114
+ // Use middleware
115
+ Router.applyMiddleware(req, res, [
116
+ Router.commonMiddleware.logger,
117
+ Router.commonMiddleware.cors
118
+ ]);
119
+ ```
120
+
121
+ ## API Documentation
122
+
123
+ ### Throwable
124
+
125
+ Custom error class for errors that are expected to be thrown and should not trigger retry mechanisms or be reported to error monitoring services.
126
+
127
+ ```typescript
128
+ new Throwable(message, options);
129
+ ```
130
+
131
+ - `message`: Error message or existing Error object to wrap
132
+ - `options`: Configuration options
133
+ - `logError`: Whether to log this error to console (default: true)
134
+ - `context`: Additional context data to attach to the error
135
+
136
+ ### Guards
137
+
138
+ Type guard utilities for safe type checking.
139
+
140
+ - `IsString(value, excludeNull?)`: Check if value is a string
141
+ - `IsNumber(value, excludeNull?)`: Check if value is a number
142
+ - `IsBoolean(value, excludeNull?)`: Check if value is a boolean
143
+ - `IsArray(value, excludeNull?)`: Check if value is an array
144
+ - `IsObject(value, excludeNull?)`: Check if value is an object
145
+ - `IsFunction(value, excludeNull?)`: Check if value is a function
146
+ - `IsNil(value)`: Check if value is null or undefined
147
+ - `IsType<T>(obj, keys?)`: Check if object matches a type
148
+
149
+ ### Lib
150
+
151
+ Extensive utility library with various helper functions.
152
+
153
+ - Date/Time utilities
154
+ - Retry mechanisms
155
+ - Logging functions
156
+ - String manipulation
157
+ - UUID generation
158
+ - And many more...
159
+
160
+ ## Development
161
+
162
+ ### Automatic Index Generation
163
+
164
+ This package includes a script to automatically generate index files based on the contents of the src directory and its subdirectories. This makes it easier to maintain the package as you add or modify files.
165
+
166
+ The script:
167
+ 1. Exports all named exports from all files
168
+ 2. Exports all default exports with capitalized names
169
+ 3. Creates barrel files (index.ts) for each subdirectory
170
+ 4. Imports and re-exports subdirectory modules in the main index.ts
171
+
172
+ To generate the index files:
173
+
174
+ ```bash
175
+ npm run generate-indexes
176
+ ```
177
+
178
+ To build the package with the updated indexes:
179
+
180
+ ```bash
181
+ npm run build:indexes
182
+ ```
183
+
184
+ #### Naming Conventions
185
+
186
+ - Default exports from files directly in src are exported with their capitalized name (e.g., `app.ts` → `App`)
187
+ - Default exports from files in subdirectories are exported with the directory name as a prefix (e.g., `router/route.ts` → `RouterRoute`)
188
+ - Subdirectories are exported as modules with the capitalized directory name (e.g., `router/` → `Router`)
189
+
190
+ ## License
191
+
192
+ MIT
package/dist/app.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare const RESPONSE_INIT: (status?: number, headers?: HeadersInit) => ResponseInit;
2
+ export declare const RESPONSE_METHOD_OPTIONS: {
3
+ name: string;
4
+ value: string;
5
+ };
6
+ declare class Application {
7
+ static Response(data: any, status?: number, headers?: HeadersInit): Response;
8
+ static Error<T extends BodyInit | unknown | Error>(error: T, status?: number, headers?: HeadersInit): Response;
9
+ static Throw<T extends BodyInit | unknown | Error>(error: T, status?: number, headers?: HeadersInit): Response;
10
+ }
11
+ export default Application;
package/dist/app.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESPONSE_METHOD_OPTIONS = exports.RESPONSE_INIT = void 0;
4
+ const RESPONSE_INIT = (status, headers) => {
5
+ return {
6
+ status: status ?? 200,
7
+ headers: {
8
+ "Content-Type": "application/json",
9
+ "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
10
+ "Access-Control-Allow-Headers": "Content-Type, Authorization",
11
+ "Access-Control-Allow-Credentials": "true",
12
+ },
13
+ };
14
+ };
15
+ exports.RESPONSE_INIT = RESPONSE_INIT;
16
+ exports.RESPONSE_METHOD_OPTIONS = {
17
+ name: "Access-Control-Max-Age",
18
+ value: "86400",
19
+ };
20
+ class Application {
21
+ static Response(data, status = 200, headers) {
22
+ return Response.json({ status: true, data }, (0, exports.RESPONSE_INIT)(status, headers));
23
+ }
24
+ static Error(error, status = 200, headers) {
25
+ return Response.json({ status: false, error }, (0, exports.RESPONSE_INIT)(status, headers));
26
+ }
27
+ static Throw(error, status = 400, headers) {
28
+ return Response.json(error, (0, exports.RESPONSE_INIT)(status, headers));
29
+ }
30
+ }
31
+ exports.default = Application;
32
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAC,MAAe,EAAE,OAAqB,EAAgB,EAAE;IACrF,OAAO;QACN,MAAM,EAAE,MAAM,IAAI,GAAG;QACrB,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;YAClC,8BAA8B,EAAE,oBAAoB;YACpD,8BAA8B,EAAE,6BAA6B;YAC7D,kCAAkC,EAAE,MAAM;SAC1C;KACD,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,aAAa,iBAUxB;AAEW,QAAA,uBAAuB,GAAG;IACtC,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,OAAO;CACd,CAAC;AAEF,MAAM,WAAW;IACT,MAAM,CAAC,QAAQ,CAAC,IAAS,EAAE,SAAiB,GAAG,EAAE,OAAqB;QAC5E,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,IAAA,qBAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9E,CAAC;IAEM,MAAM,CAAC,KAAK,CAAuC,KAAQ,EAAE,SAAiB,GAAG,EAAE,OAAqB;QAC9G,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAA,qBAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAChF,CAAC;IAEM,MAAM,CAAC,KAAK,CAAuC,KAAQ,EAAE,SAAiB,GAAG,EAAE,OAAqB;QAC9G,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAA,qBAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7D,CAAC;CACD;AAED,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,30 @@
1
+ export declare const DEFAULT_FALSE_RESPONSE = "Something went wrong. Please try again later.";
2
+ export declare const LOG_COLORS: {
3
+ reset: string;
4
+ bright: string;
5
+ dim: string;
6
+ underscore: string;
7
+ blink: string;
8
+ reverse: string;
9
+ hidden: string;
10
+ text: {
11
+ black: string;
12
+ red: string;
13
+ green: string;
14
+ yellow: string;
15
+ blue: string;
16
+ magenta: string;
17
+ cyan: string;
18
+ white: string;
19
+ };
20
+ bg: {
21
+ black: string;
22
+ red: string;
23
+ green: string;
24
+ yellow: string;
25
+ blue: string;
26
+ magenta: string;
27
+ cyan: string;
28
+ white: string;
29
+ };
30
+ };
package/dist/consts.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOG_COLORS = exports.DEFAULT_FALSE_RESPONSE = void 0;
4
+ exports.DEFAULT_FALSE_RESPONSE = "Something went wrong. Please try again later.";
5
+ exports.LOG_COLORS = {
6
+ reset: "\x1b[0m",
7
+ bright: "\x1b[1m",
8
+ dim: "\x1b[2m",
9
+ underscore: "\x1b[4m",
10
+ blink: "\x1b[5m",
11
+ reverse: "\x1b[7m",
12
+ hidden: "\x1b[8m",
13
+ text: {
14
+ black: "\x1b[30m",
15
+ red: "\x1b[31m",
16
+ green: "\x1b[32m",
17
+ yellow: "\x1b[33m",
18
+ blue: "\x1b[34m",
19
+ magenta: "\x1b[35m",
20
+ cyan: "\x1b[36m",
21
+ white: "\x1b[37m",
22
+ },
23
+ bg: {
24
+ black: "\x1b[40m",
25
+ red: "\x1b[41m",
26
+ green: "\x1b[42m",
27
+ yellow: "\x1b[43m",
28
+ blue: "\x1b[44m",
29
+ magenta: "\x1b[45m",
30
+ cyan: "\x1b[46m",
31
+ white: "\x1b[47m",
32
+ },
33
+ };
34
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,+CAA+C,CAAC;AAEzE,QAAA,UAAU,GAAG;IACzB,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,GAAG,EAAE,SAAS;IACd,UAAU,EAAE,SAAS;IACrB,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IAEjB,IAAI,EAAE;QACL,KAAK,EAAE,UAAU;QACjB,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KACjB;IACD,EAAE,EAAE;QACH,KAAK,EAAE,UAAU;QACjB,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KACjB;CACD,CAAC"}
@@ -0,0 +1,13 @@
1
+ export declare enum E_IS {
2
+ ARRAY = "array",
3
+ OBJECT = "object",
4
+ FUNCTION = "function",
5
+ STRING = "string",
6
+ NUMBER = "number",
7
+ BOOLEAN = "boolean",
8
+ REGEX = "regex"
9
+ }
10
+ export declare enum E_ENVIRONMENTS {
11
+ DEV = "development",
12
+ PROD = "production"
13
+ }
package/dist/enums.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.E_ENVIRONMENTS = exports.E_IS = void 0;
4
+ var E_IS;
5
+ (function (E_IS) {
6
+ E_IS["ARRAY"] = "array";
7
+ E_IS["OBJECT"] = "object";
8
+ E_IS["FUNCTION"] = "function";
9
+ E_IS["STRING"] = "string";
10
+ E_IS["NUMBER"] = "number";
11
+ E_IS["BOOLEAN"] = "boolean";
12
+ E_IS["REGEX"] = "regex";
13
+ })(E_IS || (exports.E_IS = E_IS = {}));
14
+ var E_ENVIRONMENTS;
15
+ (function (E_ENVIRONMENTS) {
16
+ E_ENVIRONMENTS["DEV"] = "development";
17
+ E_ENVIRONMENTS["PROD"] = "production";
18
+ })(E_ENVIRONMENTS || (exports.E_ENVIRONMENTS = E_ENVIRONMENTS = {}));
19
+ //# sourceMappingURL=enums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":";;;AAAA,IAAY,IAQX;AARD,WAAY,IAAI;IACd,uBAAe,CAAA;IACf,yBAAiB,CAAA;IACjB,6BAAqB,CAAA;IACrB,yBAAiB,CAAA;IACjB,yBAAiB,CAAA;IACjB,2BAAmB,CAAA;IACnB,uBAAe,CAAA;AACjB,CAAC,EARW,IAAI,oBAAJ,IAAI,QAQf;AAGD,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;AACrB,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB"}
@@ -0,0 +1,37 @@
1
+ export declare enum ERROR_CODE {
2
+ NO_REQUEST = -1,
3
+ UNKNOWN_ERROR = 0,
4
+ INVALID_METHOD = 1,
5
+ INVALID_REQUEST = 2,
6
+ INVALID_CONTROLLER = 3,
7
+ INVALID_ACTION = 4,
8
+ NO_ACTION_IN_MAP = 5,
9
+ NO_METHOD_HANDLER = 6,
10
+ INVALID_METHOD_INPUT = 7,
11
+ REQ_BODY_EMPTY = 8
12
+ }
13
+ export declare enum HTTP_ERROR_CODE {
14
+ OK = 200,
15
+ BAD_REQUEST = 400,
16
+ UNAUTHORIZED = 401,
17
+ FORBIDDEN = 403,
18
+ NOT_FOUND = 404,
19
+ INTERNAL_SERVER_ERROR = 500
20
+ }
21
+ export declare enum WS_ERROR_CODE {
22
+ NORMAL_CLOSURE = 1000,
23
+ GOING_AWAY = 1001,
24
+ PROTOCOL_ERROR = 1002,
25
+ UNSUPPORTED_DATA = 1003,
26
+ NO_STATUS_RECEIVED = 1005,
27
+ ABNORMAL_CLOSURE = 1006,
28
+ INVALID_FRAME_PAYLOAD_DATA = 1007,
29
+ POLICY_VIOLATION = 1008,
30
+ MESSAGE_TOO_BIG = 1009,
31
+ MISSING_EXTENSION = 1010,
32
+ INTERNAL_ERROR = 1011,
33
+ SERVICE_RESTART = 1012,
34
+ TRY_AGAIN_LATER = 1013,
35
+ BAD_GATEWAY = 1014,
36
+ TLS_HANDSHAKE = 1015
37
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WS_ERROR_CODE = exports.HTTP_ERROR_CODE = exports.ERROR_CODE = void 0;
4
+ // Error code enums
5
+ var ERROR_CODE;
6
+ (function (ERROR_CODE) {
7
+ ERROR_CODE[ERROR_CODE["NO_REQUEST"] = -1] = "NO_REQUEST";
8
+ ERROR_CODE[ERROR_CODE["UNKNOWN_ERROR"] = 0] = "UNKNOWN_ERROR";
9
+ ERROR_CODE[ERROR_CODE["INVALID_METHOD"] = 1] = "INVALID_METHOD";
10
+ ERROR_CODE[ERROR_CODE["INVALID_REQUEST"] = 2] = "INVALID_REQUEST";
11
+ ERROR_CODE[ERROR_CODE["INVALID_CONTROLLER"] = 3] = "INVALID_CONTROLLER";
12
+ ERROR_CODE[ERROR_CODE["INVALID_ACTION"] = 4] = "INVALID_ACTION";
13
+ ERROR_CODE[ERROR_CODE["NO_ACTION_IN_MAP"] = 5] = "NO_ACTION_IN_MAP";
14
+ ERROR_CODE[ERROR_CODE["NO_METHOD_HANDLER"] = 6] = "NO_METHOD_HANDLER";
15
+ ERROR_CODE[ERROR_CODE["INVALID_METHOD_INPUT"] = 7] = "INVALID_METHOD_INPUT";
16
+ ERROR_CODE[ERROR_CODE["REQ_BODY_EMPTY"] = 8] = "REQ_BODY_EMPTY";
17
+ })(ERROR_CODE || (exports.ERROR_CODE = ERROR_CODE = {}));
18
+ var HTTP_ERROR_CODE;
19
+ (function (HTTP_ERROR_CODE) {
20
+ HTTP_ERROR_CODE[HTTP_ERROR_CODE["OK"] = 200] = "OK";
21
+ HTTP_ERROR_CODE[HTTP_ERROR_CODE["BAD_REQUEST"] = 400] = "BAD_REQUEST";
22
+ HTTP_ERROR_CODE[HTTP_ERROR_CODE["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
23
+ HTTP_ERROR_CODE[HTTP_ERROR_CODE["FORBIDDEN"] = 403] = "FORBIDDEN";
24
+ HTTP_ERROR_CODE[HTTP_ERROR_CODE["NOT_FOUND"] = 404] = "NOT_FOUND";
25
+ HTTP_ERROR_CODE[HTTP_ERROR_CODE["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
26
+ })(HTTP_ERROR_CODE || (exports.HTTP_ERROR_CODE = HTTP_ERROR_CODE = {}));
27
+ var WS_ERROR_CODE;
28
+ (function (WS_ERROR_CODE) {
29
+ // WebSocket close event codes
30
+ WS_ERROR_CODE[WS_ERROR_CODE["NORMAL_CLOSURE"] = 1000] = "NORMAL_CLOSURE";
31
+ WS_ERROR_CODE[WS_ERROR_CODE["GOING_AWAY"] = 1001] = "GOING_AWAY";
32
+ WS_ERROR_CODE[WS_ERROR_CODE["PROTOCOL_ERROR"] = 1002] = "PROTOCOL_ERROR";
33
+ WS_ERROR_CODE[WS_ERROR_CODE["UNSUPPORTED_DATA"] = 1003] = "UNSUPPORTED_DATA";
34
+ WS_ERROR_CODE[WS_ERROR_CODE["NO_STATUS_RECEIVED"] = 1005] = "NO_STATUS_RECEIVED";
35
+ WS_ERROR_CODE[WS_ERROR_CODE["ABNORMAL_CLOSURE"] = 1006] = "ABNORMAL_CLOSURE";
36
+ WS_ERROR_CODE[WS_ERROR_CODE["INVALID_FRAME_PAYLOAD_DATA"] = 1007] = "INVALID_FRAME_PAYLOAD_DATA";
37
+ WS_ERROR_CODE[WS_ERROR_CODE["POLICY_VIOLATION"] = 1008] = "POLICY_VIOLATION";
38
+ WS_ERROR_CODE[WS_ERROR_CODE["MESSAGE_TOO_BIG"] = 1009] = "MESSAGE_TOO_BIG";
39
+ WS_ERROR_CODE[WS_ERROR_CODE["MISSING_EXTENSION"] = 1010] = "MISSING_EXTENSION";
40
+ WS_ERROR_CODE[WS_ERROR_CODE["INTERNAL_ERROR"] = 1011] = "INTERNAL_ERROR";
41
+ WS_ERROR_CODE[WS_ERROR_CODE["SERVICE_RESTART"] = 1012] = "SERVICE_RESTART";
42
+ WS_ERROR_CODE[WS_ERROR_CODE["TRY_AGAIN_LATER"] = 1013] = "TRY_AGAIN_LATER";
43
+ WS_ERROR_CODE[WS_ERROR_CODE["BAD_GATEWAY"] = 1014] = "BAD_GATEWAY";
44
+ WS_ERROR_CODE[WS_ERROR_CODE["TLS_HANDSHAKE"] = 1015] = "TLS_HANDSHAKE";
45
+ })(WS_ERROR_CODE || (exports.WS_ERROR_CODE = WS_ERROR_CODE = {}));
46
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,mBAAmB;AACnB,IAAY,UAWX;AAXD,WAAY,UAAU;IACrB,wDAAe,CAAA;IACf,6DAAiB,CAAA;IACjB,+DAAkB,CAAA;IAClB,iEAAmB,CAAA;IACnB,uEAAsB,CAAA;IACtB,+DAAkB,CAAA;IAClB,mEAAoB,CAAA;IACpB,qEAAqB,CAAA;IACrB,2EAAwB,CAAA;IACxB,+DAAkB,CAAA;AACnB,CAAC,EAXW,UAAU,0BAAV,UAAU,QAWrB;AAED,IAAY,eAOX;AAPD,WAAY,eAAe;IAC1B,mDAAQ,CAAA;IACR,qEAAiB,CAAA;IACjB,uEAAkB,CAAA;IAClB,iEAAe,CAAA;IACf,iEAAe,CAAA;IACf,yFAA2B,CAAA;AAC5B,CAAC,EAPW,eAAe,+BAAf,eAAe,QAO1B;AAED,IAAY,aAiBX;AAjBD,WAAY,aAAa;IACxB,8BAA8B;IAC9B,wEAAqB,CAAA;IACrB,gEAAiB,CAAA;IACjB,wEAAqB,CAAA;IACrB,4EAAuB,CAAA;IACvB,gFAAyB,CAAA;IACzB,4EAAuB,CAAA;IACvB,gGAAiC,CAAA;IACjC,4EAAuB,CAAA;IACvB,0EAAsB,CAAA;IACtB,8EAAwB,CAAA;IACxB,wEAAqB,CAAA;IACrB,0EAAsB,CAAA;IACtB,0EAAsB,CAAA;IACtB,kEAAkB,CAAA;IAClB,sEAAoB,CAAA;AACrB,CAAC,EAjBW,aAAa,6BAAb,aAAa,QAiBxB"}
@@ -0,0 +1,19 @@
1
+ import type { NonNullableType } from "./types";
2
+ declare class Guards {
3
+ static IsString(value: any): value is string;
4
+ static IsString(value: any, excludeNull: true): value is NonNullableType<string>;
5
+ static IsNumber(value: any): value is number;
6
+ static IsNumber(value: any, excludeNull: true): value is NonNullableType<number>;
7
+ static IsBoolean(value: any): value is boolean;
8
+ static IsBoolean(value: any, excludeNull: true): value is NonNullableType<boolean>;
9
+ static IsArray<T>(value: any): value is T[];
10
+ static IsArray<T>(value: any, excludeNull: true): value is NonNullableType<T[]>;
11
+ static IsObject(value: any): value is object;
12
+ static IsObject(value: any, excludeNull: true): value is NonNullableType<object>;
13
+ static IsFunction(value: any): value is Function;
14
+ static IsFunction(value: any, excludeNull: true): value is NonNullableType<Function>;
15
+ static IsNil(value: any): value is null | undefined;
16
+ static IsType<T>(obj: any): obj is T;
17
+ static IsType<T>(obj: any, keys: (keyof T)[]): obj is T;
18
+ }
19
+ export default Guards;
package/dist/guards.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const lib_1 = __importDefault(require("./lib"));
7
+ class Guards {
8
+ static IsString(value, excludeNull = false) {
9
+ const output = lib_1.default.IsString(value);
10
+ return excludeNull ? !Guards.IsNil(value) && output : output;
11
+ }
12
+ static IsNumber(value, excludeNull = false) {
13
+ const output = lib_1.default.IsNumber(value);
14
+ return excludeNull ? !Guards.IsNil(value) && output : output;
15
+ }
16
+ static IsBoolean(value, excludeNull = false) {
17
+ const output = lib_1.default.GetType(value, true) === "boolean";
18
+ return excludeNull ? !Guards.IsNil(value) && output : output;
19
+ }
20
+ static IsArray(value, excludeNull = false) {
21
+ const output = lib_1.default.IsArray(value);
22
+ return excludeNull ? !Guards.IsNil(value) && output : output;
23
+ }
24
+ static IsObject(value, excludeNull = false) {
25
+ const output = lib_1.default.IsObject(value);
26
+ return excludeNull ? !Guards.IsNil(value) && output : output;
27
+ }
28
+ static IsFunction(value, excludeNull = false) {
29
+ const output = lib_1.default.IsFunction(value);
30
+ return excludeNull ? !Guards.IsNil(value) && output : output;
31
+ }
32
+ static IsNil(value) {
33
+ return lib_1.default.IsNil(value);
34
+ }
35
+ static IsType(obj, keys) {
36
+ if (!keys)
37
+ return !this.IsNil(obj);
38
+ return keys.every((key) => key in obj);
39
+ }
40
+ }
41
+ exports.default = Guards;
42
+ //# sourceMappingURL=guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":";;;;;AACA,gDAAwB;AAExB,MAAM,MAAM;IAGJ,MAAM,CAAC,QAAQ,CAAC,KAAU,EAAE,cAAuB,KAAK;QAC9D,MAAM,MAAM,GAAG,aAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAIM,MAAM,CAAC,QAAQ,CAAC,KAAU,EAAE,cAAuB,KAAK;QAC9D,MAAM,MAAM,GAAG,aAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAIM,MAAM,CAAC,SAAS,CAAC,KAAU,EAAE,cAAuB,KAAK;QAC/D,MAAM,MAAM,GAAG,aAAG,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,SAAS,CAAC;QACtD,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAIM,MAAM,CAAC,OAAO,CAAI,KAAU,EAAE,cAAuB,KAAK;QAChE,MAAM,MAAM,GAAG,aAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAIM,MAAM,CAAC,QAAQ,CAAC,KAAU,EAAE,cAAuB,KAAK;QAC9D,MAAM,MAAM,GAAG,aAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAIM,MAAM,CAAC,UAAU,CAAC,KAAU,EAAE,cAAuB,KAAK;QAChE,MAAM,MAAM,GAAG,aAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,KAAU;QAC7B,OAAO,aAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAIM,MAAM,CAAC,MAAM,CAAI,GAAQ,EAAE,IAAkB;QACnD,IAAI,CAAC,IAAI;YAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IACxC,CAAC;CACD;AAED,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,13 @@
1
+ export { default as App } from './app';
2
+ export { default as Guards } from './guards';
3
+ export { default as Initializable } from './initializable';
4
+ export { default as Lib } from './lib';
5
+ export { default as RouterRoute } from './router/route';
6
+ export { default as RouterRouter } from './router/router';
7
+ export { default as Singleton } from './singleton';
8
+ export { default as Throwable } from './throwable';
9
+ export { ERROR_CODE, HTTP_ERROR_CODE, WS_ERROR_CODE } from './errors';
10
+ export { E_IS, E_ENVIRONMENTS } from './enums';
11
+ export { RESPONSE_INIT, RESPONSE_METHOD_OPTIONS } from './app';
12
+ import * as RouterModule from './router';
13
+ export { RouterModule as Router };
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ // This file is auto-generated by scripts/generate-indexes.sh
3
+ // Do not edit this file directly
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
37
+ var __importDefault = (this && this.__importDefault) || function (mod) {
38
+ return (mod && mod.__esModule) ? mod : { "default": mod };
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.Router = exports.RESPONSE_METHOD_OPTIONS = exports.RESPONSE_INIT = exports.E_ENVIRONMENTS = exports.E_IS = exports.WS_ERROR_CODE = exports.HTTP_ERROR_CODE = exports.ERROR_CODE = exports.Throwable = exports.Singleton = exports.RouterRouter = exports.RouterRoute = exports.Lib = exports.Initializable = exports.Guards = exports.App = void 0;
42
+ // Export all modules
43
+ // Export default classes
44
+ var app_1 = require("./app");
45
+ Object.defineProperty(exports, "App", { enumerable: true, get: function () { return __importDefault(app_1).default; } });
46
+ var guards_1 = require("./guards");
47
+ Object.defineProperty(exports, "Guards", { enumerable: true, get: function () { return __importDefault(guards_1).default; } });
48
+ var initializable_1 = require("./initializable");
49
+ Object.defineProperty(exports, "Initializable", { enumerable: true, get: function () { return __importDefault(initializable_1).default; } });
50
+ var lib_1 = require("./lib");
51
+ Object.defineProperty(exports, "Lib", { enumerable: true, get: function () { return __importDefault(lib_1).default; } });
52
+ var route_1 = require("./router/route");
53
+ Object.defineProperty(exports, "RouterRoute", { enumerable: true, get: function () { return __importDefault(route_1).default; } });
54
+ var router_1 = require("./router/router");
55
+ Object.defineProperty(exports, "RouterRouter", { enumerable: true, get: function () { return __importDefault(router_1).default; } });
56
+ var singleton_1 = require("./singleton");
57
+ Object.defineProperty(exports, "Singleton", { enumerable: true, get: function () { return __importDefault(singleton_1).default; } });
58
+ var throwable_1 = require("./throwable");
59
+ Object.defineProperty(exports, "Throwable", { enumerable: true, get: function () { return __importDefault(throwable_1).default; } });
60
+ // Re-export specific items for backward compatibility
61
+ var errors_1 = require("./errors");
62
+ Object.defineProperty(exports, "ERROR_CODE", { enumerable: true, get: function () { return errors_1.ERROR_CODE; } });
63
+ Object.defineProperty(exports, "HTTP_ERROR_CODE", { enumerable: true, get: function () { return errors_1.HTTP_ERROR_CODE; } });
64
+ Object.defineProperty(exports, "WS_ERROR_CODE", { enumerable: true, get: function () { return errors_1.WS_ERROR_CODE; } });
65
+ var enums_1 = require("./enums");
66
+ Object.defineProperty(exports, "E_IS", { enumerable: true, get: function () { return enums_1.E_IS; } });
67
+ Object.defineProperty(exports, "E_ENVIRONMENTS", { enumerable: true, get: function () { return enums_1.E_ENVIRONMENTS; } });
68
+ var app_2 = require("./app");
69
+ Object.defineProperty(exports, "RESPONSE_INIT", { enumerable: true, get: function () { return app_2.RESPONSE_INIT; } });
70
+ Object.defineProperty(exports, "RESPONSE_METHOD_OPTIONS", { enumerable: true, get: function () { return app_2.RESPONSE_METHOD_OPTIONS; } });
71
+ // Barrel exports for subdirectories
72
+ // Create module for router
73
+ const RouterModule = __importStar(require("./router"));
74
+ exports.Router = RouterModule;
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEjC,qBAAqB;AAErB,yBAAyB;AACzB,6BAAuC;AAA9B,2GAAA,OAAO,OAAO;AACvB,mCAA6C;AAApC,iHAAA,OAAO,OAAU;AAC1B,iDAA2D;AAAlD,+HAAA,OAAO,OAAiB;AACjC,6BAAuC;AAA9B,2GAAA,OAAO,OAAO;AACvB,wCAAwD;AAA/C,qHAAA,OAAO,OAAe;AAC/B,0CAA0D;AAAjD,uHAAA,OAAO,OAAgB;AAChC,yCAAmD;AAA1C,uHAAA,OAAO,OAAa;AAC7B,yCAAmD;AAA1C,uHAAA,OAAO,OAAa;AAE7B,sDAAsD;AACtD,mCAAsE;AAA7D,oGAAA,UAAU,OAAA;AAAE,yGAAA,eAAe,OAAA;AAAE,uGAAA,aAAa,OAAA;AACnD,iCAA+C;AAAtC,6FAAA,IAAI,OAAA;AAAE,uGAAA,cAAc,OAAA;AAC7B,6BAA+D;AAAtD,oGAAA,aAAa,OAAA;AAAE,8GAAA,uBAAuB,OAAA;AAE/C,oCAAoC;AACpC,2BAA2B;AAC3B,uDAAyC;AAChB,8BAAM"}