You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Create an instance of your SDK with initialization parameters
579
+
final sdk = await Sdk.create(
580
+
apiUrl: 'https://api.custom.com',
581
+
timeout: 10000,
582
+
);
583
+
584
+
// Call single-value functions (returns a Future)
585
+
final price = await sdk.calculatePrice(10, 99);
586
+
print('Total Price: $price');
587
+
588
+
// Call streaming functions (returns a Stream)
589
+
final userStream = await sdk.fetchUsers();
590
+
591
+
final completer = Completer<void>();
592
+
userStream.listen((user) {
593
+
print('User: $user');
594
+
}, onDone: completer.complete);
595
+
596
+
await completer.future;
597
+
598
+
// Clean up when done
599
+
sdk.dispose();
600
+
}
601
+
```
602
+
603
+
The `@globe/dart_source_generator` automatically generates the SDK wrapper class with type-safe methods that handle all the Dart FFI interop boilerplate. You simply call methods and get properly typed `Future` or `Stream` objects back.
604
+
605
+
For more details, see the [@globe/dart_source_generator documentation](https://www.npmjs.com/package/@globe/dart_source_generator) and [@globe/runtime_types documentation](https://www.npmjs.com/package/@globe/runtime_types).
606
+
607
+
---
608
+
609
+
### Alternative Approach 1: Using esbuild (JavaScript - Simpler)
495
610
496
611
#### Step 1: Create package.json
497
612
@@ -633,7 +748,7 @@ void main() async {
633
748
}
634
749
```
635
750
636
-
### Approach 2: Using tsup (TypeScript - Recommended)
751
+
### Alternative Approach 2: Using tsup (TypeScript)
637
752
638
753
#### Step 1: Create package.json
639
754
@@ -786,7 +901,7 @@ void main() async {
786
901
787
902
### Why This Approach Works
788
903
789
-
1.**Bundling**: `tsup`bundles all NPM dependencies into a single JavaScript file
904
+
1.**Bundling**: Bundlers like `tsup`or `esbuild` bundle all NPM dependencies into a single JavaScript file
790
905
2.**TypeScript Support**: Full type safety and IntelliSense
791
906
3.**No external dependencies**: The bundled file contains everything needed
792
907
4.**InlinedModule**: Uses the bundled code directly, avoiding file path and module resolution issues
0 commit comments