@vibecook/truffle-native 0.4.1 → 0.4.3

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/index.d.ts CHANGED
@@ -1,5 +1,51 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+ /**
4
+ * A CRDT document synchronized across the mesh, exposed to JavaScript.
5
+ *
6
+ * Obtained via `NapiNode.crdtDoc(docId)`. Each document wraps a Loro
7
+ * `LoroDoc` with automatic peer-to-peer sync.
8
+ */
9
+ export declare class NapiCrdtDoc {
10
+ /** Insert a key-value pair into a named map container. */
11
+ mapInsert(container: string, key: string, value: any): void
12
+ /** Delete a key from a named map container. */
13
+ mapDelete(container: string, key: string): void
14
+ /** Push a value to the end of a named list container. */
15
+ listPush(container: string, value: any): void
16
+ /** Insert a value at a specific index in a named list container. */
17
+ listInsert(container: string, index: number, value: any): void
18
+ /** Delete elements from a named list container. */
19
+ listDelete(container: string, index: number, len: number): void
20
+ /** Insert a string at a unicode position in a named text container. */
21
+ textInsert(container: string, pos: number, text: string): void
22
+ /** Delete text at a unicode position in a named text container. */
23
+ textDelete(container: string, pos: number, len: number): void
24
+ /** Increment a named counter container by the given value. */
25
+ counterIncrement(container: string, value: number): void
26
+ /** Get the deep JSON value of the entire document. */
27
+ getDeepValue(): any
28
+ /** Commit pending changes. Triggers sync to peers. */
29
+ commit(): void
30
+ /** The document identifier. */
31
+ docId(): string
32
+ /**
33
+ * Subscribe to document change events.
34
+ *
35
+ * The callback receives `NapiCrdtDocEvent` objects whenever a local
36
+ * change is applied, a remote change is received, or a peer syncs.
37
+ */
38
+ onChange(callback: (event: CrdtDocEvent) => void): void
39
+ /**
40
+ * Stop the document and cancel all event-forwarding tasks.
41
+ *
42
+ * # Safety
43
+ * This takes `&mut self` in an async context. The caller must ensure that
44
+ * no other calls are made on this NapiCrdtDoc while `stop()` is in progress.
45
+ */
46
+ stop(): Promise<void>
47
+ }
48
+
3
49
  /**
4
50
  * File transfer handle exposed to JavaScript.
5
51
  *
@@ -120,6 +166,8 @@ export declare class NapiNode {
120
166
  onMessage(namespace: string, callback: (msg: NamespacedMessage) => void): void
121
167
  /** Get a `NapiFileTransfer` handle for file transfer operations. */
122
168
  fileTransfer(): NapiFileTransfer
169
+ /** Get a `NapiProxy` handle for reverse proxy operations. */
170
+ proxy(): NapiProxy
123
171
  /**
124
172
  * Get a `NapiSyncedStore` handle for synchronized state operations.
125
173
  *
@@ -127,6 +175,17 @@ export declare class NapiNode {
127
175
  * Multiple stores can coexist with different IDs.
128
176
  */
129
177
  syncedStore(storeId: string): NapiSyncedStore
178
+ /**
179
+ * Get a `NapiCrdtDoc` handle for CRDT document operations.
180
+ *
181
+ * Each call creates a new document instance with the given `doc_id`.
182
+ * The document syncs automatically with peers on namespace `"crdt:{doc_id}"`.
183
+ *
184
+ * This is intentionally **synchronous** (matching `synced_store()`).
185
+ * `CrdtDoc::new` is async and calls `tokio::spawn` internally; we enter
186
+ * the napi-rs managed Tokio runtime so the spawn hits a live reactor.
187
+ */
188
+ crdtDoc(docId: string): NapiCrdtDoc
130
189
  }
131
190
 
132
191
  /**
@@ -142,6 +201,32 @@ export declare class NapiOfferResponder {
142
201
  reject(reason: string): Promise<void>
143
202
  }
144
203
 
204
+ /**
205
+ * Reverse proxy handle exposed to JavaScript.
206
+ *
207
+ * Obtained via `NapiNode.proxy()`. Holds an `Arc<Node>` to create
208
+ * fresh `Proxy` handles on each method call (the Rust `Proxy` borrows
209
+ * `&Node`, so we can't store it across JS boundaries).
210
+ */
211
+ export declare class NapiProxy {
212
+ /**
213
+ * Add a reverse proxy that forwards traffic from a TLS port on the mesh
214
+ * to a local target.
215
+ */
216
+ add(config: NapiProxyConfig): Promise<NapiProxyInfo>
217
+ /** Remove a reverse proxy by ID. */
218
+ remove(id: string): Promise<void>
219
+ /** List all active proxies on this node. */
220
+ list(): Promise<Array<NapiProxyInfo>>
221
+ /**
222
+ * Subscribe to proxy lifecycle events.
223
+ *
224
+ * The callback receives `NapiProxyEvent` objects whenever a proxy
225
+ * starts, stops, or encounters an error.
226
+ */
227
+ onEvent(callback: (event: NapiProxyEvent) => void): void
228
+ }
229
+
145
230
  /**
146
231
  * Synchronized store handle exposed to JavaScript.
147
232
  *
@@ -181,6 +266,14 @@ export declare class NapiSyncedStore {
181
266
  stop(): Promise<void>
182
267
  }
183
268
 
269
+ /** A CRDT document change event delivered to JS. */
270
+ export interface NapiCrdtDocEvent {
271
+ /** Event type: "local_change", "remote_change", "peer_synced", "peer_left". */
272
+ eventType: string
273
+ /** Peer identifier (present for remote_change, peer_synced, peer_left events). */
274
+ peerId?: string
275
+ }
276
+
184
277
  /** An incoming file offer from a remote peer. */
185
278
  export interface NapiFileOffer {
186
279
  /** Sender's stable `device_id` (ULID) from the RFC 017 hello envelope. */
@@ -354,6 +447,53 @@ export interface NapiPingResult {
354
447
  peerAddr?: string
355
448
  }
356
449
 
450
+ /** Configuration for adding a reverse proxy, received from JavaScript. */
451
+ export interface NapiProxyConfig {
452
+ /** Unique identifier (user-chosen or auto-generated). */
453
+ id: string
454
+ /** Human-readable name for the proxy. */
455
+ name: string
456
+ /** Port on which the proxy listens on the tailnet (NAPI uses i32). */
457
+ listenPort: number
458
+ /** Target host (default: "localhost"). */
459
+ targetHost?: string
460
+ /** Target port (the local service port). */
461
+ targetPort: number
462
+ /** Target scheme: "http" or "https" (default: "http"). */
463
+ targetScheme?: string
464
+ /** Whether to announce this proxy on the mesh for discovery (default: true). */
465
+ announce?: boolean
466
+ }
467
+
468
+ /** A proxy lifecycle event delivered to JavaScript. */
469
+ export interface NapiProxyEvent {
470
+ /** Event type: "started", "stopped", "error". */
471
+ eventType: string
472
+ /** Proxy ID. */
473
+ id: string
474
+ /** Fully qualified URL (present for "started" events). */
475
+ url?: string
476
+ /** Listen port (present for "started" events). */
477
+ listenPort?: number
478
+ /** Error code (present for "error" events). */
479
+ code?: string
480
+ /** Error message (present for "error" events). */
481
+ message?: string
482
+ }
483
+
484
+ /** Information about a running or configured proxy, returned to JavaScript. */
485
+ export interface NapiProxyInfo {
486
+ id: string
487
+ name: string
488
+ listenPort: number
489
+ targetHost: string
490
+ targetPort: number
491
+ targetScheme: string
492
+ url: string
493
+ /** Status: "starting", "running", "stopped", or "error: <message>". */
494
+ status: string
495
+ }
496
+
357
497
  /** A versioned slice of data owned by a single device. */
358
498
  export interface NapiSlice {
359
499
  /**
package/index.js CHANGED
@@ -576,7 +576,9 @@ if (!nativeBinding) {
576
576
  }
577
577
 
578
578
  module.exports = nativeBinding
579
+ module.exports.NapiCrdtDoc = nativeBinding.NapiCrdtDoc
579
580
  module.exports.NapiFileTransfer = nativeBinding.NapiFileTransfer
580
581
  module.exports.NapiNode = nativeBinding.NapiNode
581
582
  module.exports.NapiOfferResponder = nativeBinding.NapiOfferResponder
583
+ module.exports.NapiProxy = nativeBinding.NapiProxy
582
584
  module.exports.NapiSyncedStore = nativeBinding.NapiSyncedStore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibecook/truffle-native",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Mesh networking for local-first apps, built on Tailscale (native addon)",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
Binary file
Binary file
Binary file
Binary file
Binary file