gowm 1.0.8 โ†’ 1.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 CHANGED
@@ -14,16 +14,20 @@
14
14
 
15
15
  ## โœจ Features
16
16
 
17
- - ๐Ÿš€ **Unified Interface** - Load Go WASM modules from local files or GitHub repositories
17
+ - ๐Ÿš€ **Loader System** - Intelligent loader for all source types (files, URLs, GitHub)
18
18
  - ๐Ÿ”ง **Cross-Platform** - Full support for Node.js and browser environments
19
- - โš›๏ธ **React Integration** - Built-in hooks (`useWasm`, `useWasmFromGitHub`)
20
- - ๐Ÿ–– **Vue 3 Support** - Reactive composables with automatic cleanup
19
+ - ๐ŸŽฏ **Auto-Detection** - Automatically detects source type and optimal loading strategy
21
20
  - ๐Ÿ“ฆ **GitHub Direct Loading** - Load WASM modules directly from GitHub repositories
22
21
  - ๐Ÿท๏ธ **Version Control** - Support for branches, tags, and specific commits
23
- - ๐Ÿ›ก๏ธ **Error Handling** - Robust error handling and automatic retries
24
- - ๐Ÿงน **Memory Management** - Automatic resource cleanup and memory management
25
- - ๐Ÿ“Š **Module Statistics** - Built-in monitoring and performance metrics
26
- - ๐Ÿ”„ **Flexible Calls** - Both synchronous and asynchronous function calls
22
+ - ๐Ÿ›ก๏ธ **Enhanced Error Handling** - Robust error handling with fallback strategies
23
+ - ๐Ÿงน **Smart Memory Management** - Advanced memory management and resource cleanup
24
+ - ๐Ÿ“Š **Comprehensive Statistics** - Built-in monitoring, testing, and performance metrics
25
+ - ๐Ÿ”„ **Flexible API** - Both synchronous and asynchronous function calls
26
+ - ๐Ÿ“ **TypeScript Support** - Full TypeScript definitions included
27
+
28
+ ### ๐Ÿš€ Coming in v1.1.1
29
+ - โš›๏ธ **React Hooks** - useWasm hooks for seamless React integration
30
+ - ๐Ÿ–– **Vue 3 Composables** - useWasm composables for Vue.js applications
27
31
 
28
32
  ## ๐Ÿ“ฅ Installation
29
33
 
@@ -37,10 +41,12 @@ pnpm add gowm
37
41
 
38
42
  ## ๐Ÿš€ Quick Start
39
43
 
44
+ > **Note**: React hooks and Vue composables will be available in GoWM v1.1.1. Current version (1.1.0) provides core functionality only.
45
+
40
46
  ### Node.js Example
41
47
 
42
48
  ```javascript
43
- const { load, loadFromGitHub } = require('gowm');
49
+ const { load, loadFromGitHub, loadFromUrl } = require('gowm');
44
50
 
45
51
  async function example() {
46
52
  try {
@@ -51,9 +57,17 @@ async function example() {
51
57
  branch: 'master'
52
58
  });
53
59
 
60
+ // Load from HTTP URL
61
+ const remoteWasm = await loadFromUrl('https://example.com/module.wasm');
62
+
54
63
  // Load from local file
55
64
  const localWasm = await load('./math.wasm', { name: 'local-math' });
56
65
 
66
+ // Auto-detection: GoWM automatically detects the source type
67
+ const autoDetected1 = await load('owner/repo'); // GitHub
68
+ const autoDetected2 = await load('https://example.com/mod.wasm'); // HTTP
69
+ const autoDetected3 = await load('./local.wasm'); // File
70
+
57
71
  // Call functions
58
72
  const result = math.call('add', 5, 3);
59
73
  console.log('5 + 3 =', result); // 8
@@ -67,9 +81,14 @@ async function example() {
67
81
  console.log('divide function is available');
68
82
  }
69
83
 
70
- // Get module statistics
84
+ // Get comprehensive statistics
71
85
  const stats = math.getStats();
72
86
  console.log('Available functions:', stats.functions);
87
+ console.log('Memory usage:', stats.memoryUsage);
88
+
89
+ // Test module functionality
90
+ const testResults = math.test();
91
+ console.log('Module test results:', testResults);
73
92
 
74
93
  } catch (error) {
75
94
  console.error('Error:', error);
@@ -79,91 +98,29 @@ async function example() {
79
98
  example();
80
99
  ```
81
100
 
82
- ### React Integration
101
+ ## ๐Ÿ”„ Loader System
83
102
 
84
- ```jsx
85
- import React, { useState } from 'react';
86
- import { useWasmFromGitHub } from 'gowm/hooks/useWasm';
87
-
88
- function Calculator() {
89
- const { wasm, loading, error } = useWasmFromGitHub('benoitpetit/wasm-modules-repository', {
90
- path: 'math-wasm',
91
- branch: 'master',
92
- name: 'calculator'
93
- });
94
-
95
- const [result, setResult] = useState(null);
96
-
97
- const calculate = async () => {
98
- if (wasm) {
99
- try {
100
- const sum = await wasm.callAsync('add', 10, 20);
101
- setResult(sum);
102
- } catch (err) {
103
- console.error('Calculation failed:', err);
104
- }
105
- }
106
- };
103
+ GoWM v1.1.0 features a loader system that handles all source types with a single API:
107
104
 
108
- if (loading) return <div>Loading WASM module...</div>;
109
- if (error) return <div>Error: {error.message}</div>;
105
+ ### Auto-Detection
106
+ ```javascript
107
+ const { load } = require('gowm');
110
108
 
111
- return (
112
- <div>
113
- <button onClick={calculate}>Calculate 10 + 20</button>
114
- {result !== null && <p>Result: {result}</p>}
115
- </div>
116
- );
117
- }
109
+ // Automatically detects source type
110
+ await load('owner/repo'); // โ†’ GitHub repository
111
+ await load('https://example.com/module.wasm'); // โ†’ HTTP URL
112
+ await load('./local/module.wasm'); // โ†’ Local file
113
+ await load('/absolute/path/module.wasm'); // โ†’ Absolute path
118
114
  ```
119
115
 
120
- ### Vue 3 Integration
121
-
122
- ```vue
123
- <template>
124
- <div class="calculator">
125
- <div v-if="loading">Loading WASM module...</div>
126
- <div v-else-if="error" class="error">Error: {{ error.message }}</div>
127
- <div v-else>
128
- <input v-model.number="num1" type="number" placeholder="First number" />
129
- <input v-model.number="num2" type="number" placeholder="Second number" />
130
- <button @click="calculate">Calculate {{ num1 }} + {{ num2 }}</button>
131
- <div v-if="result !== null" class="result">Result: {{ result }}</div>
132
- </div>
133
- </div>
134
- </template>
135
-
136
- <script>
137
- import { ref } from 'vue';
138
- import { useWasmFromGitHub } from 'gowm/composables/useWasm';
139
-
140
- export default {
141
- name: 'Calculator',
142
- setup() {
143
- const { wasm, loading, error } = useWasmFromGitHub('benoitpetit/wasm-modules-repository', {
144
- path: 'math-wasm',
145
- branch: 'master',
146
- name: 'math'
147
- });
148
-
149
- const num1 = ref(10);
150
- const num2 = ref(20);
151
- const result = ref(null);
152
-
153
- const calculate = async () => {
154
- if (wasm.value) {
155
- try {
156
- result.value = await wasm.value.callAsync('add', num1.value, num2.value);
157
- } catch (err) {
158
- console.error('Calculation error:', err);
159
- }
160
- }
161
- };
116
+ ### Specific Loading Methods
117
+ ```javascript
118
+ const { loadFromFile, loadFromUrl, loadFromGitHub } = require('gowm');
162
119
 
163
- return { wasm, loading, error, num1, num2, result, calculate };
164
- }
165
- };
166
- </script>
120
+ // Explicit methods for specific sources
121
+ await loadFromFile('./module.wasm'); // Node.js only
122
+ await loadFromUrl('https://example.com/mod.wasm'); // HTTP/HTTPS
123
+ await loadFromGitHub('owner/repo', options); // GitHub repository
167
124
  ```
168
125
 
169
126
  ## ๐Ÿ™ GitHub Repository Loading
@@ -185,7 +142,8 @@ async function examples() {
185
142
  path: 'crypto-wasm',
186
143
  filename: 'main.wasm',
187
144
  branch: 'master',
188
- name: 'crypto-processor'
145
+ name: 'crypto-processor',
146
+ timeout: 30000 // Custom timeout
189
147
  });
190
148
 
191
149
  // Load from full GitHub URL
@@ -213,6 +171,20 @@ GoWM automatically searches for WASM files in these locations:
213
171
 
214
172
  ### Core Functions
215
173
 
174
+ #### `load(source, options)`
175
+
176
+ Universal loading function that auto-detects source type.
177
+
178
+ **Parameters:**
179
+ - `source` (string): Can be file path, HTTP URL, or GitHub repo
180
+ - `options` (object, optional):
181
+ - `name` (string): Module identifier
182
+ - `timeout` (number): Initialization timeout (default: 15000ms)
183
+ - `preInit` (boolean): Pre-initialize module (default: true)
184
+ - `goRuntimePath` (string): Custom path to wasm_exec.js
185
+
186
+ **Returns:** Promise<WasmBridge>
187
+
216
188
  #### `loadFromGitHub(githubRepo, options)`
217
189
 
218
190
  Loads a WASM module from a GitHub repository with automatic file resolution.
@@ -221,25 +193,33 @@ Loads a WASM module from a GitHub repository with automatic file resolution.
221
193
  - `githubRepo` (string): GitHub repository ("owner/repo" or full GitHub URL)
222
194
  - `options` (object, optional):
223
195
  - `name` (string): Module identifier (default: repository name)
224
- - `branch` (string): Git branch (default: 'master')
196
+ - `branch` (string): Git branch (default: 'main')
225
197
  - `tag` (string): Git tag (takes precedence over branch)
226
198
  - `path` (string): Path within repository (default: '')
227
199
  - `filename` (string): Specific filename (default: auto-detect)
200
+ - `timeout` (number): Initialization timeout (default: 15000ms)
228
201
  - `goRuntimePath` (string): Custom path to wasm_exec.js
229
202
  - `preInit` (boolean): Pre-initialize the module (default: true)
230
203
 
231
204
  **Returns:** Promise<WasmBridge>
232
205
 
233
- #### `load(wasmPath, options)`
206
+ #### `loadFromUrl(url, options)`
234
207
 
235
- Loads a WASM module from a local file or URL.
208
+ Loads a WASM module from HTTP/HTTPS URL.
236
209
 
237
210
  **Parameters:**
238
- - `wasmPath` (string): Path to the .wasm file or URL
239
- - `options` (object, optional):
240
- - `name` (string): Module identifier (default: 'default')
241
- - `goRuntimePath` (string): Custom path to wasm_exec.js
242
- - `preInit` (boolean): Pre-initialize the module (default: true)
211
+ - `url` (string): HTTP/HTTPS URL to WASM file
212
+ - `options` (object, optional): Same as `load()` options
213
+
214
+ **Returns:** Promise<WasmBridge>
215
+
216
+ #### `loadFromFile(filePath, options)`
217
+
218
+ Loads a WASM module from local file (Node.js only).
219
+
220
+ **Parameters:**
221
+ - `filePath` (string): Path to the .wasm file
222
+ - `options` (object, optional): Same as `load()` options
243
223
 
244
224
  **Returns:** Promise<WasmBridge>
245
225
 
@@ -250,65 +230,80 @@ Retrieves an already loaded module by name.
250
230
  **Parameters:**
251
231
  - `name` (string, optional): Module name (default: 'default')
252
232
 
253
- **Returns:** WasmBridge | null
233
+ **Returns:** UnifiedWasmBridge | null
254
234
 
255
- ### WasmBridge Methods
235
+ ### Enhanced Bridge Methods
236
+
237
+ The bridge provides comprehensive functionality:
256
238
 
257
239
  #### `call(funcName, ...args)`
258
240
 
259
241
  Calls a WASM function synchronously.
260
242
 
261
- **Parameters:**
262
- - `funcName` (string): Name of the function to call
263
- - `...args`: Function arguments
264
-
265
- **Returns:** Function result
266
-
267
243
  #### `callAsync(funcName, ...args)`
268
244
 
269
245
  Calls a WASM function asynchronously.
270
246
 
271
- **Parameters:**
272
- - `funcName` (string): Name of the function to call
273
- - `...args`: Function arguments
274
-
275
- **Returns:** Promise<Function result>
247
+ #### `createBuffer(data)`
276
248
 
277
- #### `hasFunction(funcName)`
249
+ Creates a buffer for data transfer with enhanced type support.
278
250
 
279
- Checks if a function exists in the WASM module.
251
+ **Supported Types:**
252
+ - `Float64Array`, `Float32Array`
253
+ - `Uint8Array`, `Uint16Array`, `Uint32Array`
254
+ - `Int8Array`, `Int16Array`, `Int32Array`
255
+ - `Array`, `string`
280
256
 
281
- **Parameters:**
282
- - `funcName` (string): Function name to check
283
-
284
- **Returns:** boolean
285
-
286
- #### `getAvailableFunctions()`
257
+ #### `test()`
287
258
 
288
- Gets a list of all available functions in the module.
259
+ Runs comprehensive tests on the module.
289
260
 
290
- **Returns:** string[]
261
+ **Returns:** Object with test results:
262
+ ```javascript
263
+ {
264
+ functionCalls: boolean,
265
+ memoryAllocation: boolean,
266
+ callbacks: boolean,
267
+ asyncCalls: boolean,
268
+ errors: string[]
269
+ }
270
+ ```
291
271
 
292
272
  #### `getStats()`
293
273
 
294
- Gets module statistics and information.
274
+ Gets comprehensive module statistics.
295
275
 
296
- **Returns:** Object with module statistics
297
-
298
- #### `cleanup()`
299
-
300
- Manually clean up module resources.
301
-
302
- **Returns:** void
276
+ **Returns:** Object with detailed statistics:
277
+ ```javascript
278
+ {
279
+ name: string,
280
+ ready: boolean,
281
+ environment: 'Node.js' | 'Browser',
282
+ functions: string[],
283
+ callbacks: string[],
284
+ allocatedBuffers: number,
285
+ memoryUsage: {
286
+ total: number,
287
+ wasm: number,
288
+ go: number,
289
+ buffers: number,
290
+ buffersCount: number
291
+ },
292
+ supportedDataTypes: string[],
293
+ loadedAt: string
294
+ }
295
+ ```
303
296
 
304
297
  ### Utility Functions
305
298
 
306
299
  - `listModules()`: List all loaded modules
307
- - `getStats()`: Get statistics for all modules
300
+ - `getStats()`: Get statistics for all modules
308
301
  - `unload(name)`: Unload a specific module
309
302
  - `unloadAll()`: Unload all modules
310
303
  - `isLoaded(name)`: Check if a module is loaded
311
304
  - `getTotalMemoryUsage()`: Get total memory usage
305
+ - `testAll()`: Test all loaded modules
306
+ - `getHelp()`: Get comprehensive help information
312
307
 
313
308
  ## โš›๏ธ React Hooks
314
309
 
@@ -420,7 +415,7 @@ export default {
420
415
 
421
416
  ## ๐ŸŒ Browser Usage
422
417
 
423
- For browser environments, use the ES6 module version:
418
+ For browser environments, GoWM automatically optimizes for the browser:
424
419
 
425
420
  ```html
426
421
  <!DOCTYPE html>
@@ -447,6 +442,36 @@ For browser environments, use the ES6 module version:
447
442
  </html>
448
443
  ```
449
444
 
445
+ ### Global Usage
446
+ ```html
447
+ <script src="path/to/gowm/src/browser.js"></script>
448
+ <script>
449
+ GoWM.loadFromUrl('https://example.com/module.wasm');
450
+ </script>
451
+ ```
452
+
453
+ ## ๐Ÿ—๏ธ Architecture
454
+
455
+ GoWM v1.1.0 features a clean architecture:
456
+
457
+ ```
458
+ src/
459
+ โ”œโ”€โ”€ core/gowm.js # Main GoWM class
460
+ โ”œโ”€โ”€ loaders/loader.js # Loading system
461
+ โ”œโ”€โ”€ bridges/bridge.js # Bridge interface
462
+ โ”œโ”€โ”€ legacy/ # Legacy files (preserved)
463
+ โ”œโ”€โ”€ index.js # Main entry point
464
+ โ””โ”€โ”€ browser.js # Browser-optimized entry
465
+ ```
466
+
467
+ ### Key Improvements
468
+
469
+ - **Single Loader**: One loader handles all source types
470
+ - **Enhanced Bridge**: Advanced memory management and testing
471
+ - **Better Performance**: Optimized loading and initialization
472
+ - **Comprehensive Testing**: Built-in module testing capabilities
473
+ - **Detailed Statistics**: In-depth monitoring and metrics
474
+
450
475
  ## ๐Ÿ“Š Examples
451
476
 
452
477
  Check out the `/examples` directory for comprehensive examples:
@@ -456,6 +481,47 @@ Check out the `/examples` directory for comprehensive examples:
456
481
  - **Vue examples**: Vue 3 application templates with composables
457
482
  - **Browser examples**: Vanilla JavaScript implementations
458
483
 
484
+ ### Running Examples
485
+
486
+ ```bash
487
+ # Run basic Node.js example
488
+ npm run test:basic
489
+
490
+ # Run crypto example
491
+ npm run test:crypto
492
+
493
+ # Serve browser examples
494
+ npm run demo:serve
495
+ ```
496
+
497
+ ## ๐Ÿ”ง Development
498
+
499
+ ### Testing Your Modules
500
+
501
+ ```javascript
502
+ const gowm = require('gowm');
503
+
504
+ // Load and test a module
505
+ const module = await gowm.load('your-module.wasm');
506
+ const testResults = module.test();
507
+ console.log('Test results:', testResults);
508
+
509
+ // Get comprehensive statistics
510
+ const stats = gowm.getStats();
511
+ console.log('System stats:', stats);
512
+ ```
513
+
514
+ ### Custom Loading
515
+
516
+ ```javascript
517
+ const { WasmLoader, WasmBridge } = require('gowm');
518
+
519
+ // Use components directly for advanced scenarios
520
+ const loader = new WasmLoader();
521
+ const module = await loader.loadModule('source');
522
+ const bridge = new WasmBridge(module);
523
+ ```
524
+
459
525
  ## ๐Ÿ“„ License
460
526
 
461
527
  MIT License - see the [LICENSE](LICENSE) file for details.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gowm",
3
- "version": "1.0.8",
4
- "description": "Go Wasm Manager - Simplify integration of Go Wasm modules in your JavaScript projects with GitHub repository support, React hooks, and Vue composables",
3
+ "version": "1.1.0",
4
+ "description": "Go Wasm Manager - Loader system for Go WebAssembly modules with GitHub repository support. Features intelligent auto-detection and enhanced memory management.",
5
5
  "main": "src/index.js",
6
6
  "browser": "src/browser.js",
7
7
  "module": "src/browser.js",
@@ -12,15 +12,11 @@
12
12
  "browser": "./src/browser.js",
13
13
  "import": "./src/browser.js",
14
14
  "require": "./src/index.js"
15
- },
16
- "./hooks": "./hooks/useWasm.js",
17
- "./composables": "./composables/useWasm.js"
15
+ }
18
16
  },
19
17
  "files": [
20
18
  "src/",
21
19
  "types/",
22
- "hooks/",
23
- "composables/",
24
20
  "runtime/",
25
21
  "README.md",
26
22
  "LICENSE"
@@ -29,6 +25,9 @@
29
25
  "test": "node examples/node/basic.js",
30
26
  "test:basic": "node examples/node/basic.js",
31
27
  "test:crypto": "node examples/node/crypto.js",
28
+ "test:node": "node test-quick.js",
29
+ "test:examples": "node test-examples.js",
30
+ "test:all": "npm run test:examples",
32
31
  "check": "node check-project.js",
33
32
  "demo:serve": "npx serve examples/browser -p 3000",
34
33
  "demo:browser": "npm run demo:serve && echo 'Open http://localhost:3000'",
@@ -42,14 +41,14 @@
42
41
  "golang",
43
42
  "javascript",
44
43
  "nodejs",
45
- "react",
46
- "vue",
47
- "vuejs",
48
44
  "github",
49
45
  "bridge",
50
46
  "loader",
51
47
  "manager",
52
- "typescript"
48
+ "typescript",
49
+ "auto-detection",
50
+ "memory-management",
51
+ "cross-platform"
53
52
  ],
54
53
  "author": "devbyben",
55
54
  "license": "MIT",