Skip to content

Commit

Permalink
schema-builder fixes, HyperDB proper integration
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiRegiani committed Nov 5, 2024
1 parent 27d9e35 commit 9a54209
Show file tree
Hide file tree
Showing 7 changed files with 1,092 additions and 19 deletions.
25 changes: 7 additions & 18 deletions scripts/schema-builder.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const path = require('bare-path')
const { PLATFORM_DIR } = require('../constants')
const Hyperschema = require('hyperschema')
const HyperDB = require('@holepunchto/hyperdb/builder')
const Builder = require('@holepunchto/hyperdb/builder')

const SCHEMA_DIR = './schema'
const DB_DIR = path.join(PLATFORM_DIR, 'metrics.hyperdb')
const SCHEMA_DIR = './spec/schema'
const DB_DIR = './spec/db'

const schema = Hyperschema.from(SCHEMA_DIR)
const pearSchema = schema.namespace('pear')
Expand Down Expand Up @@ -78,13 +76,12 @@ pearSchema.register({

Hyperschema.toDisk(schema)

const db = HyperDB.from(SCHEMA_DIR, DB_DIR)
const db = Builder.from(SCHEMA_DIR, DB_DIR)
const pearDB = db.namespace('pear')

pearDB.collections.register({
name: 'dht-nodes',
schema: '@pear/dht-nodes',
key: ['host', 'port']
schema: '@pear/dht-nodes'
})

pearDB.collections.register({
Expand Down Expand Up @@ -137,15 +134,7 @@ pearDB.collections.register({

pearDB.collections.register({
name: 'perf-stats',
schema: '@pear/perf-stats',
key: ['uptimeSeconds', 'os']
schema: '@pear/perf-stats'
})

pearDB.indexes.register({
name: 'error-logs-by-type',
collection: '@pear/error-logs',
key: ['type', 'trace'],
unique: false
})

HyperDB.toDisk(db)
Builder.toDisk(db)
132 changes: 132 additions & 0 deletions spec/db/db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"version": 0,
"offset": 0,
"schema": [
{
"name": "dht-nodes",
"namespace": "pear",
"id": 0,
"type": 1,
"indexes": [],
"schema": "@pear/dht-nodes",
"derived": false,
"key": [],
"trigger": null
},
{
"name": "encryption-keys",
"namespace": "pear",
"id": 1,
"type": 1,
"indexes": [],
"schema": "@pear/encryption-keys",
"derived": false,
"key": [
"publicKey"
],
"trigger": null
},
{
"name": "permits",
"namespace": "pear",
"id": 2,
"type": 1,
"indexes": [],
"schema": "@pear/permits",
"derived": false,
"key": [
"z32"
],
"trigger": null
},
{
"name": "identity",
"namespace": "pear",
"id": 3,
"type": 1,
"indexes": [],
"schema": "@pear/identity",
"derived": false,
"key": [
"publicKey"
],
"trigger": null
},
{
"name": "apps",
"namespace": "pear",
"id": 4,
"type": 1,
"indexes": [],
"schema": "@pear/apps",
"derived": false,
"key": [
"key"
],
"trigger": null
},
{
"name": "apps-owned",
"namespace": "pear",
"id": 5,
"type": 1,
"indexes": [],
"schema": "@pear/apps-owned",
"derived": false,
"key": [
"key"
],
"trigger": null
},
{
"name": "app-storage",
"namespace": "pear",
"id": 6,
"type": 1,
"indexes": [],
"schema": "@pear/app-storage",
"derived": false,
"key": [
"app"
],
"trigger": null
},
{
"name": "channels",
"namespace": "pear",
"id": 7,
"type": 1,
"indexes": [],
"schema": "@pear/channels",
"derived": false,
"key": [
"key"
],
"trigger": null
},
{
"name": "error-logs",
"namespace": "pear",
"id": 8,
"type": 1,
"indexes": [],
"schema": "@pear/error-logs",
"derived": false,
"key": [
"type"
],
"trigger": null
},
{
"name": "perf-stats",
"namespace": "pear",
"id": 9,
"type": 1,
"indexes": [],
"schema": "@pear/perf-stats",
"derived": false,
"key": [],
"trigger": null
}
]
}
Loading

0 comments on commit 9a54209

Please sign in to comment.