forked from PrivateSky/OpenDSU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
122 lines (110 loc) · 4.81 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
html API space
*/
let constants = require("./moduleConstants.js");
switch ($$.environmentType) {
case constants.ENVIRONMENT_TYPES.SERVICE_WORKER_ENVIRONMENT_TYPE:
if (typeof self !== "undefined") {
if(!self.PREVENT_DOUBLE_LOADING_OF_OPENDSU) {
self.PREVENT_DOUBLE_LOADING_OF_OPENDSU = {}
}
}
break;
case constants.ENVIRONMENT_TYPES.BROWSER_ENVIRONMENT_TYPE:
if (typeof window !== "undefined") {
if(!window.PREVENT_DOUBLE_LOADING_OF_OPENDSU){
window.PREVENT_DOUBLE_LOADING_OF_OPENDSU = {}
}
}
break;
case constants.ENVIRONMENT_TYPES.NODEJS_ENVIRONMENT_TYPE:
default:
if (typeof global !== "undefined") {
if(!global.PREVENT_DOUBLE_LOADING_OF_OPENDSU){
global.PREVENT_DOUBLE_LOADING_OF_OPENDSU = {}
}
}
}
if(!PREVENT_DOUBLE_LOADING_OF_OPENDSU.INITIALISED){
PREVENT_DOUBLE_LOADING_OF_OPENDSU.INITIALISED = true;
function loadApi(apiSpaceName){
switch (apiSpaceName) {
case "http":return require("./http"); break;
case "crypto":return require("./crypto"); break;
case "anchoring":return require("./anchoring"); break;
case "bricking":return require("./bricking"); break;
case "bdns":return require("./bdns"); break;
case "dc":return require("./dc"); break;
case "dt":return require("./dt"); break;
case "keyssi":return require("./keyssi"); break;
case "mq":return require("./mq"); break;
case "notifications":return require("./notifications"); break;
case "resolver":return require("./resolver"); break;
case "sc":return require("./sc"); break;
case "cache":return require("./cache"); break;
case "config":return require("./config"); break;
case "system":return require("./system"); break;
case "db":return require("./db"); break;
case "error":return require("./error"); break;
default: throw new Error("Unknown API space " + apiSpaceName);
}
}
function setGlobalVariable(name, value){
switch ($$.environmentType) {
case constants.ENVIRONMENT_TYPES.SERVICE_WORKER_ENVIRONMENT_TYPE:
if (typeof self !== "undefined") {
self[name] = value;
} else {
reportUserRelevantError("self not defined in Service Workers");
}
break;
case constants.ENVIRONMENT_TYPES.BROWSER_ENVIRONMENT_TYPE:
if (typeof window !== "undefined") {
window[name] = value;
}else {
reportUserRelevantError("window not defined in browser environment");
}
break;
case constants.ENVIRONMENT_TYPES.NODEJS_ENVIRONMENT_TYPE:
default:
if (typeof global !== "undefined") {
global[name] = value;
} else {
reportUserRelevantError("global not defined in nodejs environment");
}
}
};
function getGlobalVariable(name){
switch ($$.environmentType) {
case constants.ENVIRONMENT_TYPES.SERVICE_WORKER_ENVIRONMENT_TYPE:
return self[name];
case constants.ENVIRONMENT_TYPES.BROWSER_ENVIRONMENT_TYPE:
return window[name];
case constants.ENVIRONMENT_TYPES.NODEJS_ENVIRONMENT_TYPE:
default:
return global[name];
}
};
function globalVariableExists(name){
switch ($$.environmentType) {
case constants.ENVIRONMENT_TYPES.SERVICE_WORKER_ENVIRONMENT_TYPE:
return typeof self[name] != "undefined";
case constants.ENVIRONMENT_TYPES.BROWSER_ENVIRONMENT_TYPE:
return typeof window[name] != "undefined";
case constants.ENVIRONMENT_TYPES.NODEJS_ENVIRONMENT_TYPE:
default:
return typeof global[name] != "undefined";
}
};
PREVENT_DOUBLE_LOADING_OF_OPENDSU.loadApi = loadApi;
PREVENT_DOUBLE_LOADING_OF_OPENDSU.loadAPI = loadApi; //upper case version just
PREVENT_DOUBLE_LOADING_OF_OPENDSU.globalVariableExists = setGlobalVariable;
PREVENT_DOUBLE_LOADING_OF_OPENDSU.setGlobalVariable = setGlobalVariable;
PREVENT_DOUBLE_LOADING_OF_OPENDSU.getGlobalVariable = getGlobalVariable;
PREVENT_DOUBLE_LOADING_OF_OPENDSU.constants = constants;
setGlobalVariable("setGlobalVariable",setGlobalVariable);
setGlobalVariable("getGlobalVariable",getGlobalVariable);
setGlobalVariable("globalVariableExists",globalVariableExists);
require("./config/autoConfig");
}
module.exports = PREVENT_DOUBLE_LOADING_OF_OPENDSU;