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/Objects/Callable.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Vm_utils from "../utils/vm_utils";
|
|
1
|
+
import Vm_utils from "../utils/vm_utils.js";
|
|
2
2
|
|
|
3
3
|
class Callable extends Vm_utils {
|
|
4
4
|
constructor() {
|
|
@@ -7,208 +7,208 @@ class Callable extends Vm_utils {
|
|
|
7
7
|
this.objects = new Object();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
parse_aircode = async (result, { config, chain }) => {
|
|
10
|
+
parse_aircode = async (result, { config, chain, id }) => {
|
|
11
11
|
if (result == null) result = "void";
|
|
12
12
|
|
|
13
|
-
let
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
13
|
+
let loc = config && config.location.split("/").slice(2).join("/")
|
|
14
|
+
|
|
15
|
+
result = result === 'void'? result: JSON.stringify(result)
|
|
16
|
+
if (result === 'void') return await this.voided()
|
|
17
17
|
|
|
18
|
+
let res = await this.account.compiler.to_sequence(
|
|
19
|
+
result,
|
|
20
|
+
!loc ? "CONSTANTS" : loc
|
|
21
|
+
)
|
|
22
|
+
res = res[0].body[0];
|
|
23
|
+
|
|
18
24
|
await chain.add_config(res);
|
|
19
|
-
result = await this.execute(res, { chain });
|
|
25
|
+
result = await this.execute(res, { chain, id });
|
|
20
26
|
|
|
21
27
|
return result;
|
|
22
28
|
};
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
|
|
30
|
+
instantiate = async (config, { chain, value, _id }) => {
|
|
31
|
+
let chn = await chain.chain(config.location)
|
|
32
|
+
let folder = await chn.folder()
|
|
27
33
|
|
|
28
|
-
if (
|
|
29
|
-
|
|
34
|
+
if (['void', 'boolean'].includes(config.type)){
|
|
35
|
+
let res = await this.statics(config)
|
|
36
|
+
return res;
|
|
30
37
|
}
|
|
31
38
|
|
|
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
|
-
|
|
39
|
+
let obj = {
|
|
40
|
+
_id,
|
|
41
|
+
type: config.type,
|
|
42
|
+
created: Date.now(),
|
|
43
|
+
location: folder.address
|
|
44
|
+
}, res;
|
|
45
|
+
|
|
46
|
+
if(config.type === 'error'){
|
|
47
|
+
obj.value = config.payload
|
|
48
|
+
res = await folder.write(obj)
|
|
49
|
+
obj._id = res._id
|
|
50
|
+
|
|
51
|
+
} else if (config.type === 'twain'){
|
|
52
|
+
res = await folder.write(obj)
|
|
53
|
+
obj._id = res._id
|
|
54
|
+
obj.created = res.created
|
|
55
|
+
|
|
56
|
+
if (value){
|
|
57
|
+
let val_obj = await this.cloth(value)
|
|
58
|
+
let obj_obj = await this.cloth_content(obj)
|
|
59
|
+
obj_obj.address = folder.address
|
|
60
|
+
await obj_obj.extend(val_obj)
|
|
61
|
+
}else {
|
|
62
|
+
for (let key in config.value){
|
|
63
|
+
let [prop, value] = config.value[key]
|
|
64
|
+
if(typeof prop === 'string'){
|
|
65
|
+
prop = await this.execute(await this.read_config(prop), {chain})
|
|
66
|
+
}
|
|
67
|
+
if(typeof value === 'string'){
|
|
68
|
+
value = await this.execute(await this.read_config(value), {chain})
|
|
69
|
+
}
|
|
70
|
+
await chn.set({twa: obj, key, prop, value})
|
|
57
71
|
}
|
|
58
72
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
|
|
74
|
+
res = await folder.write(obj, {replace: true})
|
|
75
|
+
}else if (config.type === 'array'){
|
|
76
|
+
obj.length = 0
|
|
77
|
+
|
|
78
|
+
res = await folder.write(obj)
|
|
79
|
+
obj._id = res._id
|
|
80
|
+
obj.created = res.created
|
|
81
|
+
|
|
82
|
+
if (value){
|
|
83
|
+
let val_obj = await this.cloth(value)
|
|
84
|
+
let obj_obj = await this.cloth_content(obj)
|
|
85
|
+
obj_obj.address = folder.address
|
|
86
|
+
await obj_obj.extend(val_obj)
|
|
87
|
+
}else {
|
|
88
|
+
for (let i =0; i < config.value.length; i++){
|
|
89
|
+
let item = config.value[i]
|
|
90
|
+
if (typeof item === 'string'){
|
|
91
|
+
item = await this.execute(await this.read_config(item), {chain})
|
|
92
|
+
}
|
|
93
|
+
await chn.insert({arr: obj, item, index: obj.length})
|
|
66
94
|
}
|
|
67
95
|
}
|
|
68
|
-
|
|
96
|
+
|
|
97
|
+
res = await folder.write(obj, {replace: true})
|
|
98
|
+
}else if (['string', 'number', 'void', 'boolean'].includes(config.type)){
|
|
99
|
+
if (value){
|
|
100
|
+
folder = await this.account.manager.ds.folder(value.value)
|
|
101
|
+
obj._id = value._id
|
|
102
|
+
}else {
|
|
103
|
+
obj.value = config.value
|
|
104
|
+
res = await folder.write(obj)
|
|
105
|
+
obj._id = res._id
|
|
106
|
+
obj.created = res.created
|
|
107
|
+
obj.address = folder.address
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
res = {
|
|
111
|
+
value: folder.address,
|
|
112
|
+
type: 'address',
|
|
113
|
+
_id: obj._id
|
|
69
114
|
}
|
|
70
115
|
|
|
71
|
-
|
|
72
|
-
{ content: config.value, __classifier__: config.type, uid },
|
|
73
|
-
{ hash, is_instance: true }
|
|
74
|
-
);
|
|
75
|
-
return res;
|
|
116
|
+
return res
|
|
76
117
|
};
|
|
77
118
|
|
|
78
|
-
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
result = value;
|
|
82
|
-
} else if (value && value.type === "address") {
|
|
83
|
-
result = value;
|
|
84
|
-
} else
|
|
85
|
-
result = await this.parse_aircode(value, { config: call_config, chain });
|
|
86
|
-
|
|
87
|
-
return result;
|
|
88
|
-
};
|
|
119
|
+
callable_address = async (config, o)=>{
|
|
120
|
+
let obj = await this.cloth_content(config)
|
|
121
|
+
obj.address = config.address
|
|
89
122
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
let
|
|
95
|
-
let
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (this.datatypes.includes(classifier)) {
|
|
101
|
-
for (let a = 0; a < call_config.arguments.length; a++)
|
|
102
|
-
call_config.arguments[a] = await this.execute(
|
|
103
|
-
call_config.arguments[a],
|
|
104
|
-
{ chain, cloth: true }
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
let value = await res.operate(identifier.value, call_config.arguments, {
|
|
108
|
-
classifier,
|
|
109
|
-
config: call_config,
|
|
110
|
-
chain,
|
|
111
|
-
});
|
|
112
|
-
result = await this.operate_result(value, call_config, chain);
|
|
113
|
-
} else {
|
|
114
|
-
let conf = await oracle.fs.read(`${identifier.value}/.config`);
|
|
115
|
-
conf = await oracle.fs.read(`${identifier.value}/${conf.index - 1}`);
|
|
116
|
-
let content = JSON.parse(conf.content);
|
|
117
|
-
|
|
118
|
-
let val = await this.execute(content, {
|
|
119
|
-
chain,
|
|
120
|
-
call_config: {
|
|
121
|
-
...call_config,
|
|
122
|
-
object: { type: "address", value: identifier.object },
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
result = val;
|
|
123
|
+
return o ? obj : await obj.to_address()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
execute_call = async (call_config, { chain, thread }) => {
|
|
127
|
+
let result;
|
|
128
|
+
let {identifier, arguments: args, location} = call_config
|
|
129
|
+
|
|
130
|
+
if (location){
|
|
131
|
+
location = await chain.chain(location)
|
|
127
132
|
}
|
|
128
133
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (!["function", "class"].includes(conf.type)) {
|
|
142
|
-
conf = await obj.get(identifier.prev_name, {
|
|
143
|
-
obj: identifier.prev_name,
|
|
144
|
-
});
|
|
145
|
-
conf = await this.resolve_address(conf.value);
|
|
134
|
+
if (identifier.type === 'address'){
|
|
135
|
+
// If call is a reference, such as to a class method
|
|
136
|
+
let {object, value, config: is_config} = identifier
|
|
137
|
+
if (object){
|
|
138
|
+
let spl = this._split_datapath(object)
|
|
139
|
+
let obj = {value: spl[0], _id: spl[1], type: 'address', config: is_config}
|
|
140
|
+
obj = await this.cloth(obj)
|
|
141
|
+
|
|
142
|
+
if (value.includes('/')){
|
|
143
|
+
await obj.run(call_config, {thread, chain})
|
|
144
|
+
}else{
|
|
145
|
+
result = await obj.call(value, {chain, call_config, thread})
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
}else {
|
|
148
|
+
let obj = await this.cloth(identifier)
|
|
149
|
+
if (['class', 'function', 'instance'].includes(obj.type)){
|
|
150
|
+
|
|
151
|
+
}else result = await this.throw_error({type:"TypeError", message: `type ${obj.type} is not callable.`})
|
|
148
152
|
}
|
|
149
|
-
} else if (
|
|
150
|
-
let
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
let
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
} else {
|
|
166
|
-
let iconf = await oracle.fs.read(`${config.content.value}/.config`);
|
|
167
|
-
let configg = await oracle.fs.read(
|
|
168
|
-
`${config.content.value}/${iconf.index - 1}`
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
result = await this.execute(JSON.parse(configg.content), {
|
|
172
|
-
call_config,
|
|
173
|
-
chain,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
153
|
+
} else if (['function', 'class'].includes(identifier.type)){
|
|
154
|
+
let call = await this.cloth(identifier)
|
|
155
|
+
await call.invoke(args, {chain, call_config, thread})
|
|
156
|
+
} else if (identifier.includes('/')){
|
|
157
|
+
// If call is a user-defined address
|
|
158
|
+
let folder = await this.account.manager.ds.folder(identifier)
|
|
159
|
+
let payload = await folder.readone()
|
|
160
|
+
|
|
161
|
+
if (payload.object){
|
|
162
|
+
result = await this.execute_call({...call_config, identifier: payload}, {chain, thread})
|
|
163
|
+
}else {
|
|
164
|
+
if (payload.config && payload._id === payload.value){
|
|
165
|
+
result = await this.execute_call({...call_config, identifier: payload._id}, {chain, thread})
|
|
166
|
+
}else {
|
|
167
|
+
let call = await this.cloth(payload)
|
|
168
|
+
await call.invoke(args, {chain, call_config, thread})
|
|
176
169
|
}
|
|
177
|
-
} else if (conf.current) {
|
|
178
|
-
let iconf = await oracle.fs.read(`${conf.current}/.config`);
|
|
179
|
-
let config = await oracle.fs.read(`${conf.current}/${iconf.index - 1}`);
|
|
180
|
-
|
|
181
|
-
result = await this.execute(JSON.parse(config.content), {
|
|
182
|
-
call_config,
|
|
183
|
-
chain,
|
|
184
|
-
});
|
|
185
|
-
} else {
|
|
186
|
-
let config = await oracle.fs.read(
|
|
187
|
-
`${call_config.identifier}/${conf.index - 1}`
|
|
188
|
-
);
|
|
189
|
-
result = await this.execute(JSON.parse(config.content), {
|
|
190
|
-
call_config,
|
|
191
|
-
chain,
|
|
192
|
-
});
|
|
193
170
|
}
|
|
171
|
+
} else if (this.datatypes.includes(identifier)){
|
|
172
|
+
// If call is Datatype instantiation
|
|
173
|
+
|
|
174
|
+
let _id = call_config.arguments.find(p=>p.identifier === '_id')
|
|
175
|
+
if (_id){
|
|
176
|
+
delete _id.identifier
|
|
177
|
+
_id = await this.cloth({..._id})
|
|
178
|
+
if (_id.type === 'string')
|
|
179
|
+
_id = await this.hash(await _id.literal())
|
|
180
|
+
else _id = null
|
|
181
|
+
}else _id = null
|
|
182
|
+
let val = call_config.arguments.find(p=>p.identifier === 'value')
|
|
183
|
+
val = (val && val.value) || call_config.arguments[0]
|
|
184
|
+
result = await this.instantiate({type: identifier, location: call_config.location}, {chain, _id, value: val})
|
|
185
|
+
} else if (this.err_objects.includes(identifier)){
|
|
186
|
+
let message = await (await this.cloth(args[0])).literal()
|
|
187
|
+
result = await this.throw_error({message, type: identifier})
|
|
194
188
|
} else {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
189
|
+
// If call is a reserved word.
|
|
190
|
+
|
|
191
|
+
let call = await this.callable(identifier)
|
|
192
|
+
let {callable, config} = call;
|
|
193
|
+
let data = {}
|
|
194
|
+
for (let a = 0; a < args.length; a++) {
|
|
195
|
+
let param;
|
|
196
|
+
let arg = args[a];
|
|
197
|
+
|
|
198
|
+
if (arg.identifier)
|
|
199
|
+
param = config.parameters.find(p=>p.name === arg.identifier)
|
|
200
|
+
|
|
201
|
+
if(!param) {
|
|
202
|
+
param = config.parameters[arg.position || a];
|
|
203
|
+
if (!param) {
|
|
204
|
+
let lst_param = config.parameters.slice(-1)[0];
|
|
205
|
+
if (lst_param.spread) param = lst_param;
|
|
210
206
|
}
|
|
211
|
-
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let res = await this.cloth(arg);
|
|
210
|
+
|
|
211
|
+
if (param){
|
|
212
212
|
if (param.spread) {
|
|
213
213
|
let arr = data[param.name];
|
|
214
214
|
if (!arr) {
|
|
@@ -218,20 +218,47 @@ class Callable extends Vm_utils {
|
|
|
218
218
|
arr.push(res);
|
|
219
219
|
} else data[param.name] = res;
|
|
220
220
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
result = await callable(data, {vm: this, call_config, chain, thread})
|
|
224
|
+
|
|
225
|
+
if( ['store', 'net'].includes(identifier)){
|
|
226
|
+
result = await this.voided()
|
|
227
|
+
} else if(identifier === 'parse' && result){
|
|
228
|
+
}else if (['Twain', 'folder'].includes(identifier)){
|
|
229
|
+
result = await result.to_address()
|
|
230
|
+
} else if(result && ['address', 'function'].includes(result.type)){
|
|
231
|
+
} else {
|
|
232
|
+
result = await this.parse_aircode(result, {
|
|
233
|
+
config: call_config,
|
|
234
|
+
chain,
|
|
235
|
+
});
|
|
229
236
|
}
|
|
230
237
|
}
|
|
231
238
|
|
|
232
239
|
return result;
|
|
233
240
|
};
|
|
234
241
|
|
|
242
|
+
resolve_import = async(config, chain)=>{
|
|
243
|
+
let addr = this.resolve_addr(config.address),
|
|
244
|
+
oracle = this.account.manager.oracle;
|
|
245
|
+
|
|
246
|
+
for (let i=0; i< config.identifiers.length; i++){
|
|
247
|
+
let id = config.identifiers[i]
|
|
248
|
+
|
|
249
|
+
let conf = await oracle.read(`${oracle.manager.path}/${addr}/${id}`, {config: true})
|
|
250
|
+
|
|
251
|
+
await this.execute({
|
|
252
|
+
type: 'assignment',
|
|
253
|
+
identifier: id,
|
|
254
|
+
value: {
|
|
255
|
+
type: 'address',
|
|
256
|
+
value: conf.path
|
|
257
|
+
}
|
|
258
|
+
}, {chain})
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
235
262
|
callable = async (name) => {
|
|
236
263
|
let object = this.objects[name];
|
|
237
264
|
|
|
@@ -242,24 +269,32 @@ class Callable extends Vm_utils {
|
|
|
242
269
|
this.objects[name] = config;
|
|
243
270
|
};
|
|
244
271
|
|
|
245
|
-
native_components = async (config, chain) => {
|
|
272
|
+
native_components = async (config, {chain, object}) => {
|
|
246
273
|
let props = await this.execute(config.props, { chain, cloth: true });
|
|
247
274
|
let children = new Array();
|
|
248
275
|
for (let c = 0; c < config.children.length; c++) {
|
|
249
276
|
let child = config.children[c];
|
|
250
277
|
|
|
251
|
-
let res = await this.execute(child, { chain, cloth: true });
|
|
252
|
-
children.push(await res.literal());
|
|
278
|
+
let res = await this.execute(child, { chain, cloth: true, object });
|
|
279
|
+
children.push(await res.literal({adm:true}));
|
|
253
280
|
}
|
|
254
281
|
|
|
255
282
|
let obj = {
|
|
256
283
|
name: config.name,
|
|
257
|
-
props: await props.literal(),
|
|
284
|
+
props: await props.literal({adm:true}),
|
|
258
285
|
children,
|
|
286
|
+
_id: props.config._id,
|
|
287
|
+
path: props.path
|
|
259
288
|
};
|
|
260
289
|
|
|
261
|
-
|
|
290
|
+
let result = await this.parse_aircode(obj, {config, chain})
|
|
291
|
+
|
|
292
|
+
return result;
|
|
262
293
|
};
|
|
294
|
+
|
|
295
|
+
rerender = async(object)=>{
|
|
296
|
+
|
|
297
|
+
}
|
|
263
298
|
}
|
|
264
299
|
|
|
265
300
|
export default Callable;
|