@colabo-knalledge/i-core-services 1.0.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.
@@ -0,0 +1,1516 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var __decorateClass = (decorators, target, key, kind) => {
29
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
30
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
31
+ if (decorator = decorators[i])
32
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
33
+ if (kind && result) __defProp(target, key, result);
34
+ return result;
35
+ };
36
+ var __async = (__this, __arguments, generator) => {
37
+ return new Promise((resolve, reject) => {
38
+ var fulfilled = (value) => {
39
+ try {
40
+ step(generator.next(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var rejected = (value) => {
46
+ try {
47
+ step(generator.throw(value));
48
+ } catch (e) {
49
+ reject(e);
50
+ }
51
+ };
52
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
53
+ step((generator = generator.apply(__this, __arguments)).next());
54
+ });
55
+ };
56
+
57
+ // index.ts
58
+ var index_exports = {};
59
+ __export(index_exports, {
60
+ CFServiceFrontend: () => CFServiceIsomorphic,
61
+ CFServiceIsomorphic: () => CFServiceIsomorphic,
62
+ ColaboApiCoreService: () => ColaboApiCoreService,
63
+ ColaboKnAllEdgeContainerService: () => ColaboKnAllEdgeContainerService,
64
+ ColaboKnAllEdgeNodeService: () => ColaboKnAllEdgeNodeService,
65
+ ColaboKnAllEdgeNodeServiceExtended: () => ColaboKnAllEdgeNodeServiceExtended,
66
+ HTTP_OPTIONS_CONST_JSON: () => HTTP_OPTIONS_CONST_JSON,
67
+ KnalledgeEdgeService: () => KnalledgeEdgeService,
68
+ KnalledgeEdgeServiceExtended: () => KnalledgeEdgeServiceExtended,
69
+ MODULE_NAME: () => MODULE_NAME,
70
+ removeSecurityPrefix: () => removeSecurityPrefix
71
+ });
72
+ module.exports = __toCommonJS(index_exports);
73
+
74
+ // lib/params.ts
75
+ var MODULE_NAME = "@colabo-knalledge/i-core-services";
76
+ var DEBUG = false;
77
+ var DEBUG_VERBOSE = false;
78
+
79
+ // lib/kContainer-service.ts
80
+ var import_i_config = require("@colabo-utils/i-config");
81
+ var import_i_notifications3 = require("@colabo-utils/i-notifications");
82
+ var import_i_core4 = require("@colabo-knalledge/i-core");
83
+
84
+ // lib/cf.service.isomorphic.ts
85
+ var import_rxjs = require("rxjs");
86
+ var import_i_core = require("@colabo-knalledge/i-core");
87
+ var import_i_core2 = require("@colabo-headless/i-core");
88
+ var import_i_notifications = require("@colabo-utils/i-notifications");
89
+ var import_i_notifications2 = require("@colabo-utils/i-notifications");
90
+ var config = __toESM(require("@colabo-utils/i-config"), 1);
91
+ console.log("[CFServiceIsomorphic] Injectable: ", import_i_core2.Injectable);
92
+ var HIDE_ERRORS = true;
93
+ var HTTP_OPTIONS_CONST_JSON = {
94
+ headers: {
95
+ "Content-Type": "application/json"
96
+ }
97
+ };
98
+ var CFServiceIsomorphic = class {
99
+ constructor(utilsNotificationService) {
100
+ this.utilsNotificationService = utilsNotificationService;
101
+ }
102
+ /**
103
+ * processes array of VOs received from server to a local/fronted version
104
+ * @param vofS
105
+ * @param typeT
106
+ */
107
+ static processVOs(vofS, typeT) {
108
+ const vos = vofS.data;
109
+ if (vos) {
110
+ for (let id = 0; id < vos.length; id++) {
111
+ const vo = typeT.factory(vos[id]);
112
+ vo.state = import_i_core.VOIsomorphic.STATE_SYNCED;
113
+ vos[id] = vo;
114
+ }
115
+ }
116
+ return vos;
117
+ }
118
+ /**
119
+ * extracts VO from the server response `ServerData` and sets it up
120
+ * @param sd - data received from server
121
+ * @param typeT - type (class) of the object expected to be received
122
+ */
123
+ extractVO(sd, typeT) {
124
+ if (!sd.success) {
125
+ console.warn("[CFServiceIsomorphic::extractVO] serverData.success = false");
126
+ }
127
+ let vo;
128
+ if (sd.data) {
129
+ vo = typeT.factory(sd.data);
130
+ vo.state = import_i_core.VOIsomorphic.STATE_SYNCED;
131
+ return vo;
132
+ } else {
133
+ return {};
134
+ }
135
+ }
136
+ /**
137
+ * extracts VO from the server response `ServerData` and sets it up
138
+ * NOTE: Opposite to the `extractVO` method, this method expects the entity wrapped in an array
139
+ * The need and confusion is due to MongoDB difference in `find` method that returns an array,
140
+ * and `findById` that returns a single entity
141
+ * This method is here to treat uniformly both cases (for backend APIs, like `kContainer` API that wraps `findById` into an array)
142
+ * @param sd - data received from server
143
+ * @param typeT - type (class) of the object expected to be received
144
+ * @throws `ColaboError (DATA_MISSING | DATA_INCORRECT_FORMAT)`
145
+ */
146
+ extractVOFromDataAsArray(sd, typeT) {
147
+ if (!sd.success) {
148
+ console.warn("[CFServiceIsomorphic::extractVO] serverData.success = false");
149
+ }
150
+ let vo;
151
+ if (sd.data && Array.isArray(sd.data) && sd.data.length >= 1) {
152
+ vo = typeT.factory(sd.data[0]);
153
+ vo.state = import_i_core.VOIsomorphic.STATE_SYNCED;
154
+ return vo;
155
+ } else {
156
+ console.error("OK, there is error");
157
+ if (!sd.data) {
158
+ (0, import_i_notifications.throwColaboError)("`data` property is missing in the ServerData object", import_i_notifications.EErrorOrigin.SYSTEM, import_i_notifications.EColaboErrorKind.DATA_MISSING);
159
+ }
160
+ if (!Array.isArray(sd.data)) {
161
+ (0, import_i_notifications.throwColaboError)("`data` property is not an array", import_i_notifications.EErrorOrigin.SYSTEM, import_i_notifications.EColaboErrorKind.DATA_INCORRECT_FORMAT);
162
+ }
163
+ (0, import_i_notifications.throwColaboError)("`data` is not in right format", import_i_notifications.EErrorOrigin.SYSTEM, import_i_notifications.EColaboErrorKind.DATA_INCORRECT_FORMAT);
164
+ throw new import_i_notifications.ColaboErrorUnreachable();
165
+ }
166
+ }
167
+ errorNotification(error) {
168
+ if (this.utilsNotificationService && !HIDE_ERRORS) {
169
+ this.utilsNotificationService.addNotification({
170
+ type: import_i_notifications2.NotificationMsgType.Error,
171
+ title: "CFService Error",
172
+ msg: JSON.stringify(error)
173
+ });
174
+ }
175
+ }
176
+ handleError() {
177
+ }
178
+ /**
179
+ * Handle Http operation that failed.
180
+ * Lets the app continue.
181
+ * @param operation - name of the operation that failed
182
+ * @param result - optional value to return as the observable result
183
+ */
184
+ handleErrorForObservable(operation = "operation", result) {
185
+ return (error) => {
186
+ console.error("[CFServiceIsomorphic:handleError] operation: '%s'. error: ", operation, error);
187
+ this.errorNotification(error);
188
+ return (0, import_rxjs.of)(result);
189
+ };
190
+ }
191
+ };
192
+ // RESTfull backend API url
193
+ // eslint-disable-next-line @typescript-eslint/no-inferrable-types
194
+ CFServiceIsomorphic.serverAP = config.GetGeneral("serverUrl");
195
+ CFServiceIsomorphic = __decorateClass([
196
+ (0, import_i_core2.Injectable)()
197
+ ], CFServiceIsomorphic);
198
+
199
+ // lib/kContainer-service.ts
200
+ var import_axios2 = __toESM(require("axios"), 1);
201
+ var import_i_core5 = require("@colabo-headless/i-core");
202
+
203
+ // lib/colabo-api-core.service.ts
204
+ var import_axios = __toESM(require("axios"), 1);
205
+ var import_i_core3 = require("@colabo-headless/i-core");
206
+ console.log("[ColaboApiCoreService] Initializing");
207
+ var responseInterceptor = (response) => {
208
+ if (DEBUG_VERBOSE) console.log("[axios::interceptor::colabo-api-core.service] response.data: ", JSON.stringify(response.data, null, 4));
209
+ if (typeof response.data !== "string") {
210
+ console.error("The data are not in expected format. This could mean, either: 1) axios is used for not only colabo api backend (we do not use it as instance, probably we should eventually), 2) colabo interceptor is installed (`ColaboApiCoreService.initialize`) twice");
211
+ return response;
212
+ }
213
+ let data = response.data;
214
+ response.data = JSON.parse(removeSecurityPrefix(data));
215
+ return response;
216
+ };
217
+ var removeSecurityPrefix = (data) => {
218
+ let index = data.indexOf("\r");
219
+ const indexN = data.indexOf("\n");
220
+ if (index < 0 || index + 1 == indexN) {
221
+ index = indexN;
222
+ }
223
+ data = data.substring(index + 1);
224
+ return data;
225
+ };
226
+ var errorInterceptor = (error) => {
227
+ return Promise.reject(error);
228
+ };
229
+ if (DEBUG_VERBOSE) console.log("[ColaboApiCoreService] declaring ColaboApiCoreService class");
230
+ var ColaboApiCoreService = class _ColaboApiCoreService {
231
+ // Add a response interceptor to remove JSONP prefix that Colabo.Space is sending
232
+ // https://docs.angularjs.org/api/ng/service/$http#json-vulnerability-protection
233
+ // https://stackoverflow.com/questions/33967189/angular-not-removing-json-prefix
234
+ // [Ejecting an interceptor #2615](https://github.com/axios/axios/issues/2615#issuecomment-567964331)
235
+ static initialize(namespace, specificAxios = import_axios.default) {
236
+ if (DEBUG_VERBOSE) console.log("[ColaboApiCoreService:initialize] Initializing interceptor for the namespace: ", namespace);
237
+ if (typeof _ColaboApiCoreService.colaboApiInterceptorId === "undefined") {
238
+ _ColaboApiCoreService.colaboApiInterceptorNamespace = namespace;
239
+ _ColaboApiCoreService.colaboApiInterceptorId = specificAxios.interceptors.response.use(responseInterceptor, errorInterceptor);
240
+ if (DEBUG_VERBOSE) console.log("[ColaboApiCoreService:initialize] Initialized interceptor for the namespace: ", namespace);
241
+ } else {
242
+ if (DEBUG_VERBOSE) console.log("[ColaboApiCoreService:initialize] Skipping initialization. The colabo interceptor was already initialized for the namespace: ", _ColaboApiCoreService.colaboApiInterceptorNamespace);
243
+ }
244
+ return _ColaboApiCoreService.colaboApiInterceptorId;
245
+ }
246
+ static destroy(namespace, specificAxios = import_axios.default) {
247
+ if (DEBUG_VERBOSE) console.log("[ColaboApiCoreService:initialize] Destroying interceptor for the namespace: ", namespace);
248
+ specificAxios.interceptors.request.eject(_ColaboApiCoreService.colaboApiInterceptorId);
249
+ }
250
+ };
251
+ (0, import_i_core3.injectInterceptorService)(ColaboApiCoreService);
252
+
253
+ // lib/kContainer-service.ts
254
+ var puzzleConfig;
255
+ var ColaboKnAllEdgeContainerService = class extends CFServiceIsomorphic {
256
+ constructor(http, utilsNotificationService) {
257
+ super(utilsNotificationService);
258
+ this.http = http;
259
+ this.utilsNotificationService = utilsNotificationService;
260
+ this.defaultAction = "default";
261
+ puzzleConfig = (0, import_i_config.GetPuzzle)(MODULE_NAME);
262
+ ColaboKnAllEdgeContainerService.serverAP = puzzleConfig.serverUrl;
263
+ if (!this.http) {
264
+ if (import_i_core5.currentContext === import_i_core5.CONTEXTS.FRONTEND_ANGULAR) {
265
+ const msg = "[ColaboKnAllEdgeContainerService] DI Problem: There is no provider injected for the service `HttpClient`.";
266
+ console.error(msg);
267
+ if (this.utilsNotificationService) {
268
+ const nMsg = {
269
+ title: "DI Problem",
270
+ msg,
271
+ type: import_i_notifications3.NotificationMsgType.Error
272
+ };
273
+ this.utilsNotificationService.addNotification(nMsg);
274
+ }
275
+ } else {
276
+ console.log("[ColaboKnAllEdgeContainerService] Invited from the non-DI (non-angular) context. Initializing HttpClient ...");
277
+ this.http = new import_i_core5.HttpClient(null);
278
+ }
279
+ }
280
+ ColaboApiCoreService.initialize("ColaboKnAllEdgeContainerService", import_axios2.default);
281
+ console.log("[ColaboKnAllEdgeContainerService] created");
282
+ this.apiUrl = ColaboKnAllEdgeContainerService.serverAP + "/" + import_i_core4.KCONTAINER_API_PARAMS.API_PATH + "/";
283
+ }
284
+ getById(id) {
285
+ return __async(this, null, function* () {
286
+ let result;
287
+ const url = this.apiUrl + this.defaultAction + "/" + import_i_core4.KCONTAINER_API_TYPE.INDEX_BY_ID + "/" + id;
288
+ if (DEBUG) console.log("[getByIdPromise] url: ", url);
289
+ try {
290
+ const mResult = yield import_axios2.default.get(url);
291
+ const serverData = mResult.data;
292
+ result = import_i_core4.ColaboApiOperators.extractVoFromServerDataAsArray(serverData);
293
+ if (!result) {
294
+ return Promise.reject(new Error("Problem with extracting data as an array from serverData"));
295
+ }
296
+ if (import_i_core4.ColaboApiOperators.getParentEntity(result).type != import_i_core4.KCONTAINER_API_PARAMS.KCONTAINER_TYPE) {
297
+ return Promise.reject(new Error("Wrong entity type, expected: " + import_i_core4.KCONTAINER_API_PARAMS.KCONTAINER_TYPE));
298
+ }
299
+ } catch (error) {
300
+ console.error(error);
301
+ return Promise.reject(error);
302
+ }
303
+ return result;
304
+ });
305
+ }
306
+ create(kContainerWContent) {
307
+ return __async(this, null, function* () {
308
+ console.log("ColaboKnAllEdgeContainerService.create");
309
+ let result;
310
+ const url = this.apiUrl;
311
+ try {
312
+ const requestRoot = {
313
+ type: import_i_core4.KCONTAINER_API_TYPE.CREATE_NEW,
314
+ data: kContainerWContent
315
+ };
316
+ const mResult = yield import_axios2.default.post(url, requestRoot, HTTP_OPTIONS_CONST_JSON);
317
+ const serverData = mResult.data;
318
+ result = import_i_core4.ColaboApiOperators.extractVoFromServerData(serverData);
319
+ return result;
320
+ } catch (error) {
321
+ if (error.response) {
322
+ console.log("[create]", error);
323
+ console.warn("Response status:", error.response.status);
324
+ console.warn("Response data:", error.response.data);
325
+ if (error.response.data.code === "EMAIL_EXISTS") {
326
+ console.warn("EMAIL_EXISTS");
327
+ }
328
+ return error.response.data;
329
+ } else if (error.request) {
330
+ console.error("No response received");
331
+ } else {
332
+ console.error("[ColaboKnAllEdgeContainerService:create] Error during request setup:", error.message);
333
+ }
334
+ (0, import_i_notifications3.rethrowColaboError)(error);
335
+ throw new import_i_notifications3.ColaboErrorUnreachable();
336
+ }
337
+ });
338
+ }
339
+ update(kContainer) {
340
+ return __async(this, null, function* () {
341
+ console.log("ColaboKnAllEdgeContainerService.update");
342
+ let result;
343
+ const actionType = import_i_core4.KCONTAINER_API_TYPE.UPDATE_BY_ID;
344
+ const url = this.apiUrl + "one/" + actionType + "/" + kContainer._id;
345
+ try {
346
+ const mResult = yield import_axios2.default.put(url, kContainer, HTTP_OPTIONS_CONST_JSON);
347
+ const serverData = mResult.data;
348
+ result = import_i_core4.ColaboApiOperators.extractVoFromServerData(serverData);
349
+ } catch (error) {
350
+ console.error(error);
351
+ return Promise.reject(error);
352
+ }
353
+ return result;
354
+ });
355
+ }
356
+ /**
357
+ /**
358
+ * Deletes the IKContainer on server
359
+ * In server's response, the ServerData.data is equal to the _id of the deleted VO. ServerData.data will be equal to null, if there is no data we intended to delete. In both cases `ServerData.success` will be eq `true`
360
+ * @example URL:http://localhost:8001/knodes/one/default/5a156965d0b7970f365e1a4b.json
361
+ * @param {string} id id of the node to be deleted
362
+ * @return {*} {Promise<boolean>}
363
+ * @memberof ColaboKnAllEdgeContainerService
364
+ */
365
+ destroy(id) {
366
+ return __async(this, null, function* () {
367
+ console.log(`[destroy] id=${id}`);
368
+ const url = this.apiUrl + this.defaultAction + "/" + import_i_core4.KCONTAINER_API_TYPE.DESTROY_ONE + "/" + id;
369
+ try {
370
+ const mResult = yield import_axios2.default.delete(url, HTTP_OPTIONS_CONST_JSON);
371
+ const serverData = mResult.data;
372
+ return serverData.success;
373
+ } catch (error) {
374
+ (0, import_i_notifications3.rethrowColaboError)(error);
375
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
376
+ }
377
+ });
378
+ }
379
+ /**
380
+ * @param containerId The id of the kContainer to which we want to add kNodes
381
+ * @param containedIds The list of ids of the kNodes we want to add to the container
382
+ * @description adds kNodes in a kContainer
383
+ * @returns edges created between the container and entities added to the container
384
+ */
385
+ updateAddNodes(containerId, containedIds) {
386
+ return __async(this, null, function* () {
387
+ if (DEBUG) console.log("[ColaboKnAllEdgeContainerService::updateAddNodes(containerId, containedIds)", containerId, containedIds);
388
+ let result;
389
+ const idsStr = containedIds.join(",");
390
+ const url = this.apiUrl + this.defaultAction + "/" + import_i_core4.KCONTAINER_API_TYPE.UPDATE_ADD_KNODE_BY_IDS + "/" + containerId + "/" + idsStr;
391
+ console.log("updateAddNodes called", url);
392
+ try {
393
+ const mResult = yield import_axios2.default.put(url, {}, HTTP_OPTIONS_CONST_JSON);
394
+ const serverData = mResult.data;
395
+ result = import_i_core4.ColaboApiOperators.extractVosFromServerData(serverData);
396
+ } catch (error) {
397
+ console.error(error);
398
+ return Promise.reject(error);
399
+ }
400
+ return result;
401
+ });
402
+ }
403
+ /**
404
+ * removes kNodes from a kContainer
405
+ *
406
+ * @param id The id of the kContainer from which we want to remove kNodes
407
+ * @param ids The list of ids of the kNodes we want to remove from the container
408
+ * @returns edges created between the container and entities added to the container
409
+ */
410
+ updateRemoveNodes(id, ids) {
411
+ return __async(this, null, function* () {
412
+ console.log("[ColaboKnAllEdgeContainerService::updateRemoveNodes(id, ids)", id, ids);
413
+ let result;
414
+ const idsStr = ids.join(",");
415
+ const url = this.apiUrl + this.defaultAction + "/" + import_i_core4.KCONTAINER_API_TYPE.UPDATE_REMOVE_KNODE_BY_IDS + "/" + id + "/" + idsStr;
416
+ console.log("updateRemoveNodes called", url);
417
+ try {
418
+ const mResult = yield import_axios2.default.put(url, {}, HTTP_OPTIONS_CONST_JSON);
419
+ const serverData = mResult.data;
420
+ result = import_i_core4.ColaboApiOperators.extractVosFromServerData(serverData);
421
+ } catch (error) {
422
+ console.error(error);
423
+ return Promise.reject(error);
424
+ }
425
+ return result;
426
+ });
427
+ }
428
+ /**
429
+ *
430
+ * @param id The id of the kContainer which knodes we want to retrieve
431
+ * @description retrieves kNodes in a kContainer
432
+ */
433
+ getInContainer(id) {
434
+ return __async(this, null, function* () {
435
+ let result;
436
+ if (DEBUG) console.log(`this.apiUrl:${this.apiUrl}, this.defaultAction:${this.defaultAction}`);
437
+ const url = `http://127.0.0.1:8001/kcontainers/` + this.defaultAction + "/" + import_i_core4.KCONTAINER_API_TYPE.INDEX_IN_CONTAINER + "/" + id + ".json";
438
+ try {
439
+ const response = yield this.http.get(url).toPromise();
440
+ if (DEBUG_VERBOSE) console.log(`[ColaboKnAllEdgeContainerService::getInContainer] response`, response);
441
+ if (!response) {
442
+ return [];
443
+ }
444
+ const processedResponse = CFServiceIsomorphic.processVOs(response, import_i_core4.KNodeFrontend);
445
+ if (DEBUG_VERBOSE) console.log("[ColaboKnAllEdgeContainerService::getInContainer] response<KNodeFrontend>: ", JSON.stringify(processedResponse, null, 4));
446
+ return processedResponse;
447
+ } catch (error) {
448
+ (0, import_i_notifications3.rethrowColaboError)(error);
449
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
450
+ }
451
+ });
452
+ }
453
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
454
+ getVOs(type, upperLayerType) {
455
+ return __async(this, null, function* () {
456
+ let result;
457
+ const url = `${this.apiUrl}${this.defaultAction}/${import_i_core4.KCONTAINER_API_TYPE.INDEX_BY_TYPE}/${type}${upperLayerType ? "/" + upperLayerType : ""}.json`;
458
+ const mResult = yield import_axios2.default.get(url);
459
+ try {
460
+ const serverData = mResult.data;
461
+ result = import_i_core4.ColaboApiOperators.extractVosFromServerData(serverData);
462
+ if (!result) {
463
+ return Promise.reject(new Error("Couldn't extract VOs from the serverData"));
464
+ }
465
+ } catch (error) {
466
+ console.error(error);
467
+ return Promise.reject(error);
468
+ }
469
+ return result;
470
+ });
471
+ }
472
+ /**
473
+ * Extracts upper-layer entity from kContainer and sets it up
474
+ * @param kContainer - kContainer holding the upper-layer entity
475
+ * @param typeT - type (class) of the expected upper-layer entity
476
+ * @returns the extracted upper-layer entity
477
+ */
478
+ extractEntityFromPayload(kContainer, typeT) {
479
+ if (!kContainer.dataContent) {
480
+ console.error("[ColaboKnAllEdgeContainerService::extractEntityFromPayload] container payload (kContainer.dataContent) is missing");
481
+ }
482
+ const vo = typeT.factory(kContainer.dataContent, kContainer);
483
+ return vo;
484
+ }
485
+ /**
486
+ * Extracts upper-layer entity (`<T>`) from the lower-layer entity (`IKContainer`) and sets it up into the `<T>` entity
487
+ * @param kContainer - kContainer containing the payload of the upper-layer entity
488
+ * @param factoryOperator - the operator responsible for generating and filling in the data into the upper-layer entity (`<T>`)
489
+ * @returns the extracted upper-layer entity
490
+ */
491
+ extractEntityFromPayloadWithExternalOperators(kContainer, factoryOperator) {
492
+ if (!kContainer.dataContent) {
493
+ console.error("[ColaboKnAllEdgeContainerService::extractEntityFromPayload] container payload (kContainer.dataContent) is missing");
494
+ }
495
+ const vo = factoryOperator(kContainer.dataContent, kContainer);
496
+ return vo;
497
+ }
498
+ /**
499
+ * Extracts upper-layer entities from kContainers and sets them up
500
+ * @param kContainers - kContainer holding the upper-layer entity
501
+ * @param typeT - type (class) of the expected upper-layer entity
502
+ * @returns the extracted upper-layer entities
503
+ */
504
+ extractEntitiesFromPayload(kContainers, typeT) {
505
+ const vos = [];
506
+ if (!Array.isArray(kContainers)) return vos;
507
+ for (const kContainer of kContainers) {
508
+ vos.push(this.extractEntityFromPayload(kContainer, typeT));
509
+ }
510
+ return vos;
511
+ }
512
+ };
513
+ ColaboKnAllEdgeContainerService = __decorateClass([
514
+ (0, import_i_core5.Injectable)()
515
+ ], ColaboKnAllEdgeContainerService);
516
+
517
+ // lib/kNode-service.ts
518
+ var import_rxjs2 = require("rxjs");
519
+ var import_axios3 = __toESM(require("axios"), 1);
520
+ var import_i_notifications4 = require("@colabo-utils/i-notifications");
521
+ var import_i_core6 = require("@colabo-headless/i-core");
522
+ var import_i_core7 = require("@colabo-headless/i-core");
523
+ var import_i_core8 = require("@colabo-headless/i-core");
524
+ var import_i_core9 = require("@colabo-headless/i-core");
525
+ var import_i_config2 = require("@colabo-utils/i-config");
526
+ var import_i_core10 = require("@colabo-knalledge/i-core");
527
+ var import_i_notifications5 = require("@colabo-utils/i-notifications");
528
+ var import_i_core11 = require("@colabo-knalledge/i-core");
529
+ console.info(`[ColaboKnAllEdgeNodeService] Current context: ${import_i_core9.currentContext}`);
530
+ var class_id = 1;
531
+ var ColaboKnAllEdgeNodeService = class extends CFServiceIsomorphic {
532
+ /**
533
+ * Initializes and constructs the service
534
+ * In the case of the DI support, it receives http client and notification service
535
+ * @param http DI-ed http client (primarily in the angular environment or testing), if missing it will be created internally
536
+ * @param utilsNotificationService notification service for reporting errors, info and warnings to user, TODO: if missing, should we create a default `console.*` equivalent?
537
+ */
538
+ constructor(http, utilsNotificationService) {
539
+ super();
540
+ this.http = http;
541
+ this.utilsNotificationService = utilsNotificationService;
542
+ /** the id of the current service instance */
543
+ this.id = class_id++;
544
+ /** default API action used for standard (CRUD) calls */
545
+ this.defaultAction = "default";
546
+ ColaboApiCoreService.initialize("ColaboKnAllEdgeNodeService", import_axios3.default);
547
+ if (!this.http) {
548
+ if (import_i_core9.currentContext == import_i_core9.CONTEXTS.FRONTEND_ANGULAR) {
549
+ const msg = "DI Problem: There is no provider injected for the service `HttpClient`.";
550
+ console.error(msg);
551
+ if (this.utilsNotificationService) {
552
+ const nMsg = {
553
+ title: "DI Problem",
554
+ msg,
555
+ type: import_i_notifications5.NotificationMsgType.Error
556
+ };
557
+ this.utilsNotificationService.addNotification(nMsg);
558
+ }
559
+ } else {
560
+ this.http = new import_i_core7.HttpClient(null);
561
+ console.log(`[ColaboKnAllEdgeNodeService:${this.id}] invited from the isomorphic context. Creating and initializing vanilla HttpClient ...`);
562
+ }
563
+ }
564
+ console.log("[ColaboKnAllEdgeNodeService] created");
565
+ const puzzleConfig2 = (0, import_i_config2.GetPuzzle)(MODULE_NAME);
566
+ this.serverAP = puzzleConfig2.serverUrl;
567
+ console.log("[ColaboKnAllEdgeNodeService] connecting to backend: ", import_i_core8.chalk.bold.white(this.serverAP));
568
+ this.apiUrl = this.serverAP + "/" + import_i_core11.KNODE_API_PARAMS.API_PATH + "/";
569
+ console.log("[ColaboKnAllEdgeNodeService] REST API URL: ", import_i_core8.chalk.bold.white(this.apiUrl));
570
+ }
571
+ /**
572
+ * Get a KN Node from the server by its `id`
573
+ * @param {string} id id of the node
574
+ * @param {function} callback Function to be called when the node is retrieved
575
+ * @returns {Promise<KNodeFrontend>} the retrieved node
576
+ * @throws `ColaboError (REQUEST_BAD | DATA_MISSING | DATA_INCORRECT_FORMAT)`
577
+ */
578
+ // eslint-disable-next-line @typescript-eslint/ban-types
579
+ // OLD: getById(id: string, callback?: Function): Observable<KNodeFrontend> {
580
+ getById(id) {
581
+ return __async(this, null, function* () {
582
+ const url = this.apiUrl + "one/" + this.defaultAction + "/" + id;
583
+ console.log(`[ColaboKnAllEdgeNodeService:getById] url: ${url}`);
584
+ console.log(`[ColaboKnAllEdgeNodeService:getById] ${this.id}`);
585
+ try {
586
+ const result = yield import_axios3.default.get(url);
587
+ const data = result.data;
588
+ const kNode = this.extractVOFromDataAsArray(data, import_i_core10.KNodeFrontend);
589
+ return kNode;
590
+ } catch (e) {
591
+ if ((0, import_i_notifications4.isColaboError)(e)) {
592
+ throw e;
593
+ }
594
+ const error = e;
595
+ if (error.response) {
596
+ } else if (error.request) {
597
+ (0, import_i_notifications4.throwColaboError)(error.message, import_i_notifications4.EErrorOrigin.SYSTEM, import_i_notifications4.EColaboErrorKind.REQUEST_BAD);
598
+ } else {
599
+ console.error("[ColaboKnAllEdgeNodeService:getById] Error during request setup:");
600
+ (0, import_i_notifications4.throwColaboError)(error.message, import_i_notifications4.EErrorOrigin.SYSTEM, import_i_notifications4.EColaboErrorKind.REQUEST_BAD);
601
+ }
602
+ throw new Error("This should never be reached, but throwing just because of TS error in diagnosing unreachable end");
603
+ }
604
+ });
605
+ }
606
+ getVosWithColaboApi(request) {
607
+ return __async(this, null, function* () {
608
+ request.type = import_i_core10.KNODE_API_TYPE.INDEX_COLABO_API;
609
+ const requestSerialized = import_i_core10.ColaboApiOperators.serializeApiRequest(request);
610
+ let result = [];
611
+ const url = this.apiUrl + import_i_core10.KNODE_API_TYPE.INDEX_COLABO_API + "/" + this.defaultAction + "/" + requestSerialized + ".json";
612
+ console.log("[getVos] url: ", url);
613
+ const mResult = yield import_axios3.default.get(url);
614
+ try {
615
+ const serverData = mResult.data;
616
+ if (!serverData) return result;
617
+ result = import_i_core10.ColaboApiOperators.extractVosFromServerData(serverData);
618
+ if (!result) {
619
+ return Promise.reject(new Error("Error with extracting VOs from serverData"));
620
+ }
621
+ } catch (error) {
622
+ console.error(error);
623
+ return Promise.reject(error);
624
+ }
625
+ return result;
626
+ });
627
+ }
628
+ updateSingleWithColaboApi(request) {
629
+ return __async(this, null, function* () {
630
+ const kNodes = yield this.updateWithColaboApi(request);
631
+ if (!kNodes) throw new Error("kNodes is not defined");
632
+ if (kNodes.length <= 0) throw new Error("kNodes is empty");
633
+ return kNodes[0];
634
+ });
635
+ }
636
+ updateWithColaboApi(request) {
637
+ return __async(this, null, function* () {
638
+ var _a, _b;
639
+ request.type = import_i_core10.KNODE_API_TYPE.UPDATE_COLABO_API;
640
+ let result;
641
+ const url = this.apiUrl + import_i_core10.KNODE_API_TYPE.UPDATE_COLABO_API + ".json";
642
+ console.log("[getVos] url: ", url);
643
+ let mResult;
644
+ try {
645
+ mResult = yield import_axios3.default.put(url, request);
646
+ } catch (error) {
647
+ console.error(`${import_i_core10.contextReportText}Error updating: ${error}`);
648
+ return Promise.reject(error);
649
+ }
650
+ try {
651
+ const serverData = mResult.data;
652
+ if (!serverData.success) {
653
+ console.error(`Error updating: [code: ${(_a = serverData.error) == null ? void 0 : _a.kind}] ${(_b = serverData.error) == null ? void 0 : _b.message}`);
654
+ return Promise.reject(serverData);
655
+ }
656
+ result = import_i_core10.ColaboApiOperators.extractVosFromServerData(serverData);
657
+ if (!result) {
658
+ return Promise.reject(new Error("Error with extracting VOs from serverData"));
659
+ }
660
+ } catch (error) {
661
+ console.error(error);
662
+ return Promise.reject(error);
663
+ }
664
+ return result;
665
+ });
666
+ }
667
+ // getVOs(type:string):Observable<KNodeFrontend[]> {
668
+ // return this.queryInMapofType(ColaboKnAllEdgeNodeService.mapId,type);
669
+ // }
670
+ createSingle(kNode) {
671
+ return __async(this, null, function* () {
672
+ const kNodesCreated = yield this.create(kNode);
673
+ if (!Array.isArray(kNodesCreated) || kNodesCreated.length <= 0) throw new Error(`${(0, import_i_core10.contextReportText)()} No kNode created`);
674
+ const kNodeCreated = kNodesCreated[0];
675
+ return kNodeCreated;
676
+ });
677
+ }
678
+ /** creates a new Element (VO) */
679
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/ban-types
680
+ create(kNode, callback) {
681
+ return __async(this, null, function* () {
682
+ var _a, _b;
683
+ console.log(`${(0, import_i_core10.contextReportText)()}`);
684
+ let result;
685
+ const request = {
686
+ type: import_i_core10.KNODE_API_TYPE.CREATE_COLABO_API,
687
+ data: kNode
688
+ };
689
+ const url = this.apiUrl;
690
+ try {
691
+ const mResult = yield import_axios3.default.post(url, request, HTTP_OPTIONS_CONST_JSON);
692
+ const serverData = mResult.data;
693
+ if (!serverData.success) {
694
+ throw new Error(`${import_i_core10.contextReportText} Error creating node. [code: ${(_a = serverData.error) == null ? void 0 : _a.kind}] ${(_b = serverData.error) == null ? void 0 : _b.message}`);
695
+ }
696
+ result = import_i_core10.ColaboApiOperators.extractVoFromServerData(serverData);
697
+ } catch (error) {
698
+ (0, import_i_notifications4.rethrowColaboError)(error);
699
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
700
+ }
701
+ return result;
702
+ });
703
+ }
704
+ createWithColaboApi(request) {
705
+ return __async(this, null, function* () {
706
+ var _a, _b;
707
+ request.type = import_i_core10.KNODE_API_TYPE.CREATE_COLABO_API;
708
+ let result;
709
+ const url = this.apiUrl + import_i_core10.KNODE_API_TYPE.CREATE_COLABO_API + ".json";
710
+ console.log("[getVos] url: ", url);
711
+ let mResult;
712
+ try {
713
+ mResult = yield import_axios3.default.post(url, request);
714
+ } catch (error) {
715
+ console.error(`${import_i_core10.contextReportText}Error updating: ${error}`);
716
+ return Promise.reject(error);
717
+ }
718
+ try {
719
+ const serverData = mResult.data;
720
+ if (!serverData.success) {
721
+ console.error(`Error creating: [code: ${(_a = serverData.error) == null ? void 0 : _a.kind}] ${(_b = serverData.error) == null ? void 0 : _b.message}`);
722
+ return Promise.reject(serverData);
723
+ }
724
+ result = import_i_core10.ColaboApiOperators.extractVoFromServerData(serverData);
725
+ if (!result) {
726
+ return Promise.reject(new Error("Error with extracting VOs from serverData"));
727
+ }
728
+ } catch (error) {
729
+ console.error(error);
730
+ return Promise.reject(error);
731
+ }
732
+ return result;
733
+ });
734
+ }
735
+ /** destroys the Element (VO) with the `_id === id` */
736
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
737
+ destroy(id) {
738
+ return __async(this, null, function* () {
739
+ return true;
740
+ });
741
+ }
742
+ destroyWithColaboApi(request) {
743
+ return __async(this, null, function* () {
744
+ request.type = import_i_core10.KNODE_API_TYPE.DESTROY_COLABO_API;
745
+ const requestSerialized = import_i_core10.ColaboApiOperators.serializeApiRequest(request);
746
+ let result;
747
+ const url = this.apiUrl + import_i_core10.KNODE_API_TYPE.DESTROY_COLABO_API + "/" + this.defaultAction + "/" + requestSerialized + ".json";
748
+ console.log("[getVos] url: ", url);
749
+ const mResult = yield import_axios3.default.delete(url);
750
+ try {
751
+ const serverData = mResult.data;
752
+ result = import_i_core10.ColaboApiOperators.extractVosFromServerData(serverData);
753
+ if (!result) {
754
+ return Promise.reject(new Error("Error with extracting VOs from serverData"));
755
+ }
756
+ } catch (error) {
757
+ console.error(error);
758
+ return Promise.reject(error);
759
+ }
760
+ return result;
761
+ });
762
+ }
763
+ /** gets Elements (VOs) to populate the list */
764
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
765
+ getVOs(type) {
766
+ return (0, import_rxjs2.of)([]);
767
+ }
768
+ };
769
+ ColaboKnAllEdgeNodeService = __decorateClass([
770
+ (0, import_i_core6.Injectable)()
771
+ ], ColaboKnAllEdgeNodeService);
772
+
773
+ // lib/kNode-service-extended.ts
774
+ var import_i_core12 = require("@colabo-headless/i-core");
775
+ var import_i_core13 = require("@colabo-headless/i-core");
776
+ var import_axios4 = __toESM(require("axios"), 1);
777
+ var import_i_core14 = require("@colabo-knalledge/i-core");
778
+ var import_i_notifications6 = require("@colabo-utils/i-notifications");
779
+ var config2 = __toESM(require("@colabo-utils/i-config"), 1);
780
+ var import_i_core15 = require("@colabo-knalledge/i-core");
781
+ console.log("[ColaboKnAllEdgeNodeServiceExtended] Injectable: ", import_i_core12.Injectable);
782
+ console.log("[ColaboKnAllEdgeNodeServiceExtended] HttpClient: ", import_i_core13.HttpClient);
783
+ var ColaboKnAllEdgeNodeServiceExtended = class extends ColaboKnAllEdgeNodeService {
784
+ // protected http:HttpClient = null;
785
+ // protected utilsNotificationService: UtilsNotificationService;
786
+ constructor(http, utilsNotificationService) {
787
+ super(http, utilsNotificationService);
788
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
789
+ this.knalledgeMapQueue = null;
790
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
791
+ this.knAllEdgeRealTimeService = null;
792
+ console.log("[ColaboKnAllEdgeNodeServiceExtended:constructor] constructed");
793
+ }
794
+ queryByIds(ids, callback) {
795
+ return __async(this, null, function* () {
796
+ console.log("queryByIds", ids);
797
+ const idsStr = ids.join(",");
798
+ const url = this.apiUrl + import_i_core15.KNODE_API_TYPE.INDEX_ID_IN + "/" + this.defaultAction + "/" + idsStr + ".json";
799
+ try {
800
+ const mResult = yield import_axios4.default.get(url);
801
+ const serverData = mResult.data;
802
+ const result = CFServiceIsomorphic.processVOs(serverData, import_i_core14.KNodeFrontend);
803
+ if (callback) {
804
+ callback(result);
805
+ }
806
+ return result;
807
+ } catch (error) {
808
+ (0, import_i_notifications6.rethrowColaboError)(error);
809
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
810
+ }
811
+ });
812
+ }
813
+ /**
814
+ * BREAKING CHANGE: removed as the code is old, sending raw request to backend instead of `IApiRequest`. The right version is available in the `ColaboKnAllEdgeNodeService` class with the same name
815
+ * Creates the provided node on the server and returns its server-updated appearance
816
+ * @param {KNodeFrontend} kNode the pre-populated node to be created on the server
817
+ * @param {function} callback Function to be called when the node is created
818
+ * @returns {Observable<KNodeFrontend>} the created node (now with the id and other specific data allocated to it by server, so the caller should fill the original node with it)
819
+ @example http://localhost:8001/knodes/in_map/default/579811d88e12abfa556f6b59.json
820
+ */
821
+ // eslint-disable-next-line @typescript-eslint/ban-types
822
+ // async create(kNode: KNodeFrontend, callback?: Function): Promise<KNodeFrontend> {
823
+ // console.log(`[ColaboKnAllEdgeNodeServiceExtended.create] kNode: ${JSON.stringify(kNode, null, 4)}`);
824
+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
825
+ // let kNodeForServer: any;
826
+ // if (kNode.toServerCopy) kNodeForServer = kNode.toServerCopy();
827
+ // else kNodeForServer = kNode;
828
+ // /*
829
+ // TODO:NG2: in the line
830
+ // `result = this.http.post<KNode>(this.apiUrl, kNodeForServer, HTTP_OPTIONS_CONST_JSON)`
831
+ // we had to replace Generic type setting <KNode> with <ServerData> because it defines the return value
832
+ // (and probably the posted value), because server returns the `ServerData` object
833
+ // */
834
+ // try {
835
+ // const mResult: AxiosResponse<ServerData> = await axios.post<ServerData>(this.apiUrl, kNodeForServer, HTTP_OPTIONS_CONST_JSON);
836
+ // const serverData: ServerData = mResult.data;
837
+ // const result: KNodeFrontend = this.extractVO<KNodeFrontend>(serverData, KNodeFrontend);
838
+ // if (callback) {
839
+ // callback(result);
840
+ // }
841
+ // return result;
842
+ // } catch(error) {
843
+ // rethrowColaboError(error);
844
+ // throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
845
+ // }
846
+ // /* TODO:NG2 : remain of the NG1 Promise code to be integrated:
847
+ // let node = this.createPlain({
848
+ // //actionType:'default'
849
+ // }, kNodeForServer, function(nodeFromServer){
850
+ // kNode.$resolved = node.$resolved;
851
+ // kNode.overrideFromServer(nodeFromServer);
852
+ // if(callback) callback(kNode);
853
+ // });
854
+ // //createPlain manages promises for its returning value, in our case 'node', so we need to set its promise to the value we return
855
+ // kNode.$promise = node.$promise;
856
+ // kNode.$resolved = node.$resolved;
857
+ // if(node.$resolved){// for the case promise was resolved immediatelly (in synchonous manner) instead synchronously
858
+ // kNode.overrideFromServer(node);
859
+ // }
860
+ // */
861
+ // // }
862
+ // //we return this value to caller as a dirty one, and then set its value to nodeFromServer when upper callback is called
863
+ // }
864
+ /**
865
+ * Deletes the KNode from the server
866
+ * In server's response, the ServerData.data is equal to the _id of the deleted VO. ServerData.data will be equal to null, if there is no data we intended to delete. In both cases `ServerData.success` will be eq `true`
867
+ * @param {string} id id of the node to be deleted
868
+ * @param {function} callback Function to be called when the node is deleted
869
+ * @example URL:http://localhost:8001/knodes/one/default/5a156965d0b7970f365e1a4b.json
870
+ */
871
+ // eslint-disable-next-line @typescript-eslint/ban-types
872
+ destroy(id, callback) {
873
+ return __async(this, null, function* () {
874
+ try {
875
+ const mResult = yield import_axios4.default.delete(this.apiUrl + "one/" + this.defaultAction + "/" + id, HTTP_OPTIONS_CONST_JSON);
876
+ const serverData = mResult.data;
877
+ const result = serverData.success;
878
+ if (callback) {
879
+ callback(result);
880
+ }
881
+ return result;
882
+ } catch (error) {
883
+ (0, import_i_notifications6.rethrowColaboError)(error);
884
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
885
+ }
886
+ });
887
+ }
888
+ /**
889
+ * Updates the provided node on the server and returns its server-updated appearance
890
+ * @param {KNodeFrontend} kNode the pre-populated node to update the content of the existing node on the server
891
+ * @param {string} actionType type of the update action (e.g. UPDATE_NODE_NAME_FINAL, UPDATE_NODE_NAME)
892
+ * @param {any} patch if we provide null here, the `kNode` param is used, but if we provide here an object, it will be patched 'over' the existing node on the server
893
+ * @param {function} callback Function to be called when the node is updated
894
+ * @returns {Observable<KNodeFrontend>} the updated node (now with some specific data updated by the server, so the caller should fill the original node with it)
895
+ @example URLs: http://localhost:8001/knodes/one/UPDATE_NODE_NAME/5a156935d0b7970f365e1a42.json
896
+ http://localhost:8001/knodes/one/UPDATE_NODE_NAME_FINAL/5a156935d0b7970f365e1a42.json
897
+ */
898
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/ban-types, @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
899
+ update(kNode, actionType, patch, callback) {
900
+ return __async(this, null, function* () {
901
+ function updateResponse(nodeFromServer) {
902
+ const responseTime = /* @__PURE__ */ new Date();
903
+ }
904
+ let result;
905
+ const id = kNode._id;
906
+ const kNodeForServer = patch ? patch : kNode.toServerCopy();
907
+ actionType = actionType !== null ? actionType : ColaboKnAllEdgeNodeServiceExtended.UPDATE_NODE_NAME_FINAL;
908
+ if (kNode.state == import_i_core14.VOFrontend.STATE_LOCAL) {
909
+ window.alert(`Please, wait while the entity '${kNode.name}' is being saved, before updating it`);
910
+ result = void 0;
911
+ return result;
912
+ } else {
913
+ try {
914
+ const mResult = yield import_axios4.default.put(this.apiUrl + "one/" + actionType + "/" + id, kNodeForServer, HTTP_OPTIONS_CONST_JSON);
915
+ const serverData = mResult.data;
916
+ const result2 = this.extractVO(serverData, import_i_core14.KNodeFrontend);
917
+ if (callback) {
918
+ callback(result2);
919
+ }
920
+ return result2;
921
+ } catch (error) {
922
+ (0, import_i_notifications6.rethrowColaboError)(error);
923
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
924
+ }
925
+ }
926
+ });
927
+ }
928
+ // getVOs(type: string): Observable<KNodeFrontend[] | undefined> {
929
+ // return this.queryInMapofType(ColaboKnAllEdgeNodeServiceExtended.mapId, type);
930
+ // }
931
+ // getVOsWithPromise(type: string): Promise<IKNode[]> {
932
+ // return this.getVOs(type).toPromise() as Promise<IKNode[]>;
933
+ // }
934
+ // /**
935
+ // * Gets from the server all the KN Nodes that are contained in the map
936
+ // * @param {string} id id of the map
937
+ // * @param {function} callback Function to be called when the nodes are retrieved
938
+ // * @returns {Observable<KNodeFrontend[]>} array of the nodes
939
+ // @example http://localhost:8001/knodes/in_map/default/579811d88e12abfa556f6b59.json
940
+ // */
941
+ // queryInMap(mapId: string, callback?: Function): Observable<KNodeFrontend[] | undefined> {
942
+ // const result: Observable<KNodeFrontend[] | undefined> = this.http.get<ServerData>(this.apiUrl + "in_map/" + this.defaultAction + "/" + mapId).pipe(
943
+ // map((nodesFromServer: ServerData) => CFServiceIsomorphic.processVOs(nodesFromServer, KNodeFrontend)),
944
+ // catchError(this.handleErrorForObservable("ColaboKnAllEdgeNodeServiceExtended::queryInMap", undefined))
945
+ // );
946
+ // // I get 2 errors for the above lines:
947
+ // // 1st error:
948
+ // /*
949
+ // ../../../isomorphic/puzzles/knalledge/core-services/lib/kNode-service-extended.ts:89:9 - error TS2739: Type 'Observable<unknown>' is missing the following properties from type 'Observable<KNodeFrontend[]>': _isScalar, _trySubscribe, _subscribe
950
+ // 89 const result: Observable<KNodeFrontend[] | undefined> = this.http.get<ServerData>(this.apiUrl + "in_map/" + this.defaultAction + "/" + mapId).pipe(
951
+ // */
952
+ // //that "solve with replacing the last `);`
953
+ // //with `) as unknown as (Observable<KNodeFrontend[] | undefined>);` to enforce return type
954
+ // // ...
955
+ // // but I still cannot solve the 2nd error:
956
+ // /*
957
+ // ../../../isomorphic/puzzles/knalledge/core-services/lib/kNode-service-extended.ts:90:4 - error TS2345: Argument of type 'OperatorFunction<ServerData, KNodeFrontend[]>' is not assignable to parameter of type 'OperatorFunction<ServerData, unknown>'.
958
+ // Types of parameters 'source' and 'source' are incompatible.
959
+ // Type 'Observable<ServerData>' is missing the following properties from type 'Observable<ServerData>': _isScalar, _trySubscribe, _subscribe
960
+ // 90 map((nodesFromServer: ServerData) => CFServiceIsomorphic.processVOs(nodesFromServer, KNodeFrontend)),
961
+ // */
962
+ // if (callback) {
963
+ // result.subscribe((nodes) => callback(nodes));
964
+ // }
965
+ // return result;
966
+ // }
967
+ // /**
968
+ // * Gets from the server all the KN Nodes that are contained in the map
969
+ // * @param {string} mapId id of the map
970
+ // * @param {function} callback Function to be called when the nodes are retrieved
971
+ // * @returns {Observable<KNodeFrontend[]>} array of the nodes
972
+ // @example http://localhost:8001/knodes/in_map/default/579811d88e12abfa556f6b59.json
973
+ // */
974
+ // // eslint-disable-next-line @typescript-eslint/ban-types
975
+ // queryInMapofType(mapId: string, type: string, callback?: Function): Observable<KNodeFrontend[] | undefined> {
976
+ // const url: string = this.apiUrl + KNODE_API_TYPE.INDEX_IN_MAP_OF_TYPE + "/" + this.defaultAction + "/" + mapId + "/" + type + ".json";
977
+ // const result: Observable<KNodeFrontend[] | undefined> = this.http.get<ServerData>(url).pipe(
978
+ // map((nodesFromServer: ServerData) => CFServiceIsomorphic.processVOs(nodesFromServer, KNodeFrontend)),
979
+ // catchError(this.handleErrorForObservable("ColaboKnAllEdgeNodeServiceExtended::queryInMapofType", undefined))
980
+ // );
981
+ // if (callback) {
982
+ // result.subscribe((nodes) => callback(nodes));
983
+ // }
984
+ // return result;
985
+ // }
986
+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
987
+ // queryInMapofTypeAndContentData(mapId: string, type: string, contentDataPath: string, data: any, callback?: Function): Observable<KNodeFrontend[] | undefined> {
988
+ // console.log("queryInMapofTypeAndContentData", mapId, type, contentDataPath, data);
989
+ // const result: Observable<KNodeFrontend[] | undefined> = this.http.get<ServerData>(
990
+ // this.apiUrl + "in_map_of_type_and_content_data/" + this.defaultAction + "/" + mapId + "/" + type + "/" + contentDataPath + "/" + data + ".json"
991
+ // ).pipe(
992
+ // map((nodesFromServer: ServerData) => CFServiceIsomorphic.processVOs(nodesFromServer, KNodeFrontend)),
993
+ // catchError(this.handleErrorForObservable<KNodeFrontend[] | undefined>("ColaboKnAllEdgeNodeServiceExtended::queryInMapofTypeAndContentData", undefined))
994
+ // );
995
+ // if (callback) {
996
+ // result.subscribe((nodes) => callback(nodes));
997
+ // }
998
+ // return result;
999
+ // }
1000
+ // queryInMapofTypeForUser(mapId: string, type: string, iAmid: string, callback?: Function): Observable<KNodeFrontend[] | undefined> {
1001
+ // console.log("queryInMapofTypeForUser", mapId, type, iAmid);
1002
+ // const result: Observable<KNodeFrontend[] | undefined> = this.http.get<ServerData>(this.apiUrl + "in_map_of_type_for_user/" + this.defaultAction + "/" + mapId + "/" + type + "/" + iAmid + ".json").pipe(
1003
+ // map((nodesFromServer) => CFServiceIsomorphic.processVOs(nodesFromServer, KNodeFrontend)),
1004
+ // catchError(this.handleErrorForObservable("ColaboKnAllEdgeNodeServiceExtended::queryInMap", undefined))
1005
+ // );
1006
+ // if (callback) {
1007
+ // result.subscribe((nodes) => callback(nodes));
1008
+ // }
1009
+ // return result;
1010
+ // }
1011
+ // // eslint-disable-next-line @typescript-eslint/ban-types
1012
+ // destroyByTypeInMap(type: string, mapId: string, callback?: Function): Observable<boolean> {
1013
+ // //TODO:NG2 fix usage of this function to expect boolean
1014
+ // const result: Observable<boolean> = this.http.delete<ServerData>(this.apiUrl + "by-type-in-map/" + this.defaultAction + "/" + type + "/" + mapId + ".json", HTTP_OPTIONS_CONST_JSON).pipe(
1015
+ // tap((_) => console.log(`deleted nodes type=${type} and mapId=${mapId}`)),
1016
+ // map((serverData: ServerData) => serverData.success),
1017
+ // catchError(this.handleErrorForObservable<boolean>("destroyByTypeInMap"))
1018
+ // );
1019
+ // /* TODO:NG2
1020
+ // if(this.knAllEdgeRealTimeService){ // realtime distribution
1021
+ // //
1022
+ // // let change = new puzzles.changes.Change();
1023
+ // // change.value = null;
1024
+ // // change.valueBeforeChange = null; //TODO
1025
+ // // change.reference = id;
1026
+ // // change.type = puzzles.changes.ChangeType.STRUCTURAL;
1027
+ // // change.event = Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName;
1028
+ // // // change.action = null;
1029
+ // // change.domain = puzzles.changes.Domain.NODE;
1030
+ // // change.visibility = puzzles.changes.ChangeVisibility.ALL;
1031
+ // // change.phase = puzzles.changes.ChangePhase.UNDISPLAYED;
1032
+ // //
1033
+ // // this.knAllEdgeRealTimeService.emit(Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName, change);//{'_id':id});
1034
+ // }*/
1035
+ // if (callback) {
1036
+ // result.subscribe((success) => callback(success));
1037
+ // }
1038
+ // return result;
1039
+ // }
1040
+ // destroyByUser(iAmid: string): Observable<boolean> {
1041
+ // //TODO:NG2 fix usage of this function to expect boolean
1042
+ // const result: Observable<boolean> = this.http.delete<ServerData>(this.apiUrl + "by-user/" + this.defaultAction + "/" + iAmid + ".json", HTTP_OPTIONS_CONST_JSON).pipe(
1043
+ // tap((_: ServerData) => console.log(`deleted nodes: iAmid=${iAmid}`)),
1044
+ // map((serverData: ServerData) => serverData.success),
1045
+ // catchError(this.handleErrorForObservable<boolean>("destroyByUser"))
1046
+ // );
1047
+ // /* TODO:NG2
1048
+ // if(this.knAllEdgeRealTimeService){ // realtime distribution
1049
+ // //
1050
+ // // let change = new puzzles.changes.Change();
1051
+ // // change.value = null;
1052
+ // // change.valueBeforeChange = null; //TODO
1053
+ // // change.reference = id;
1054
+ // // change.type = puzzles.changes.ChangeType.STRUCTURAL;
1055
+ // // change.event = Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName;
1056
+ // // // change.action = null;
1057
+ // // change.domain = puzzles.changes.Domain.NODE;
1058
+ // // change.visibility = puzzles.changes.ChangeVisibility.ALL;
1059
+ // // change.phase = puzzles.changes.ChangePhase.UNDISPLAYED;
1060
+ // //
1061
+ // // this.knAllEdgeRealTimeService.emit(Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName, change);//{'_id':id});
1062
+ // }*/
1063
+ // return result;
1064
+ // }
1065
+ // // eslint-disable-next-line @typescript-eslint/ban-types
1066
+ // destroyByTypeByUser(type: string, iAmid: string, callback?: Function): Observable<boolean> {
1067
+ // //TODO:NG2 fix usage of this function to expect boolean
1068
+ // const result: Observable<boolean> = this.http.delete<ServerData>(this.apiUrl + "by-type-n-user/" + this.defaultAction + "/" + type + "/" + iAmid + ".json", HTTP_OPTIONS_CONST_JSON).pipe(
1069
+ // tap((_) => console.log(`deleted nodes type=${type} and iAmid=${iAmid}`)),
1070
+ // map((serverData: ServerData) => serverData.success),
1071
+ // catchError(this.handleErrorForObservable<boolean>("destroyByTypeByUser"))
1072
+ // );
1073
+ // /* TODO:NG2
1074
+ // if(this.knAllEdgeRealTimeService){ // realtime distribution
1075
+ // //
1076
+ // // let change = new puzzles.changes.Change();
1077
+ // // change.value = null;
1078
+ // // change.valueBeforeChange = null; //TODO
1079
+ // // change.reference = id;
1080
+ // // change.type = puzzles.changes.ChangeType.STRUCTURAL;
1081
+ // // change.event = Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName;
1082
+ // // // change.action = null;
1083
+ // // change.domain = puzzles.changes.Domain.NODE;
1084
+ // // change.visibility = puzzles.changes.ChangeVisibility.ALL;
1085
+ // // change.phase = puzzles.changes.ChangePhase.UNDISPLAYED;
1086
+ // //
1087
+ // // this.knAllEdgeRealTimeService.emit(Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName, change);//{'_id':id});
1088
+ // }*/
1089
+ // if (callback) {
1090
+ // result.subscribe((success) => callback(success));
1091
+ // }
1092
+ // return result;
1093
+ // }
1094
+ };
1095
+ // eslint-disable-next-line @typescript-eslint/no-inferrable-types
1096
+ ColaboKnAllEdgeNodeServiceExtended.mapId = config2.GetGeneral("mapId");
1097
+ ColaboKnAllEdgeNodeServiceExtended.UPDATE_NODE_NAME_FINAL = "UPDATE_NODE_NAME_FINAL";
1098
+ ColaboKnAllEdgeNodeServiceExtended.UPDATE_NODE_NAME = "UPDATE_NODE_NAME";
1099
+ ColaboKnAllEdgeNodeServiceExtended = __decorateClass([
1100
+ (0, import_i_core12.Injectable)()
1101
+ ], ColaboKnAllEdgeNodeServiceExtended);
1102
+
1103
+ // lib/kEdge-service.ts
1104
+ var import_i_core16 = require("@colabo-headless/i-core");
1105
+ var import_i_core17 = require("@colabo-headless/i-core");
1106
+ var import_i_core18 = require("@colabo-knalledge/i-core");
1107
+ var import_axios5 = __toESM(require("axios"), 1);
1108
+ var import_i_core19 = require("@colabo-headless/i-core");
1109
+ var import_i_core20 = require("@colabo-headless/i-core");
1110
+ var import_i_notifications7 = require("@colabo-utils/i-notifications");
1111
+ var KnalledgeEdgeService = class extends CFServiceIsomorphic {
1112
+ constructor(http, utilsNotificationService) {
1113
+ super(utilsNotificationService);
1114
+ this.http = http;
1115
+ this.defaultAction = "default";
1116
+ ColaboApiCoreService.initialize("ColaboKnAllEdgeNodeService", import_axios5.default);
1117
+ if (!this.http) {
1118
+ if (import_i_core20.currentContext == import_i_core20.CONTEXTS.FRONTEND_ANGULAR) {
1119
+ const msg = "DI Problem: There is no provider injected for the service `HttpClient`.";
1120
+ console.error(msg);
1121
+ if (this.utilsNotificationService) {
1122
+ const nMsg = {
1123
+ title: "DI Problem",
1124
+ msg,
1125
+ type: import_i_notifications7.NotificationMsgType.Error
1126
+ };
1127
+ this.utilsNotificationService.addNotification(nMsg);
1128
+ }
1129
+ } else {
1130
+ console.log("[KnalledgeEdgeService] invited from the isomorphic context. Initializing HttpClient ...");
1131
+ this.http = new import_i_core17.HttpClient(null);
1132
+ }
1133
+ }
1134
+ console.log("[KnalledgeEdgeService] created");
1135
+ console.log("[KnalledgeEdgeService] connecting to backend: ", import_i_core19.chalk.bold.white(KnalledgeEdgeService.serverAP));
1136
+ this.apiUrl = KnalledgeEdgeService.serverAP + "/" + import_i_core18.KEDGE_API_PARAMS.API_PATH + "/";
1137
+ console.log("[KnalledgeEdgeService] REST API URL: ", import_i_core19.chalk.bold.white(this.apiUrl));
1138
+ }
1139
+ getVosWithColaboApi(request) {
1140
+ return __async(this, null, function* () {
1141
+ request.type = import_i_core18.KEDGE_API_TYPE.INDEX_COLABO_API;
1142
+ console.log(`[KnalledgeEdgeService.getVosWithColaboApi] request: ${JSON.stringify(request, null, 4)}`);
1143
+ const requestSerialized = import_i_core18.ColaboApiOperators.serializeApiRequest(request);
1144
+ let result;
1145
+ const url = this.apiUrl + import_i_core18.KEDGE_API_TYPE.INDEX_COLABO_API + "/" + requestSerialized + ".json";
1146
+ console.log("[getVos] url: ", url);
1147
+ const mResult = yield import_axios5.default.get(url);
1148
+ try {
1149
+ const serverData = mResult.data;
1150
+ result = import_i_core18.ColaboApiOperators.extractVosFromServerData(serverData);
1151
+ if (!result) {
1152
+ return Promise.reject(new Error("Error with extracting VOs from serverData"));
1153
+ }
1154
+ } catch (error) {
1155
+ console.error(error);
1156
+ return Promise.reject(error);
1157
+ }
1158
+ return result;
1159
+ });
1160
+ }
1161
+ /** creates a new Element (VO) */
1162
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/ban-types
1163
+ createWithPromise(kEdge, callback) {
1164
+ return __async(this, null, function* () {
1165
+ var _a, _b;
1166
+ console.log(`${(0, import_i_core18.contextReportText)()}`);
1167
+ let result;
1168
+ const request = {
1169
+ type: import_i_core18.KEDGE_API_TYPE.CREATE_COLABO_API,
1170
+ data: kEdge
1171
+ };
1172
+ const url = this.apiUrl;
1173
+ try {
1174
+ const mResult = yield import_axios5.default.post(url, request, HTTP_OPTIONS_CONST_JSON);
1175
+ const serverData = mResult.data;
1176
+ if (!serverData.success) {
1177
+ throw new Error(`${import_i_core18.contextReportText} Error creating edge. code: ${(_a = serverData.error) == null ? void 0 : _a.kind}, error msg: ${(_b = serverData.error) == null ? void 0 : _b.message}`);
1178
+ }
1179
+ result = import_i_core18.ColaboApiOperators.extractVoFromServerData(serverData);
1180
+ } catch (error) {
1181
+ console.error(error);
1182
+ return Promise.reject(error);
1183
+ }
1184
+ return result;
1185
+ });
1186
+ }
1187
+ /** creates a new Element (VO) */
1188
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/ban-types
1189
+ createWithRequest(request) {
1190
+ return __async(this, null, function* () {
1191
+ var _a, _b;
1192
+ console.log(`${(0, import_i_core18.contextReportText)()}`);
1193
+ let result;
1194
+ const url = this.apiUrl;
1195
+ try {
1196
+ const mResult = yield import_axios5.default.post(url, request, HTTP_OPTIONS_CONST_JSON);
1197
+ const serverData = mResult.data;
1198
+ if (!serverData.success) {
1199
+ throw new Error(`${import_i_core18.contextReportText} Error creating edge. code: ${(_a = serverData.error) == null ? void 0 : _a.kind}, error msg: ${(_b = serverData.error) == null ? void 0 : _b.message}`);
1200
+ }
1201
+ result = import_i_core18.ColaboApiOperators.extractVoFromServerData(serverData);
1202
+ } catch (error) {
1203
+ console.error(error);
1204
+ return Promise.reject(error);
1205
+ }
1206
+ return result;
1207
+ });
1208
+ }
1209
+ };
1210
+ KnalledgeEdgeService = __decorateClass([
1211
+ (0, import_i_core16.Injectable)()
1212
+ ], KnalledgeEdgeService);
1213
+
1214
+ // lib/kEdge-service-extended.ts
1215
+ var import_i_core21 = require("@colabo-headless/i-core");
1216
+ var import_i_core22 = require("@colabo-knalledge/i-core");
1217
+ var import_axios6 = __toESM(require("axios"), 1);
1218
+ var import_i_notifications8 = require("@colabo-utils/i-notifications");
1219
+ var KnalledgeEdgeServiceExtended = class extends KnalledgeEdgeService {
1220
+ constructor(http, utilsNotificationService) {
1221
+ super(http, utilsNotificationService);
1222
+ //http://api.colabo.space/kedges/
1223
+ // "http://127.0.0.1:888/kedges/";
1224
+ //private defaultAction:string = 'default'; not used here - only for nodes is used
1225
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1226
+ this.knalledgeMapQueue = null;
1227
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1228
+ this.knAllEdgeRealTimeService = null;
1229
+ console.log("KnalledgeEdgeServiceExtended:: constructor");
1230
+ }
1231
+ /**
1232
+ * Gets an KN Edge from the server by its id
1233
+ * @param {string} id id of the edge
1234
+ * @param {function} callback Function to be called when the edge is retrieved
1235
+ * @returns {Observable<KEdge>} retrieved edge
1236
+ */
1237
+ // eslint-disable-next-line @typescript-eslint/ban-types
1238
+ getById(id, callback) {
1239
+ return __async(this, null, function* () {
1240
+ console.log("getById(" + id + ")");
1241
+ const url = this.apiUrl + "one/" + id;
1242
+ try {
1243
+ const mResult = yield import_axios6.default.get(url);
1244
+ const serverData = mResult.data;
1245
+ const result = this.extractVO(serverData, import_i_core22.KEdgeFrontend);
1246
+ if (callback) {
1247
+ callback(result);
1248
+ }
1249
+ return result;
1250
+ } catch (error) {
1251
+ (0, import_i_notifications8.rethrowColaboError)(error);
1252
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
1253
+ }
1254
+ });
1255
+ }
1256
+ /**
1257
+ * Creates the provided edge on the server and returns its server-updated appearance
1258
+ * @param {KEdge} kEdge the pre-populated edge to be created on the server
1259
+ * @param {function} callback Function to be called when the edge is created
1260
+ * @returns {Observable<KEdge>} the created edge (now with the id and other specific data allocated to it by server, so the caller should fill the original edge with it)
1261
+ @example http://localhost:8001/kedges/in_map/default/579811d88e12abfa556f6b59.json
1262
+ */
1263
+ create(kEdge, callback) {
1264
+ return __async(this, null, function* () {
1265
+ let result;
1266
+ if (false) {
1267
+ } else {
1268
+ if (!kEdge.toServerCopy) {
1269
+ throw new Error("kEdge.toServerCopy is not defined");
1270
+ }
1271
+ const kEdgeForServer = kEdge.toServerCopy();
1272
+ try {
1273
+ const mResult = yield import_axios6.default.post(this.apiUrl, kEdgeForServer, HTTP_OPTIONS_CONST_JSON);
1274
+ const serverData = mResult.data;
1275
+ const result2 = this.extractVO(serverData, import_i_core22.KEdgeFrontend);
1276
+ if (callback) {
1277
+ callback(result2);
1278
+ }
1279
+ return result2;
1280
+ } catch (error) {
1281
+ (0, import_i_notifications8.rethrowColaboError)(error);
1282
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
1283
+ }
1284
+ }
1285
+ });
1286
+ }
1287
+ /**
1288
+ * Deletes the KEdge from the server
1289
+ * In server's response, the ServerData.data is equal to the _id of the deleted VO. ServerData.data will be equal to null, if there is no data we intended to delete. In both cases `ServerData.success` will be eq `true`
1290
+ * @param {string} id id of the edge to be deleted
1291
+ * @param {function} callback Function to be called when the edge is deleted
1292
+ * @example URL:http://localhost:8001/kedges/one/default/5a156965d0b7970f365e1a4b.json
1293
+ */
1294
+ destroy(id, callback) {
1295
+ return __async(this, null, function* () {
1296
+ try {
1297
+ const mResult = yield import_axios6.default.delete(this.apiUrl + "one/" + id, HTTP_OPTIONS_CONST_JSON);
1298
+ const serverData = mResult.data;
1299
+ const result = serverData.success;
1300
+ if (callback) {
1301
+ callback(result);
1302
+ }
1303
+ return result;
1304
+ } catch (error) {
1305
+ (0, import_i_notifications8.rethrowColaboError)(error);
1306
+ throw new Error("This should never be reached, but throwing because TS misses seeing `rethrowColaboError` as `never`");
1307
+ }
1308
+ });
1309
+ }
1310
+ // /*
1311
+ // TODO:
1312
+ // When needed, we could develop these functions that are already supported on backend:
1313
+ // //gets all edges between 2 specific nodes:
1314
+ // queryBetween(sourceId:string, targetId:string, callback?:Function)
1315
+ // {
1316
+ // // return this.queryPlain({ searchParam:id, type:'between' }, callback);
1317
+ // }
1318
+ // //gets all edges connected to the specific node (with the provided id) (both those edges whose it's source node and those whose this is a target node)
1319
+ // // @example URL: URL:http://localhost:8001/kedges/connected/5a156965d0b7970f365e1a4b.json
1320
+ // queryConnected(id:string, callback?:Function)
1321
+ // {
1322
+ // // return this.queryPlain({ searchParam:id, type:'connected' }, callback);
1323
+ // }
1324
+ // //destroys all the edges connected to the specific node
1325
+ // //destroyConnected(id:string)
1326
+ // {
1327
+ // }
1328
+ // */
1329
+ // /**
1330
+ // * Gets from the server all the KN Edges that are contained in the map
1331
+ // * @param {string} id id of the map
1332
+ // * @param {function} callback Function to be called when the edges are retrieved
1333
+ // * @returns {Observable<KEdge[]>} array of the edges
1334
+ // @example URL: http://localhost:8001/kedges/in_map/579811d88e12abfa556f6b59.json
1335
+ // */
1336
+ // // eslint-disable-next-line @typescript-eslint/ban-types
1337
+ // queryInMap(id: string, callback?: Function): Observable<KEdge[] | undefined> {
1338
+ // const result: Observable<KEdge[] | undefined> = this.http.get<ServerData>(this.apiUrl + "in_map/" + id).pipe(
1339
+ // map((edgesS: ServerData) => CFServiceIsomorphic.processVOs<KEdge>(edgesS, KEdge)),
1340
+ // // map(edgesFromServer => CFServiceIsomorphic.processVOs<KEdge>(edgesFromServer, KEdge)),
1341
+ // catchError(this.handleErrorForObservable("KnalledgeEdgeService::queryInMap", undefined))
1342
+ // );
1343
+ // if (callback) {
1344
+ // result.subscribe((edges) => callback(edges));
1345
+ // }
1346
+ // return result;
1347
+ // }
1348
+ // /**
1349
+ // * UNSUPPORTED TEMPORARILY #551 (https://github.com/Cha-OS/colabo/issues/551)
1350
+ // * Gets from the server all the KN Edges that are contained in the map
1351
+ // * @param {string} id id of the map
1352
+ // * @param {function} callback Function to be called when the edges are retrieved
1353
+ // * @returns {Observable<KEdge[]>} array of the edges
1354
+ // @example URL: TBD
1355
+ // //
1356
+ // queryForMapTypeUserWTargetNodes(mapId:string, type:string, iAmid:string=null): Observable<KEdge[]>
1357
+ // {
1358
+ // var result:Observable<KEdge[]> = this.http.get<ServerData>(this.apiUrl+'for_map_type_user_w_target_nodes/'+mapId+'/'+type+'/'+iAmid+'.json')
1359
+ // .pipe(
1360
+ // map(edgesFromServer => CFServiceIsomorphic.processVOs(edgesFromServer, KEdge)),
1361
+ // catchError(this.handleError('KnalledgeEdgeService::queryForMapTypeUserWTargetNodes', null))
1362
+ // );
1363
+ // return result;
1364
+ // }
1365
+ // */
1366
+ // /**
1367
+ // * Gets from the server all the KN Edges that are contained in the map
1368
+ // * @param {string} id id of the map
1369
+ // * @param {function} callback Function to be called when the edges are retrieved
1370
+ // * @returns {Observable<KEdge[]>} array of the edges
1371
+ // @example URL: TBD
1372
+ // */
1373
+ // queryForMapTypeUser(mapId: string, type: string, iAmid: string = ""): Observable<KEdge[] | undefined> {
1374
+ // const result: Observable<KEdge[] | undefined> = this.http.get<ServerData>(this.apiUrl + "for_map_type_user/" + mapId + "/" + type + "/" + iAmid + ".json").pipe(
1375
+ // map((edgesFromServer: ServerData) => CFServiceIsomorphic.processVOs<KEdge>(edgesFromServer, KEdge)),
1376
+ // catchError(this.handleErrorForObservable("KnalledgeEdgeService::queryForMapTypeUser", undefined))
1377
+ // );
1378
+ // return result;
1379
+ // }
1380
+ /**
1381
+ * Gets from the server all the KN Edges that are contained in the map
1382
+ * @param {string} id id of the map
1383
+ * @param {function} callback Function to be called when the edges are retrieved
1384
+ * @returns {Observable<KEdge[]>} array of the edges
1385
+ @example URL: TBD
1386
+ */
1387
+ // queryFromToForType(from: string | null, to: string, type: string = ""): Observable<KEdge[] | undefined> {
1388
+ // const result: Observable<KEdge[] | undefined> = this.http.get<ServerData>(this.apiUrl + "from_to_for_type/" + from + "/" + to + "/" + type + ".json").pipe(
1389
+ // map((edgesFromServer: ServerData) => CFServiceIsomorphic.processVOs<KEdge>(edgesFromServer, KEdge)),
1390
+ // catchError(this.handleErrorForObservable("KnalledgeEdgeService::queryForMapTypeUser", undefined))
1391
+ // );
1392
+ // return result;
1393
+ // }
1394
+ // public destroyInMap(mapid: string, callback?: Function): Observable<boolean> {
1395
+ // //TODO:NG2 fix usage of this function to expect boolean
1396
+ // const result: Observable<boolean> = this.http.delete<ServerData>(this.apiUrl + "in-map/" + mapid, HTTP_OPTIONS_CONST_JSON).pipe(
1397
+ // tap((_) => console.log(`deleted edges for mapid=${mapid}`)),
1398
+ // map((serverData) => serverData.success),
1399
+ // catchError(this.handleErrorForObservable<boolean>("destroy"))
1400
+ // );
1401
+ // if (callback) {
1402
+ // result.subscribe((success) => callback(success));
1403
+ // }
1404
+ // return result;
1405
+ // }
1406
+ // /**
1407
+ // * @description BACKEND NOT FINISHED!
1408
+ // */
1409
+ // private destroyByTypeInMap(type: string, mapId: string): Observable<boolean> {
1410
+ // //TODO:NG2 fix usage of this function to expect boolean
1411
+ // const result: Observable<boolean> = this.http.delete<ServerData>(this.apiUrl + "by-type-in-map/" + type + "/" + mapId + ".json", HTTP_OPTIONS_CONST_JSON).pipe(
1412
+ // tap((_) => console.log(`deleted nodes type=${type} and mapId=${mapId}`)),
1413
+ // map((serverData) => serverData.success),
1414
+ // catchError(this.handleErrorForObservable<boolean>("destroyByTypeInMap"))
1415
+ // );
1416
+ // /* TODO:NG2
1417
+ // if(this.knAllEdgeRealTimeService){ // realtime distribution
1418
+ // //
1419
+ // // let change = new puzzles.changes.Change();
1420
+ // // change.value = null;
1421
+ // // change.valueBeforeChange = null; //TODO
1422
+ // // change.reference = id;
1423
+ // // change.type = puzzles.changes.ChangeType.STRUCTURAL;
1424
+ // // change.event = Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName;
1425
+ // // // change.action = null;
1426
+ // // change.domain = puzzles.changes.Domain.NODE;
1427
+ // // change.visibility = puzzles.changes.ChangeVisibility.ALL;
1428
+ // // change.phase = puzzles.changes.ChangePhase.UNDISPLAYED;
1429
+ // //
1430
+ // // this.knAllEdgeRealTimeService.emit(Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName, change);//{'_id':id});
1431
+ // }*/
1432
+ // return result;
1433
+ // }
1434
+ // destroyByTypeByUser(type: string, iAmid: string, callback?: Function): Observable<boolean> {
1435
+ // //TODO:NG2 fix usage of this function to expect boolean
1436
+ // const result: Observable<boolean> = this.http.delete<ServerData>(this.apiUrl + "by-type-n-user/" + type + "/" + iAmid, HTTP_OPTIONS_CONST_JSON).pipe(
1437
+ // tap((_) => console.log(`deleted edges type=${type} and iAmid=${iAmid}`)),
1438
+ // map((serverData) => serverData.success),
1439
+ // catchError(this.handleErrorForObservable<boolean>("destroyByTypeByUser"))
1440
+ // );
1441
+ // /* TODO:NG2
1442
+ // if(this.knAllEdgeRealTimeService){ // realtime distribution
1443
+ // //
1444
+ // // let change = new puzzles.changes.Change();
1445
+ // // change.value = null;
1446
+ // // change.valueBeforeChange = null; //TODO
1447
+ // // change.reference = id;
1448
+ // // change.type = puzzles.changes.ChangeType.STRUCTURAL;
1449
+ // // change.event = Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName;
1450
+ // // // change.action = null;
1451
+ // // change.domain = puzzles.changes.Domain.NODE;
1452
+ // // change.visibility = puzzles.changes.ChangeVisibility.ALL;
1453
+ // // change.phase = puzzles.changes.ChangePhase.UNDISPLAYED;
1454
+ // //
1455
+ // // this.knAllEdgeRealTimeService.emit(Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName, change);//{'_id':id});
1456
+ // }*/
1457
+ // if (callback) {
1458
+ // result.subscribe((success) => callback(success));
1459
+ // }
1460
+ // return result;
1461
+ // }
1462
+ // destroyByUser(iAmid: string): Observable<boolean> {
1463
+ // //TODO:NG2 fix usage of this function to expect boolean
1464
+ // const result: Observable<boolean> = this.http.delete<ServerData>(this.apiUrl + "by-user/" + iAmid, HTTP_OPTIONS_CONST_JSON).pipe(
1465
+ // tap((_) => console.log(`deleted nodes: iAmid=${iAmid}`)),
1466
+ // map((serverData) => serverData.success),
1467
+ // catchError(this.handleErrorForObservable<boolean>("destroyByUser"))
1468
+ // );
1469
+ // /* TODO:NG2
1470
+ // if(this.knAllEdgeRealTimeService){ // realtime distribution
1471
+ // //
1472
+ // // let change = new puzzles.changes.Change();
1473
+ // // change.value = null;
1474
+ // // change.valueBeforeChange = null; //TODO
1475
+ // // change.reference = id;
1476
+ // // change.type = puzzles.changes.ChangeType.STRUCTURAL;
1477
+ // // change.event = Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName;
1478
+ // // // change.action = null;
1479
+ // // change.domain = puzzles.changes.Domain.NODE;
1480
+ // // change.visibility = puzzles.changes.ChangeVisibility.ALL;
1481
+ // // change.phase = puzzles.changes.ChangePhase.UNDISPLAYED;
1482
+ // //
1483
+ // // this.knAllEdgeRealTimeService.emit(Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName, change);//{'_id':id});
1484
+ // }*/
1485
+ // return result;
1486
+ // }
1487
+ // destroyEdgesToChild(targetId: string): Observable<boolean> {
1488
+ // //TODO:NG2 fix usage of this function to expect boolean
1489
+ // const result: Observable<boolean> = this.http.delete<ServerData>(this.apiUrl + "edges-to-child/" + targetId, HTTP_OPTIONS_CONST_JSON).pipe(
1490
+ // // tap(_ => console.log(`deleted edges type=${type} and iAmid=${iAmid}`)),
1491
+ // map((serverData) => serverData.success),
1492
+ // catchError(this.handleErrorForObservable<boolean>("destroyEdgeToChild"))
1493
+ // );
1494
+ // /* TODO:NG2
1495
+ // if(this.knAllEdgeRealTimeService){ // realtime distribution
1496
+ // //
1497
+ // // let change = new puzzles.changes.Change();
1498
+ // // change.value = null;
1499
+ // // change.valueBeforeChange = null; //TODO
1500
+ // // change.reference = id;
1501
+ // // change.type = puzzles.changes.ChangeType.STRUCTURAL;
1502
+ // // change.event = Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName;
1503
+ // // // change.action = null;
1504
+ // // change.domain = puzzles.changes.Domain.NODE;
1505
+ // // change.visibility = puzzles.changes.ChangeVisibility.ALL;
1506
+ // // change.phase = puzzles.changes.ChangePhase.UNDISPLAYED;
1507
+ // //
1508
+ // // this.knAllEdgeRealTimeService.emit(Plugins.puzzles.knalledgeMap.config.services.KnRealTimeEdgeDeletedEventName, change);//{'_id':id});
1509
+ // }*/
1510
+ // return result;
1511
+ // }
1512
+ };
1513
+ KnalledgeEdgeServiceExtended = __decorateClass([
1514
+ (0, import_i_core21.Injectable)()
1515
+ ], KnalledgeEdgeServiceExtended);
1516
+ //# sourceMappingURL=index.js.map