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.
Files changed (71) hide show
  1. package/Datatypes/arr.js +559 -254
  2. package/Datatypes/bool.js +8 -5
  3. package/Datatypes/callable.js +1 -1
  4. package/Datatypes/cls.js +193 -24
  5. package/Datatypes/conf.js +2 -2
  6. package/Datatypes/err.js +25 -0
  7. package/Datatypes/func.js +89 -13
  8. package/Datatypes/functions/storage.js +572 -12
  9. package/Datatypes/functions/wallet.js +49 -0
  10. package/Datatypes/instance.js +87 -122
  11. package/Datatypes/num.js +192 -153
  12. package/Datatypes/str.js +188 -122
  13. package/Datatypes/twa.js +346 -71
  14. package/Datatypes/voi.js +9 -4
  15. package/Index.js +1 -1
  16. package/Instances/account.js +0 -0
  17. package/Instances/event.js +0 -0
  18. package/Instances/fold.js +103 -0
  19. package/Instances/folder_queries.js +46 -0
  20. package/Instances/response.js +31 -0
  21. package/Objects/Account.js +160 -110
  22. package/Objects/Blockweb.js +6 -11
  23. package/Objects/Callable.js +223 -188
  24. package/Objects/Chain.js +127 -142
  25. package/Objects/Datatypes.js +114 -588
  26. package/Objects/Manager.js +349 -39
  27. package/Objects/Oracle.js +283 -210
  28. package/Objects/Repository.js +12 -33
  29. package/Objects/Trinity.js +9 -7
  30. package/Objects/Utils.js +8 -8
  31. package/Objects/Virtual_machine.js +320 -320
  32. package/README.md +0 -0
  33. package/callables/functions/assert.js +10 -0
  34. package/callables/functions/display.js +2 -3
  35. package/callables/functions/env.js +5 -0
  36. package/callables/functions/event.js +14 -0
  37. package/callables/functions/exit.js +3 -2
  38. package/callables/functions/folder.js +15 -0
  39. package/callables/functions/get_uid.js +6 -0
  40. package/callables/functions/hash.js +7 -0
  41. package/callables/functions/import_.js +62 -0
  42. package/callables/functions/local.js +9 -0
  43. package/callables/functions/net.js +33 -18
  44. package/callables/functions/parse.js +35 -0
  45. package/callables/functions/query.js +12 -0
  46. package/callables/functions/render.js +9 -13
  47. package/callables/functions/servers.js +10 -0
  48. package/callables/functions/spawn.js +7 -0
  49. package/callables/functions/store.js +75 -0
  50. package/callables/functions/super_.js +24 -0
  51. package/callables/functions/typeof.js +32 -0
  52. package/callables/functions/wait.js +9 -0
  53. package/callables/register.js +193 -8
  54. package/html/create.js +110 -0
  55. package/html/index.js +114 -0
  56. package/html/load.js +165 -0
  57. package/html/parse.js +171 -0
  58. package/html/run.js +151 -0
  59. package/html/util.js +5 -0
  60. package/package.json +5 -3
  61. package/repos/fs.js +114 -0
  62. package/repos/github.js +73 -0
  63. package/repos/ram.js +47 -0
  64. package/utils/create_server.js +66 -26
  65. package/utils/hash.js +3 -2
  66. package/utils/ops.js +2 -0
  67. package/utils/oracle_handlers.js +7 -0
  68. package/utils/services.js +18 -51
  69. package/utils/socket_server.js +36 -0
  70. package/utils/vm_utils.js +271 -59
  71. 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 Callable from "../Datatypes/callable";
3
- import Num from "../Datatypes/num";
4
- import Str from "../Datatypes/str";
5
- import Twa from "../Datatypes/twa";
6
- import Ins from "../Datatypes/instance";
7
- import Voi from "../Datatypes/voi";
8
- import Bool from "../Datatypes/bool";
9
- import Instance from "../Datatypes/instance";
10
- import Func from "../Datatypes/func";
11
- import Cls from "../Datatypes/cls";
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.literal_methods = {
16
- number: ['add','sub','div','mul', 'exp', 'floordiv', 'eq', "ne", "lt", 'gt', 'gte', 'lte', 'neg', 'abs', 'and', 'or', 'xor', 'lshift', 'rshift', 'invert'].map(i=>`__${i}__`).concat(['to_int', 'to_float', 'to_string', 'sqrt', 'log', 'sin', 'sinh', 'tanh', 'cosh', 'atanh', 'acosh', 'asinh', 'atan', 'acos', 'asin', 'cos', 'tan', 'round', 'factorial', 'ceil', 'floor', 'is_prime', 'is_even', 'is_odd', 'is_perfect_square', 'to_degrees', 'to_radians']),
17
- string: ['upper','lower','title','slice', 'concat', 'find', 'includes', 'index', 'trim', 'split', 'padstart', 'padend', 'repeat', 'replace', 'startswith', 'endswith', 'count', 'length', 'reverse', 'is_numeric', 'is_empty', 'is_blank', 'charcode'],
18
- array:[
19
- 'push', 'pop', 'length', 'run', 'copy', 'deepcopy', 'extend', 'slice', 'index', 'includes', 'replace', 'map', 'find', 'filter', 'padstart', 'padend', 'clear', 'to_string', 'reverse', 'repeat', 'join', 'splice'
20
- ],
21
- twain: [
22
- 'entries', 'get', 'set', 'keys', 'clear', 'is_empty', 'values', 'copy', 'deepcopy', 'remove'
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
- this.datatypes = ['string', 'number', 'void', 'boolean', 'array', 'twain']
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
- gen_uid = ()=>{
30
- return `_${Math.random().toString().replace('.', '')}_${Date.now()}`
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
- parse_dynamic = async(literal, options={})=>{
34
- let {chain, config} = options;
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(JSON.stringify(literal), chain.physical_address)
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
- cloth_object = async addr=>{
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 instanceof Instance)return content;
261
+ if (!content) return content;
63
262
 
64
- switch(content.type){
65
- case 'number':
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 'string':
69
- obj = new Str(content, this.account)
267
+ case "string":
268
+ obj = new Str(content, this.account);
70
269
  break;
71
- case 'boolean':
72
- obj = new Bool(content, this.account)
270
+ case "boolean":
271
+ obj = new Bool(content, this.account);
73
272
  break;
74
- case 'void':
75
- obj = new Voi(content, this.account)
273
+ case "void":
274
+ obj = new Voi(content, this.account);
76
275
  break;
77
- case 'array':
78
- obj = new Arr(content, this.account)
79
- break
80
- case 'twain':
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 'instance':
84
- obj = new Instance(content, this.account)
288
+ case 'folder':
289
+ obj = new Fold(content, this.account)
85
290
  break;
86
- case 'function':
87
- obj = new Func(content, this.account)
291
+ case 'folder_response':
292
+ obj = new Res(content, this.account)
88
293
  break;
89
- case 'class':
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
- if (content.type === 'address'){
94
- obj = new Func(content, this.account)
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
 
@@ -1,6 +0,0 @@
1
- const assign = async (args, vm, options) => {
2
- console.log(args);
3
- process.exit();
4
- };
5
-
6
- export default assign;