beamdb 0.9.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/LICENSE +22 -0
- package/README.md +979 -0
- package/beam.d.ts +151 -0
- package/beam.js +837 -0
- package/beam_bg.wasm +0 -0
- package/package.json +33 -0
package/beam.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* JavaScript-facing BEAM API.
|
|
6
|
+
*
|
|
7
|
+
* Wraps a [`Node`] and exposes a simplified interface for browser use.
|
|
8
|
+
* Each `Beam` instance is an independent node in the P2P mesh.
|
|
9
|
+
*/
|
|
10
|
+
export class Beam {
|
|
11
|
+
free(): void;
|
|
12
|
+
[Symbol.dispose](): void;
|
|
13
|
+
/**
|
|
14
|
+
* Connects to a relay server via WebSocket.
|
|
15
|
+
*
|
|
16
|
+
* The connection is asynchronous — data will start flowing once the
|
|
17
|
+
* WebSocket handshake completes. You can call `put()` immediately;
|
|
18
|
+
* messages will be queued and sent once connected.
|
|
19
|
+
*
|
|
20
|
+
* # Arguments
|
|
21
|
+
*
|
|
22
|
+
* * `url` - WebSocket URL (e.g. `"wss://relay.example.com/ws"`)
|
|
23
|
+
*/
|
|
24
|
+
connect(url: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Reads the value at the given path once.
|
|
27
|
+
*
|
|
28
|
+
* Returns a `Promise` that resolves to the value (string) or `null`
|
|
29
|
+
* if not found within the timeout (default 66ms, matching Gun.js).
|
|
30
|
+
*
|
|
31
|
+
* ```js
|
|
32
|
+
* const val = await beam.get("chat.123");
|
|
33
|
+
* if (val) console.log("got:", val);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
get(path: string): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new BEAM node with in-memory storage.
|
|
39
|
+
*
|
|
40
|
+
* Data is lost when the page reloads. For persistence, use
|
|
41
|
+
* [`new_persistent()`](Self::new_persistent) instead.
|
|
42
|
+
*/
|
|
43
|
+
constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new BEAM node with IndexedDB persistent storage.
|
|
46
|
+
*
|
|
47
|
+
* Data survives page reloads. The IndexedDB database opens
|
|
48
|
+
* asynchronously — writes are buffered until the DB is ready,
|
|
49
|
+
* then flushed automatically.
|
|
50
|
+
*/
|
|
51
|
+
static new_persistent(): Beam;
|
|
52
|
+
/**
|
|
53
|
+
* Subscribes to child updates at the given path.
|
|
54
|
+
*
|
|
55
|
+
* Uses Gun.js `.on()` semantics: the callback fires for each child
|
|
56
|
+
* value under the path, not just the path's own value. For example,
|
|
57
|
+
* `beam.on("chat", cb)` fires for each message written to
|
|
58
|
+
* `chat.<timestamp>`.
|
|
59
|
+
*
|
|
60
|
+
* The subscription lives until `stop()` is called or the `Beam`
|
|
61
|
+
* instance is dropped.
|
|
62
|
+
*
|
|
63
|
+
* ```js
|
|
64
|
+
* beam.on("chat", (value) => {
|
|
65
|
+
* console.log("new message:", value);
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
on(path: string, callback: Function): void;
|
|
70
|
+
/**
|
|
71
|
+
* Writes a string value to the graph at the given path.
|
|
72
|
+
*
|
|
73
|
+
* # Arguments
|
|
74
|
+
*
|
|
75
|
+
* * `path` - Dot-separated path (e.g. `"chat.123"`)
|
|
76
|
+
* * `value` - String to store
|
|
77
|
+
*/
|
|
78
|
+
put(path: string, value: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* Writes a boolean value to the graph at the given path.
|
|
81
|
+
*/
|
|
82
|
+
put_bool(path: string, value: boolean): void;
|
|
83
|
+
/**
|
|
84
|
+
* Writes a null value to the graph at the given path.
|
|
85
|
+
*/
|
|
86
|
+
put_null(path: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Writes a numeric value to the graph at the given path.
|
|
89
|
+
*/
|
|
90
|
+
put_num(path: string, value: number): void;
|
|
91
|
+
/**
|
|
92
|
+
* Stops the node and closes all connections.
|
|
93
|
+
*/
|
|
94
|
+
stop(): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Entry point invoked by JavaScript in a worker.
|
|
99
|
+
*/
|
|
100
|
+
export function task_worker_entry_point(ptr: number): void;
|
|
101
|
+
|
|
102
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
103
|
+
|
|
104
|
+
export interface InitOutput {
|
|
105
|
+
readonly memory: WebAssembly.Memory;
|
|
106
|
+
readonly __wbg_beam_free: (a: number, b: number) => void;
|
|
107
|
+
readonly beam_connect: (a: number, b: number, c: number) => void;
|
|
108
|
+
readonly beam_get: (a: number, b: number, c: number) => number;
|
|
109
|
+
readonly beam_new: () => number;
|
|
110
|
+
readonly beam_new_persistent: () => number;
|
|
111
|
+
readonly beam_on: (a: number, b: number, c: number, d: number) => void;
|
|
112
|
+
readonly beam_put: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
113
|
+
readonly beam_put_bool: (a: number, b: number, c: number, d: number) => void;
|
|
114
|
+
readonly beam_put_null: (a: number, b: number, c: number) => void;
|
|
115
|
+
readonly beam_put_num: (a: number, b: number, c: number, d: number) => void;
|
|
116
|
+
readonly beam_stop: (a: number) => void;
|
|
117
|
+
readonly task_worker_entry_point: (a: number, b: number) => void;
|
|
118
|
+
readonly __wasm_bindgen_func_elem_1101: (a: number, b: number, c: number, d: number) => void;
|
|
119
|
+
readonly __wasm_bindgen_func_elem_1115: (a: number, b: number, c: number, d: number) => void;
|
|
120
|
+
readonly __wasm_bindgen_func_elem_234: (a: number, b: number, c: number) => void;
|
|
121
|
+
readonly __wasm_bindgen_func_elem_234_2: (a: number, b: number, c: number) => void;
|
|
122
|
+
readonly __wasm_bindgen_func_elem_234_3: (a: number, b: number, c: number) => void;
|
|
123
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
124
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
125
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
126
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
127
|
+
readonly __wbindgen_export5: (a: number, b: number) => void;
|
|
128
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
135
|
+
* a precompiled `WebAssembly.Module`.
|
|
136
|
+
*
|
|
137
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
138
|
+
*
|
|
139
|
+
* @returns {InitOutput}
|
|
140
|
+
*/
|
|
141
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
145
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
146
|
+
*
|
|
147
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
148
|
+
*
|
|
149
|
+
* @returns {Promise<InitOutput>}
|
|
150
|
+
*/
|
|
151
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|