topsyde-utils 1.3.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/dist/index.d.ts +2 -43
- package/dist/index.js +1 -38
- package/dist/index.js.map +1 -1
- package/dist/utils/Lib.d.ts +0 -12
- package/dist/utils/Lib.js +0 -65
- package/dist/utils/Lib.js.map +1 -1
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +0 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/websocket.shared.types.d.ts +25 -0
- package/dist/websocket.shared.types.js +4 -0
- package/dist/websocket.shared.types.js.map +1 -0
- package/package.json +12 -66
- package/src/__tests__/singleton.test.ts +0 -143
- package/src/index.ts +2 -83
- package/src/utils/Lib.ts +0 -77
- package/src/utils/index.ts +0 -3
- package/src/websocket.shared.types.ts +27 -0
- package/dist/application.d.ts +0 -18
- package/dist/application.js +0 -60
- package/dist/application.js.map +0 -1
- package/dist/client/api/base.api.d.ts +0 -63
- package/dist/client/api/base.api.js +0 -61
- package/dist/client/api/base.api.js.map +0 -1
- package/dist/client/api/index.d.ts +0 -2
- package/dist/client/api/index.js +0 -5
- package/dist/client/api/index.js.map +0 -1
- package/dist/client/rxjs/index.d.ts +0 -1
- package/dist/client/rxjs/index.js +0 -4
- package/dist/client/rxjs/index.js.map +0 -1
- package/dist/client/rxjs/useRxjs.d.ts +0 -17
- package/dist/client/rxjs/useRxjs.js +0 -87
- package/dist/client/rxjs/useRxjs.js.map +0 -1
- package/dist/client/vite/plugins/index.d.ts +0 -2
- package/dist/client/vite/plugins/index.js +0 -5
- package/dist/client/vite/plugins/index.js.map +0 -1
- package/dist/client/vite/plugins/topsydeUtilsVitePlugin.d.ts +0 -9
- package/dist/client/vite/plugins/topsydeUtilsVitePlugin.js +0 -74
- package/dist/client/vite/plugins/topsydeUtilsVitePlugin.js.map +0 -1
- package/dist/external/index.d.ts +0 -1
- package/dist/external/index.js +0 -4
- package/dist/external/index.js.map +0 -1
- package/dist/external/re-exports.d.ts +0 -16
- package/dist/external/re-exports.js +0 -24
- package/dist/external/re-exports.js.map +0 -1
- package/dist/server/base/base.database.d.ts +0 -10
- package/dist/server/base/base.database.js +0 -23
- package/dist/server/base/base.database.js.map +0 -1
- package/dist/server/base/index.d.ts +0 -2
- package/dist/server/base/index.js +0 -5
- package/dist/server/base/index.js.map +0 -1
- package/dist/server/bun/index.d.ts +0 -3
- package/dist/server/bun/index.js +0 -6
- package/dist/server/bun/index.js.map +0 -1
- package/dist/server/bun/router/controller-discovery.d.ts +0 -13
- package/dist/server/bun/router/controller-discovery.js +0 -83
- package/dist/server/bun/router/controller-discovery.js.map +0 -1
- package/dist/server/bun/router/index.d.ts +0 -6
- package/dist/server/bun/router/index.js +0 -9
- package/dist/server/bun/router/index.js.map +0 -1
- package/dist/server/bun/router/router.d.ts +0 -12
- package/dist/server/bun/router/router.internal.d.ts +0 -15
- package/dist/server/bun/router/router.internal.js +0 -51
- package/dist/server/bun/router/router.internal.js.map +0 -1
- package/dist/server/bun/router/router.js +0 -38
- package/dist/server/bun/router/router.js.map +0 -1
- package/dist/server/bun/router/routes.d.ts +0 -5
- package/dist/server/bun/router/routes.js +0 -2
- package/dist/server/bun/router/routes.js.map +0 -1
- package/dist/server/bun/websocket/Channel.d.ts +0 -68
- package/dist/server/bun/websocket/Channel.js +0 -263
- package/dist/server/bun/websocket/Channel.js.map +0 -1
- package/dist/server/bun/websocket/Client.d.ts +0 -87
- package/dist/server/bun/websocket/Client.js +0 -193
- package/dist/server/bun/websocket/Client.js.map +0 -1
- package/dist/server/bun/websocket/Message.d.ts +0 -10
- package/dist/server/bun/websocket/Message.js +0 -103
- package/dist/server/bun/websocket/Message.js.map +0 -1
- package/dist/server/bun/websocket/Websocket.d.ts +0 -171
- package/dist/server/bun/websocket/Websocket.js +0 -336
- package/dist/server/bun/websocket/Websocket.js.map +0 -1
- package/dist/server/bun/websocket/index.d.ts +0 -11
- package/dist/server/bun/websocket/index.js +0 -14
- package/dist/server/bun/websocket/index.js.map +0 -1
- package/dist/server/bun/websocket/websocket.enums.d.ts +0 -27
- package/dist/server/bun/websocket/websocket.enums.js +0 -31
- package/dist/server/bun/websocket/websocket.enums.js.map +0 -1
- package/dist/server/bun/websocket/websocket.guards.d.ts +0 -3
- package/dist/server/bun/websocket/websocket.guards.js +0 -17
- package/dist/server/bun/websocket/websocket.guards.js.map +0 -1
- package/dist/server/bun/websocket/websocket.types.d.ts +0 -235
- package/dist/server/bun/websocket/websocket.types.js +0 -2
- package/dist/server/bun/websocket/websocket.types.js.map +0 -1
- package/dist/server/controller.d.ts +0 -62
- package/dist/server/controller.js +0 -55
- package/dist/server/controller.js.map +0 -1
- package/dist/server/index.d.ts +0 -4
- package/dist/server/index.js +0 -7
- package/dist/server/index.js.map +0 -1
- package/dist/server/service.d.ts +0 -5
- package/dist/server/service.js +0 -38
- package/dist/server/service.js.map +0 -1
- package/dist/utils/BaseDto.d.ts +0 -33
- package/dist/utils/BaseDto.js +0 -69
- package/dist/utils/BaseDto.js.map +0 -1
- package/dist/utils/BaseEntity.d.ts +0 -31
- package/dist/utils/BaseEntity.js +0 -37
- package/dist/utils/BaseEntity.js.map +0 -1
- package/dist/utils/dto_validators/IsNumberOrRangeConstraint.d.ts +0 -9
- package/dist/utils/dto_validators/IsNumberOrRangeConstraint.js +0 -85
- package/dist/utils/dto_validators/IsNumberOrRangeConstraint.js.map +0 -1
- package/dist/utils/dto_validators/index.d.ts +0 -1
- package/dist/utils/dto_validators/index.js +0 -4
- package/dist/utils/dto_validators/index.js.map +0 -1
- package/src/__tests__/app.test.ts +0 -206
- package/src/application.ts +0 -73
- package/src/client/api/base.api.ts +0 -111
- package/src/client/api/index.ts +0 -5
- package/src/client/rxjs/index.ts +0 -4
- package/src/client/rxjs/useRxjs.ts +0 -113
- package/src/client/vite/plugins/index.ts +0 -5
- package/src/client/vite/plugins/topsydeUtilsVitePlugin.ts +0 -80
- package/src/external/index.ts +0 -4
- package/src/external/re-exports.ts +0 -54
- package/src/server/base/base.database.ts +0 -31
- package/src/server/base/index.ts +0 -5
- package/src/server/bun/index.ts +0 -6
- package/src/server/bun/router/controller-discovery.ts +0 -94
- package/src/server/bun/router/index.ts +0 -9
- package/src/server/bun/router/router.internal.ts +0 -64
- package/src/server/bun/router/router.ts +0 -51
- package/src/server/bun/router/routes.ts +0 -7
- package/src/server/bun/websocket/Channel.ts +0 -310
- package/src/server/bun/websocket/Client.ts +0 -243
- package/src/server/bun/websocket/ISSUES.md +0 -1175
- package/src/server/bun/websocket/Message.ts +0 -120
- package/src/server/bun/websocket/Websocket.ts +0 -402
- package/src/server/bun/websocket/index.ts +0 -14
- package/src/server/bun/websocket/websocket.enums.ts +0 -29
- package/src/server/bun/websocket/websocket.guards.ts +0 -22
- package/src/server/bun/websocket/websocket.types.ts +0 -252
- package/src/server/controller.ts +0 -121
- package/src/server/index.ts +0 -7
- package/src/server/service.ts +0 -36
- package/src/utils/BaseDto.ts +0 -77
- package/src/utils/BaseEntity.ts +0 -49
- package/src/utils/dto_validators/IsNumberOrRangeConstraint.ts +0 -32
- package/src/utils/dto_validators/index.ts +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "topsyde-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A bundle of TypeScript utility classes and functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,65 +32,9 @@
|
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
33
|
"default": "./dist/index.js"
|
|
34
34
|
},
|
|
35
|
-
"./
|
|
36
|
-
"types": "./dist/
|
|
37
|
-
"default": "./dist/
|
|
38
|
-
},
|
|
39
|
-
"./client/rxjs": {
|
|
40
|
-
"types": "./dist/client/rxjs/index.d.ts",
|
|
41
|
-
"default": "./dist/client/rxjs/index.js"
|
|
42
|
-
},
|
|
43
|
-
"./client/vite/plugins": {
|
|
44
|
-
"types": "./dist/client/vite/plugins/index.d.ts",
|
|
45
|
-
"default": "./dist/client/vite/plugins/index.js"
|
|
46
|
-
},
|
|
47
|
-
"./external": {
|
|
48
|
-
"types": "./dist/external/index.d.ts",
|
|
49
|
-
"default": "./dist/external/index.js"
|
|
50
|
-
},
|
|
51
|
-
"./server/base": {
|
|
52
|
-
"types": "./dist/server/base/index.d.ts",
|
|
53
|
-
"default": "./dist/server/base/index.js"
|
|
54
|
-
},
|
|
55
|
-
"./server/bun/router": {
|
|
56
|
-
"types": "./dist/server/bun/router/index.d.ts",
|
|
57
|
-
"default": "./dist/server/bun/router/index.js"
|
|
58
|
-
},
|
|
59
|
-
"./server/bun/websocket": {
|
|
60
|
-
"types": "./dist/server/bun/websocket/index.d.ts",
|
|
61
|
-
"default": "./dist/server/bun/websocket/index.js"
|
|
62
|
-
},
|
|
63
|
-
"./utils/dto_validators": {
|
|
64
|
-
"types": "./dist/utils/dto_validators/index.d.ts",
|
|
65
|
-
"default": "./dist/utils/dto_validators/index.js"
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
"typesVersions": {
|
|
69
|
-
"*": {
|
|
70
|
-
"client/api": [
|
|
71
|
-
"./dist/client/api/index.d.ts"
|
|
72
|
-
],
|
|
73
|
-
"client/rxjs": [
|
|
74
|
-
"./dist/client/rxjs/index.d.ts"
|
|
75
|
-
],
|
|
76
|
-
"client/vite/plugins": [
|
|
77
|
-
"./dist/client/vite/plugins/index.d.ts"
|
|
78
|
-
],
|
|
79
|
-
"external": [
|
|
80
|
-
"./dist/external/index.d.ts"
|
|
81
|
-
],
|
|
82
|
-
"server/base": [
|
|
83
|
-
"./dist/server/base/index.d.ts"
|
|
84
|
-
],
|
|
85
|
-
"server/bun/router": [
|
|
86
|
-
"./dist/server/bun/router/index.d.ts"
|
|
87
|
-
],
|
|
88
|
-
"server/bun/websocket": [
|
|
89
|
-
"./dist/server/bun/websocket/index.d.ts"
|
|
90
|
-
],
|
|
91
|
-
"utils/dto_validators": [
|
|
92
|
-
"./dist/utils/dto_validators/index.d.ts"
|
|
93
|
-
]
|
|
35
|
+
"./utils": {
|
|
36
|
+
"types": "./dist/utils/index.d.ts",
|
|
37
|
+
"default": "./dist/utils/index.js"
|
|
94
38
|
}
|
|
95
39
|
},
|
|
96
40
|
"keywords": [
|
|
@@ -124,11 +68,13 @@
|
|
|
124
68
|
"node": ">=14.0.0"
|
|
125
69
|
},
|
|
126
70
|
"dependencies": {
|
|
127
|
-
"
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
"
|
|
131
|
-
|
|
132
|
-
|
|
71
|
+
"rxjs": "^7.8.2"
|
|
72
|
+
},
|
|
73
|
+
"typesVersions": {
|
|
74
|
+
"*": {
|
|
75
|
+
"utils": [
|
|
76
|
+
"./dist/utils/index.d.ts"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
133
79
|
}
|
|
134
80
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import Singleton from "../singleton";
|
|
2
|
-
import Channel from "../server/bun/websocket/Channel";
|
|
3
|
-
import { BroadcastOptions, WebsocketStructuredMessage } from "../server/bun/websocket/websocket.types";
|
|
4
|
-
import * as app from "../server/bun/websocket";
|
|
5
|
-
import { Client } from "../server/bun/websocket";
|
|
6
|
-
import { Server } from "bun";
|
|
7
2
|
|
|
8
3
|
// Base class that extends Singleton
|
|
9
4
|
class BaseClass extends Singleton {
|
|
@@ -263,142 +258,4 @@ describe("Singleton", () => {
|
|
|
263
258
|
expect(instance).toBeDefined();
|
|
264
259
|
});
|
|
265
260
|
|
|
266
|
-
it("should allow custom channel map implementation", () => {
|
|
267
|
-
class CustomChannel extends Channel {
|
|
268
|
-
public broadcast(message: WebsocketStructuredMessage) {
|
|
269
|
-
console.log("CONSOLE LOG");
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Create a map with our custom channel
|
|
274
|
-
// Create a new Websocket instance with our custom channels
|
|
275
|
-
const ws = app.Websocket.GetInstance<app.Websocket>({
|
|
276
|
-
channelClass: CustomChannel, // Explicitly set the channel class
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
// Create a new channel - it should be a CustomChannel instance
|
|
280
|
-
const newChannel = ws.createChannel("test", "Test Channel", 5);
|
|
281
|
-
expect(newChannel).toBeInstanceOf(CustomChannel);
|
|
282
|
-
|
|
283
|
-
// Verify that broadcast uses our custom implementation
|
|
284
|
-
const spy = jest.spyOn(console, "log");
|
|
285
|
-
newChannel.broadcast({ type: "test", content: { message: "test message" } });
|
|
286
|
-
expect(spy).toHaveBeenCalledWith("CONSOLE LOG");
|
|
287
|
-
spy.mockRestore();
|
|
288
|
-
|
|
289
|
-
// Verify that the global channel is also a CustomChannel
|
|
290
|
-
const globalChannel = app.Websocket.GetChannel("global");
|
|
291
|
-
expect(globalChannel).toBeInstanceOf(CustomChannel);
|
|
292
|
-
});
|
|
293
|
-
it("should allow custom client implementation", () => {
|
|
294
|
-
class CustomClient extends Client {
|
|
295
|
-
public send(message: string, options?: app.WebsocketMessageOptions): void;
|
|
296
|
-
public send(message: WebsocketStructuredMessage): void;
|
|
297
|
-
public send(message: WebsocketStructuredMessage | string, options?: app.WebsocketMessageOptions): void {
|
|
298
|
-
console.log("CUSTOM SEND");
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
const ws = app.Websocket.GetInstance<app.Websocket>({ clientClass: CustomClient });
|
|
302
|
-
const client = app.Websocket.CreateClient({ id: "test", name: "Test Client", ws: {} as any });
|
|
303
|
-
expect(client).toBeInstanceOf(CustomClient);
|
|
304
|
-
});
|
|
305
|
-
it("should allow custom channel implementation", () => {
|
|
306
|
-
class CustomChannel extends Channel {
|
|
307
|
-
public broadcast(message: WebsocketStructuredMessage) {
|
|
308
|
-
console.log("CONSOLE LOG");
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Create a map with our custom channel
|
|
313
|
-
const ws = app.Websocket.GetInstance<app.Websocket>({ channelClass: CustomChannel });
|
|
314
|
-
|
|
315
|
-
// Create a new channel - it should be a CustomChannel instance
|
|
316
|
-
const newChannel = ws.createChannel("test", "Test Channel", 5);
|
|
317
|
-
expect(newChannel).toBeInstanceOf(CustomChannel);
|
|
318
|
-
|
|
319
|
-
// Verify that broadcast uses our custom implementation
|
|
320
|
-
const spy = jest.spyOn(console, "log");
|
|
321
|
-
newChannel.broadcast({ type: "test", content: { message: "test message" } });
|
|
322
|
-
expect(spy).toHaveBeenCalledWith("CONSOLE LOG");
|
|
323
|
-
spy.mockRestore();
|
|
324
|
-
|
|
325
|
-
// Verify that the global channel is also a CustomChannel
|
|
326
|
-
const globalChannel = app.Websocket.GetChannel("global");
|
|
327
|
-
expect(globalChannel).toBeInstanceOf(CustomChannel);
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
it("should handle derived channel broadcast with server correctly", () => {
|
|
331
|
-
// Mock server setup
|
|
332
|
-
const mockPublish = jest.fn();
|
|
333
|
-
const server = {
|
|
334
|
-
publish: mockPublish,
|
|
335
|
-
} as unknown as Server;
|
|
336
|
-
|
|
337
|
-
// Create derived channel class
|
|
338
|
-
class GameChannel<T extends app.Websocket = GameWebsocket> extends Channel<T> {
|
|
339
|
-
public override broadcast(message: WebsocketStructuredMessage, options?: BroadcastOptions): void {
|
|
340
|
-
// Log the message and options for testing
|
|
341
|
-
console.log("GameChannel");
|
|
342
|
-
// Call the parent implementation
|
|
343
|
-
super.broadcast(message, options);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
class GameWebsocket extends app.Websocket {
|
|
348
|
-
constructor() {
|
|
349
|
-
super({
|
|
350
|
-
channelClass: GameChannel,
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Create and configure the Websocket instance
|
|
356
|
-
const ws = GameWebsocket.GetInstance<GameWebsocket>({
|
|
357
|
-
channelClass: GameChannel,
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
ws.set(server);
|
|
361
|
-
|
|
362
|
-
// Create and test channel
|
|
363
|
-
const channel = ws.createChannel("game", "Game Channel");
|
|
364
|
-
expect(channel).toBeInstanceOf(GameChannel);
|
|
365
|
-
|
|
366
|
-
// Test broadcast
|
|
367
|
-
const spy = jest.spyOn(console, "log");
|
|
368
|
-
const message = { type: "test", content: { message: "test message" } };
|
|
369
|
-
const extraData = { param1: "param1", extra: { data: "data" } };
|
|
370
|
-
|
|
371
|
-
// Call broadcast with the new options-based API
|
|
372
|
-
channel.broadcast(message, { data: extraData, client: { id: "test", name: "Test Client" } });
|
|
373
|
-
|
|
374
|
-
// Verify console.log was called
|
|
375
|
-
expect(spy).toHaveBeenCalled();
|
|
376
|
-
|
|
377
|
-
// Verify server publish was called correctly
|
|
378
|
-
expect(mockPublish).toHaveBeenCalledWith(channel.id, expect.any(String));
|
|
379
|
-
|
|
380
|
-
// Verify the JSON structure
|
|
381
|
-
const lastCall = mockPublish.mock.calls[0];
|
|
382
|
-
const parsedJson = JSON.parse(lastCall[1]);
|
|
383
|
-
|
|
384
|
-
// Update expectations to match actual structure - we don't care about exact format
|
|
385
|
-
// as long as it contains the message
|
|
386
|
-
expect(parsedJson).toHaveProperty("type", message.type);
|
|
387
|
-
expect(parsedJson).toHaveProperty("channel", channel.id);
|
|
388
|
-
|
|
389
|
-
spy.mockRestore();
|
|
390
|
-
});
|
|
391
|
-
it("should make sure broadcast structured message is correct", () => {
|
|
392
|
-
const mockPublish = jest.fn();
|
|
393
|
-
const server = {
|
|
394
|
-
publish: mockPublish,
|
|
395
|
-
} as unknown as Server;
|
|
396
|
-
const ws = app.Websocket.GetInstance<app.Websocket>();
|
|
397
|
-
ws.set(server);
|
|
398
|
-
|
|
399
|
-
const channel = ws.createChannel("test", "Test Channel");
|
|
400
|
-
const message = { type: "test", content: { message: "test message" } };
|
|
401
|
-
channel.broadcast(message, { debug: true, client: { id: "test", name: "Test Client" } });
|
|
402
|
-
expect(mockPublish).toHaveBeenCalledWith(channel.id, expect.any(String));
|
|
403
|
-
});
|
|
404
261
|
});
|
package/src/index.ts
CHANGED
|
@@ -5,110 +5,29 @@
|
|
|
5
5
|
export * from "./errors";
|
|
6
6
|
export * from "./singleton";
|
|
7
7
|
export * from "./initializable";
|
|
8
|
-
export * from "./application";
|
|
9
8
|
export * from "./consts";
|
|
10
9
|
export * from "./types";
|
|
10
|
+
export * from "./websocket.shared.types";
|
|
11
11
|
export * from "./throwable";
|
|
12
12
|
export * from "./enums";
|
|
13
|
-
export * from "./client/api/base.api";
|
|
14
|
-
export * from "./client/rxjs/useRxjs";
|
|
15
|
-
export * from "./client/vite/plugins/topsydeUtilsVitePlugin";
|
|
16
|
-
export * from "./external/re-exports";
|
|
17
|
-
export * from "./server/controller";
|
|
18
|
-
export * from "./server/service";
|
|
19
|
-
export * from "./server/base/base.database";
|
|
20
|
-
export * from "./server/bun/router/controller-discovery";
|
|
21
|
-
export * from "./server/bun/router/routes";
|
|
22
|
-
export * from "./server/bun/router/router";
|
|
23
|
-
export * from "./server/bun/router/router.internal";
|
|
24
|
-
export * from "./server/bun/websocket/Websocket";
|
|
25
|
-
export * from "./server/bun/websocket/websocket.guards";
|
|
26
|
-
export * from "./server/bun/websocket/Message";
|
|
27
|
-
export * from "./server/bun/websocket/Channel";
|
|
28
|
-
export * from "./server/bun/websocket/Client";
|
|
29
|
-
export * from "./server/bun/websocket/websocket.enums";
|
|
30
|
-
export * from "./server/bun/websocket/websocket.types";
|
|
31
13
|
export * from "./utils/Rxjs";
|
|
32
14
|
export * from "./utils/Lib";
|
|
33
15
|
export * from "./utils/Guards";
|
|
34
|
-
export * from "./utils/BaseEntity";
|
|
35
16
|
export * from "./utils/Console";
|
|
36
|
-
export * from "./utils/BaseDto";
|
|
37
|
-
export * from "./utils/dto_validators/IsNumberOrRangeConstraint";
|
|
38
17
|
|
|
39
18
|
// Export default classes
|
|
40
19
|
export { default as Singleton } from "./singleton";
|
|
41
20
|
export { default as Initializable } from "./initializable";
|
|
42
|
-
export { default as Application } from "./application";
|
|
43
21
|
export { default as Throwable } from "./throwable";
|
|
44
|
-
export { default as BaseAPI } from "./client/api/base.api";
|
|
45
|
-
export { default as TopsydeUtilsVitePlugin } from "./client/vite/plugins/topsydeUtilsVitePlugin";
|
|
46
|
-
export { default as Controller } from "./server/controller";
|
|
47
|
-
export { default as Service } from "./server/service";
|
|
48
|
-
export { default as Database } from "./server/base/base.database";
|
|
49
|
-
export { default as Router } from "./server/bun/router/router";
|
|
50
|
-
export { default as Router_Internal } from "./server/bun/router/router.internal";
|
|
51
|
-
export { default as Websocket } from "./server/bun/websocket/Websocket";
|
|
52
|
-
export { default as Message } from "./server/bun/websocket/Message";
|
|
53
|
-
export { default as Channel } from "./server/bun/websocket/Channel";
|
|
54
|
-
export { default as Client } from "./server/bun/websocket/Client";
|
|
55
22
|
export { default as Lib } from "./utils/Lib";
|
|
56
23
|
export { default as Guards } from "./utils/Guards";
|
|
57
|
-
export { default as BaseEntity } from "./utils/BaseEntity";
|
|
58
24
|
export { default as Console } from "./utils/Console";
|
|
59
25
|
|
|
60
26
|
// Re-export specific items for backward compatibility
|
|
61
27
|
export { ERROR_CODE, HTTP_ERROR_CODE, WS_ERROR_CODE } from "./errors";
|
|
62
28
|
export { InitializableOptions, InitializableEvent } from "./initializable";
|
|
63
|
-
export { RESPONSE_INIT, HEADERS_INIT, RESPONSE_METHOD_OPTIONS } from "./application";
|
|
64
29
|
export { DEFAULT_FALSE_RESPONSE, LOG_COLORS, LOG_ICONS } from "./consts";
|
|
65
30
|
export { ClassConstructor, NonNullableType, ObjectKeys, KVObj, I_ApplicationResponse } from "./types";
|
|
31
|
+
export { WebsocketEntityId, WebsocketEntityName, WebsocketEntityData, WebsocketMessage, WebsocketStructuredMessage } from "./websocket.shared.types";
|
|
66
32
|
export { E_IS, E_ENVIRONMENTS } from "./enums";
|
|
67
|
-
export { RxjsDataType, NamespaceActions, MultiNamespaceActions } from "./client/rxjs/useRxjs";
|
|
68
|
-
export {
|
|
69
|
-
Expose,
|
|
70
|
-
ValidationError,
|
|
71
|
-
IsArray,
|
|
72
|
-
IsBoolean,
|
|
73
|
-
IsDate,
|
|
74
|
-
IsEnum,
|
|
75
|
-
IsNumber,
|
|
76
|
-
IsObject,
|
|
77
|
-
IsOptional,
|
|
78
|
-
IsString,
|
|
79
|
-
Validate,
|
|
80
|
-
IsAlphanumeric,
|
|
81
|
-
IsBooleanString,
|
|
82
|
-
IsDateString,
|
|
83
|
-
IsDecimal,
|
|
84
|
-
IsDefined,
|
|
85
|
-
IsNumberString,
|
|
86
|
-
IsNotEmpty,
|
|
87
|
-
IsNotEmptyObject,
|
|
88
|
-
} from "./external/re-exports";
|
|
89
|
-
export { ControllerResponse, ControllerAction, ControllerMap, ControllerOptions } from "./server/controller";
|
|
90
|
-
export { Routes } from "./server/bun/router/routes";
|
|
91
|
-
export { WebsocketConstructorOptions, I_WebsocketConstructor } from "./server/bun/websocket/Websocket";
|
|
92
|
-
export { E_WebsocketMessageType, E_WebsocketMessagePriority, E_ClientState } from "./server/bun/websocket/websocket.enums";
|
|
93
|
-
export {
|
|
94
|
-
BunWebsocketMessage,
|
|
95
|
-
WebsocketChannel,
|
|
96
|
-
WebsocketClients,
|
|
97
|
-
WebsocketMessageOptions,
|
|
98
|
-
WebsocketMessage,
|
|
99
|
-
WebsocketStructuredMessage,
|
|
100
|
-
WebsocketEntityId,
|
|
101
|
-
WebsocketEntityName,
|
|
102
|
-
WebsocketEntityData,
|
|
103
|
-
I_WebsocketEntity,
|
|
104
|
-
I_WebsocketClient,
|
|
105
|
-
I_WebsocketChannelEntity,
|
|
106
|
-
BroadcastOptions,
|
|
107
|
-
AddMemberResult,
|
|
108
|
-
AddMemberOptions,
|
|
109
|
-
RemoveMemberOptions,
|
|
110
|
-
I_WebsocketChannel,
|
|
111
|
-
WebsocketInterfaceHandlers,
|
|
112
|
-
I_WebsocketInterface,
|
|
113
|
-
} from "./server/bun/websocket/websocket.types";
|
|
114
33
|
export { E_SUBJET_TYPE, I_RxjsPayload, RxjsNamespaces, AsyncSubject, BehaviorSubject, ReplaySubject, Subject, Subscription } from "./utils/Rxjs";
|
package/src/utils/Lib.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
1
|
import { E_IS } from "../enums";
|
|
4
2
|
import Throwable from "../throwable";
|
|
5
3
|
|
|
@@ -328,63 +326,10 @@ class Lib {
|
|
|
328
326
|
}
|
|
329
327
|
}
|
|
330
328
|
|
|
331
|
-
public static GetProjectRoot(startDir: string = __dirname, rootReference = "package.json"): string {
|
|
332
|
-
let currentDir = startDir;
|
|
333
|
-
|
|
334
|
-
while (!fs.existsSync(path.join(currentDir, rootReference))) {
|
|
335
|
-
const parentDir = path.resolve(currentDir, "..");
|
|
336
|
-
if (parentDir === currentDir) {
|
|
337
|
-
throw new Error("Unable to find project root");
|
|
338
|
-
}
|
|
339
|
-
currentDir = parentDir;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
return currentDir;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
329
|
public static async RunTaskWithTimeout(task: () => Promise<void>, timeout: number) {
|
|
346
330
|
return Promise.race([task(), new Promise((_, reject) => setTimeout(() => reject(new Error("Task timed out")), timeout))]);
|
|
347
331
|
}
|
|
348
332
|
|
|
349
|
-
public static GetFolderPath(folder: string): string {
|
|
350
|
-
return path.join(this.GetProjectRoot(), folder);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
public static GetFilePath(folder: string, file: string): string {
|
|
354
|
-
return path.join(this.GetFolderPath(folder), file);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
public static async CreateDirectory(folderToCreate: string) {
|
|
358
|
-
const directoryPath = Lib.GetFolderPath(folderToCreate);
|
|
359
|
-
await fs.promises.access(directoryPath, fs.constants.F_OK).catch(async () => {
|
|
360
|
-
await fs.promises.mkdir(directoryPath, { recursive: true });
|
|
361
|
-
});
|
|
362
|
-
return directoryPath;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
public static async DeleteDirectory(folderToDelete: string) {
|
|
366
|
-
const directoryPath = path.join(this.GetProjectRoot(), folderToDelete);
|
|
367
|
-
await fs.promises.rm(directoryPath, { recursive: true, force: true });
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
public static async CreateFile(folderPath: string, filePath: string, content: string) {
|
|
371
|
-
await Lib.CreateDirectory(folderPath);
|
|
372
|
-
const file = Lib.GetFilePath(folderPath, filePath);
|
|
373
|
-
await fs.promises.writeFile(file, content, "utf8");
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
public static GetFile(filePathFromRoot: string) {
|
|
377
|
-
return fs.createReadStream(filePathFromRoot);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
public static GetFilesInDirectory(directoryPath: string): string[] {
|
|
381
|
-
return fs.readdirSync(directoryPath);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
public static async DeleteFile(filePathFromRoot: string) {
|
|
385
|
-
await fs.promises.unlink(filePathFromRoot);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
333
|
public static Timestamp(log = false) {
|
|
389
334
|
const currentTime = new Date().toLocaleTimeString();
|
|
390
335
|
if (log) console.log(`[${currentTime}]`);
|
|
@@ -455,10 +400,6 @@ class Lib {
|
|
|
455
400
|
return x.filter((x) => !y.includes(x));
|
|
456
401
|
}
|
|
457
402
|
|
|
458
|
-
public static async ReadFileContent(filePath: string): Promise<string> {
|
|
459
|
-
return fs.promises.readFile(filePath, "utf8");
|
|
460
|
-
}
|
|
461
|
-
|
|
462
403
|
public static async measureExecutionTime<T extends (...args: any[]) => any, U extends ReturnType<T>>(
|
|
463
404
|
func: T,
|
|
464
405
|
...args: Parameters<T>
|
|
@@ -521,22 +462,4 @@ export class Debug {
|
|
|
521
462
|
Lib.LogObject(object, text);
|
|
522
463
|
}
|
|
523
464
|
|
|
524
|
-
public static GetLocalIpAddress(): string {
|
|
525
|
-
try {
|
|
526
|
-
const { networkInterfaces } = require("os");
|
|
527
|
-
const nets = networkInterfaces();
|
|
528
|
-
|
|
529
|
-
for (const name of Object.keys(nets)) {
|
|
530
|
-
for (const net of nets[name]) {
|
|
531
|
-
// Skip internal and non-IPv4 addresses
|
|
532
|
-
if (!net.internal && net.family === "IPv4") {
|
|
533
|
-
return net.address;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
return "127.0.0.1"; // Fallback to localhost
|
|
538
|
-
} catch (err) {
|
|
539
|
-
return "127.0.0.1"; // Fallback to localhost
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
465
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
export * from './Rxjs';
|
|
5
5
|
export * from './Lib';
|
|
6
6
|
export * from './Guards';
|
|
7
|
-
export * from './BaseEntity';
|
|
8
7
|
export * from './Console';
|
|
9
|
-
export * from './BaseDto';
|
|
10
8
|
export { default as Lib } from './Lib';
|
|
11
9
|
export { default as Guards } from './Guards';
|
|
12
|
-
export { default as BaseEntity } from './BaseEntity';
|
|
13
10
|
export { default as Console } from './Console';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type WebsocketEntityId = string;
|
|
2
|
+
export type WebsocketEntityName = string;
|
|
3
|
+
export type WebsocketEntityData = { id: WebsocketEntityId; name: WebsocketEntityName };
|
|
4
|
+
|
|
5
|
+
export type WebsocketMessage<T extends Record<string, any> = Record<string, any>> = {
|
|
6
|
+
type: string;
|
|
7
|
+
content: T;
|
|
8
|
+
channel?: string;
|
|
9
|
+
timestamp?: string;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type WebsocketStructuredMessage<T extends Record<string, any> = Record<string, any>> = {
|
|
14
|
+
type: string;
|
|
15
|
+
content: T;
|
|
16
|
+
channel?: string;
|
|
17
|
+
timestamp?: string;
|
|
18
|
+
client?: WebsocketEntityData;
|
|
19
|
+
metadata?: Record<string, string>;
|
|
20
|
+
priority?: number;
|
|
21
|
+
expiresAt?: number;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function IsWebsocketStructuredMessage(message: any): message is WebsocketStructuredMessage {
|
|
26
|
+
return typeof message === "object" && message !== null && "type" in message && "content" in message;
|
|
27
|
+
}
|
package/dist/application.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { I_ApplicationResponse } from "./types";
|
|
2
|
-
export declare const RESPONSE_INIT: (status?: number, headers?: HeadersInit) => ResponseInit;
|
|
3
|
-
export declare const HEADERS_INIT: (headers?: HeadersInit) => HeadersInit;
|
|
4
|
-
export declare const RESPONSE_METHOD_OPTIONS: {
|
|
5
|
-
name: string;
|
|
6
|
-
value: string;
|
|
7
|
-
};
|
|
8
|
-
declare class Application {
|
|
9
|
-
static Response<T>(data: T | I_ApplicationResponse<T>, options?: {
|
|
10
|
-
after_action?: () => void | Promise<void>;
|
|
11
|
-
before_action?: () => void;
|
|
12
|
-
}, status?: number, headers?: HeadersInit): Response;
|
|
13
|
-
private static AfterAction;
|
|
14
|
-
private static BeforeAction;
|
|
15
|
-
static Error<T extends BodyInit | unknown | Error>(error: T | I_ApplicationResponse<T>, status?: number, headers?: HeadersInit): Response;
|
|
16
|
-
static Throw<T extends BodyInit | unknown | Error>(error: T | I_ApplicationResponse<T>, status?: number, headers?: HeadersInit): Response;
|
|
17
|
-
}
|
|
18
|
-
export default Application;
|
package/dist/application.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export const RESPONSE_INIT = (status, headers) => {
|
|
2
|
-
return {
|
|
3
|
-
status: status ?? 200,
|
|
4
|
-
headers: HEADERS_INIT(headers),
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
export const HEADERS_INIT = (headers) => {
|
|
8
|
-
return {
|
|
9
|
-
"Access-Control-Allow-Origin": "*", // Specific origin
|
|
10
|
-
"Content-Type": "application/json",
|
|
11
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, DELETE",
|
|
12
|
-
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With, Origin, Accept",
|
|
13
|
-
"Access-Control-Allow-Credentials": "true",
|
|
14
|
-
"Access-Control-Max-Age": "86400", // 24 hours
|
|
15
|
-
...headers,
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export const RESPONSE_METHOD_OPTIONS = {
|
|
19
|
-
name: "Access-Control-Max-Age",
|
|
20
|
-
value: "86400",
|
|
21
|
-
};
|
|
22
|
-
function isApplicationResponse(data) {
|
|
23
|
-
return typeof data === "object" && data !== null && "status" in data;
|
|
24
|
-
}
|
|
25
|
-
class Application {
|
|
26
|
-
static Response(data, options, status = 200, headers) {
|
|
27
|
-
const { after_action, before_action } = options || {};
|
|
28
|
-
Application.BeforeAction(before_action);
|
|
29
|
-
const response = isApplicationResponse(data) ? data : { status: true, data };
|
|
30
|
-
const output = Response.json(response, RESPONSE_INIT(status, headers));
|
|
31
|
-
Application.AfterAction(after_action);
|
|
32
|
-
return output;
|
|
33
|
-
}
|
|
34
|
-
static AfterAction(after_action) {
|
|
35
|
-
if (after_action) {
|
|
36
|
-
queueMicrotask(async () => {
|
|
37
|
-
try {
|
|
38
|
-
await after_action();
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error("[Application] After-action error:", error);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
static BeforeAction(before_action) {
|
|
47
|
-
if (before_action)
|
|
48
|
-
before_action();
|
|
49
|
-
}
|
|
50
|
-
static Error(error, status = 200, headers) {
|
|
51
|
-
const response = isApplicationResponse(error) ? error : { status: false, data: error, error };
|
|
52
|
-
return Response.json(response, RESPONSE_INIT(status, headers));
|
|
53
|
-
}
|
|
54
|
-
static Throw(error, status = 400, headers) {
|
|
55
|
-
const response = isApplicationResponse(error) ? error : { status: false, data: error, error };
|
|
56
|
-
return Response.json(response, RESPONSE_INIT(status, headers));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export default Application;
|
|
60
|
-
//# sourceMappingURL=application.js.map
|
package/dist/application.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"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","sourcesContent":["import { I_ApplicationResponse } from \"./types\";\n\nexport const RESPONSE_INIT = (status?: number, headers?: HeadersInit): ResponseInit => {\n\treturn {\n\t\tstatus: status ?? 200,\n\t\theaders: HEADERS_INIT(headers),\n\t};\n};\n\nexport const HEADERS_INIT = (headers?: HeadersInit): HeadersInit => {\n\treturn {\n\t\t\"Access-Control-Allow-Origin\": \"*\", // Specific origin\n\t\t\"Content-Type\": \"application/json\",\n\t\t\"Access-Control-Allow-Methods\": \"GET, POST, OPTIONS, PUT, DELETE\",\n\t\t\"Access-Control-Allow-Headers\": \"Content-Type, Authorization, X-Requested-With, Origin, Accept\",\n\t\t\"Access-Control-Allow-Credentials\": \"true\",\n\t\t\"Access-Control-Max-Age\": \"86400\", // 24 hours\n\t\t...headers,\n\t};\n};\n\nexport const RESPONSE_METHOD_OPTIONS = {\n\tname: \"Access-Control-Max-Age\",\n\tvalue: \"86400\",\n};\n\nfunction isApplicationResponse<T>(data: T | I_ApplicationResponse<T>): data is I_ApplicationResponse<T> {\n\treturn typeof data === \"object\" && data !== null && \"status\" in data;\n}\n\nclass Application {\n\tpublic static Response<T>(\n\t\tdata: T | I_ApplicationResponse<T>,\n\t\toptions?: { after_action?: () => void | Promise<void>; before_action?: () => void },\n\t\tstatus = 200,\n\t\theaders?: HeadersInit,\n\t): Response {\n\t\tconst { after_action, before_action } = options || {};\n\t\tApplication.BeforeAction(before_action);\n\t\tconst response = isApplicationResponse(data) ? data : { status: true, data };\n\t\tconst output = Response.json(response, RESPONSE_INIT(status, headers));\n\t\tApplication.AfterAction(after_action);\n\t\treturn output;\n\t}\n\n\tprivate static AfterAction(after_action?: () => void | Promise<void>) {\n\t\tif (after_action) {\n\t\t\tqueueMicrotask(async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait after_action();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(\"[Application] After-action error:\", error);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate static BeforeAction(before_action?: () => void) {\n\t\tif (before_action) before_action();\n\t}\n\n\tpublic static Error<T extends BodyInit | unknown | Error>(error: T | I_ApplicationResponse<T>, status = 200, headers?: HeadersInit): Response {\n\t\tconst response = isApplicationResponse(error) ? error : { status: false, data: error, error };\n\t\treturn Response.json(response, RESPONSE_INIT(status, headers));\n\t}\n\n\tpublic static Throw<T extends BodyInit | unknown | Error>(error: T | I_ApplicationResponse<T>, status = 400, headers?: HeadersInit): Response {\n\t\tconst response = isApplicationResponse(error) ? error : { status: false, data: error, error };\n\t\treturn Response.json(response, RESPONSE_INIT(status, headers));\n\t}\n}\n\nexport default Application;\n"]}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse } from "axios";
|
|
2
|
-
declare class BaseAPI {
|
|
3
|
-
private api;
|
|
4
|
-
protected controller: string;
|
|
5
|
-
protected base_url: string;
|
|
6
|
-
constructor(controller: string, base_url?: string);
|
|
7
|
-
private initAxios;
|
|
8
|
-
static Status(response: AxiosResponse<{
|
|
9
|
-
status: boolean;
|
|
10
|
-
}>): void;
|
|
11
|
-
/**
|
|
12
|
-
* @description Axios GET request wrapper
|
|
13
|
-
* @param endpoint string
|
|
14
|
-
* @generic T
|
|
15
|
-
* @returns Promise<AxiosResponse<T>>
|
|
16
|
-
*/
|
|
17
|
-
get<T extends {
|
|
18
|
-
status: boolean;
|
|
19
|
-
}>(endpoint: string): Promise<AxiosResponse<T>>;
|
|
20
|
-
/**
|
|
21
|
-
* @description Axios GET request wrapper
|
|
22
|
-
* @param controller string - which controller to use
|
|
23
|
-
* @param endpoint string - controller action to call
|
|
24
|
-
* @generic T
|
|
25
|
-
* @returns Promise<AxiosResponse<T>>
|
|
26
|
-
*/
|
|
27
|
-
get<T extends {
|
|
28
|
-
status: boolean;
|
|
29
|
-
}>(controller: string, endpoint: string): Promise<AxiosResponse<T>>;
|
|
30
|
-
/**
|
|
31
|
-
* @description Axios GET request wrapper
|
|
32
|
-
* @param controller string - which controller to use
|
|
33
|
-
* @param endpoint string - controller action to call
|
|
34
|
-
* @param debounceDelay number - debounce delay
|
|
35
|
-
* @generic T
|
|
36
|
-
* @returns Promise<AxiosResponse<T>>
|
|
37
|
-
*/
|
|
38
|
-
get<T extends {
|
|
39
|
-
status: boolean;
|
|
40
|
-
}>(controller: string, endpoint: string, debounceDelay?: number): Promise<AxiosResponse<T>>;
|
|
41
|
-
/**
|
|
42
|
-
* @description Axios POST request wrapper
|
|
43
|
-
* @param endpoint string - controller action to call
|
|
44
|
-
* @param payload any
|
|
45
|
-
* @generic T
|
|
46
|
-
* @returns Promise<AxiosResponse<T>>
|
|
47
|
-
*/
|
|
48
|
-
post<T extends {
|
|
49
|
-
status: boolean;
|
|
50
|
-
}>(endpoint: string, payload: any): Promise<AxiosResponse<T>>;
|
|
51
|
-
/**
|
|
52
|
-
* @description Axios POST request wrapper
|
|
53
|
-
* @param controller string - which controller to use
|
|
54
|
-
* @param endpoint string - controller action to call
|
|
55
|
-
* @param payload any
|
|
56
|
-
* @generic T
|
|
57
|
-
* @returns Promise<AxiosResponse<T>>
|
|
58
|
-
*/
|
|
59
|
-
post<T extends {
|
|
60
|
-
status: boolean;
|
|
61
|
-
}>(controller: string, endpoint: string, payload: any): Promise<AxiosResponse<T>>;
|
|
62
|
-
}
|
|
63
|
-
export default BaseAPI;
|