Permalink
Browse files

Updated to Peruse v0.6.0

  • Loading branch information...
Ward Br
Ward Br committed Jun 26, 2018
1 parent d3a26a3 commit 33dde76c3ae02705bd336503119f5536335b9f1e
Showing with 32 additions and 38 deletions.
  1. +1 −3 src/js/app.js
  2. +31 −35 src/js/safe.js
@@ -164,9 +164,7 @@
el.focus()
}
}
},
// destroyed doesn't seem to be loaded before a page refresh
destroyed: safeWrap.free()
}
})

// handle routing
@@ -4,16 +4,16 @@
(function (exports) {
'use strict'

let AppToken
let SmdHandle
let SentriesHandle
let Sentries
let AppConnected

const SAFE_LIST_KEY = 'key_TodoMVC'

async function GetListEntrySafe (getType) {
let rc = ''
try {
const value = await window.safeMutableDataEntries.get(SentriesHandle, SAFE_LIST_KEY)
const value = await Sentries.get(SAFE_LIST_KEY)
console.log('GetListEntrySafe entry: ' + SAFE_LIST_KEY + ', getType: ' + getType + ', version: ' + value.version + ', value: ' + value.buf.toString())
if (getType === 'version') {
rc = value.version
@@ -26,14 +26,13 @@
// like in fu safeWrap.setList to be consistent,
// but on the other hand: here it works and maybe better example-wise to have 2 ways of doing it.
console.log('GetListEntrySafe entry:' + SAFE_LIST_KEY + ', getType: ' + getType + ' before mutate: err: ' + err)
const mutHandle = await window.safeMutableDataEntries.mutate(SentriesHandle)
const mutHandle = await Sentries.mutate(Sentries)
if (!mutHandle) {
window.alert('GetListEntrySafe entry:' + SAFE_LIST_KEY + ', getType: ' + getType + ': mutHandle null')
} else {
rc = '[]'
await window.safeMutableDataMutation.insert(mutHandle, SAFE_LIST_KEY, rc)
await window.safeMutableData.applyEntriesMutation(SmdHandle, mutHandle)
window.safeMutableDataMutation.free(mutHandle)
await mutHandle.insert(SAFE_LIST_KEY, rc)
await SmdHandle.applyEntriesMutation(mutHandle)
}
} else {
window.alert('GetListEntrySafe entry:' + SAFE_LIST_KEY + ' getType: ' + getType + ', err: ' + err)
@@ -45,18 +44,18 @@
let rc = '[]'
try {
const container = '_public'
SmdHandle = await window.safeApp.getContainer(AppToken, container)
SmdHandle = await AppConnected.auth.getContainer(container)

// const r = await window.safeMutableData.getNameAndTag(SmdHandle)
// const r = await SmdHandle.getNameAndTag()
// console.log('MutableData tag: ' + r.tag + ' and name: ' + r.name.buffer)
// const version = await window.safeMutableData.getVersion(SmdHandle)
// const version = await SmdHandle.getVersion()
// console.log('MutableData current version: ' + version)

SentriesHandle = await window.safeMutableData.getEntries(SmdHandle)
if (!SentriesHandle) {
Sentries = await SmdHandle.getEntries()
if (!Sentries) {
window.alert('InitMData: safeMutableData.getEntries returns nothing')
}
console.log('SentriesHandle: ', SentriesHandle)
console.log('Sentries: ', Sentries)

rc = await GetListEntrySafe('init')
} catch (err) {
@@ -71,21 +70,23 @@
const appInfo = {
name: 'TodoMVC Vue.js public',
id: 'TodoMVC.Vue.js.webapp',
version: '0.3.2',
version: '0.3.3',
vendor: 'Bedraw'
}
const access = {
const containerPermissions = {
'_public': ['Read', 'Insert', 'Update', 'Delete', 'ManagePermissions']
}
const options = { own_container: false }
const authorisationOptions = { own_container: false }

AppToken = await window.safeApp.initialise(appInfo)
console.log('Application Token received: ' + AppToken)
const app = await safe.initialiseApp(appInfo)
console.log('after app = safe.initialiseApp')

const authUri = await window.safeApp.authorise(AppToken, access, options)
console.log('authUri' + authUri)
const authReqUri = await app.auth.genAuthUri(containerPermissions, authorisationOptions)
console.log('after app.auth.genAuthUri')

const authUri = await safe.authorise(authReqUri)
AppConnected = await app.auth.loginFromUri(authUri)

await window.safeApp.connectAuthorised(AppToken, authUri)
return await InitMData()
} catch (err) {
window.alert('safeWrap.init error: ' + err)
@@ -95,34 +96,29 @@

setList: async function (value) {
try {
const mutHandle = await window.safeMutableData.newMutation(AppToken)
const prevValue = await window.safeMutableData.get(SmdHandle, SAFE_LIST_KEY)
const mutHandle = await AppConnected.mutableData.newMutation()
const prevValue = await SmdHandle.get(SAFE_LIST_KEY)
const newVersion = prevValue.version + 1
console.log('safeWrap.setList entry: ' + SAFE_LIST_KEY + ', version: ' + newVersion + ', value: ' + value)
await window.safeMutableDataMutation.update(mutHandle, SAFE_LIST_KEY, value, newVersion)
await window.safeMutableData.applyEntriesMutation(SmdHandle, mutHandle)
await mutHandle.update(SAFE_LIST_KEY, value, newVersion)
await SmdHandle.applyEntriesMutation(mutHandle)
// code below gives error below:
// safeWrap.setList error: -107: Core error: Routing client error -> Entry actions are invalid: {[107, 101, 121, 95, 84, 111, 100, 111, 77, 86, 67]: InvalidSuccessor(21)}
// ->therefore switched to code above
/* if(SentriesHandle) {
/* if(Sentries) {
let version = await GetListEntrySafe('version')
if(version) {
const mutHandle = await window.safeMutableDataEntries.mutate(SentriesHandle)
const mutHandle = await Sentries.mutate()
console.log('safeWrap.setList entry: ' + SAFE_LIST_KEY + ', version: ' + version + ', value: ' + value)
await window.safeMutableDataMutation.update(mutHandle, SAFE_LIST_KEY, value, version + 1)
await window.safeMutableData.applyEntriesMutation(SmdHandle, mutHandle)
window.safeMutableDataMutation.free(mutHandle)
await mutHandle.update(SAFE_LIST_KEY, value, version + 1)
await SmdHandle.applyEntriesMutation(mutHandle)
}
} else {
window.alert('safeWrap.setList SentriesHandle null')
window.alert('safeWrap.setList Sentries null')
} */
} catch (err) {
window.alert('safeWrap.setList error: ' + err)
}
},

free: function () {
window.safeApp.free(AppToken)
}
}
}(window))

0 comments on commit 33dde76

Please sign in to comment.