godprotocol 1.2.25 → 1.2.26
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/Objects/Callable.js +197 -176
- package/Objects/Oracle.js +61 -294
- package/Objects/Virtual_machine.js +303 -263
- package/package.json +22 -15
- package/utils/vm_utils.js +162 -147
- package/repos/fs.js +0 -122
- package/repos/github.js +0 -185
- package/repos/ram.js +0 -47
package/package.json
CHANGED
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "godprotocol",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "A distributed computing environment",
|
|
3
|
+
"version": "1.2.26",
|
|
4
|
+
"description": "A distributed computing environment for Web 4.0 — integrating AI, decentralisation, and virtual computation.",
|
|
5
5
|
"main": "Index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
8
|
+
"start": "nodemon Index.js",
|
|
9
|
+
"dev": "node Index.js",
|
|
10
|
+
"test": "echo \"No test specified\" && exit 0"
|
|
9
11
|
},
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
12
14
|
"url": "git+https://github.com/immanuel-savvy/GodProtocol.git"
|
|
13
15
|
},
|
|
14
16
|
"keywords": [
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
+
"godprotocol",
|
|
18
|
+
"distributed",
|
|
19
|
+
"decentralized",
|
|
17
20
|
"web4",
|
|
18
21
|
"ai",
|
|
22
|
+
"blockweb",
|
|
23
|
+
"virtual-machine",
|
|
24
|
+
"loader-sequence",
|
|
19
25
|
"ar",
|
|
20
|
-
"vr"
|
|
21
|
-
"virtual-machine"
|
|
26
|
+
"vr"
|
|
22
27
|
],
|
|
23
|
-
"author": "Savvy",
|
|
28
|
+
"author": "Savvy <contact@yourdomain.com>",
|
|
24
29
|
"license": "ISC",
|
|
25
30
|
"bugs": {
|
|
26
31
|
"url": "https://github.com/immanuel-savvy/GodProtocol/issues"
|
|
27
32
|
},
|
|
28
|
-
"type": "module",
|
|
29
33
|
"homepage": "https://github.com/immanuel-savvy/GodProtocol#readme",
|
|
30
34
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"generalised-datastore": "latest",
|
|
34
|
-
"aircode4": "latest"
|
|
35
|
+
"aircode4": "latest",
|
|
36
|
+
"generalised-datastore": "latest"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"esm": "^3.2.25",
|
|
38
39
|
"nodemon": "^3.1.7"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
39
46
|
}
|
|
40
47
|
}
|
package/utils/vm_utils.js
CHANGED
|
@@ -16,103 +16,116 @@ import { hash } from "godprotocol/utils/hash.js";
|
|
|
16
16
|
class Vm_utils {
|
|
17
17
|
constructor() {
|
|
18
18
|
this.ops = ops;
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
this.datatypes = ["string", "number", "void", "boolean", "array", "twain"];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
gen_location=(addr)=>{
|
|
24
|
-
return `${addr|| this.account.physical_address}/${this.gen_uid(true)}
|
|
25
|
-
}
|
|
23
|
+
gen_location = (addr) => {
|
|
24
|
+
return `${addr || this.account.physical_address}/${this.gen_uid(true)}`;
|
|
25
|
+
};
|
|
26
26
|
|
|
27
|
-
error_instance = async(err_payload, alias)=>{
|
|
28
|
-
let {chain, manager} = this.account;
|
|
29
|
-
let res = await this.instantiate(
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
error_instance = async (err_payload, alias) => {
|
|
28
|
+
let { chain, manager } = this.account;
|
|
29
|
+
let res = await this.instantiate(
|
|
30
|
+
{ type: "error", ...err_payload },
|
|
31
|
+
{ chain }
|
|
32
|
+
);
|
|
33
|
+
if (alias) {
|
|
34
|
+
await (await manager.ds.folder(alias.location)).write(res);
|
|
32
35
|
}
|
|
33
|
-
}
|
|
36
|
+
};
|
|
34
37
|
|
|
35
|
-
variable = async(address, {chain, config, obj})=>{
|
|
38
|
+
variable = async (address, { chain, config, obj }) => {
|
|
36
39
|
let result;
|
|
37
|
-
let chn = await chain.chain(address)
|
|
38
|
-
let fold = await chn.folder()
|
|
40
|
+
let chn = await chain.chain(address);
|
|
41
|
+
let fold = await chn.folder();
|
|
39
42
|
|
|
40
|
-
if(config && config._id && config.type ===
|
|
43
|
+
if (config && config._id && config.type === "reference") {
|
|
41
44
|
result = {
|
|
42
|
-
type:
|
|
43
|
-
value: address,
|
|
44
|
-
_id: config._id
|
|
45
|
-
}
|
|
46
|
-
if (config.object) result.object = config.object
|
|
47
|
-
}else
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
type: "address",
|
|
46
|
+
value: address,
|
|
47
|
+
_id: config._id,
|
|
48
|
+
};
|
|
49
|
+
if (config.object) result.object = config.object;
|
|
50
|
+
} else
|
|
51
|
+
result = await fold.readone(
|
|
52
|
+
config && config._id ? { _id: config._id } : null
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (obj) result = await this.cloth(result);
|
|
56
|
+
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
53
59
|
|
|
54
60
|
gen_uid = (loc) => {
|
|
55
|
-
return `_${Math.random().toString().replace(".", "")}${
|
|
61
|
+
return `_${Math.random().toString().replace(".", "")}${
|
|
62
|
+
loc ? "" : "_"
|
|
63
|
+
}${Date.now()}`;
|
|
56
64
|
};
|
|
57
65
|
|
|
58
|
-
spread_properties = async(object, cls, {lists, benches})=>{
|
|
59
|
-
for (let m in cls.methods){
|
|
60
|
-
object.methods[m] = cls.methods[m]
|
|
66
|
+
spread_properties = async (object, cls, { lists, benches }) => {
|
|
67
|
+
for (let m in cls.methods) {
|
|
68
|
+
object.methods[m] = cls.methods[m];
|
|
61
69
|
}
|
|
62
|
-
for(let p in cls.properties){
|
|
63
|
-
let prop = cls.properties[p]
|
|
64
|
-
let res = await this.nodelist(prop)
|
|
65
|
-
lists.push(...res)
|
|
70
|
+
for (let p in cls.properties) {
|
|
71
|
+
let prop = cls.properties[p];
|
|
72
|
+
let res = await this.nodelist(prop);
|
|
73
|
+
lists.push(...res);
|
|
66
74
|
benches[p] = lists.length - 1;
|
|
67
75
|
}
|
|
68
|
-
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
base_classes = async (
|
|
79
|
+
object,
|
|
80
|
+
config,
|
|
81
|
+
{ inherited, lists, benches, chain }
|
|
82
|
+
) => {
|
|
83
|
+
for (let b = 0; b < config.base_classes.length; b++) {
|
|
84
|
+
let blc = config.base_classes[b];
|
|
85
|
+
if (inherited.includes(blc.location)) continue;
|
|
69
86
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let blc = config.base_classes[b]
|
|
74
|
-
if (inherited.includes(blc.location)) continue
|
|
87
|
+
let cls = await this.cloth(await this.variable(blc.location, { chain }), {
|
|
88
|
+
just_content: true,
|
|
89
|
+
});
|
|
75
90
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await this.spread_properties(object, cls, {lists, benches})
|
|
91
|
+
await this.spread_properties(object, cls, { lists, benches });
|
|
79
92
|
|
|
80
93
|
if (cls.base_classes.length)
|
|
81
|
-
await this.base_classes(object, cls, {inherited, chain})
|
|
94
|
+
await this.base_classes(object, cls, { inherited, chain });
|
|
82
95
|
}
|
|
83
|
-
}
|
|
96
|
+
};
|
|
84
97
|
|
|
85
|
-
retrieve = async(object, o)=>{
|
|
98
|
+
retrieve = async (object, o) => {
|
|
86
99
|
let obj, addr;
|
|
87
|
-
if (object.type ===
|
|
100
|
+
if (object.type === "instance") {
|
|
88
101
|
let cls = await this.cloth({
|
|
89
|
-
type:
|
|
102
|
+
type: "function",
|
|
90
103
|
address: object.cls,
|
|
91
104
|
// _id: object.cls_id
|
|
92
|
-
})
|
|
93
|
-
addr = await cls.get_instance(object, true)
|
|
94
|
-
if (o){
|
|
95
|
-
obj = await this.cloth(addr)
|
|
105
|
+
});
|
|
106
|
+
addr = await cls.get_instance(object, true);
|
|
107
|
+
if (o) {
|
|
108
|
+
obj = await this.cloth(addr);
|
|
96
109
|
}
|
|
97
|
-
} else if ([
|
|
110
|
+
} else if (["twain", "array"].includes(object.type)) {
|
|
98
111
|
obj = await this.cloth_content(object);
|
|
99
112
|
|
|
100
|
-
await obj.retrieve(object.entries || object.items)
|
|
113
|
+
await obj.retrieve(object.entries || object.items);
|
|
101
114
|
|
|
102
|
-
addr = await obj.to_address()
|
|
103
|
-
} else if (object.type ===
|
|
104
|
-
console.log(object,
|
|
115
|
+
addr = await obj.to_address();
|
|
116
|
+
} else if (object.type === "function") {
|
|
117
|
+
console.log(object, "in here");
|
|
105
118
|
// process.exit()
|
|
106
|
-
obj = object
|
|
107
|
-
addr = await object.to_address()
|
|
119
|
+
obj = object;
|
|
120
|
+
addr = await object.to_address();
|
|
108
121
|
} else {
|
|
109
|
-
obj =
|
|
122
|
+
obj = await this.cloth_content(object);
|
|
110
123
|
|
|
111
|
-
addr = await obj.to_address()
|
|
124
|
+
addr = await obj.to_address();
|
|
112
125
|
}
|
|
113
126
|
|
|
114
127
|
return o ? obj : addr;
|
|
115
|
-
}
|
|
128
|
+
};
|
|
116
129
|
|
|
117
130
|
parse_dynamic = async (literal, options = {}) => {
|
|
118
131
|
let { chain, config } = options;
|
|
@@ -129,36 +142,36 @@ class Vm_utils {
|
|
|
129
142
|
return address;
|
|
130
143
|
};
|
|
131
144
|
|
|
132
|
-
folder = async(fold)=>{
|
|
145
|
+
folder = async (fold) => {
|
|
133
146
|
return {
|
|
134
|
-
type:
|
|
147
|
+
type: "folder",
|
|
135
148
|
repo: fold.config.repo,
|
|
136
|
-
value: fold.address,
|
|
137
|
-
_id: await this.hash(fold.address)
|
|
138
|
-
}
|
|
139
|
-
}
|
|
149
|
+
value: fold.address,
|
|
150
|
+
_id: await this.hash(fold.address),
|
|
151
|
+
};
|
|
152
|
+
};
|
|
140
153
|
|
|
141
|
-
base_val = async type=>{
|
|
154
|
+
base_val = async (type) => {
|
|
142
155
|
let result;
|
|
143
|
-
|
|
144
|
-
switch(type){
|
|
145
|
-
case
|
|
146
|
-
result =
|
|
156
|
+
|
|
157
|
+
switch (type) {
|
|
158
|
+
case "string":
|
|
159
|
+
result = "";
|
|
147
160
|
break;
|
|
148
|
-
case
|
|
149
|
-
result =
|
|
161
|
+
case "number":
|
|
162
|
+
result = "0";
|
|
150
163
|
break;
|
|
151
|
-
case
|
|
152
|
-
result = []
|
|
164
|
+
case "array":
|
|
165
|
+
result = [];
|
|
153
166
|
break;
|
|
154
|
-
case
|
|
155
|
-
result = {}
|
|
167
|
+
case "twain":
|
|
168
|
+
result = {};
|
|
156
169
|
break;
|
|
157
|
-
case
|
|
158
|
-
result = false
|
|
170
|
+
case "boolean":
|
|
171
|
+
result = false;
|
|
159
172
|
}
|
|
160
|
-
return await this.typecast(result, type, true)
|
|
161
|
-
}
|
|
173
|
+
return await this.typecast(result, type, true);
|
|
174
|
+
};
|
|
162
175
|
|
|
163
176
|
resolve_addr = (addr) => {
|
|
164
177
|
if (!addr) return addr;
|
|
@@ -170,34 +183,34 @@ class Vm_utils {
|
|
|
170
183
|
return addr;
|
|
171
184
|
};
|
|
172
185
|
|
|
173
|
-
typecast = async(obj, type)=>{
|
|
174
|
-
return obj
|
|
175
|
-
}
|
|
186
|
+
typecast = async (obj, type) => {
|
|
187
|
+
return obj;
|
|
188
|
+
};
|
|
176
189
|
|
|
177
|
-
_split_datapath = (datapath)=>{
|
|
178
|
-
datapath = datapath.split(
|
|
190
|
+
_split_datapath = (datapath) => {
|
|
191
|
+
datapath = datapath.split("/");
|
|
179
192
|
|
|
180
|
-
return [datapath.slice(0
|
|
181
|
-
}
|
|
193
|
+
return [datapath.slice(0, -1).join("/"), datapath.slice(-1)[0]];
|
|
194
|
+
};
|
|
182
195
|
|
|
183
|
-
voided = async ()=>{
|
|
184
|
-
return await this.statics({type:
|
|
185
|
-
}
|
|
196
|
+
voided = async () => {
|
|
197
|
+
return await this.statics({ type: "void" });
|
|
198
|
+
};
|
|
186
199
|
|
|
187
|
-
statics = async(config)=>{
|
|
188
|
-
let addr = `${this.account.physical_address}/__$STATICS
|
|
189
|
-
let folder = await this.account.manager.ds.folder(addr)
|
|
200
|
+
statics = async (config) => {
|
|
201
|
+
let addr = `${this.account.physical_address}/__$STATICS/`;
|
|
202
|
+
let folder = await this.account.manager.ds.folder(addr);
|
|
190
203
|
|
|
191
|
-
let value = config.type===
|
|
192
|
-
let _id = await this.hash(value)
|
|
193
|
-
await folder.write({type: config.type, value, _id })
|
|
204
|
+
let value = config.type === "boolean" ? config.value : "void";
|
|
205
|
+
let _id = await this.hash(value);
|
|
206
|
+
await folder.write({ type: config.type, value, _id });
|
|
194
207
|
|
|
195
208
|
return {
|
|
196
209
|
value: addr,
|
|
197
|
-
_id,
|
|
198
|
-
type:
|
|
199
|
-
}
|
|
200
|
-
}
|
|
210
|
+
_id,
|
|
211
|
+
type: "address",
|
|
212
|
+
};
|
|
213
|
+
};
|
|
201
214
|
|
|
202
215
|
err_objects = [
|
|
203
216
|
"ZeroDivisionError",
|
|
@@ -207,59 +220,61 @@ class Vm_utils {
|
|
|
207
220
|
"RuntimeError",
|
|
208
221
|
"CompileError",
|
|
209
222
|
"AssertionError",
|
|
210
|
-
]
|
|
223
|
+
];
|
|
211
224
|
|
|
212
|
-
cloth = async(address, options={})=>{
|
|
213
|
-
let {just_content} = options
|
|
225
|
+
cloth = async (address, options = {}) => {
|
|
226
|
+
let { just_content } = options;
|
|
214
227
|
let content;
|
|
215
228
|
|
|
216
|
-
if (address.config){
|
|
229
|
+
if (address.config) {
|
|
217
230
|
address = {
|
|
218
|
-
type:
|
|
219
|
-
_id: address._id,
|
|
231
|
+
type: "function",
|
|
232
|
+
_id: address._id,
|
|
220
233
|
address: address.value,
|
|
221
234
|
value: address.value,
|
|
222
|
-
}
|
|
235
|
+
};
|
|
223
236
|
}
|
|
224
|
-
|
|
225
|
-
if (address.type ===
|
|
226
|
-
if (address.value.includes(
|
|
227
|
-
let folder = await this.account.manager.ds.folder(address.value)
|
|
228
|
-
if (address.object){
|
|
229
|
-
folder = await folder.folder(
|
|
237
|
+
|
|
238
|
+
if (address.type === "address") {
|
|
239
|
+
if (address.value.includes("/")) {
|
|
240
|
+
let folder = await this.account.manager.ds.folder(address.value);
|
|
241
|
+
if (address.object) {
|
|
242
|
+
folder = await folder.folder(".configs");
|
|
230
243
|
}
|
|
231
|
-
content = await folder.readone({_id: address._id})
|
|
232
|
-
}else if(address.object) {
|
|
233
|
-
content = {...address, type:
|
|
244
|
+
content = await folder.readone({ _id: address._id });
|
|
245
|
+
} else if (address.object) {
|
|
246
|
+
content = { ...address, type: "function" };
|
|
234
247
|
}
|
|
235
|
-
}else if([
|
|
236
|
-
if (address._id && address._id === address.value){
|
|
237
|
-
content = address
|
|
238
|
-
}else {
|
|
239
|
-
let folder = await this.account.manager.ds.folder(`${address.address}`)
|
|
240
|
-
folder = await folder.folder(
|
|
241
|
-
|
|
242
|
-
content = await folder.readone(
|
|
248
|
+
} else if (["function", "class"].includes(address.type)) {
|
|
249
|
+
if (address._id && address._id === address.value) {
|
|
250
|
+
content = address;
|
|
251
|
+
} else {
|
|
252
|
+
let folder = await this.account.manager.ds.folder(`${address.address}`);
|
|
253
|
+
folder = await folder.folder(".configs");
|
|
254
|
+
|
|
255
|
+
content = await folder.readone(
|
|
256
|
+
address._id ? { _id: address._id } : null
|
|
257
|
+
);
|
|
243
258
|
}
|
|
244
259
|
}
|
|
245
260
|
|
|
246
|
-
if (just_content)
|
|
247
|
-
return content;
|
|
261
|
+
if (just_content) return content;
|
|
248
262
|
|
|
249
|
-
if (content){
|
|
250
|
-
content = await this.cloth_content(content)
|
|
251
|
-
content.address = address.value
|
|
252
|
-
if (address.is_literal && content.type ===
|
|
263
|
+
if (content) {
|
|
264
|
+
content = await this.cloth_content(content);
|
|
265
|
+
content.address = address.value;
|
|
266
|
+
if (address.is_literal && content.type === "twain")
|
|
267
|
+
content.is_literal = true;
|
|
253
268
|
}
|
|
254
269
|
|
|
255
|
-
return content
|
|
256
|
-
}
|
|
270
|
+
return content;
|
|
271
|
+
};
|
|
257
272
|
|
|
258
273
|
cloth_content = async (content, options) => {
|
|
259
274
|
let obj;
|
|
260
275
|
|
|
261
276
|
if (!content) return content;
|
|
262
|
-
|
|
277
|
+
|
|
263
278
|
switch (content.type) {
|
|
264
279
|
case "number":
|
|
265
280
|
obj = new Num(content, this.account);
|
|
@@ -285,31 +300,31 @@ class Vm_utils {
|
|
|
285
300
|
case "function":
|
|
286
301
|
obj = new Func(content, this.account);
|
|
287
302
|
break;
|
|
288
|
-
case
|
|
289
|
-
obj = new Fold(content, this.account)
|
|
303
|
+
case "folder":
|
|
304
|
+
obj = new Fold(content, this.account);
|
|
290
305
|
break;
|
|
291
|
-
case
|
|
292
|
-
obj = new Res(content, this.account)
|
|
306
|
+
case "folder_response":
|
|
307
|
+
obj = new Res(content, this.account);
|
|
293
308
|
break;
|
|
294
309
|
case "class":
|
|
295
310
|
obj = new Cls(content, this.account);
|
|
296
311
|
break;
|
|
297
|
-
case
|
|
298
|
-
obj = new Err(content, this.account)
|
|
312
|
+
case "error":
|
|
313
|
+
obj = new Err(content, this.account);
|
|
299
314
|
break;
|
|
300
315
|
default:
|
|
301
|
-
obj = await this.cloth(content)
|
|
316
|
+
obj = await this.cloth(content);
|
|
302
317
|
break;
|
|
303
318
|
}
|
|
304
319
|
|
|
305
320
|
return await obj.sync(options);
|
|
306
321
|
};
|
|
307
322
|
|
|
308
|
-
hash = async(value, alg)=>{
|
|
309
|
-
if (typeof value !==
|
|
310
|
-
|
|
311
|
-
return hash(value, alg)
|
|
312
|
-
}
|
|
323
|
+
hash = async (value, alg) => {
|
|
324
|
+
if (typeof value !== "string") value = JSON.stringify(value);
|
|
325
|
+
|
|
326
|
+
return hash(value, alg);
|
|
327
|
+
};
|
|
313
328
|
}
|
|
314
329
|
|
|
315
330
|
export default Vm_utils;
|
package/repos/fs.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { copy_object } from "generalised-datastore/utils/functions.js";
|
|
3
|
-
import Repository from "godprotocol/Objects/Repository.js";
|
|
4
|
-
import { post_request } from "godprotocol/utils/services.js";
|
|
5
|
-
|
|
6
|
-
class Fs extends Repository {
|
|
7
|
-
constructor(options = {}) {
|
|
8
|
-
super();
|
|
9
|
-
|
|
10
|
-
this._fs = fs;
|
|
11
|
-
this.__dirname = options.__dirname;
|
|
12
|
-
this.remote = options.remote;
|
|
13
|
-
this.name = options.name;
|
|
14
|
-
|
|
15
|
-
this.type = "fs";
|
|
16
|
-
this.cache = new Object();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
parse_path = async (path) => {
|
|
20
|
-
path = path.split("/");
|
|
21
|
-
let addr = path.slice(0, -1).join("/");
|
|
22
|
-
if (!this._fs.existsSync(addr)) {
|
|
23
|
-
this._fs.mkdirSync(addr, { recursive: true });
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
call = async (payload) => {
|
|
28
|
-
let result;
|
|
29
|
-
switch (payload.op) {
|
|
30
|
-
case "write":
|
|
31
|
-
result = await this.write(payload.path, payload.data);
|
|
32
|
-
break;
|
|
33
|
-
case "read":
|
|
34
|
-
result = await this.read(payload.path);
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
fetch = async (payload) => {
|
|
41
|
-
let res;
|
|
42
|
-
if (this.remote) {
|
|
43
|
-
res = await post_request({
|
|
44
|
-
options: {
|
|
45
|
-
...this.remote,
|
|
46
|
-
path: "/oracle",
|
|
47
|
-
},
|
|
48
|
-
data: JSON.stringify({
|
|
49
|
-
method: "fs",
|
|
50
|
-
arg: { payload, name: this.name },
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
} else {
|
|
54
|
-
res = await this.call(payload);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return res;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
write_file = async (path, data) => {
|
|
61
|
-
path = this.path(path);
|
|
62
|
-
console.log(path, data);
|
|
63
|
-
|
|
64
|
-
await this.fetch({ path, data, op: "write" });
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
write = async (path, data) => {
|
|
68
|
-
await this.parse_path(path);
|
|
69
|
-
this._fs.writeFileSync(path, data);
|
|
70
|
-
|
|
71
|
-
this.cache[path] = data;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
read = async (path) => {
|
|
75
|
-
let data;
|
|
76
|
-
try {
|
|
77
|
-
data = this.cache[path];
|
|
78
|
-
if (!data) {
|
|
79
|
-
await this.parse_path(path);
|
|
80
|
-
data = this._fs.readFileSync(path, { encoding: "utf-8" });
|
|
81
|
-
} else {
|
|
82
|
-
data = copy_object(data);
|
|
83
|
-
}
|
|
84
|
-
} catch (e) {
|
|
85
|
-
console.log(e.message);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return data;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
read_file = async (path) => {
|
|
92
|
-
path = this.path(path);
|
|
93
|
-
|
|
94
|
-
let data = await this.fetch({ path, op: "read" });
|
|
95
|
-
|
|
96
|
-
return data;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
path = (pth) => {
|
|
100
|
-
return `${this.__dirname}/${pth}`;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
mkdir = async (path) => {
|
|
104
|
-
let done;
|
|
105
|
-
try {
|
|
106
|
-
this._fs.mkdirSync(this.path(path), { recursive: true });
|
|
107
|
-
done = true;
|
|
108
|
-
} catch (e) {
|
|
109
|
-
done = false;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return done;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
exists = async (path) => {
|
|
116
|
-
path = this.path(path);
|
|
117
|
-
|
|
118
|
-
return !!this.cache[path] || this._fs.existsSync(path);
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export default Fs;
|