godprotocol 1.2.20 → 1.2.22
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/Manager.js +362 -296
- package/Objects/Oracle.js +49 -27
- package/package.json +1 -4
- package/repos/fs.js +83 -75
package/Objects/Manager.js
CHANGED
|
@@ -5,421 +5,487 @@ import { hash } from "godprotocol/utils/hash.js";
|
|
|
5
5
|
import { copy_object } from "generalised-datastore/utils/functions.js";
|
|
6
6
|
|
|
7
7
|
class Manager {
|
|
8
|
-
constructor(name, options){
|
|
9
|
-
this.name = name
|
|
10
|
-
this.options = options
|
|
8
|
+
constructor(name, options) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.options = options;
|
|
11
11
|
this.trinity = options.trinity;
|
|
12
12
|
|
|
13
|
-
this.accounts = new Object()
|
|
13
|
+
this.accounts = new Object();
|
|
14
14
|
|
|
15
|
-
this.clock_speed = 0
|
|
16
|
-
this.accounts_pairs = new Object()
|
|
15
|
+
this.clock_speed = 0;
|
|
16
|
+
this.accounts_pairs = new Object();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
swap_result = async (id, thread)=>{
|
|
20
|
-
if (typeof id ===
|
|
21
|
-
id = thread.results[id]
|
|
19
|
+
swap_result = async (id, thread) => {
|
|
20
|
+
if (typeof id === "number") {
|
|
21
|
+
id = thread.results[id];
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
return id
|
|
25
|
-
}
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
return id;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
set_bullet = async (bullet, thread) => {
|
|
28
|
+
switch (bullet.type) {
|
|
29
|
+
case "assignment":
|
|
30
|
+
bullet.value = await this.swap_result(bullet.value, thread);
|
|
31
31
|
break;
|
|
32
|
-
case
|
|
33
|
-
bullet.identifier = await this.swap_result(bullet.identifier, thread
|
|
34
|
-
|
|
35
|
-
for (let a = 0; a< bullet.arguments.length; a++){
|
|
36
|
-
bullet.arguments[a] = await this.swap_result(
|
|
32
|
+
case "call":
|
|
33
|
+
bullet.identifier = await this.swap_result(bullet.identifier, thread);
|
|
34
|
+
|
|
35
|
+
for (let a = 0; a < bullet.arguments.length; a++) {
|
|
36
|
+
bullet.arguments[a] = await this.swap_result(
|
|
37
|
+
bullet.arguments[a],
|
|
38
|
+
thread
|
|
39
|
+
);
|
|
37
40
|
}
|
|
38
41
|
break;
|
|
39
|
-
case
|
|
40
|
-
bullet.output = await this.swap_result(bullet.output, thread)
|
|
42
|
+
case "return":
|
|
43
|
+
bullet.output = await this.swap_result(bullet.output, thread);
|
|
44
|
+
break;
|
|
45
|
+
case "module":
|
|
46
|
+
for (let b = 0; b < bullet.body.length; b++) {
|
|
47
|
+
bullet.body[b] = await this.swap_result(bullet.body[b], thread);
|
|
48
|
+
}
|
|
41
49
|
break;
|
|
42
|
-
case
|
|
43
|
-
for(let
|
|
44
|
-
bullet.
|
|
50
|
+
case "nest":
|
|
51
|
+
for (let n = 0; n < bullet.nests.length; n++) {
|
|
52
|
+
bullet.nests[n] = await this.swap_result(bullet.nests[n], thread);
|
|
45
53
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
for (let n=0; n< bullet.nests.length; n++){
|
|
49
|
-
bullet.nests[n] = await this.swap_result(bullet.nests[n], thread, )
|
|
54
|
+
if (bullet.assignment) {
|
|
55
|
+
bullet.assignment = await this.swap_result(bullet.assignment, thread);
|
|
50
56
|
}
|
|
51
|
-
if (bullet.assignment){
|
|
52
|
-
bullet.assignment = await this.swap_result(bullet.assignment, thread, )
|
|
53
|
-
}
|
|
54
57
|
break;
|
|
55
|
-
case
|
|
56
|
-
for (let key in bullet.value){
|
|
57
|
-
let [prop, value] = bullet.value[key]
|
|
58
|
-
bullet.value[key][0] = await this.swap_result(prop, thread
|
|
59
|
-
bullet.value[key][1] = await this.swap_result(value, thread
|
|
58
|
+
case "twain":
|
|
59
|
+
for (let key in bullet.value) {
|
|
60
|
+
let [prop, value] = bullet.value[key];
|
|
61
|
+
bullet.value[key][0] = await this.swap_result(prop, thread);
|
|
62
|
+
bullet.value[key][1] = await this.swap_result(value, thread);
|
|
60
63
|
}
|
|
61
|
-
break
|
|
62
|
-
case
|
|
63
|
-
for (let i=0; i< bullet.value.length; i++){
|
|
64
|
-
let val = bullet.value[i]
|
|
65
|
-
bullet.value[i] = await this.swap_result(val, thread
|
|
64
|
+
break;
|
|
65
|
+
case "array":
|
|
66
|
+
for (let i = 0; i < bullet.value.length; i++) {
|
|
67
|
+
let val = bullet.value[i];
|
|
68
|
+
bullet.value[i] = await this.swap_result(val, thread);
|
|
66
69
|
}
|
|
67
|
-
break
|
|
68
|
-
case 'variable':
|
|
69
70
|
break;
|
|
70
|
-
case
|
|
71
|
-
|
|
71
|
+
case "variable":
|
|
72
|
+
break;
|
|
73
|
+
case "try":
|
|
74
|
+
}
|
|
72
75
|
|
|
73
|
-
return bullet
|
|
74
|
-
}
|
|
76
|
+
return bullet;
|
|
77
|
+
};
|
|
75
78
|
|
|
76
|
-
_stack = new Array()
|
|
79
|
+
_stack = new Array();
|
|
77
80
|
|
|
78
|
-
break_count = 0
|
|
79
|
-
|
|
80
|
-
start_clock = async()=>{
|
|
81
|
-
this.clock = setInterval(async() => {
|
|
81
|
+
break_count = 0;
|
|
82
|
+
|
|
83
|
+
start_clock = async () => {
|
|
84
|
+
this.clock = setInterval(async () => {
|
|
82
85
|
this.clock_running = true;
|
|
83
|
-
for (let account in this.accounts_pairs){
|
|
84
|
-
let account_pair = this.accounts_pairs[account]
|
|
85
|
-
let {threads, threadlist, state, current_thread} = account_pair
|
|
86
|
-
|
|
87
|
-
if (state ===
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
let
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
continue
|
|
86
|
+
for (let account in this.accounts_pairs) {
|
|
87
|
+
let account_pair = this.accounts_pairs[account];
|
|
88
|
+
let { threads, threadlist, state, current_thread } = account_pair;
|
|
89
|
+
|
|
90
|
+
if (state === "running") continue;
|
|
91
|
+
|
|
92
|
+
let total_loop = 0;
|
|
93
|
+
while (threadlist.length && total_loop < threadlist.length) {
|
|
94
|
+
let thread_id = threadlist[account_pair.current_thread];
|
|
95
|
+
let thread = threads[thread_id];
|
|
96
|
+
if (!thread) {
|
|
97
|
+
account_pair.current_thread = 0;
|
|
98
|
+
continue;
|
|
97
99
|
}
|
|
98
|
-
let {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
let {
|
|
101
|
+
bullets,
|
|
102
|
+
pointer,
|
|
103
|
+
callback,
|
|
104
|
+
results,
|
|
105
|
+
chain,
|
|
106
|
+
spawn,
|
|
107
|
+
status,
|
|
108
|
+
_stack,
|
|
109
|
+
on_pointer,
|
|
110
|
+
} = thread;
|
|
111
|
+
|
|
112
|
+
if (status && status.start) {
|
|
113
|
+
if (Date.now() - status.start > status.duration) {
|
|
114
|
+
thread.status = "active";
|
|
103
115
|
}
|
|
104
|
-
}
|
|
105
|
-
if (status ===
|
|
106
|
-
account_pair.current_thread
|
|
107
|
-
account_pair.state =
|
|
116
|
+
}
|
|
117
|
+
if (status === "active") {
|
|
118
|
+
account_pair.current_thread++;
|
|
119
|
+
account_pair.state = "running";
|
|
108
120
|
} else {
|
|
109
|
-
total_loop
|
|
110
|
-
account_pair.current_thread
|
|
111
|
-
continue
|
|
121
|
+
total_loop++;
|
|
122
|
+
account_pair.current_thread++;
|
|
123
|
+
continue;
|
|
112
124
|
}
|
|
113
|
-
|
|
114
|
-
total_loop = 0
|
|
115
|
-
let current_bullet = bullets[pointer],
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
|
|
126
|
+
total_loop = 0;
|
|
127
|
+
let current_bullet = bullets[pointer],
|
|
128
|
+
res;
|
|
129
|
+
|
|
130
|
+
if (current_bullet) {
|
|
131
|
+
if (current_bullet.type === "loop") {
|
|
132
|
+
_stack.push(current_bullet);
|
|
133
|
+
} else if (current_bullet.type === "try") {
|
|
134
|
+
_stack.push(current_bullet);
|
|
135
|
+
} else if (current_bullet.type === "catch") {
|
|
136
|
+
let try_conf = _stack.pop();
|
|
137
|
+
thread.pointer += try_conf.catch_offset;
|
|
138
|
+
} else if (current_bullet.type === "endloop") {
|
|
139
|
+
let loop_conf = _stack.pop();
|
|
140
|
+
if (!loop_conf || loop_conf.type !== "loop") {
|
|
141
|
+
console.log(`ErrorLog: Corrupt stacking`);
|
|
142
|
+
thread.pointer = bullets.length;
|
|
143
|
+
} else thread.pointer = loop_conf.conditional_jmp;
|
|
131
144
|
} else {
|
|
132
|
-
let account_obj = this.accounts[account]
|
|
133
|
-
|
|
134
|
-
if (Object.keys(current_bullet).includes(
|
|
135
|
-
else
|
|
136
|
-
res = await account_obj.vm.execute(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
let account_obj = this.accounts[account];
|
|
146
|
+
|
|
147
|
+
if (Object.keys(current_bullet).includes("jmp")) {
|
|
148
|
+
} else
|
|
149
|
+
res = await account_obj.vm.execute(
|
|
150
|
+
this.set_bullet(copy_object(current_bullet), thread),
|
|
151
|
+
{ chain, manager: this, thread }
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
if (res && res.__interrupt__) {
|
|
155
|
+
if (res.type === "return") {
|
|
156
|
+
if (spawn) {
|
|
157
|
+
let thrd = threads[spawn.thread_id];
|
|
158
|
+
thrd.results[spawn.pointer] = res.output;
|
|
159
|
+
thread.pointer = bullets.length - 1;
|
|
160
|
+
} else res = res.output;
|
|
161
|
+
} else if (["break", "continue"].includes(res.__interrupt__)) {
|
|
146
162
|
let caught;
|
|
147
|
-
while(_stack.length){
|
|
148
|
-
let loop = _stack.slice(-1)[0]
|
|
149
|
-
|
|
150
|
-
if (loop && loop.type ===
|
|
151
|
-
if (res.__interrupt__ ===
|
|
152
|
-
thread.pointer = loop.conditional_jmp -1
|
|
153
|
-
}else if(res.__interrupt__ ===
|
|
154
|
-
thread.pointer = loop.update_jmp -1
|
|
163
|
+
while (_stack.length) {
|
|
164
|
+
let loop = _stack.slice(-1)[0];
|
|
165
|
+
|
|
166
|
+
if (loop && loop.type === "loop") {
|
|
167
|
+
if (res.__interrupt__ === "break") {
|
|
168
|
+
thread.pointer = loop.conditional_jmp - 1;
|
|
169
|
+
} else if (res.__interrupt__ === "continue") {
|
|
170
|
+
thread.pointer = loop.update_jmp - 1;
|
|
155
171
|
}
|
|
156
|
-
caught = true
|
|
157
|
-
break
|
|
172
|
+
caught = true;
|
|
173
|
+
break;
|
|
158
174
|
}
|
|
159
|
-
_stack.pop()
|
|
175
|
+
_stack.pop();
|
|
160
176
|
}
|
|
161
|
-
if (!caught){
|
|
162
|
-
console.log(
|
|
163
|
-
|
|
177
|
+
if (!caught) {
|
|
178
|
+
console.log(
|
|
179
|
+
`ErrorLog: Loop keywords can only be used inside a loop`
|
|
180
|
+
);
|
|
181
|
+
thread.pointer = bullets.length;
|
|
164
182
|
}
|
|
165
|
-
}else {
|
|
166
|
-
let i = _stack.length - 1,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
i
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
183
|
+
} else {
|
|
184
|
+
let i = _stack.length - 1,
|
|
185
|
+
caught;
|
|
186
|
+
while (_stack.length) {
|
|
187
|
+
let tstack = _stack[i];
|
|
188
|
+
i--;
|
|
189
|
+
let t_catch = bullets[tstack.catch_index];
|
|
190
|
+
|
|
191
|
+
if (
|
|
192
|
+
!t_catch.objects.length ||
|
|
193
|
+
t_catch.objects.includes(res.payload.type)
|
|
194
|
+
) {
|
|
195
|
+
thread.pointer = tstack.catch_index;
|
|
174
196
|
|
|
175
197
|
if (tstack.alias)
|
|
176
|
-
await account_obj.vm.error_instance(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
198
|
+
await account_obj.vm.error_instance(
|
|
199
|
+
{ location: tstack.location, payload: res.payload },
|
|
200
|
+
tstack.alias
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
_stack.pop();
|
|
204
|
+
caught = true;
|
|
205
|
+
break;
|
|
181
206
|
}
|
|
182
|
-
_stack.pop()
|
|
207
|
+
_stack.pop();
|
|
183
208
|
}
|
|
184
|
-
if (!caught){
|
|
185
|
-
console.log(`ErrorLog: ${res.payload.message}`)
|
|
186
|
-
if (spawn){
|
|
187
|
-
let thrd = threads[spawn.thread_id]
|
|
188
|
-
thrd.results[spawn.pointer] = res
|
|
209
|
+
if (!caught) {
|
|
210
|
+
console.log(`ErrorLog: ${res.payload.message}`);
|
|
211
|
+
if (spawn) {
|
|
212
|
+
let thrd = threads[spawn.thread_id];
|
|
213
|
+
thrd.results[spawn.pointer] = res;
|
|
189
214
|
}
|
|
190
|
-
thread.pointer = bullets.length
|
|
215
|
+
thread.pointer = bullets.length;
|
|
191
216
|
}
|
|
192
217
|
}
|
|
193
|
-
}else {
|
|
194
|
-
if (current_bullet.type ===
|
|
195
|
-
bullets.map(bull=>{
|
|
196
|
-
if (
|
|
197
|
-
bull.
|
|
218
|
+
} else {
|
|
219
|
+
if (current_bullet.type === "assignment") {
|
|
220
|
+
bullets.map((bull) => {
|
|
221
|
+
if (
|
|
222
|
+
bull.type === "variable" &&
|
|
223
|
+
bull.location === current_bullet.location
|
|
224
|
+
) {
|
|
225
|
+
bull._id = res._id;
|
|
198
226
|
}
|
|
199
|
-
})
|
|
227
|
+
});
|
|
200
228
|
}
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
229
|
+
if (
|
|
230
|
+
current_bullet.type === "nest" &&
|
|
231
|
+
current_bullet.assignment
|
|
232
|
+
) {
|
|
233
|
+
if (current_bullet.assignment_location) {
|
|
234
|
+
bullets.map((bull) => {
|
|
235
|
+
if (
|
|
236
|
+
bull.type === "variable" &&
|
|
237
|
+
bull.location === current_bullet.assignment_location
|
|
238
|
+
) {
|
|
239
|
+
bull._id = res._id;
|
|
240
|
+
let trd = thread;
|
|
241
|
+
while (trd.spawn) {
|
|
242
|
+
let tid = trd.spawn.thread_id;
|
|
243
|
+
trd = threads[tid];
|
|
244
|
+
trd.bullets.map((bl) => {
|
|
245
|
+
if (
|
|
246
|
+
bl.type === "variable" &&
|
|
247
|
+
bl.location === current_bullet.assignment_location
|
|
248
|
+
) {
|
|
249
|
+
bl._id = res._id;
|
|
213
250
|
}
|
|
214
|
-
})
|
|
251
|
+
});
|
|
215
252
|
}
|
|
216
253
|
}
|
|
217
|
-
})
|
|
254
|
+
});
|
|
218
255
|
}
|
|
219
256
|
}
|
|
220
|
-
if (current_bullet.conditional_jmp){
|
|
221
|
-
if (!res.literal){
|
|
222
|
-
console.log("Manager.js::SHOUT!")
|
|
257
|
+
if (current_bullet.conditional_jmp) {
|
|
258
|
+
if (!res.literal) {
|
|
259
|
+
console.log("Manager.js::SHOUT!");
|
|
223
260
|
}
|
|
224
|
-
let pass = await res.literal()
|
|
225
|
-
|
|
226
|
-
if (current_bullet.invert){
|
|
227
|
-
if(!pass){
|
|
228
|
-
thread.pointer = current_bullet.conditional_jmp - 1
|
|
261
|
+
let pass = await res.literal();
|
|
262
|
+
|
|
263
|
+
if (current_bullet.invert) {
|
|
264
|
+
if (!pass) {
|
|
265
|
+
thread.pointer = current_bullet.conditional_jmp - 1;
|
|
229
266
|
}
|
|
230
|
-
}else{
|
|
231
|
-
if (!pass){
|
|
232
|
-
thread.pointer = current_bullet.conditional_jmp - 1
|
|
267
|
+
} else {
|
|
268
|
+
if (!pass) {
|
|
269
|
+
thread.pointer = current_bullet.conditional_jmp - 1;
|
|
233
270
|
}
|
|
234
271
|
}
|
|
235
272
|
}
|
|
236
|
-
if (current_bullet.jmp){
|
|
237
|
-
thread.pointer = current_bullet.jmp - 1
|
|
273
|
+
if (current_bullet.jmp) {
|
|
274
|
+
thread.pointer = current_bullet.jmp - 1;
|
|
238
275
|
}
|
|
239
276
|
}
|
|
240
277
|
|
|
241
|
-
results[pointer] = res
|
|
278
|
+
results[pointer] = res;
|
|
242
279
|
|
|
243
|
-
on_pointer && await on_pointer(pointer, res)
|
|
280
|
+
on_pointer && (await on_pointer(pointer, res));
|
|
244
281
|
}
|
|
245
282
|
}
|
|
246
|
-
|
|
247
|
-
thread.pointer
|
|
248
|
-
if (thread.pointer >= bullets.length){
|
|
249
|
-
callback && await callback(res, thread)
|
|
250
|
-
delete threads[thread_id]
|
|
251
|
-
delete this.accounts[account].vm.envs[thread_id]
|
|
252
|
-
account_pair.current_thread
|
|
253
|
-
threadlist.splice(account_pair.current_thread, 1)
|
|
254
|
-
if (spawn){
|
|
255
|
-
let thrd = threads[spawn.thread_id]
|
|
256
|
-
if(thrd){
|
|
257
|
-
thrd.status =
|
|
283
|
+
|
|
284
|
+
thread.pointer++;
|
|
285
|
+
if (thread.pointer >= bullets.length) {
|
|
286
|
+
callback && (await callback(res, thread));
|
|
287
|
+
delete threads[thread_id];
|
|
288
|
+
delete this.accounts[account].vm.envs[thread_id];
|
|
289
|
+
account_pair.current_thread--;
|
|
290
|
+
threadlist.splice(account_pair.current_thread, 1);
|
|
291
|
+
if (spawn) {
|
|
292
|
+
let thrd = threads[spawn.thread_id];
|
|
293
|
+
if (thrd) {
|
|
294
|
+
thrd.status = "active";
|
|
258
295
|
}
|
|
259
296
|
}
|
|
260
297
|
}
|
|
261
|
-
if (account_pair.current_thread === threadlist.length){
|
|
262
|
-
account_pair.current_thread = 0
|
|
298
|
+
if (account_pair.current_thread === threadlist.length) {
|
|
299
|
+
account_pair.current_thread = 0;
|
|
263
300
|
}
|
|
264
|
-
|
|
265
|
-
account_pair.state =
|
|
266
|
-
break
|
|
301
|
+
|
|
302
|
+
account_pair.state = "active";
|
|
303
|
+
break;
|
|
267
304
|
}
|
|
268
|
-
if (!threadlist.length){
|
|
269
|
-
delete this.accounts_pairs[account]
|
|
270
|
-
if (!Object.keys(this.accounts_pairs).length){
|
|
271
|
-
this.clock_running = false
|
|
272
|
-
clearInterval(this.clock)
|
|
305
|
+
if (!threadlist.length) {
|
|
306
|
+
delete this.accounts_pairs[account];
|
|
307
|
+
if (!Object.keys(this.accounts_pairs).length) {
|
|
308
|
+
this.clock_running = false;
|
|
309
|
+
clearInterval(this.clock);
|
|
273
310
|
}
|
|
274
311
|
}
|
|
275
312
|
}
|
|
276
313
|
}, this.clock_speed);
|
|
277
|
-
}
|
|
314
|
+
};
|
|
278
315
|
|
|
279
|
-
load = async(thread, account, options={})=>{
|
|
280
|
-
let {callback, on_pointer, spawn, addr, pointer} = options
|
|
281
|
-
let tracker = this.accounts_pairs[account.name]
|
|
316
|
+
load = async (thread, account, options = {}) => {
|
|
317
|
+
let { callback, on_pointer, spawn, addr, pointer } = options;
|
|
318
|
+
let tracker = this.accounts_pairs[account.name];
|
|
282
319
|
|
|
283
|
-
if (!tracker){
|
|
320
|
+
if (!tracker) {
|
|
284
321
|
tracker = {
|
|
285
322
|
threadlist: [],
|
|
286
323
|
threads: {},
|
|
287
324
|
current_thread: 0,
|
|
288
|
-
}
|
|
289
|
-
this.accounts_pairs[account.name] = tracker
|
|
325
|
+
};
|
|
326
|
+
this.accounts_pairs[account.name] = tracker;
|
|
290
327
|
}
|
|
291
|
-
|
|
292
|
-
let thread_id = Math.random().toString()
|
|
293
|
-
tracker.threadlist.push(thread_id)
|
|
328
|
+
|
|
329
|
+
let thread_id = Math.random().toString();
|
|
330
|
+
tracker.threadlist.push(thread_id);
|
|
294
331
|
tracker.threads[thread_id] = {
|
|
295
|
-
bullets: thread,
|
|
296
|
-
_id: thread_id,
|
|
332
|
+
bullets: thread,
|
|
333
|
+
_id: thread_id,
|
|
297
334
|
on_pointer,
|
|
298
|
-
pointer: 0,
|
|
335
|
+
pointer: 0,
|
|
299
336
|
results: {},
|
|
300
|
-
_stack: new Array(),
|
|
301
|
-
status:
|
|
337
|
+
_stack: new Array(),
|
|
338
|
+
status: "active",
|
|
302
339
|
addr,
|
|
303
|
-
chain: account.chain,
|
|
304
|
-
spawn: spawn? { thread_id: spawn, pointer } : null,
|
|
305
|
-
callback
|
|
340
|
+
chain: account.chain,
|
|
341
|
+
spawn: spawn ? { thread_id: spawn, pointer } : null,
|
|
342
|
+
callback,
|
|
306
343
|
};
|
|
307
|
-
if (spawn){
|
|
308
|
-
let spawn_thread = tracker.threads[spawn]
|
|
309
|
-
|
|
310
|
-
spawn_thread.status = thread_id
|
|
344
|
+
if (spawn) {
|
|
345
|
+
let spawn_thread = tracker.threads[spawn];
|
|
346
|
+
|
|
347
|
+
spawn_thread.status = thread_id;
|
|
311
348
|
}
|
|
312
349
|
|
|
313
|
-
if (!this.clock_running){
|
|
314
|
-
await this.start_clock()
|
|
350
|
+
if (!this.clock_running) {
|
|
351
|
+
await this.start_clock();
|
|
315
352
|
}
|
|
316
353
|
|
|
317
|
-
return thread_id
|
|
318
|
-
}
|
|
354
|
+
return thread_id;
|
|
355
|
+
};
|
|
319
356
|
|
|
320
|
-
sync = async()=>{
|
|
321
|
-
this.path = `${this.trinity.game}/${this.name}
|
|
322
|
-
this.hash = hash
|
|
357
|
+
sync = async () => {
|
|
358
|
+
this.path = `${this.trinity.game}/${this.name}`;
|
|
359
|
+
this.hash = hash;
|
|
323
360
|
|
|
324
|
-
this.ds = new GDS(this)
|
|
325
|
-
await this.ds.sync()
|
|
361
|
+
this.ds = new GDS(this);
|
|
362
|
+
await this.ds.sync();
|
|
326
363
|
let create_serv;
|
|
327
|
-
if (this.options.server){
|
|
328
|
-
this.server = this.options.server
|
|
364
|
+
if (this.options.server) {
|
|
365
|
+
this.server = this.options.server;
|
|
329
366
|
if (this.options.server.port)
|
|
330
|
-
this.options.server_domain = `${this.options.server.hostname}:${this.options.server.port}
|
|
331
|
-
else this.options.server_domain = this.options.server.hostname
|
|
332
|
-
let handle = create_server({
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
367
|
+
this.options.server_domain = `${this.options.server.hostname}:${this.options.server.port}`;
|
|
368
|
+
else this.options.server_domain = this.options.server.hostname;
|
|
369
|
+
let handle = create_server({
|
|
370
|
+
manager: this,
|
|
371
|
+
...this.options.server,
|
|
372
|
+
app: this.options.app,
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
this.handler = (req, res, cb) => {
|
|
376
|
+
handle(req, res);
|
|
377
|
+
|
|
378
|
+
if (this.options.oracle && !this.served) {
|
|
379
|
+
this.served = true;
|
|
340
380
|
this.oracle = this.options.oracle;
|
|
341
|
-
this.oracle.
|
|
342
|
-
.
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
381
|
+
this.oracle.sync(this).then(async () => {
|
|
382
|
+
if (this.options.init_account) {
|
|
383
|
+
await this.add_account(this.options.init_account.name, {
|
|
384
|
+
password: this.options.init_account.password,
|
|
385
|
+
init: true,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
cb && cb();
|
|
389
|
+
}
|
|
390
|
+
});
|
|
349
391
|
}
|
|
350
|
-
}
|
|
392
|
+
};
|
|
351
393
|
}
|
|
352
394
|
|
|
353
395
|
return create_serv;
|
|
354
|
-
}
|
|
396
|
+
};
|
|
355
397
|
|
|
356
|
-
get_init = async()=>{
|
|
398
|
+
get_init = async () => {
|
|
357
399
|
let acc = this.init_account;
|
|
358
400
|
|
|
359
401
|
if (!acc && this.options.init_account) {
|
|
360
|
-
acc = await this.add_account(this.options.init_account.name, {
|
|
402
|
+
acc = await this.add_account(this.options.init_account.name, {
|
|
403
|
+
password: this.options.init_account.password,
|
|
404
|
+
init: true,
|
|
405
|
+
});
|
|
361
406
|
}
|
|
362
407
|
|
|
363
408
|
return acc;
|
|
364
|
-
}
|
|
409
|
+
};
|
|
365
410
|
|
|
366
|
-
get_from_repo = async(address, options={}) =>{
|
|
367
|
-
let acc = this.get_acc(options)
|
|
411
|
+
get_from_repo = async (address, options = {}) => {
|
|
412
|
+
let acc = this.get_acc(options);
|
|
368
413
|
|
|
369
|
-
address = `.storage/${acc}/${address}/__literal__
|
|
370
|
-
let content = await this.oracle.get_from_repos(address, {
|
|
414
|
+
address = `.storage/${acc}/${address}/__literal__`;
|
|
415
|
+
let content = await this.oracle.get_from_repos(address, {
|
|
416
|
+
count: 1,
|
|
417
|
+
args: options,
|
|
418
|
+
});
|
|
371
419
|
|
|
372
|
-
return content && JSON.parse(content)
|
|
373
|
-
}
|
|
420
|
+
return content && JSON.parse(content);
|
|
421
|
+
};
|
|
374
422
|
|
|
375
|
-
get_acc = options=>{
|
|
376
|
-
let acc = options.account
|
|
377
|
-
if (!acc){
|
|
378
|
-
acc = this.options.init_account
|
|
379
|
-
if (!acc) return
|
|
380
|
-
acc = `Accounts/${acc.name}
|
|
423
|
+
get_acc = (options) => {
|
|
424
|
+
let acc = options.account;
|
|
425
|
+
if (!acc) {
|
|
426
|
+
acc = this.options.init_account;
|
|
427
|
+
if (!acc) return;
|
|
428
|
+
acc = `Accounts/${acc.name}`;
|
|
381
429
|
}
|
|
382
430
|
|
|
383
431
|
return acc;
|
|
384
|
-
}
|
|
432
|
+
};
|
|
385
433
|
|
|
386
|
-
set_to_repo =
|
|
387
|
-
let acc = this.get_acc(options)
|
|
434
|
+
set_to_repo = async (address, content, options = {}) => {
|
|
435
|
+
let acc = this.get_acc(options);
|
|
388
436
|
|
|
389
|
-
address = `.storage/${acc}/${address}/__literal__
|
|
390
|
-
let response = await this.oracle.set_to_repos(
|
|
437
|
+
address = `.storage/${acc}/${address}/__literal__`;
|
|
438
|
+
let response = await this.oracle.set_to_repos(
|
|
439
|
+
address,
|
|
440
|
+
JSON.stringify(content),
|
|
441
|
+
{ count: 1, args: options }
|
|
442
|
+
);
|
|
391
443
|
|
|
392
|
-
return response
|
|
393
|
-
}
|
|
444
|
+
return response;
|
|
445
|
+
};
|
|
394
446
|
|
|
395
|
-
get_account = async(name) => {
|
|
396
|
-
let acc = this.accounts[name]
|
|
397
|
-
if (!acc){
|
|
398
|
-
let servers = await this.oracle.get_servers(`Accounts/${name}`)
|
|
399
|
-
if(servers.length){
|
|
400
|
-
acc = await this.add_account(name, {servers})
|
|
447
|
+
get_account = async (name) => {
|
|
448
|
+
let acc = this.accounts[name];
|
|
449
|
+
if (!acc) {
|
|
450
|
+
let servers = await this.oracle.get_servers(`Accounts/${name}`);
|
|
451
|
+
if (servers.length) {
|
|
452
|
+
acc = await this.add_account(name, { servers });
|
|
401
453
|
}
|
|
402
454
|
}
|
|
403
455
|
|
|
404
456
|
return acc;
|
|
405
|
-
}
|
|
457
|
+
};
|
|
406
458
|
|
|
407
|
-
add_account = async(name, options={}) => {
|
|
408
|
-
let acc = this.accounts[name]
|
|
459
|
+
add_account = async (name, options = {}) => {
|
|
460
|
+
let acc = this.accounts[name];
|
|
409
461
|
if (!acc) {
|
|
410
|
-
acc = new Account(name, {...options, manager: this})
|
|
411
|
-
let res = await acc.sync()
|
|
412
|
-
if (res)
|
|
413
|
-
|
|
414
|
-
else return
|
|
462
|
+
acc = new Account(name, { ...options, manager: this });
|
|
463
|
+
let res = await acc.sync();
|
|
464
|
+
if (res) this.accounts[name] = acc;
|
|
465
|
+
else return;
|
|
415
466
|
}
|
|
416
467
|
|
|
417
|
-
if (options.init){
|
|
418
|
-
this.init_account = acc
|
|
468
|
+
if (options.init) {
|
|
469
|
+
this.init_account = acc;
|
|
419
470
|
}
|
|
420
471
|
|
|
421
472
|
return acc;
|
|
422
|
-
}
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
folder = async (address, options = {}) => {
|
|
476
|
+
let acc;
|
|
477
|
+
if (options.account) {
|
|
478
|
+
acc = `Accounts/${options.account}`;
|
|
479
|
+
} else if (this.options.init_account) {
|
|
480
|
+
acc = `Accounts/${this.options.init_account.name}`;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
address = `${acc}/${address}`;
|
|
484
|
+
|
|
485
|
+
let folder = await this.ds.folder(address, { account: acc });
|
|
486
|
+
|
|
487
|
+
return folder;
|
|
488
|
+
};
|
|
423
489
|
}
|
|
424
490
|
|
|
425
491
|
export default Manager;
|
package/Objects/Oracle.js
CHANGED
|
@@ -13,6 +13,7 @@ class Oracle extends Handlers {
|
|
|
13
13
|
this.remotes = new Array();
|
|
14
14
|
|
|
15
15
|
this.account_repos = new Object();
|
|
16
|
+
this.configs = new Object();
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
fetch = async (payload, server) => {
|
|
@@ -34,7 +35,7 @@ class Oracle extends Handlers {
|
|
|
34
35
|
let { method, args } = payload;
|
|
35
36
|
|
|
36
37
|
switch (method) {
|
|
37
|
-
case "
|
|
38
|
+
case "update_servers":
|
|
38
39
|
let { repos, account, server } = args;
|
|
39
40
|
|
|
40
41
|
let servers = await this.get_servers(account);
|
|
@@ -88,9 +89,10 @@ class Oracle extends Handlers {
|
|
|
88
89
|
|
|
89
90
|
let fnd =
|
|
90
91
|
this.repos.find((r) => r.repo.get_id() === repo) ||
|
|
91
|
-
acc_repos.find((r) => r.repo._id === repo);
|
|
92
|
+
acc_repos.find((r) => (r.repo._id || r.repo.get_id()) === repo);
|
|
92
93
|
if (fnd) {
|
|
93
94
|
if (fnd.repo.get_id) {
|
|
95
|
+
fnd = { ...fnd };
|
|
94
96
|
fnd.repo = fnd.repo.objectify();
|
|
95
97
|
}
|
|
96
98
|
repos[r] = fnd;
|
|
@@ -135,11 +137,12 @@ class Oracle extends Handlers {
|
|
|
135
137
|
parse_option_repos = async (options) => {
|
|
136
138
|
let repos = [];
|
|
137
139
|
if (options.repos) {
|
|
138
|
-
for (let r = 0; r < options.repos
|
|
140
|
+
for (let r = 0; r < options.repos.length; r++) {
|
|
139
141
|
let rep = options.repos[r];
|
|
142
|
+
|
|
140
143
|
repos.push({
|
|
141
144
|
filter: rep.filter,
|
|
142
|
-
repo: await this.cloth_repo(rep.repo),
|
|
145
|
+
repo: rep.repo.get_id ? rep.repo : await this.cloth_repo(rep.repo),
|
|
143
146
|
});
|
|
144
147
|
}
|
|
145
148
|
} else repos = this.repos;
|
|
@@ -150,7 +153,6 @@ class Oracle extends Handlers {
|
|
|
150
153
|
set_to_repos = async (path, content, options = {}) => {
|
|
151
154
|
let { exclude } = options;
|
|
152
155
|
let repos = await this.parse_option_repos(options),
|
|
153
|
-
content,
|
|
154
156
|
reps = [];
|
|
155
157
|
|
|
156
158
|
for (let r = 0; r < repos.length; r++) {
|
|
@@ -193,31 +195,37 @@ class Oracle extends Handlers {
|
|
|
193
195
|
dot_config = ".config";
|
|
194
196
|
|
|
195
197
|
write = async (path, content, options = {}) => {
|
|
196
|
-
let { account, address } = options
|
|
198
|
+
let { account, address } = options,
|
|
199
|
+
conf;
|
|
197
200
|
|
|
198
201
|
if (path.endsWith(this.dot_config)) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
);
|
|
202
|
+
let sli = path.slice(0, (this.dot_config.length + 1) * -1);
|
|
203
|
+
conf = await this.get_config(sli);
|
|
202
204
|
|
|
203
205
|
let conf_repos = conf ? this.repo_object(conf.repositories, account) : [];
|
|
204
|
-
let reps =
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
`.oracle/${path}`,
|
|
208
|
-
JSON.stringify({
|
|
209
|
-
...conf,
|
|
210
|
-
content,
|
|
211
|
-
repos: reps.map((r) => r.repo._id),
|
|
212
|
-
}),
|
|
213
|
-
{ repos: reps }
|
|
206
|
+
let reps = await this.merge_repos(
|
|
207
|
+
conf_repos,
|
|
208
|
+
await this.filter_repos(`.oracle/${path}`)
|
|
214
209
|
);
|
|
210
|
+
conf = {
|
|
211
|
+
...conf,
|
|
212
|
+
content,
|
|
213
|
+
repositories: reps.map((r) => r.repo._id || r.repo.get_id()),
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
this.configs[sli] = conf;
|
|
217
|
+
|
|
218
|
+
await this.set_to_repos(`.oracle/${path}`, JSON.stringify(conf), {
|
|
219
|
+
repos: reps,
|
|
220
|
+
});
|
|
215
221
|
} else {
|
|
216
222
|
conf = await this.get_config(address, true);
|
|
217
223
|
|
|
218
224
|
let conf_repos = conf ? this.repo_object(conf.repositories, account) : [];
|
|
219
|
-
let reps =
|
|
220
|
-
|
|
225
|
+
let reps = await this.merge_repos(
|
|
226
|
+
conf_repos,
|
|
227
|
+
await this.filter_repos(`.storage/${path}`)
|
|
228
|
+
);
|
|
221
229
|
await this.set_to_repos(`.storage/${path}`, content, { repos: reps });
|
|
222
230
|
}
|
|
223
231
|
};
|
|
@@ -226,7 +234,7 @@ class Oracle extends Handlers {
|
|
|
226
234
|
let { account, address } = options,
|
|
227
235
|
content;
|
|
228
236
|
|
|
229
|
-
if (path.endsWith(this.dot_config
|
|
237
|
+
if (path.endsWith(this.dot_config)) {
|
|
230
238
|
content = await this.get_config(
|
|
231
239
|
path.slice(0, (this.dot_config.length + 1) * -1)
|
|
232
240
|
);
|
|
@@ -234,7 +242,10 @@ class Oracle extends Handlers {
|
|
|
234
242
|
} else {
|
|
235
243
|
let conf = await this.get_config(address, true);
|
|
236
244
|
let conf_repos = conf ? this.repo_object(conf.repositories, account) : [];
|
|
237
|
-
let reps =
|
|
245
|
+
let reps = await this.merge_repos(
|
|
246
|
+
conf_repos,
|
|
247
|
+
await this.filter_repos(`.storage/${path}`)
|
|
248
|
+
);
|
|
238
249
|
|
|
239
250
|
content = await this.get_from_repos(`.storage/${path}`, { repos: reps });
|
|
240
251
|
}
|
|
@@ -242,7 +253,7 @@ class Oracle extends Handlers {
|
|
|
242
253
|
return content;
|
|
243
254
|
};
|
|
244
255
|
|
|
245
|
-
|
|
256
|
+
update_servers = async (account) => {
|
|
246
257
|
let servers = await this.get_servers(account);
|
|
247
258
|
if (servers.find((serv) => this.server_match(serv, this.server))) {
|
|
248
259
|
return;
|
|
@@ -260,7 +271,7 @@ class Oracle extends Handlers {
|
|
|
260
271
|
|
|
261
272
|
let reps = await this.fetch(
|
|
262
273
|
{
|
|
263
|
-
method: "
|
|
274
|
+
method: "update_servers",
|
|
264
275
|
args: { account, repos, server: this.server },
|
|
265
276
|
},
|
|
266
277
|
server
|
|
@@ -285,15 +296,26 @@ class Oracle extends Handlers {
|
|
|
285
296
|
return filtered_repos;
|
|
286
297
|
};
|
|
287
298
|
|
|
299
|
+
get_repo = async (repo) => {
|
|
300
|
+
for (let r = 0; r < this.repos.length; r++) {
|
|
301
|
+
let rep = this.repos[r];
|
|
302
|
+
|
|
303
|
+
if (rep.repo.get_id() === repo.get_id()) return rep.repo;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
288
307
|
add_repo = async (repository) => {
|
|
289
308
|
let { filter, repo } = repository;
|
|
290
|
-
if (await this.get_repo(repo.type, repo.options.name)) return;
|
|
291
309
|
|
|
292
310
|
repo = await this.cloth_repo(repo);
|
|
311
|
+
if (await this.get_repo(repo)) return;
|
|
312
|
+
|
|
293
313
|
this.repos.push({ filter, repo });
|
|
294
314
|
};
|
|
295
315
|
|
|
296
|
-
sync = async () => {
|
|
316
|
+
sync = async (mgr) => {
|
|
317
|
+
this.manager = mgr;
|
|
318
|
+
};
|
|
297
319
|
}
|
|
298
320
|
|
|
299
321
|
export default Oracle;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "godprotocol",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.22",
|
|
4
4
|
"description": "A distributed computing environment",
|
|
5
5
|
"main": "Index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,12 +28,9 @@
|
|
|
28
28
|
"type": "module",
|
|
29
29
|
"homepage": "https://github.com/immanuel-savvy/GodProtocol#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@octokit/rest": "^21.0.2",
|
|
32
31
|
"crypto": "^1.0.1",
|
|
33
|
-
"elliptic": "^6.6.0",
|
|
34
32
|
"fs": "^0.0.1-security",
|
|
35
33
|
"generalised-datastore": "latest",
|
|
36
|
-
"js-base64": "^3.7.7",
|
|
37
34
|
"aircode4": "latest"
|
|
38
35
|
},
|
|
39
36
|
"devDependencies": {
|
package/repos/fs.js
CHANGED
|
@@ -1,114 +1,122 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import { copy_object } from
|
|
3
|
-
import Repository from
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { copy_object } from "generalised-datastore/utils/functions.js";
|
|
3
|
+
import Repository from "godprotocol/Objects/Repository.js";
|
|
4
4
|
import { post_request } from "godprotocol/utils/services.js";
|
|
5
5
|
|
|
6
|
-
class Fs extends Repository{
|
|
7
|
-
constructor(options={}){
|
|
8
|
-
super()
|
|
9
|
-
|
|
6
|
+
class Fs extends Repository {
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
10
|
this._fs = fs;
|
|
11
11
|
this.__dirname = options.__dirname;
|
|
12
12
|
this.remote = options.remote;
|
|
13
13
|
this.name = options.name;
|
|
14
14
|
|
|
15
|
-
this.type =
|
|
15
|
+
this.type = "fs";
|
|
16
16
|
this.cache = new Object();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
parse_path = async(path)=>{
|
|
20
|
-
path = path.split(
|
|
21
|
-
let addr = path.slice(0
|
|
22
|
-
if (!this._fs.existsSync(addr)){
|
|
23
|
-
this._fs.mkdirSync(addr, {recursive: true})
|
|
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
24
|
}
|
|
25
|
-
}
|
|
25
|
+
};
|
|
26
26
|
|
|
27
|
-
call = async payload=>{
|
|
27
|
+
call = async (payload) => {
|
|
28
28
|
let result;
|
|
29
|
-
switch(payload.op){
|
|
30
|
-
case
|
|
31
|
-
result = await this.write(payload.path, payload.data)
|
|
32
|
-
break
|
|
33
|
-
case
|
|
34
|
-
result = await this.read(payload.path)
|
|
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
35
|
break;
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fetch = async payload=>{
|
|
41
|
-
let res
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
}
|
|
48
56
|
|
|
49
57
|
return res;
|
|
50
|
-
}
|
|
58
|
+
};
|
|
51
59
|
|
|
52
|
-
write_file = async(path, data)=>{
|
|
53
|
-
path = this.path(path)
|
|
60
|
+
write_file = async (path, data) => {
|
|
61
|
+
path = this.path(path);
|
|
62
|
+
console.log(path, data);
|
|
54
63
|
|
|
55
|
-
await this.fetch({path, data, op:
|
|
56
|
-
}
|
|
64
|
+
await this.fetch({ path, data, op: "write" });
|
|
65
|
+
};
|
|
57
66
|
|
|
58
|
-
write = async(path, data) => {
|
|
59
|
-
await this.parse_path(path)
|
|
60
|
-
this._fs.writeFileSync(path, data)
|
|
61
|
-
|
|
62
|
-
this.cache[path] = data
|
|
63
|
-
}
|
|
67
|
+
write = async (path, data) => {
|
|
68
|
+
await this.parse_path(path);
|
|
69
|
+
this._fs.writeFileSync(path, data);
|
|
64
70
|
|
|
65
|
-
|
|
71
|
+
this.cache[path] = data;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
read = async (path) => {
|
|
66
75
|
let data;
|
|
67
|
-
try{
|
|
68
|
-
data = this.cache[path]
|
|
69
|
-
if (!data){
|
|
70
|
-
await this.parse_path(path)
|
|
71
|
-
data = this._fs.readFileSync(path, {encoding:
|
|
72
|
-
}else {
|
|
73
|
-
data = copy_object(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);
|
|
74
83
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
console.log(e.message)
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.log(e.message);
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
return data;
|
|
81
|
-
}
|
|
89
|
+
};
|
|
82
90
|
|
|
83
|
-
read_file = async(path)=>{
|
|
84
|
-
path = this.path(path)
|
|
91
|
+
read_file = async (path) => {
|
|
92
|
+
path = this.path(path);
|
|
93
|
+
|
|
94
|
+
let data = await this.fetch({ path, op: "read" });
|
|
85
95
|
|
|
86
|
-
let data = await this.fetch({path, op: 'read'})
|
|
87
|
-
|
|
88
96
|
return data;
|
|
89
|
-
}
|
|
97
|
+
};
|
|
90
98
|
|
|
91
|
-
path = pth=>{
|
|
92
|
-
return `${this.__dirname}/${pth}
|
|
93
|
-
}
|
|
99
|
+
path = (pth) => {
|
|
100
|
+
return `${this.__dirname}/${pth}`;
|
|
101
|
+
};
|
|
94
102
|
|
|
95
|
-
mkdir = async(path)=>{
|
|
103
|
+
mkdir = async (path) => {
|
|
96
104
|
let done;
|
|
97
|
-
try{
|
|
98
|
-
this._fs.mkdirSync(this.path(path), {recursive: true})
|
|
99
|
-
done = true
|
|
100
|
-
}catch(e){
|
|
101
|
-
done = false
|
|
105
|
+
try {
|
|
106
|
+
this._fs.mkdirSync(this.path(path), { recursive: true });
|
|
107
|
+
done = true;
|
|
108
|
+
} catch (e) {
|
|
109
|
+
done = false;
|
|
102
110
|
}
|
|
103
111
|
|
|
104
112
|
return done;
|
|
105
|
-
}
|
|
113
|
+
};
|
|
106
114
|
|
|
107
|
-
exists = async(path)=>{
|
|
108
|
-
path = this.path(path)
|
|
109
|
-
|
|
110
|
-
return !!this.cache[path] || this._fs.existsSync(path)
|
|
111
|
-
}
|
|
115
|
+
exists = async (path) => {
|
|
116
|
+
path = this.path(path);
|
|
117
|
+
|
|
118
|
+
return !!this.cache[path] || this._fs.existsSync(path);
|
|
119
|
+
};
|
|
112
120
|
}
|
|
113
121
|
|
|
114
|
-
export default Fs
|
|
122
|
+
export default Fs;
|