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.
- 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 +241 -137
- package/callables/functions/assign.js +0 -6
package/html/parse.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {message_box} from './util.js'
|
|
2
|
+
|
|
3
|
+
const script = (manager)=> {
|
|
4
|
+
return `
|
|
5
|
+
const account_selection_el = document.getElementById('account_selection'), address_el = document.getElementById('address'),
|
|
6
|
+
from_el = document.getElementById('from'),
|
|
7
|
+
query_el = document.getElementById('query'), parse = document.getElementById('parse');
|
|
8
|
+
|
|
9
|
+
let message_box = document.getElementById('message-box')
|
|
10
|
+
|
|
11
|
+
document.addEventListener('DOMContentLoaded', e=>{
|
|
12
|
+
let accs = sessionStorage.getItem('accounts')
|
|
13
|
+
if (!accs) return;
|
|
14
|
+
|
|
15
|
+
let tml = '<option default>--Select Account--</option>'
|
|
16
|
+
if (accs){
|
|
17
|
+
accs = JSON.parse(accs)
|
|
18
|
+
accs.map(acc=>{
|
|
19
|
+
let el = document.createElement('option')
|
|
20
|
+
el.id = acc.uid
|
|
21
|
+
el.value = acc.uid
|
|
22
|
+
el.textContent = acc.name
|
|
23
|
+
|
|
24
|
+
account_selection_el.appendChild(el)
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
function render_object(obj, parentElement) {
|
|
30
|
+
let list = document.createElement("ul");
|
|
31
|
+
list.className = "list-group mb-3";
|
|
32
|
+
|
|
33
|
+
for (let key in obj) {
|
|
34
|
+
if (obj.hasOwnProperty(key)) {
|
|
35
|
+
let item = document.createElement("li");
|
|
36
|
+
item.className = "list-group-item";
|
|
37
|
+
|
|
38
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
39
|
+
item.innerHTML = "<strong>" + key + ":</strong>";
|
|
40
|
+
render_object(obj[key], item);
|
|
41
|
+
} else {
|
|
42
|
+
item.innerHTML =
|
|
43
|
+
"<strong>" + key + ":</strong> " + obj[key];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
list.appendChild(item);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
parentElement.appendChild(list);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
parse.addEventListener('click', async e=>{
|
|
55
|
+
e.preventDefault()
|
|
56
|
+
|
|
57
|
+
let account = account_selection_el.selectedIndex, query = query_el.value.trim(),
|
|
58
|
+
address = address_el.value.trim();
|
|
59
|
+
from = from_el.value.trim();
|
|
60
|
+
|
|
61
|
+
message_box.textContent = ''
|
|
62
|
+
|
|
63
|
+
let account_uid = account_selection_el.children[account].id
|
|
64
|
+
if (!address){
|
|
65
|
+
message_box.textContent = 'Please completely fill all form fields.'
|
|
66
|
+
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
message_box.textContent = ''
|
|
69
|
+
}, 2500);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (query) {
|
|
74
|
+
try{
|
|
75
|
+
query = JSON.parse(query)
|
|
76
|
+
} catch(e){
|
|
77
|
+
message_box.textContent = e.message
|
|
78
|
+
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
message_box.textContent = ''
|
|
81
|
+
}, 2500);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
let data = {
|
|
88
|
+
address, query, from, account: account_uid, account_name: account_selection_el.children[account].value
|
|
89
|
+
}
|
|
90
|
+
console.log(data)
|
|
91
|
+
|
|
92
|
+
ftch('/parse', data)
|
|
93
|
+
.then(res=>{
|
|
94
|
+
let container = document.getElementById("parser-result");
|
|
95
|
+
render_object(res, container);
|
|
96
|
+
}).catch(err=>console.log(err))
|
|
97
|
+
|
|
98
|
+
})
|
|
99
|
+
`
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const parse = (manager)=>{
|
|
103
|
+
let tml = `
|
|
104
|
+
<!-- Container for the Parse form -->
|
|
105
|
+
<div class="container my-5">
|
|
106
|
+
<div class="row justify-content-center">
|
|
107
|
+
<div class="col-md-8">
|
|
108
|
+
<form id="run-form" class="card p-4 shadow-sm">
|
|
109
|
+
<h4 class="mb-4 text-center">Parse</h4>
|
|
110
|
+
|
|
111
|
+
<!-- Account Selection -->
|
|
112
|
+
<div class="mb-3">
|
|
113
|
+
<label for="account_selection" class="form-label">Account</label>
|
|
114
|
+
<select id="account_selection" class="form-select" required>
|
|
115
|
+
<option selected disabled>-- Select Account --</option>
|
|
116
|
+
<!-- Options will be injected via JS -->
|
|
117
|
+
</select>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<!-- Address -->
|
|
121
|
+
<div class="mb-3">
|
|
122
|
+
<label for="address" class="form-label">Address</label>
|
|
123
|
+
<input type="text" class="form-control" id="address" placeholder="Address" required>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<!-- From (Optional) -->
|
|
127
|
+
<div class="mb-3">
|
|
128
|
+
<label for="from" class="form-label">From (optional)</label>
|
|
129
|
+
<input type="text" value='.storage' class="form-control" id="from" placeholder=".storage | .codes | thread">
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<!-- Query -->
|
|
133
|
+
<div class="mb-3">
|
|
134
|
+
<label for="query" class="form-label">Query</label>
|
|
135
|
+
<textarea class="form-control mt-2" id="query" rows="4" placeholder="Query"></textarea>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
<!-- Submit Button -->
|
|
139
|
+
<div class="d-grid">
|
|
140
|
+
<button type="submit" class="btn btn-secondary" id="parse">Send</button>
|
|
141
|
+
</div>
|
|
142
|
+
</form>
|
|
143
|
+
|
|
144
|
+
<!-- Message box -->
|
|
145
|
+
<div id="message-box" class="mt-3"></div>
|
|
146
|
+
|
|
147
|
+
<div class="container py-4">
|
|
148
|
+
<div class="row justify-content-center">
|
|
149
|
+
<div class="col-lg-8 col-md-10">
|
|
150
|
+
|
|
151
|
+
<div class="card shadow-sm">
|
|
152
|
+
<div class="card-body">
|
|
153
|
+
<h3 class="card-title text-center mb-3">Parser Result Viewer</h3>
|
|
154
|
+
<div id="parser-result"></div>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
</div>`
|
|
164
|
+
|
|
165
|
+
tml = `${tml} <script>${script(manager)}</script>`
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
return tml
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export default parse
|
package/html/run.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {message_box} from './util.js'
|
|
2
|
+
|
|
3
|
+
const script = (manager)=> {
|
|
4
|
+
return `
|
|
5
|
+
const account_selection_el = document.getElementById('account_selection'), address_el = document.getElementById('address'),
|
|
6
|
+
config_el = document.getElementById('config'),
|
|
7
|
+
callback_el = document.getElementById('callback'),
|
|
8
|
+
id_el = document.getElementById('ID'),
|
|
9
|
+
is_config = document.getElementById('is_config'), run = document.getElementById('run')
|
|
10
|
+
|
|
11
|
+
// let configs = {}
|
|
12
|
+
// is_config.addEventListener('click', e=>{
|
|
13
|
+
// if (e.target.checked){
|
|
14
|
+
// let addr = address_el.value.trim()
|
|
15
|
+
|
|
16
|
+
// }
|
|
17
|
+
// })
|
|
18
|
+
|
|
19
|
+
let message_box = document.getElementById('message-box')
|
|
20
|
+
|
|
21
|
+
document.addEventListener('DOMContentLoaded', e=>{
|
|
22
|
+
let accs = sessionStorage.getItem('accounts')
|
|
23
|
+
if (!accs) return;
|
|
24
|
+
|
|
25
|
+
let tml = '<option default>--Select Account--</option>'
|
|
26
|
+
if (accs){
|
|
27
|
+
accs = JSON.parse(accs)
|
|
28
|
+
accs.map(acc=>{
|
|
29
|
+
let el = document.createElement('option')
|
|
30
|
+
el.id = acc.uid
|
|
31
|
+
el.value = acc.uid
|
|
32
|
+
el.textContent = acc.name
|
|
33
|
+
|
|
34
|
+
account_selection_el.appendChild(el)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
run.addEventListener('click', e=>{
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
|
|
42
|
+
let id = id_el.value.trim(), address = address_el.value.trim(), config = config_el.value.trim(), account = account_selection_el.selectedIndex, callback = callback_el.value.trim();
|
|
43
|
+
|
|
44
|
+
if (!account){
|
|
45
|
+
message_box.innerHTML = 'Provide an account, or <a href="http://${manager.options.server_domain}/create_account">create one here</a>'
|
|
46
|
+
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
message_box.textContent = ''
|
|
49
|
+
}, 2500);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let account_uid = account_selection_el.children[account].id
|
|
54
|
+
if (!address && !config){
|
|
55
|
+
message_box.textContent = 'Please completely fill all form fields.'
|
|
56
|
+
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
message_box.textContent = ''
|
|
59
|
+
}, 2500);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (config){
|
|
64
|
+
try{
|
|
65
|
+
config = JSON.parse(config)
|
|
66
|
+
}catch(e){
|
|
67
|
+
message_box.textContent = e.message
|
|
68
|
+
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
message_box.textContent = ''
|
|
71
|
+
}, 2500);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let data = {
|
|
77
|
+
_id: id, address, config, account: account_uid, account_name: account_selection_el.children[account].value, callback
|
|
78
|
+
}
|
|
79
|
+
console.log(data)
|
|
80
|
+
|
|
81
|
+
ftch("/run", data).then(res=>{
|
|
82
|
+
message_box.textContent = res.thread_id ? 'Sequence is in execution! @ '.concat(res.thread_id).concat(' :: Callback at: ').concat(res.callback) : res.message
|
|
83
|
+
|
|
84
|
+
return;
|
|
85
|
+
})
|
|
86
|
+
.catch(err=>console.log(err))
|
|
87
|
+
|
|
88
|
+
}) `
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const run = (manager)=>{
|
|
92
|
+
let tml = `
|
|
93
|
+
<!-- Container for the Run form -->
|
|
94
|
+
<div class="container my-5">
|
|
95
|
+
<div class="row justify-content-center">
|
|
96
|
+
<div class="col-md-8">
|
|
97
|
+
<form id="run-form" class="card p-4 shadow-sm">
|
|
98
|
+
<h4 class="mb-4 text-center">Run</h4>
|
|
99
|
+
|
|
100
|
+
<!-- Account Selection -->
|
|
101
|
+
<div class="mb-3">
|
|
102
|
+
<label for="account_selection" class="form-label">Account</label>
|
|
103
|
+
<select id="account_selection" class="form-select" required>
|
|
104
|
+
<option selected disabled>-- Select Account --</option>
|
|
105
|
+
<!-- Options will be injected via JS -->
|
|
106
|
+
</select>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<!-- Address -->
|
|
110
|
+
<div class="mb-3">
|
|
111
|
+
<label for="address" class="form-label">Address</label>
|
|
112
|
+
<input type="text" class="form-control" id="address" placeholder="Address">
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<!-- ID (Optional) -->
|
|
116
|
+
<div class="mb-3">
|
|
117
|
+
<label for="ID" class="form-label">ID (optional)</label>
|
|
118
|
+
<input type="text" class="form-control" id="ID" placeholder="ID">
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<!-- Config -->
|
|
122
|
+
<div class="mb-3">
|
|
123
|
+
<label for="config" class="form-label">Config</label>
|
|
124
|
+
<textarea class="form-control mt-2" id="config" rows="4" placeholder="Config"></textarea>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<!-- Callback (Optional) -->
|
|
128
|
+
<div class="mb-3">
|
|
129
|
+
<label for="callback" class="form-label">Callback (optional)</label>
|
|
130
|
+
<input type="text" class="form-control" id="callback" placeholder="Callback">
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
<!-- Submit Button -->
|
|
134
|
+
<div class="d-grid">
|
|
135
|
+
<button type="submit" class="btn btn-warning" id="run">Send</button>
|
|
136
|
+
</div>
|
|
137
|
+
</form>
|
|
138
|
+
|
|
139
|
+
<!-- Message box -->
|
|
140
|
+
<div id="message-box" class="mt-3"></div>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
</div>`
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
tml = `${tml} <script>${script(manager)}</script>`
|
|
147
|
+
|
|
148
|
+
return tml
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export default run
|
package/html/util.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "godprotocol",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A distributed computing environment",
|
|
5
5
|
"main": "Index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,14 +25,16 @@
|
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/immanuel-savvy/GodProtocol/issues"
|
|
27
27
|
},
|
|
28
|
+
"type": "module",
|
|
28
29
|
"homepage": "https://github.com/immanuel-savvy/GodProtocol#readme",
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@octokit/rest": "^21.0.2",
|
|
31
32
|
"crypto": "^1.0.1",
|
|
32
33
|
"elliptic": "^6.6.0",
|
|
33
34
|
"fs": "^0.0.1-security",
|
|
34
|
-
"generalised-datastore": "
|
|
35
|
-
"js-base64": "^3.7.7"
|
|
35
|
+
"generalised-datastore": "latest",
|
|
36
|
+
"js-base64": "^3.7.7",
|
|
37
|
+
"aircode4": "latest"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
40
|
"esm": "^3.2.25",
|
package/repos/fs.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { copy_object } from 'generalised-datastore/utils/functions.js'
|
|
3
|
+
import Repository from 'godprotocol/Objects/Repository.js';
|
|
4
|
+
import { post_request } from "godprotocol/utils/services.js";
|
|
5
|
+
|
|
6
|
+
class Fs extends Repository{
|
|
7
|
+
constructor(options={}){
|
|
8
|
+
super()
|
|
9
|
+
|
|
10
|
+
this._fs = fs;
|
|
11
|
+
this.__dirname = options.__dirname;
|
|
12
|
+
this.remote = options.remote;
|
|
13
|
+
this.name = options.name;
|
|
14
|
+
|
|
15
|
+
this.type = 'fs'
|
|
16
|
+
this.cache = new Object();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
parse_path = async(path)=>{
|
|
20
|
+
path = path.split('/')
|
|
21
|
+
let addr = path.slice(0,-1).join('/')
|
|
22
|
+
if (!this._fs.existsSync(addr)){
|
|
23
|
+
this._fs.mkdirSync(addr, {recursive: true})
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
call = async payload=>{
|
|
28
|
+
let result;
|
|
29
|
+
switch(payload.op){
|
|
30
|
+
case 'write':
|
|
31
|
+
result = await this.write(payload.path, payload.data)
|
|
32
|
+
break
|
|
33
|
+
case 'read':
|
|
34
|
+
result = await this.read(payload.path)
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fetch = async payload=>{
|
|
41
|
+
let res = await post_request({
|
|
42
|
+
options: {
|
|
43
|
+
...this.remote,
|
|
44
|
+
path: '/oracle'
|
|
45
|
+
},
|
|
46
|
+
data: JSON.stringify({method: 'fs', arg: {payload, name: this.name}})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return res;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
write_file = async(path, data)=>{
|
|
53
|
+
path = this.path(path)
|
|
54
|
+
|
|
55
|
+
await this.fetch({path, data, op: 'write'})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
write = async(path, data) => {
|
|
59
|
+
await this.parse_path(path)
|
|
60
|
+
this._fs.writeFileSync(path, data)
|
|
61
|
+
|
|
62
|
+
this.cache[path] = data
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
read = async(path)=>{
|
|
66
|
+
let data;
|
|
67
|
+
try{
|
|
68
|
+
data = this.cache[path]
|
|
69
|
+
if (!data){
|
|
70
|
+
await this.parse_path(path)
|
|
71
|
+
data = this._fs.readFileSync(path, {encoding: 'utf-8'})
|
|
72
|
+
}else {
|
|
73
|
+
data = copy_object(data)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}catch(e){
|
|
77
|
+
console.log(e.message)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
read_file = async(path)=>{
|
|
84
|
+
path = this.path(path)
|
|
85
|
+
|
|
86
|
+
let data = await this.fetch({path, op: 'read'})
|
|
87
|
+
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
path = pth=>{
|
|
92
|
+
return `${this.__dirname}/${pth}`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
mkdir = async(path)=>{
|
|
96
|
+
let done;
|
|
97
|
+
try{
|
|
98
|
+
this._fs.mkdirSync(this.path(path), {recursive: true})
|
|
99
|
+
done = true
|
|
100
|
+
}catch(e){
|
|
101
|
+
done = false
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return done;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
exists = async(path)=>{
|
|
108
|
+
path = this.path(path)
|
|
109
|
+
|
|
110
|
+
return !!this.cache[path] || this._fs.existsSync(path)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default Fs
|
package/repos/github.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import Repository from '../Objects/Repository.js'
|
|
2
|
+
|
|
3
|
+
class Github extends Repository{
|
|
4
|
+
constructor({ key, username, repo }) {
|
|
5
|
+
super('github')
|
|
6
|
+
|
|
7
|
+
this.base_url = 'https://api.github.com';
|
|
8
|
+
this.auth_token = key;
|
|
9
|
+
this.owner = username;
|
|
10
|
+
this.repo = repo;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Headers for API calls
|
|
14
|
+
get_headers = () => ({
|
|
15
|
+
Authorization: `Bearer ${this.auth_token}`,
|
|
16
|
+
Accept: 'application/vnd.github.v3+json',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Write (create or update) a file
|
|
20
|
+
write_file = async (file_path, content) => {
|
|
21
|
+
const url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
|
|
22
|
+
let sha = null;
|
|
23
|
+
|
|
24
|
+
// Check if file exists, get its SHA
|
|
25
|
+
const exists = await this.file_exists(file_path);
|
|
26
|
+
if (exists) {
|
|
27
|
+
const res = await fetch(url, { headers: this.get_headers() });
|
|
28
|
+
if (res.ok) {
|
|
29
|
+
const data = await res.json();
|
|
30
|
+
sha = data.sha;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Build payload
|
|
35
|
+
const body = {
|
|
36
|
+
message: exists ? 'Update file' : 'Create file',
|
|
37
|
+
content: Buffer.from(content).toString('base64'),
|
|
38
|
+
...(sha && { sha }),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
method: 'PUT',
|
|
43
|
+
headers: this.get_headers(),
|
|
44
|
+
body: JSON.stringify(body),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return response.json();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Read a file
|
|
51
|
+
read_file = async (file_path) => {
|
|
52
|
+
const url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
|
|
53
|
+
|
|
54
|
+
const response = await fetch(url, { headers: this.get_headers() });
|
|
55
|
+
if (!response.ok) return null;
|
|
56
|
+
|
|
57
|
+
const fileData = await response.json();
|
|
58
|
+
return Buffer.from(fileData.content, 'base64').toString('utf-8');
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Check if file exists
|
|
62
|
+
file_exists = async (file_path) => {
|
|
63
|
+
const url = `${this.base_url}/repos/${this.owner}/${this.repo}/contents/${file_path}`;
|
|
64
|
+
try {
|
|
65
|
+
const response = await fetch(url, { headers: this.get_headers() });
|
|
66
|
+
return response.ok;
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default Github;
|
package/repos/ram.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class Ram {
|
|
2
|
+
constructor(account){
|
|
3
|
+
this.account = account;
|
|
4
|
+
this.oracle = account.manager.oracle;
|
|
5
|
+
this.blocks = new Object();
|
|
6
|
+
this.mbr = new Object()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
write = async(path, content, repo)=>{
|
|
10
|
+
let contents = this.blocks[repo]
|
|
11
|
+
if (!contents){
|
|
12
|
+
contents = new Object()
|
|
13
|
+
this.blocks[repo] = contents
|
|
14
|
+
}
|
|
15
|
+
contents[path] = content;
|
|
16
|
+
this.mbr[path] = content;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
mkdir = async(path, repo)=>{
|
|
20
|
+
await this.oracle.mkdir(path, repo)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exists = async(path, repo)=>{
|
|
24
|
+
return await this.oracle.exists(path, repo)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
read = async(path, repo)=>{
|
|
28
|
+
// console.log(path, repo, 'uhh')
|
|
29
|
+
if (!repo) return this.mbr[path]
|
|
30
|
+
|
|
31
|
+
let contents = this.blocks[repo]
|
|
32
|
+
|
|
33
|
+
if(!contents){
|
|
34
|
+
contents = {}
|
|
35
|
+
this.blocks[repo] = contents
|
|
36
|
+
}
|
|
37
|
+
if (!contents[path]){
|
|
38
|
+
let cont = await this.oracle.read(path, repo)
|
|
39
|
+
|
|
40
|
+
if (cont) contents[path] = cont
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return contents[path]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default Ram
|