@@ -133,14 +133,14 @@
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
|
||||
const collection = 'records';
|
||||
const collection = '@bridgeswarm/records';
|
||||
document.getElementById('hyperdbPut').onclick = async function () {
|
||||
const id = document.getElementById('hyperdbId').value;
|
||||
const value = document.getElementById('hyperdbValue').value;
|
||||
if (!id) return;
|
||||
try {
|
||||
await request('hyperdbInsert', { collection, doc: { id, value: value || '' } });
|
||||
log('hyperdb.insert(records, { id: "' + id + '", value: "' + (value || '') + '" })', 'val');
|
||||
log('hyperdb.insert(@bridgeswarm/records, { id: "' + id + '", value: "' + (value || '') + '" })', 'val');
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
document.getElementById('hyperdbGet').onclick = async function () {
|
||||
@@ -148,7 +148,7 @@
|
||||
if (!id) return;
|
||||
try {
|
||||
const r = await request('hyperdbGet', { collection, query: { id } });
|
||||
log('hyperdb.get(records, { id: "' + id + '" }) => ' + (r.doc === null ? 'null' : JSON.stringify(r.doc)), 'val');
|
||||
log('hyperdb.get(@bridgeswarm/records, { id: "' + id + '" }) => ' + (r.doc === null ? 'null' : JSON.stringify(r.doc)), 'val');
|
||||
if (r.doc) document.getElementById('hyperdbValue').value = r.doc.value || '';
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
@@ -157,14 +157,14 @@
|
||||
if (!id) return;
|
||||
try {
|
||||
await request('hyperdbDelete', { collection, query: { id } });
|
||||
log('hyperdb.delete(records, { id: "' + id + '" })', 'val');
|
||||
log('hyperdb.delete(@bridgeswarm/records, { id: "' + id + '" })', 'val');
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
document.getElementById('hyperdbFind').onclick = async function () {
|
||||
try {
|
||||
const r = await request('hyperdbFindToArray', { collectionOrIndex: collection });
|
||||
const docs = r.docs || [];
|
||||
log('hyperdb.find(records) => ' + docs.length + ' doc(s) ' + JSON.stringify(docs), 'val');
|
||||
log('hyperdb.find(@bridgeswarm/records) => ' + docs.length + ' doc(s) ' + JSON.stringify(docs), 'val');
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
document.getElementById('hyperdbFlush').onclick = async function () {
|
||||
@@ -173,6 +173,50 @@
|
||||
log('hyperdb.flush()', 'val');
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
|
||||
document.getElementById('coreOpenNamed').onclick = async function () {
|
||||
try {
|
||||
const r = await request('coreOpen', { name: 'demo-named-core' });
|
||||
log('coreOpen(demo-named-core) => resourceId=' + r.resourceId + ' key=' + (r.key || '').slice(0, 16) + '…', 'val');
|
||||
window.__namedCoreId = r.resourceId;
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
document.getElementById('coreAppendNamed').onclick = async function () {
|
||||
if (!window.__namedCoreId) {
|
||||
log('Open a named core first', 'err');
|
||||
return;
|
||||
}
|
||||
const data = document.getElementById('coreAppend').value || 'named';
|
||||
try {
|
||||
const base64 = btoa(unescape(encodeURIComponent(data)));
|
||||
const r = await request('coreAppend', { resourceId: window.__namedCoreId, base64 });
|
||||
log('coreAppend(resourceId) length=' + r.length, 'val');
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
|
||||
const notesCollection = '@bridgeswarm/notes';
|
||||
document.getElementById('notePut').onclick = async function () {
|
||||
const id = document.getElementById('noteId').value;
|
||||
const title = document.getElementById('noteTitle').value || '';
|
||||
const body = document.getElementById('noteBody').value || '';
|
||||
if (!id) return;
|
||||
try {
|
||||
await request('hyperdbInsert', { collection: notesCollection, doc: { id, title, body } });
|
||||
log('hyperdb.insert(@bridgeswarm/notes, …)', 'val');
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
document.getElementById('noteGet').onclick = async function () {
|
||||
const id = document.getElementById('noteId').value;
|
||||
if (!id) return;
|
||||
try {
|
||||
const r = await request('hyperdbGet', { collection: notesCollection, query: { id } });
|
||||
log('note => ' + JSON.stringify(r.doc), 'val');
|
||||
if (r.doc) {
|
||||
document.getElementById('noteTitle').value = r.doc.title || '';
|
||||
document.getElementById('noteBody').value = r.doc.body || '';
|
||||
}
|
||||
} catch (e) { log(e.message, 'err'); }
|
||||
};
|
||||
}).catch(function () { log('BridgeSwarm not available.', 'err'); });
|
||||
})(0);
|
||||
})();
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
<button class="primary" id="coreInfo">Core info</button>
|
||||
<input type="text" id="coreAppend" placeholder="Data to append (text)">
|
||||
<button class="secondary" id="coreAppendBtn">Append</button>
|
||||
<button class="secondary" id="coreOpenNamed">Open named core</button>
|
||||
<button class="secondary" id="coreAppendNamed">Append to named</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -82,6 +84,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Hyperdb (notes)</h2>
|
||||
<div class="row">
|
||||
<input type="text" id="noteId" placeholder="Note id">
|
||||
<input type="text" id="noteTitle" placeholder="Title">
|
||||
<input type="text" id="noteBody" placeholder="Body">
|
||||
<button class="primary" id="notePut">Put note</button>
|
||||
<button class="secondary" id="noteGet">Get note</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Log</h2>
|
||||
<div class="log" id="log"></div>
|
||||
|
||||
Reference in New Issue
Block a user