@opra/nestjs-socketio 1.21.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/LICENSE +21 -0
- package/README.md +3 -0
- package/cjs/constants.js +4 -0
- package/cjs/index.js +10 -0
- package/cjs/opra-socketio-core.module.js +147 -0
- package/cjs/opra-socketio.module.js +33 -0
- package/cjs/package.json +3 -0
- package/esm/constants.js +1 -0
- package/esm/index.js +4 -0
- package/esm/opra-socketio-core.module.js +144 -0
- package/esm/opra-socketio.module.js +30 -0
- package/esm/package.json +3 -0
- package/package.json +65 -0
- package/types/constants.d.ts +1 -0
- package/types/index.d.cts +4 -0
- package/types/index.d.ts +4 -0
- package/types/opra-socketio-core.module.d.ts +18 -0
- package/types/opra-socketio.module.d.ts +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Panates
|
|
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
package/cjs/constants.js
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Public = exports.OpraNestUtils = exports.IS_PUBLIC_KEY = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const nestjs_1 = require("@opra/nestjs");
|
|
6
|
+
Object.defineProperty(exports, "IS_PUBLIC_KEY", { enumerable: true, get: function () { return nestjs_1.IS_PUBLIC_KEY; } });
|
|
7
|
+
Object.defineProperty(exports, "OpraNestUtils", { enumerable: true, get: function () { return nestjs_1.OpraNestUtils; } });
|
|
8
|
+
Object.defineProperty(exports, "Public", { enumerable: true, get: function () { return nestjs_1.Public; } });
|
|
9
|
+
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./opra-socketio.module.js"), exports);
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var OpraSocketioCoreModule_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OpraSocketioCoreModule = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const objects_1 = require("@jsopen/objects");
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const core_1 = require("@nestjs/core");
|
|
9
|
+
const common_2 = require("@opra/common");
|
|
10
|
+
const nestjs_1 = require("@opra/nestjs");
|
|
11
|
+
const socketio_1 = require("@opra/socketio");
|
|
12
|
+
const constants_js_1 = require("./constants.js");
|
|
13
|
+
const opraSocketioNestjsAdapterToken = Symbol('OpraSocketioNestjsAdapter');
|
|
14
|
+
let OpraSocketioCoreModule = OpraSocketioCoreModule_1 = class OpraSocketioCoreModule {
|
|
15
|
+
constructor(controllerFactory, adapter, config, httpAdapterHost) {
|
|
16
|
+
this.controllerFactory = controllerFactory;
|
|
17
|
+
this.adapter = adapter;
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.httpAdapterHost = httpAdapterHost;
|
|
20
|
+
}
|
|
21
|
+
static forRoot(moduleOptions) {
|
|
22
|
+
return this._getDynamicModule({
|
|
23
|
+
...moduleOptions,
|
|
24
|
+
providers: [
|
|
25
|
+
...(moduleOptions?.providers || []),
|
|
26
|
+
{
|
|
27
|
+
provide: constants_js_1.OPRA_SOCKETIO_MODULE_OPTIONS,
|
|
28
|
+
useValue: {
|
|
29
|
+
...moduleOptions,
|
|
30
|
+
logger: moduleOptions.logger || new common_1.Logger(moduleOptions.name),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
static forRootAsync(moduleOptions) {
|
|
37
|
+
if (!moduleOptions.useFactory)
|
|
38
|
+
throw new Error('Invalid configuration. Must provide "useFactory"');
|
|
39
|
+
return this._getDynamicModule({
|
|
40
|
+
...moduleOptions,
|
|
41
|
+
providers: [
|
|
42
|
+
...(moduleOptions?.providers || []),
|
|
43
|
+
{
|
|
44
|
+
provide: constants_js_1.OPRA_SOCKETIO_MODULE_OPTIONS,
|
|
45
|
+
inject: moduleOptions.inject,
|
|
46
|
+
useFactory: async (...args) => {
|
|
47
|
+
const result = await moduleOptions.useFactory(...args);
|
|
48
|
+
result.logger = result.logger || new common_1.Logger(result.name);
|
|
49
|
+
return result;
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
static _getDynamicModule(moduleOptions) {
|
|
56
|
+
const token = moduleOptions.token || socketio_1.SocketioAdapter;
|
|
57
|
+
const adapterProvider = {
|
|
58
|
+
provide: token,
|
|
59
|
+
inject: [nestjs_1.WSControllerFactory, core_1.ModuleRef, constants_js_1.OPRA_SOCKETIO_MODULE_OPTIONS],
|
|
60
|
+
useFactory: async (controllerFactory, moduleRef, config) => {
|
|
61
|
+
const controllers = controllerFactory
|
|
62
|
+
.exploreControllers()
|
|
63
|
+
.map(x => x.wrapper.instance);
|
|
64
|
+
const document = await common_2.ApiDocumentFactory.createDocument({
|
|
65
|
+
info: config.info,
|
|
66
|
+
types: config.types,
|
|
67
|
+
references: config.references,
|
|
68
|
+
api: {
|
|
69
|
+
name: config.name,
|
|
70
|
+
description: config.description,
|
|
71
|
+
transport: 'ws',
|
|
72
|
+
platform: socketio_1.SocketioAdapter.PlatformName,
|
|
73
|
+
controllers,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const interceptors = moduleOptions.interceptors
|
|
77
|
+
? moduleOptions.interceptors.map(x => {
|
|
78
|
+
if ((0, objects_1.isConstructor)(x)) {
|
|
79
|
+
return async (ctx, next) => {
|
|
80
|
+
const interceptor = moduleRef.get(x);
|
|
81
|
+
if (typeof interceptor.intercept === 'function')
|
|
82
|
+
return interceptor.intercept(ctx, next);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return x;
|
|
86
|
+
})
|
|
87
|
+
: undefined;
|
|
88
|
+
return new socketio_1.SocketioAdapter(document, { ...config, interceptors });
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
global: moduleOptions.global,
|
|
93
|
+
module: OpraSocketioCoreModule_1,
|
|
94
|
+
controllers: moduleOptions.controllers,
|
|
95
|
+
providers: [
|
|
96
|
+
...(moduleOptions?.providers || []),
|
|
97
|
+
nestjs_1.WSControllerFactory,
|
|
98
|
+
adapterProvider,
|
|
99
|
+
{
|
|
100
|
+
provide: opraSocketioNestjsAdapterToken,
|
|
101
|
+
useExisting: token,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
imports: [...(moduleOptions?.imports || [])],
|
|
105
|
+
exports: [...(moduleOptions?.exports || []), adapterProvider],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
onModuleInit() {
|
|
109
|
+
/** NestJS initialize controller instances on init stage.
|
|
110
|
+
* So we should update instance properties */
|
|
111
|
+
const wsApi = this.adapter.document.getWsApi();
|
|
112
|
+
const controllers = Array.from(wsApi.controllers.values());
|
|
113
|
+
for (const { wrapper } of this.controllerFactory
|
|
114
|
+
.exploreControllers()
|
|
115
|
+
.values()) {
|
|
116
|
+
const ctor = wrapper.instance.constructor;
|
|
117
|
+
const controller = controllers.find(x => x.ctor === ctor);
|
|
118
|
+
if (controller) {
|
|
119
|
+
controller.instance = wrapper.instance;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async onApplicationBootstrap() {
|
|
124
|
+
const httpServer = this.httpAdapterHost.httpAdapter.getHttpServer();
|
|
125
|
+
if (this.config.port) {
|
|
126
|
+
const addr = httpServer.address();
|
|
127
|
+
const httpPort = addr && typeof addr === 'object' ? addr.port : 0;
|
|
128
|
+
if (httpPort !== this.config.port) {
|
|
129
|
+
this.adapter.listen(this.config.port, this.config.serverOptions);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.adapter.listen(httpServer, this.config.serverOptions);
|
|
134
|
+
}
|
|
135
|
+
async onApplicationShutdown() {
|
|
136
|
+
await this.adapter.close();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
exports.OpraSocketioCoreModule = OpraSocketioCoreModule;
|
|
140
|
+
exports.OpraSocketioCoreModule = OpraSocketioCoreModule = OpraSocketioCoreModule_1 = tslib_1.__decorate([
|
|
141
|
+
(0, common_1.Module)({}),
|
|
142
|
+
(0, common_1.Global)(),
|
|
143
|
+
tslib_1.__param(1, (0, common_1.Inject)(opraSocketioNestjsAdapterToken)),
|
|
144
|
+
tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_SOCKETIO_MODULE_OPTIONS)),
|
|
145
|
+
tslib_1.__metadata("design:paramtypes", [nestjs_1.WSControllerFactory,
|
|
146
|
+
socketio_1.SocketioAdapter, Object, core_1.HttpAdapterHost])
|
|
147
|
+
], OpraSocketioCoreModule);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var OpraSocketioModule_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OpraSocketioModule = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const opra_socketio_core_module_js_1 = require("./opra-socketio-core.module.js");
|
|
8
|
+
let OpraSocketioModule = OpraSocketioModule_1 = class OpraSocketioModule {
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param init
|
|
12
|
+
*/
|
|
13
|
+
static forRoot(init) {
|
|
14
|
+
return {
|
|
15
|
+
module: OpraSocketioModule_1,
|
|
16
|
+
imports: [opra_socketio_core_module_js_1.OpraSocketioCoreModule.forRoot(init)],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param options
|
|
22
|
+
*/
|
|
23
|
+
static forRootAsync(options) {
|
|
24
|
+
return {
|
|
25
|
+
module: OpraSocketioModule_1,
|
|
26
|
+
imports: [opra_socketio_core_module_js_1.OpraSocketioCoreModule.forRootAsync(options)],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.OpraSocketioModule = OpraSocketioModule;
|
|
31
|
+
exports.OpraSocketioModule = OpraSocketioModule = OpraSocketioModule_1 = tslib_1.__decorate([
|
|
32
|
+
(0, common_1.Module)({})
|
|
33
|
+
], OpraSocketioModule);
|
package/cjs/package.json
ADDED
package/esm/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const OPRA_SOCKETIO_MODULE_OPTIONS = 'OPRA_SOCKETIO_MODULE_OPTIONS';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var OpraSocketioCoreModule_1;
|
|
2
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
+
import { isConstructor } from '@jsopen/objects';
|
|
4
|
+
import { Global, Inject, Logger, Module, } from '@nestjs/common';
|
|
5
|
+
import { HttpAdapterHost, ModuleRef } from '@nestjs/core';
|
|
6
|
+
import { ApiDocumentFactory } from '@opra/common';
|
|
7
|
+
import { WSControllerFactory } from '@opra/nestjs';
|
|
8
|
+
import { SocketioAdapter } from '@opra/socketio';
|
|
9
|
+
import { OPRA_SOCKETIO_MODULE_OPTIONS } from './constants.js';
|
|
10
|
+
const opraSocketioNestjsAdapterToken = Symbol('OpraSocketioNestjsAdapter');
|
|
11
|
+
let OpraSocketioCoreModule = OpraSocketioCoreModule_1 = class OpraSocketioCoreModule {
|
|
12
|
+
constructor(controllerFactory, adapter, config, httpAdapterHost) {
|
|
13
|
+
this.controllerFactory = controllerFactory;
|
|
14
|
+
this.adapter = adapter;
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.httpAdapterHost = httpAdapterHost;
|
|
17
|
+
}
|
|
18
|
+
static forRoot(moduleOptions) {
|
|
19
|
+
return this._getDynamicModule({
|
|
20
|
+
...moduleOptions,
|
|
21
|
+
providers: [
|
|
22
|
+
...(moduleOptions?.providers || []),
|
|
23
|
+
{
|
|
24
|
+
provide: OPRA_SOCKETIO_MODULE_OPTIONS,
|
|
25
|
+
useValue: {
|
|
26
|
+
...moduleOptions,
|
|
27
|
+
logger: moduleOptions.logger || new Logger(moduleOptions.name),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
static forRootAsync(moduleOptions) {
|
|
34
|
+
if (!moduleOptions.useFactory)
|
|
35
|
+
throw new Error('Invalid configuration. Must provide "useFactory"');
|
|
36
|
+
return this._getDynamicModule({
|
|
37
|
+
...moduleOptions,
|
|
38
|
+
providers: [
|
|
39
|
+
...(moduleOptions?.providers || []),
|
|
40
|
+
{
|
|
41
|
+
provide: OPRA_SOCKETIO_MODULE_OPTIONS,
|
|
42
|
+
inject: moduleOptions.inject,
|
|
43
|
+
useFactory: async (...args) => {
|
|
44
|
+
const result = await moduleOptions.useFactory(...args);
|
|
45
|
+
result.logger = result.logger || new Logger(result.name);
|
|
46
|
+
return result;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
static _getDynamicModule(moduleOptions) {
|
|
53
|
+
const token = moduleOptions.token || SocketioAdapter;
|
|
54
|
+
const adapterProvider = {
|
|
55
|
+
provide: token,
|
|
56
|
+
inject: [WSControllerFactory, ModuleRef, OPRA_SOCKETIO_MODULE_OPTIONS],
|
|
57
|
+
useFactory: async (controllerFactory, moduleRef, config) => {
|
|
58
|
+
const controllers = controllerFactory
|
|
59
|
+
.exploreControllers()
|
|
60
|
+
.map(x => x.wrapper.instance);
|
|
61
|
+
const document = await ApiDocumentFactory.createDocument({
|
|
62
|
+
info: config.info,
|
|
63
|
+
types: config.types,
|
|
64
|
+
references: config.references,
|
|
65
|
+
api: {
|
|
66
|
+
name: config.name,
|
|
67
|
+
description: config.description,
|
|
68
|
+
transport: 'ws',
|
|
69
|
+
platform: SocketioAdapter.PlatformName,
|
|
70
|
+
controllers,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const interceptors = moduleOptions.interceptors
|
|
74
|
+
? moduleOptions.interceptors.map(x => {
|
|
75
|
+
if (isConstructor(x)) {
|
|
76
|
+
return async (ctx, next) => {
|
|
77
|
+
const interceptor = moduleRef.get(x);
|
|
78
|
+
if (typeof interceptor.intercept === 'function')
|
|
79
|
+
return interceptor.intercept(ctx, next);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return x;
|
|
83
|
+
})
|
|
84
|
+
: undefined;
|
|
85
|
+
return new SocketioAdapter(document, { ...config, interceptors });
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
global: moduleOptions.global,
|
|
90
|
+
module: OpraSocketioCoreModule_1,
|
|
91
|
+
controllers: moduleOptions.controllers,
|
|
92
|
+
providers: [
|
|
93
|
+
...(moduleOptions?.providers || []),
|
|
94
|
+
WSControllerFactory,
|
|
95
|
+
adapterProvider,
|
|
96
|
+
{
|
|
97
|
+
provide: opraSocketioNestjsAdapterToken,
|
|
98
|
+
useExisting: token,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
imports: [...(moduleOptions?.imports || [])],
|
|
102
|
+
exports: [...(moduleOptions?.exports || []), adapterProvider],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
onModuleInit() {
|
|
106
|
+
/** NestJS initialize controller instances on init stage.
|
|
107
|
+
* So we should update instance properties */
|
|
108
|
+
const wsApi = this.adapter.document.getWsApi();
|
|
109
|
+
const controllers = Array.from(wsApi.controllers.values());
|
|
110
|
+
for (const { wrapper } of this.controllerFactory
|
|
111
|
+
.exploreControllers()
|
|
112
|
+
.values()) {
|
|
113
|
+
const ctor = wrapper.instance.constructor;
|
|
114
|
+
const controller = controllers.find(x => x.ctor === ctor);
|
|
115
|
+
if (controller) {
|
|
116
|
+
controller.instance = wrapper.instance;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async onApplicationBootstrap() {
|
|
121
|
+
const httpServer = this.httpAdapterHost.httpAdapter.getHttpServer();
|
|
122
|
+
if (this.config.port) {
|
|
123
|
+
const addr = httpServer.address();
|
|
124
|
+
const httpPort = addr && typeof addr === 'object' ? addr.port : 0;
|
|
125
|
+
if (httpPort !== this.config.port) {
|
|
126
|
+
this.adapter.listen(this.config.port, this.config.serverOptions);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
this.adapter.listen(httpServer, this.config.serverOptions);
|
|
131
|
+
}
|
|
132
|
+
async onApplicationShutdown() {
|
|
133
|
+
await this.adapter.close();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
OpraSocketioCoreModule = OpraSocketioCoreModule_1 = __decorate([
|
|
137
|
+
Module({}),
|
|
138
|
+
Global(),
|
|
139
|
+
__param(1, Inject(opraSocketioNestjsAdapterToken)),
|
|
140
|
+
__param(2, Inject(OPRA_SOCKETIO_MODULE_OPTIONS)),
|
|
141
|
+
__metadata("design:paramtypes", [WSControllerFactory,
|
|
142
|
+
SocketioAdapter, Object, HttpAdapterHost])
|
|
143
|
+
], OpraSocketioCoreModule);
|
|
144
|
+
export { OpraSocketioCoreModule };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var OpraSocketioModule_1;
|
|
2
|
+
import { __decorate } from "tslib";
|
|
3
|
+
import { Module } from '@nestjs/common';
|
|
4
|
+
import { OpraSocketioCoreModule } from './opra-socketio-core.module.js';
|
|
5
|
+
let OpraSocketioModule = OpraSocketioModule_1 = class OpraSocketioModule {
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param init
|
|
9
|
+
*/
|
|
10
|
+
static forRoot(init) {
|
|
11
|
+
return {
|
|
12
|
+
module: OpraSocketioModule_1,
|
|
13
|
+
imports: [OpraSocketioCoreModule.forRoot(init)],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param options
|
|
19
|
+
*/
|
|
20
|
+
static forRootAsync(options) {
|
|
21
|
+
return {
|
|
22
|
+
module: OpraSocketioModule_1,
|
|
23
|
+
imports: [OpraSocketioCoreModule.forRootAsync(options)],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
OpraSocketioModule = OpraSocketioModule_1 = __decorate([
|
|
28
|
+
Module({})
|
|
29
|
+
], OpraSocketioModule);
|
|
30
|
+
export { OpraSocketioModule };
|
package/esm/package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opra/nestjs-socketio",
|
|
3
|
+
"version": "1.21.0",
|
|
4
|
+
"description": "Opra NestJS Socket.io Module",
|
|
5
|
+
"author": "Panates",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@jsopen/objects": "^2.0.2",
|
|
9
|
+
"tslib": "^2.8.1"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@opra/common": "^1.21.0",
|
|
13
|
+
"@opra/core": "^1.21.0",
|
|
14
|
+
"@opra/nestjs": "^1.21.0",
|
|
15
|
+
"@opra/socketio": "^1.21.0",
|
|
16
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
17
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
18
|
+
"socket.io": "^4.8.1"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./types/index.d.ts",
|
|
25
|
+
"default": "./esm/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./types/index.d.cts",
|
|
29
|
+
"default": "./cjs/index.js"
|
|
30
|
+
},
|
|
31
|
+
"default": "./esm/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"main": "./cjs/index.js",
|
|
36
|
+
"module": "./esm/index.js",
|
|
37
|
+
"types": "./types/index.d.ts",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/panates/opra.git",
|
|
41
|
+
"directory": "packages/nestjs-socketio"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=16.0",
|
|
45
|
+
"npm": ">=7.0.0"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"bin/",
|
|
49
|
+
"cjs/",
|
|
50
|
+
"esm/",
|
|
51
|
+
"types/",
|
|
52
|
+
"LICENSE",
|
|
53
|
+
"README.md"
|
|
54
|
+
],
|
|
55
|
+
"keywords": [
|
|
56
|
+
"opra",
|
|
57
|
+
"nestjs",
|
|
58
|
+
"socket.io",
|
|
59
|
+
"websockets",
|
|
60
|
+
"ws"
|
|
61
|
+
],
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const OPRA_SOCKETIO_MODULE_OPTIONS = "OPRA_SOCKETIO_MODULE_OPTIONS";
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type DynamicModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
3
|
+
import { WSControllerFactory } from '@opra/nestjs';
|
|
4
|
+
import { SocketioAdapter } from '@opra/socketio';
|
|
5
|
+
import type { OpraSocketioModule } from './opra-socketio.module.js';
|
|
6
|
+
export declare class OpraSocketioCoreModule implements OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown {
|
|
7
|
+
private controllerFactory;
|
|
8
|
+
protected adapter: SocketioAdapter;
|
|
9
|
+
protected config: OpraSocketioModule.ModuleOptions;
|
|
10
|
+
private httpAdapterHost;
|
|
11
|
+
constructor(controllerFactory: WSControllerFactory, adapter: SocketioAdapter, config: OpraSocketioModule.ModuleOptions, httpAdapterHost: HttpAdapterHost);
|
|
12
|
+
static forRoot(moduleOptions: OpraSocketioModule.ModuleOptions): DynamicModule;
|
|
13
|
+
static forRootAsync(moduleOptions: OpraSocketioModule.AsyncModuleOptions): DynamicModule;
|
|
14
|
+
protected static _getDynamicModule(moduleOptions: OpraSocketioModule.ModuleOptions | OpraSocketioModule.AsyncModuleOptions): DynamicModule;
|
|
15
|
+
onModuleInit(): any;
|
|
16
|
+
onApplicationBootstrap(): Promise<void>;
|
|
17
|
+
onApplicationShutdown(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DynamicModule, Logger, type Type } from '@nestjs/common';
|
|
2
|
+
import type { ApiDocumentFactory } from '@opra/common';
|
|
3
|
+
import type { SocketioAdapter } from '@opra/socketio';
|
|
4
|
+
import * as socketio from 'socket.io';
|
|
5
|
+
export declare namespace OpraSocketioModule {
|
|
6
|
+
export interface ModuleOptions extends BaseModuleOptions, ApiConfig {
|
|
7
|
+
}
|
|
8
|
+
export interface AsyncModuleOptions extends BaseModuleOptions {
|
|
9
|
+
inject?: any[];
|
|
10
|
+
useFactory?: (...args: any[]) => Promise<ApiConfig> | ApiConfig;
|
|
11
|
+
}
|
|
12
|
+
interface BaseModuleOptions extends Pick<DynamicModule, 'imports' | 'providers' | 'exports' | 'controllers' | 'global'> {
|
|
13
|
+
token?: any;
|
|
14
|
+
port?: number;
|
|
15
|
+
serverOptions?: Partial<socketio.ServerOptions>;
|
|
16
|
+
interceptors?: (SocketioAdapter.InterceptorFunction | SocketioAdapter.IWSInterceptor | Type<SocketioAdapter.IWSInterceptor>)[];
|
|
17
|
+
}
|
|
18
|
+
export interface ApiConfig extends Pick<ApiDocumentFactory.InitArguments, 'types' | 'references' | 'info'> {
|
|
19
|
+
name: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
scope?: string;
|
|
22
|
+
logger?: Logger;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
}
|
|
26
|
+
export declare class OpraSocketioModule {
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param init
|
|
30
|
+
*/
|
|
31
|
+
static forRoot(init: OpraSocketioModule.ModuleOptions): DynamicModule;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param options
|
|
35
|
+
*/
|
|
36
|
+
static forRootAsync(options: OpraSocketioModule.AsyncModuleOptions): DynamicModule;
|
|
37
|
+
}
|