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

HyperDB schema: instrumentation/metrics #399

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 14 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,22 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 https://github.com/actions/checkout/releases/tag/v4.1.1
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 https://github.com/actions/setup-node/releases/tag/v4.0.2
with:
node-version: lts/*
- name: Setup repo
uses: holepunchto/actions/.github/steps/setup-repo@v1

- name: Install w/ dev deps
run: npm install
- name: Install w/ dev deps
run: npm install
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Bootstrap
run: npm run bootstrap
- name: Bootstrap
run: npm run bootstrap

- name: Install Bare
run: npm i -g bare-runtime
- name: Install Bare
run: npm i -g bare-runtime

- name: Test
run: npm test
- name: Test
run: npm test

- name: Lint
run: npm run lint
- name: Lint
run: npm run lint
266 changes: 266 additions & 0 deletions output/hyperschema/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
// This file is autogenerated by the hyperschema compiler
// Schema Version: 1
/* eslint-disable camelcase */
/* eslint-disable quotes */

const VERSION = 1
const { c } = require('hyperschema/runtime')

// eslint-disable-next-line no-unused-vars
let version = VERSION

// @pear/dht-nodes
const encoding0 = {
preencode (state, m) {
c.string.preencode(state, m.host)
c.int.preencode(state, m.port)
},
encode (state, m) {
c.string.encode(state, m.host)
c.int.encode(state, m.port)
},
decode (state) {
const res = {}
res.host = null
res.port = 0

res.host = c.string.decode(state)
res.port = c.int.decode(state)

return res
}
}

// @pear/encryption-keys
const encoding1 = {
preencode (state, m) {
c.string.preencode(state, m.publicKey)
c.string.preencode(state, m.privateKey)
},
encode (state, m) {
c.string.encode(state, m.publicKey)
c.string.encode(state, m.privateKey)
},
decode (state) {
const res = {}
res.publicKey = null
res.privateKey = null

res.publicKey = c.string.decode(state)
res.privateKey = c.string.decode(state)

return res
}
}

// @pear/permits
const encoding2 = {
preencode (state, m) {
c.string.preencode(state, m.z32)
},
encode (state, m) {
c.string.encode(state, m.z32)
},
decode (state) {
const res = {}
res.z32 = null

res.z32 = c.string.decode(state)

return res
}
}

// @pear/identity
const encoding3 = {
preencode (state, m) {
let flags = 0
if (m.privateKey) flags |= 1

c.string.preencode(state, m.publicKey)
c.uint.preencode(state, flags)

if (m.privateKey) c.string.preencode(state, m.privateKey)
},
encode (state, m) {
let flags = 0
if (m.privateKey) flags |= 1

c.string.encode(state, m.publicKey)
c.uint.encode(state, flags)

if (m.privateKey) c.string.encode(state, m.privateKey)
},
decode (state) {
const res = {}
res.publicKey = null
res.privateKey = null

res.publicKey = c.string.decode(state)

const flags = state.start < state.end ? c.uint.decode(state) : 0
if ((flags & 1) !== 0) res.privateKey = c.string.decode(state)

return res
}
}

// @pear/apps
const encoding4 = {
preencode (state, m) {
c.string.preencode(state, m.key)
},
encode (state, m) {
c.string.encode(state, m.key)
},
decode (state) {
const res = {}
res.key = null

res.key = c.string.decode(state)

return res
}
}

// @pear/apps-owned
const encoding5 = {
preencode (state, m) {
c.string.preencode(state, m.key)
},
encode (state, m) {
c.string.encode(state, m.key)
},
decode (state) {
const res = {}
res.key = null

res.key = c.string.decode(state)

return res
}
}

// @pear/app-storage
const encoding6 = {
preencode (state, m) {
c.string.preencode(state, m.app)
},
encode (state, m) {
c.string.encode(state, m.app)
},
decode (state) {
const res = {}
res.app = null

res.app = c.string.decode(state)

return res
}
}

// @pear/channels
const encoding7 = {
preencode (state, m) {
c.string.preencode(state, m.key)
},
encode (state, m) {
c.string.encode(state, m.key)
},
decode (state) {
const res = {}
res.key = null

res.key = c.string.decode(state)

return res
}
}

// @pear/error-logs
const encoding8 = {
preencode (state, m) {
c.string.preencode(state, m.type)
c.string.preencode(state, m.trace)
},
encode (state, m) {
c.string.encode(state, m.type)
c.string.encode(state, m.trace)
},
decode (state) {
const res = {}
res.type = null
res.trace = null

res.type = c.string.decode(state)
res.trace = c.string.decode(state)

return res
}
}

// @pear/perf-stats
const encoding9 = {
preencode (state, m) {
c.int.preencode(state, m.uptimeSeconds)
c.float64.preencode(state, m.ramUsage)
c.float64.preencode(state, m.cpuUsage)
c.string.preencode(state, m.os)
},
encode (state, m) {
c.int.encode(state, m.uptimeSeconds)
c.float64.encode(state, m.ramUsage)
c.float64.encode(state, m.cpuUsage)
c.string.encode(state, m.os)
},
decode (state) {
const res = {}
res.uptimeSeconds = 0
res.ramUsage = 0
res.cpuUsage = 0
res.os = null

res.uptimeSeconds = c.int.decode(state)
res.ramUsage = c.float64.decode(state)
res.cpuUsage = c.float64.decode(state)
res.os = c.string.decode(state)

return res
}
}

function getStructByName (name) {
switch (name) {
case '@pear/dht-nodes': return encoding0
case '@pear/encryption-keys': return encoding1
case '@pear/permits': return encoding2
case '@pear/identity': return encoding3
case '@pear/apps': return encoding4
case '@pear/apps-owned': return encoding5
case '@pear/app-storage': return encoding6
case '@pear/channels': return encoding7
case '@pear/error-logs': return encoding8
case '@pear/perf-stats': return encoding9
default: throw new Error('Encoder not found ' + name)
}
}

function resolveStruct (name, v = VERSION) {
const enc = getStructByName(name)
return {
preencode (state, m) {
version = v
enc.preencode(state, m)
},
encode (state, m) {
version = v
enc.encode(state, m)
},
decode (state) {
version = v
return enc.decode(state)
}
}
}

module.exports = { resolveStruct, version }
Loading
Loading