dbm-graph-api 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.
- package/index.js +1 -0
- package/package.json +18 -0
- package/src/dbm-graph-api/Api.js +72 -0
- package/src/dbm-graph-api/WebSocketConnection.js +258 -0
- package/src/dbm-graph-api/admin/edit/AddIncomingRelation.js +12 -0
- package/src/dbm-graph-api/admin/edit/AddOutgoingRelation.js +12 -0
- package/src/dbm-graph-api/admin/edit/EditBaseObject.js +11 -0
- package/src/dbm-graph-api/admin/edit/SetField.js +12 -0
- package/src/dbm-graph-api/admin/edit/index.js +29 -0
- package/src/dbm-graph-api/admin/index.js +1 -0
- package/src/dbm-graph-api/data/Example.js +15 -0
- package/src/dbm-graph-api/data/UploadS3.js +67 -0
- package/src/dbm-graph-api/data/index.js +30 -0
- package/src/dbm-graph-api/index.js +183 -0
- package/src/dbm-graph-api/range/EncodeSession.js +99 -0
- package/src/dbm-graph-api/range/Query.js +56 -0
- package/src/dbm-graph-api/range/encode/Content.js +20 -0
- package/src/dbm-graph-api/range/encode/EncodeBaseObject.js +36 -0
- package/src/dbm-graph-api/range/encode/Example.js +17 -0
- package/src/dbm-graph-api/range/encode/Identifier.js +19 -0
- package/src/dbm-graph-api/range/encode/Name.js +20 -0
- package/src/dbm-graph-api/range/encode/Title.js +20 -0
- package/src/dbm-graph-api/range/encode/UrlRequest.js +24 -0
- package/src/dbm-graph-api/range/encode/index.js +8 -0
- package/src/dbm-graph-api/range/index.js +5 -0
- package/src/dbm-graph-api/range/select/IdSelection.js +17 -0
- package/src/dbm-graph-api/range/select/SelectBaseObject.js +15 -0
- package/src/dbm-graph-api/range/select/index.js +2 -0
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as default from "./src/dbm-graph-api/index.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dbm-graph-api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"description": "",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@aws-sdk/client-s3": "^3.693.0",
|
|
15
|
+
"@aws-sdk/s3-request-presigner": "^3.693.0",
|
|
16
|
+
"ws": "^8.18.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { WebSocketServer } from 'ws';
|
|
2
|
+
import Dbm from "dbm";
|
|
3
|
+
|
|
4
|
+
import WebSocketConnection from "./WebSocketConnection.js";
|
|
5
|
+
|
|
6
|
+
export default class Api extends Dbm.core.BaseObject {
|
|
7
|
+
_construct() {
|
|
8
|
+
super._construct();
|
|
9
|
+
|
|
10
|
+
this._server = null;
|
|
11
|
+
this._webSocketServer = null;
|
|
12
|
+
|
|
13
|
+
this.item.setValue("controller", this);
|
|
14
|
+
this.item.setValue("connections", []);
|
|
15
|
+
|
|
16
|
+
this._callback_connectionBound = this._callback_connection.bind(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setup(aServer, aPath = "/ws/") {
|
|
20
|
+
|
|
21
|
+
this._webSocketServer = new WebSocketServer({"server": aServer, "path": aPath});
|
|
22
|
+
|
|
23
|
+
this._webSocketServer.on('connection', this._callback_connectionBound);
|
|
24
|
+
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_callback_connection(aWebSocket, aRequest) {
|
|
29
|
+
let newWebSocketConnection = new WebSocketConnection();
|
|
30
|
+
|
|
31
|
+
newWebSocketConnection.item.setValue("api", this.item);
|
|
32
|
+
|
|
33
|
+
newWebSocketConnection.setWebSocket(aWebSocket);
|
|
34
|
+
newWebSocketConnection.addListeners();
|
|
35
|
+
|
|
36
|
+
let connections = [].concat(this.item.connections);
|
|
37
|
+
connections.push(newWebSocketConnection.item);
|
|
38
|
+
this.item.setValue("connections", connections);
|
|
39
|
+
|
|
40
|
+
let hasUserCookie = false;
|
|
41
|
+
if(aRequest.headers.cookie) {
|
|
42
|
+
let cookies = aRequest.headers.cookie.split(";");
|
|
43
|
+
let currentArray = cookies;
|
|
44
|
+
let currentArrayLength = currentArray.length;
|
|
45
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
46
|
+
let [key, value] = currentArray[i].split("=");
|
|
47
|
+
if(key === "dbm_session" || key === " dbm_session") {
|
|
48
|
+
let userId = 1*value.split(":")[1];
|
|
49
|
+
let user = Dbm.getInstance().repository.getItem("graphDatabase").controller.getUser(userId);
|
|
50
|
+
|
|
51
|
+
user.verifySession(value).then(function(aIsValidSession) {
|
|
52
|
+
console.log("verifySession", aIsValidSession);
|
|
53
|
+
|
|
54
|
+
if(aIsValidSession) {
|
|
55
|
+
newWebSocketConnection.setInitialUser(userId);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
newWebSocketConnection.setInitialUser(0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
});
|
|
62
|
+
hasUserCookie = true;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if(!hasUserCookie) {
|
|
69
|
+
newWebSocketConnection.setInitialUser(0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import DbmGraphApi from "../../index.js";
|
|
3
|
+
|
|
4
|
+
export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
this._webSocket = null;
|
|
8
|
+
|
|
9
|
+
this._callback_errorBound = this._callback_error.bind(this);
|
|
10
|
+
this._callback_messageBound = this._callback_message.bind(this);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setWebSocket(aWebSocket) {
|
|
14
|
+
this._webSocket = aWebSocket;
|
|
15
|
+
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async _applyChanges(aObject, aChanges, aRequest) {
|
|
20
|
+
let currentArray = aChanges;
|
|
21
|
+
let currentArrayLength = currentArray.length;
|
|
22
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
23
|
+
let currentData = currentArray[i];
|
|
24
|
+
let currentType = currentData["type"];
|
|
25
|
+
let changeData = currentData["data"];
|
|
26
|
+
|
|
27
|
+
let changeItem = Dbm.getInstance().repository.getItemIfExists("graphApi/admin/edit/" + currentType);
|
|
28
|
+
if(changeItem) {
|
|
29
|
+
await changeItem.controller.performChange(aObject, changeData, aRequest);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async _callback_message(aDataString) {
|
|
35
|
+
console.log('received: %s', aDataString);
|
|
36
|
+
|
|
37
|
+
let data;
|
|
38
|
+
|
|
39
|
+
try{
|
|
40
|
+
data = JSON.parse(aDataString);
|
|
41
|
+
}
|
|
42
|
+
catch(theError) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let request = {}; //METODO
|
|
47
|
+
|
|
48
|
+
request.connection = this;
|
|
49
|
+
|
|
50
|
+
let type = data["type"];
|
|
51
|
+
switch(type) {
|
|
52
|
+
case "range":
|
|
53
|
+
let selectQuery = new DbmGraphApi.range.Query();
|
|
54
|
+
|
|
55
|
+
let ids = [];
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
let hasSelection = false;
|
|
59
|
+
let currentArray = data.select;
|
|
60
|
+
let currentArrayLength = currentArray.length;
|
|
61
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
62
|
+
let currentSelectData = currentArray[i];
|
|
63
|
+
let currentSelectType = currentSelectData["type"];
|
|
64
|
+
let selection = Dbm.getInstance().repository.getItemIfExists("graphApi/range/select/" + currentSelectType);
|
|
65
|
+
if(selection) {
|
|
66
|
+
hasSelection = true;
|
|
67
|
+
await selection.controller.select(selectQuery, currentSelectData, request);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if(hasSelection) {
|
|
72
|
+
ids = await selectQuery.getIds();
|
|
73
|
+
|
|
74
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
75
|
+
let currentSelectData = currentArray[i];
|
|
76
|
+
let currentSelectType = currentSelectData["type"];
|
|
77
|
+
let selection = Dbm.getInstance().repository.getItemIfExists("graphApi/range/select/" + currentSelectType);
|
|
78
|
+
if(selection) {
|
|
79
|
+
ids = await selection.controller.filter(ids, currentSelectData, request);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
//METODO: log error
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
{
|
|
90
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
91
|
+
encodeSession.outputController = this;
|
|
92
|
+
|
|
93
|
+
let currentArray = data.encode;
|
|
94
|
+
let currentArrayLength = currentArray.length;
|
|
95
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
96
|
+
let currentType = currentArray[i];
|
|
97
|
+
|
|
98
|
+
await encodeSession.encode(ids, currentType);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
encodeSession.destroy();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this._webSocket.send(JSON.stringify({"type": "range/response", "ids": ids, "requestId": data["requestId"]}));
|
|
105
|
+
break;
|
|
106
|
+
case "data":
|
|
107
|
+
{
|
|
108
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
109
|
+
encodeSession.outputController = this;
|
|
110
|
+
|
|
111
|
+
let dataFunctionItem = Dbm.getInstance().repository.getItemIfExists("graphApi/data/" + data['functionName']);
|
|
112
|
+
|
|
113
|
+
let returnData = null;
|
|
114
|
+
if(dataFunctionItem) {
|
|
115
|
+
returnData = await dataFunctionItem.controller.getData(data['data'], encodeSession);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this._webSocket.send(JSON.stringify({"type": "data/response", "data": returnData, "requestId": data["requestId"]}));
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
case "item":
|
|
122
|
+
{
|
|
123
|
+
let id = data['id'];
|
|
124
|
+
//METODO: check visibility in database
|
|
125
|
+
|
|
126
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
127
|
+
encodeSession.outputController = this;
|
|
128
|
+
|
|
129
|
+
await encodeSession.encodeSingleWithTypes(id, data.encode);
|
|
130
|
+
|
|
131
|
+
encodeSession.destroy();
|
|
132
|
+
|
|
133
|
+
this._webSocket.send(JSON.stringify({"type": "item/response", "id": id, "requestId": data["requestId"]}));
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case "url":
|
|
137
|
+
{
|
|
138
|
+
let url = data['url'];
|
|
139
|
+
if(url[url.length-1] !== "/") {
|
|
140
|
+
url += "/";
|
|
141
|
+
}
|
|
142
|
+
//METODO: check visibility in database
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
147
|
+
let urlObject = await database.getObjectByUrl(url);
|
|
148
|
+
|
|
149
|
+
if(urlObject) {
|
|
150
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
151
|
+
encodeSession.outputController = this;
|
|
152
|
+
|
|
153
|
+
await encodeSession.encodeSingleWithTypes(urlObject.id, ["urlRequest"]);
|
|
154
|
+
encodeSession.destroy();
|
|
155
|
+
this._webSocket.send(JSON.stringify({"type": "url/response", "id": urlObject.id, "requestId": data["requestId"]}));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this._webSocket.send(JSON.stringify({"type": "url/response", "id": 0, "requestId": data["requestId"]}));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case "admin/createObject":
|
|
163
|
+
{
|
|
164
|
+
let types = data['types'];
|
|
165
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
166
|
+
let visibility = data['visibility'] ? data['visibility'] : 'draft';
|
|
167
|
+
|
|
168
|
+
let draftVisibility = await database.getVisibilityType(visibility);
|
|
169
|
+
|
|
170
|
+
let newObject = await database.createObject(draftVisibility, types);
|
|
171
|
+
|
|
172
|
+
if(data.changes) {
|
|
173
|
+
await this._applyChanges(newObject, data.changes, request);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if(data.encode) {
|
|
177
|
+
|
|
178
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
179
|
+
encodeSession.outputController = this;
|
|
180
|
+
|
|
181
|
+
await encodeSession.encodeSingleWithTypes(newObject.id, data.encode);
|
|
182
|
+
|
|
183
|
+
encodeSession.destroy();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
this._webSocket.send(JSON.stringify({"type": "item/response", "id": newObject.id, "requestId": data["requestId"]}));
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
case "admin/editObject":
|
|
190
|
+
{
|
|
191
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
192
|
+
|
|
193
|
+
let theObject = database.getObject(data.id);
|
|
194
|
+
|
|
195
|
+
if(data.changes) {
|
|
196
|
+
await this._applyChanges(theObject, data.changes, request);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if(data.encode) {
|
|
200
|
+
|
|
201
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
202
|
+
encodeSession.outputController = this;
|
|
203
|
+
|
|
204
|
+
await encodeSession.encodeSingleWithTypes(theObject.id, data.encode);
|
|
205
|
+
|
|
206
|
+
encodeSession.destroy();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this._webSocket.send(JSON.stringify({"type": "item/response", "id": theObject.id, "requestId": data["requestId"]}));
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
case "user/signInWithToken":
|
|
213
|
+
{
|
|
214
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
215
|
+
|
|
216
|
+
let user = database.getUser(1*data.token.split(":")[1]);
|
|
217
|
+
|
|
218
|
+
let isVerified = await user.verifySignedSessionToken(data.token);
|
|
219
|
+
|
|
220
|
+
let userId = 0;
|
|
221
|
+
if(isVerified) {
|
|
222
|
+
//METODO: set user for connection
|
|
223
|
+
userId = user.id;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
this._webSocket.send(JSON.stringify({"type": "currentUser/response", "id": userId, "requestId": data["requestId"]}));
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
_callback_error(aMessage) {
|
|
234
|
+
console.error(aMessage);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
addListeners() {
|
|
238
|
+
|
|
239
|
+
this._webSocket.on('error', this._callback_error);
|
|
240
|
+
this._webSocket.on('message', this._callback_messageBound);
|
|
241
|
+
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
outputEncodedData(aId, aData, aEncoding) {
|
|
246
|
+
console.log("WebSocketConnection::outputEncodedData");
|
|
247
|
+
|
|
248
|
+
this._webSocket.send(JSON.stringify({"type": "updateEncodedObject", "id": aId, "data": aData, "encoding": aEncoding}));
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
setInitialUser(aId) {
|
|
253
|
+
|
|
254
|
+
//METODO: set the user for connection
|
|
255
|
+
|
|
256
|
+
this._webSocket.send(JSON.stringify({"type": "connectionReady", "user": aId}));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class AddIncomigRelation extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
performChange(aObject, aData, aRequest) {
|
|
10
|
+
aObject.addIncomingRelation(aData["value"], aData["type"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class AddOutgoingRelation extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
performChange(aObject, aData, aRequest) {
|
|
10
|
+
aObject.addOutgoingRelation(aData["value"], aData["type"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class SetField extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
performChange(aObject, aData, aRequest) {
|
|
10
|
+
aObject.updateField(aData["field"], aData["value"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import DbmGraphApi from "../../../../index.js";
|
|
2
|
+
export {default as EditBaseObject} from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export {default as SetField} from "./SetField.js";
|
|
5
|
+
export {default as AddIncomingRelation} from "./AddIncomingRelation.js";
|
|
6
|
+
export {default as AddOutgoingRelation} from "./AddOutgoingRelation.js";
|
|
7
|
+
|
|
8
|
+
let fullSetup = function() {
|
|
9
|
+
let prefix = "graphApi/admin/edit/";
|
|
10
|
+
{
|
|
11
|
+
let name = "setField";
|
|
12
|
+
let currentSelect = new DbmGraphApi.admin.edit.SetField();
|
|
13
|
+
currentSelect.item.register(prefix + name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
{
|
|
17
|
+
let name = "addIncomingRelation";
|
|
18
|
+
let currentSelect = new DbmGraphApi.admin.edit.AddIncomingRelation();
|
|
19
|
+
currentSelect.item.register(prefix + name);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
{
|
|
23
|
+
let name = "addOutgoingRelation";
|
|
24
|
+
let currentSelect = new DbmGraphApi.admin.edit.AddOutgoingRelation();
|
|
25
|
+
currentSelect.item.register(prefix + name);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {fullSetup};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as edit from "./edit/index.js";
|
|
@@ -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 getData(aData, aEncodeSession) {
|
|
9
|
+
let returnObject = {};
|
|
10
|
+
|
|
11
|
+
returnObject["example"] = "This is an example";
|
|
12
|
+
|
|
13
|
+
return returnObject;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
|
|
4
|
+
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
|
5
|
+
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
6
|
+
|
|
7
|
+
export default class UploadS3 extends Dbm.core.BaseObject {
|
|
8
|
+
_construct() {
|
|
9
|
+
super._construct();
|
|
10
|
+
|
|
11
|
+
this.item.requireProperty("client");
|
|
12
|
+
this.item.requireProperty("bucketName");
|
|
13
|
+
this.item.requireProperty("path", "content/{year}/{month}/{date}/{generatedId}/");
|
|
14
|
+
this.item.requireProperty("publicPath", "");
|
|
15
|
+
this.item.requireProperty("acl", "public-read");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getData(aData, aEncodeSession) {
|
|
19
|
+
let returnObject = {};
|
|
20
|
+
|
|
21
|
+
let fileName = aData["fileName"].toLowerCase();
|
|
22
|
+
let mimeType = aData["mimeType"];
|
|
23
|
+
|
|
24
|
+
fileName = fileName.replace(/[åäã]/gi, 'a');
|
|
25
|
+
fileName = fileName.replace(/[ö]/gi, 'o');
|
|
26
|
+
fileName = fileName.replace(/ /gi, '-');
|
|
27
|
+
fileName = fileName.replace(/[\(\),\*']/gi, '');
|
|
28
|
+
fileName = fileName.replace(/[^a-z0-9\-_\.]/gi, '-');
|
|
29
|
+
fileName = fileName.replace(/\-+/gi, '-');
|
|
30
|
+
|
|
31
|
+
let date = new Date();
|
|
32
|
+
|
|
33
|
+
let month = (date.getMonth()+1);
|
|
34
|
+
if(month < 10) month = "0" + month;
|
|
35
|
+
|
|
36
|
+
let dateDay = (date.getDate());
|
|
37
|
+
if(dateDay < 10) dateDay = "0" + dateDay;
|
|
38
|
+
|
|
39
|
+
let generatedId = crypto.randomBytes(6).toString('base64url');
|
|
40
|
+
|
|
41
|
+
let fullPath = this.item.path;
|
|
42
|
+
fullPath = fullPath.split("{year}").join(date.getFullYear());
|
|
43
|
+
fullPath = fullPath.split("{month}").join(month);
|
|
44
|
+
fullPath = fullPath.split("{date}").join(dateDay);
|
|
45
|
+
fullPath = fullPath.split("{generatedId}").join(generatedId);
|
|
46
|
+
|
|
47
|
+
//METODO: add to database
|
|
48
|
+
|
|
49
|
+
fileName = fullPath + fileName;
|
|
50
|
+
let acl = this.item.acl;
|
|
51
|
+
|
|
52
|
+
let command = new PutObjectCommand({
|
|
53
|
+
Bucket: this.item.bucketName,
|
|
54
|
+
Key: fileName,
|
|
55
|
+
ContentType: mimeType,
|
|
56
|
+
ACL: acl,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
let presignedUrl = await getSignedUrl(this.item.client, command, { expiresIn: 360 });
|
|
60
|
+
|
|
61
|
+
returnObject["url"] = presignedUrl;
|
|
62
|
+
returnObject["publicUrl"] = this.item.publicPath + fileName;
|
|
63
|
+
returnObject["acl"] = acl;
|
|
64
|
+
|
|
65
|
+
return returnObject;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export {default as Example} from "./Example.js";
|
|
2
|
+
export {default as UploadS3} from "./UploadS3.js";
|
|
3
|
+
|
|
4
|
+
import UploadS3 from "./UploadS3.js";
|
|
5
|
+
|
|
6
|
+
import { S3Client } from "@aws-sdk/client-s3";
|
|
7
|
+
|
|
8
|
+
export let createDigitalOceanSpacesUpload = function(aKeyId, aSecret, aRegion, aBucketName, aPublicPath = null) {
|
|
9
|
+
|
|
10
|
+
if(aPublicPath === null) {
|
|
11
|
+
aPublicPath = "https://" + aBucketName + "." + aRegion + ".cdn.digitaloceanspaces.com/";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let client = new S3Client({
|
|
15
|
+
endpoint: "https://" + aRegion + ".digitaloceanspaces.com",
|
|
16
|
+
forcePathStyle: false,
|
|
17
|
+
region: aRegion,
|
|
18
|
+
credentials: {
|
|
19
|
+
accessKeyId: aKeyId,
|
|
20
|
+
secretAccessKey: aSecret
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
let newUploadS3 = new UploadS3();
|
|
25
|
+
newUploadS3.item.client = client;
|
|
26
|
+
newUploadS3.item.bucketName = aBucketName;
|
|
27
|
+
newUploadS3.item.publicPath = aPublicPath;
|
|
28
|
+
|
|
29
|
+
return newUploadS3;
|
|
30
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
|
|
4
|
+
import DbmGraphApi from "../../index.js";
|
|
5
|
+
import Api from "./Api.js";
|
|
6
|
+
|
|
7
|
+
export {Api};
|
|
8
|
+
|
|
9
|
+
export * as range from "./range/index.js";
|
|
10
|
+
export * as admin from "./admin/index.js";
|
|
11
|
+
export * as data from "./data/index.js";
|
|
12
|
+
|
|
13
|
+
let fullSelectSetup = function() {
|
|
14
|
+
let selectPrefix = "graphApi/range/select/";
|
|
15
|
+
{
|
|
16
|
+
let name = "idSelection";
|
|
17
|
+
let currentSelect = new DbmGraphApi.range.select.IdSelection();
|
|
18
|
+
currentSelect.item.register(selectPrefix + name);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {fullSelectSetup};
|
|
23
|
+
|
|
24
|
+
let fullEncodeSetup = function() {
|
|
25
|
+
let encodePrefix = "graphApi/range/encode/";
|
|
26
|
+
{
|
|
27
|
+
let name = "example";
|
|
28
|
+
let currentEncode = new DbmGraphApi.range.encode.Example();
|
|
29
|
+
currentEncode.item.register(encodePrefix + name);
|
|
30
|
+
currentEncode.item.setValue("encodingType", name);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
{
|
|
34
|
+
let name = "identifier";
|
|
35
|
+
let currentEncode = new DbmGraphApi.range.encode.Identifier();
|
|
36
|
+
currentEncode.item.register(encodePrefix + name);
|
|
37
|
+
currentEncode.item.setValue("encodingType", name);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
let name = "name";
|
|
42
|
+
let currentEncode = new DbmGraphApi.range.encode.Name();
|
|
43
|
+
currentEncode.item.register(encodePrefix + name);
|
|
44
|
+
currentEncode.item.setValue("encodingType", name);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
{
|
|
48
|
+
let name = "content";
|
|
49
|
+
let currentEncode = new DbmGraphApi.range.encode.Content();
|
|
50
|
+
currentEncode.item.register(encodePrefix + name);
|
|
51
|
+
currentEncode.item.setValue("encodingType", name);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
{
|
|
55
|
+
let name = "title";
|
|
56
|
+
let currentEncode = new DbmGraphApi.range.encode.Title();
|
|
57
|
+
currentEncode.item.register(encodePrefix + name);
|
|
58
|
+
currentEncode.item.setValue("encodingType", name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
{
|
|
62
|
+
let name = "urlRequest";
|
|
63
|
+
let currentEncode = new DbmGraphApi.range.encode.UrlRequest();
|
|
64
|
+
currentEncode.item.register(encodePrefix + name);
|
|
65
|
+
currentEncode.item.setValue("encodingType", name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {fullEncodeSetup};
|
|
70
|
+
|
|
71
|
+
export let registerDataFunction = function(aName, aDataFunction) {
|
|
72
|
+
|
|
73
|
+
aDataFunction.item.register("graphApi/data/" + aName);
|
|
74
|
+
aDataFunction.item.setValue("functionName", aName);
|
|
75
|
+
|
|
76
|
+
return aDataFunction;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let fullDataSetup = function() {
|
|
80
|
+
registerDataFunction("example", new DbmGraphApi.data.Example());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export {fullDataSetup};
|
|
84
|
+
|
|
85
|
+
let fullSetup = function() {
|
|
86
|
+
|
|
87
|
+
fullSelectSetup();
|
|
88
|
+
fullEncodeSetup();
|
|
89
|
+
fullDataSetup();
|
|
90
|
+
|
|
91
|
+
DbmGraphApi.admin.edit.fullSetup();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export {fullSetup};
|
|
95
|
+
|
|
96
|
+
let setupEndpoints = function(aServer) {
|
|
97
|
+
aServer.post('/api/user/login', async function handler (aRequest, aReply) {
|
|
98
|
+
|
|
99
|
+
let username = aRequest.body['username'];
|
|
100
|
+
|
|
101
|
+
let user = await Dbm.getInstance().repository.getItem("graphDatabase").controller.getUserByUsername(username);
|
|
102
|
+
|
|
103
|
+
if(!user) {
|
|
104
|
+
//METODO: get user by email
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if(!user) {
|
|
108
|
+
return { success: false, error: "noUserFound", message: "No user found"};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let isCorrectPassword = await user.verifyPassword(aRequest.body['password']);
|
|
112
|
+
|
|
113
|
+
if(isCorrectPassword) {
|
|
114
|
+
let sessionId = await user.createSession();
|
|
115
|
+
|
|
116
|
+
let tempArray = sessionId.split(":");
|
|
117
|
+
let sessionDatabaseId = 1*tempArray[0];
|
|
118
|
+
let expiresTime = 1*tempArray[2];
|
|
119
|
+
let expiresDate = (new Date(expiresTime)).toUTCString();
|
|
120
|
+
|
|
121
|
+
aReply.header("Set-Cookie", "dbm_session=" +sessionId + "; Path=/; Expires=" + expiresDate + "; HttpOnly;");
|
|
122
|
+
|
|
123
|
+
let wsToken = crypto.randomBytes(32).toString('base64');
|
|
124
|
+
let expiryLength = 60;
|
|
125
|
+
let hashedWsToken = await user.generateSignedSessionToken(sessionDatabaseId, (new Date()).valueOf()+expiryLength*1000, wsToken, sessionId)
|
|
126
|
+
|
|
127
|
+
return { success: true, data: {id: user.id, "wsToken": hashedWsToken}};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return { success: false, error: "incorrect", message: "Incorrect details"};
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
aServer.get('/api/user/me', async function handler (aRequest, aReply) {
|
|
134
|
+
let cookies = aRequest.headers.cookie ? aRequest.headers.cookie.split(";") : [];
|
|
135
|
+
let currentArray = cookies;
|
|
136
|
+
let currentArrayLength = currentArray.length;
|
|
137
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
138
|
+
let [key, value] = currentArray[i].split("=");
|
|
139
|
+
if(key === "dbm_session" || key === " dbm_session") {
|
|
140
|
+
let userId = 1*value.split(":")[1];
|
|
141
|
+
let user = Dbm.getInstance().repository.getItem("graphDatabase").controller.getUser(userId);
|
|
142
|
+
|
|
143
|
+
let isValidSession = await user.verifySession(value);
|
|
144
|
+
if(isValidSession) {
|
|
145
|
+
return {success: true, data: {id: userId}};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {success: false, data: null};
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
aServer.post('/api/user/logout', async function handler (aRequest, aReply) {
|
|
154
|
+
console.log(aRequest.body);
|
|
155
|
+
|
|
156
|
+
//METODO: clear session from database
|
|
157
|
+
//METODO: clear cookie
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
aServer.post('/api/user/renewSession', async function handler (aRequest, aReply) {
|
|
161
|
+
console.log(aRequest.body);
|
|
162
|
+
|
|
163
|
+
//METODO: clear session from database
|
|
164
|
+
//METODO: clear cookie
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
//METODO: setup ranges
|
|
168
|
+
//METODO: setup edit
|
|
169
|
+
//METODO: setup data
|
|
170
|
+
//METODO: setup actions
|
|
171
|
+
//METODO: setup cron
|
|
172
|
+
|
|
173
|
+
aServer.get('/api/', async function handler (aRequest, aResponse) {
|
|
174
|
+
return { version: Dbm.getInstance().repository.getItem("site").version };
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
aServer.get('/api/*', async function handler (aRequest, aResponse) {
|
|
178
|
+
aResponse.code(404);
|
|
179
|
+
return { success: false, error: "notFound", message: "Not found" };
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export {setupEndpoints};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
|
|
3
|
+
export default class EncodeSession extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this._encodings = {};
|
|
8
|
+
this.outputController = null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
_readyToEncode(aId, aType) {
|
|
12
|
+
let encodings = this._encodings[aId];
|
|
13
|
+
if(!encodings) {
|
|
14
|
+
encodings = this._encodings[aId] = {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if(encodings[aType]) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (encodings[aType] = true);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
_encodeSingleNoAwait(aId, aType) {
|
|
25
|
+
console.log("_encodeSingleNoAwait");
|
|
26
|
+
|
|
27
|
+
let shouldEncode = this._readyToEncode(aId, aType);
|
|
28
|
+
console.log(shouldEncode, aId, aType);
|
|
29
|
+
if(shouldEncode) {
|
|
30
|
+
let encoding = Dbm.getInstance().repository.getItemIfExists("graphApi/range/encode/" + aType);
|
|
31
|
+
if(encoding) {
|
|
32
|
+
return encoding.controller.encodeSingle(aId, this);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async encodeSingle(aId, aType) {
|
|
38
|
+
console.log("encodeSingle");
|
|
39
|
+
|
|
40
|
+
await this._encodeSingleNoAwait(aId, aType);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async encodeSingleWithTypes(aId, aTypes) {
|
|
44
|
+
let currentArray = aTypes;
|
|
45
|
+
let currentArrayLength = currentArray.length;
|
|
46
|
+
let promises = new Array(currentArrayLength);
|
|
47
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
48
|
+
promises[i] = this._encodeSingleNoAwait(aId, currentArray[i]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
await Promise.all(promises);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async encode(aIds, aType) {
|
|
55
|
+
let currentArray = aIds;
|
|
56
|
+
let currentArrayLength = currentArray.length;
|
|
57
|
+
let ids = new Array(currentArrayLength);
|
|
58
|
+
let promises = new Array(currentArrayLength);
|
|
59
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
60
|
+
let id = currentArray[i];
|
|
61
|
+
promises[i] = this._encodeSingleNoAwait(id, aType);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await Promise.all(promises);
|
|
65
|
+
|
|
66
|
+
return ids;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async encodeObjectOrNull(aObject, aType) {
|
|
70
|
+
if(!aObject) {
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
await this.encodeSingle(aObject.id, aType);
|
|
75
|
+
return aObject.id;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async encodeObjects(aObjects, aType) {
|
|
79
|
+
let currentArray = aObjects;
|
|
80
|
+
let currentArrayLength = currentArray.length;
|
|
81
|
+
let ids = new Array(currentArrayLength);
|
|
82
|
+
let promises = new Array(currentArrayLength);
|
|
83
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
84
|
+
let object = currentArray[i];
|
|
85
|
+
ids[i] = object.id;
|
|
86
|
+
promises[i] = this._encodeSingleNoAwait(object.id, aType);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
await Promise.all(promises);
|
|
90
|
+
|
|
91
|
+
return ids;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
outputEncodedData(aId, aData, aEncoding) {
|
|
95
|
+
//console.log("EncodeSession::outputEncodedData");
|
|
96
|
+
|
|
97
|
+
this.outputController.outputEncodedData(aId, aData, aEncoding);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
|
|
3
|
+
export default class Query extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this._includeOnly = null;
|
|
8
|
+
this._visibilities = ["public"];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
includeOnly(aIds) {
|
|
12
|
+
if(!this._includeOnly) {
|
|
13
|
+
this._includeOnly = aIds;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this._includeOnly = this._includeOnly.filter(value => aIds.includes(value));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
includeNone() {
|
|
23
|
+
this._includeOnly = [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getIds() {
|
|
27
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
28
|
+
|
|
29
|
+
let query = "SELECT Objects.id as id FROM Objects";
|
|
30
|
+
|
|
31
|
+
let whereStatements = [];
|
|
32
|
+
if(this._includeOnly !== null) {
|
|
33
|
+
if(this._includeOnly.length === 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
whereStatements.push("Objects.id IN (" + this._includeOnly.join(",") + ")");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//METODO: include visibility
|
|
40
|
+
|
|
41
|
+
if(whereStatements.length) {
|
|
42
|
+
query += " WHERE " + whereStatements.join(" AND ");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let result = await database.connection.query(query);
|
|
46
|
+
let currentArray = result[0];
|
|
47
|
+
let currentArrayLength = currentArray.length;
|
|
48
|
+
let returnArray = new Array(currentArrayLength);
|
|
49
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
50
|
+
returnArray[i] = currentArray[i]["id"];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
return returnArray;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Content 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["content"] = fields["content"] ? fields["content"] : null;
|
|
17
|
+
|
|
18
|
+
return returnObject;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
|
|
3
|
+
export default class EncodeBaseObject extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async encode(aIds, aEncodingSession) {
|
|
9
|
+
|
|
10
|
+
let encodingPromises = [];
|
|
11
|
+
|
|
12
|
+
let currentArray = aIds;
|
|
13
|
+
let currentArrayLength = currentArray.length;
|
|
14
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
15
|
+
let currentId = currentArray[i];
|
|
16
|
+
encodingPromises.push(this.encodeSingle(currentId, aEncodingSession));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
await Promise.all(encodingPromises);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async encodeSingle(aId, aEncodingSession) {
|
|
23
|
+
//console.log("EncodeBaseObject::encodeSingle");
|
|
24
|
+
|
|
25
|
+
let data = await this.getEncodedData(aId, aEncodingSession);
|
|
26
|
+
aEncodingSession.outputEncodedData(aId, data, this.item.encodingType);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getEncodedData(aId, aRequest) {
|
|
30
|
+
//console.log("EncodeBaseObject::encodeSingle");
|
|
31
|
+
|
|
32
|
+
//MENOTE: should be overridden
|
|
33
|
+
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Example extends EncodeBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getEncodedData(aId, aEncodingSession) {
|
|
10
|
+
|
|
11
|
+
let returnObject = {};
|
|
12
|
+
|
|
13
|
+
returnObject["example"] = "This is an example";
|
|
14
|
+
|
|
15
|
+
return returnObject;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Identifier 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
|
+
returnObject["identifier"] = await object.getIdentifier();
|
|
16
|
+
|
|
17
|
+
return returnObject;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Name 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["name"] = fields["name"] ? fields["name"] : null;
|
|
17
|
+
|
|
18
|
+
return returnObject;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Title 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["title"] = fields["title"] ? fields["title"] : null;
|
|
17
|
+
|
|
18
|
+
return returnObject;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class UrlRequest extends EncodeBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getEncodedData(aId, aEncodingSession) {
|
|
10
|
+
console.log("UrlRequest::getEncodedData");
|
|
11
|
+
|
|
12
|
+
let returnObject = {};
|
|
13
|
+
|
|
14
|
+
let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
|
|
15
|
+
|
|
16
|
+
await aEncodingSession.encodeSingle(aId, "title");
|
|
17
|
+
await aEncodingSession.encodeSingle(aId, "content");
|
|
18
|
+
|
|
19
|
+
let fields = await object.getFields();
|
|
20
|
+
returnObject["meta/description"] = fields["meta/description"] ? fields["meta/description"] : null;
|
|
21
|
+
|
|
22
|
+
return returnObject;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export {default as EncodeBaseObject} from "./EncodeBaseObject.js";
|
|
2
|
+
|
|
3
|
+
export {default as Example} from "./Example.js";
|
|
4
|
+
export {default as Identifier} from "./Identifier.js";
|
|
5
|
+
export {default as Name} from "./Name.js";
|
|
6
|
+
export {default as Content} from "./Content.js";
|
|
7
|
+
export {default as Title} from "./Title.js";
|
|
8
|
+
export {default as UrlRequest} from "./UrlRequest.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
|
|
3
|
+
import SelectBaseObject from "./SelectBaseObject.js";
|
|
4
|
+
|
|
5
|
+
export default class IdSelection extends SelectBaseObject {
|
|
6
|
+
_construct() {
|
|
7
|
+
super._construct();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async select(aQuery, aData, aRequest) {
|
|
11
|
+
aQuery.includeOnly(aData["ids"]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async filter(aIds, aData, aRequest) {
|
|
15
|
+
return aIds;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
|
|
3
|
+
export default class SelectBaseObject extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async select(aQuery, aData, aRequest) {
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async filter(aIds, aData, aRequest) {
|
|
13
|
+
return aIds;
|
|
14
|
+
}
|
|
15
|
+
}
|