godprotocol 1.1.31 → 1.2.0
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/Datatypes/arr.js +559 -254
- package/Datatypes/bool.js +8 -5
- package/Datatypes/callable.js +1 -1
- package/Datatypes/cls.js +193 -24
- package/Datatypes/conf.js +2 -2
- package/Datatypes/err.js +25 -0
- package/Datatypes/func.js +89 -13
- package/Datatypes/functions/storage.js +572 -12
- package/Datatypes/functions/wallet.js +49 -0
- package/Datatypes/instance.js +87 -122
- package/Datatypes/num.js +192 -153
- package/Datatypes/str.js +188 -122
- package/Datatypes/twa.js +346 -71
- package/Datatypes/voi.js +9 -4
- package/Index.js +1 -1
- package/Instances/account.js +0 -0
- package/Instances/event.js +0 -0
- package/Instances/fold.js +103 -0
- package/Instances/folder_queries.js +46 -0
- package/Instances/response.js +31 -0
- package/Objects/Account.js +160 -110
- package/Objects/Blockweb.js +6 -11
- package/Objects/Callable.js +223 -188
- package/Objects/Chain.js +127 -142
- package/Objects/Datatypes.js +114 -588
- package/Objects/Manager.js +349 -39
- package/Objects/Oracle.js +283 -210
- package/Objects/Repository.js +12 -33
- package/Objects/Trinity.js +9 -7
- package/Objects/Utils.js +8 -8
- package/Objects/Virtual_machine.js +320 -320
- package/README.md +0 -0
- package/callables/functions/assert.js +10 -0
- package/callables/functions/display.js +2 -3
- package/callables/functions/env.js +5 -0
- package/callables/functions/event.js +14 -0
- package/callables/functions/exit.js +3 -2
- package/callables/functions/folder.js +15 -0
- package/callables/functions/get_uid.js +6 -0
- package/callables/functions/hash.js +7 -0
- package/callables/functions/import_.js +62 -0
- package/callables/functions/local.js +9 -0
- package/callables/functions/net.js +33 -18
- package/callables/functions/parse.js +35 -0
- package/callables/functions/query.js +12 -0
- package/callables/functions/render.js +9 -13
- package/callables/functions/servers.js +10 -0
- package/callables/functions/spawn.js +7 -0
- package/callables/functions/store.js +75 -0
- package/callables/functions/super_.js +24 -0
- package/callables/functions/typeof.js +32 -0
- package/callables/functions/wait.js +9 -0
- package/callables/register.js +193 -8
- package/html/create.js +110 -0
- package/html/index.js +114 -0
- package/html/load.js +165 -0
- package/html/parse.js +171 -0
- package/html/run.js +151 -0
- package/html/util.js +5 -0
- package/package.json +5 -3
- package/repos/fs.js +114 -0
- package/repos/github.js +73 -0
- package/repos/ram.js +47 -0
- package/utils/create_server.js +66 -26
- package/utils/hash.js +3 -2
- package/utils/ops.js +2 -0
- package/utils/oracle_handlers.js +7 -0
- package/utils/services.js +18 -51
- package/utils/socket_server.js +36 -0
- package/utils/vm_utils.js +271 -59
- package/callables/functions/assign.js +0 -6
package/utils/vm_utils.js
CHANGED
|
@@ -1,102 +1,314 @@
|
|
|
1
|
-
import Arr from "../Datatypes/arr";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
1
|
+
import Arr from "../Datatypes/arr.js";
|
|
2
|
+
import Num from "../Datatypes/num.js";
|
|
3
|
+
import Str from "../Datatypes/str.js";
|
|
4
|
+
import Twa from "../Datatypes/twa.js";
|
|
5
|
+
import Voi from "../Datatypes/voi.js";
|
|
6
|
+
import Bool from "../Datatypes/bool.js";
|
|
7
|
+
import Instance from "../Datatypes/instance.js";
|
|
8
|
+
import Func from "../Datatypes/func.js";
|
|
9
|
+
import Cls from "../Datatypes/cls.js";
|
|
10
|
+
import Err from "../Datatypes/err.js";
|
|
11
|
+
import { ops } from "./ops.js";
|
|
12
|
+
import Fold from "godprotocol/Instances/fold.js";
|
|
13
|
+
import Res from "godprotocol/Instances/response.js";
|
|
14
|
+
import { hash } from "godprotocol/utils/hash.js";
|
|
12
15
|
|
|
13
16
|
class Vm_utils {
|
|
14
17
|
constructor() {
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
this.ops = ops;
|
|
19
|
+
|
|
20
|
+
this.datatypes = ["string", "number", "void", "boolean", "array", "twain"];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
gen_location=(addr)=>{
|
|
24
|
+
return `${addr|| this.account.physical_address}/${this.gen_uid(true)}`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
error_instance = async(err_payload, alias)=>{
|
|
28
|
+
let {chain, manager} = this.account;
|
|
29
|
+
let res = await this.instantiate({type: 'error', ...err_payload}, {chain})
|
|
30
|
+
if (alias){
|
|
31
|
+
await (await manager.ds.folder(alias.location)).write(res)
|
|
24
32
|
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
variable = async(address, {chain, config, obj})=>{
|
|
36
|
+
let result;
|
|
37
|
+
let chn = await chain.chain(address)
|
|
38
|
+
let fold = await chn.folder()
|
|
39
|
+
|
|
40
|
+
if(config && config._id && config.type === 'reference'){
|
|
41
|
+
result = {
|
|
42
|
+
type: 'address',
|
|
43
|
+
value: address,
|
|
44
|
+
_id: config._id
|
|
45
|
+
}
|
|
46
|
+
if (config.object) result.object = config.object
|
|
47
|
+
}else result = await fold.readone(config && config._id?{_id: config._id}: null)
|
|
48
|
+
|
|
49
|
+
if (obj) result = await this.cloth(result)
|
|
50
|
+
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
gen_uid = (loc) => {
|
|
55
|
+
return `_${Math.random().toString().replace(".", "")}${loc ?'': '_'}${Date.now()}`;
|
|
56
|
+
};
|
|
25
57
|
|
|
26
|
-
|
|
58
|
+
spread_properties = async(object, cls, {lists, benches})=>{
|
|
59
|
+
for (let m in cls.methods){
|
|
60
|
+
object.methods[m] = cls.methods[m]
|
|
61
|
+
}
|
|
62
|
+
for(let p in cls.properties){
|
|
63
|
+
let prop = cls.properties[p]
|
|
64
|
+
let res = await this.nodelist(prop)
|
|
65
|
+
lists.push(...res)
|
|
66
|
+
benches[p] = lists.length - 1;
|
|
67
|
+
}
|
|
27
68
|
}
|
|
28
69
|
|
|
29
|
-
|
|
30
|
-
|
|
70
|
+
base_classes = async (object, config, {inherited, lists, benches, chain})=>{
|
|
71
|
+
|
|
72
|
+
for (let b=0; b< config.base_classes.length; b++){
|
|
73
|
+
let blc = config.base_classes[b]
|
|
74
|
+
if (inherited.includes(blc.location)) continue
|
|
75
|
+
|
|
76
|
+
let cls = await this.cloth(await this.variable(blc.location, {chain}), {just_content: true})
|
|
77
|
+
|
|
78
|
+
await this.spread_properties(object, cls, {lists, benches})
|
|
79
|
+
|
|
80
|
+
if (cls.base_classes.length)
|
|
81
|
+
await this.base_classes(object, cls, {inherited, chain})
|
|
82
|
+
}
|
|
31
83
|
}
|
|
32
84
|
|
|
33
|
-
|
|
34
|
-
let
|
|
85
|
+
retrieve = async(object, o)=>{
|
|
86
|
+
let obj, addr;
|
|
87
|
+
if (object.type === 'instance') {
|
|
88
|
+
let cls = await this.cloth({
|
|
89
|
+
type:'function',
|
|
90
|
+
address: object.cls,
|
|
91
|
+
// _id: object.cls_id
|
|
92
|
+
})
|
|
93
|
+
addr = await cls.get_instance(object, true)
|
|
94
|
+
if (o){
|
|
95
|
+
obj = await this.cloth(addr)
|
|
96
|
+
}
|
|
97
|
+
} else if (['twain', 'array'].includes(object.type)) {
|
|
98
|
+
obj = await this.cloth_content(object);
|
|
99
|
+
|
|
100
|
+
await obj.retrieve(object.entries || object.items)
|
|
101
|
+
|
|
102
|
+
addr = await obj.to_address()
|
|
103
|
+
} else if (object.type === 'function') {
|
|
104
|
+
console.log(object, 'in here')
|
|
105
|
+
// process.exit()
|
|
106
|
+
obj = object
|
|
107
|
+
addr = await object.to_address()
|
|
108
|
+
} else {
|
|
109
|
+
obj = await this.cloth_content(object)
|
|
110
|
+
|
|
111
|
+
addr = await obj.to_address()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return o ? obj : addr;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
parse_dynamic = async (literal, options = {}) => {
|
|
118
|
+
let { chain, config } = options;
|
|
35
119
|
|
|
36
120
|
let aircode = this.account.aircode;
|
|
37
|
-
let sequence = aircode.to_sequence(
|
|
121
|
+
let sequence = aircode.to_sequence(
|
|
122
|
+
JSON.stringify(literal),
|
|
123
|
+
chain.physical_address
|
|
124
|
+
);
|
|
38
125
|
|
|
39
126
|
let res = await chain.add_config(sequence[0].body[0]);
|
|
40
|
-
let address = await this.execute(res, {chain})
|
|
127
|
+
let address = await this.execute(res, { chain });
|
|
41
128
|
|
|
42
129
|
return address;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
folder = async(fold)=>{
|
|
133
|
+
return {
|
|
134
|
+
type: 'folder',
|
|
135
|
+
repo: fold.config.repo,
|
|
136
|
+
value: fold.address,
|
|
137
|
+
_id: await this.hash(fold.address)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
base_val = async type=>{
|
|
142
|
+
let result;
|
|
143
|
+
|
|
144
|
+
switch(type){
|
|
145
|
+
case 'string':
|
|
146
|
+
result = ''
|
|
147
|
+
break;
|
|
148
|
+
case 'number':
|
|
149
|
+
result = '0'
|
|
150
|
+
break;
|
|
151
|
+
case 'array':
|
|
152
|
+
result = []
|
|
153
|
+
break;
|
|
154
|
+
case 'twain':
|
|
155
|
+
result = {}
|
|
156
|
+
break;
|
|
157
|
+
case 'boolean':
|
|
158
|
+
result = false
|
|
159
|
+
}
|
|
160
|
+
return await this.typecast(result, type, true)
|
|
43
161
|
}
|
|
44
162
|
|
|
45
|
-
resolve_addr = (addr)=>{
|
|
46
|
-
if (!addr)return addr
|
|
163
|
+
resolve_addr = (addr) => {
|
|
164
|
+
if (!addr) return addr;
|
|
47
165
|
|
|
48
|
-
if (addr.startsWith(
|
|
49
|
-
addr = `${this.account.physical_address}/${addr.slice(2)}
|
|
166
|
+
if (addr.startsWith("@")) {
|
|
167
|
+
addr = `${this.account.physical_address}/${addr.slice(2)}`;
|
|
50
168
|
}
|
|
51
169
|
|
|
52
170
|
return addr;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
typecast = async(obj, type)=>{
|
|
174
|
+
return obj
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
_split_datapath = (datapath)=>{
|
|
178
|
+
datapath = datapath.split('/')
|
|
179
|
+
|
|
180
|
+
return [datapath.slice(0,-1).join('/'), datapath.slice(-1)[0]]
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
voided = async ()=>{
|
|
184
|
+
return await this.statics({type: 'void'})
|
|
53
185
|
}
|
|
54
186
|
|
|
55
|
-
|
|
187
|
+
statics = async(config)=>{
|
|
188
|
+
let addr = `${this.account.physical_address}/__$STATICS/`
|
|
189
|
+
let folder = await this.account.manager.ds.folder(addr)
|
|
190
|
+
|
|
191
|
+
let value = config.type=== 'boolean'? config.value : 'void'
|
|
192
|
+
let _id = await this.hash(value)
|
|
193
|
+
await folder.write({type: config.type, value, _id })
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
value: addr,
|
|
197
|
+
_id,
|
|
198
|
+
type: 'address'
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
err_objects = [
|
|
203
|
+
"ZeroDivisionError",
|
|
204
|
+
"MathError",
|
|
205
|
+
"SyntaxError",
|
|
206
|
+
"ValueError",
|
|
207
|
+
"RuntimeError",
|
|
208
|
+
"CompileError",
|
|
209
|
+
"AssertionError",
|
|
210
|
+
]
|
|
211
|
+
|
|
212
|
+
cloth = async(address, options={})=>{
|
|
213
|
+
let {just_content} = options
|
|
214
|
+
let content;
|
|
215
|
+
|
|
216
|
+
if (address.config){
|
|
217
|
+
address = {
|
|
218
|
+
type: 'function',
|
|
219
|
+
_id: address._id,
|
|
220
|
+
address: address.value,
|
|
221
|
+
value: address.value,
|
|
222
|
+
}
|
|
223
|
+
}
|
|
56
224
|
|
|
225
|
+
if (address.type === 'address'){
|
|
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('.configs')
|
|
230
|
+
}
|
|
231
|
+
content = await folder.readone({_id: address._id})
|
|
232
|
+
}else if(address.object) {
|
|
233
|
+
content = {...address, type: 'function'}
|
|
234
|
+
}
|
|
235
|
+
}else if(['function', 'class'].includes(address.type)) {
|
|
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('.configs')
|
|
241
|
+
|
|
242
|
+
content = await folder.readone(address._id? {_id: address._id}: null)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (just_content)
|
|
247
|
+
return content;
|
|
248
|
+
|
|
249
|
+
if (content){
|
|
250
|
+
content = await this.cloth_content(content)
|
|
251
|
+
content.address = address.value
|
|
252
|
+
if (address.is_literal && content.type === 'twain') content.is_literal = true
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return content
|
|
57
256
|
}
|
|
58
257
|
|
|
59
|
-
cloth_content = async(content, options)=>{
|
|
258
|
+
cloth_content = async (content, options) => {
|
|
60
259
|
let obj;
|
|
61
260
|
|
|
62
|
-
if (content
|
|
261
|
+
if (!content) return content;
|
|
63
262
|
|
|
64
|
-
switch(content.type){
|
|
65
|
-
case
|
|
66
|
-
obj = new Num(content, this.account)
|
|
263
|
+
switch (content.type) {
|
|
264
|
+
case "number":
|
|
265
|
+
obj = new Num(content, this.account);
|
|
67
266
|
break;
|
|
68
|
-
case
|
|
69
|
-
obj = new Str(content, this.account)
|
|
267
|
+
case "string":
|
|
268
|
+
obj = new Str(content, this.account);
|
|
70
269
|
break;
|
|
71
|
-
case
|
|
72
|
-
obj = new Bool(content, this.account)
|
|
270
|
+
case "boolean":
|
|
271
|
+
obj = new Bool(content, this.account);
|
|
73
272
|
break;
|
|
74
|
-
case
|
|
75
|
-
obj = new Voi(content, this.account)
|
|
273
|
+
case "void":
|
|
274
|
+
obj = new Voi(content, this.account);
|
|
76
275
|
break;
|
|
77
|
-
case
|
|
78
|
-
obj = new Arr(content, this.account)
|
|
79
|
-
break
|
|
80
|
-
case
|
|
81
|
-
obj = new Twa(content, this.account)
|
|
276
|
+
case "array":
|
|
277
|
+
obj = new Arr(content, this.account);
|
|
278
|
+
break;
|
|
279
|
+
case "twain":
|
|
280
|
+
obj = new Twa(content, this.account);
|
|
281
|
+
break;
|
|
282
|
+
case "instance":
|
|
283
|
+
obj = new Instance(content, this.account);
|
|
284
|
+
break;
|
|
285
|
+
case "function":
|
|
286
|
+
obj = new Func(content, this.account);
|
|
82
287
|
break;
|
|
83
|
-
case '
|
|
84
|
-
obj = new
|
|
288
|
+
case 'folder':
|
|
289
|
+
obj = new Fold(content, this.account)
|
|
85
290
|
break;
|
|
86
|
-
case '
|
|
87
|
-
obj = new
|
|
291
|
+
case 'folder_response':
|
|
292
|
+
obj = new Res(content, this.account)
|
|
88
293
|
break;
|
|
89
|
-
case
|
|
90
|
-
obj = new Cls(content, this.account)
|
|
294
|
+
case "class":
|
|
295
|
+
obj = new Cls(content, this.account);
|
|
296
|
+
break;
|
|
297
|
+
case 'error':
|
|
298
|
+
obj = new Err(content, this.account)
|
|
91
299
|
break;
|
|
92
300
|
default:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}else obj = content
|
|
96
|
-
// console.log(content, 'uh')
|
|
301
|
+
obj = await this.cloth(content)
|
|
302
|
+
break;
|
|
97
303
|
}
|
|
98
304
|
|
|
99
|
-
return await obj.sync(options)
|
|
305
|
+
return await obj.sync(options);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
hash = async(value, alg)=>{
|
|
309
|
+
if (typeof value !== 'string') value = JSON.stringify(value)
|
|
310
|
+
|
|
311
|
+
return hash(value, alg)
|
|
100
312
|
}
|
|
101
313
|
}
|
|
102
314
|
|