@buley/dash 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -5
- package/dist/src/auth/manager.d.ts +8 -0
- package/dist/src/auth/manager.js +39 -0
- package/dist/src/engine/sqlite.d.ts +3 -0
- package/dist/src/engine/sqlite.js +24 -7
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +4 -0
- package/dist/src/schema/lens.d.ts +29 -0
- package/dist/src/schema/lens.js +122 -0
- package/dist/src/sync/hybrid-provider.d.ts +1 -0
- package/dist/src/sync/hybrid-provider.js +64 -26
- package/dist/src/sync/verify.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
- package/dist/src/sync/webtransport-provider.d.ts +0 -25
- package/dist/src/sync/webtransport-provider.js +0 -128
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buley/dash",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "The Local-First, AI-Native Database for the Web. Featuring WASM SQLite, Vector Embeddings, and MCP support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -35,8 +35,10 @@
|
|
|
35
35
|
"@modelcontextprotocol/sdk": "^0.6.0",
|
|
36
36
|
"@preact/signals-core": "^1.5.1",
|
|
37
37
|
"@sqlite.org/sqlite-wasm": "*",
|
|
38
|
+
"devonian": "^0.4.1",
|
|
38
39
|
"lib0": "^0.2.117",
|
|
39
40
|
"sqlite-vec": "^0.1.7-alpha.2",
|
|
41
|
+
"ucans": "^0.10.0",
|
|
40
42
|
"y-protocols": "^1.0.7",
|
|
41
43
|
"y-webrtc": "^10.3.0",
|
|
42
44
|
"yjs": "^13.6.29"
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as Y from 'yjs';
|
|
2
|
-
import { Observable } from 'lib0/observable';
|
|
3
|
-
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
4
|
-
export declare class WebTransportProvider extends Observable<string> {
|
|
5
|
-
private doc;
|
|
6
|
-
private transport;
|
|
7
|
-
private connected;
|
|
8
|
-
private url;
|
|
9
|
-
private roomName;
|
|
10
|
-
awareness: awarenessProtocol.Awareness;
|
|
11
|
-
private writer;
|
|
12
|
-
private reader;
|
|
13
|
-
constructor(url: string, roomName: string, doc: Y.Doc, { awareness }?: {
|
|
14
|
-
awareness?: awarenessProtocol.Awareness | undefined;
|
|
15
|
-
});
|
|
16
|
-
private connect;
|
|
17
|
-
private writeHandshake;
|
|
18
|
-
private sendSyncStep1;
|
|
19
|
-
private readLoop;
|
|
20
|
-
private handleMessage;
|
|
21
|
-
private send;
|
|
22
|
-
private onDocUpdate;
|
|
23
|
-
private onAwarenessUpdate;
|
|
24
|
-
destroy(): void;
|
|
25
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'lib0/observable';
|
|
2
|
-
import * as encoding from 'lib0/encoding';
|
|
3
|
-
import * as decoding from 'lib0/decoding';
|
|
4
|
-
import * as syncProtocol from 'y-protocols/sync';
|
|
5
|
-
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
6
|
-
export class WebTransportProvider extends Observable {
|
|
7
|
-
doc;
|
|
8
|
-
transport = null;
|
|
9
|
-
connected = false;
|
|
10
|
-
url;
|
|
11
|
-
roomName;
|
|
12
|
-
awareness;
|
|
13
|
-
writer = null;
|
|
14
|
-
reader = null;
|
|
15
|
-
constructor(url, roomName, doc, { awareness = new awarenessProtocol.Awareness(doc) } = {}) {
|
|
16
|
-
super();
|
|
17
|
-
this.url = url;
|
|
18
|
-
this.roomName = roomName;
|
|
19
|
-
this.doc = doc;
|
|
20
|
-
this.awareness = awareness;
|
|
21
|
-
this.doc.on('update', this.onDocUpdate.bind(this));
|
|
22
|
-
this.awareness.on('update', this.onAwarenessUpdate.bind(this));
|
|
23
|
-
this.connect();
|
|
24
|
-
}
|
|
25
|
-
async connect() {
|
|
26
|
-
try {
|
|
27
|
-
this.transport = new WebTransport(this.url);
|
|
28
|
-
await this.transport.ready;
|
|
29
|
-
this.connected = true;
|
|
30
|
-
this.emit('status', [{ status: 'connected' }]);
|
|
31
|
-
// Create a bidirectional stream for the session
|
|
32
|
-
// Protocol: Client initiates stream, sends room name, then sync starts
|
|
33
|
-
const stream = await this.transport.createBidirectionalStream();
|
|
34
|
-
this.writer = stream.writable;
|
|
35
|
-
this.reader = stream.readable;
|
|
36
|
-
this.writeHandshake(this.writer);
|
|
37
|
-
this.readLoop(this.reader);
|
|
38
|
-
// Start Sync
|
|
39
|
-
this.sendSyncStep1();
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
console.error('WebTransport connection failed', err);
|
|
43
|
-
this.connected = false;
|
|
44
|
-
this.emit('status', [{ status: 'disconnected' }]);
|
|
45
|
-
// Simple retry logic (exponential backoff could be added)
|
|
46
|
-
setTimeout(() => this.connect(), 3000);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async writeHandshake(writable) {
|
|
50
|
-
const writer = writable.getWriter();
|
|
51
|
-
// Simple handshake: Send Room Name length + Room Name string
|
|
52
|
-
// In a real protocol, use better encoding. Here we assume the server expects this.
|
|
53
|
-
const encoder = encoding.createEncoder();
|
|
54
|
-
encoding.writeVarString(encoder, this.roomName);
|
|
55
|
-
await writer.write(encoding.toUint8Array(encoder));
|
|
56
|
-
writer.releaseLock();
|
|
57
|
-
}
|
|
58
|
-
sendSyncStep1() {
|
|
59
|
-
const encoder = encoding.createEncoder();
|
|
60
|
-
encoding.writeVarUint(encoder, 0); // MessageType.Sync
|
|
61
|
-
syncProtocol.writeSyncStep1(encoder, this.doc);
|
|
62
|
-
this.send(encoding.toUint8Array(encoder));
|
|
63
|
-
}
|
|
64
|
-
async readLoop(readable) {
|
|
65
|
-
const reader = readable.getReader();
|
|
66
|
-
try {
|
|
67
|
-
while (true) {
|
|
68
|
-
const { value, done } = await reader.read();
|
|
69
|
-
if (done)
|
|
70
|
-
break;
|
|
71
|
-
if (value) {
|
|
72
|
-
this.handleMessage(value);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
console.error('Read loop error', e);
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
this.connected = false;
|
|
81
|
-
this.emit('status', [{ status: 'disconnected' }]);
|
|
82
|
-
reader.releaseLock();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
handleMessage(buf) {
|
|
86
|
-
const decoder = decoding.createDecoder(buf);
|
|
87
|
-
const messageType = decoding.readVarUint(decoder);
|
|
88
|
-
switch (messageType) {
|
|
89
|
-
case 0: // Sync
|
|
90
|
-
syncProtocol.readSyncMessage(decoder, encoding.createEncoder(), this.doc, this);
|
|
91
|
-
break;
|
|
92
|
-
case 1: // Awareness
|
|
93
|
-
awarenessProtocol.applyAwarenessUpdate(this.awareness, decoding.readVarUint8Array(decoder), this);
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async send(message) {
|
|
98
|
-
if (!this.writer || !this.connected)
|
|
99
|
-
return;
|
|
100
|
-
const writer = this.writer.getWriter();
|
|
101
|
-
await writer.write(message);
|
|
102
|
-
writer.releaseLock();
|
|
103
|
-
}
|
|
104
|
-
onDocUpdate(update, origin) {
|
|
105
|
-
if (origin === this)
|
|
106
|
-
return; // Ignore local updates applied from the network
|
|
107
|
-
const encoder = encoding.createEncoder();
|
|
108
|
-
encoding.writeVarUint(encoder, 0); // MessageType.Sync
|
|
109
|
-
syncProtocol.writeUpdate(encoder, update);
|
|
110
|
-
this.send(encoding.toUint8Array(encoder));
|
|
111
|
-
}
|
|
112
|
-
onAwarenessUpdate({ added, updated, removed }, origin) {
|
|
113
|
-
if (origin === this)
|
|
114
|
-
return;
|
|
115
|
-
const changedClients = added.concat(updated).concat(removed);
|
|
116
|
-
const encoder = encoding.createEncoder();
|
|
117
|
-
encoding.writeVarUint(encoder, 1); // MessageType.Awareness
|
|
118
|
-
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(this.awareness, changedClients));
|
|
119
|
-
this.send(encoding.toUint8Array(encoder));
|
|
120
|
-
}
|
|
121
|
-
destroy() {
|
|
122
|
-
this.transport?.close();
|
|
123
|
-
this.doc.off('update', this.onDocUpdate);
|
|
124
|
-
this.awareness.off('update', this.onAwarenessUpdate);
|
|
125
|
-
this.connected = false;
|
|
126
|
-
super.destroy();
|
|
127
|
-
}
|
|
128
|
-
}
|