dbm-graph-api 1.1.16 → 1.1.18
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 -2
- package/src/dbm-graph-api/admin/edit/AddObjectType.js +12 -0
- package/src/dbm-graph-api/admin/edit/RemoveObjectType.js +12 -0
- package/src/dbm-graph-api/admin/edit/ReplaceMultipleIncomingRelations.js +12 -0
- package/src/dbm-graph-api/admin/edit/ReplaceMultipleOutgoingRelations.js +12 -0
- package/src/dbm-graph-api/admin/edit/index.js +29 -0
- package/src/dbm-graph-api/data/HelpSectionSuggestions.js +6 -6
- package/src/dbm-graph-api/index.js +16 -0
- package/src/dbm-graph-api/range/encode/AtLocation.js +23 -0
- package/src/dbm-graph-api/range/encode/Location.js +30 -0
- package/src/dbm-graph-api/range/encode/MainImage.js +21 -0
- package/src/dbm-graph-api/range/encode/Relations.js +10 -0
- package/src/dbm-graph-api/range/encode/index.js +3 -0
- package/src/dbm-graph-api/schema/JsonLdGenerator.js +66 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbm-graph-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
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.
|
|
16
|
+
"dbm": "^1.1.13",
|
|
17
17
|
"mime": "^4.0.6",
|
|
18
18
|
"sharp": "^0.33.5",
|
|
19
19
|
"ws": "^8.18.0"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class AddObjectType extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.addObjectType(aData["value"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class AddObjectType extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.removeObjectType(aData["value"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class ReplaceMultipleIncomingRelations extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.replaceMultipleIncomingRelations(aData["value"], aData["type"], aData["objectType"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class ReplaceMultipleOutgoingRelations extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.replaceMultipleOutgoingRelations(aData["value"], aData["type"]), aData["objectType"];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -10,6 +10,11 @@ export {default as AddOutgoingRelation} from "./AddOutgoingRelation.js";
|
|
|
10
10
|
export {default as ClearCloudflareCache} from "./ClearCloudflareCache.js";
|
|
11
11
|
export {default as ReplaceIncomingRelation} from "./ReplaceIncomingRelation.js";
|
|
12
12
|
export {default as ReplaceOutgoingRelation} from "./ReplaceOutgoingRelation.js";
|
|
13
|
+
export {default as ReplaceMultipleIncomingRelations} from "./ReplaceMultipleIncomingRelations.js";
|
|
14
|
+
export {default as ReplaceMultipleOutgoingRelations} from "./ReplaceMultipleOutgoingRelations.js";
|
|
15
|
+
export {default as AddObjectType} from "./AddObjectType.js";
|
|
16
|
+
export {default as RemoveObjectType} from "./RemoveObjectType.js";
|
|
17
|
+
|
|
13
18
|
|
|
14
19
|
export const fullSetup = function() {
|
|
15
20
|
let prefix = "graphApi/admin/edit/";
|
|
@@ -61,9 +66,33 @@ export const fullSetup = function() {
|
|
|
61
66
|
currentSelect.item.register(prefix + name);
|
|
62
67
|
}
|
|
63
68
|
|
|
69
|
+
{
|
|
70
|
+
let name = "replaceMultipleIncomingRelations";
|
|
71
|
+
let currentSelect = new DbmGraphApi.admin.edit.ReplaceMultipleIncomingRelations();
|
|
72
|
+
currentSelect.item.register(prefix + name);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
let name = "replaceMultipleOutgoingRelations";
|
|
77
|
+
let currentSelect = new DbmGraphApi.admin.edit.ReplaceMultipleOutgoingRelations();
|
|
78
|
+
currentSelect.item.register(prefix + name);
|
|
79
|
+
}
|
|
80
|
+
|
|
64
81
|
{
|
|
65
82
|
let name = "clearCache";
|
|
66
83
|
let currentSelect = new DbmGraphApi.admin.edit.ClearCloudflareCache();
|
|
67
84
|
currentSelect.item.register(prefix + name);
|
|
68
85
|
}
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
let name = "addObjectType";
|
|
89
|
+
let currentSelect = new DbmGraphApi.admin.edit.AddObjectType();
|
|
90
|
+
currentSelect.item.register(prefix + name);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
{
|
|
94
|
+
let name = "removeObjectType";
|
|
95
|
+
let currentSelect = new DbmGraphApi.admin.edit.RemoveObjectType();
|
|
96
|
+
currentSelect.item.register(prefix + name);
|
|
97
|
+
}
|
|
69
98
|
}
|
|
@@ -23,22 +23,22 @@ export default class HelpSectionSuggestions extends Dbm.core.BaseObject {
|
|
|
23
23
|
"All about this section"
|
|
24
24
|
];
|
|
25
25
|
|
|
26
|
-
let alreadyAddedString = "The page already have these
|
|
26
|
+
let alreadyAddedString = "The page already have these faq sections: " + JSON.stringify(alreadyAdded);
|
|
27
27
|
|
|
28
|
-
let contentString =
|
|
28
|
+
let contentString = JSON.stringify(content);
|
|
29
29
|
|
|
30
|
-
let instructions = "
|
|
30
|
+
let instructions = "Generate a seo description for the page data provided by the user. Split up the description into different lines and only keep the ones that can be used to link to this page. {additionalInstructions} Respond with only a json object {seoDescription: string, linkTitles: array of string}, no markdown.";
|
|
31
31
|
instructions = instructions.split("{data}").join(contentString);
|
|
32
32
|
|
|
33
33
|
let additionalInstructions = "";
|
|
34
34
|
instructions = instructions.split("{additionalInstructions}").join(additionalInstructions);
|
|
35
35
|
|
|
36
36
|
let body = {
|
|
37
|
-
"model": "gpt-4o
|
|
37
|
+
"model": "gpt-4o",
|
|
38
38
|
"response_format": { "type": "json_object" },
|
|
39
39
|
"messages": [
|
|
40
40
|
{"role":"system","content": instructions},
|
|
41
|
-
{"role": "user", "content": alreadyAddedString}
|
|
41
|
+
/*{"role": "user", "content": alreadyAddedString},*/
|
|
42
42
|
{"role": "user", "content": contentString}
|
|
43
43
|
],
|
|
44
44
|
"temperature": 0.1
|
|
@@ -62,7 +62,7 @@ export default class HelpSectionSuggestions extends Dbm.core.BaseObject {
|
|
|
62
62
|
let responseContent = JSON.parse(message.content);
|
|
63
63
|
console.log(responseContent);
|
|
64
64
|
|
|
65
|
-
returnObject["titles"] = responseContent
|
|
65
|
+
returnObject["titles"] = responseContent;
|
|
66
66
|
|
|
67
67
|
return returnObject;
|
|
68
68
|
}
|
|
@@ -59,8 +59,20 @@ let fullSelectSetup = function() {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
|
|
63
|
+
|
|
62
64
|
export {fullSelectSetup};
|
|
63
65
|
|
|
66
|
+
let registerEncoding = function(aName, aEncoder) {
|
|
67
|
+
let encodePrefix = "graphApi/range/encode/";
|
|
68
|
+
aEncoder.item.register(encodePrefix + aName);
|
|
69
|
+
aEncoder.item.setValue("encodingType", aName);
|
|
70
|
+
|
|
71
|
+
return aEncoder;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export {registerEncoding};
|
|
75
|
+
|
|
64
76
|
let fullEncodeSetup = function() {
|
|
65
77
|
let encodePrefix = "graphApi/range/encode/";
|
|
66
78
|
{
|
|
@@ -188,6 +200,10 @@ let fullEncodeSetup = function() {
|
|
|
188
200
|
currentEncode.item.register(encodePrefix + name);
|
|
189
201
|
currentEncode.item.setValue("encodingType", name);
|
|
190
202
|
}
|
|
203
|
+
|
|
204
|
+
registerEncoding("atLocation", new DbmGraphApi.range.encode.AtLocation());
|
|
205
|
+
registerEncoding("location", new DbmGraphApi.range.encode.Location());
|
|
206
|
+
registerEncoding("mainImage", new DbmGraphApi.range.encode.MainImage());
|
|
191
207
|
}
|
|
192
208
|
|
|
193
209
|
export {fullEncodeSetup};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class MainImage 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
|
+
{
|
|
16
|
+
let relatedItem = await object.singleObjectRelationQuery("out:at:location");
|
|
17
|
+
returnObject["location"] = await aEncodingSession.encodeObjectOrNull(relatedItem, "location");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
return returnObject;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Location 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["street"] = fields["street"] ? fields["street"] : null;
|
|
17
|
+
returnObject["postCode"] = fields["postCode"] ? fields["postCode"] : null;
|
|
18
|
+
returnObject["city"] = fields["city"] ? fields["city"] : null;
|
|
19
|
+
returnObject["country"] = fields["country"] ? fields["country"] : null;
|
|
20
|
+
|
|
21
|
+
if(fields["latitude"]) {
|
|
22
|
+
returnObject["coordinates"] = {latitude: fields["latitude"], longitude: fields["longitude"]};
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
returnObject["coordinates"] = null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return returnObject;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class MainImage 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 representingPage = await object.singleObjectRelationQuery("in:isMainImageFor:image");
|
|
16
|
+
|
|
17
|
+
returnObject["image"] = await aEncodingSession.encodeObjectOrNull(representingPage, "image");
|
|
18
|
+
|
|
19
|
+
return returnObject;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -18,6 +18,16 @@ export default class Relations extends EncodeBaseObject {
|
|
|
18
18
|
|
|
19
19
|
returnObject["relations"] = relations;
|
|
20
20
|
|
|
21
|
+
{
|
|
22
|
+
let ids = Dbm.utils.ArrayFunctions.mapField(relations["in"], "id");
|
|
23
|
+
await aEncodingSession.encodeObjects(database.getObjects(ids), "objectTypes");
|
|
24
|
+
}
|
|
25
|
+
{
|
|
26
|
+
let ids = Dbm.utils.ArrayFunctions.mapField(relations["out"], "id");
|
|
27
|
+
await aEncodingSession.encodeObjects(database.getObjects(ids), "objectTypes");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
21
31
|
return returnObject;
|
|
22
32
|
}
|
|
23
33
|
}
|
|
@@ -17,5 +17,8 @@ export {default as ObjectTypes} from "./ObjectTypes.js";
|
|
|
17
17
|
export {default as RepresentingPage} from "./RepresentingPage.js";
|
|
18
18
|
export {default as PageRepresentation} from "./PageRepresentation.js";
|
|
19
19
|
export {default as HelpSection} from "./HelpSection.js";
|
|
20
|
+
export {default as MainImage} from "./MainImage.js";
|
|
21
|
+
export {default as Location} from "./Location.js";
|
|
22
|
+
export {default as AtLocation} from "./AtLocation.js";
|
|
20
23
|
|
|
21
24
|
export * as admin from "./admin/index.js";
|
|
@@ -32,28 +32,49 @@ export default class JsonLdGenerator extends Dbm.core.BaseObject{
|
|
|
32
32
|
let site = Dbm.getInstance().repository.getItem("site");
|
|
33
33
|
let fields = await aDatabaseObject.getFields();
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
let returnObject = {
|
|
36
36
|
"@type": "Organization",
|
|
37
37
|
"@id": this.baseUrl + "/" + "#organization",
|
|
38
38
|
"url": this.baseUrl + "/",
|
|
39
39
|
"name": fields["name"] ? fields["name"] : site.name,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
let image = await aDatabaseObject.singleObjectRelationQuery("in:isLogoFor:image");
|
|
43
|
+
if(image) {
|
|
44
|
+
let fields = await image.getFields();
|
|
45
|
+
returnObject["logo"] = fields["url"];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return returnObject;
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
async encodeLocalBusiness(aDatabaseObject) {
|
|
46
52
|
|
|
53
|
+
|
|
47
54
|
let site = Dbm.getInstance().repository.getItem("site");
|
|
48
55
|
|
|
49
56
|
let type = await aDatabaseObject.singleObjectRelationQuery("in:for:schema/type");
|
|
50
|
-
let typeName =
|
|
57
|
+
let typeName = "LocalBusiness";
|
|
58
|
+
if(type) {
|
|
59
|
+
typeName = await type.getIdentifier();
|
|
60
|
+
}
|
|
61
|
+
|
|
51
62
|
let fields = await aDatabaseObject.getFields();
|
|
52
63
|
|
|
64
|
+
let baseUrl = this.baseUrl;
|
|
65
|
+
|
|
66
|
+
let representingPage = await aDatabaseObject.singleObjectRelationQuery("in:pageRepresentationFor:page");
|
|
67
|
+
if(representingPage) {
|
|
68
|
+
baseUrl += await representingPage.getUrl();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
baseUrl += "/";
|
|
72
|
+
}
|
|
73
|
+
|
|
53
74
|
let returnObject = {
|
|
54
75
|
"@type": typeName,
|
|
55
|
-
"@id":
|
|
56
|
-
"url":
|
|
76
|
+
"@id": baseUrl + "#local-business",
|
|
77
|
+
"url": baseUrl,
|
|
57
78
|
"name": fields["name"] ? fields["name"] : site.name,
|
|
58
79
|
"telephone": fields["phoneNumber"],
|
|
59
80
|
"email": fields["email"],
|
|
@@ -93,6 +114,12 @@ export default class JsonLdGenerator extends Dbm.core.BaseObject{
|
|
|
93
114
|
};
|
|
94
115
|
}
|
|
95
116
|
|
|
117
|
+
let image = await aDatabaseObject.singleObjectRelationQuery("in:isMainImageFor:image");
|
|
118
|
+
if(image) {
|
|
119
|
+
let fields = await image.getFields();
|
|
120
|
+
returnObject["image"] = fields["url"];
|
|
121
|
+
}
|
|
122
|
+
|
|
96
123
|
return returnObject;
|
|
97
124
|
}
|
|
98
125
|
|
|
@@ -107,13 +134,19 @@ export default class JsonLdGenerator extends Dbm.core.BaseObject{
|
|
|
107
134
|
returnArray.push(await this.encodeWebsiteEntity(website));
|
|
108
135
|
|
|
109
136
|
let organization = await website.singleObjectRelationQuery("out:by:organization");
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
let
|
|
116
|
-
|
|
137
|
+
if(organization) {
|
|
138
|
+
returnArray.push(await this.encodeOrganizationEntity(organization));
|
|
139
|
+
|
|
140
|
+
let currentArray = await website.objectRelationQuery("out:by:organization,in:in:localBusiness");
|
|
141
|
+
let currentArrayLength = currentArray.length;
|
|
142
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
143
|
+
let currentLocalBusiness = currentArray[i];
|
|
144
|
+
if(currentLocalBusiness) {
|
|
145
|
+
console.log(currentLocalBusiness);
|
|
146
|
+
returnArray.push(await this.encodeLocalBusiness(currentLocalBusiness));
|
|
147
|
+
console.log("-");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
117
150
|
}
|
|
118
151
|
}
|
|
119
152
|
|
|
@@ -140,7 +173,27 @@ export default class JsonLdGenerator extends Dbm.core.BaseObject{
|
|
|
140
173
|
"@id": fullUrl +"#breadcrumb"
|
|
141
174
|
},
|
|
142
175
|
|
|
143
|
-
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
let image = await aPage.singleObjectRelationQuery("in:isMainImageFor:image");
|
|
179
|
+
if(image) {
|
|
180
|
+
let fields = await image.getFields();
|
|
181
|
+
|
|
182
|
+
let imageObject = {
|
|
183
|
+
"@type": "ImageObject",
|
|
184
|
+
"url": fields["url"]
|
|
185
|
+
};
|
|
186
|
+
pageObject["primaryImageOfPage"] = imageObject;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
let representingEntity = await aPage.singleObjectRelationQuery("out:pageRepresentationFor:localBusiness");
|
|
191
|
+
if(representingEntity) {
|
|
192
|
+
pageObject["mainEntity"] = {
|
|
193
|
+
"@id": fullUrl + "#local-business"
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
144
197
|
returnArray.push(pageObject);
|
|
145
198
|
|
|
146
199
|
let urlParts = url.split("/");
|