@eleven-am/pondsocket-nest 0.0.23 → 0.0.25
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/modules/pondSocket.js +2 -2
- package/package.json +1 -1
- package/services/pondSocket.js +3 -1
- package/services/discovery.js +0 -127
package/modules/pondSocket.js
CHANGED
|
@@ -10,12 +10,12 @@ class PondSocketModule {
|
|
|
10
10
|
const pondSocketProvider = {
|
|
11
11
|
provide: pondSocket_1.PondSocketService,
|
|
12
12
|
useFactory: (moduleRef, adapterHost, discovery) => new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, guards),
|
|
13
|
-
inject: [core_1.ModuleRef, core_1.HttpAdapterHost, nestjs_discovery_1.
|
|
13
|
+
inject: [core_1.ModuleRef, core_1.HttpAdapterHost, nestjs_discovery_1.DiscoveryService],
|
|
14
14
|
};
|
|
15
15
|
return {
|
|
16
|
-
imports,
|
|
17
16
|
exports,
|
|
18
17
|
global: isGlobal,
|
|
18
|
+
imports: [...imports, nestjs_discovery_1.DiscoveryModule],
|
|
19
19
|
module: PondSocketModule,
|
|
20
20
|
providers: [
|
|
21
21
|
pondSocketProvider,
|
package/package.json
CHANGED
package/services/pondSocket.js
CHANGED
|
@@ -138,6 +138,7 @@ class PondSocketService {
|
|
|
138
138
|
const instances = [...modules.values()];
|
|
139
139
|
const channelsWithNoEndpoints = instances.filter((instance) => instance.channels.length > 0 && instance.endpoints.length === 0);
|
|
140
140
|
const channelsWithEndpoints = instances.filter((instance) => instance.channels.length > 0 && instance.endpoints.length > 0);
|
|
141
|
+
const endpointsWithNoChannels = instances.filter((instance) => instance.endpoints.length > 0 && instance.channels.length === 0);
|
|
141
142
|
const groupedInstances = channelsWithEndpoints.map((instance) => instance.endpoints.map((endpoint) => ({
|
|
142
143
|
endpoint,
|
|
143
144
|
channels: instance.channels,
|
|
@@ -149,7 +150,8 @@ class PondSocketService {
|
|
|
149
150
|
baseEndpointInstance.channels.push(...channels);
|
|
150
151
|
}
|
|
151
152
|
else if (channelsWithNoEndpoints.length > 0) {
|
|
152
|
-
|
|
153
|
+
const channels = channelsWithNoEndpoints.map((instance) => instance.channels).flat();
|
|
154
|
+
endpointsWithNoChannels.forEach((instance) => instance.channels.push(...channels));
|
|
153
155
|
}
|
|
154
156
|
return groupedInstances;
|
|
155
157
|
});
|
package/services/discovery.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.DiscoveryService = void 0;
|
|
13
|
-
// eslint-disable-next-line import/no-unresolved
|
|
14
|
-
const common_1 = require("@nestjs/common");
|
|
15
|
-
// eslint-disable-next-line import/no-unresolved
|
|
16
|
-
const constants_1 = require("@nestjs/core/injector/constants");
|
|
17
|
-
const constants_2 = require("../constants");
|
|
18
|
-
class DiscoveryService {
|
|
19
|
-
constructor(modulesContainer, appModuleName) {
|
|
20
|
-
this.modulesContainer = modulesContainer;
|
|
21
|
-
this.appModuleName = appModuleName;
|
|
22
|
-
this.providers = [];
|
|
23
|
-
}
|
|
24
|
-
groupToModules() {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const endpoints = yield this.findEndpoints();
|
|
27
|
-
const channels = yield this.findChannels();
|
|
28
|
-
const modules = new Map();
|
|
29
|
-
endpoints.forEach((endpoint) => {
|
|
30
|
-
const module = endpoint.parentModule.injectType;
|
|
31
|
-
if (!modules.has(module)) {
|
|
32
|
-
modules.set(module, {
|
|
33
|
-
endpoints: [],
|
|
34
|
-
channels: [],
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
modules.get(module).endpoints.push(endpoint);
|
|
38
|
-
});
|
|
39
|
-
channels.forEach((channel) => {
|
|
40
|
-
const module = channel.parentModule.injectType;
|
|
41
|
-
if (!modules.has(module)) {
|
|
42
|
-
modules.set(module, {
|
|
43
|
-
endpoints: [],
|
|
44
|
-
channels: [],
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
modules.get(module).channels.push(channel);
|
|
48
|
-
});
|
|
49
|
-
return modules;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
getAppModule() {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const providers = yield this.getProviders();
|
|
55
|
-
const appModule = providers
|
|
56
|
-
.find((provider) => provider.name === this.appModuleName);
|
|
57
|
-
if (!appModule) {
|
|
58
|
-
throw new Error('AppModule not found');
|
|
59
|
-
}
|
|
60
|
-
return appModule;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
getProviders() {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
if (this.providers.length) {
|
|
66
|
-
return this.providers;
|
|
67
|
-
}
|
|
68
|
-
const promises = [...this.modulesContainer.values()]
|
|
69
|
-
.flatMap((nestModule) => {
|
|
70
|
-
const providers = [...nestModule.providers.values()];
|
|
71
|
-
return providers
|
|
72
|
-
.filter((wrapper) => wrapper.isDependencyTreeStatic())
|
|
73
|
-
.filter((component) => component.scope !== common_1.Scope.REQUEST)
|
|
74
|
-
.map((wrapper) => this.toDiscoveredClass(nestModule, wrapper));
|
|
75
|
-
});
|
|
76
|
-
const resolvedProviders = yield Promise.all(promises);
|
|
77
|
-
this.providers.push(...resolvedProviders.filter((provider) => provider !== undefined));
|
|
78
|
-
return this.providers;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
toDiscoveredClass(nestModule, wrapper) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
const instanceHost = wrapper.getInstanceByContextId(constants_1.STATIC_CONTEXT, wrapper && wrapper.id ? wrapper.id : undefined);
|
|
84
|
-
if (instanceHost.isPending && !instanceHost.isResolved) {
|
|
85
|
-
yield instanceHost.donePromise;
|
|
86
|
-
}
|
|
87
|
-
if (!instanceHost.instance) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
name: wrapper.name,
|
|
92
|
-
instance: instanceHost.instance,
|
|
93
|
-
injectType: wrapper.metatype,
|
|
94
|
-
dependencyType: instanceHost.instance.constructor,
|
|
95
|
-
parentModule: {
|
|
96
|
-
name: nestModule.metatype.name,
|
|
97
|
-
instance: nestModule.instance,
|
|
98
|
-
injectType: nestModule.metatype,
|
|
99
|
-
dependencyType: nestModule.instance.constructor,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
findEndpoints() {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const providers = yield this.getProviders();
|
|
107
|
-
return providers
|
|
108
|
-
.filter((provider) => this.withMetadata(constants_2.endpointKey, provider));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
findChannels() {
|
|
112
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const providers = yield this.getProviders();
|
|
114
|
-
return providers
|
|
115
|
-
.filter((provider) => this.withMetadata(constants_2.channelKey, provider));
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
withMetadata(metaKey, provider) {
|
|
119
|
-
return [
|
|
120
|
-
provider.instance.constructor,
|
|
121
|
-
provider.dependencyType,
|
|
122
|
-
provider.injectType,
|
|
123
|
-
].filter((target) => target !== null && target !== undefined)
|
|
124
|
-
.some((target) => Reflect.getMetadata(metaKey, target));
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.DiscoveryService = DiscoveryService;
|