dbm-graph-api 1.1.1 → 1.1.3

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.
Files changed (33) hide show
  1. package/package.json +2 -2
  2. package/src/dbm-graph-api/UrlRequest.js +14 -0
  3. package/src/dbm-graph-api/WebSocketConnection.js +15 -0
  4. package/src/dbm-graph-api/action/Example.js +15 -0
  5. package/src/dbm-graph-api/action/IncomingWebhook.js +35 -0
  6. package/src/dbm-graph-api/action/cron/ProcessActions.js +49 -0
  7. package/src/dbm-graph-api/action/cron/index.js +1 -0
  8. package/src/dbm-graph-api/action/index.js +4 -0
  9. package/src/dbm-graph-api/admin/edit/AddIncomingRelation.js +2 -2
  10. package/src/dbm-graph-api/admin/edit/AddOutgoingRelation.js +2 -2
  11. package/src/dbm-graph-api/admin/edit/EditBaseObject.js +1 -1
  12. package/src/dbm-graph-api/admin/edit/PurgeCache.js +13 -0
  13. package/src/dbm-graph-api/admin/edit/SetField.js +2 -2
  14. package/src/dbm-graph-api/admin/edit/SetIdentifier.js +12 -0
  15. package/src/dbm-graph-api/admin/edit/SetUrl.js +2 -2
  16. package/src/dbm-graph-api/admin/edit/index.js +9 -4
  17. package/src/dbm-graph-api/data/AltText.js +75 -0
  18. package/src/dbm-graph-api/data/SeoSummary.js +59 -0
  19. package/src/dbm-graph-api/data/UploadS3.js +14 -2
  20. package/src/dbm-graph-api/data/index.js +2 -0
  21. package/src/dbm-graph-api/index.js +89 -4
  22. package/src/dbm-graph-api/processAction/Example.js +11 -0
  23. package/src/dbm-graph-api/processAction/index.js +1 -0
  24. package/src/dbm-graph-api/range/EncodeSession.js +3 -2
  25. package/src/dbm-graph-api/range/Query.js +62 -1
  26. package/src/dbm-graph-api/range/encode/EncodeBaseObject.js +8 -0
  27. package/src/dbm-graph-api/range/encode/Image.js +27 -0
  28. package/src/dbm-graph-api/range/encode/Type.js +20 -0
  29. package/src/dbm-graph-api/range/encode/index.js +3 -1
  30. package/src/dbm-graph-api/range/select/ByObjectType.js +5 -0
  31. package/src/dbm-graph-api/range/select/IdSelection.js +1 -1
  32. package/src/dbm-graph-api/range/select/IncludePrivate.js +18 -0
  33. package/src/dbm-graph-api/range/select/index.js +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm-graph-api",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
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.1.0",
16
+ "dbm": "^1.1.2",
17
17
  "ws": "^8.18.0"
18
18
  },
19
19
  "optionalDependencies": {
@@ -118,6 +118,20 @@ export default class UrlRequest extends Dbm.core.BaseObject {
118
118
 
119
119
  this._responseData = returnData;
120
120
  }
121
+
122
+ async performAction(aFunctionName, aData) {
123
+ let encodeSession = new DbmGraphApi.range.EncodeSession();
124
+ encodeSession.outputController = this;
125
+
126
+ let dataFunctionItem = Dbm.getInstance().repository.getItemIfExists("graphApi/action/" + aFunctionName);
127
+
128
+ let returnData = null;
129
+ if(dataFunctionItem) {
130
+ returnData = await dataFunctionItem.controller.performAction(aData, encodeSession);
131
+ }
132
+
133
+ this._responseData = returnData;
134
+ }
121
135
 
122
136
  outputEncodedData(aId, aData, aEncoding) {
123
137
  //console.log("UrlRequest::outputEncodedData");
@@ -123,6 +123,21 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
123
123
  this._webSocket.send(JSON.stringify({"type": "data/response", "data": returnData, "requestId": data["requestId"]}));
124
124
  }
125
125
  break;
126
+ case "action":
127
+ {
128
+ let encodeSession = new DbmGraphApi.range.EncodeSession();
129
+ encodeSession.outputController = this;
130
+
131
+ let dataFunctionItem = Dbm.getInstance().repository.getItemIfExists("graphApi/action/" + data['functionName']);
132
+
133
+ let returnData = null;
134
+ if(dataFunctionItem) {
135
+ returnData = await dataFunctionItem.controller.performAction(data['data'], encodeSession);
136
+ }
137
+
138
+ this._webSocket.send(JSON.stringify({"type": "data/response", "data": returnData, "requestId": data["requestId"]}));
139
+ }
140
+ break;
126
141
  case "item":
127
142
  {
128
143
  let id = data['id'];
@@ -0,0 +1,15 @@
1
+ import Dbm from "dbm";
2
+
3
+ export default class Example extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ async performAction(aData, aEncodeSession) {
9
+ let returnObject = {};
10
+
11
+ returnObject["example"] = "This is an example of an action";
12
+
13
+ return returnObject;
14
+ }
15
+ }
@@ -0,0 +1,35 @@
1
+ import Dbm from "dbm";
2
+
3
+ export default class IncomingWebhook extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ async performAction(aData, aEncodeSession) {
9
+ let returnObject = {};
10
+
11
+ let type = aData['type'];
12
+ let data = aData;
13
+
14
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
15
+
16
+ let webhookType = await database.getTypeObject("type/webhookType", type);
17
+
18
+ let incomingWebhook = await database.createObject("private", ["incomingWebhook"]);
19
+ await incomingWebhook.updateField("data", data);
20
+ await incomingWebhook.addIncomingRelation(webhookType, "for");
21
+
22
+ let actionType = await database.getTypeObject("type/actionType", "incomingWebhook/" + type);
23
+ let actionStatus = await database.getTypeObject("status/actionStatus", "readyToProcess");
24
+
25
+ let action = await database.createObject("private", ["action"]);
26
+ await action.addIncomingRelation(actionType, "for");
27
+ await action.addIncomingRelation(incomingWebhook, "from");
28
+ await action.addIncomingRelation(actionStatus, "for");
29
+
30
+ returnObject["id"] = incomingWebhook.id;
31
+ returnObject["action"] = action.id;
32
+
33
+ return returnObject;
34
+ }
35
+ }
@@ -0,0 +1,49 @@
1
+ import Dbm from "dbm";
2
+
3
+ export default class ProcessActions extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ async performAction(aData, aEncodeSession) {
9
+ let returnObject = {};
10
+
11
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
12
+
13
+ let actionStatus = await database.getTypeObject("status/actionStatus", "readyToProcess");
14
+ let actions = await actionStatus.objectRelationQuery("out:for:action");
15
+
16
+ if(actions.length) {
17
+ let action = actions[0];
18
+ returnObject["processed"] = action.id;
19
+
20
+ let processingActionStatus = await database.getTypeObject("status/actionStatus", "processing");
21
+ await action.replaceIncomingRelation(processingActionStatus, "for", "status/actionStatus");
22
+
23
+ let actionType = await (await action.singleObjectRelationQuery("in:for:type/actionType")).getIdentifier();
24
+ console.log(actionType);
25
+
26
+ let processActionItem = Dbm.getInstance().repository.getItemIfExists("graphApi/procesAction/" + actionType);
27
+
28
+ if(processActionItem) {
29
+
30
+ await processActionItem.controller.process(action);
31
+
32
+ let doneActionStatus = await database.getTypeObject("status/actionStatus", "done");
33
+ await action.replaceIncomingRelation(doneActionStatus, "for", "status/actionStatus");
34
+ }
35
+ else {
36
+ let doneActionStatus = await database.getTypeObject("status/actionStatus", "noAction");
37
+ await action.replaceIncomingRelation(doneActionStatus, "for", "status/actionStatus");
38
+ }
39
+
40
+ returnObject["remaining"] = actions.length-1;
41
+ }
42
+ else {
43
+ returnObject["processed"] = 0;
44
+ returnObject["remaining"] = 0;
45
+ }
46
+
47
+ return returnObject;
48
+ }
49
+ }
@@ -0,0 +1 @@
1
+ export {default as ProcessActions} from "./ProcessActions.js";
@@ -0,0 +1,4 @@
1
+ export {default as Example} from "./Example.js";
2
+ export {default as IncomingWebhook} from "./IncomingWebhook.js";
3
+
4
+ export * as cron from "./cron/index.js";
@@ -6,7 +6,7 @@ export default class AddIncomigRelation extends EditBaseObject {
6
6
  super._construct();
7
7
  }
8
8
 
9
- performChange(aObject, aData, aRequest) {
10
- aObject.addIncomingRelation(aData["value"], aData["type"]);
9
+ async performChange(aObject, aData, aRequest) {
10
+ await aObject.addIncomingRelation(aData["value"], aData["type"]);
11
11
  }
12
12
  }
@@ -6,7 +6,7 @@ export default class AddOutgoingRelation extends EditBaseObject {
6
6
  super._construct();
7
7
  }
8
8
 
9
- performChange(aObject, aData, aRequest) {
10
- aObject.addOutgoingRelation(aData["value"], aData["type"]);
9
+ async performChange(aObject, aData, aRequest) {
10
+ await aObject.addOutgoingRelation(aData["value"], aData["type"]);
11
11
  }
12
12
  }
@@ -5,7 +5,7 @@ export default class EditBaseObject extends Dbm.core.BaseObject {
5
5
  super._construct();
6
6
  }
7
7
 
8
- performChange(aObject, aData, aRequest) {
8
+ async performChange(aObject, aData, aRequest) {
9
9
  //MENOTE: should be overridden
10
10
  }
11
11
  }
@@ -0,0 +1,13 @@
1
+ import Dbm from "dbm";
2
+ import EditBaseObject from "./EditBaseObject.js";
3
+
4
+ export default class PurgeCache extends EditBaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ async performChange(aObject, aData, aRequest) {
10
+ let url = await aObject.getUrl();
11
+ console.log(url);
12
+ }
13
+ }
@@ -6,7 +6,7 @@ export default class SetField extends EditBaseObject {
6
6
  super._construct();
7
7
  }
8
8
 
9
- performChange(aObject, aData, aRequest) {
10
- aObject.updateField(aData["field"], aData["value"]);
9
+ async performChange(aObject, aData, aRequest) {
10
+ await aObject.updateField(aData["field"], aData["value"]);
11
11
  }
12
12
  }
@@ -0,0 +1,12 @@
1
+ import Dbm from "dbm";
2
+ import EditBaseObject from "./EditBaseObject.js";
3
+
4
+ export default class SetIdentifier extends EditBaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ async performChange(aObject, aData, aRequest) {
10
+ await aObject.setIdentifier(aData["value"]);
11
+ }
12
+ }
@@ -6,7 +6,7 @@ export default class SetUrl extends EditBaseObject {
6
6
  super._construct();
7
7
  }
8
8
 
9
- performChange(aObject, aData, aRequest) {
10
- aObject.setUrl(aData["value"]);
9
+ async performChange(aObject, aData, aRequest) {
10
+ await aObject.setUrl(aData["value"]);
11
11
  }
12
12
  }
@@ -2,11 +2,12 @@ import DbmGraphApi from "../../../../index.js";
2
2
  export {default as EditBaseObject} from "./EditBaseObject.js";
3
3
 
4
4
  export {default as SetField} from "./SetField.js";
5
+ export {default as SetIdentifier} from "./SetIdentifier.js";
5
6
  export {default as SetUrl} from "./SetUrl.js";
6
7
  export {default as AddIncomingRelation} from "./AddIncomingRelation.js";
7
8
  export {default as AddOutgoingRelation} from "./AddOutgoingRelation.js";
8
9
 
9
- let fullSetup = function() {
10
+ export const fullSetup = function() {
10
11
  let prefix = "graphApi/admin/edit/";
11
12
  {
12
13
  let name = "setField";
@@ -14,6 +15,12 @@ let fullSetup = function() {
14
15
  currentSelect.item.register(prefix + name);
15
16
  }
16
17
 
18
+ {
19
+ let name = "setIdentifier";
20
+ let currentSelect = new DbmGraphApi.admin.edit.SetIdentifier();
21
+ currentSelect.item.register(prefix + name);
22
+ }
23
+
17
24
  {
18
25
  let name = "setUrl";
19
26
  let currentSelect = new DbmGraphApi.admin.edit.SetUrl();
@@ -31,6 +38,4 @@ let fullSetup = function() {
31
38
  let currentSelect = new DbmGraphApi.admin.edit.AddOutgoingRelation();
32
39
  currentSelect.item.register(prefix + name);
33
40
  }
34
- }
35
-
36
- export {fullSetup};
41
+ }
@@ -0,0 +1,75 @@
1
+ import Dbm from "dbm";
2
+
3
+ export default class SeoSummary extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ async getData(aData, aEncodeSession) {
9
+ let returnObject = {};
10
+
11
+ let imageId = aData["id"];
12
+
13
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
14
+ let item = await database.createObject("private", ["aiGeneratedAltText"]);
15
+
16
+ returnObject["id"] = item.id;
17
+ returnObject["imageId"] = imageId;
18
+
19
+ let image = database.getObject(imageId);
20
+ let fields = await image.getFields();
21
+
22
+ let url = fields["resizeUrl"];
23
+ if(url) {
24
+ url = url.split("{scale}").join("width=1024,height=1024")
25
+ }
26
+
27
+ returnObject["url"] = url;
28
+
29
+ let instructions = "Generate an alt text for the image. Respond with only a json object {altText: string}, no markdown.";
30
+
31
+ let body = {
32
+ "model": "gpt-4o",
33
+ "response_format": { "type": "json_object" },
34
+ "max_tokens": 300,
35
+ "messages": [
36
+ {"role":"system","content": instructions},
37
+ {
38
+ "role": "user",
39
+ "content": [
40
+ {
41
+ "type": "image_url",
42
+ "image_url": {
43
+ "url": url
44
+ }
45
+ }
46
+ ]
47
+ }
48
+ ]
49
+ }
50
+
51
+ let headers = {
52
+ "Content-Type": "application/json",
53
+ 'Authorization': 'Bearer ' + Dbm.getInstance().repository.getItem("openAi").token
54
+ }
55
+
56
+ let response = await fetch('https://api.openai.com/v1/chat/completions', {
57
+ method: "POST",
58
+ headers: headers,
59
+ body: JSON.stringify(body),
60
+ });
61
+
62
+ let data = await response.json();
63
+ console.log(data);
64
+ await item.updateField("response", data);
65
+
66
+ let message = data.choices[0].message;
67
+ console.log(message.content);
68
+ let responseContent = JSON.parse(message.content);
69
+ console.log(responseContent);
70
+
71
+ returnObject["altText"] = responseContent["altText"];
72
+
73
+ return returnObject;
74
+ }
75
+ }
@@ -0,0 +1,59 @@
1
+ import Dbm from "dbm";
2
+
3
+ export default class SeoSummary extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ async getData(aData, aEncodeSession) {
9
+ let returnObject = {};
10
+
11
+ let content = aData["value"];
12
+ returnObject["content"] = content;
13
+
14
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
15
+ let item = await database.createObject("private", ["aiGeneratedSeoSummary"]);
16
+ await item.updateField("content", content);
17
+ returnObject["id"] = item.id;
18
+
19
+ let contentString = JSON.stringify(content);
20
+
21
+ let instructions = "Generate an seo description for the page data provided by the user, with a max character count of 155. {additionalInstructions} Respond with only a json object {seoSummary: string}, no markdown.";
22
+ instructions = instructions.split("{data}").join(contentString);
23
+
24
+ let additionalInstructions = "";
25
+ instructions = instructions.split("{additionalInstructions}").join(additionalInstructions);
26
+
27
+ let body = {
28
+ "model": "gpt-4o-mini",
29
+ "response_format": { "type": "json_object" },
30
+ "messages": [
31
+ {"role":"system","content": instructions},
32
+ {"role": "user", "content": contentString}
33
+ ],
34
+ "temperature": 0.7
35
+ }
36
+
37
+ let headers = {
38
+ "Content-Type": "application/json",
39
+ 'Authorization': 'Bearer ' + Dbm.getInstance().repository.getItem("openAi").token
40
+ }
41
+
42
+ let response = await fetch('https://api.openai.com/v1/chat/completions', {
43
+ method: "POST",
44
+ headers: headers,
45
+ body: JSON.stringify(body),
46
+ });
47
+
48
+ let data = await response.json();
49
+ await item.updateField("response", data);
50
+
51
+ let message = data.choices[0].message;
52
+ let responseContent = JSON.parse(message.content);
53
+ console.log(responseContent);
54
+
55
+ returnObject["seoSummary"] = responseContent["seoSummary"];
56
+
57
+ return returnObject;
58
+ }
59
+ }
@@ -20,7 +20,8 @@ export default class UploadS3 extends Dbm.core.BaseObject {
20
20
  async getData(aData, aEncodeSession) {
21
21
  let returnObject = {};
22
22
 
23
- let fileName = aData["fileName"].toLowerCase();
23
+ let originalFileName = aData["fileName"];
24
+ let fileName = originalFileName.toLowerCase();
24
25
  let mimeType = aData["mimeType"];
25
26
 
26
27
  fileName = fileName.replace(/[åäã]/gi, 'a');
@@ -46,7 +47,8 @@ export default class UploadS3 extends Dbm.core.BaseObject {
46
47
  fullPath = fullPath.split("{date}").join(dateDay);
47
48
  fullPath = fullPath.split("{generatedId}").join(generatedId);
48
49
 
49
- //METODO: add to database
50
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
51
+ let item = await database.createObject("public", ["image"]);
50
52
 
51
53
  fileName = fullPath + fileName;
52
54
  let acl = this.item.acl;
@@ -60,8 +62,18 @@ export default class UploadS3 extends Dbm.core.BaseObject {
60
62
 
61
63
  let presignedUrl = await getSignedUrl(this.item.client, command, { expiresIn: 360 });
62
64
 
65
+ await item.setIdentifier(generatedId);
66
+ await item.updateField("name", originalFileName);
67
+ await item.updateField("path", fileName);
68
+ await item.updateField("originalFileName", originalFileName);
69
+ await item.updateField("url", this.item.publicPath + fileName);
70
+ await item.updateField("resizeUrl", this.item.publicResizePath + fileName);
71
+
72
+ returnObject["id"] = item.id;
63
73
  returnObject["identifier"] = generatedId;
64
74
  returnObject["url"] = presignedUrl;
75
+ returnObject["name"] = fileName;
76
+ returnObject["originalFileName"] = fileName;
65
77
  returnObject["publicUrl"] = this.item.publicPath + fileName;
66
78
  returnObject["publicResizeUrl"] = this.item.publicResizePath + fileName;
67
79
  returnObject["acl"] = acl;
@@ -1,6 +1,8 @@
1
1
  export {default as Example} from "./Example.js";
2
2
  export {default as UploadS3} from "./UploadS3.js";
3
3
  export {default as FreeUrl} from "./FreeUrl.js";
4
+ export {default as SeoSummary} from "./SeoSummary.js";
5
+ export {default as AltText} from "./AltText.js";
4
6
 
5
7
  import UploadS3 from "./UploadS3.js";
6
8
 
@@ -1,5 +1,6 @@
1
1
  import Dbm from "dbm";
2
2
  import crypto from "node:crypto";
3
+ import url from "node:url";
3
4
 
4
5
  import DbmGraphApi from "../../index.js";
5
6
  import Api from "./Api.js";
@@ -10,6 +11,8 @@ export {Api};
10
11
  export * as range from "./range/index.js";
11
12
  export * as admin from "./admin/index.js";
12
13
  export * as data from "./data/index.js";
14
+ export * as action from "./action/index.js";
15
+ export * as processAction from "./processAction/index.js";
13
16
 
14
17
  let fullSelectSetup = function() {
15
18
  let selectPrefix = "graphApi/range/select/";
@@ -24,6 +27,12 @@ let fullSelectSetup = function() {
24
27
  let currentSelect = new DbmGraphApi.range.select.ByObjectType();
25
28
  currentSelect.item.register(selectPrefix + name);
26
29
  }
30
+
31
+ {
32
+ let name = "includePrivate";
33
+ let currentSelect = new DbmGraphApi.range.select.IncludePrivate();
34
+ currentSelect.item.register(selectPrefix + name);
35
+ }
27
36
  }
28
37
 
29
38
  export {fullSelectSetup};
@@ -92,6 +101,20 @@ let fullEncodeSetup = function() {
92
101
  currentEncode.item.register(encodePrefix + name);
93
102
  currentEncode.item.setValue("encodingType", name);
94
103
  }
104
+
105
+ {
106
+ let name = "type";
107
+ let currentEncode = new DbmGraphApi.range.encode.Type();
108
+ currentEncode.item.register(encodePrefix + name);
109
+ currentEncode.item.setValue("encodingType", name);
110
+ }
111
+
112
+ {
113
+ let name = "image";
114
+ let currentEncode = new DbmGraphApi.range.encode.Image();
115
+ currentEncode.item.register(encodePrefix + name);
116
+ currentEncode.item.setValue("encodingType", name);
117
+ }
95
118
  }
96
119
 
97
120
  export {fullEncodeSetup};
@@ -107,15 +130,49 @@ export let registerDataFunction = function(aName, aDataFunction) {
107
130
  let fullDataSetup = function() {
108
131
  registerDataFunction("example", new DbmGraphApi.data.Example());
109
132
  registerDataFunction("admin/freeUrl", new DbmGraphApi.data.FreeUrl());
133
+ registerDataFunction("admin/seoSummary", new DbmGraphApi.data.SeoSummary());
134
+ registerDataFunction("admin/altText", new DbmGraphApi.data.AltText());
110
135
  }
111
136
 
112
137
  export {fullDataSetup};
113
138
 
139
+ export let registerActionFunction = function(aName, aDataFunction) {
140
+
141
+ aDataFunction.item.register("graphApi/action/" + aName);
142
+ aDataFunction.item.setValue("functionName", aName);
143
+
144
+ return aDataFunction;
145
+ }
146
+
147
+ let fullActionSetup = function() {
148
+ registerActionFunction("example", new DbmGraphApi.action.Example());
149
+ registerActionFunction("incomingWebhook", new DbmGraphApi.action.IncomingWebhook());
150
+ registerActionFunction("cron/processActions", new DbmGraphApi.action.cron.ProcessActions());
151
+ }
152
+
153
+ export {fullActionSetup};
154
+
155
+ export let registerProcessActionFunction = function(aName, aDataFunction) {
156
+
157
+ aDataFunction.item.register("graphApi/processAction/" + aName);
158
+ aDataFunction.item.setValue("functionName", aName);
159
+
160
+ return aDataFunction;
161
+ }
162
+
163
+ let fullProcessActionSetup = function() {
164
+ registerProcessActionFunction("example", new DbmGraphApi.processAction.Example());
165
+ }
166
+
167
+ export {fullProcessActionSetup};
168
+
114
169
  let fullSetup = function() {
115
170
 
116
171
  fullSelectSetup();
117
172
  fullEncodeSetup();
118
173
  fullDataSetup();
174
+ fullActionSetup();
175
+ fullProcessActionSetup()
119
176
 
120
177
  DbmGraphApi.admin.edit.fullSetup();
121
178
  }
@@ -245,18 +302,46 @@ let setupEndpoints = function(aServer) {
245
302
  return request.getResponse();
246
303
  });
247
304
 
248
- aServer.get('/api/data/:functionName', async function handler (aRequest, aReply) {
305
+ aServer.get('/api/data/*', async function handler (aRequest, aReply) {
249
306
  let params = {...aRequest.query};
250
307
  let request = new UrlRequest();
251
308
 
252
- await request.requestData(aRequest.params.functionName, params);
309
+ let currentUrl = url.parse(aRequest.url);
310
+ let functionName = currentUrl.pathname.substring("/api/data/".length);
311
+
312
+ await request.requestData(functionName, params);
253
313
 
254
314
  return request.getResponse();
255
315
  });
256
316
 
317
+ aServer.get('/api/action/*', async function handler (aRequest, aReply) {
318
+
319
+ let params = {...aRequest.query};
320
+ let request = new UrlRequest();
321
+
322
+ let currentUrl = url.parse(aRequest.url);
323
+ let functionName = currentUrl.pathname.substring("/api/action/".length);
324
+
325
+ await request.performAction(functionName, params);
326
+
327
+ return request.getResponse();
328
+ });
329
+
330
+ aServer.post('/api/action/*', async function handler (aRequest, aReply) {
331
+ let params = {...aRequest.body};
332
+ let request = new UrlRequest();
333
+
334
+ let currentUrl = url.parse(aRequest.url);
335
+ let functionName = currentUrl.pathname.substring("/api/action/".length);
336
+
337
+ await request.performAction(functionName, params);
338
+
339
+ return request.getResponse();
340
+ });
341
+
342
+ //METODO: setup raw data posts
343
+
257
344
  //METODO: setup edit
258
- //METODO: setup actions
259
- //METODO: setup cron
260
345
 
261
346
  aServer.get('/api/', async function handler (aRequest, aResponse) {
262
347
  return { version: Dbm.getInstance().repository.getItem("site").version };
@@ -0,0 +1,11 @@
1
+ import Dbm from "dbm";
2
+
3
+ export default class Example extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ async process(aAction) {
9
+
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export {default as Example} from "./Example.js";
@@ -6,6 +6,8 @@ export default class EncodeSession extends Dbm.core.BaseObject {
6
6
 
7
7
  this._encodings = {};
8
8
  this.outputController = null;
9
+
10
+ //METODO: add cache of database objects
9
11
  }
10
12
 
11
13
  _readyToEncode(aId, aType) {
@@ -54,7 +56,6 @@ export default class EncodeSession extends Dbm.core.BaseObject {
54
56
  async encode(aIds, aType) {
55
57
  let currentArray = aIds;
56
58
  let currentArrayLength = currentArray.length;
57
- let ids = new Array(currentArrayLength);
58
59
  let promises = new Array(currentArrayLength);
59
60
  for(let i = 0; i < currentArrayLength; i++) {
60
61
  let id = currentArray[i];
@@ -63,7 +64,7 @@ export default class EncodeSession extends Dbm.core.BaseObject {
63
64
 
64
65
  await Promise.all(promises);
65
66
 
66
- return ids;
67
+ return aIds;
67
68
  }
68
69
 
69
70
  async encodeObjectOrNull(aObject, aType) {
@@ -8,6 +8,7 @@ export default class Query extends Dbm.core.BaseObject {
8
8
  this._whereStatements = [];
9
9
  this._includeOnly = null;
10
10
  this._visibilities = ["public"];
11
+ this._skipVisibility = false;
11
12
  }
12
13
 
13
14
  async setObjectType(aName) {
@@ -38,6 +39,44 @@ export default class Query extends Dbm.core.BaseObject {
38
39
  return this;
39
40
  }
40
41
 
42
+ includePrivate() {
43
+ this._visibilities.push("private");
44
+
45
+ return this;
46
+ }
47
+
48
+ includeDraft() {
49
+ this._visibilities.push("draft");
50
+
51
+ return this;
52
+ }
53
+
54
+ includeAnyStatus() {
55
+ this._skipVisibility = true;
56
+
57
+ return this;
58
+ }
59
+
60
+ addFieldQuery(aKey, aValue) {
61
+
62
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
63
+
64
+ this._joins.push("INNER JOIN Fields ON Objects.id = Fields.object");
65
+ this._whereStatements.push("Fields.name = " + database.connection.escape(aKey));
66
+ this._whereStatements.push("Fields.value = " + database.connection.escape(JSON.stringify(aValue)));
67
+
68
+ return this;
69
+ }
70
+
71
+ withIdentifier(aIdentifier) {
72
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
73
+
74
+ this._joins.push("INNER JOIN Identifiers ON Objects.id = Identifiers.object");
75
+ this._whereStatements.push("Identifiers.identifier = " + database.connection.escape(aIdentifier));
76
+
77
+ return this;
78
+ }
79
+
41
80
  async getIds() {
42
81
  let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
43
82
 
@@ -55,7 +94,17 @@ export default class Query extends Dbm.core.BaseObject {
55
94
  whereStatements.push("Objects.id IN (" + this._includeOnly.join(",") + ")");
56
95
  }
57
96
 
58
- //METODO: include visibility
97
+ if(!this._skipVisibility) {
98
+ let visibilityIds = [];
99
+ let currentArray = this._visibilities;
100
+ let currentArrayLength = currentArray.length;
101
+ for(let i = 0; i < currentArrayLength; i++) {
102
+ let currentId = await database.getVisibilityType(currentArray[i]);
103
+ visibilityIds.push(currentId);
104
+ }
105
+
106
+ whereStatements.push("Objects.visibility IN (" + visibilityIds.join(",") + ")");
107
+ }
59
108
 
60
109
  if(whereStatements.length) {
61
110
  query += " WHERE " + whereStatements.join(" AND ");
@@ -79,4 +128,16 @@ export default class Query extends Dbm.core.BaseObject {
79
128
 
80
129
  return database.getObjects(ids);
81
130
  }
131
+
132
+ async getObject() {
133
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
134
+ let ids = await this.getIds();
135
+
136
+ if(ids.length) {
137
+ //METODO: warning if more than 1
138
+ return database.getObject(ids[0]);
139
+ }
140
+
141
+ return null;
142
+ }
82
143
  }
@@ -33,4 +33,12 @@ export default class EncodeBaseObject extends Dbm.core.BaseObject {
33
33
 
34
34
  return {};
35
35
  }
36
+
37
+ _dataOrNull(aData) {
38
+ if(aData === undefined) {
39
+ return null;
40
+ }
41
+
42
+ return aData;
43
+ }
36
44
  }
@@ -0,0 +1,27 @@
1
+ import Dbm from "dbm";
2
+ import EncodeBaseObject from "./EncodeBaseObject.js";
3
+
4
+ export default class Image 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
+ let fields = await object.getFields();
16
+ returnObject["originalFileName"] = fields["originalFileName"];
17
+ returnObject["path"] = fields["path"];
18
+ returnObject["url"] = fields["url"];
19
+ returnObject["resizeUrl"] = fields["resizeUrl"];
20
+ returnObject["altText"] = this._dataOrNull(fields["altText"]);
21
+
22
+ await aEncodingSession.encodeSingle(aId, "identifier");
23
+ await aEncodingSession.encodeSingle(aId, "name");
24
+
25
+ return returnObject;
26
+ }
27
+ }
@@ -0,0 +1,20 @@
1
+ import Dbm from "dbm";
2
+ import EncodeBaseObject from "./EncodeBaseObject.js";
3
+
4
+ export default class Type 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, "identifier");
16
+ await aEncodingSession.encodeSingle(aId, "name");
17
+
18
+ return returnObject;
19
+ }
20
+ }
@@ -8,4 +8,6 @@ export {default as Title} from "./Title.js";
8
8
  export {default as UrlRequest} from "./UrlRequest.js";
9
9
  export {default as Url} from "./Url.js";
10
10
  export {default as Breadcrumb} from "./Breadcrumb.js";
11
- export {default as NavigationName} from "./NavigationName.js";
11
+ export {default as NavigationName} from "./NavigationName.js";
12
+ export {default as Type} from "./Type.js";
13
+ export {default as Image} from "./Image.js";
@@ -8,6 +8,11 @@ export default class ByObjectType extends SelectBaseObject {
8
8
  }
9
9
 
10
10
  async select(aQuery, aData, aRequest) {
11
+
12
+ if(!aData["objectType"]) {
13
+ throw("Parameter objectType not set");
14
+ }
15
+
11
16
  await aQuery.setObjectType(aData["objectType"]);
12
17
  }
13
18
 
@@ -8,7 +8,7 @@ export default class IdSelection extends SelectBaseObject {
8
8
  }
9
9
 
10
10
  async select(aQuery, aData, aRequest) {
11
- aQuery.includeOnly(aData["ids"]);
11
+ aQuery.includeOnly(Dbm.utils.ArrayFunctions.arrayOrSeparatedString(aData["ids"]));
12
12
  }
13
13
 
14
14
  async filter(aIds, aData, aRequest) {
@@ -0,0 +1,18 @@
1
+ import Dbm from "dbm";
2
+
3
+ import SelectBaseObject from "./SelectBaseObject.js";
4
+
5
+ export default class IncludePrivate extends SelectBaseObject {
6
+ _construct() {
7
+ super._construct();
8
+ }
9
+
10
+ async select(aQuery, aData, aRequest) {
11
+ //METODO: check that we are allowed
12
+ aQuery.includePrivate();
13
+ }
14
+
15
+ async filter(aIds, aData, aRequest) {
16
+ return aIds;
17
+ }
18
+ }
@@ -1,3 +1,4 @@
1
1
  export {default as SelectBaseObject} from "./SelectBaseObject.js";
2
2
  export {default as IdSelection} from "./IdSelection.js";
3
- export {default as ByObjectType} from "./ByObjectType.js";
3
+ export {default as ByObjectType} from "./ByObjectType.js";
4
+ export {default as IncludePrivate} from "./IncludePrivate.js";