dbm-graph-api 1.1.31 → 1.1.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm-graph-api",
3
- "version": "1.1.31",
3
+ "version": "1.1.33",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "@aws-sdk/client-s3": "^3.741.0",
15
15
  "@aws-sdk/s3-request-presigner": "^3.741.0",
16
- "dbm": "^1.2.1",
16
+ "dbm": "^1.2.3",
17
17
  "mime": "^4.0.6",
18
18
  "sharp": "^0.33.5",
19
19
  "ws": "^8.18.0"
@@ -114,7 +114,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
114
114
  console.error(theError);
115
115
  }
116
116
 
117
- this._webSocket.send(JSON.stringify({"type": "range/response", "ids": ids, "requestId": data["requestId"], "logs": logs}));
117
+ this._sendData({"type": "range/response", "ids": ids, "requestId": data["requestId"], "logs": logs});
118
118
  break;
119
119
  case "data":
120
120
  {
@@ -128,7 +128,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
128
128
  returnData = await dataFunctionItem.controller.getData(data['data'], encodeSession);
129
129
  }
130
130
 
131
- this._webSocket.send(JSON.stringify({"type": "data/response", "data": returnData, "requestId": data["requestId"]}));
131
+ this._sendData({"type": "data/response", "data": returnData, "requestId": data["requestId"]});
132
132
  }
133
133
  break;
134
134
  case "action":
@@ -151,7 +151,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
151
151
  console.error(theError);
152
152
  }
153
153
 
154
- this._webSocket.send(JSON.stringify({"type": "data/response", "data": returnData, "requestId": data["requestId"], "logs": logs}));
154
+ this._sendData({"type": "data/response", "data": returnData, "requestId": data["requestId"], "logs": logs});
155
155
  }
156
156
  break;
157
157
  case "item":
@@ -162,11 +162,19 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
162
162
  let encodeSession = new DbmGraphApi.range.EncodeSession();
163
163
  encodeSession.outputController = this;
164
164
 
165
- await encodeSession.encodeSingleWithTypes(id, data.encode);
165
+ let logs = [];
166
+
167
+ try {
168
+ await encodeSession.encodeSingleWithTypes(id, data.encode);
169
+ }
170
+ catch(theError) {
171
+ logs.push(theError.message);
172
+ console.error(theError);
173
+ }
166
174
 
167
175
  encodeSession.destroy();
168
176
 
169
- this._webSocket.send(JSON.stringify({"type": "item/response", "id": id, "requestId": data["requestId"]}));
177
+ this._sendData({"type": "item/response", "id": id, "requestId": data["requestId"], "logs": logs});
170
178
  }
171
179
  break;
172
180
  case "url":
@@ -188,10 +196,10 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
188
196
 
189
197
  await encodeSession.encodeSingleWithTypes(urlObject.id, ["urlRequest"]);
190
198
  encodeSession.destroy();
191
- this._webSocket.send(JSON.stringify({"type": "url/response", "id": urlObject.id, "requestId": data["requestId"]}));
199
+ this._sendData({"type": "url/response", "id": urlObject.id, "requestId": data["requestId"]});
192
200
  }
193
201
  else {
194
- this._webSocket.send(JSON.stringify({"type": "url/response", "id": 0, "requestId": data["requestId"]}));
202
+ this._sendData({"type": "url/response", "id": 0, "requestId": data["requestId"]});
195
203
  }
196
204
  }
197
205
  break;
@@ -230,7 +238,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
230
238
  }
231
239
 
232
240
 
233
- this._webSocket.send(JSON.stringify({"type": "item/response", "id": returnId, "requestId": data["requestId"]}));
241
+ this._sendData({"type": "item/response", "id": returnId, "requestId": data["requestId"]});
234
242
  }
235
243
  break;
236
244
  case "admin/editObject":
@@ -260,7 +268,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
260
268
  }
261
269
 
262
270
 
263
- this._webSocket.send(JSON.stringify({"type": "item/response", "id": theObject.id, "requestId": data["requestId"]}));
271
+ this._sendData({"type": "item/response", "id": theObject.id, "requestId": data["requestId"]});
264
272
  }
265
273
  break;
266
274
  case "user/signInWithToken":
@@ -279,19 +287,29 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
279
287
  this.item.setValue("user", user);
280
288
  }
281
289
 
282
- this._webSocket.send(JSON.stringify({"type": "currentUser/response", "id": userId, "requestId": data["requestId"]}));
283
-
290
+ this._sendData({"type": "currentUser/response", "id": userId, "requestId": data["requestId"]});
284
291
  }
285
292
  break;
286
293
  case "heartbeat":
287
294
  {
288
- this._webSocket.send(JSON.stringify({"type": "heartbeat/response"}));
289
-
295
+ this._sendData({"type": "heartbeat/response"});
290
296
  }
291
297
  break;
292
298
  }
293
299
  }
294
300
 
301
+ _sendData(aData) {
302
+ if(this._webSocket) {
303
+ let encodedData = JSON.stringify(aData);
304
+ try {
305
+ this._webSocket.send(encodedData);
306
+ }
307
+ catch(theError) {
308
+ console.error();
309
+ }
310
+ }
311
+ }
312
+
295
313
  _callback_error(aMessage) {
296
314
  console.log("_callback_error");
297
315
  console.error(aMessage);
@@ -328,7 +346,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
328
346
  outputEncodedData(aId, aData, aEncoding) {
329
347
  //console.log("WebSocketConnection::outputEncodedData");
330
348
 
331
- this._webSocket.send(JSON.stringify({"type": "updateEncodedObject", "id": aId, "data": aData, "encoding": aEncoding}));
349
+ this._sendData({"type": "updateEncodedObject", "id": aId, "data": aData, "encoding": aEncoding});
332
350
 
333
351
  }
334
352
 
@@ -344,7 +362,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
344
362
  this.item.setValue("user", null);
345
363
  }
346
364
 
347
- this._webSocket.send(JSON.stringify({"type": "connectionReady", "user": aId}));
365
+ this._sendData({"type": "connectionReady", "user": aId});
348
366
  }
349
367
 
350
368
  async getUser() {
@@ -11,6 +11,7 @@ export default class AddAndProcessAction extends Dbm.core.BaseObject {
11
11
  await aEncodeSession.outputController.requireRole("admin");
12
12
  let user = await aEncodeSession.outputController.getUser();
13
13
 
14
+ //METODO: check role
14
15
  if(user) {
15
16
  let type = aData["type"];
16
17
 
@@ -6,44 +6,40 @@ export default class AddUser extends Dbm.core.BaseObject {
6
6
  }
7
7
 
8
8
  async performAction(aData, aEncodeSession) {
9
- console.log("AddUser");
9
+ //console.log("AddUser");
10
10
  let returnObject = {};
11
11
 
12
12
  await aEncodeSession.outputController.requireRole("admin");
13
- let user = await aEncodeSession.outputController.getUser();
14
13
 
15
14
  let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
16
15
 
17
- if(user) {
18
- let username = aData["username"];
16
+ let username = aData["username"];
19
17
 
20
- if(username) {
21
- let user = await database.getUserByUsername(username);
18
+ if(username) {
19
+ let user = await database.getUserByUsername(username);
22
20
 
23
- if(!user) {
24
- user = await database.createUser();
25
- returnObject["created"] = true;
21
+ if(!user) {
22
+ user = await database.createUser();
23
+ returnObject["created"] = true;
26
24
 
27
- await user.setUsername(username);
28
- if(aData["password"]) {
29
- await user.setPassword(aData["password"]);
30
- }
31
-
32
- if(aData["role"]) {
33
- let role = await database.getIdentifiableObject("type/userRole", aData["role"]);
34
- await user.addIncomingRelation(role, "for");
35
- }
36
- }
37
- else {
38
- returnObject["created"] = false;
25
+ await user.setUsername(username);
26
+ if(aData["password"]) {
27
+ await user.setPassword(aData["password"]);
39
28
  }
40
29
 
41
- returnObject["id"] = user.id;
30
+ if(aData["role"]) {
31
+ let role = await database.getIdentifiableObject("type/userRole", aData["role"]);
32
+ await user.addIncomingRelation(role, "for");
33
+ }
42
34
  }
43
35
  else {
44
- throw("No username");
36
+ returnObject["created"] = false;
45
37
  }
46
-
38
+
39
+ returnObject["id"] = user.id;
40
+ }
41
+ else {
42
+ throw("No username");
47
43
  }
48
44
 
49
45
  return returnObject;
@@ -0,0 +1,35 @@
1
+ import Dbm from "dbm";
2
+
3
+ export default class SetPassword extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ async performAction(aData, aEncodeSession) {
9
+ //console.log("SetPassword");
10
+ let returnObject = {};
11
+
12
+ await aEncodeSession.outputController.requireRole("admin");
13
+
14
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
15
+
16
+ let id = aData["id"];
17
+
18
+ if(id) {
19
+ let user = await database.getUser(id);
20
+
21
+ if(user) {
22
+ await user.setPassword(aData["password"]);
23
+ returnObject["updated"] = true;
24
+ }
25
+ else {
26
+ throw("No user");
27
+ }
28
+ }
29
+ else {
30
+ throw("No id");
31
+ }
32
+
33
+ return returnObject;
34
+ }
35
+ }
@@ -1,4 +1,5 @@
1
1
  export {default as AddAndProcessAction} from "./AddAndProcessAction.js";
2
2
  export {default as AddUser} from "./AddUser.js";
3
+ export {default as SetPassword} from "./SetPassword.js";
3
4
 
4
5
  export * as setup from "./setup/index.js";
@@ -7,6 +7,6 @@ export default class ReplaceOutgoingRelation extends EditBaseObject {
7
7
  }
8
8
 
9
9
  async performChange(aObject, aData, aRequest) {
10
- await aObject.replaceOutgoingRelation(aData["value"], aData["type"]), aData["objectType"];
10
+ await aObject.replaceOutgoingRelation(aData["value"], aData["type"], aData["objectType"]);
11
11
  }
12
12
  }
@@ -0,0 +1,12 @@
1
+ import Dbm from "dbm";
2
+ import EditBaseObject from "./EditBaseObject.js";
3
+
4
+ export default class SetFieldTranslation extends EditBaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ async performChange(aObject, aData, aRequest) {
10
+ await aObject.updateFieldTranslation(aData["field"], aData["language"], aData["value"]);
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import Dbm from "dbm";
2
+ import EditBaseObject from "./EditBaseObject.js";
3
+
4
+ export default class Trash extends EditBaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ async performChange(aObject, aData, aRequest) {
10
+ await aObject.trash();
11
+ }
12
+ }
@@ -15,6 +15,8 @@ export {default as ReplaceMultipleOutgoingRelations} from "./ReplaceMultipleOutg
15
15
  export {default as AddObjectType} from "./AddObjectType.js";
16
16
  export {default as RemoveObjectType} from "./RemoveObjectType.js";
17
17
  export {default as AddAction} from "./AddAction.js";
18
+ export {default as SetFieldTranslation} from "./SetFieldTranslation.js";
19
+ export {default as Trash} from "./Trash.js";
18
20
 
19
21
 
20
22
  export const fullSetup = function() {
@@ -102,4 +104,16 @@ export const fullSetup = function() {
102
104
  let currentSelect = new DbmGraphApi.admin.edit.AddAction();
103
105
  currentSelect.item.register(prefix + name);
104
106
  }
107
+
108
+ {
109
+ let name = "setFieldTranslation";
110
+ let currentSelect = new DbmGraphApi.admin.edit.SetFieldTranslation();
111
+ currentSelect.item.register(prefix + name);
112
+ }
113
+
114
+ {
115
+ let name = "trash";
116
+ let currentSelect = new DbmGraphApi.admin.edit.Trash();
117
+ currentSelect.item.register(prefix + name);
118
+ }
105
119
  }
@@ -73,6 +73,12 @@ let registerEncoding = function(aName, aEncoder) {
73
73
 
74
74
  export {registerEncoding};
75
75
 
76
+ let registerEncodingClass = function(aEncoderClass) {
77
+ return registerEncoding(aEncoderClass.DEFAULT_ENCODING_NAME, new aEncoderClass());
78
+ }
79
+
80
+ export {registerEncodingClass};
81
+
76
82
  let fullEncodeSetup = function() {
77
83
  let encodePrefix = "graphApi/range/encode/";
78
84
  {
@@ -213,6 +219,13 @@ let fullEncodeSetup = function() {
213
219
  registerEncoding("mainImage", new DbmGraphApi.range.encode.MainImage());
214
220
  registerEncoding("linkPreview", new DbmGraphApi.range.encode.LinkPreview());
215
221
  registerEncoding("publishDate", new DbmGraphApi.range.encode.PublishDate());
222
+
223
+ registerEncoding("title_translations", new DbmGraphApi.range.encode.TranslatedTitle());
224
+ registerEncoding("admin_fieldTranslations", new DbmGraphApi.range.encode.admin.FieldTranslations());
225
+
226
+ registerEncoding("language", DbmGraphApi.range.encode.SingleRelation.create("language", "in:for:language", "type"));
227
+ registerEncodingClass(DbmGraphApi.range.encode.TranslatedName);
228
+ registerEncoding("translationGroup", new DbmGraphApi.range.encode.TranslationGroup());
216
229
  }
217
230
 
218
231
  export {fullEncodeSetup};
@@ -256,6 +269,7 @@ let fullActionSetup = function() {
256
269
  registerActionFunction("cron/processActions", new DbmGraphApi.action.cron.ProcessActions());
257
270
  registerActionFunction("admin/addAndProcessAction", new DbmGraphApi.action.admin.AddAndProcessAction());
258
271
  registerActionFunction("admin/addUser", new DbmGraphApi.action.admin.AddUser());
272
+ registerActionFunction("admin/user/setPassword", new DbmGraphApi.action.admin.SetPassword());
259
273
 
260
274
  registerActionFunction("admin/setup/setupWebsite", new DbmGraphApi.action.admin.setup.SetupWebsite());
261
275
  registerActionFunction("admin/setup/setupOrganization", new DbmGraphApi.action.admin.setup.SetupOrganization());
@@ -706,6 +720,10 @@ export const setupSite = function(aServer) {
706
720
  reply.type('text/html');
707
721
 
708
722
  let fields = await urlObject.getFields();
723
+ let languageItem = await urlObject.singleObjectRelationQuery("in:for:language");
724
+ if(languageItem) {
725
+ language = await languageItem.getIdentifier();
726
+ }
709
727
 
710
728
  let baseUrl = request.protocol + "://" + request.hostname;
711
729
  if(request.port && request.port !== 80 && request.port !== 443) {
@@ -0,0 +1,39 @@
1
+ import Dbm from "dbm";
2
+ import EncodeBaseObject from "./EncodeBaseObject.js";
3
+
4
+ export default class Language extends EncodeBaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.outputFieldName = "language";
9
+ this.relationPath = "in:for:language";
10
+ this.encodeType = "type";
11
+ }
12
+
13
+ setup(aOutputFieldName, aRelationPath, aEncodeType) {
14
+
15
+ this.outputFieldName = aOutputFieldName;
16
+ this.relationPath = aRelationPath;
17
+ this.encodeType = aEncodeType;
18
+
19
+ return this;
20
+ }
21
+
22
+ async getEncodedData(aId, aEncodingSession) {
23
+
24
+ let returnObject = {};
25
+
26
+ let object = Dbm.getRepositoryItem("graphDatabase").controller.getObject(aId);
27
+
28
+ returnObject[this.outputFieldName] = await aEncodingSession.encodeObjectOrNull(await object.singleObjectRelationQuery(this.relationPath), this.encodeType);
29
+
30
+ return returnObject;
31
+ }
32
+
33
+ static create(aOutputFieldName, aRelationPath, aEncodeType) {
34
+ let newEncoder = new Language();
35
+ newEncoder.setup(aOutputFieldName, aRelationPath, aEncodeType);
36
+
37
+ return newEncoder;
38
+ }
39
+ }
@@ -0,0 +1,25 @@
1
+ import Dbm from "dbm";
2
+ import EncodeBaseObject from "./EncodeBaseObject.js";
3
+
4
+ export default class TranslatedName extends EncodeBaseObject {
5
+
6
+ static DEFAULT_ENCODING_NAME = "name_translations";
7
+
8
+ _construct() {
9
+ super._construct();
10
+ }
11
+
12
+ async getEncodedData(aId, aEncodingSession) {
13
+
14
+ let returnObject = {};
15
+
16
+ let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
17
+
18
+ await aEncodingSession.encodeSingle(aId, "name");
19
+
20
+ let fieldTranslations = await object.getFieldTranslation("name");
21
+ returnObject["name/translations"] = fieldTranslations;
22
+
23
+ return returnObject;
24
+ }
25
+ }
@@ -0,0 +1,22 @@
1
+ import Dbm from "dbm";
2
+ import EncodeBaseObject from "./EncodeBaseObject.js";
3
+
4
+ export default class TranslatedTitle extends EncodeBaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ async getEncodedData(aId, aEncodingSession) {
10
+
11
+ let returnObject = {};
12
+
13
+ let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
14
+
15
+ await aEncodingSession.encodeSingle(aId, "title");
16
+
17
+ let fieldTranslations = await object.getFieldTranslation("title");
18
+ returnObject["title/translations"] = fieldTranslations;
19
+
20
+ return returnObject;
21
+ }
22
+ }
@@ -0,0 +1,28 @@
1
+ import Dbm from "dbm";
2
+ import EncodeBaseObject from "./EncodeBaseObject.js";
3
+
4
+ export default class TranslationGroup extends EncodeBaseObject {
5
+
6
+ static DEFAULT_ENCODING_NAME = "translationGroup";
7
+
8
+ _construct() {
9
+ super._construct();
10
+ }
11
+
12
+ async getEncodedData(aId, aEncodingSession) {
13
+ //console.log("TranslationGroup::getEncodedData");
14
+
15
+ let returnObject = {};
16
+
17
+ let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
18
+
19
+
20
+ {
21
+ let relatedItems = await object.objectRelationQuery("in:in:page");
22
+ returnObject["pages"] = await aEncodingSession.encodeObjects(relatedItems, "language");
23
+ await aEncodingSession.encodeObjects(relatedItems, "url");
24
+ }
25
+
26
+ return returnObject;
27
+ }
28
+ }
@@ -18,6 +18,7 @@ export default class UrlRequest extends EncodeBaseObject {
18
18
  await aEncodingSession.encodeSingle(aId, "url");
19
19
  await aEncodingSession.encodeSingle(aId, "navigationName");
20
20
  await aEncodingSession.encodeSingle(aId, "pageRepresentation");
21
+ await aEncodingSession.encodeSingle(aId, "language");
21
22
 
22
23
  let fields = await object.getFields();
23
24
 
@@ -38,6 +39,12 @@ export default class UrlRequest extends EncodeBaseObject {
38
39
  returnObject["category"] = await aEncodingSession.encodeObjectOrNull(relatedItem, "type");
39
40
  }
40
41
 
42
+ {
43
+ let relatedItem = await object.singleObjectRelationQuery("out:in:group/translationGroup");
44
+
45
+ returnObject["translations"] = await aEncodingSession.encodeObjectOrNull(relatedItem, "translationGroup");
46
+ }
47
+
41
48
  return returnObject;
42
49
  }
43
50
  }
@@ -0,0 +1,22 @@
1
+ import Dbm from "dbm";
2
+ import EncodeBaseObject from "../EncodeBaseObject.js";
3
+
4
+ export default class Fields extends EncodeBaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ async getEncodedData(aId, aEncodingSession) {
10
+
11
+ let returnObject = {};
12
+
13
+ await aEncodingSession.outputController.requireRole("admin");
14
+
15
+ let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
16
+
17
+ let fields = await object.getAllFieldTranslations();
18
+ returnObject["fields/translations"] = fields;
19
+
20
+ return returnObject;
21
+ }
22
+ }
@@ -1,2 +1,3 @@
1
1
  export {default as Fields} from "./Fields.js";
2
- export {default as User} from "./User.js";
2
+ export {default as User} from "./User.js";
3
+ export {default as FieldTranslations} from "./FieldTranslations.js";
@@ -22,5 +22,9 @@ export {default as Location} from "./Location.js";
22
22
  export {default as AtLocation} from "./AtLocation.js";
23
23
  export {default as LinkPreview} from "./LinkPreview.js";
24
24
  export {default as PublishDate} from "./PublishDate.js";
25
+ export {default as SingleRelation} from "./SingleRelation.js";
26
+ export {default as TranslatedTitle} from "./TranslatedTitle.js";
27
+ export {default as TranslatedName} from "./TranslatedName.js";
28
+ export {default as TranslationGroup} from "./TranslationGroup.js";
25
29
 
26
30
  export * as admin from "./admin/index.js";
@@ -45,14 +45,26 @@ export default class ExternalTaskRunner extends Dbm.core.BaseObject {
45
45
 
46
46
  let response = await fetch(this.item.url, requestData);
47
47
 
48
- let data = await response.json();
48
+ let responseText = await response.text();
49
49
 
50
- let continueData = Dbm.objectPath(data, this.item.continueField);
51
- console.log(this.item.name + " " + continueData);
50
+ let data = null;
51
+ try {
52
+ data = JSON.parse(responseText);
53
+ }
54
+ catch(theError) {
55
+ console.error(theError);
56
+ console.log(responseText);
57
+ }
58
+
59
+ if(data) {
60
+ let continueData = Dbm.objectPath(data, this.item.continueField);
61
+ console.log(this.item.name + " " + continueData);
52
62
 
53
- if(continueData > 0) {
54
- runDirect = true;
63
+ if(continueData > 0) {
64
+ runDirect = true;
65
+ }
55
66
  }
67
+
56
68
  }
57
69
  catch(theError) {
58
70
  console.log(theError);