@vibecook/truffle-native 0.4.1 → 0.4.2

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
  *
@@ -127,6 +173,17 @@ export declare class NapiNode {
127
173
  * Multiple stores can coexist with different IDs.
128
174
  */
129
175
  syncedStore(storeId: string): NapiSyncedStore
176
+ /**
177
+ * Get a `NapiCrdtDoc` handle for CRDT document operations.
178
+ *
179
+ * Each call creates a new document instance with the given `doc_id`.
180
+ * The document syncs automatically with peers on namespace `"crdt:{doc_id}"`.
181
+ *
182
+ * This is intentionally **synchronous** (matching `synced_store()`).
183
+ * `CrdtDoc::new` is async and calls `tokio::spawn` internally; we enter
184
+ * the napi-rs managed Tokio runtime so the spawn hits a live reactor.
185
+ */
186
+ crdtDoc(docId: string): NapiCrdtDoc
130
187
  }
131
188
 
132
189
  /**
@@ -181,6 +238,14 @@ export declare class NapiSyncedStore {
181
238
  stop(): Promise<void>
182
239
  }
183
240
 
241
+ /** A CRDT document change event delivered to JS. */
242
+ export interface NapiCrdtDocEvent {
243
+ /** Event type: "local_change", "remote_change", "peer_synced", "peer_left". */
244
+ eventType: string
245
+ /** Peer identifier (present for remote_change, peer_synced, peer_left events). */
246
+ peerId?: string
247
+ }
248
+
184
249
  /** An incoming file offer from a remote peer. */
185
250
  export interface NapiFileOffer {
186
251
  /** Sender's stable `device_id` (ULID) from the RFC 017 hello envelope. */
package/index.js CHANGED
@@ -576,6 +576,7 @@ 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
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.2",
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