Skip to content

Commit 919f05d

Browse files
committed
Release v0.8.0: Dynamic Reconfiguration, Leader Election, and Docs Refactor
1 parent e63ebda commit 919f05d

21 files changed

Lines changed: 332 additions & 151 deletions

docs/index.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,59 @@ layout: default
44

55
# EntglDb Node.js Documentation
66

7-
Welcome to the documentation for **EntglDb Node.js**.
7+
**EntglDb** is a decentralized, offline-first peer-to-peer database. This repository contains the **Node.js** implementation.
88

9-
## Active Versions
9+
## Installation
1010

11-
* [**v0.7.0 (Latest)**](https://www.entgldb.com/docs/v0.7.0) - *Hosted on EntglDb.com*
11+
```bash
12+
npm install @entgldb/core @entgldb/persistence-sqlite @entgldb/network
13+
```
14+
15+
## Getting Started
16+
17+
### 1. Initialize
18+
19+
```typescript
20+
import { EntglDb } from '@entgldb/core';
21+
import { SqlitePeerStore } from '@entgldb/persistence-sqlite';
22+
import { TcpSyncServer, UdpDiscoveryService } from '@entgldb/network';
23+
24+
const store = new SqlitePeerStore('my-db.sqlite');
25+
await store.initialize();
26+
27+
const db = new EntglDb(store);
28+
29+
// Network
30+
const discovery = new UdpDiscoveryService(db.nodeId, 25000);
31+
const server = new TcpSyncServer({
32+
store,
33+
nodeId: db.nodeId,
34+
port: 25000
35+
});
36+
37+
server.start();
38+
discovery.start();
39+
```
40+
41+
### 2. Save Data
42+
43+
```typescript
44+
await db.put('todos', 'todo-1', { title: 'Buy Milk' });
45+
```
46+
47+
### 3. Subscribe to Changes
48+
49+
```typescript
50+
db.on('change', (collections) => {
51+
console.log('Collections changed:', collections);
52+
});
53+
```
54+
55+
## Dynamic Reconfiguration (v0.8.0)
56+
57+
See [Dynamic Reconfiguration](https://github.com/EntglDb/EntglDb.Net/blob/main/docs/dynamic-reconfiguration.md) in the main documentation.
1258

1359
## Links
1460

61+
* [**Central Documentation**](https://github.com/EntglDb/EntglDb.Net/tree/main/docs) - Architecture, Protocol, and Concepts.
1562
* [GitHub Repository](https://github.com/EntglDb/EntglDb.NodeJs)

docs/v0.7.0/getting-started.md

Lines changed: 0 additions & 59 deletions
This file was deleted.

docs/v0.7.0/index.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/v0.7.0/querying.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@entgldb/core",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "EntglDb core database engine",
55
"repository": {
66
"type": "git",

packages/core/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ export type { HLCTimestamp, Document, OplogEntry } from '@entgldb/protocol';
1919
export * from './query/query-node';
2020
export * from './query/translator';
2121

22+
23+
// Network abstractions
24+
export * from './network/PeerNode';
25+
export * from './network/IDiscoveryService';
26+
export * from './network/PeerNodeConfigurationProvider';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { PeerNode } from './PeerNode';
2+
3+
export interface IDiscoveryService {
4+
start(): Promise<void>;
5+
stop(): Promise<void>;
6+
getActivePeers(): PeerNode[];
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export enum PeerType {
2+
LanDiscovered = 0,
3+
StaticRemote = 1,
4+
CloudRemote = 2
5+
}
6+
7+
export interface PeerNode {
8+
nodeId: string;
9+
host: string; // address in .NET
10+
port: number;
11+
lastSeen: Date;
12+
type: PeerType;
13+
}
14+
15+
export enum NodeRole {
16+
Member = 0,
17+
CloudGateway = 1
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export interface PeerNodeConfiguration {
2+
nodeId: string;
3+
tcpPort: number;
4+
// Add other config fields as needed matching .NET
5+
}
6+
7+
export type ConfigurationChangedHandler = (config: PeerNodeConfiguration) => void;
8+
9+
export interface IPeerNodeConfigurationProvider {
10+
getConfiguration(): Promise<PeerNodeConfiguration>;
11+
onConfigurationChanged(handler: ConfigurationChangedHandler): void;
12+
}
13+
14+
export class StaticPeerNodeConfigurationProvider implements IPeerNodeConfigurationProvider {
15+
private handlers: ConfigurationChangedHandler[] = [];
16+
17+
constructor(private configuration: PeerNodeConfiguration) { }
18+
19+
async getConfiguration(): Promise<PeerNodeConfiguration> {
20+
return this.configuration;
21+
}
22+
23+
onConfigurationChanged(handler: ConfigurationChangedHandler): void {
24+
this.handlers.push(handler);
25+
}
26+
27+
updateConfiguration(newConfig: PeerNodeConfiguration): void {
28+
this.configuration = newConfig;
29+
this.handlers.forEach(h => h(newConfig));
30+
}
31+
}

packages/core/src/storage/interface.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { HLCTimestamp, Document, OplogEntry } from '@entgldb/protocol';
2+
import { PeerNode } from '../network/PeerNode';
23
export type { OplogEntry };
34

45
/**
@@ -50,6 +51,21 @@ export interface IPeerStore {
5051
*/
5152
findDocuments(collection: string, query: any /* QueryNode */): Promise<Document[]>;
5253

54+
/**
55+
* Get all persistent remote peers
56+
*/
57+
getRemotePeers(): Promise<PeerNode[]>;
58+
59+
/**
60+
* Save a remote peer configuration
61+
*/
62+
saveRemotePeer(peer: PeerNode): Promise<void>;
63+
64+
/**
65+
* Remove a remote peer configuration
66+
*/
67+
removeRemotePeer(nodeId: string): Promise<void>;
68+
5369
/**
5470
* Close the store
5571
*/

0 commit comments

Comments
 (0)