flbrowser-core 0.1.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 ADDED
@@ -0,0 +1,108 @@
1
+ # @danu/danu
2
+
3
+ Browser library for Fledger network, compiled to WebAssembly.
4
+
5
+ ## Installation
6
+
7
+ For local development:
8
+ ```bash
9
+ npm install file:../package/pkg
10
+ ```
11
+
12
+ When published:
13
+ ```bash
14
+ npm install @danu/danu
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```typescript
20
+ import init, { FlNode, initialize } from '@danu/danu';
21
+
22
+ // Initialize WASM module
23
+ await init();
24
+
25
+ // Set up logging and panic hooks
26
+ initialize();
27
+
28
+ // Create a node instance
29
+ const node = new FlNode();
30
+
31
+ // Connect to signal server
32
+ await node.connect('wss://signal.fledg.re');
33
+
34
+ // Get connection status
35
+ const status = node.get_connection_status();
36
+ console.log(status);
37
+
38
+ // Get statistics
39
+ const stats = node.get_stats();
40
+ console.log(stats);
41
+
42
+ // Set up event listener for asynchronous events
43
+ node.set_event_listener((event) => {
44
+ console.log('Event:', event.type, event.data);
45
+
46
+ switch (event.type) {
47
+ case 'connecting':
48
+ console.log('Connecting to:', event.data.signal_server);
49
+ break;
50
+ case 'connected':
51
+ console.log('Connected!');
52
+ break;
53
+ case 'message':
54
+ console.log('Message received:', event.data);
55
+ break;
56
+ // ... handle other events
57
+ }
58
+ });
59
+
60
+ // Remove event listener when done
61
+ node.remove_event_listener();
62
+ ```
63
+
64
+ ## Event System
65
+
66
+ The package emits events for asynchronous operations. Set up a listener to receive them:
67
+
68
+ ```typescript
69
+ node.set_event_listener((event: { type: string, data: any }) => {
70
+ // Handle events
71
+ });
72
+ ```
73
+
74
+ **Common Event Types:**
75
+ - `connecting` - Connection attempt started
76
+ - `connected` - Successfully connected
77
+ - `disconnected` - Connection closed
78
+ - `message` - Message received from peer
79
+ - `peer_joined` - Peer joined the network
80
+ - `peer_left` - Peer left the network
81
+ - `error` - An error occurred
82
+ ```
83
+
84
+ ## Building
85
+
86
+ ```bash
87
+ # Development build
88
+ make build
89
+
90
+ # Production build
91
+ make build-release
92
+
93
+ # Clean build artifacts
94
+ make clean
95
+
96
+ # Create npm package
97
+ make pack
98
+ ```
99
+
100
+ ## Requirements
101
+
102
+ - Rust toolchain
103
+ - wasm-pack (`cargo install wasm-pack`)
104
+ - Node.js >= 18
105
+
106
+ ## License
107
+
108
+ MIT OR Apache-2.0
@@ -0,0 +1,201 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * The `ReadableStreamType` enum.
5
+ *
6
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
7
+ */
8
+
9
+ type ReadableStreamType = "bytes";
10
+
11
+ /**
12
+ * Main DaNode interface for browser
13
+ */
14
+ export class DaNode {
15
+ private constructor();
16
+ free(): void;
17
+ [Symbol.dispose](): void;
18
+ /**
19
+ * Add an event listener callback
20
+ * The callback will be called with events in the format: { type: string, data: any }
21
+ * Returns a ListenerId that can be used to remove this specific listener
22
+ */
23
+ add_event_listener(callback: Function): ListenerId;
24
+ static from_config(cfg: NetConf): Promise<DaNode>;
25
+ /**
26
+ * Create a new DaNode instance
27
+ */
28
+ static from_default(): Promise<DaNode>;
29
+ get_realm(id: RealmID): Promise<DaRealm>;
30
+ /**
31
+ * Get basic statistics
32
+ */
33
+ get_stats(): any;
34
+ /**
35
+ * Remove a specific event listener by its ID
36
+ */
37
+ remove_event_listener(listener_id: ListenerId): void;
38
+ sync(): Promise<void>;
39
+ }
40
+
41
+ export class DaRealm {
42
+ private constructor();
43
+ free(): void;
44
+ [Symbol.dispose](): void;
45
+ get_path(path: string): string;
46
+ get_path_data(path: string, data: string): Uint8Array;
47
+ }
48
+
49
+ export class FloID {
50
+ private constructor();
51
+ free(): void;
52
+ [Symbol.dispose](): void;
53
+ toString(): string;
54
+ }
55
+
56
+ export class IntoUnderlyingByteSource {
57
+ private constructor();
58
+ free(): void;
59
+ [Symbol.dispose](): void;
60
+ cancel(): void;
61
+ pull(controller: ReadableByteStreamController): Promise<any>;
62
+ start(controller: ReadableByteStreamController): void;
63
+ readonly autoAllocateChunkSize: number;
64
+ readonly type: ReadableStreamType;
65
+ }
66
+
67
+ export class IntoUnderlyingSink {
68
+ private constructor();
69
+ free(): void;
70
+ [Symbol.dispose](): void;
71
+ abort(reason: any): Promise<any>;
72
+ close(): Promise<any>;
73
+ write(chunk: any): Promise<any>;
74
+ }
75
+
76
+ export class IntoUnderlyingSource {
77
+ private constructor();
78
+ free(): void;
79
+ [Symbol.dispose](): void;
80
+ cancel(): void;
81
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
82
+ }
83
+
84
+ /**
85
+ * Unique identifier for an event listener
86
+ */
87
+ export class ListenerId {
88
+ private constructor();
89
+ free(): void;
90
+ [Symbol.dispose](): void;
91
+ /**
92
+ * Get the numeric ID value
93
+ */
94
+ value(): number;
95
+ }
96
+
97
+ export class NetConf {
98
+ private constructor();
99
+ free(): void;
100
+ [Symbol.dispose](): void;
101
+ }
102
+
103
+ export enum NodeStatus {
104
+ ConnectSignal = 0,
105
+ ConnectedNodes = 1,
106
+ AvailableNodes = 2,
107
+ DisconnectSignal = 3,
108
+ DisconnectNodes = 4,
109
+ RealmAvailable = 5,
110
+ ReceivedFlo = 6,
111
+ }
112
+
113
+ export class RealmID {
114
+ private constructor();
115
+ free(): void;
116
+ [Symbol.dispose](): void;
117
+ toString(): string;
118
+ }
119
+
120
+ /**
121
+ * Initialize the WASM module with logging and panic hooks
122
+ */
123
+ export function initialize(): void;
124
+
125
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
126
+
127
+ export interface InitOutput {
128
+ readonly memory: WebAssembly.Memory;
129
+ readonly __wbg_danode_free: (a: number, b: number) => void;
130
+ readonly __wbg_darealm_free: (a: number, b: number) => void;
131
+ readonly __wbg_floid_free: (a: number, b: number) => void;
132
+ readonly __wbg_listenerid_free: (a: number, b: number) => void;
133
+ readonly __wbg_netconf_free: (a: number, b: number) => void;
134
+ readonly danode_add_event_listener: (a: number, b: any) => [number, number, number];
135
+ readonly danode_from_config: (a: number) => any;
136
+ readonly danode_from_default: () => any;
137
+ readonly danode_get_realm: (a: number, b: number) => any;
138
+ readonly danode_get_stats: (a: number) => any;
139
+ readonly danode_remove_event_listener: (a: number, b: number) => [number, number];
140
+ readonly danode_sync: (a: number) => any;
141
+ readonly darealm_get_path: (a: number, b: number, c: number) => [number, number, number, number];
142
+ readonly darealm_get_path_data: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
143
+ readonly floid_toString: (a: number) => [number, number];
144
+ readonly initialize: () => void;
145
+ readonly listenerid_value: (a: number) => number;
146
+ readonly realmid_toString: (a: number) => [number, number];
147
+ readonly __wbg_realmid_free: (a: number, b: number) => void;
148
+ readonly __wbg_intounderlyingbytesource_free: (a: number, b: number) => void;
149
+ readonly __wbg_intounderlyingsink_free: (a: number, b: number) => void;
150
+ readonly __wbg_intounderlyingsource_free: (a: number, b: number) => void;
151
+ readonly intounderlyingbytesource_autoAllocateChunkSize: (a: number) => number;
152
+ readonly intounderlyingbytesource_cancel: (a: number) => void;
153
+ readonly intounderlyingbytesource_pull: (a: number, b: any) => any;
154
+ readonly intounderlyingbytesource_start: (a: number, b: any) => void;
155
+ readonly intounderlyingbytesource_type: (a: number) => number;
156
+ readonly intounderlyingsink_abort: (a: number, b: any) => any;
157
+ readonly intounderlyingsink_close: (a: number) => any;
158
+ readonly intounderlyingsink_write: (a: number, b: any) => any;
159
+ readonly intounderlyingsource_cancel: (a: number) => void;
160
+ readonly intounderlyingsource_pull: (a: number, b: any) => any;
161
+ readonly wasm_bindgen__closure__destroy__ha917655cf973976a: (a: number, b: number) => void;
162
+ readonly wasm_bindgen__closure__destroy__h2072d9fd4fb6b987: (a: number, b: number) => void;
163
+ readonly wasm_bindgen__closure__destroy__hc77efcacde91f08c: (a: number, b: number) => void;
164
+ readonly wasm_bindgen__closure__destroy__h2e4299a9319bc03b: (a: number, b: number) => void;
165
+ readonly wasm_bindgen__convert__closures_____invoke__h4d8a9638d0e04172: (a: number, b: number, c: any, d: any) => void;
166
+ readonly wasm_bindgen__convert__closures_____invoke__h0d268f64b67d3868: (a: number, b: number, c: any) => void;
167
+ readonly wasm_bindgen__convert__closures_____invoke__h1f94d242aababef4: (a: number, b: number, c: any) => void;
168
+ readonly wasm_bindgen__convert__closures_____invoke__h8c172a5ae5173bf3: (a: number, b: number) => void;
169
+ readonly wasm_bindgen__convert__closures_____invoke__h2fda946b1c2a6d9b: (a: number, b: number) => void;
170
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
171
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
172
+ readonly __wbindgen_exn_store: (a: number) => void;
173
+ readonly __externref_table_alloc: () => number;
174
+ readonly __wbindgen_externrefs: WebAssembly.Table;
175
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
176
+ readonly __externref_drop_slice: (a: number, b: number) => void;
177
+ readonly __externref_table_dealloc: (a: number) => void;
178
+ readonly __wbindgen_start: () => void;
179
+ }
180
+
181
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
182
+
183
+ /**
184
+ * Instantiates the given `module`, which can either be bytes or
185
+ * a precompiled `WebAssembly.Module`.
186
+ *
187
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
188
+ *
189
+ * @returns {InitOutput}
190
+ */
191
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
192
+
193
+ /**
194
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
195
+ * for everything else, calls `WebAssembly.instantiate` directly.
196
+ *
197
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
198
+ *
199
+ * @returns {Promise<InitOutput>}
200
+ */
201
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;