@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.
package/LICENSE ADDED
@@ -0,0 +1,184 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity granting the License.
13
+
14
+ "Legal Entity" shall mean the union of the acting entity and all
15
+ other entities that control, are controlled by, or are under common
16
+ control with that entity. For the purposes of this definition,
17
+ "control" means (i) the power, direct or indirect, to cause the
18
+ direction or management of such entity, whether by contract or
19
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity
23
+ exercising permissions granted by this License.
24
+
25
+ "Source" shall mean the preferred form for making modifications,
26
+ including but not limited to software source code, documentation
27
+ source, and configuration files.
28
+
29
+ "Object" shall mean any form resulting from mechanical
30
+ transformation or translation of a Source form, including but
31
+ not limited to compiled object code, generated documentation,
32
+ and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or
35
+ Object form, made available under the License, as indicated by a
36
+ copyright notice that is included in or attached to the work
37
+ (which shall not include communications that are clearly marked or
38
+ otherwise designated in writing by the copyright owner as "Not a Work").
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based upon (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and derivative works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control
57
+ systems, and issue tracking systems that are managed by, or on behalf
58
+ of, the Licensor for the purpose of discussing and improving the Work,
59
+ but excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to use, reproduce, modify, distribute, prepare
70
+ Derivative Works of, publicly display, publicly perform, sublicense,
71
+ and distribute the Work and such Derivative Works in Source or Object
72
+ form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of this
75
+ License, each Contributor hereby grants to You a perpetual, worldwide,
76
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in
77
+ this section) patent license to make, have made, use, offer to sell,
78
+ sell, import, and otherwise transfer the Work, where such license applies
79
+ only to those patent claims licensable by such Contributor that are
80
+ necessarily infringed by their Contribution(s) alone or by combination
81
+ of their Contribution(s) with the Work to which such Contribution(s)
82
+ was submitted. If You institute patent litigation against any entity
83
+ (including a cross-claim or counterclaim in a lawsuit) alleging that the
84
+ Work or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses granted to
86
+ You under this License for that Work shall terminate as of the date such
87
+ litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
90
+ Derivative Works thereof in any medium, with or without modifications,
91
+ and in Source or Object form, provided that You meet the following
92
+ conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative Works
95
+ a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works that You
101
+ distribute, all copyright, trademark, patent, and attribution
102
+ notices from the Source form of the Work, excluding those notices
103
+ that do not pertain to any part of the Derivative Works; and
104
+
105
+ (d) If the Work includes a "NOTICE" text file as part of its
106
+ distribution, then any Derivative Works that You distribute must
107
+ include a readable copy of the attribution notices contained
108
+ within such NOTICE file, excluding those notices that do not
109
+ pertain to any part of the Derivative Works, in at least one
110
+ of the following places: within a NOTICE text file distributed
111
+ as part of the Derivative Works; within the Source form or
112
+ documentation, if provided along with the Derivative Works; or,
113
+ within a display generated by the Derivative Works, if and
114
+ wherever such third-party notices normally appear. The contents
115
+ of the NOTICE file are for informational purposes only and
116
+ do not modify the License. You may add Your own attribution
117
+ notices within Derivative Works that You distribute, alongside
118
+ or as an addendum to the NOTICE text from the Work, provided
119
+ that such additional attribution notices cannot be construed
120
+ as modifying the License.
121
+
122
+ You may add Your own copyright notice to Your modifications and
123
+ may provide additional or different license terms and conditions
124
+ for use, reproduction, or distribution of Your modifications, or
125
+ for any such Derivative Works as a whole, provided Your use,
126
+ reproduction, and distribution of the Work otherwise complies with
127
+ the conditions stated in this License.
128
+
129
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
130
+ any Contribution intentionally submitted for inclusion in the Work
131
+ by You to the Licensor shall be under the terms and conditions of
132
+ this License, without any additional terms or conditions.
133
+ Notwithstanding the above, nothing herein shall supersede or modify
134
+ the terms of any separate license agreement you may have executed
135
+ with Licensor regarding such Contributions.
136
+
137
+ 6. Trademarks. This License does not grant permission to use the trade
138
+ names, trademarks, service marks, or product names of the Licensor,
139
+ except as required for reasonable and customary use in describing the
140
+ origin of the Work and reproducing the content of the NOTICE file.
141
+
142
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to
143
+ in writing, Licensor provides the Work (and each Contributor provides
144
+ its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
145
+ OF ANY KIND, either express or implied, including, without limitation,
146
+ any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY,
147
+ or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
148
+ determining the appropriateness of using or redistributing the Work and
149
+ assume any risks associated with Your exercise of permissions under this
150
+ License.
151
+
152
+ 8. Limitation of Liability. In no event and under no legal theory, whether
153
+ in tort (including negligence), contract, or otherwise, unless required
154
+ by applicable law (such as deliberate and grossly negligent acts) or
155
+ agreed to in writing, shall any Contributor be liable to You for damages,
156
+ including any direct, indirect, special, incidental, or consequential
157
+ damages of any character arising as a result of this License or out of
158
+ the use or inability to use the Work (including but not limited to
159
+ damages for loss of goodwill, work stoppage, computer failure or
160
+ malfunction, or any and all other commercial damages or losses), even
161
+ if such Contributor has been advised of the possibility of such damages.
162
+
163
+ 9. Termination. This License shall terminate automatically if You fail to
164
+ comply with any of its terms. However, if You cure such failure within
165
+ 30 days of becoming aware of the failure, then the rights granted by this
166
+ License are automatically reinstated. This License will also terminate
167
+ if You institute patent litigation against any entity alleging that the
168
+ Work directly or indirectly infringes any patent.
169
+
170
+ END OF TERMS AND CONDITIONS
171
+
172
+ Copyright 2025 Sri Panyam
173
+
174
+ Licensed under the Apache License, Version 2.0 (the "License");
175
+ you may not use this file except in compliance with the License.
176
+ You may obtain a copy of the License at
177
+
178
+ http://www.apache.org/licenses/LICENSE-2.0
179
+
180
+ Unless required by applicable law or agreed to in writing, software
181
+ distributed under the License is distributed on an "AS IS" BASIS,
182
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183
+ See the License for the specific language governing permissions and
184
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @protoc-gen-go-wasmjs/runtime
2
+
3
+ Runtime utilities for TypeScript code generated by [protoc-gen-go-wasmjs](https://github.com/panyam/protoc-gen-go-wasmjs).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @protoc-gen-go-wasmjs/runtime
9
+ # or
10
+ pnpm add @protoc-gen-go-wasmjs/runtime
11
+ # or
12
+ yarn add @protoc-gen-go-wasmjs/runtime
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ This package provides shared runtime utilities used by generated TypeScript clients. You typically don't need to import these directly - they're imported automatically by generated code.
18
+
19
+ ### Browser Service Manager
20
+
21
+ Handles WASM service calls in browser environments:
22
+
23
+ ```typescript
24
+ import { BrowserServiceManager } from '@protoc-gen-go-wasmjs/runtime/browser';
25
+
26
+ const manager = new BrowserServiceManager();
27
+ manager.registerService('MyService', myServiceImplementation);
28
+ await manager.startProcessing();
29
+ ```
30
+
31
+ ### Schema Types
32
+
33
+ Type definitions for protobuf schema handling:
34
+
35
+ ```typescript
36
+ import { FieldType, FieldSchema, MessageSchema } from '@protoc-gen-go-wasmjs/runtime/schema';
37
+ ```
38
+
39
+ ### Client Types
40
+
41
+ Common interfaces for WASM clients:
42
+
43
+ ```typescript
44
+ import { WASMResponse, WasmError } from '@protoc-gen-go-wasmjs/runtime/client';
45
+ ```
46
+
47
+ ### Factory Types
48
+
49
+ Interfaces for message factory patterns:
50
+
51
+ ```typescript
52
+ import { FactoryResult, FactoryInterface } from '@protoc-gen-go-wasmjs/runtime/types';
53
+ ```
54
+
55
+ ### Patch Types
56
+
57
+ Types for stateful proxy operations:
58
+
59
+ ```typescript
60
+ import { PatchOperation, MessagePatch, PatchBatch } from '@protoc-gen-go-wasmjs/runtime/types';
61
+ ```
62
+
63
+ ## Tree Shaking
64
+
65
+ This package is designed for optimal tree shaking. Import only what you need:
66
+
67
+ ```typescript
68
+ // Import everything (not recommended)
69
+ import * from '@protoc-gen-go-wasmjs/runtime';
70
+
71
+ // Import specific modules (recommended)
72
+ import { BrowserServiceManager } from '@protoc-gen-go-wasmjs/runtime/browser';
73
+ import { FieldType } from '@protoc-gen-go-wasmjs/runtime/schema';
74
+ ```
75
+
76
+ ## TypeScript Support
77
+
78
+ Full TypeScript support with complete type definitions included.
79
+
80
+ ## License
81
+
82
+ Apache-2.0
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Browser Service Manager
3
+ * Handles FIFO processing of browser service calls from WASM
4
+ * This is a shared component used by all WASM clients that interact with browser services
5
+ */
6
+ declare class BrowserServiceManager {
7
+ private processing;
8
+ private serviceImplementations;
9
+ private wasmModule;
10
+ constructor();
11
+ /**
12
+ * Register a browser service implementation
13
+ */
14
+ registerService(name: string, implementation: any): void;
15
+ /**
16
+ * Set the WASM module reference
17
+ */
18
+ setWasmModule(wasmModule: any): void;
19
+ /**
20
+ * Start processing browser service calls
21
+ */
22
+ startProcessing(): Promise<void>;
23
+ /**
24
+ * Process a single browser service call asynchronously
25
+ */
26
+ private processCall;
27
+ /**
28
+ * Stop processing browser service calls
29
+ */
30
+ stopProcessing(): void;
31
+ /**
32
+ * Get the next browser call from WASM
33
+ */
34
+ private getNextBrowserCall;
35
+ /**
36
+ * Deliver a response back to WASM (called internally)
37
+ */
38
+ private deliverBrowserResponse;
39
+ }
40
+
41
+ export { BrowserServiceManager };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Browser Service Manager
3
+ * Handles FIFO processing of browser service calls from WASM
4
+ * This is a shared component used by all WASM clients that interact with browser services
5
+ */
6
+ declare class BrowserServiceManager {
7
+ private processing;
8
+ private serviceImplementations;
9
+ private wasmModule;
10
+ constructor();
11
+ /**
12
+ * Register a browser service implementation
13
+ */
14
+ registerService(name: string, implementation: any): void;
15
+ /**
16
+ * Set the WASM module reference
17
+ */
18
+ setWasmModule(wasmModule: any): void;
19
+ /**
20
+ * Start processing browser service calls
21
+ */
22
+ startProcessing(): Promise<void>;
23
+ /**
24
+ * Process a single browser service call asynchronously
25
+ */
26
+ private processCall;
27
+ /**
28
+ * Stop processing browser service calls
29
+ */
30
+ stopProcessing(): void;
31
+ /**
32
+ * Get the next browser call from WASM
33
+ */
34
+ private getNextBrowserCall;
35
+ /**
36
+ * Deliver a response back to WASM (called internally)
37
+ */
38
+ private deliverBrowserResponse;
39
+ }
40
+
41
+ export { BrowserServiceManager };
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ // src/browser/service-manager.ts
4
+ var BrowserServiceManager = class {
5
+ constructor() {
6
+ this.processing = false;
7
+ this.serviceImplementations = /* @__PURE__ */ new Map();
8
+ }
9
+ /**
10
+ * Register a browser service implementation
11
+ */
12
+ registerService(name, implementation) {
13
+ this.serviceImplementations.set(name, implementation);
14
+ }
15
+ /**
16
+ * Set the WASM module reference
17
+ */
18
+ setWasmModule(wasmModule) {
19
+ this.wasmModule = wasmModule;
20
+ }
21
+ /**
22
+ * Start processing browser service calls
23
+ */
24
+ async startProcessing() {
25
+ if (this.processing) return;
26
+ this.processing = true;
27
+ while (this.processing) {
28
+ const call = this.getNextBrowserCall();
29
+ if (!call) {
30
+ await new Promise((resolve) => setTimeout(resolve, 10));
31
+ continue;
32
+ }
33
+ this.processCall(call);
34
+ }
35
+ }
36
+ /**
37
+ * Process a single browser service call asynchronously
38
+ */
39
+ async processCall(call) {
40
+ try {
41
+ const service = this.serviceImplementations.get(call.service);
42
+ if (!service) {
43
+ throw new Error(`No implementation registered for service: ${call.service}`);
44
+ }
45
+ const methodName = call.method.charAt(0).toLowerCase() + call.method.slice(1);
46
+ const method = service[methodName];
47
+ if (!method) {
48
+ throw new Error(`Method ${methodName} not found on service ${call.service}`);
49
+ }
50
+ const request = JSON.parse(call.request);
51
+ const response = await Promise.resolve(method.call(service, request));
52
+ console.log(`DEBUG: Browser service response for ${call.service}.${call.method}:`, response);
53
+ const jsonResponse = JSON.stringify(response);
54
+ console.log(`DEBUG: JSON stringified response:`, jsonResponse);
55
+ this.deliverBrowserResponse(call.id, jsonResponse, null);
56
+ } catch (error) {
57
+ this.deliverBrowserResponse(call.id, null, error.message || String(error));
58
+ }
59
+ }
60
+ /**
61
+ * Stop processing browser service calls
62
+ */
63
+ stopProcessing() {
64
+ this.processing = false;
65
+ }
66
+ /**
67
+ * Get the next browser call from WASM
68
+ */
69
+ getNextBrowserCall() {
70
+ if (typeof window.__wasmGetNextBrowserCall === "function") {
71
+ return window.__wasmGetNextBrowserCall();
72
+ }
73
+ return null;
74
+ }
75
+ /**
76
+ * Deliver a response back to WASM (called internally)
77
+ */
78
+ deliverBrowserResponse(callId, response, error) {
79
+ if (!window.__wasmDeliverBrowserResponse) {
80
+ return false;
81
+ }
82
+ return window.__wasmDeliverBrowserResponse(callId, response, error);
83
+ }
84
+ };
85
+
86
+ exports.BrowserServiceManager = BrowserServiceManager;
87
+ //# sourceMappingURL=index.js.map
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/browser/service-manager.ts"],"names":[],"mappings":";;;AAmBO,IAAM,wBAAN,MAA4B;AAAA,EAK/B,WAAA,GAAc;AAJd,IAAA,IAAA,CAAQ,UAAA,GAAa,KAAA;AACrB,IAAA,IAAA,CAAQ,sBAAA,uBAA6B,GAAA,EAAiB;AAAA,EAMtD;AAAA;AAAA;AAAA;AAAA,EAKA,eAAA,CAAgB,MAAc,cAAA,EAA2B;AACrD,IAAA,IAAA,CAAK,sBAAA,CAAuB,GAAA,CAAI,IAAA,EAAM,cAAc,CAAA;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKA,cAAc,UAAA,EAAuB;AACjC,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,eAAA,GAAiC;AACnC,IAAA,IAAI,KAAK,UAAA,EAAY;AACrB,IAAA,IAAA,CAAK,UAAA,GAAa,IAAA;AAGlB,IAAA,OAAO,KAAK,UAAA,EAAY;AACpB,MAAA,MAAM,IAAA,GAAO,KAAK,kBAAA,EAAmB;AACrC,MAAA,IAAI,CAAC,IAAA,EAAM;AAEP,QAAA,MAAM,IAAI,OAAA,CAAQ,CAAA,OAAA,KAAW,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC,CAAA;AACpD,Q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AA,EAAI,YAAA,EAAc,IAAI,CAAA;AAAA,IAC3D,SAAS,KAAA,EAAY;AAEjB,MAAA,IAAA,CAAK,sBAAA,CAAuB,KAAK,EAAA,EAAI,IAAA,EAAM,MAAM,OAAA,IAAW,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,IAC7E;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA,EAKA,cAAA,GAAuB;AACnB,IAAA,IAAA,CAAK,UAAA,GAAa,KAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKQ,kBAAA,GAA0B;AAE9B,IAAA,IAAI,OAAQ,MAAA,CAAe,wBAAA,KAA6B,UAAA,EAAY;AAChE,MAAA,OAAQ,OAAe,wBAAA,EAAyB;AAAA,IACpD;AACA,IAAA,OAAO,IAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKQ,sBAAA,CAAuB,MAAA,EAAgB,QAAA,EAAyB,KAAA,EAA+B;AACnG,IAAA,IAAI,CAAE,OAAe,4BAAA,EAA8B;AAC/C,MAAA,OAAO,KAAA;AAAA,IACX;AACA,IAAA,OAAQ,MAAA,CAAe,4BAAA,CAA6B,MAAA,EAAQ,QAAA,EAAU,KAAK,CAAA;AAAA,EAC/E;AACJ","file":"index.js","sourcesContent":["// Copyright 2025 Sri Panyam\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Browser Service Manager\n * Handles FIFO processing of browser service calls from WASM\n * This is a shared component used by all WASM clients that interact with browser services\n */\nexport class BrowserServiceManager {\n private processing = false;\n private serviceImplementations = new Map<string, any>();\n private wasmModule: any;\n\n constructor() {\n // WASM will set up the global functions __wasmGetNextBrowserCall and __wasmDeliverBrowserResponse\n // We'll just use them when they're available\n }\n\n /**\n * Register a browser service implementation\n */\n registerService(name: string, implementation: any): void {\n this.serviceImplementations.set(name, implementation);\n }\n\n /**\n * Set the WASM module reference\n */\n setWasmModule(wasmModule: any): void {\n this.wasmModule = wasmModule;\n }\n\n /**\n * Start processing browser service calls\n */\n async startProcessing(): Promise<void> {\n if (this.processing) return;\n this.processing = true;\n\n // Process calls in a loop\n while (this.processing) {\n const call = this.getNextBrowserCall();\n if (!call) {\n // No pending calls, wait a bit\n await new Promise(resolve => setTimeout(resolve, 10));\n continue;\n }\n\n // Process each call asynchronously without blocking the loop\n this.processCall(call);\n }\n }\n\n /**\n * Process a single browser service call asynchronously\n */\n private async processCall(call: any): Promise<void> {\n try {\n // Get the service implementation\n const service = this.serviceImplementations.get(call.service);\n if (!service) {\n throw new Error(`No implementation registered for service: ${call.service}`);\n }\n\n // Get the method\n const methodName = call.method.charAt(0).toLowerCase() + call.method.slice(1);\n const method = service[methodName];\n if (!method) {\n throw new Error(`Method ${methodName} not found on service ${call.service}`);\n }\n\n // Parse request\n const request = JSON.parse(call.request);\n\n // Call the method (auto-await if async)\n const response = await Promise.resolve(method.call(service, request));\n \n console.log(`DEBUG: Browser service response for ${call.service}.${call.method}:`, response);\n const jsonResponse = JSON.stringify(response);\n console.log(`DEBUG: JSON stringified response:`, jsonResponse);\n\n // Deliver response\n this.deliverBrowserResponse(call.id, jsonResponse, null);\n } catch (error: any) {\n // Deliver error\n this.deliverBrowserResponse(call.id, null, error.message || String(error));\n }\n }\n\n /**\n * Stop processing browser service calls\n */\n stopProcessing(): void {\n this.processing = false;\n }\n\n /**\n * Get the next browser call from WASM\n */\n private getNextBrowserCall(): any {\n // The __wasmGetNextBrowserCall function should be provided by WASM\n if (typeof (window as any).__wasmGetNextBrowserCall === 'function') {\n return (window as any).__wasmGetNextBrowserCall();\n }\n return null;\n }\n\n /**\n * Deliver a response back to WASM (called internally)\n */\n private deliverBrowserResponse(callId: string, response: string | null, error: string | null): boolean {\n if (!(window as any).__wasmDeliverBrowserResponse) {\n return false;\n }\n return (window as any).__wasmDeliverBrowserResponse(callId, response, error);\n }\n}\n"]}
@@ -0,0 +1,86 @@
1
+ // src/browser/service-manager.ts
2
+ var BrowserServiceManager = class {
3
+ constructor() {
4
+ this.processing = false;
5
+ this.serviceImplementations = /* @__PURE__ */ new Map();
6
+ }
7
+ /**
8
+ * Register a browser service implementation
9
+ */
10
+ registerService(name, implementation) {
11
+ this.serviceImplementations.set(name, implementation);
12
+ }
13
+ /**
14
+ * Set the WASM module reference
15
+ */
16
+ setWasmModule(wasmModule) {
17
+ this.wasmModule = wasmModule;
18
+ }
19
+ /**
20
+ * Start processing browser service calls
21
+ */
22
+ async startProcessing() {
23
+ if (this.processing) return;
24
+ this.processing = true;
25
+ while (this.processing) {
26
+ const call = this.getNextBrowserCall();
27
+ if (!call) {
28
+ await new Promise((resolve) => setTimeout(resolve, 10));
29
+ continue;
30
+ }
31
+ this.processCall(call);
32
+ }
33
+ }
34
+ /**
35
+ * Process a single browser service call asynchronously
36
+ */
37
+ async processCall(call) {
38
+ try {
39
+ const service = this.serviceImplementations.get(call.service);
40
+ if (!service) {
41
+ throw new Error(`No implementation registered for service: ${call.service}`);
42
+ }
43
+ const methodName = call.method.charAt(0).toLowerCase() + call.method.slice(1);
44
+ const method = service[methodName];
45
+ if (!method) {
46
+ throw new Error(`Method ${methodName} not found on service ${call.service}`);
47
+ }
48
+ const request = JSON.parse(call.request);
49
+ const response = await Promise.resolve(method.call(service, request));
50
+ console.log(`DEBUG: Browser service response for ${call.service}.${call.method}:`, response);
51
+ const jsonResponse = JSON.stringify(response);
52
+ console.log(`DEBUG: JSON stringified response:`, jsonResponse);
53
+ this.deliverBrowserResponse(call.id, jsonResponse, null);
54
+ } catch (error) {
55
+ this.deliverBrowserResponse(call.id, null, error.message || String(error));
56
+ }
57
+ }
58
+ /**
59
+ * Stop processing browser service calls
60
+ */
61
+ stopProcessing() {
62
+ this.processing = false;
63
+ }
64
+ /**
65
+ * Get the next browser call from WASM
66
+ */
67
+ getNextBrowserCall() {
68
+ if (typeof window.__wasmGetNextBrowserCall === "function") {
69
+ return window.__wasmGetNextBrowserCall();
70
+ }
71
+ return null;
72
+ }
73
+ /**
74
+ * Deliver a response back to WASM (called internally)
75
+ */
76
+ deliverBrowserResponse(callId, response, error) {
77
+ if (!window.__wasmDeliverBrowserResponse) {
78
+ return false;
79
+ }
80
+ return window.__wasmDeliverBrowserResponse(callId, response, error);
81
+ }
82
+ };
83
+
84
+ export { BrowserServiceManager };
85
+ //# sourceMappingURL=index.mjs.map
86
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/browser/service-manager.ts"],"names":[],"mappings":";AAmBO,IAAM,wBAAN,MAA4B;AAAA,EAK/B,WAAA,GAAc;AAJd,IAAA,IAAA,CAAQ,UAAA,GAAa,KAAA;AACrB,IAAA,IAAA,CAAQ,sBAAA,uBAA6B,GAAA,EAAiB;AAAA,EAMtD;AAAA;AAAA;AAAA;AAAA,EAKA,eAAA,CAAgB,MAAc,cAAA,EAA2B;AACrD,IAAA,IAAA,CAAK,sBAAA,CAAuB,GAAA,CAAI,IAAA,EAAM,cAAc,CAAA;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKA,cAAc,UAAA,EAAuB;AACjC,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,eAAA,GAAiC;AACnC,IAAA,IAAI,KAAK,UAAA,EAAY;AACrB,IAAA,IAAA,CAAK,UAAA,GAAa,IAAA;AAGlB,IAAA,OAAO,KAAK,UAAA,EAAY;AACpB,MAAA,MAAM,IAAA,GAAO,KAAK,kBAAA,EAAmB;AACrC,MAAA,IAAI,CAAC,IAAA,EAAM;AAEP,QAAA,MAAM,IAAI,OAAA,CAAQ,CAAA,OAAA,KAAW,UAAA,CAAW,OAA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AAK,sBAAA,CAAuB,IAAA,CAAK,EAAA,EAAI,YAAA,EAAc,IAAI,CAAA;AAAA,IAC3D,SAAS,KAAA,EAAY;AAEjB,MAAA,IAAA,CAAK,sBAAA,CAAuB,KAAK,EAAA,EAAI,IAAA,EAAM,MAAM,OAAA,IAAW,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,IAC7E;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA,EAKA,cAAA,GAAuB;AACnB,IAAA,IAAA,CAAK,UAAA,GAAa,KAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKQ,kBAAA,GAA0B;AAE9B,IAAA,IAAI,OAAQ,MAAA,CAAe,wBAAA,KAA6B,UAAA,EAAY;AAChE,MAAA,OAAQ,OAAe,wBAAA,EAAyB;AAAA,IACpD;AACA,IAAA,OAAO,IAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKQ,sBAAA,CAAuB,MAAA,EAAgB,QAAA,EAAyB,KAAA,EAA+B;AACnG,IAAA,IAAI,CAAE,OAAe,4BAAA,EAA8B;AAC/C,MAAA,OAAO,KAAA;AAAA,IACX;AACA,IAAA,OAAQ,MAAA,CAAe,4BAAA,CAA6B,MAAA,EAAQ,QAAA,EAAU,KAAK,CAAA;AAAA,EAC/E;AACJ","file":"index.mjs","sourcesContent":["// Copyright 2025 Sri Panyam\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Browser Service Manager\n * Handles FIFO processing of browser service calls from WASM\n * This is a shared component used by all WASM clients that interact with browser services\n */\nexport class BrowserServiceManager {\n private processing = false;\n private serviceImplementations = new Map<string, any>();\n private wasmModule: any;\n\n constructor() {\n // WASM will set up the global functions __wasmGetNextBrowserCall and __wasmDeliverBrowserResponse\n // We'll just use them when they're available\n }\n\n /**\n * Register a browser service implementation\n */\n registerService(name: string, implementation: any): void {\n this.serviceImplementations.set(name, implementation);\n }\n\n /**\n * Set the WASM module reference\n */\n setWasmModule(wasmModule: any): void {\n this.wasmModule = wasmModule;\n }\n\n /**\n * Start processing browser service calls\n */\n async startProcessing(): Promise<void> {\n if (this.processing) return;\n this.processing = true;\n\n // Process calls in a loop\n while (this.processing) {\n const call = this.getNextBrowserCall();\n if (!call) {\n // No pending calls, wait a bit\n await new Promise(resolve => setTimeout(resolve, 10));\n continue;\n }\n\n // Process each call asynchronously without blocking the loop\n this.processCall(call);\n }\n }\n\n /**\n * Process a single browser service call asynchronously\n */\n private async processCall(call: any): Promise<void> {\n try {\n // Get the service implementation\n const service = this.serviceImplementations.get(call.service);\n if (!service) {\n throw new Error(`No implementation registered for service: ${call.service}`);\n }\n\n // Get the method\n const methodName = call.method.charAt(0).toLowerCase() + call.method.slice(1);\n const method = service[methodName];\n if (!method) {\n throw new Error(`Method ${methodName} not found on service ${call.service}`);\n }\n\n // Parse request\n const request = JSON.parse(call.request);\n\n // Call the method (auto-await if async)\n const response = await Promise.resolve(method.call(service, request));\n \n console.log(`DEBUG: Browser service response for ${call.service}.${call.method}:`, response);\n const jsonResponse = JSON.stringify(response);\n console.log(`DEBUG: JSON stringified response:`, jsonResponse);\n\n // Deliver response\n this.deliverBrowserResponse(call.id, jsonResponse, null);\n } catch (error: any) {\n // Deliver error\n this.deliverBrowserResponse(call.id, null, error.message || String(error));\n }\n }\n\n /**\n * Stop processing browser service calls\n */\n stopProcessing(): void {\n this.processing = false;\n }\n\n /**\n * Get the next browser call from WASM\n */\n private getNextBrowserCall(): any {\n // The __wasmGetNextBrowserCall function should be provided by WASM\n if (typeof (window as any).__wasmGetNextBrowserCall === 'function') {\n return (window as any).__wasmGetNextBrowserCall();\n }\n return null;\n }\n\n /**\n * Deliver a response back to WASM (called internally)\n */\n private deliverBrowserResponse(callId: string, response: string | null, error: string | null): boolean {\n if (!(window as any).__wasmDeliverBrowserResponse) {\n return false;\n }\n return (window as any).__wasmDeliverBrowserResponse(callId, response, error);\n }\n}\n"]}