@asenajs/asena 0.3.3 → 0.5.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.
- package/README.md +165 -140
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/adapter/AsenaAdapter.d.ts +19 -3
- package/dist/lib/adapter/AsenaAdapter.js.map +1 -1
- package/dist/lib/adapter/AsenaWebsocketAdapter.d.ts +2 -2
- package/dist/lib/adapter/AsenaWebsocketAdapter.js.map +1 -1
- package/dist/lib/adapter/types/RouteParams.d.ts +3 -0
- package/dist/lib/adapter/types/ServeOptions.d.ts +2 -2
- package/dist/lib/adapter/types/index.d.ts +4 -4
- package/dist/lib/adapter/types/index.js +4 -4
- package/dist/lib/adapter/types/index.js.map +1 -1
- package/dist/lib/ioc/CircularDependencyDetector.d.ts +49 -0
- package/dist/lib/ioc/CircularDependencyDetector.js +69 -0
- package/dist/lib/ioc/CircularDependencyDetector.js.map +1 -0
- package/dist/lib/ioc/Container.d.ts +16 -0
- package/dist/lib/ioc/Container.js +61 -11
- package/dist/lib/ioc/Container.js.map +1 -1
- package/dist/lib/ioc/CoreContainer.d.ts +78 -0
- package/dist/lib/ioc/CoreContainer.js +139 -0
- package/dist/lib/ioc/CoreContainer.js.map +1 -0
- package/dist/lib/ioc/IocEngine.d.ts +16 -6
- package/dist/lib/ioc/IocEngine.js +35 -7
- package/dist/lib/ioc/IocEngine.js.map +1 -1
- package/dist/lib/ioc/component/decorators/Inject.d.ts +24 -4
- package/dist/lib/ioc/component/decorators/Inject.js +44 -7
- package/dist/lib/ioc/component/decorators/Inject.js.map +1 -1
- package/dist/lib/ioc/component/index.d.ts +1 -1
- package/dist/lib/ioc/component/index.js +1 -1
- package/dist/lib/ioc/component/index.js.map +1 -1
- package/dist/lib/ioc/constants/ComponentConstants.d.ts +27 -18
- package/dist/lib/ioc/constants/ComponentConstants.js +34 -20
- package/dist/lib/ioc/constants/ComponentConstants.js.map +1 -1
- package/dist/lib/ioc/decorators/CoreService.d.ts +8 -0
- package/dist/lib/ioc/decorators/CoreService.js +27 -0
- package/dist/lib/ioc/decorators/CoreService.js.map +1 -0
- package/dist/lib/ioc/decorators/index.d.ts +1 -0
- package/dist/lib/ioc/decorators/index.js +2 -0
- package/dist/lib/ioc/decorators/index.js.map +1 -0
- package/dist/lib/ioc/index.d.ts +5 -0
- package/dist/lib/ioc/index.js +5 -0
- package/dist/lib/ioc/index.js.map +1 -1
- package/dist/lib/ioc/types/CoreBootstrapPhase.d.ts +15 -0
- package/dist/lib/ioc/types/CoreBootstrapPhase.js +17 -0
- package/dist/lib/ioc/types/CoreBootstrapPhase.js.map +1 -0
- package/dist/lib/ioc/types/ICoreService.d.ts +9 -0
- package/dist/lib/ioc/types/ICoreService.js +2 -0
- package/dist/lib/ioc/types/ICoreService.js.map +1 -0
- package/dist/lib/ioc/types/ICoreServiceNamesType.d.ts +19 -0
- package/dist/lib/ioc/types/ICoreServiceNamesType.js +25 -0
- package/dist/lib/ioc/types/ICoreServiceNamesType.js.map +1 -0
- package/dist/lib/ioc/types/decorators/ControllerParams.d.ts +1 -1
- package/dist/lib/ioc/types/index.d.ts +3 -0
- package/dist/lib/ioc/types/index.js +3 -0
- package/dist/lib/ioc/types/index.js.map +1 -1
- package/dist/lib/server/AsenaServer.d.ts +85 -14
- package/dist/lib/server/AsenaServer.js +176 -68
- package/dist/lib/server/AsenaServer.js.map +1 -1
- package/dist/lib/server/AsenaServerFactory.d.ts +26 -0
- package/dist/lib/server/AsenaServerFactory.js +66 -0
- package/dist/lib/server/AsenaServerFactory.js.map +1 -0
- package/dist/lib/server/config/AsenaConfig.d.ts +91 -18
- package/dist/lib/server/decorators/Override.js +1 -1
- package/dist/lib/server/decorators/Override.js.map +1 -1
- package/dist/lib/server/decorators/components/Config.d.ts +1 -1
- package/dist/lib/server/decorators/components/Config.js +1 -1
- package/dist/lib/server/decorators/components/Config.js.map +1 -1
- package/dist/lib/server/decorators/components/Controller.d.ts +1 -1
- package/dist/lib/server/decorators/components/Controller.js +1 -2
- package/dist/lib/server/decorators/components/Controller.js.map +1 -1
- package/dist/lib/server/decorators/components/Middleware.js +1 -2
- package/dist/lib/server/decorators/components/Middleware.js.map +1 -1
- package/dist/lib/server/decorators/components/Schedule.d.ts +1 -1
- package/dist/lib/server/decorators/components/Schedule.js +1 -2
- package/dist/lib/server/decorators/components/Schedule.js.map +1 -1
- package/dist/lib/server/decorators/components/WebSocket.d.ts +1 -1
- package/dist/lib/server/decorators/components/WebSocket.js +1 -2
- package/dist/lib/server/decorators/components/WebSocket.js.map +1 -1
- package/dist/lib/server/decorators/index.d.ts +2 -0
- package/dist/lib/server/decorators/index.js +2 -0
- package/dist/lib/server/decorators/index.js.map +1 -1
- package/dist/lib/server/index.d.ts +3 -0
- package/dist/lib/server/index.js +4 -0
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/server/messaging/Ulak.d.ts +224 -0
- package/dist/lib/server/messaging/Ulak.js +351 -0
- package/dist/lib/server/messaging/Ulak.js.map +1 -0
- package/dist/lib/server/messaging/index.d.ts +8 -0
- package/dist/lib/server/messaging/index.js +9 -0
- package/dist/lib/server/messaging/index.js.map +1 -0
- package/dist/lib/server/messaging/types.d.ts +73 -0
- package/dist/lib/server/messaging/types.js +35 -0
- package/dist/lib/server/messaging/types.js.map +1 -0
- package/dist/lib/server/src/services/PrepareConfigService.d.ts +9 -5
- package/dist/lib/server/src/services/PrepareConfigService.js +32 -7
- package/dist/lib/server/src/services/PrepareConfigService.js.map +1 -1
- package/dist/lib/server/src/services/PrepareMiddlewareService.d.ts +8 -5
- package/dist/lib/server/src/services/PrepareMiddlewareService.js +27 -7
- package/dist/lib/server/src/services/PrepareMiddlewareService.js.map +1 -1
- package/dist/lib/server/src/services/PrepareStaticServeConfigService.d.ts +8 -5
- package/dist/lib/server/src/services/PrepareStaticServeConfigService.js +27 -6
- package/dist/lib/server/src/services/PrepareStaticServeConfigService.js.map +1 -1
- package/dist/lib/server/src/services/PrepareValidatorService.d.ts +8 -5
- package/dist/lib/server/src/services/PrepareValidatorService.js +27 -6
- package/dist/lib/server/src/services/PrepareValidatorService.js.map +1 -1
- package/dist/lib/server/src/services/PrepareWebsocketService.d.ts +9 -5
- package/dist/lib/server/src/services/PrepareWebsocketService.js +35 -9
- package/dist/lib/server/src/services/PrepareWebsocketService.js.map +1 -1
- package/dist/lib/server/web/decorators/http.base.d.ts +1 -1
- package/dist/lib/server/web/decorators/http.base.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Connect.d.ts +1 -1
- package/dist/lib/server/web/decorators/methods/Delete.d.ts +1 -1
- package/dist/lib/server/web/decorators/methods/Get.d.ts +1 -1
- package/dist/lib/server/web/decorators/methods/Head.d.ts +1 -1
- package/dist/lib/server/web/decorators/methods/Options.d.ts +1 -1
- package/dist/lib/server/web/decorators/methods/Patch.d.ts +1 -1
- package/dist/lib/server/web/decorators/methods/Post.d.ts +1 -1
- package/dist/lib/server/web/decorators/methods/Put.d.ts +1 -1
- package/dist/lib/server/web/decorators/methods/Trace.d.ts +1 -1
- package/dist/lib/server/web/websocket/AsenaSocket.js.map +1 -1
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.d.ts +3 -16
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.js +3 -20
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.js.map +1 -1
- package/dist/lib/server/web/websocket/index.d.ts +1 -1
- package/dist/lib/server/web/websocket/index.js +1 -1
- package/dist/lib/server/web/websocket/index.js.map +1 -1
- package/dist/lib/utils/patternMatcher.d.ts +41 -0
- package/dist/lib/utils/patternMatcher.js +99 -0
- package/dist/lib/utils/patternMatcher.js.map +1 -0
- package/dist/lib/utils/typedMetadata.d.ts +3 -3
- package/dist/lib/utils/typedMetadata.js.map +1 -1
- package/package.json +19 -8
- package/dist/lib/server/src/PrepareService.d.ts +0 -8
- package/dist/lib/server/src/PrepareService.js +0 -9
- package/dist/lib/server/src/PrepareService.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Controller.js","sourceRoot":"","sources":["../../../../../lib/server/decorators/components/Controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,
|
|
1
|
+
{"version":3,"file":"Controller.js","sourceRoot":"","sources":["../../../../../lib/server/decorators/components/Controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAyB,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAInE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAkC,EAAkB,EAAE;IAC/E,MAAM,OAAO,GACX,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAE3G,OAAO,eAAe,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;QACnE,mBAAmB,CACjB,kBAAkB,CAAC,OAAO,EACzB,OAA4B,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,GAAG,EAC9D,MAAM,CACP,CAAC;QAEF,gBAAgB,CAAC,MAAM,EAAG,OAA4B,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;QAE1E,mBAAmB,CACjB,kBAAkB,CAAC,cAAc,EAChC,OAA4B,CAAC,WAAW,IAAK,EAAwB,EACtE,MAAM,CACP,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { defineComponent } from '../../../ioc/component';
|
|
2
|
-
import { ComponentType } from '../../../ioc
|
|
3
|
-
import { ComponentConstants } from '../../../ioc/constants';
|
|
2
|
+
import { ComponentConstants, ComponentType } from '../../../ioc';
|
|
4
3
|
import { defineTypedMetadata } from '../../../utils/typedMetadata';
|
|
5
4
|
import { VALIDATOR_METHODS } from '../../../adapter';
|
|
6
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Middleware.js","sourceRoot":"","sources":["../../../../../lib/server/decorators/components/Middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Middleware.js","sourceRoot":"","sources":["../../../../../lib/server/decorators/components/Middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAyB,EAAkB,EAAE;IACtE,OAAO,eAAe,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;QAClE,mBAAmB,CAAU,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,IAAI,KAAK,EAAE,MAAM,CAAC,CAAC;QAElG,IAAI,MAAM,EAAE,SAAS,EAAE,CAAC;YACtB,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,CAAC;YAE9G,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACxB,OAAO,CAAC,KAAK,CACX,SAAS,MAAM,CAAC,IAAI,0DAA0D,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC9G,CAAC;gBACF,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,CAAC;QACH,CAAC;aAAM,IAAI,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACzD,OAAO,CAAC,KAAK,CAAC,SAAS,MAAM,CAAC,IAAI,mDAAmD,CAAC,CAAC;YACvF,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ComponentType } from '../../../ioc
|
|
1
|
+
import { ComponentConstants, ComponentType } from '../../../ioc';
|
|
2
2
|
import { defineComponent } from '../../../ioc/component';
|
|
3
3
|
import { parseCron } from '../../../ioc/helper/cronParser';
|
|
4
|
-
import { ComponentConstants } from '../../../ioc/constants';
|
|
5
4
|
import { defineTypedMetadata } from '../../../utils/typedMetadata';
|
|
6
5
|
/**
|
|
7
6
|
* @deprecated Not working right now.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schedule.js","sourceRoot":"","sources":["../../../../../lib/server/decorators/components/Schedule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,
|
|
1
|
+
{"version":3,"file":"Schedule.js","sourceRoot":"","sources":["../../../../../lib/server/decorators/components/Schedule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAuB,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAmB,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAsB,EAAkB,EAAE;IACjE,OAAO,eAAe,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;QAChE,MAAM,UAAU,GAAG,SAAS,CAAE,MAAyB,CAAC,IAAI,CAAC,CAAC;QAE9D,mBAAmB,CAAa,kBAAkB,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ComponentType } from '../../../ioc
|
|
1
|
+
import { ComponentConstants, ComponentType } from '../../../ioc';
|
|
2
2
|
import { defineComponent } from '../../../ioc/component';
|
|
3
|
-
import { ComponentConstants } from '../../../ioc/constants';
|
|
4
3
|
import { defineMiddleware } from '../../web/helper';
|
|
5
4
|
import { defineTypedMetadata } from '../../../utils/typedMetadata';
|
|
6
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocket.js","sourceRoot":"","sources":["../../../../../lib/server/decorators/components/WebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,
|
|
1
|
+
{"version":3,"file":"WebSocket.js","sourceRoot":"","sources":["../../../../../lib/server/decorators/components/WebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAyB,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAInE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAiC,EAAkB,EAAE;IAC7E,OAAO,eAAe,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;QACjE,IAAI,IAAI,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;QAE7D,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAC5C,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC;QAED,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAEhC,mBAAmB,CAAS,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAEtE,gBAAgB,CAAC,MAAM,EAAG,MAA2B,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;QAEzE,mBAAmB,CACjB,kBAAkB,CAAC,cAAc,EAChC,MAA2B,CAAC,WAAW,IAAI,EAAE,EAC9C,MAAM,CACP,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/server/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/server/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC"}
|
package/dist/lib/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAE3C,kCAAkC;AAClC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import type { AsenaWebSocketService } from '../web/websocket';
|
|
2
|
+
import { type ICoreService, ICoreServiceNames } from '../../ioc';
|
|
3
|
+
import { type BulkOperation, type BulkResult } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Central WebSocket message broker for Asena.js
|
|
6
|
+
*
|
|
7
|
+
* Ulak (Turkish: Messenger/Courier) provides a centralized way to send WebSocket messages
|
|
8
|
+
* without circular dependencies. Services can inject Ulak to send messages to any
|
|
9
|
+
* WebSocket namespace without directly injecting WebSocket services.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Service('UserService')
|
|
14
|
+
* class UserService {
|
|
15
|
+
* @Inject(ulak("/notifications"))
|
|
16
|
+
* private notifications: Ulak.NameSpace<"/notifications">;
|
|
17
|
+
*
|
|
18
|
+
* async createUser(data: any) {
|
|
19
|
+
* const user = await this.saveUser(data);
|
|
20
|
+
* await this.notifications.broadcast({ type: 'user_created', user });
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class Ulak implements ICoreService {
|
|
26
|
+
readonly serviceName: string;
|
|
27
|
+
/**
|
|
28
|
+
* Logger instance injected from CoreContainer
|
|
29
|
+
*/
|
|
30
|
+
private logger;
|
|
31
|
+
/**
|
|
32
|
+
* Map of namespace path to WebSocket service instance
|
|
33
|
+
*/
|
|
34
|
+
private namespaces;
|
|
35
|
+
/**
|
|
36
|
+
* Initialize Ulak messaging system
|
|
37
|
+
* Called after dependency injection is complete
|
|
38
|
+
*/
|
|
39
|
+
init(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Register a WebSocket namespace
|
|
42
|
+
* Called automatically during WebSocket service initialization
|
|
43
|
+
*
|
|
44
|
+
* @param path - The namespace path (e.g., "/notifications")
|
|
45
|
+
* @param service - The WebSocket service instance
|
|
46
|
+
*/
|
|
47
|
+
registerNamespace(path: string, service: AsenaWebSocketService<any>): void;
|
|
48
|
+
/**
|
|
49
|
+
* Unregister a WebSocket namespace
|
|
50
|
+
* Useful for cleanup and preventing memory leaks
|
|
51
|
+
*
|
|
52
|
+
* @param path - The namespace path to unregister
|
|
53
|
+
*/
|
|
54
|
+
unregisterNamespace(path: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Select a specific namespace for scoped operations
|
|
57
|
+
* Returns a scoped namespace interface for ergonomic API
|
|
58
|
+
*
|
|
59
|
+
* @param path - The namespace path
|
|
60
|
+
* @returns Scoped namespace instance
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const chat = ulak.namespace('/chat');
|
|
65
|
+
* await chat.broadcast({ message: 'Hello' }); // No need to repeat '/chat'
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
namespace<T extends string>(path: T): Ulak.NameSpace<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Broadcast message to all clients in a namespace
|
|
71
|
+
*
|
|
72
|
+
* @param namespace - The target namespace
|
|
73
|
+
* @param data - The data to send
|
|
74
|
+
* @throws {UlakError} If namespace not found or broadcast fails
|
|
75
|
+
*/
|
|
76
|
+
broadcast(namespace: string, data: any): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Send message to specific room in a namespace
|
|
79
|
+
*
|
|
80
|
+
* @param namespace - The target namespace
|
|
81
|
+
* @param room - The room name
|
|
82
|
+
* @param data - The data to send
|
|
83
|
+
* @throws {UlakError} If namespace not found or send fails
|
|
84
|
+
*/
|
|
85
|
+
to(namespace: string, room: string, data: any): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Send message to specific socket by ID
|
|
88
|
+
*
|
|
89
|
+
* @param namespace - The target namespace
|
|
90
|
+
* @param socketId - The socket ID
|
|
91
|
+
* @param data - The data to send
|
|
92
|
+
* @throws {UlakError} If namespace not found, socket not found, or send fails
|
|
93
|
+
*/
|
|
94
|
+
toSocket(namespace: string, socketId: string, data: any): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Send to multiple rooms at once (parallel execution)
|
|
97
|
+
*
|
|
98
|
+
* @param namespace - The target namespace
|
|
99
|
+
* @param rooms - Array of room names
|
|
100
|
+
* @param data - The data to send
|
|
101
|
+
*/
|
|
102
|
+
toMany(namespace: string, rooms: string[], data: any): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Broadcast to all registered namespaces
|
|
105
|
+
*
|
|
106
|
+
* @param data - The data to send
|
|
107
|
+
*/
|
|
108
|
+
broadcastAll(data: any): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Send different messages to different targets (bulk operation)
|
|
111
|
+
*
|
|
112
|
+
* @param operations - Array of operations to perform
|
|
113
|
+
* @returns Result summary
|
|
114
|
+
*/
|
|
115
|
+
bulkSend(operations: BulkOperation[]): Promise<BulkResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Get all active namespaces
|
|
118
|
+
*
|
|
119
|
+
* @returns Array of namespace paths
|
|
120
|
+
*/
|
|
121
|
+
getNamespaces(): string[];
|
|
122
|
+
/**
|
|
123
|
+
* Check if namespace exists
|
|
124
|
+
*
|
|
125
|
+
* @param namespace - The namespace to check
|
|
126
|
+
* @returns True if namespace is registered
|
|
127
|
+
*/
|
|
128
|
+
hasNamespace(namespace: string): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Get socket count for a namespace
|
|
131
|
+
*
|
|
132
|
+
* @param namespace - The namespace to query
|
|
133
|
+
* @returns Number of active sockets
|
|
134
|
+
*/
|
|
135
|
+
getSocketCount(namespace: string): number;
|
|
136
|
+
/**
|
|
137
|
+
* Dispose of all resources and stop background tasks
|
|
138
|
+
* Should be called during application shutdown
|
|
139
|
+
*/
|
|
140
|
+
dispose(): void;
|
|
141
|
+
/**
|
|
142
|
+
* Get namespace service or throw error
|
|
143
|
+
*
|
|
144
|
+
* @param namespace - The namespace to retrieve
|
|
145
|
+
* @returns The WebSocket service
|
|
146
|
+
* @throws {UlakError} If namespace not found
|
|
147
|
+
*/
|
|
148
|
+
private getNamespaceService;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Scoped namespace interface
|
|
152
|
+
* Provides ergonomic API without repeating namespace path
|
|
153
|
+
*/
|
|
154
|
+
export declare namespace Ulak {
|
|
155
|
+
interface NameSpace<T extends string = string> {
|
|
156
|
+
/**
|
|
157
|
+
* The namespace path
|
|
158
|
+
*/
|
|
159
|
+
readonly path: T;
|
|
160
|
+
/**
|
|
161
|
+
* Broadcast to all clients in this namespace
|
|
162
|
+
*
|
|
163
|
+
* @param data - The data to send
|
|
164
|
+
*/
|
|
165
|
+
broadcast(data: any): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Send to specific room in this namespace
|
|
168
|
+
*
|
|
169
|
+
* @param room - The room name
|
|
170
|
+
* @param data - The data to send
|
|
171
|
+
*/
|
|
172
|
+
to(room: string, data: any): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Send to specific socket by ID in this namespace
|
|
175
|
+
*
|
|
176
|
+
* @param socketId - The socket ID
|
|
177
|
+
* @param data - The data to send
|
|
178
|
+
*/
|
|
179
|
+
toSocket(socketId: string, data: any): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Send to multiple rooms at once
|
|
182
|
+
*
|
|
183
|
+
* @param rooms - Array of room names
|
|
184
|
+
* @param data - The data to send
|
|
185
|
+
*/
|
|
186
|
+
toMany(rooms: string[], data: any): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Get socket count for this namespace
|
|
189
|
+
*
|
|
190
|
+
* @returns Number of active sockets
|
|
191
|
+
*/
|
|
192
|
+
getSocketCount(): number;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Helper function for injecting scoped Ulak namespace
|
|
197
|
+
*
|
|
198
|
+
* This function returns a tuple that can be used with the @Inject decorator
|
|
199
|
+
* to inject a scoped namespace from Ulak. This provides an ergonomic API
|
|
200
|
+
* where you don't need to repeat the namespace path in every method call.
|
|
201
|
+
*
|
|
202
|
+
* @param namespace - The WebSocket namespace path (e.g., "/chat", "/notifications")
|
|
203
|
+
* @returns A tuple of [serviceName, expression] for @Inject decorator
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* @Service('ChatService')
|
|
208
|
+
* export class ChatService {
|
|
209
|
+
* // Inject scoped namespace
|
|
210
|
+
* @Inject(ulak("/chat"))
|
|
211
|
+
* private chat: Ulak.NameSpace<"/chat">;
|
|
212
|
+
*
|
|
213
|
+
* async sendMessage(roomId: string, message: string) {
|
|
214
|
+
* // Clean API - no need to repeat '/chat'
|
|
215
|
+
* await this.chat.to(roomId, { message });
|
|
216
|
+
* }
|
|
217
|
+
*
|
|
218
|
+
* async broadcastAnnouncement(text: string) {
|
|
219
|
+
* await this.chat.broadcast({ type: 'announcement', text });
|
|
220
|
+
* }
|
|
221
|
+
* }
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export declare function ulak<T extends string>(namespace: T): readonly [ICoreServiceNames.__ULAK__, (ulak: Ulak) => Ulak.NameSpace<T>];
|