godprotocol 1.1.32 → 1.2.1

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 +287 -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/Datatypes/bool.js CHANGED
@@ -1,13 +1,16 @@
1
- import Storage from "./functions/storage";
1
+ import Storage from "./functions/storage.js";
2
2
 
3
3
  class Bool extends Storage {
4
- constructor(payload, account) {
5
- super(payload.config, account);
4
+ constructor(config, account) {
5
+ super(config, account);
6
6
 
7
- this.instance_object = payload.value;
8
- this.value = JSON.parse(payload.value.value)
7
+ this.config = config
9
8
  this.type = 'boolean'
10
9
  }
10
+
11
+ literal = ()=>{
12
+ return JSON.parse(this.config.value)
13
+ }
11
14
  }
12
15
 
13
16
  export default Bool;
@@ -1,4 +1,4 @@
1
- import Storage from "./functions/storage";
1
+ import Storage from "./functions/storage.js";
2
2
 
3
3
  class Callable extends Storage {
4
4
  constructor(payload, account) {
package/Datatypes/cls.js CHANGED
@@ -1,40 +1,209 @@
1
- import Storage from "./functions/storage";
1
+ import { generate_random_string } from "generalised-datastore/utils/functions.js";
2
+ import Storage from "godprotocol/Datatypes/functions/storage.js";
2
3
 
3
4
  class Cls extends Storage{
4
- constructor(payload, account){
5
- super(payload.config, account)
5
+ constructor(config, account){
6
+ super(account)
6
7
 
7
- this.value = payload.value;
8
+ this.account = account
9
+ this.config = config;
8
10
  this.type = 'class'
11
+
12
+ this.lits = ['listen', 'emit']
13
+
14
+ this.methods = {
15
+ ...this.methods,
16
+ 'get_instance': {args: [['query', 'twain']], ret: ['object', 'instance | void']}
17
+ }
9
18
  }
10
19
 
11
- initiate = async({chain, class_chain, ass_chain})=>{
12
- let config = this.value
13
- let conf = this.config.content;
14
- let vm = this.account.vm;
20
+ get_instance = async(query, is_obj)=>{
21
+ let account = this.account, res;
22
+
23
+ if (is_obj === true){
24
+ console.log(query)
25
+ res = query
26
+ } else {
27
+ let folder = await account.manager.ds.folder(`${this.config.address}/instances`, {account: account.physical_address})
28
+ res = await folder.readone(await query.literal())
29
+ }
30
+
31
+ // console.log(query, folder.address)
32
+ if(!res){
33
+ return
34
+
35
+ }
36
+
37
+ console.log(query)
38
+
39
+ let ponse = await (await account.manager.ds.folder(res.location)).write(res, {replace: true})
40
+ console.log(ponse)
15
41
 
16
- let obj = {__classifier__: config.identifier, __class_config__: this.config.path}
42
+ for (let prop in res.properties){
43
+ let value = res.properties[prop]
44
+ let spli = account.vm._split_datapath(value)
45
+ let raw = await account.manager.ds.folder(spli[0], {account: account.physical_address})
46
+ raw = await raw.readone({_id: spli[1]})
47
+
48
+ if (!raw) continue
17
49
 
18
- let storage_chain = await chain.chain(config.location)
19
- let addr = await storage_chain.write(obj)
50
+ // console.log(raw)
51
+
52
+ if (raw.type === 'array'){
53
+ await (await account.vm.cloth_content(raw)).retrieve(raw.items)
54
+ } else if (raw.type === 'twain'){
55
+ await (await account.vm.cloth_content(raw)).retrieve(raw.entries)
56
+ } else {
57
+ await (await account.manager.ds.folder(raw.location)).write(raw, {replace: true})
58
+ }
59
+ }
60
+ return {
61
+ type: 'address',
62
+ _id: res._id,
63
+ value: res.location,
64
+ }
65
+ }
20
66
 
21
- class_chain = await storage_chain.chain(config.identifier)
22
- let ths = {object: addr, type: 'instance'}
23
- await class_chain.write(ths)
24
- console.log(obj, config)
67
+ get_ = async(name)=>{
25
68
 
26
- if (conf.methods.__init__){
27
- console.log(conf.methods)
69
+ }
70
+
71
+ run_init = async ({ins, args, vm, thread})=>{
72
+ let init = this.config.methods.__init__
28
73
 
29
- await vm.execute({
30
- type:'call',
31
- identifier: `${config.identifier}/__init__`,
32
- arguments: config.arguments,
33
- object: addr,
34
- }, {chain, ass_chain})
74
+ if (!init) return;
35
75
 
76
+ init = init.split('/')
77
+ let func = await vm.cloth({
78
+ type: 'function',
79
+ address: init.slice(0,-1).join('/'),
80
+ _id: init.slice(-1)[0]
81
+ })
82
+
83
+ await func.invoke([...args], {instance_:ins, thread})
84
+ }
85
+
86
+ handle_id = async(args)=>{
87
+ let _id, propaddr = this.config.class_.properties.__id_prop__, vm = this.account.vm
88
+ if (propaddr){
89
+ let spli = vm._split_datapath(propaddr)
90
+ let prop = await vm.cloth({
91
+ type: 'address',
92
+ value: spli[0],
93
+ _id: spli[1]
94
+ })
95
+
96
+ let lit = await prop.literal()
97
+
98
+ let arg = args.find(a=>a.identifier === lit)
99
+ let init = this.config.methods['__init__']
100
+ if (lit && init && !arg){
101
+ let spli = vm._split_datapath(init), indx;
102
+
103
+ init = await vm.cloth({address: spli[0], _id: spli[1], type: 'function'}, {just_content: true});
104
+
105
+ for (let p=0; p < init.parameters.length; p++){
106
+ let param = init.parameters[p].split('/')
107
+ let name = param.slice(-3)[0]
108
+
109
+ if(name === lit){
110
+ indx = p
111
+ break
112
+ }
113
+ }
114
+ arg = args[indx]
115
+ }
116
+ if (arg){
117
+ _id = await(await vm.cloth(arg)).literal()
118
+ _id = await vm.hash(_id)
119
+ }
36
120
  }
37
- return ths
121
+ if (!_id)
122
+ _id = generate_random_string(16, 'alnum')
123
+
124
+ return _id;
125
+ }
126
+
127
+ invoke = async(args, options)=>{
128
+ let {thread, call_config} = options
129
+
130
+ let _id = await this.handle_id(args);
131
+ let location = `${this.config.address}/instances`;
132
+
133
+ let folder = await this.account.manager.ds.folder(location)
134
+
135
+ let obj = {
136
+ type: 'instance',
137
+ name: this.config.name,
138
+ cls: this.config.address,
139
+ cls_id: this.config._id,
140
+ location,
141
+ _id,
142
+ properties: {},
143
+ methods: {},
144
+ inherited: []
145
+ }
146
+
147
+ let inherited = new Array(), lists = new Array(), benches = new Object(), {vm} = this.account;
148
+
149
+ await this.account.vm.base_classes(obj, this.config, {inherited, chain: this.account.chain, lists, benches})
150
+
151
+ await this.account.vm.spread_properties(obj, this.config, {lists, benches})
152
+
153
+ let init = this.config.methods.__init__
154
+ if (init){
155
+ let res = await folder.write(obj)
156
+ obj._id = res._id
157
+ obj.created = res.created
158
+
159
+ init = init.split('/')
160
+ let func = await vm.cloth({
161
+ type: 'function',
162
+ address: init.slice(0,-1).join('/'),
163
+ _id: init.slice(-1)[0]
164
+ })
165
+
166
+ await func.invoke([...args], {list: lists, instance_:{
167
+ type: 'address',
168
+ value: folder.address,
169
+ _id: obj._id
170
+ }})
171
+ }
172
+
173
+ let thread_id = await vm.account.manager.load(lists, vm.account, {
174
+ on_pointer: async (pointer, result)=>{
175
+ if (Object.values(benches).includes(pointer)){
176
+ for (let b in benches){
177
+ if (benches[b] === pointer){
178
+ obj.properties[b] = `${result.value}/${result._id}`
179
+
180
+ await folder.write(obj, {replace: true})
181
+ break
182
+ }
183
+ }
184
+ }
185
+ },
186
+ callback: async (result, thrd)=>{
187
+ let obj_addr = {
188
+ type:'address',
189
+ value: obj.location,
190
+ _id: obj._id
191
+ }
192
+ thread.results[thread.pointer-1] = obj_addr
193
+ },
194
+ spawn: thread._id,
195
+ pointer: thread.pointer
196
+ })
197
+ if (thread)
198
+ vm.envs[thread_id] = vm.envs[thread._id]
199
+ }
200
+
201
+ literal = (options={})=>{
202
+ return options.adm? this.config: `[${this.type} ${this.config.name}]`
203
+ }
204
+
205
+ sync = async()=>{
206
+ return this
38
207
  }
39
208
  }
40
209
 
package/Datatypes/conf.js CHANGED
@@ -1,5 +1,5 @@
1
- import Arr from "./arr";
2
- import Storage from "./functions/storage";
1
+ import Arr from "./arr.js";
2
+ import Storage from "./functions/storage.js";
3
3
 
4
4
  class Conf extends Storage{
5
5
  constructor(object, account){
@@ -0,0 +1,25 @@
1
+ import Storage from "godprotocol/Datatypes/functions/storage.js";
2
+
3
+ class Err extends Storage{
4
+ constructor(config, account){
5
+ super(account)
6
+
7
+ this.account = account;
8
+ this.config = config
9
+ this.type = 'error'
10
+ }
11
+
12
+ get_type = async ()=>{
13
+ return this.config.value.type
14
+ }
15
+
16
+ get_message = async ()=>{
17
+ return this.config.value.message
18
+ }
19
+
20
+ literal = async()=>{
21
+ return `[Error ${this.config.value.type}]`
22
+ }
23
+ }
24
+
25
+ export default Err
package/Datatypes/func.js CHANGED
@@ -1,22 +1,98 @@
1
- import Datatypes from "godprotocol/Objects/Datatypes";
1
+ import { copy_object } from "generalised-datastore/utils/functions.js";
2
+ import Storage from "godprotocol/Datatypes/functions/storage.js";
2
3
 
3
- class Func extends Datatypes{
4
- constructor(payload, account){
5
- super()
4
+ class Func extends Storage {
5
+ constructor(config, account) {
6
+ super(account);
6
7
 
7
- this.account = account
8
- this.value = payload;
9
- this.type = 'function'
8
+ this.config = config;
9
+ this.type = "function";
10
10
  }
11
11
 
12
- literal = ()=>{
13
- return `[${this.value.value || this.value.name}]`
12
+ invoke = async (args, options) => {
13
+ let {no_wait, list, thread, instance_, callback} = options || {}
14
+ let {vm} = this.account
15
+ let config = copy_object(this.config);
16
+ for (let p =0; p< config.parameters.length; p++){
17
+ config.parameters[p] = await vm.read_config(config.parameters[p])
18
+ }
19
+
20
+ for (let a=0; a< args.length; a++){
21
+ let arg = args[a], param;
22
+
23
+ if (arg.identifier){
24
+ param = config.parameters.find(p=>p.identifier === arg.identifier)
25
+ }
26
+ if (!param){
27
+ param = config.parameters[a]
28
+ if (!param) {
29
+ continue;
30
+ }
31
+ }
32
+
33
+
34
+ param.value = {
35
+ type:'reference',
36
+ location: arg.value,
37
+ _id: arg._id
38
+ }
39
+ if (arg.object){
40
+ param.value.object = arg.object
41
+ }
42
+ }
43
+
44
+ if (instance_){
45
+ config.parameters.push({
46
+ type: 'assignment',
47
+ identifier: 'this',
48
+ value: {
49
+ type: 'reference',
50
+ location: instance_.value,
51
+ _id: instance_._id
52
+ }
53
+ })
54
+ }
55
+
56
+ let nodes = await this.account.vm.nodelist(config, {call: true, list})
57
+
58
+ if (list) return nodes
59
+
60
+ let thread_id = await vm.account.manager.load(nodes, vm.account, {
61
+ callback,
62
+ spawn: no_wait ? null : thread._id,
63
+ addr: this.config.address,
64
+ pointer: !no_wait && thread.pointer
65
+ })
66
+ if (thread){
67
+ vm.envs[thread_id] = vm.envs[thread._id]
68
+ }
69
+ };
70
+
71
+ set_ = async(prop, value)=>{
72
+ let prop_obj = await this.account.vm.cloth(prop)
73
+ let prop_val = await prop_obj.literal()
74
+
75
+ let addr = `${this.config.address}/${prop_val}`
76
+ let res = await (await this.account.manager.ds.folder(addr)).write(value, {replace: true})
77
+
78
+ return addr;
14
79
  }
15
80
 
16
- sync = async()=>{
17
- return this
81
+ get_ = async(prop)=>{
82
+ let res = await (await this.account.manager.ds.folder(`${this.config.address}/${prop}`)).readone()
83
+
84
+ return res;
18
85
  }
19
- }
20
86
 
87
+ literal = (options = {}) => {
88
+ return options.adm
89
+ ? this.config
90
+ : `[${this.type} ${this.config.value || this.config.name}]`;
91
+ };
92
+
93
+ sync = async () => {
94
+ return this;
95
+ };
96
+ }
21
97
 
22
- export default Func
98
+ export default Func;