dbm 1.0.1 → 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.
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import Dbm from "../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class ApiConnection extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this._url = null;
|
|
8
|
+
this._setupItemResponseBound = this._setupItemResponse.bind(this);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setup(aUrl) {
|
|
12
|
+
|
|
13
|
+
this._url = aUrl;
|
|
14
|
+
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_getRequestItem() {
|
|
19
|
+
|
|
20
|
+
let request = new Dbm.graphapi.webclient.ApiRequest();
|
|
21
|
+
request.item.setValue("status", Dbm.loading.LoadingStatus.NOT_STARTED);
|
|
22
|
+
request.item.setValue("connection", this.item);
|
|
23
|
+
|
|
24
|
+
return request.item;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
requestRange(aSelect, aEncode) {
|
|
28
|
+
let item = this._getRequestItem();
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
return item;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
requestItem(aId, aEncode) {
|
|
35
|
+
let item = this._getRequestItem();
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
return item;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
requestData(aFunctionName, aData) {
|
|
42
|
+
let item = this._getRequestItem();
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
return item;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
createItem(aTypes, aVisibility = "draft", aChanges = [], aEncode = []) {
|
|
49
|
+
let item = this._getRequestItem();
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
return item;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
editItem(aId, aChanges, aEncode = []) {
|
|
56
|
+
let item = this._getRequestItem();
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
return item;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_updateObjects(aObjects) {
|
|
63
|
+
let repository = Dbm.getInstance().repository;
|
|
64
|
+
|
|
65
|
+
let currentArray = aObjects;
|
|
66
|
+
let currentArrayLength = currentArray.length;
|
|
67
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
68
|
+
let data = currentArray[i];
|
|
69
|
+
let item = repository.getItem(data["id"]);
|
|
70
|
+
let decoder = repository.getItemIfExists("graphApi/decode/" + data["encoding"]);
|
|
71
|
+
if(decoder) {
|
|
72
|
+
decoder.controller.updateItemWithEncoding(item, data["data"]);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
console.warn("No decoder for " + data["encoding"]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_setupItemResponse(aRequestItem, aData) {
|
|
81
|
+
this._updateObjects(aData.objects);
|
|
82
|
+
|
|
83
|
+
let repository = Dbm.getInstance().repository;
|
|
84
|
+
|
|
85
|
+
let id = aData.data.id;
|
|
86
|
+
if(id) {
|
|
87
|
+
aRequestItem.setValue("item", repository.getItem(id));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
aRequestItem.setValue("item", null);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
aRequestItem.status = 1;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
requestUrl(aUrl) {
|
|
97
|
+
|
|
98
|
+
let item = this._getRequestItem();
|
|
99
|
+
|
|
100
|
+
let fullUrl = this._url + "url?url=" + encodeURIComponent(aUrl);
|
|
101
|
+
fetch(fullUrl).then((aRequest) => {
|
|
102
|
+
return aRequest.json();
|
|
103
|
+
}).then((aData) => {
|
|
104
|
+
this._setupItemResponseBound(item, aData);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return item;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Dbm from "../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class ApiRequest extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get processPromise() {
|
|
10
|
+
if(this.item.status === Dbm.loading.LoadingStatus.LOADED) {
|
|
11
|
+
return Promise.resolve(this.item);
|
|
12
|
+
}
|
|
13
|
+
if(this.item.status === Dbm.loading.LoadingStatus.LOADING || this.item.status === Dbm.loading.LoadingStatus.NOT_STARTED) {
|
|
14
|
+
if(!this.item.processPromise) {
|
|
15
|
+
let resolveCommand = Dbm.commands.resolvePromise(this.item);
|
|
16
|
+
this.item.setValue("doneCommands", [resolveCommand]);
|
|
17
|
+
let rejectCommand = Dbm.commands.callFunction(resolveCommand.item.reject, []);
|
|
18
|
+
this.item.setValue("errorCommands", [rejectCommand]);
|
|
19
|
+
|
|
20
|
+
//METODO: change these to addToArray
|
|
21
|
+
|
|
22
|
+
this.item.setValue("processPromise", resolveCommand.item.promise);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return this.item.processPromise;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return Promise.reject();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import Dbm from "../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class GraphApi extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this._websocketConnection = null;
|
|
8
|
+
this._apiConnection = null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setWebsocketConnection(aConnection) {
|
|
12
|
+
this._websocketConnection = aConnection;
|
|
13
|
+
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setApiConnection(aConnection) {
|
|
18
|
+
this._apiConnection = aConnection;
|
|
19
|
+
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
requestRange(aSelect, aEncode) {
|
|
24
|
+
return this._websocketConnection.requestRange(aSelect, aEncode);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
requestItem(aId, aEncode) {
|
|
28
|
+
return this._websocketConnection.requestItem(aId, aEncode);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
requestData(aFunctionName, aData) {
|
|
32
|
+
return this._websocketConnection.requestData(aFunctionName, aData);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
createItem(aTypes, aVisibility = "draft", aChanges = [], aEncode = []) {
|
|
36
|
+
return this._websocketConnection.createItem(aTypes, aVisibility, aChanges, aEncode);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
editItem(aId, aChanges, aEncode = []) {
|
|
40
|
+
return this._websocketConnection.editItem(aId, aChanges, aEncode);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
requestUrl(aUrl) {
|
|
44
|
+
//console.log("requestUrl");
|
|
45
|
+
//console.log(aUrl);
|
|
46
|
+
|
|
47
|
+
if(this._websocketConnection && this._websocketConnection.item.status === 1) {
|
|
48
|
+
return this._websocketConnection.requestUrl(aUrl);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return this._apiConnection.requestUrl(aUrl);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
signIn(aToken) {
|
|
55
|
+
return this._websocketConnection.signIn(aToken);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
signOut() {
|
|
59
|
+
return this._websocketConnection.signOut();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -60,7 +60,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
requestData(aFunctionName, aData) {
|
|
63
|
-
console.log("requestData");
|
|
63
|
+
//console.log("requestData");
|
|
64
64
|
let item = this._getRequestItem();
|
|
65
65
|
item.setValue("requestData", {"type": "data", "functionName": aFunctionName, "data": aData, "requestId": item.id});
|
|
66
66
|
this._runRequest(item);
|
|
@@ -85,6 +85,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
requestUrl(aUrl) {
|
|
88
|
+
|
|
88
89
|
let item = this._getRequestItem();
|
|
89
90
|
item.setValue("requestData", {"type": "url", "url": aUrl, "requestId": item.id});
|
|
90
91
|
this._runRequest(item);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export {default as WebSocketConnection} from "./WebSocketConnection.js";
|
|
2
2
|
export {default as WebSocketRequest} from "./WebSocketRequest.js";
|
|
3
|
+
export {default as GraphApi} from "./GraphApi.js";
|
|
4
|
+
export {default as ApiConnection} from "./ApiConnection.js";
|
|
5
|
+
export {default as ApiRequest} from "./ApiRequest.js";
|
|
3
6
|
|
|
4
7
|
export * as decode from "./decode/index.js";
|