@futdevpro/nts-dynamo 1.10.26 → 1.10.29
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/build/_models/control-models/app-params.control-model.d.ts +30 -0
- package/build/_models/control-models/app-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/app-params.control-model.js +6 -0
- package/build/_models/control-models/app-params.control-model.js.map +1 -1
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts +2 -21
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts.map +1 -1
- package/build/_modules/open-ai/_services/embedding.control-service.js +12 -25
- package/build/_modules/open-ai/_services/embedding.control-service.js.map +1 -1
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts.map +1 -1
- package/build/_modules/open-ai/_services/gpt.service-base.js.map +1 -1
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts.map +1 -1
- package/build/_modules/open-ai/_services/open-ai.service-base.js.map +1 -1
- package/build/_modules/open-ai/_services/vector-data.service.d.ts +32 -0
- package/build/_modules/open-ai/_services/vector-data.service.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/vector-data.service.js +126 -0
- package/build/_modules/open-ai/_services/vector-data.service.js.map +1 -0
- package/build/_modules/open-ai/index.d.ts +1 -0
- package/build/_modules/open-ai/index.d.ts.map +1 -1
- package/build/_modules/open-ai/index.js +1 -0
- package/build/_modules/open-ai/index.js.map +1 -1
- package/build/_modules/server/errors/errors.data-service.d.ts.map +1 -1
- package/build/_modules/server/errors/errors.data-service.js +6 -1
- package/build/_modules/server/errors/errors.data-service.js.map +1 -1
- package/build/_modules/socket/_models/socket-presence.control-model.js +1 -1
- package/build/_modules/socket/_services/socket-client.service.d.ts +2 -1
- package/build/_modules/socket/_services/socket-client.service.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-client.service.js +22 -19
- package/build/_modules/socket/_services/socket-client.service.js.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.d.ts +1 -1
- package/build/_modules/socket/_services/socket-server.service.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.js +40 -29
- package/build/_modules/socket/_services/socket-server.service.js.map +1 -1
- package/build/_services/base/data.service.d.ts +13 -4
- package/build/_services/base/data.service.d.ts.map +1 -1
- package/build/_services/base/data.service.js +16 -10
- package/build/_services/base/data.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +13 -4
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +3 -3
- package/src/_models/control-models/app-params.control-model.ts +9 -0
- package/src/_modules/open-ai/_services/embedding.control-service.ts +16 -26
- package/src/_modules/open-ai/_services/gpt.service-base.ts +0 -1
- package/src/_modules/open-ai/_services/open-ai.service-base.ts +1 -2
- package/src/_modules/open-ai/_services/vector-data.service.ts +188 -0
- package/src/_modules/open-ai/index.ts +1 -0
- package/src/_modules/server/errors/errors.data-service.ts +5 -1
- package/src/_modules/socket/_models/socket-presence.control-model.ts +1 -1
- package/src/_modules/socket/_services/socket-client.service.ts +23 -20
- package/src/_modules/socket/_services/socket-server.service.ts +40 -28
- package/src/_services/base/data.service.ts +14 -14
- package/src/_services/server/app.server.ts +13 -9
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
DyFM_Array,
|
|
4
|
+
DyFM_DataModel_Params,
|
|
5
|
+
DyFM_DataProperty_Params,
|
|
6
|
+
DyFM_Error,
|
|
7
|
+
DyFM_Metadata
|
|
8
|
+
} from '@futdevpro/fsm-dynamo';
|
|
9
|
+
import { DyFM_OpenAI_Settings, DyFM_OpenAIModel } from '@futdevpro/fsm-dynamo/open-ai';
|
|
10
|
+
|
|
11
|
+
import { DyNTS_global_settings } from '../../../_collections/global-settings.const';
|
|
12
|
+
import { DyNTS_DataService } from '../../../_services/base/data.service';
|
|
13
|
+
import { Embedding_ControlService } from './embedding.control-service';
|
|
14
|
+
|
|
15
|
+
export class DyNTS_VectorDataService<T extends DyFM_Metadata> extends DyNTS_DataService<T> {
|
|
16
|
+
|
|
17
|
+
readonly vectorizeProperties: DyFM_DataProperty_Params<any>[];
|
|
18
|
+
/* readonly vectorizeProperties: { from: string, to: string }[]; */
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
/**
|
|
22
|
+
* Initial data, this will be used by functions on default
|
|
23
|
+
*/
|
|
24
|
+
data: T,
|
|
25
|
+
/**
|
|
26
|
+
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
27
|
+
*/
|
|
28
|
+
dataParams: DyFM_DataModel_Params<T>,
|
|
29
|
+
/**
|
|
30
|
+
* OpenAI settings
|
|
31
|
+
*/
|
|
32
|
+
public readonly openAISettings: DyFM_OpenAI_Settings,
|
|
33
|
+
/**
|
|
34
|
+
* Initial set for issuer to be able to follow the issuer's activity
|
|
35
|
+
*/
|
|
36
|
+
issuer: string
|
|
37
|
+
) {
|
|
38
|
+
super(data, dataParams, issuer);
|
|
39
|
+
|
|
40
|
+
const vectorizePropertyKeys: string[] = Object.keys(dataParams.properties).filter(
|
|
41
|
+
(key: string): boolean => dataParams.properties[key].vectorizeFrom &&
|
|
42
|
+
dataParams.properties[key].vectorizeFrom !== key
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (!vectorizePropertyKeys.length) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
'vectorizedPropertyKeys is missing! ' +
|
|
48
|
+
`\nkeys with vectorizeFrom: ${Object.keys(dataParams.properties).filter(
|
|
49
|
+
(key: string): boolean => dataParams.properties[key].vectorizeFrom
|
|
50
|
+
).join(', ')}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.vectorizeProperties = vectorizePropertyKeys.map(
|
|
55
|
+
(key: string): DyFM_DataProperty_Params<any> => dataParams.properties[key]
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async vectorizeDataProperties(data?: T): Promise<T> {
|
|
60
|
+
try {
|
|
61
|
+
await DyFM_Array.asyncForEachAllAtOnce(
|
|
62
|
+
this.vectorizeProperties,
|
|
63
|
+
async (property: DyFM_DataProperty_Params<any>) => {
|
|
64
|
+
if (!data[property.key] || property.vectorizeAlways) {
|
|
65
|
+
data[property.key] = await this.vectorize(
|
|
66
|
+
data[property.key],
|
|
67
|
+
property.embeddingModel
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return data;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new DyFM_Error({
|
|
76
|
+
...this.getDefaultErrorSettings('vectorizeDataProperties', error),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async vectorize(
|
|
82
|
+
input: string,
|
|
83
|
+
useModel: DyFM_OpenAIModel | string = this.openAISettings.defaultSettings.useModel
|
|
84
|
+
): Promise<number[]> {
|
|
85
|
+
try {
|
|
86
|
+
const embedding_CS: Embedding_ControlService = new Embedding_ControlService(
|
|
87
|
+
this.openAISettings
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return await embedding_CS.createEmbedding(
|
|
91
|
+
input,
|
|
92
|
+
useModel,
|
|
93
|
+
this.issuer
|
|
94
|
+
);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw new DyFM_Error({
|
|
97
|
+
...this.getDefaultErrorSettings('vectorize', error),
|
|
98
|
+
|
|
99
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-VDB-V0`,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async vectorSearch(
|
|
105
|
+
input: string,
|
|
106
|
+
searchInKey: string,
|
|
107
|
+
/* useIndex: string, */
|
|
108
|
+
limit: number = 5,
|
|
109
|
+
useModel?: DyFM_OpenAIModel | string
|
|
110
|
+
): Promise<any> {
|
|
111
|
+
try {
|
|
112
|
+
const embedding_CS: Embedding_ControlService = new Embedding_ControlService(
|
|
113
|
+
this.openAISettings
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const property: DyFM_DataProperty_Params<any> = this.dataParams.properties[searchInKey];
|
|
117
|
+
|
|
118
|
+
if (!property) {
|
|
119
|
+
throw new DyFM_Error({
|
|
120
|
+
...this.getDefaultErrorSettings(
|
|
121
|
+
'vectorSearch',
|
|
122
|
+
new Error(`Property "${searchInKey}" not found!`)
|
|
123
|
+
),
|
|
124
|
+
|
|
125
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-VDB-VS0`,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const embeddedInput: number[] = await embedding_CS.createEmbedding(
|
|
130
|
+
input,
|
|
131
|
+
useModel ?? property.embeddingModel,
|
|
132
|
+
this.issuer
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const result = await this.dataDBService.aggregate(
|
|
136
|
+
[
|
|
137
|
+
{
|
|
138
|
+
$vectorSearch: {
|
|
139
|
+
index: property.vectorizeUseIndex,
|
|
140
|
+
queryVector: embeddedInput,
|
|
141
|
+
path: searchInKey,
|
|
142
|
+
numCandidates: 100,
|
|
143
|
+
limit: limit
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
/* {
|
|
148
|
+
$search: {
|
|
149
|
+
index: 'default',
|
|
150
|
+
knnBeta: {
|
|
151
|
+
vector: embeddedInput,
|
|
152
|
+
path: searchInKey,
|
|
153
|
+
numCandidates: 100,
|
|
154
|
+
limit: limit
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
} */
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return result;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
throw new DyFM_Error({
|
|
163
|
+
...this.getDefaultErrorSettings('vectorSearch', error),
|
|
164
|
+
|
|
165
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-VDB-VS0`,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
override async saveData(data?: T, dontSetToService?: boolean): Promise<T> {
|
|
171
|
+
try {
|
|
172
|
+
data = this.ensureData(data);
|
|
173
|
+
|
|
174
|
+
data = await this.vectorizeDataProperties(data);
|
|
175
|
+
|
|
176
|
+
return await super.saveData(data, dontSetToService);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
throw new DyFM_Error({
|
|
179
|
+
...this.getDefaultErrorSettings(
|
|
180
|
+
'saveData',
|
|
181
|
+
error
|
|
182
|
+
),
|
|
183
|
+
|
|
184
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-VDB-SD0`,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -169,7 +169,11 @@ export class DyNTS_Errors_DataService<
|
|
|
169
169
|
DyFM_Log.warn('error saved');
|
|
170
170
|
}
|
|
171
171
|
} catch (error) {
|
|
172
|
-
|
|
172
|
+
if (error instanceof DyFM_Error) {
|
|
173
|
+
error.logSimple('recordError error');
|
|
174
|
+
} else {
|
|
175
|
+
DyFM_Log.error('recordError error:', error);
|
|
176
|
+
}
|
|
173
177
|
/* throw new DyFM_Error({
|
|
174
178
|
...this.getDefaultErrorSettings(
|
|
175
179
|
'recordError',
|
|
@@ -36,7 +36,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
36
36
|
tasks: [
|
|
37
37
|
async () => {
|
|
38
38
|
this._connected = true;
|
|
39
|
-
DyFM_Log.success(`< > socket-client(${this.params.name}) connected!`);
|
|
39
|
+
DyFM_Log.success(`< > socket-client (${this.params.name}) connected!`);
|
|
40
40
|
},
|
|
41
41
|
],
|
|
42
42
|
}),
|
|
@@ -46,7 +46,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
46
46
|
tasks: [
|
|
47
47
|
async () => {
|
|
48
48
|
this._connected = false;
|
|
49
|
-
DyFM_Log.warn(`<x > socket-client(${this.params.name}) disconnected!`);
|
|
49
|
+
DyFM_Log.warn(`<x > socket-client (${this.params.name}) disconnected!`);
|
|
50
50
|
|
|
51
51
|
if (this._params.reconnect) {
|
|
52
52
|
await DyFM_delay(this._params.reconnectDelay);
|
|
@@ -60,7 +60,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
60
60
|
eventKey: DyFM_SocketEvent_Key.subscriptionSuccessful,
|
|
61
61
|
tasks: [
|
|
62
62
|
async () => {
|
|
63
|
-
DyFM_Log.success(`<=--> socket-client(${this.params.name}) subscription successful!`);
|
|
63
|
+
DyFM_Log.success(`<=--> socket-client (${this.params.name}) subscription successful!`);
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
66
|
}),
|
|
@@ -70,9 +70,9 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
70
70
|
tasks: [
|
|
71
71
|
async (content: any) => {
|
|
72
72
|
if (content instanceof DyFM_Error) {
|
|
73
|
-
content.logSimple(`=--> socket-client(${this.params.name}) ERROR`);
|
|
73
|
+
content.logSimple(`=--> socket-client (${this.params.name}) ERROR`);
|
|
74
74
|
} else {
|
|
75
|
-
DyFM_Log.error(`=--> socket-client(${this.params.name}) ERROR:`, content);
|
|
75
|
+
DyFM_Log.error(`=--> socket-client (${this.params.name}) ERROR:`, content);
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
],
|
|
@@ -88,13 +88,13 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
88
88
|
!(error instanceof DyFM_Error)
|
|
89
89
|
) {
|
|
90
90
|
DyFM_Log.H_error(
|
|
91
|
-
`socket-client
|
|
91
|
+
`socket-client (${this.params?.name}) Service setup failed! ` +
|
|
92
92
|
`(DyNTS_SocketClientService constructor catch)`,
|
|
93
93
|
`\n ERROR:`, error
|
|
94
94
|
);
|
|
95
95
|
} else {
|
|
96
96
|
error.logSimple(
|
|
97
|
-
`socket-client
|
|
97
|
+
`socket-client (${this.params?.name}) Service setup failed! ` +
|
|
98
98
|
`(DyNTS_SocketClientService constructor catch)`
|
|
99
99
|
);
|
|
100
100
|
}
|
|
@@ -118,11 +118,11 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
118
118
|
|
|
119
119
|
await this.setupSocketEvents();
|
|
120
120
|
|
|
121
|
-
DyFM_Log.success(`\nsocket-client(${this.params?.name}) Service setup finished`);
|
|
121
|
+
DyFM_Log.success(`\nsocket-client (${this.params?.name}) Service setup finished`);
|
|
122
122
|
|
|
123
123
|
await this.connectSocket();
|
|
124
124
|
} catch (error) {
|
|
125
|
-
DyFM_Log.error(`socket-client(${this.params?.name}) Service setup failed!`, error);
|
|
125
|
+
DyFM_Log.error(`socket-client (${this.params?.name}) Service setup failed!`, error);
|
|
126
126
|
|
|
127
127
|
throw new DyFM_Error({
|
|
128
128
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SCS-001`,
|
|
@@ -149,7 +149,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
149
149
|
});
|
|
150
150
|
} catch (error) {
|
|
151
151
|
DyFM_Log.error(
|
|
152
|
-
`socket-client(${this.params.name}) Service Setup Default Events failed, ` +
|
|
152
|
+
`socket-client (${this.params.name}) Service Setup Default Events failed, ` +
|
|
153
153
|
`ERROR:`, error
|
|
154
154
|
);
|
|
155
155
|
|
|
@@ -159,7 +159,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
159
159
|
|
|
160
160
|
private async setupSocketEvents(): Promise<void> {
|
|
161
161
|
try {
|
|
162
|
-
if (this.debugLog) console.log(`Setup socket-client(${this.params.name}) Events...`);
|
|
162
|
+
if (this.debugLog) console.log(`Setup socket-client (${this.params.name}) Events...`);
|
|
163
163
|
|
|
164
164
|
await DyFM_Array.asyncForEach(
|
|
165
165
|
this.incomingEvents,
|
|
@@ -169,7 +169,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
169
169
|
try {
|
|
170
170
|
await event.executeEventTasks(content, this.params.service);
|
|
171
171
|
} catch (error) {
|
|
172
|
-
DyFM_Log.error(`socket-client(${this.params.name}) Event failed, ERROR:`, error);
|
|
172
|
+
DyFM_Log.error(`socket-client (${this.params.name}) Event failed, ERROR:`, error);
|
|
173
173
|
await this.emitEvent(DyFM_SocketEvent_Key.error, error);
|
|
174
174
|
}
|
|
175
175
|
});
|
|
@@ -177,7 +177,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
177
177
|
);
|
|
178
178
|
} catch (error) {
|
|
179
179
|
DyFM_Log.error(
|
|
180
|
-
`socket-client(${this.params.name}) Service Setup Socket Events failed, ` +
|
|
180
|
+
`socket-client (${this.params.name}) Service Setup Socket Events failed, ` +
|
|
181
181
|
`ERROR:`, error
|
|
182
182
|
);
|
|
183
183
|
|
|
@@ -185,21 +185,22 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
tryingToReconnect = false;
|
|
189
|
+
protected async connectSocket(): Promise<void> {
|
|
189
190
|
try {
|
|
190
191
|
DyFM_Log.info(
|
|
191
|
-
`< .. > socket-client(${this.params.name}) ` +
|
|
192
|
+
`< .. > socket-client (${this.params.name}) ` +
|
|
192
193
|
`connecting to ${this.params.address}:${this.params.port} ...`
|
|
193
194
|
);
|
|
194
195
|
|
|
195
196
|
this.socket.connect();
|
|
196
197
|
|
|
197
|
-
if (this.params.reconnect) {
|
|
198
|
+
if (this.params.reconnect && !this.tryingToReconnect) {
|
|
198
199
|
await this.tryReconnectIfNeeded();
|
|
199
200
|
}
|
|
200
201
|
} catch (error) {
|
|
201
202
|
DyFM_Log.error(
|
|
202
|
-
`socket-client(${this.params.name}) Service Connect Socket failed, ` +
|
|
203
|
+
`socket-client (${this.params.name}) Service Connect Socket failed, ` +
|
|
203
204
|
`ERROR:`, error
|
|
204
205
|
);
|
|
205
206
|
|
|
@@ -210,14 +211,16 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
210
211
|
private async tryReconnectIfNeeded(): Promise<void> {
|
|
211
212
|
try {
|
|
212
213
|
if (this.logFn) console.log(`\nFn:. tryReconnectIfNeeded`);
|
|
214
|
+
this.tryingToReconnect = true;
|
|
213
215
|
await DyFM_delay(this._params.reconnectDelay);
|
|
214
216
|
|
|
217
|
+
this.tryingToReconnect = false;
|
|
215
218
|
if (!this._connected) {
|
|
216
219
|
await this.connectSocket();
|
|
217
220
|
}
|
|
218
221
|
} catch (error) {
|
|
219
222
|
DyFM_Log.error(
|
|
220
|
-
`socket-client(${this.params.name}) Service Try Reconnect failed, ` +
|
|
223
|
+
`socket-client (${this.params.name}) Service Try Reconnect failed, ` +
|
|
221
224
|
`ERROR:`, error
|
|
222
225
|
);
|
|
223
226
|
|
|
@@ -232,11 +235,11 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
232
235
|
*/
|
|
233
236
|
async emitEvent(eventType: string, content: any): Promise<void> {
|
|
234
237
|
try {
|
|
235
|
-
DyFM_Log.log(`<=-- outgoing socket-client(${this.params.name}) event: ${eventType}`);
|
|
238
|
+
DyFM_Log.log(`<=-- outgoing socket-client (${this.params.name}) event: ${eventType}`);
|
|
236
239
|
this.socket.emit(eventType, content);
|
|
237
240
|
} catch (error) {
|
|
238
241
|
DyFM_Log.error(
|
|
239
|
-
`socket-client(${this.params.name}) ` +
|
|
242
|
+
`socket-client (${this.params.name}) ` +
|
|
240
243
|
`Service Emit Event failed: ${this.params?.name} (${this.params?.port})`, error
|
|
241
244
|
);
|
|
242
245
|
|
|
@@ -209,9 +209,9 @@ export abstract class DyNTS_SocketServerService<
|
|
|
209
209
|
tasks: [
|
|
210
210
|
async (content: any) => {
|
|
211
211
|
if (content instanceof DyFM_Error) {
|
|
212
|
-
content.logSimple(`=--> socket-client(${this.params.name}) ERROR`);
|
|
212
|
+
content.logSimple(`=--> socket-client (${this.params.name}) ERROR`);
|
|
213
213
|
} else {
|
|
214
|
-
DyFM_Log.error(`=--> socket-client(${this.params.name}) ERROR:`, content);
|
|
214
|
+
DyFM_Log.error(`=--> socket-client (${this.params.name}) ERROR:`, content);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
],
|
|
@@ -306,13 +306,13 @@ export abstract class DyNTS_SocketServerService<
|
|
|
306
306
|
*/
|
|
307
307
|
if (DyNTS_global_settings.log_settings.socket_eventContent) {
|
|
308
308
|
DyFM_Log.log(
|
|
309
|
-
`--=> incoming socket(${this.params.name}) ` +
|
|
309
|
+
`--=> incoming socket (${this.params.name}) ` +
|
|
310
310
|
`event: "${DyFM_SocketEvent_Key.subscribe}";` +
|
|
311
311
|
`\ncontent:`, content
|
|
312
312
|
);
|
|
313
313
|
} else {
|
|
314
314
|
DyFM_Log.log(
|
|
315
|
-
`--=> incoming socket(${this.params.name}) ` +
|
|
315
|
+
`--=> incoming socket (${this.params.name}) ` +
|
|
316
316
|
`event: "${DyFM_SocketEvent_Key.subscribe}"`
|
|
317
317
|
);
|
|
318
318
|
}
|
|
@@ -352,7 +352,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
352
352
|
);
|
|
353
353
|
} catch (error) {
|
|
354
354
|
if (error instanceof DyFM_Error) {
|
|
355
|
-
error.
|
|
355
|
+
error.logShort(
|
|
356
356
|
`Socket Subscription failed: "${this.params.name}" ` +
|
|
357
357
|
`(${this.params.port}) will disconnect now...`
|
|
358
358
|
)
|
|
@@ -386,13 +386,13 @@ export abstract class DyNTS_SocketServerService<
|
|
|
386
386
|
*/
|
|
387
387
|
if (DyNTS_global_settings.log_settings.socket_eventContent) {
|
|
388
388
|
DyFM_Log.log(
|
|
389
|
-
`--=> incoming socket(${this.params.name}) ` +
|
|
389
|
+
`--=> incoming socket (${this.params.name}) ` +
|
|
390
390
|
`event: ${DyFM_SocketEvent_Key.unsubscribe};` +
|
|
391
391
|
`\ncontent:`, issuer
|
|
392
392
|
);
|
|
393
393
|
} else {
|
|
394
394
|
DyFM_Log.log(
|
|
395
|
-
`--=> incoming socket(${this.params.name}) ` +
|
|
395
|
+
`--=> incoming socket (${this.params.name}) ` +
|
|
396
396
|
`event: ${DyFM_SocketEvent_Key.unsubscribe}`
|
|
397
397
|
);
|
|
398
398
|
}
|
|
@@ -547,7 +547,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
547
547
|
}
|
|
548
548
|
} catch (error) {
|
|
549
549
|
if (error instanceof DyFM_Error) {
|
|
550
|
-
error.
|
|
550
|
+
error.logShort(
|
|
551
551
|
`Socket Subscription failed: "${this.params?.name}" (${this.params?.port})`
|
|
552
552
|
)
|
|
553
553
|
} else if (DyNTS_global_settings.log_settings.socket_eventContent) {
|
|
@@ -636,15 +636,27 @@ export abstract class DyNTS_SocketServerService<
|
|
|
636
636
|
private async disconnectBaseTask(socket: SocketIO.Socket, issuer: string): Promise<void> {
|
|
637
637
|
try {
|
|
638
638
|
if (!(socket instanceof SocketIO.Socket)) {
|
|
639
|
-
throw new DyFM_Error({
|
|
639
|
+
/* throw new DyFM_Error({
|
|
640
640
|
...this._getDefaultErrorSettings(
|
|
641
641
|
'disconnectBaseTask',
|
|
642
|
-
new Error('Socket is not a SocketIO.Socket'),
|
|
642
|
+
new Error('Socket is not a SocketIO.Socket, type: ' + typeof socket),
|
|
643
643
|
),
|
|
644
|
-
});
|
|
644
|
+
}); */
|
|
645
|
+
DyFM_Log.error(
|
|
646
|
+
`Socket is not a SocketIO.Socket, type: ${typeof socket}`,
|
|
647
|
+
socket
|
|
648
|
+
);
|
|
645
649
|
}
|
|
646
650
|
|
|
647
|
-
await this.removeSubscription(socket, issuer)
|
|
651
|
+
await this.removeSubscription(socket, issuer).catch(error => {
|
|
652
|
+
if (error instanceof DyFM_Error) {
|
|
653
|
+
error.logShort(
|
|
654
|
+
`Remove Subscription failed: "${this.params.name}" (${this.params.port})`
|
|
655
|
+
);
|
|
656
|
+
} else {
|
|
657
|
+
DyFM_Log.error(`Remove Subscription failed: "${this.params.name}" (${this.params.port})`, error);
|
|
658
|
+
}
|
|
659
|
+
});
|
|
648
660
|
|
|
649
661
|
DyFM_Log.info(`< x > socket(${this.params.name}) disconnected (${issuer})`);
|
|
650
662
|
} catch (error) {
|
|
@@ -671,7 +683,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
671
683
|
...this._getDefaultErrorSettings(
|
|
672
684
|
'sendEventForId',
|
|
673
685
|
new Error(
|
|
674
|
-
`closing socket(${this.params.name}) does not match any in the activePresences`
|
|
686
|
+
`closing socket (${this.params.name}) does not match any in the activePresences`
|
|
675
687
|
),
|
|
676
688
|
issuer ?? 'unknown issuer'
|
|
677
689
|
),
|
|
@@ -704,7 +716,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
704
716
|
...this._getDefaultErrorSettings(
|
|
705
717
|
'sendEventForId',
|
|
706
718
|
new Error(
|
|
707
|
-
`closing socket(${this.params.name}) does not match any in the activePresences`
|
|
719
|
+
`closing socket (${this.params.name}) does not match any in the activePresences`
|
|
708
720
|
),
|
|
709
721
|
activePresence.issuerLocalId
|
|
710
722
|
),
|
|
@@ -740,7 +752,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
740
752
|
|
|
741
753
|
socket.emit(DyFM_SocketEvent_Key.unsubscribeSuccessful, 'unsubscribe was successful');
|
|
742
754
|
socket.disconnect();
|
|
743
|
-
DyFM_Log.info(`<x==> socket(${this.params.name}) unsubscription successful (${issuer})`);
|
|
755
|
+
DyFM_Log.info(`<x==> socket (${this.params.name}) unsubscription successful (${issuer})`);
|
|
744
756
|
} catch (error) {
|
|
745
757
|
throw new DyFM_Error({
|
|
746
758
|
...this._getDefaultErrorSettings(
|
|
@@ -750,7 +762,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
750
762
|
),
|
|
751
763
|
|
|
752
764
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SSS-RS0`,
|
|
753
|
-
message: `socket(${this.params.name}) Subscription Removal failed: "${this.params?.name}"`,
|
|
765
|
+
message: `socket (${this.params.name}) Subscription Removal failed: "${this.params?.name}"`,
|
|
754
766
|
});
|
|
755
767
|
}
|
|
756
768
|
}
|
|
@@ -788,7 +800,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
788
800
|
),
|
|
789
801
|
|
|
790
802
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SSS-IIS0`,
|
|
791
|
-
message: `socket(${this.params.name}) ID Subscription Check (${id}) failed`,
|
|
803
|
+
message: `socket (${this.params.name}) ID Subscription Check (${id}) failed`,
|
|
792
804
|
});
|
|
793
805
|
}
|
|
794
806
|
}
|
|
@@ -804,7 +816,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
804
816
|
presenceIssuerId
|
|
805
817
|
),
|
|
806
818
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SSS-EE0`,
|
|
807
|
-
message: `socket(${this.params.name}) Error Emit (id: ${presenceIssuerId}) failed`,
|
|
819
|
+
message: `socket (${this.params.name}) Error Emit (id: ${presenceIssuerId}) failed`,
|
|
808
820
|
});
|
|
809
821
|
}
|
|
810
822
|
}
|
|
@@ -852,13 +864,13 @@ export abstract class DyNTS_SocketServerService<
|
|
|
852
864
|
|
|
853
865
|
if (DyNTS_global_settings.log_settings.socket_eventContent) {
|
|
854
866
|
DyFM_Log.success(
|
|
855
|
-
` <--= emitted socket(${this.params.name}) event: "${event}", ` +
|
|
867
|
+
` <--= emitted socket (${this.params.name}) event: "${event}", ` +
|
|
856
868
|
`\n presenceId: "${id}", sockets: ${presence.sockets.length}` +
|
|
857
869
|
`\n content:`, content
|
|
858
870
|
);
|
|
859
871
|
} else {
|
|
860
872
|
DyFM_Log.success(
|
|
861
|
-
` <--= emitted socket(${this.params.name}) event: "${event}", ` +
|
|
873
|
+
` <--= emitted socket (${this.params.name}) event: "${event}", ` +
|
|
862
874
|
`\n presenceId: ${id}, sockets: ${presence.sockets.length}`
|
|
863
875
|
);
|
|
864
876
|
}
|
|
@@ -879,7 +891,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
879
891
|
throw new DyFM_Error({
|
|
880
892
|
...this._getDefaultErrorSettings(
|
|
881
893
|
'sendEventForId',
|
|
882
|
-
new Error(`No active socket(${this.params.name}) with this specific ID: "${id}"`),
|
|
894
|
+
new Error(`No active socket (${this.params.name}) with this specific ID: "${id}"`),
|
|
883
895
|
content?.source
|
|
884
896
|
),
|
|
885
897
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SSS-SEFI4`,
|
|
@@ -891,7 +903,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
891
903
|
...this._getDefaultErrorSettings('sendEventForId', error, content?.source),
|
|
892
904
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SSS-SEFI5`,
|
|
893
905
|
message:
|
|
894
|
-
`Error handling of inactive sockets(${this.params.name}) failed!` +
|
|
906
|
+
`Error handling of inactive sockets (${this.params.name}) failed!` +
|
|
895
907
|
`\n(Socket Event Emit for id (${id}, ${event}) failed)`,
|
|
896
908
|
});
|
|
897
909
|
}
|
|
@@ -899,14 +911,14 @@ export abstract class DyNTS_SocketServerService<
|
|
|
899
911
|
throw new DyFM_Error({
|
|
900
912
|
...this._getDefaultErrorSettings('sendEventForId', error, content?.source),
|
|
901
913
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SSS-SEFI0`,
|
|
902
|
-
message: `socket(${this.params.name}) Event Emit for id (${id}, ${event}) failed`,
|
|
914
|
+
message: `socket (${this.params.name}) Event Emit for id (${id}, ${event}) failed`,
|
|
903
915
|
});
|
|
904
916
|
}
|
|
905
917
|
}
|
|
906
918
|
|
|
907
|
-
broadcastEvent(event: string, content: any, issuer: string): void {
|
|
919
|
+
async broadcastEvent(event: string, content: any, issuer: string): Promise<void> {
|
|
908
920
|
try {
|
|
909
|
-
DyFM_Log.log(
|
|
921
|
+
DyFM_Log.log(`<=-== broadcasting socket (${this.params.name}) event: "${event}"`);
|
|
910
922
|
|
|
911
923
|
this.presences.forEach((presence: DyNTS_SocketPresence) => {
|
|
912
924
|
presence.emitEvent(event, content, issuer);
|
|
@@ -914,9 +926,9 @@ export abstract class DyNTS_SocketServerService<
|
|
|
914
926
|
} catch (error) {
|
|
915
927
|
if (DyNTS_global_settings.log_settings.detailedErrors) {
|
|
916
928
|
if (error instanceof DyFM_Error) {
|
|
917
|
-
error.logSimple(`socket(${this.params.name}) Event Broadcast (${event}) failed`);
|
|
929
|
+
error.logSimple(`socket (${this.params.name}) Event Broadcast (${event}) failed`);
|
|
918
930
|
} else {
|
|
919
|
-
DyFM_Log.error(`socket(${this.params.name}) Event Broadcast (${event}) failed`, error);
|
|
931
|
+
DyFM_Log.error(`socket (${this.params.name}) Event Broadcast (${event}) failed`, error);
|
|
920
932
|
}
|
|
921
933
|
}
|
|
922
934
|
|
|
@@ -924,7 +936,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
924
936
|
...this._getDefaultErrorSettings('broadcastEvent', error),
|
|
925
937
|
|
|
926
938
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SSS-BE0`,
|
|
927
|
-
message: `socket(${this.params.name}) Event Broadcast (${event}) failed`,
|
|
939
|
+
message: `socket (${this.params.name}) Event Broadcast (${event}) failed`,
|
|
928
940
|
});
|
|
929
941
|
}
|
|
930
942
|
}
|
|
@@ -57,9 +57,9 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
57
57
|
dataDBService: DyNTS_DBService<T>;
|
|
58
58
|
haveArchiveDataService: boolean;
|
|
59
59
|
|
|
60
|
-
data: T;
|
|
60
|
+
/* data: T; */
|
|
61
61
|
dataList: T[] = [];
|
|
62
|
-
issuer: string;
|
|
62
|
+
/* issuer: string; */
|
|
63
63
|
|
|
64
64
|
readonly depSettings: {
|
|
65
65
|
key: string;
|
|
@@ -73,7 +73,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
73
73
|
depKeyIsRequired: boolean[] = []; */
|
|
74
74
|
private depDataDBService: DyNTS_DBService<any>;
|
|
75
75
|
|
|
76
|
-
dataParams: DyFM_DataModel_Params<T>;
|
|
76
|
+
/* dataParams: DyFM_DataModel_Params<T>; */
|
|
77
77
|
|
|
78
78
|
readonly defaultErrorUserMsg: string =
|
|
79
79
|
`We encountered an unhandled Data Service Error, ` +
|
|
@@ -86,25 +86,25 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
86
86
|
/**
|
|
87
87
|
* Initial data, this will be used by functions on default
|
|
88
88
|
*/
|
|
89
|
-
data: T,
|
|
89
|
+
public data: T,
|
|
90
90
|
/**
|
|
91
91
|
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
92
92
|
*/
|
|
93
93
|
/* dataParams: DyFM_DataModel_Params, */
|
|
94
|
-
dataParams: DyFM_Data_Params<T>,
|
|
94
|
+
public dataParams: DyFM_Data_Params<T>,
|
|
95
95
|
/**
|
|
96
96
|
* Initial set for issuer to be able to follow the issuer's activity
|
|
97
97
|
*/
|
|
98
|
-
issuer: string
|
|
98
|
+
public issuer: string
|
|
99
99
|
) {
|
|
100
100
|
try {
|
|
101
101
|
this.serviceName = this.constructor?.name;
|
|
102
|
-
this.dataDBService = DyNTS_GlobalService.getDBService<T>(dataParams);
|
|
103
|
-
this.data = data;
|
|
104
|
-
this.dataParams = dataParams;
|
|
105
|
-
this.haveArchiveDataService = dataParams.addArchive;
|
|
102
|
+
this.dataDBService = DyNTS_GlobalService.getDBService<T>(this.dataParams);
|
|
103
|
+
/* this.data = data; */
|
|
104
|
+
/* this.dataParams = dataParams; */
|
|
105
|
+
this.haveArchiveDataService = this.dataParams.addArchive;
|
|
106
106
|
this.lookForDependencyDataSettings();
|
|
107
|
-
this.issuer = issuer;
|
|
107
|
+
/* this.issuer = issuer; */
|
|
108
108
|
/* DyNTS_GlobalService.addDataService(this); */
|
|
109
109
|
} catch (error) {
|
|
110
110
|
throw new DyFM_Error({
|
|
@@ -112,15 +112,15 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
112
112
|
|
|
113
113
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-C00`,
|
|
114
114
|
message:
|
|
115
|
-
`The dataService construction failed for "${dataParams?.dataName}". ` +
|
|
115
|
+
`The dataService construction failed for "${this.dataParams?.dataName}". ` +
|
|
116
116
|
`at "${this.serviceName}" (${this.constructor.name})` +
|
|
117
117
|
`\nMaybe you forgot to add the dbService to the GlobalService?`,
|
|
118
118
|
level: DyFM_ErrorLevel.critical,
|
|
119
|
-
});
|
|
119
|
+
});
|
|
120
120
|
/* DyFM_Log.error(
|
|
121
121
|
`\nDyNTS_DataService ERROR: ` +
|
|
122
122
|
`\nThe dataService construction failed for ` +
|
|
123
|
-
`${dataParams?.dataName}. ${this.serviceName} (${this.constructor.name})` +
|
|
123
|
+
`${this.dataParams?.dataName}. ${this.serviceName} (${this.constructor.name})` +
|
|
124
124
|
`\nMaybe you forgot to add the dbService to the GlobalService?` +
|
|
125
125
|
`\n\n`,
|
|
126
126
|
new Error()
|