godprotocol 1.1.32 → 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 +241 -137
  71. package/callables/functions/assign.js +0 -6
package/utils/vm_utils.js CHANGED
@@ -1,142 +1,119 @@
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";
12
- import { ops } from "./ops";
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";
13
15
 
14
16
  class Vm_utils {
15
17
  constructor() {
16
18
  this.ops = ops;
17
- this.literal_methods = {
18
- number: [
19
- "add",
20
- "sub",
21
- "div",
22
- "mul",
23
- "exp",
24
- "floordiv",
25
- "eq",
26
- "ne",
27
- "lt",
28
- "gt",
29
- "gte",
30
- "lte",
31
- "neg",
32
- "abs",
33
- "and",
34
- "or",
35
- "xor",
36
- "lshift",
37
- "rshift",
38
- "invert",
39
- ]
40
- .map((i) => `__${i}__`)
41
- .concat([
42
- "to_int",
43
- "to_float",
44
- "to_string",
45
- "sqrt",
46
- "log",
47
- "sin",
48
- "sinh",
49
- "tanh",
50
- "cosh",
51
- "atanh",
52
- "acosh",
53
- "asinh",
54
- "atan",
55
- "acos",
56
- "asin",
57
- "cos",
58
- "tan",
59
- "round",
60
- "factorial",
61
- "ceil",
62
- "floor",
63
- "is_prime",
64
- "is_even",
65
- "is_odd",
66
- "is_perfect_square",
67
- "to_degrees",
68
- "to_radians",
69
- ]),
70
- string: [
71
- "upper",
72
- "lower",
73
- "title",
74
- "slice",
75
- "concat",
76
- "find",
77
- "includes",
78
- "index",
79
- "trim",
80
- "split",
81
- "padstart",
82
- "padend",
83
- "repeat",
84
- "replace",
85
- "startswith",
86
- "endswith",
87
- "count",
88
- "length",
89
- "reverse",
90
- "is_numeric",
91
- "is_empty",
92
- "is_blank",
93
- "charcode",
94
- ],
95
- array: [
96
- "push",
97
- "pop",
98
- "length",
99
- "run",
100
- "copy",
101
- "deepcopy",
102
- "extend",
103
- "slice",
104
- "index",
105
- "includes",
106
- "replace",
107
- "map",
108
- "find",
109
- "filter",
110
- "padstart",
111
- "padend",
112
- "clear",
113
- "to_string",
114
- "reverse",
115
- "repeat",
116
- "join",
117
- "splice",
118
- ],
119
- twain: [
120
- "entries",
121
- "get",
122
- "set",
123
- "keys",
124
- "clear",
125
- "is_empty",
126
- "values",
127
- "copy",
128
- "deepcopy",
129
- "remove",
130
- ],
131
- };
132
-
19
+
133
20
  this.datatypes = ["string", "number", "void", "boolean", "array", "twain"];
134
21
  }
135
22
 
136
- gen_uid = () => {
137
- return `_${Math.random().toString().replace(".", "")}_${Date.now()}`;
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)
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()}`;
138
56
  };
139
57
 
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
+ }
68
+ }
69
+
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
+ }
83
+ }
84
+
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
+
140
117
  parse_dynamic = async (literal, options = {}) => {
141
118
  let { chain, config } = options;
142
119
 
@@ -152,6 +129,37 @@ class Vm_utils {
152
129
  return address;
153
130
  };
154
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)
161
+ }
162
+
155
163
  resolve_addr = (addr) => {
156
164
  if (!addr) return addr;
157
165
 
@@ -162,13 +170,96 @@ class Vm_utils {
162
170
  return addr;
163
171
  };
164
172
 
165
- cloth_object = async (addr) => {};
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'})
185
+ }
186
+
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
+ }
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
256
+ }
166
257
 
167
258
  cloth_content = async (content, options) => {
168
259
  let obj;
169
260
 
170
- if (content instanceof Instance) return content;
171
-
261
+ if (!content) return content;
262
+
172
263
  switch (content.type) {
173
264
  case "number":
174
265
  obj = new Num(content, this.account);
@@ -194,18 +285,31 @@ class Vm_utils {
194
285
  case "function":
195
286
  obj = new Func(content, this.account);
196
287
  break;
288
+ case 'folder':
289
+ obj = new Fold(content, this.account)
290
+ break;
291
+ case 'folder_response':
292
+ obj = new Res(content, this.account)
293
+ break;
197
294
  case "class":
198
295
  obj = new Cls(content, this.account);
199
296
  break;
297
+ case 'error':
298
+ obj = new Err(content, this.account)
299
+ break;
200
300
  default:
201
- if (content.type === "address") {
202
- obj = new Func(content, this.account);
203
- } else obj = content;
204
- // console.log(content, 'uh')
301
+ obj = await this.cloth(content)
302
+ break;
205
303
  }
206
304
 
207
305
  return await obj.sync(options);
208
306
  };
307
+
308
+ hash = async(value, alg)=>{
309
+ if (typeof value !== 'string') value = JSON.stringify(value)
310
+
311
+ return hash(value, alg)
312
+ }
209
313
  }
210
314
 
211
315
  export default Vm_utils;
@@ -1,6 +0,0 @@
1
- const assign = async (args, vm, options) => {
2
- console.log(args);
3
- process.exit();
4
- };
5
-
6
- export default assign;