@protoc-gen-go-wasmjs/runtime 0.0.14

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.
@@ -0,0 +1,169 @@
1
+ import { BrowserServiceManager } from '../browser/index.mjs';
2
+
3
+ /**
4
+ * WASM Response interface for all service calls
5
+ */
6
+ interface WASMResponse<T = any> {
7
+ success: boolean;
8
+ message: string;
9
+ data: T;
10
+ }
11
+ /**
12
+ * Error class for WASM-specific errors
13
+ */
14
+ declare class WasmError extends Error {
15
+ readonly methodPath?: string | undefined;
16
+ constructor(message: string, methodPath?: string | undefined);
17
+ }
18
+
19
+ /**
20
+ * Base WASM service client containing all non-template-dependent logic
21
+ */
22
+ declare abstract class WASMServiceClient {
23
+ protected wasm: any;
24
+ protected wasmLoadPromise: Promise<void> | null;
25
+ protected browserServiceManager: BrowserServiceManager | null;
26
+ constructor();
27
+ /**
28
+ * Register a browser service implementation
29
+ * Can be used to register browser services from any package
30
+ */
31
+ registerBrowserService(name: string, implementation: any): void;
32
+ /**
33
+ * Check if WASM is ready for operations
34
+ */
35
+ isReady(): boolean;
36
+ /**
37
+ * Wait for WASM to be ready (use during initialization)
38
+ */
39
+ waitUntilReady(): Promise<void>;
40
+ /**
41
+ * Internal method to call WASM functions with JSON conversion
42
+ */
43
+ callMethod<TRequest, TResponse>(methodPath: string, request: TRequest): Promise<TResponse>;
44
+ /**
45
+ * Internal method to call async WASM functions with callback
46
+ */
47
+ callMethodWithCallback<TRequest>(methodPath: string, request: TRequest, callback: (response: any, error?: string) => void): Promise<void>;
48
+ /**
49
+ * Internal method to call server streaming WASM functions
50
+ */
51
+ callStreamingMethod<TRequest, TResponse>(methodPath: string, request: TRequest, callback: (response: TResponse | null, error: string | null, done: boolean) => boolean): void;
52
+ /**
53
+ * Ensure WASM module is loaded (synchronous version for service calls)
54
+ */
55
+ protected ensureWASMLoaded(): void;
56
+ /**
57
+ * Load the WASM module asynchronously
58
+ */
59
+ loadWasm(wasmPath: string): Promise<void>;
60
+ /**
61
+ * Load the WASM module implementation (implemented by subclasses)
62
+ * This is abstract because it contains template-specific logic
63
+ */
64
+ protected abstract loadWASMModule(wasmPath: string): Promise<void>;
65
+ /**
66
+ * Abstract method for getting WASM method function by path
67
+ * Implementation depends on API structure (namespaced, flat, service_based)
68
+ */
69
+ protected abstract getWasmMethod(methodPath: string): Function;
70
+ }
71
+
72
+ /**
73
+ * Configuration for API structure and bundle behavior
74
+ */
75
+ interface WASMBundleConfig {
76
+ moduleName: string;
77
+ apiStructure: 'namespaced' | 'flat' | 'service_based';
78
+ jsNamespace: string;
79
+ }
80
+ /**
81
+ * WASM Bundle - manages loading and shared access to a WASM module
82
+ * One bundle per WASM file, shared by multiple service clients
83
+ */
84
+ declare class WASMBundle {
85
+ private wasm;
86
+ private wasmLoadPromise;
87
+ private browserServiceManager;
88
+ private config;
89
+ constructor(config: WASMBundleConfig);
90
+ /**
91
+ * Register a browser service implementation
92
+ */
93
+ registerBrowserService(name: string, implementation: any): void;
94
+ /**
95
+ * Check if WASM is ready for operations
96
+ */
97
+ isReady(): boolean;
98
+ /**
99
+ * Wait for WASM to be ready (use during initialization)
100
+ */
101
+ waitUntilReady(): Promise<void>;
102
+ /**
103
+ * Load the WASM module asynchronously (singleton pattern)
104
+ */
105
+ loadWasm(wasmPath: string): Promise<void>;
106
+ /**
107
+ * Get WASM method function by path
108
+ */
109
+ getWasmMethod(methodPath: string): Function;
110
+ /**
111
+ * Internal method to call WASM functions with JSON conversion
112
+ */
113
+ callMethod<TRequest, TResponse>(methodPath: string, request: TRequest): Promise<TResponse>;
114
+ /**
115
+ * Internal method to call async WASM functions with callback
116
+ */
117
+ callMethodWithCallback<TRequest>(methodPath: string, request: TRequest, callback: (response: any, error?: string) => void): Promise<void>;
118
+ /**
119
+ * Internal method to call server streaming WASM functions
120
+ */
121
+ callStreamingMethod<TRequest, TResponse>(methodPath: string, request: TRequest, callback: (response: TResponse | null, error: string | null, done: boolean) => boolean): void;
122
+ /**
123
+ * Ensure WASM module is loaded (synchronous version for service calls)
124
+ */
125
+ private ensureWASMLoaded;
126
+ /**
127
+ * Load the WASM module implementation
128
+ */
129
+ private loadWASMModule;
130
+ /**
131
+ * Check if WASM is pre-loaded (for testing)
132
+ */
133
+ private checkIfPreLoaded;
134
+ /**
135
+ * Verify WASM APIs are available after loading
136
+ */
137
+ private verifyWASMLoaded;
138
+ }
139
+
140
+ /**
141
+ * Base service client that references a shared WASM bundle
142
+ * Lightweight facade for service-specific method calls
143
+ */
144
+ declare abstract class ServiceClient {
145
+ protected bundle: WASMBundle;
146
+ constructor(bundle: WASMBundle);
147
+ /**
148
+ * Check if the underlying WASM bundle is ready
149
+ */
150
+ isReady(): boolean;
151
+ /**
152
+ * Wait for the underlying WASM bundle to be ready
153
+ */
154
+ waitUntilReady(): Promise<void>;
155
+ /**
156
+ * Call a synchronous WASM method
157
+ */
158
+ protected callMethod<TRequest, TResponse>(methodPath: string, request: TRequest): Promise<TResponse>;
159
+ /**
160
+ * Call an asynchronous WASM method with callback
161
+ */
162
+ protected callMethodWithCallback<TRequest>(methodPath: string, request: TRequest, callback: (response: any, error?: string) => void): Promise<void>;
163
+ /**
164
+ * Call a server streaming WASM method
165
+ */
166
+ protected callStreamingMethod<TRequest, TResponse>(methodPath: string, request: TRequest, callback: (response: TResponse | null, error: string | null, done: boolean) => boolean): void;
167
+ }
168
+
169
+ export { ServiceClient, WASMBundle, type WASMBundleConfig, type WASMResponse, WASMServiceClient, WasmError };
@@ -0,0 +1,169 @@
1
+ import { BrowserServiceManager } from '../browser/index.js';
2
+
3
+ /**
4
+ * WASM Response interface for all service calls
5
+ */
6
+ interface WASMResponse<T = any> {
7
+ success: boolean;
8
+ message: string;
9
+ data: T;
10
+ }
11
+ /**
12
+ * Error class for WASM-specific errors
13
+ */
14
+ declare class WasmError extends Error {
15
+ readonly methodPath?: string | undefined;
16
+ constructor(message: string, methodPath?: string | undefined);
17
+ }
18
+
19
+ /**
20
+ * Base WASM service client containing all non-template-dependent logic
21
+ */
22
+ declare abstract class WASMServiceClient {
23
+ protected wasm: any;
24
+ protected wasmLoadPromise: Promise<void> | null;
25
+ protected browserServiceManager: BrowserServiceManager | null;
26
+ constructor();
27
+ /**
28
+ * Register a browser service implementation
29
+ * Can be used to register browser services from any package
30
+ */
31
+ registerBrowserService(name: string, implementation: any): void;
32
+ /**
33
+ * Check if WASM is ready for operations
34
+ */
35
+ isReady(): boolean;
36
+ /**
37
+ * Wait for WASM to be ready (use during initialization)
38
+ */
39
+ waitUntilReady(): Promise<void>;
40
+ /**
41
+ * Internal method to call WASM functions with JSON conversion
42
+ */
43
+ callMethod<TRequest, TResponse>(methodPath: string, request: TRequest): Promise<TResponse>;
44
+ /**
45
+ * Internal method to call async WASM functions with callback
46
+ */
47
+ callMethodWithCallback<TRequest>(methodPath: string, request: TRequest, callback: (response: any, error?: string) => void): Promise<void>;
48
+ /**
49
+ * Internal method to call server streaming WASM functions
50
+ */
51
+ callStreamingMethod<TRequest, TResponse>(methodPath: string, request: TRequest, callback: (response: TResponse | null, error: string | null, done: boolean) => boolean): void;
52
+ /**
53
+ * Ensure WASM module is loaded (synchronous version for service calls)
54
+ */
55
+ protected ensureWASMLoaded(): void;
56
+ /**
57
+ * Load the WASM module asynchronously
58
+ */
59
+ loadWasm(wasmPath: string): Promise<void>;
60
+ /**
61
+ * Load the WASM module implementation (implemented by subclasses)
62
+ * This is abstract because it contains template-specific logic
63
+ */
64
+ protected abstract loadWASMModule(wasmPath: string): Promise<void>;
65
+ /**
66
+ * Abstract method for getting WASM method function by path
67
+ * Implementation depends on API structure (namespaced, flat, service_based)
68
+ */
69
+ protected abstract getWasmMethod(methodPath: string): Function;
70
+ }
71
+
72
+ /**
73
+ * Configuration for API structure and bundle behavior
74
+ */
75
+ interface WASMBundleConfig {
76
+ moduleName: string;
77
+ apiStructure: 'namespaced' | 'flat' | 'service_based';
78
+ jsNamespace: string;
79
+ }
80
+ /**
81
+ * WASM Bundle - manages loading and shared access to a WASM module
82
+ * One bundle per WASM file, shared by multiple service clients
83
+ */
84
+ declare class WASMBundle {
85
+ private wasm;
86
+ private wasmLoadPromise;
87
+ private browserServiceManager;
88
+ private config;
89
+ constructor(config: WASMBundleConfig);
90
+ /**
91
+ * Register a browser service implementation
92
+ */
93
+ registerBrowserService(name: string, implementation: any): void;
94
+ /**
95
+ * Check if WASM is ready for operations
96
+ */
97
+ isReady(): boolean;
98
+ /**
99
+ * Wait for WASM to be ready (use during initialization)
100
+ */
101
+ waitUntilReady(): Promise<void>;
102
+ /**
103
+ * Load the WASM module asynchronously (singleton pattern)
104
+ */
105
+ loadWasm(wasmPath: string): Promise<void>;
106
+ /**
107
+ * Get WASM method function by path
108
+ */
109
+ getWasmMethod(methodPath: string): Function;
110
+ /**
111
+ * Internal method to call WASM functions with JSON conversion
112
+ */
113
+ callMethod<TRequest, TResponse>(methodPath: string, request: TRequest): Promise<TResponse>;
114
+ /**
115
+ * Internal method to call async WASM functions with callback
116
+ */
117
+ callMethodWithCallback<TRequest>(methodPath: string, request: TRequest, callback: (response: any, error?: string) => void): Promise<void>;
118
+ /**
119
+ * Internal method to call server streaming WASM functions
120
+ */
121
+ callStreamingMethod<TRequest, TResponse>(methodPath: string, request: TRequest, callback: (response: TResponse | null, error: string | null, done: boolean) => boolean): void;
122
+ /**
123
+ * Ensure WASM module is loaded (synchronous version for service calls)
124
+ */
125
+ private ensureWASMLoaded;
126
+ /**
127
+ * Load the WASM module implementation
128
+ */
129
+ private loadWASMModule;
130
+ /**
131
+ * Check if WASM is pre-loaded (for testing)
132
+ */
133
+ private checkIfPreLoaded;
134
+ /**
135
+ * Verify WASM APIs are available after loading
136
+ */
137
+ private verifyWASMLoaded;
138
+ }
139
+
140
+ /**
141
+ * Base service client that references a shared WASM bundle
142
+ * Lightweight facade for service-specific method calls
143
+ */
144
+ declare abstract class ServiceClient {
145
+ protected bundle: WASMBundle;
146
+ constructor(bundle: WASMBundle);
147
+ /**
148
+ * Check if the underlying WASM bundle is ready
149
+ */
150
+ isReady(): boolean;
151
+ /**
152
+ * Wait for the underlying WASM bundle to be ready
153
+ */
154
+ waitUntilReady(): Promise<void>;
155
+ /**
156
+ * Call a synchronous WASM method
157
+ */
158
+ protected callMethod<TRequest, TResponse>(methodPath: string, request: TRequest): Promise<TResponse>;
159
+ /**
160
+ * Call an asynchronous WASM method with callback
161
+ */
162
+ protected callMethodWithCallback<TRequest>(methodPath: string, request: TRequest, callback: (response: any, error?: string) => void): Promise<void>;
163
+ /**
164
+ * Call a server streaming WASM method
165
+ */
166
+ protected callStreamingMethod<TRequest, TResponse>(methodPath: string, request: TRequest, callback: (response: TResponse | null, error: string | null, done: boolean) => boolean): void;
167
+ }
168
+
169
+ export { ServiceClient, WASMBundle, type WASMBundleConfig, type WASMResponse, WASMServiceClient, WasmError };