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/Datatypes/twa.js
CHANGED
|
@@ -1,88 +1,363 @@
|
|
|
1
|
-
import Storage from "./functions/storage";
|
|
1
|
+
import Storage from "./functions/storage.js";
|
|
2
2
|
|
|
3
3
|
class Twa extends Storage {
|
|
4
|
-
constructor(config,
|
|
5
|
-
super(
|
|
4
|
+
constructor(config, account) {
|
|
5
|
+
super(account);
|
|
6
6
|
|
|
7
7
|
this.config = config
|
|
8
8
|
this.type = 'twain'
|
|
9
|
+
|
|
10
|
+
this.methods = {
|
|
11
|
+
...this.methods,
|
|
12
|
+
|
|
13
|
+
extend: {args: [['obj', 'twain']], ret: ['thisobj', 'twain']},
|
|
14
|
+
zip: {args: [['prop', 'array'], ['value', 'array']], ret: ['obj', 'twain']},
|
|
15
|
+
unzip: {args: [], ret: ['array_pair', 'array[[], []]']},
|
|
16
|
+
copy: {args: [], ret: ['obj', 'twain']},
|
|
17
|
+
clear: {args: [], ret: ['obj', 'twain']},
|
|
18
|
+
is_empty: {args: [], ret: ['yes', 'boolean']},
|
|
19
|
+
has: {args: [['prop', 'object']], ret: ['yes', 'boolean']},
|
|
20
|
+
unset: {args: [['prop', 'object']], ret: ['yes', 'boolean']},
|
|
21
|
+
keys: {args: [], ret: ['keys', 'array']},
|
|
22
|
+
values: {args: [], ret: ['values', 'array']},
|
|
23
|
+
entries: {args: [], ret: ['[[key, value],...pair]', 'array']},
|
|
24
|
+
get: {args: [['prop', 'string']], ret: ['value', 'object|void']},
|
|
25
|
+
set: {args: [['prop', 'string'], ['value', 'object']], ret: ['done', 'void']},
|
|
26
|
+
}
|
|
9
27
|
}
|
|
10
28
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
29
|
+
__or__ = async(other)=>{
|
|
30
|
+
if (!this.config.value){
|
|
31
|
+
return await other.to_address()
|
|
32
|
+
}
|
|
33
|
+
return await this.to_address()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
__and__ = async(other)=>{
|
|
37
|
+
if (!this.config.value){
|
|
38
|
+
return await this.to_address()
|
|
39
|
+
}
|
|
40
|
+
return await other.to_address()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get_ = async(prop)=>{
|
|
44
|
+
let key = await this.key(prop.literal? await prop.literal(): prop)
|
|
45
|
+
|
|
46
|
+
return await (await this.chain()).get({key})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
set_ = async(prop, args)=>{
|
|
50
|
+
let value = args[1]
|
|
51
|
+
let key = await this.key(await prop.literal())
|
|
52
|
+
prop = await prop.to_address();
|
|
53
|
+
value = await value.to_address()
|
|
54
|
+
let chain = await this.chain()
|
|
55
|
+
await chain.set({twa: this.config, prop, value, key})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
retrieve = async(entries)=>{
|
|
59
|
+
delete this.config.entries
|
|
60
|
+
|
|
61
|
+
let ds = this.account.manager.ds
|
|
62
|
+
await (await ds.folder(this.config.location)).write(this.config, {replace: true})
|
|
46
63
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
for (let i=0; i< entries.length; i++){
|
|
65
|
+
let entry = entries[i]
|
|
66
|
+
|
|
67
|
+
let prop = await (await ds.folder(entry.prop.value, {account: this.account.physical_address})).readone({_id: entry.prop._id})
|
|
68
|
+
let val;
|
|
69
|
+
if (entry.value.type === 'function'){
|
|
70
|
+
let res = await this.account.vm.cloth(entry.value, {just_content: true})
|
|
71
|
+
|
|
72
|
+
if (!res){
|
|
73
|
+
await this.account.reload({address: entry.value.module})
|
|
53
74
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
75
|
+
} else val = await (await ds.folder(entry.value.value, {account: this.account.physical_address})).readone({_id: entry.value._id})
|
|
76
|
+
|
|
77
|
+
if(!val && entry.value.type !== 'function' && entry.value.value.endsWith('/instances')){
|
|
78
|
+
let adr = entry.value.value.split('/').slice(0,-1).join('/')
|
|
79
|
+
val = await (await ds.folder(adr, {account: this.account.physical_address})).readone({_id: entry.value._id})
|
|
80
|
+
}
|
|
81
|
+
if (val){
|
|
82
|
+
if (['array', 'twain'].includes(val.type)){
|
|
83
|
+
await (await this.account.vm.cloth_content(val)).retrieve(val.items || val.entries)
|
|
84
|
+
} else if(val.type === 'instance'){
|
|
85
|
+
await this.account.vm.retrieve(val)
|
|
86
|
+
} else if (val.type === 'function'){
|
|
87
|
+
} else {
|
|
88
|
+
await (await ds.folder(entry.value.value)).write(val, {replace: true})
|
|
60
89
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
90
|
+
}
|
|
91
|
+
prop && await (await ds.folder(entry.prop.value)).write(prop, {replace: true})
|
|
92
|
+
|
|
93
|
+
let pair_folder = await ds.folder(entry.location)
|
|
94
|
+
await (await pair_folder.folder('__prop__')).write(entry.prop, {replace: true})
|
|
95
|
+
delete entry.prop
|
|
96
|
+
delete entry.location
|
|
97
|
+
|
|
98
|
+
await pair_folder.write(entry, {replace: true})
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
store = async({store, thread})=>{
|
|
103
|
+
let ds = this.account.manager.ds, vm = this.account.vm;
|
|
104
|
+
|
|
105
|
+
let addr = this.config.value;
|
|
106
|
+
let data = {...this.config, entries: []}
|
|
107
|
+
while(addr){
|
|
108
|
+
let o = this._split_datapath(addr)
|
|
109
|
+
let val = await ds.folder(o[0])
|
|
110
|
+
let pair_value = await val.readone({_id: o[1]})
|
|
111
|
+
|
|
112
|
+
let datum = await store({object: await vm.cloth(pair_value.value)}, {vm, thread})
|
|
113
|
+
if (datum && datum.config){
|
|
114
|
+
process.exit()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let prop = await this.get_prop(val)
|
|
118
|
+
let prop_obj = await vm.cloth(prop)
|
|
119
|
+
await store({object: prop_obj}, {vm, thread})
|
|
120
|
+
|
|
121
|
+
pair_value.prop = prop;
|
|
122
|
+
pair_value.location = o[0]
|
|
123
|
+
|
|
124
|
+
data.entries.push(pair_value)
|
|
125
|
+
|
|
126
|
+
addr = pair_value.prev
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return data;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
extend = async(obj)=>{
|
|
133
|
+
let {vm, manager} = this.account;
|
|
134
|
+
|
|
135
|
+
let addr = obj.config.value
|
|
136
|
+
while(addr){
|
|
137
|
+
let o = this._split_datapath(addr)
|
|
138
|
+
o = {value: o[0], _id: o[1], type: 'address'}
|
|
139
|
+
let val = await vm.cloth(o, {just_content: true})
|
|
140
|
+
|
|
141
|
+
let prop_folder = await manager.ds.folder(o.value)
|
|
142
|
+
let conf = await this.get_prop(prop_folder)
|
|
143
|
+
let prop_obj = await vm.cloth(conf)
|
|
144
|
+
|
|
145
|
+
await this.set_(prop_obj, [null, await vm.cloth_content(val.value)])
|
|
146
|
+
|
|
147
|
+
addr = val.prev
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return await this.to_address()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
zip = async(prop, args)=>{
|
|
154
|
+
let {vm} = this.account;
|
|
155
|
+
for (let i=0; i< prop.config.length; i++){
|
|
156
|
+
let item = await prop.index(i)
|
|
157
|
+
let val = await args[1].index(i)
|
|
158
|
+
await this.set_(await vm.cloth_content(item), [null, await vm.cloth_content(val)])
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return await this.to_address()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
unzip = async()=>{
|
|
165
|
+
let addr = this.config.value, vals = new Array(), props = new Array();
|
|
166
|
+
let {vm, chain, manager} = this.account;
|
|
167
|
+
|
|
168
|
+
while (addr){
|
|
169
|
+
let o = this._split_datapath(addr)
|
|
170
|
+
o = {value: o[0], _id: o[1], type: 'address'}
|
|
171
|
+
let val = await vm.cloth(o, {just_content: true})
|
|
172
|
+
|
|
173
|
+
let prop_folder = await manager.ds.folder(o.value)
|
|
174
|
+
let conf = await this.get_prop(prop_folder)
|
|
175
|
+
|
|
176
|
+
vals.push(val.value)
|
|
177
|
+
props.push(conf)
|
|
178
|
+
|
|
179
|
+
addr= val.prev
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return await vm.instantiate({
|
|
183
|
+
type: 'array',
|
|
184
|
+
value: [
|
|
185
|
+
await vm.instantiate({value: props, type:'array', location:this.spawn_address()}, {chain}),
|
|
186
|
+
await vm.instantiate({value: vals, type:'array', location:this.spawn_address()}, {chain})]
|
|
187
|
+
,
|
|
188
|
+
location: this.spawn_address()
|
|
189
|
+
}, {chain})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
copy = async()=>{
|
|
193
|
+
let addr = this.config.value, tries = new Object();
|
|
194
|
+
let {vm, chain, manager} = this.account;
|
|
195
|
+
|
|
196
|
+
while (addr){
|
|
197
|
+
let o = this._split_datapath(addr)
|
|
198
|
+
o = {value: o[0], _id: o[1], type: 'address'}
|
|
199
|
+
let val = await vm.cloth(o, {just_content: true})
|
|
200
|
+
|
|
201
|
+
let prop_folder = await manager.ds.folder(o.value)
|
|
202
|
+
let conf = await this.get_prop(prop_folder)
|
|
203
|
+
let prop_obj = await vm.cloth(conf)
|
|
204
|
+
|
|
205
|
+
let pair = [conf, val.value]
|
|
206
|
+
tries[await this.key(await prop_obj.literal())] = pair
|
|
207
|
+
|
|
208
|
+
addr= val.prev
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return await vm.instantiate({
|
|
212
|
+
type: 'twain',
|
|
213
|
+
value: tries,
|
|
214
|
+
location: this.spawn_address()
|
|
215
|
+
}, {chain})
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
clear = async()=>{
|
|
219
|
+
this.config.value = ''
|
|
220
|
+
let fold = await this._folder()
|
|
221
|
+
await fold.write(this.config, {replace: true})
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
is_empty = async()=>{
|
|
225
|
+
return !this.config.value
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
has = async(prop)=>{
|
|
229
|
+
let folder = await this._folder()
|
|
230
|
+
let child = await folder.folder(await this.key(await prop.literal()))
|
|
231
|
+
|
|
232
|
+
let v = (await child.readone())
|
|
233
|
+
|
|
234
|
+
return (v && !v.deleted) || false
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
key = async lit=>{
|
|
238
|
+
return await this.account.vm.hash(lit, 'sha1')
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
unset = async(prop)=>{
|
|
242
|
+
let key = await this.key(await prop.literal())
|
|
243
|
+
|
|
244
|
+
let chain = await this.chain()
|
|
245
|
+
|
|
246
|
+
return await chain.remove({twa: this.config, key})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
get_prop = async(folder)=>{
|
|
250
|
+
return await (await folder.folder('__prop__')).readone()
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
keys = async(func)=>{
|
|
254
|
+
let addr = this.config.value, kys = new Array();
|
|
255
|
+
let {vm, chain, manager} = this.account;
|
|
256
|
+
|
|
257
|
+
while (addr){
|
|
258
|
+
let o = this._split_datapath(addr)
|
|
259
|
+
o = {value: o[0], _id: o[1], type: 'address'}
|
|
260
|
+
let val = await vm.cloth(o, {just_content: true})
|
|
261
|
+
|
|
262
|
+
let prop_folder = await manager.ds.folder(o.value)
|
|
263
|
+
let conf = await this.get_prop(prop_folder)
|
|
264
|
+
|
|
265
|
+
kys.push(conf)
|
|
266
|
+
|
|
267
|
+
addr = val.prev
|
|
79
268
|
}
|
|
80
269
|
|
|
81
|
-
|
|
82
|
-
|
|
270
|
+
return await vm.instantiate({
|
|
271
|
+
type: 'array',
|
|
272
|
+
value: kys,
|
|
273
|
+
location: this.spawn_address()
|
|
274
|
+
}, {chain})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
values = async(func)=>{
|
|
278
|
+
let addr = this.config.value, tries = new Array();
|
|
279
|
+
let {vm, chain} = this.account;
|
|
280
|
+
|
|
281
|
+
while (addr){
|
|
282
|
+
let o = this._split_datapath(addr)
|
|
283
|
+
o = {value: o[0], _id: o[1], type: 'address'}
|
|
284
|
+
let val = await vm.cloth(o, {just_content: true})
|
|
285
|
+
|
|
286
|
+
tries.push(val.value)
|
|
287
|
+
|
|
288
|
+
addr= val.prev
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return await vm.instantiate({
|
|
292
|
+
type: 'array',
|
|
293
|
+
value: tries,
|
|
294
|
+
location: this.spawn_address()
|
|
295
|
+
}, {chain})
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
entries = async(func)=>{
|
|
299
|
+
let addr = this.config.value, tries = new Array();
|
|
300
|
+
let {vm, chain, manager} = this.account;
|
|
301
|
+
|
|
302
|
+
while (addr){
|
|
303
|
+
let o = this._split_datapath(addr)
|
|
304
|
+
o = {value: o[0], _id: o[1], type: 'address'}
|
|
305
|
+
let val = await vm.cloth(o, {just_content: true})
|
|
306
|
+
|
|
307
|
+
let prop_folder = await manager.ds.folder(o.value)
|
|
308
|
+
let conf = await (await prop_folder.folder('__prop__')).readone()
|
|
309
|
+
|
|
310
|
+
let pair = [conf, val.value]
|
|
311
|
+
pair = await vm.instantiate({
|
|
312
|
+
type: 'array',
|
|
313
|
+
value: pair,
|
|
314
|
+
location: this.spawn_address()
|
|
315
|
+
}, {chain})
|
|
316
|
+
tries.push(pair)
|
|
317
|
+
|
|
318
|
+
addr= val.prev
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return await vm.instantiate({
|
|
322
|
+
type: 'array',
|
|
323
|
+
value: tries,
|
|
324
|
+
location: this.spawn_address()
|
|
325
|
+
}, {chain})
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
literal = async(options={})=>{
|
|
329
|
+
if (this.value)return this.value;
|
|
330
|
+
|
|
331
|
+
let {vm, manager} = this.account;
|
|
332
|
+
|
|
333
|
+
this.value = {}
|
|
334
|
+
|
|
335
|
+
let addr = this.config.value, val;
|
|
336
|
+
while (addr){
|
|
337
|
+
let o = this._split_datapath(addr)
|
|
338
|
+
o = {value: o[0], _id: o[1], type: 'address'}
|
|
339
|
+
val = await vm.cloth(o, {just_content: true, })
|
|
340
|
+
let value = await vm.cloth(val.value)
|
|
341
|
+
|
|
342
|
+
let prop_folder = await manager.ds.folder(o.value)
|
|
343
|
+
let conf = await this.get_prop(prop_folder)
|
|
344
|
+
let prop = await vm.cloth(conf)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
if(!value){
|
|
348
|
+
console.log(val)
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
this.value[await prop.literal()] = await value.literal()
|
|
353
|
+
addr= val.prev
|
|
83
354
|
}
|
|
84
355
|
|
|
85
|
-
return
|
|
356
|
+
return this.value
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
sync = ()=>{
|
|
360
|
+
return this
|
|
86
361
|
}
|
|
87
362
|
}
|
|
88
363
|
|
package/Datatypes/voi.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import Storage from "./functions/storage";
|
|
1
|
+
import Storage from "./functions/storage.js";
|
|
2
2
|
|
|
3
3
|
class Voi extends Storage {
|
|
4
|
-
constructor(config,
|
|
5
|
-
super(
|
|
4
|
+
constructor(config, account) {
|
|
5
|
+
super(account);
|
|
6
6
|
|
|
7
|
-
this.
|
|
7
|
+
this.config = config
|
|
8
|
+
this.type = 'void'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
literal = ()=>{
|
|
12
|
+
return 'void'
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
|
package/Index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import store from "godprotocol/callables/functions/store.js";
|
|
2
|
+
import Storage from "godprotocol/Datatypes/functions/storage.js";
|
|
3
|
+
|
|
4
|
+
class Fold extends Storage{
|
|
5
|
+
constructor(config, account) {
|
|
6
|
+
super(account)
|
|
7
|
+
|
|
8
|
+
this.config = config
|
|
9
|
+
this.type = 'folder'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
child = async(name, opts)=>{
|
|
13
|
+
return await this.folder(name, {...opts, account: this.account.physical_address})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
_folder_ = async()=>{
|
|
17
|
+
let folder = await this.account.manager.ds.folder(this.config.value, {account: this.account.physical_address})
|
|
18
|
+
|
|
19
|
+
return folder;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get_config = async()=>{
|
|
23
|
+
let folder = await this._folder_()
|
|
24
|
+
return folder.config.config
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
total_entries = async()=>{
|
|
28
|
+
let folder = await this._folder_()
|
|
29
|
+
|
|
30
|
+
return folder.config.config.files
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
read = async(query, args, {call_config, chain})=>{
|
|
34
|
+
let ds = this.account.manager.ds;
|
|
35
|
+
let folder = await ds.folder(this.config.value, {account: this.account.physical_address})
|
|
36
|
+
let options = args[1] && await args[1].literal()
|
|
37
|
+
|
|
38
|
+
let res = await folder.read(query && await query.literal(), {...options})
|
|
39
|
+
|
|
40
|
+
for (let i=0; i< res.length; i++){
|
|
41
|
+
let item = res[i]
|
|
42
|
+
|
|
43
|
+
let fold = await ds.folder(item.address, {account: this.account.physical_address})
|
|
44
|
+
let value = await fold.readone({_id: item.data_id || item._id})
|
|
45
|
+
|
|
46
|
+
let obj = await this.account.vm.retrieve(value)
|
|
47
|
+
|
|
48
|
+
res[i] = obj;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return await this.account.vm.instantiate({
|
|
52
|
+
type: 'array',
|
|
53
|
+
location: call_config.location,
|
|
54
|
+
value: res,
|
|
55
|
+
}, {chain})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
readone = async(query, args)=>{
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
persist_repo = async(buffer)=>{
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
write = async(data, args, {thread})=>{
|
|
67
|
+
let _id = await data.get('_id', {raw: true})
|
|
68
|
+
let options = (args[1] && await args[1].literal()) || {}
|
|
69
|
+
|
|
70
|
+
if (_id && _id.type === 'address'){
|
|
71
|
+
_id = await (await this.account.vm.cloth(_id)).literal()
|
|
72
|
+
if (_id) _id = await this.account.vm.hash(_id.toString())
|
|
73
|
+
} else _id = null
|
|
74
|
+
|
|
75
|
+
let folder = await this.account.manager.ds.folder(this.config.value, {account: this.account.physical_address})
|
|
76
|
+
|
|
77
|
+
if (_id && options.replace === false){
|
|
78
|
+
if (await folder.readone({_id})) return _id
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
data = await store({object: data}, {chain: this.account.chain, vm: this.account.vm, thread })
|
|
82
|
+
|
|
83
|
+
let res = await folder.write({address: data.location, data_id: data._id, _id: _id || data._id, }, {replace: true, ...options})
|
|
84
|
+
|
|
85
|
+
return res._id;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
update = async(query, args)=>{
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
remove = async(query, args)=>{
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
literal = async()=>{
|
|
97
|
+
let folder = await this.account.manager.gds.folder(this.config.value)
|
|
98
|
+
|
|
99
|
+
return `[Folder ${folder.name}]`
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default Fold
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class Folder_queries {
|
|
2
|
+
write = async(payload, args)=>{
|
|
3
|
+
if (this.type !== 'folder') return 'READ-ONLY';
|
|
4
|
+
|
|
5
|
+
payload = await args[0].literal()
|
|
6
|
+
let options = args[1] && await args[1].literal()
|
|
7
|
+
|
|
8
|
+
let folder = await this._folder()
|
|
9
|
+
|
|
10
|
+
return await (await folder.write(payload, options)).to_instance(this.account)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
read = async(payload, args)=>{
|
|
14
|
+
payload = await args[0].literal()
|
|
15
|
+
let options = args[1] && await args[1].literal()
|
|
16
|
+
|
|
17
|
+
let folder = await this._folder()
|
|
18
|
+
|
|
19
|
+
return await (await folder.read(payload, options)).to_instance(this.account)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
update = async(payload, args)=>{
|
|
23
|
+
if (this.type !== 'folder') return 'READ-ONLY';
|
|
24
|
+
|
|
25
|
+
payload = await args[0].literal()
|
|
26
|
+
let options = args[1] && await args[1].literal()
|
|
27
|
+
|
|
28
|
+
let folder = await this._folder()
|
|
29
|
+
|
|
30
|
+
return await (await folder.update(payload, options)).to_instance(this.account)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
remove = async(payload, args)=>{
|
|
34
|
+
if (this.type !== 'folder') return 'READ-ONLY';
|
|
35
|
+
|
|
36
|
+
payload = await args[0].literal()
|
|
37
|
+
let options = args[1] && await args[1].literal()
|
|
38
|
+
|
|
39
|
+
let folder = await this._folder()
|
|
40
|
+
|
|
41
|
+
return await (await folder.remove(payload, options)).to_instance(this.account)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
export default Folder_queries
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Storage from "godprotocol/Datatypes/functions/storage.js";
|
|
2
|
+
|
|
3
|
+
class Res extends Storage{
|
|
4
|
+
constructor(config, account){
|
|
5
|
+
super(account)
|
|
6
|
+
|
|
7
|
+
this.config = config
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
content = async()=>{
|
|
11
|
+
return await this.literal()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
literal = async()=>{
|
|
15
|
+
if (this.value){
|
|
16
|
+
return this.value
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.value = await this.account.vm.execute({
|
|
20
|
+
type:'address',
|
|
21
|
+
value: this.config.value,
|
|
22
|
+
}, {chain: this.account.chain, cloth: true})
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
this.value = await this.value.literal()
|
|
26
|
+
|
|
27
|
+
return this.value
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default Res
|