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
@@ -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 res = await this.account.compiler.to_sequence(
14
- JSON.stringify(result),
15
- config.location.split("/").slice(2).join("/")
16
- )[0].body[0];
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
- resolve_address = async (path, chain) => {
25
- let oracle = this.account.manager.oracle,
26
- fs = oracle.fs;
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 (typeof path !== "string") {
29
- return path;
34
+ if (['void', 'boolean'].includes(config.type)){
35
+ let res = await this.statics(config)
36
+ return res;
30
37
  }
31
38
 
32
- if (path == "g") throw new Error();
33
- let conf = await fs.read(`${path}/.config`),
34
- value;
35
- if (!conf.current) {
36
- value = await fs.read(`${path}/${conf.index - 1}`);
37
- value = JSON.parse(value.content);
38
- } else value = await fs.read(`${path}/${conf.current}`);
39
- value.path = path;
40
-
41
- return value;
42
- };
43
-
44
- instantiate = async (config, { chain, hash, pure }) => {
45
- let instance_chain = await chain.chain(
46
- config.type === "void" ? config.value : config.location
47
- );
48
- let uid = this.gen_uid();
49
-
50
- if (config.type === "twain") {
51
- if (!pure) {
52
- for (let p in config.value) {
53
- let pair = config.value[p];
54
-
55
- pair[0] = (await this.execute(pair[0], { chain })).value;
56
- pair[1] = (await this.execute(pair[1], { chain })).value;
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
- config.value = JSON.stringify(config.value);
61
- } else if (config.type === "array") {
62
- if (!pure) {
63
- for (let i = 0; i < config.value.length; i++) {
64
- let item = config.value[i];
65
- config.value[i] = (await this.execute(item, { chain })).value;
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
- config.value = JSON.stringify(config.value);
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
- let res = await instance_chain.write(
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
- operate_result = async (value, call_config, chain) => {
79
- let result;
80
- if (value && value.error) {
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
- object_identifier = async (call_config, chain) => {
91
- let { identifier } = call_config,
92
- result,
93
- oracle = this.account.manager.oracle;
94
- let conf = await oracle.fs.read(`${identifier.object}/.config`);
95
- let obj = await oracle.fs.read(`${identifier.object}/${conf.current}`);
96
-
97
- let res = await this.cloth_content({ ...obj, path: identifier.object });
98
- let classifier = await res.get("__classifier__");
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
- return result;
130
- };
131
-
132
- execute_call = async (call_config, { chain, obj }) => {
133
- let { identifier, arguments: args } = call_config,
134
- result;
135
-
136
- if (typeof identifier !== "string") {
137
- if (identifier.object) {
138
- result = await this.object_identifier(call_config, chain);
139
- } else {
140
- let conf = await this.read_config(identifier.value);
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
- result = await this.execute(conf, { call_config, chain });
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 (identifier.includes("/")) {
150
- let oracle = this.account.manager.oracle;
151
- let i_chain = identifier.startsWith(this.account.manager.path)
152
- ? { path: identifier }
153
- : await chain.chain(identifier);
154
- let conf = await oracle.fs.read(`${i_chain.path}/.config`);
155
-
156
- if (conf.sibling) {
157
- let config = await oracle.fs.read(conf.sibling);
158
-
159
- if (config.content.type === "address") {
160
- if (config.content.object) {
161
- result = await this.object_identifier(
162
- { ...call_config, identifier: config.content },
163
- chain
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
- if (this.datatypes.includes(identifier)) {
196
- } else {
197
- let { callable, config } = await this.callable(identifier);
198
- let data = {};
199
-
200
- for (let a = 0; a < args.length; a++) {
201
- let param;
202
- let arg = args[a];
203
- if (arg.identifier) {
204
- } else {
205
- param = config.parameters[arg.position];
206
- if (!param) {
207
- let lst_param = config.parameters.slice(-1)[0];
208
- if (lst_param.spread) param = lst_param;
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
- let res = await this.execute(arg, { chain, cloth: true });
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
- result = await callable(data, { vm: this, config, chain });
223
- if (["Twain", "exit", "render"].includes(identifier)) {
224
- } else
225
- result = await this.parse_aircode(result, {
226
- config: call_config,
227
- chain,
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
- return obj;
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;