Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Store -> HyperDB #455

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f45cfc7
hyperdb: identity schema
AndreiRegiani Nov 21, 2024
dc76956
Merge branch 'main' into hyperdb-store-refactor
AndreiRegiani Nov 21, 2024
e9ceaeb
Add `bundle`, remove `identity`
AndreiRegiani Nov 25, 2024
e0e29a6
Merge branch 'main' into hyperdb-store-refactor
AndreiRegiani Nov 26, 2024
6bd7f5b
New collections `permits` and `encryption-keys`
AndreiRegiani Nov 28, 2024
0c00a15
WIP bundle schema implementation
AndreiRegiani Nov 29, 2024
2f69059
Sidecar integration
AndreiRegiani Dec 2, 2024
08c17ef
sidecar/ops implementation
AndreiRegiani Dec 2, 2024
eb37ba0
class EncryptionKey
AndreiRegiani Dec 3, 2024
c54257b
permit() check for nulls
AndreiRegiani Dec 3, 2024
9ea0258
Fix encryption-key property name
AndreiRegiani Dec 3, 2024
1ab3b89
Refactor encryption-key -> encryptionKey
AndreiRegiani Dec 3, 2024
e9281c5
sidecar/ops isValid
AndreiRegiani Dec 4, 2024
edc2da2
Merge branch 'main' into hyperdb-store-refactor
AndreiRegiani Dec 4, 2024
0516ec7
key->link, remove --unsafe-clear-preferences, code style
AndreiRegiani Dec 5, 2024
50236ac
Sidecar: re-usable hyperdb instance
AndreiRegiani Dec 6, 2024
2a67f3f
Merge branch 'main' into hyperdb-store-refactor
AndreiRegiani Dec 6, 2024
dfbd90c
use this.sidecar.db
AndreiRegiani Dec 6, 2024
7f7b4ba
Add sidecar instance into `ops/encryptionKey`
AndreiRegiani Dec 9, 2024
8bb80e4
ops: query bundle.encryptionKey
AndreiRegiani Dec 9, 2024
b8eb847
ops/stage: handle both key and params.encryptionKey
AndreiRegiani Dec 9, 2024
8244d75
fixed worker args (#486)
rafapaezbas Dec 9, 2024
39a8a87
fixed encryption key in hyperdb
rafapaezbas Dec 9, 2024
0baa5aa
Merge branch 'main' into hyperdb-store-refactor
rafapaezbas Dec 9, 2024
71e42bc
removed log from example app
rafapaezbas Dec 9, 2024
f227d38
Remove `cmd/encryption-key`
AndreiRegiani Dec 10, 2024
c30d2fb
revert remove of encryption-key flags
rafapaezbas Dec 10, 2024
e82c82a
pass encryption key to worker
rafapaezbas Dec 10, 2024
70faa82
corrected encryption-key flag for dump, seed and info
rafapaezbas Dec 10, 2024
d0aae11
removed encryption-key op
rafapaezbas Dec 10, 2024
d2a5b5a
lint fix
rafapaezbas Dec 10, 2024
ea2a419
storedEncryptedKey -> storedEncryptionKey
AndreiRegiani Dec 10, 2024
eb11a8f
remove encryption-key flags
rafapaezbas Dec 10, 2024
40a3da7
removed encryption key flag from ops and cmds
rafapaezbas Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const output = outputter('stage', {
})

module.exports = (ipc) => async function dump (cmd) {
const { dryRun, checkout, json, encryptionKey, ask, force } = cmd.flags
const { dryRun, checkout, json, ask, force } = cmd.flags
const { link } = cmd.args
let { dir } = cmd.args
if (!link) throw ERR_INVALID_INPUT('<link> must be specified.')
if (!dir) throw ERR_INVALID_INPUT('<dir> must be specified.')
dir = dir === '-' ? '-' : (isAbsolute(dir) ? dir : resolve('.', dir))
await output(json, ipc.dump({ id: Bare.pid, link, dir, dryRun, checkout, encryptionKey, force }), { ask }, ipc)
await output(json, ipc.dump({ id: Bare.pid, link, dir, dryRun, checkout, force }), { ask }, ipc)
}
39 changes: 0 additions & 39 deletions cmd/encryption-key.js

This file was deleted.

13 changes: 0 additions & 13 deletions cmd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const runners = {
sidecar: require('./sidecar'),
gc: require('./gc'),
run: require('./run'),
encryptionKey: require('./encryption-key'),
versions: require('./versions')
}

Expand Down Expand Up @@ -62,7 +61,6 @@ module.exports = async (ipc, argv = Bare.argv.slice(1)) => {
flag('--name <name>', 'Advanced. Override app name'),
flag('--no-ask', 'Suppress permissions dialogs'),
flag('--json', 'Newline delimited JSON output'),
flag('--encryption-key <name>', 'Application encryption key').hide(),
runners.seed(ipc)
)

Expand All @@ -78,7 +76,6 @@ module.exports = async (ipc, argv = Bare.argv.slice(1)) => {
flag('--name <name>', 'Advanced. Override app name'),
flag('--json', 'Newline delimited JSON output'),
flag('--no-ask', 'Suppress permissions dialogs'),
flag('--encryption-key <name>', 'Application encryption key').hide(),
runners.stage(ipc)
)

Expand Down Expand Up @@ -113,7 +110,6 @@ module.exports = async (ipc, argv = Bare.argv.slice(1)) => {
flag('--key', 'View key only'),
flag('--json', 'Newline delimited JSON output'),
flag('--no-ask', 'Suppress permissions dialogs'),
flag('--encryption-key <name>', 'Application encryption key').hide(),
runners.info(ipc)
)

Expand All @@ -127,7 +123,6 @@ module.exports = async (ipc, argv = Bare.argv.slice(1)) => {
flag('--json', 'Newline delimited JSON output'),
flag('--force|-f', 'Force overwrite existing files'),
flag('--no-ask', 'Suppress permissions dialogs'),
flag('--encryption-key <name>', 'Application encryption key').hide(),
runners.dump(ipc)
)

Expand Down Expand Up @@ -186,13 +181,6 @@ module.exports = async (ipc, argv = Bare.argv.slice(1)) => {
else console.log(cmd.overview({ full: true }))
})

const encryptionKey = command(
'encryption-key',
command('add', arg('<name>'), arg('<secret>'), (cmd) => runners.encryptionKey(ipc).add(cmd)),
command('remove', arg('<name>'), (cmd) => runners.encryptionKey(ipc).remove(cmd)),
command('generate', (cmd) => runners.encryptionKey(ipc).generate(cmd))
).hide()

const cmd = command('pear',
...def.pear,
header(usage.header),
Expand All @@ -208,7 +196,6 @@ module.exports = async (ipc, argv = Bare.argv.slice(1)) => {
shift,
sidecar,
gc,
encryptionKey,
versions,
help,
footer(usage.footer),
Expand Down
3 changes: 1 addition & 2 deletions cmd/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const output = outputter('info', {
})

module.exports = (ipc) => async function info (cmd) {
const { json, changelog, fullChangelog: full, metadata, key: showKey, encryptionKey } = cmd.flags
const { json, changelog, fullChangelog: full, metadata, key: showKey } = cmd.flags
const isKey = cmd.args.link && parseLink(cmd.args.link).drive.key !== null
const channel = isKey ? null : cmd.args.link
const link = isKey ? cmd.args.link : null
Expand All @@ -71,7 +71,6 @@ module.exports = (ipc) => async function info (cmd) {
metadata,
changelog,
full,
encryptionKey,
cmdArgs: Bare.argv.slice(1)
}), { ask: cmd.flags.ask }, ipc)
}
4 changes: 2 additions & 2 deletions cmd/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ module.exports = (ipc) => async function seed (cmd) {
const isKey = parseLink(cmd.args.channel).drive.key !== null
const channel = isKey ? null : cmd.args.channel
const link = isKey ? cmd.args.channel : null
let { name, encryptionKey } = cmd.flags
let { name } = cmd.flags
if (!name && !link) {
const pkg = JSON.parse(await readFile(join(dir, 'package.json')))
name = pkg.pear?.name || pkg.name
}
const id = Bare.pid

await output(json, ipc.seed({ id, name, channel, link, verbose, seeders, dir, encryptionKey, cmdArgs: Bare.argv.slice(1) }), { ask }, ipc)
await output(json, ipc.seed({ id, name, channel, link, verbose, seeders, dir, cmdArgs: Bare.argv.slice(1) }), { ask }, ipc)
}
4 changes: 2 additions & 2 deletions cmd/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ const output = outputter('stage', {
})

module.exports = (ipc) => async function stage (cmd) {
const { dryRun, bare, json, ignore, name, truncate, encryptionKey } = cmd.flags
const { dryRun, bare, json, ignore, name, truncate } = cmd.flags
const isKey = cmd.args.channel && parseLink(cmd.args.channel).drive.key !== null
const channel = isKey ? null : cmd.args.channel
const key = isKey ? cmd.args.channel : null
if (!channel && !key) throw ERR_INVALID_INPUT('A key or the channel name must be specified.')
let { dir = os.cwd() } = cmd.args
if (isAbsolute(dir) === false) dir = dir ? resolve(os.cwd(), dir) : os.cwd()
const id = Bare.pid
await output(json, ipc.stage({ id, channel, key, dir, encryptionKey, dryRun, bare, ignore, name, truncate, cmdArgs: Bare.argv.slice(1) }), { ask: cmd.flags.ask }, ipc)
await output(json, ipc.stage({ id, channel, key, dir, dryRun, bare, ignore, name, truncate, cmdArgs: Bare.argv.slice(1) }), { ask: cmd.flags.ask }, ipc)
}
2 changes: 0 additions & 2 deletions def/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ module.exports = [
flag('--links <kvs>', 'Override configured links with comma-separated key-values'),
flag('--chrome-webrtc-internals', 'Enable chrome://webrtc-internals'),
flag('--unsafe-clear-app-storage', 'Clear app storage'),
flag('--unsafe-clear-preferences', 'Clear preferences (such as trustlist)'),
flag('--appling <path>', 'Set application shell path'),
flag('--checkout <n|release|staged>', 'Run a checkout from version length'),
flag('--detached', 'Wakeup existing app or run detached'),
flag('--no-ask', 'Suppress permissions dialog'),
flag('--dht-bootstrap <nodes>', 'DHT boostrap').hide(),
flag('--encryption-key <name>', 'Application encryption key').hide(),
flag('--trusted').hide(),
flag('--detach').hide(),
flag('--swap <path>').hide(),
Expand Down
15 changes: 14 additions & 1 deletion hyperdb/db/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
"offset": 0,
"schema": [
{
"name": "dht",
"name": "bundle",
"namespace": "pear",
"id": 0,
"type": 1,
"indexes": [],
"schema": "@pear/bundle",
"derived": false,
"key": [
"link"
],
"trigger": null
},
{
"name": "dht",
"namespace": "pear",
"id": 1,
"type": 1,
"indexes": [],
"schema": "@pear/dht",
"derived": false,
"key": [],
Expand Down
81 changes: 68 additions & 13 deletions hyperdb/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,40 @@ const { IndexEncoder, c } = require('hyperdb/runtime')

const { version, resolveStruct } = require('./messages.js')

// '@pear/dht' collection key
// '@pear/bundle' collection key
const collection0_key = new IndexEncoder([
IndexEncoder.STRING
], { prefix: 0 })

function collection0_indexify (record) {
return []
const a = record.link
return a === undefined ? [] : [a]
}

// '@pear/dht' reconstruction function
// '@pear/bundle' reconstruction function
function collection0_reconstruct (version, keyBuf, valueBuf) {
const value = c.decode(resolveStruct('@pear/dht/value', version), valueBuf)
return value
const key = collection0_key.decode(keyBuf)
const value = c.decode(resolveStruct('@pear/bundle/value', version), valueBuf)
// TODO: This should be fully code generated
return {
link: key[0],
...value
}
}
// '@pear/dht' key reconstruction function
// '@pear/bundle' key reconstruction function
function collection0_reconstruct_key (keyBuf) {
return {}
const key = collection0_key.decode(keyBuf)
return {
link: key[0]
}
}

// '@pear/dht'
// '@pear/bundle'
const collection0 = {
name: '@pear/dht',
name: '@pear/bundle',
id: 0,
encodeKey (record) {
const key = []
const key = [record.link]
return collection0_key.encode(key)
},
encodeKeyRange ({ gt, lt, gte, lte } = {}) {
Expand All @@ -40,18 +50,62 @@ const collection0 = {
})
},
encodeValue (version, record) {
return c.encode(resolveStruct('@pear/dht/value', version), record)
return c.encode(resolveStruct('@pear/bundle/value', version), record)
},
trigger: null,
reconstruct: collection0_reconstruct,
reconstructKey: collection0_reconstruct_key,
indexes: []
}

// '@pear/dht' collection key
const collection1_key = new IndexEncoder([
], { prefix: 1 })

function collection1_indexify (record) {
return []
}

// '@pear/dht' reconstruction function
function collection1_reconstruct (version, keyBuf, valueBuf) {
const value = c.decode(resolveStruct('@pear/dht/value', version), valueBuf)
return value
}
// '@pear/dht' key reconstruction function
function collection1_reconstruct_key (keyBuf) {
return {}
}

// '@pear/dht'
const collection1 = {
name: '@pear/dht',
id: 1,
encodeKey (record) {
const key = []
return collection1_key.encode(key)
},
encodeKeyRange ({ gt, lt, gte, lte } = {}) {
return collection1_key.encodeRange({
gt: gt ? collection1_indexify(gt) : null,
lt: lt ? collection1_indexify(lt) : null,
gte: gte ? collection1_indexify(gte) : null,
lte: lte ? collection1_indexify(lte) : null
})
},
encodeValue (version, record) {
return c.encode(resolveStruct('@pear/dht/value', version), record)
},
trigger: null,
reconstruct: collection1_reconstruct,
reconstructKey: collection1_reconstruct_key,
indexes: []
}

module.exports = {
version,
collections: [
collection0
collection0,
collection1
],
indexes: [
],
Expand All @@ -61,7 +115,8 @@ module.exports = {

function resolveCollection (name) {
switch (name) {
case '@pear/dht': return collection0
case '@pear/bundle': return collection0
case '@pear/dht': return collection1
default: return null
}
}
Expand Down
Loading
Loading