Skip to content

Commit

Permalink
add cmd/list.js and sidecar/ops/list.js
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiRegiani committed Jan 6, 2025
1 parent 0225e72 commit e36dee1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module.exports = async (ipc, argv = Bare.argv.slice(1)) => {
const list = command(
'list',
summary('View local database contents'),
flag('--bundle', 'View only the Bundle collection'),
flag('--bundles', 'View only the Bundle collection'),
runners.list(ipc)
)

Expand Down
29 changes: 18 additions & 11 deletions cmd/list.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
'use strict'
const { outputter } = require('./iface')

const listBundle = () => {
console.log('List bundle')
const bundles = (items) => {
let out = 'BUNDLES\n'
for (const b of items) {
out += `- link: ${b.link}\n`
out += ` appStorage: ${b.appStorage}\n`
out += ` encryptionKey: ${b.encryptionKey}\n`
out += ` tags: ${b.tags}\n`
}
return out
}

const listAll = () => {
listBundle()
}
const all = (items) => bundles(items)

const output = outputter('list', {
bundle: listBundle,
all: listAll
bundles,
all,
error: (err) => `List Error (code: ${err.code || 'none'}) ${err.stack}`,
final: () => false
})

module.exports = (ipc) => async function list (cmd) {
if (cmd.flags.bundle) {
await output(false, [{ tag: 'bundle' }])
} else {
await output(false, [{ tag: 'all' }])
const data = await ipc.list({ bundles: cmd.flags.bundles })
if (cmd.flags.bundles) {
return await output(false, data, { tag: 'bundles' }, ipc)
}
return await output(false, data, { tag: 'all' }, ipc)
}
1 change: 1 addition & 0 deletions gui/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class IPC {
message (...args) { return electron.ipcRenderer.invoke('message', ...args) }
checkpoint (...args) { return electron.ipcRenderer.invoke('checkpoint', ...args) }
versions (...args) { return electron.ipcRenderer.invoke('versions', ...args) }
list (...args) { return electron.ipcRenderer.invoke('list', ...args) }
restart (...args) { return electron.ipcRenderer.invoke('restart', ...args) }
badge (...args) { return electron.ipcRenderer.invoke('badge', ...args) }

Expand Down
5 changes: 4 additions & 1 deletion subsystems/sidecar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const ops = {
Dump: require('./ops/dump'),
Info: require('./ops/info'),
Shift: require('./ops/shift'),
Touch: require('./ops/touch')
Touch: require('./ops/touch'),
List: require('./ops/list')
}

// ensure that we are registered as a link handler
Expand Down Expand Up @@ -355,6 +356,8 @@ class Sidecar extends ReadyResource {

info (params, client) { return new ops.Info(params, client, this) }

list (params, client) { return new ops.List(params, client, this) }

shift (params, client) { return new ops.Shift(params, client, this) }

gc (params, client) { return new ops.GC(params, client) }
Expand Down
21 changes: 21 additions & 0 deletions subsystems/sidecar/ops/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'
const Opstream = require('../lib/opstream')

module.exports = class List extends Opstream {
constructor (...args) {
super((...args) => this.#op(...args), ...args)
}

async #op ({ bundles }) {
const all = await this.model.allBundles()
this.push({
tag: bundles ? 'bundles' : 'all',
data: all.map(b => ({
link: b.link,
appStorage: b.appStorage,
encryptionKey: b.encryptionKey,
tags: b.tags
}))
})
}
}

0 comments on commit e36dee1

Please sign in to comment.