dbm-graph-api 1.0.0 → 1.0.2
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 +2 -1
- package/src/dbm-graph-api/UrlRequest.js +54 -0
- package/src/dbm-graph-api/admin/edit/SetUrl.js +12 -0
- package/src/dbm-graph-api/admin/edit/index.js +7 -0
- package/src/dbm-graph-api/data/FreeUrl.js +34 -0
- package/src/dbm-graph-api/data/index.js +1 -0
- package/src/dbm-graph-api/index.js +27 -0
- package/src/dbm-graph-api/range/encode/Url.js +20 -0
- package/src/dbm-graph-api/range/encode/UrlRequest.js +1 -0
- package/src/dbm-graph-api/range/encode/index.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbm-graph-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@aws-sdk/client-s3": "^3.693.0",
|
|
15
15
|
"@aws-sdk/s3-request-presigner": "^3.693.0",
|
|
16
|
+
"dbm": "^1.0.0",
|
|
16
17
|
"ws": "^8.18.0"
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import DbmGraphApi from "../../index.js";
|
|
3
|
+
|
|
4
|
+
export default class UrlRequest extends Dbm.core.BaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this._encodedObjects = [];
|
|
9
|
+
this._responseData = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async requestUrl(aUrl) {
|
|
13
|
+
|
|
14
|
+
let url = aUrl;
|
|
15
|
+
|
|
16
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
17
|
+
let urlObject = await database.getObjectByUrl(url);
|
|
18
|
+
|
|
19
|
+
if(urlObject) {
|
|
20
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
21
|
+
encodeSession.outputController = this;
|
|
22
|
+
|
|
23
|
+
await encodeSession.encodeSingleWithTypes(urlObject.id, ["urlRequest"]);
|
|
24
|
+
encodeSession.destroy();
|
|
25
|
+
this._responseData = {"id": urlObject.id};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this._responseData = {"id": 0};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async requestRange(aSelects, aEncodes, aData) {
|
|
33
|
+
//METODO
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async requestItem(aId, aEncodes) {
|
|
37
|
+
//METODO
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async requestData(aFunctionName, aData) {
|
|
41
|
+
//METODO
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
outputEncodedData(aId, aData, aEncoding) {
|
|
45
|
+
console.log("UrlRequest::outputEncodedData");
|
|
46
|
+
|
|
47
|
+
this._encodedObjects.push({"id": aId, "data": aData, "encoding": aEncoding});
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getResponse() {
|
|
52
|
+
return {"objects": this._encodedObjects, "data": this._responseData};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class SetUrl extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
performChange(aObject, aData, aRequest) {
|
|
10
|
+
aObject.setUrl(aData["value"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -2,6 +2,7 @@ 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 SetUrl} from "./SetUrl.js";
|
|
5
6
|
export {default as AddIncomingRelation} from "./AddIncomingRelation.js";
|
|
6
7
|
export {default as AddOutgoingRelation} from "./AddOutgoingRelation.js";
|
|
7
8
|
|
|
@@ -13,6 +14,12 @@ let fullSetup = function() {
|
|
|
13
14
|
currentSelect.item.register(prefix + name);
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
{
|
|
18
|
+
let name = "setUrl";
|
|
19
|
+
let currentSelect = new DbmGraphApi.admin.edit.SetUrl();
|
|
20
|
+
currentSelect.item.register(prefix + name);
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
{
|
|
17
24
|
let name = "addIncomingRelation";
|
|
18
25
|
let currentSelect = new DbmGraphApi.admin.edit.AddIncomingRelation();
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
let requestedUrl = aData["url"];
|
|
12
|
+
let returnUrl = requestedUrl;
|
|
13
|
+
|
|
14
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
15
|
+
|
|
16
|
+
let urlObject = await database.getObjectByUrl(requestedUrl + "/");
|
|
17
|
+
|
|
18
|
+
if(urlObject) {
|
|
19
|
+
let exisitingUrls = await database.getUrlsForNextId(requestedUrl);
|
|
20
|
+
let idsToTry = exisitingUrls.length + 1;
|
|
21
|
+
for(let i = 0; i < idsToTry; i++) {
|
|
22
|
+
let currentId = i+2;
|
|
23
|
+
let testUrl = requestedUrl + "-" + currentId;
|
|
24
|
+
if(exisitingUrls.indexOf(testUrl + "/") === -1) {
|
|
25
|
+
returnUrl = testUrl;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
returnObject["url"] = returnUrl;
|
|
31
|
+
|
|
32
|
+
return returnObject;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -3,6 +3,7 @@ import crypto from "node:crypto";
|
|
|
3
3
|
|
|
4
4
|
import DbmGraphApi from "../../index.js";
|
|
5
5
|
import Api from "./Api.js";
|
|
6
|
+
import UrlRequest from "./UrlRequest.js";
|
|
6
7
|
|
|
7
8
|
export {Api};
|
|
8
9
|
|
|
@@ -58,6 +59,13 @@ let fullEncodeSetup = function() {
|
|
|
58
59
|
currentEncode.item.setValue("encodingType", name);
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
{
|
|
63
|
+
let name = "url";
|
|
64
|
+
let currentEncode = new DbmGraphApi.range.encode.Url();
|
|
65
|
+
currentEncode.item.register(encodePrefix + name);
|
|
66
|
+
currentEncode.item.setValue("encodingType", name);
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
{
|
|
62
70
|
let name = "urlRequest";
|
|
63
71
|
let currentEncode = new DbmGraphApi.range.encode.UrlRequest();
|
|
@@ -78,6 +86,7 @@ export let registerDataFunction = function(aName, aDataFunction) {
|
|
|
78
86
|
|
|
79
87
|
let fullDataSetup = function() {
|
|
80
88
|
registerDataFunction("example", new DbmGraphApi.data.Example());
|
|
89
|
+
registerDataFunction("admin/freeUrl", new DbmGraphApi.data.FreeUrl());
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
export {fullDataSetup};
|
|
@@ -163,6 +172,24 @@ let setupEndpoints = function(aServer) {
|
|
|
163
172
|
//METODO: clear session from database
|
|
164
173
|
//METODO: clear cookie
|
|
165
174
|
});
|
|
175
|
+
|
|
176
|
+
aServer.get('/api/url', async function handler (aRequest, aReply) {
|
|
177
|
+
//console.log(aRequest);
|
|
178
|
+
|
|
179
|
+
let url = aRequest.query.url;
|
|
180
|
+
|
|
181
|
+
if(url[url.length-1] !== "/") {
|
|
182
|
+
url += "/";
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
console.log(url);
|
|
186
|
+
//METODO: check visibility in database
|
|
187
|
+
let request = new UrlRequest();
|
|
188
|
+
|
|
189
|
+
await request.requestUrl(url);
|
|
190
|
+
|
|
191
|
+
return request.getResponse();
|
|
192
|
+
});
|
|
166
193
|
|
|
167
194
|
//METODO: setup ranges
|
|
168
195
|
//METODO: setup edit
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Url 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 url = await object.getUrl();
|
|
16
|
+
returnObject["url"] = url;
|
|
17
|
+
|
|
18
|
+
return returnObject;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -15,6 +15,7 @@ export default class UrlRequest extends EncodeBaseObject {
|
|
|
15
15
|
|
|
16
16
|
await aEncodingSession.encodeSingle(aId, "title");
|
|
17
17
|
await aEncodingSession.encodeSingle(aId, "content");
|
|
18
|
+
await aEncodingSession.encodeSingle(aId, "url");
|
|
18
19
|
|
|
19
20
|
let fields = await object.getFields();
|
|
20
21
|
returnObject["meta/description"] = fields["meta/description"] ? fields["meta/description"] : null;
|
|
@@ -5,4 +5,5 @@ export {default as Identifier} from "./Identifier.js";
|
|
|
5
5
|
export {default as Name} from "./Name.js";
|
|
6
6
|
export {default as Content} from "./Content.js";
|
|
7
7
|
export {default as Title} from "./Title.js";
|
|
8
|
-
export {default as UrlRequest} from "./UrlRequest.js";
|
|
8
|
+
export {default as UrlRequest} from "./UrlRequest.js";
|
|
9
|
+
export {default as Url} from "./Url.js";
|