shogun-core 3.0.8 → 3.0.9

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
@@ -21,6 +21,7 @@ Shogun Core is a comprehensive SDK for building decentralized applications (dApp
21
21
  - ✅ **Type Consistency**: Unified return types across all authentication methods
22
22
  - 🚀 **Simplified Architecture**: Focused on core functionality with reduced complexity
23
23
  - ⭐ **Simple API**: Easy-to-use wrapper for common operations with minimal complexity
24
+ - 🔗 **Advanced Chaining**: Powerful chaining operations for complex nested data structures
24
25
  - 👤 **User Space Management**: Complete CRUD operations for user-specific data storage
25
26
  - ⚡ **Quick Start**: Rapid initialization with pre-configured setups
26
27
  - 🎛️ **Configuration Presets**: Pre-built configurations for common use cases
@@ -30,6 +31,7 @@ Shogun Core is a comprehensive SDK for building decentralized applications (dApp
30
31
  ### ✅ **Major API Improvements & Simplification**
31
32
 
32
33
  - **⭐ NEW: Simple API Layer**: Added `SimpleGunAPI` with simplified methods for common operations
34
+ - **⭐ NEW: Advanced Chaining**: Added `node()`, `chain()`, and `getNode()` methods for powerful data chaining
33
35
  - **⭐ NEW: User Space Management**: Complete CRUD operations for user-specific data storage
34
36
  - **⭐ NEW: Quick Start Functions**: `quickStart()` and `QuickStart` class for rapid initialization
35
37
  - **⭐ NEW: Improved Type System**: Reduced `any` usage with better TypeScript types
@@ -181,6 +183,19 @@ const data = await shogun.api.get('path/to/data');
181
183
  await shogun.api.set('path/to/data', { value: 'updated' });
182
184
  await shogun.api.remove('path/to/data');
183
185
 
186
+ // Advanced chaining operations (NEW!)
187
+ // Direct Gun node chaining - recommended for complex operations
188
+ await shogun.api.node('users').get('alice').get('profile').put({ name: 'Alice' });
189
+ const profile = await shogun.api.node('users').get('alice').get('profile').once();
190
+
191
+ // Simplified chaining wrapper
192
+ await shogun.api.chain('users').get('alice').get('settings').put({ theme: 'dark' });
193
+ const settings = await shogun.api.chain('users').get('alice').get('settings').once();
194
+
195
+ // Get Gun node for advanced operations like .map()
196
+ const userNode = shogun.api.getNode('users');
197
+ userNode.map((user, userId) => console.log(`User ${userId}:`, user));
198
+
184
199
  // User space operations (requires login)
185
200
  await shogun.api.putUserData('preferences', { theme: 'dark' });
186
201
  const prefs = await shogun.api.getUserData('preferences');
@@ -221,6 +236,140 @@ const userExists = await shogun.api.userExists('username');
221
236
  const user = await shogun.api.getUser('username');
222
237
  ```
223
238
 
239
+ ## 🔗 **NEW: Advanced Chaining Operations**
240
+
241
+ Shogun Core now supports powerful chaining operations for complex data structures. You have three options depending on your needs:
242
+
243
+ ### 1. **Direct Gun Node Chaining (Recommended)**
244
+
245
+ Use `node()` for full Gun.js functionality with chaining:
246
+
247
+ ```typescript
248
+ // Store nested data
249
+ await shogun.api.node('users').get('alice').get('profile').put({
250
+ name: 'Alice Smith',
251
+ email: 'alice@example.com',
252
+ preferences: {
253
+ theme: 'dark',
254
+ language: 'en'
255
+ }
256
+ });
257
+
258
+ // Read nested data
259
+ const profile = await shogun.api.node('users').get('alice').get('profile').once();
260
+
261
+ // Update specific fields
262
+ await shogun.api.node('users').get('alice').get('profile').get('preferences').get('theme').put('light');
263
+
264
+ // Iterate over collections
265
+ shogun.api.node('users').map((user, userId) => {
266
+ console.log(`User ${userId}:`, user);
267
+ });
268
+
269
+ // Complex chaining
270
+ await shogun.api.node('projects').get('my-app').get('tasks').get('1').put({
271
+ title: 'Implement authentication',
272
+ status: 'completed',
273
+ assignee: 'alice'
274
+ });
275
+ ```
276
+
277
+ ### 2. **Simplified Chaining Wrapper**
278
+
279
+ Use `chain()` for simplified chaining with error handling:
280
+
281
+ ```typescript
282
+ // Simplified chaining with built-in error handling
283
+ const success = await shogun.api.chain('users').get('alice').get('settings').put({
284
+ notifications: true,
285
+ privacy: 'private'
286
+ });
287
+
288
+ if (success) {
289
+ console.log('Settings saved successfully');
290
+ }
291
+
292
+ // Read with simplified chaining
293
+ const settings = await shogun.api.chain('users').get('alice').get('settings').once();
294
+ ```
295
+
296
+ ### 3. **Get Gun Node for Advanced Operations**
297
+
298
+ Use `getNode()` for advanced Gun.js operations:
299
+
300
+ ```typescript
301
+ // Get node for advanced operations
302
+ const usersNode = shogun.api.getNode('users');
303
+
304
+ // Use all Gun.js methods
305
+ usersNode.map((user, userId) => {
306
+ console.log(`Processing user ${userId}`);
307
+ return user;
308
+ });
309
+
310
+ // Chain from the node
311
+ const aliceProfile = await usersNode.get('alice').get('profile').once();
312
+ ```
313
+
314
+ ### Chaining Examples
315
+
316
+ ```typescript
317
+ // User management system
318
+ await shogun.api.node('users').get('alice').put({
319
+ profile: {
320
+ name: 'Alice',
321
+ email: 'alice@example.com'
322
+ },
323
+ settings: {
324
+ theme: 'dark',
325
+ notifications: true
326
+ },
327
+ posts: {
328
+ '1': { title: 'Hello World', content: 'My first post' },
329
+ '2': { title: 'GunDB is awesome', content: 'Learning decentralized storage' }
330
+ }
331
+ });
332
+
333
+ // Blog system
334
+ await shogun.api.node('blog').get('posts').get('2024-01-15').put({
335
+ title: 'Getting Started with Shogun Core',
336
+ author: 'alice',
337
+ content: 'Shogun Core makes decentralized apps easy...',
338
+ tags: ['tutorial', 'decentralized', 'web3'],
339
+ comments: {
340
+ '1': { author: 'bob', text: 'Great tutorial!' },
341
+ '2': { author: 'charlie', text: 'Very helpful, thanks!' }
342
+ }
343
+ });
344
+
345
+ // E-commerce system
346
+ await shogun.api.node('shop').get('products').get('laptop-001').put({
347
+ name: 'Gaming Laptop',
348
+ price: 1299.99,
349
+ stock: 15,
350
+ reviews: {
351
+ '1': { user: 'alice', rating: 5, comment: 'Amazing performance!' },
352
+ '2': { user: 'bob', rating: 4, comment: 'Good value for money' }
353
+ }
354
+ });
355
+
356
+ // Read complex nested data
357
+ const product = await shogun.api.node('shop').get('products').get('laptop-001').once();
358
+ console.log('Product:', product.name);
359
+ console.log('Reviews:', product.reviews);
360
+
361
+ // Update nested data
362
+ await shogun.api.node('shop').get('products').get('laptop-001').get('stock').put(12);
363
+ ```
364
+
365
+ ### Best Practices for Chaining
366
+
367
+ 1. **Use `node()` for most operations** - It provides full Gun.js functionality
368
+ 2. **Use `chain()` for simplified error handling** - Good for beginners
369
+ 3. **Use `getNode()` for advanced operations** - When you need Gun.js methods like `.map()`
370
+ 4. **Keep paths descriptive** - Use meaningful path segments like `users/alice/profile`
371
+ 5. **Handle errors appropriately** - Chaining operations can fail, always check results
372
+
224
373
  ## Plugin Authentication APIs
225
374
 
226
375
  Shogun Core provides a unified plugin system for different authentication methods. Each plugin implements standardized `login()` and `signUp()` methods that return consistent `AuthResult` and `SignUpResult` objects.
@@ -601,6 +750,11 @@ You can also use Shogun Core directly in the browser by including it from a CDN.
601
750
  - `set<T>(path: string, data: T): Promise<boolean>` - Update data at path
602
751
  - `remove(path: string): Promise<boolean>` - Remove data from path
603
752
 
753
+ #### Advanced Chaining Operations (NEW!)
754
+ - `node(path: string): GunNode` - Get Gun node for direct chaining (recommended)
755
+ - `chain(path: string): ChainingWrapper` - Get simplified chaining wrapper
756
+ - `getNode(path: string): GunNode` - Get Gun node for advanced operations like .map()
757
+
604
758
  #### User Space Operations
605
759
  - `putUserData<T>(path: string, data: T): Promise<boolean>` - Store user-specific data
606
760
  - `getUserData<T>(path: string): Promise<T | null>` - Get user-specific data
@@ -89704,6 +89704,58 @@ class SimpleGunAPI {
89704
89704
  getNode(path) {
89705
89705
  return this.db.get(path);
89706
89706
  }
89707
+ // Get Gun node for direct chaining - returns the actual Gun node for full chaining support
89708
+ node(path) {
89709
+ return this.db.get(path);
89710
+ }
89711
+ // Get Gun node with chaining support - returns a wrapper that supports chaining
89712
+ chain(path) {
89713
+ const node = this.db.get(path);
89714
+ return {
89715
+ get: (subPath) => this.chain(`${path}/${subPath}`),
89716
+ put: async (data) => {
89717
+ try {
89718
+ const result = await this.db.put(path, data);
89719
+ return result.success;
89720
+ }
89721
+ catch (error) {
89722
+ console.warn(`Failed to put data to ${path}:`, error);
89723
+ return false;
89724
+ }
89725
+ },
89726
+ set: async (data) => {
89727
+ try {
89728
+ const result = await this.db.set(path, data);
89729
+ return result.success;
89730
+ }
89731
+ catch (error) {
89732
+ console.warn(`Failed to set data to ${path}:`, error);
89733
+ return false;
89734
+ }
89735
+ },
89736
+ once: async () => {
89737
+ try {
89738
+ return await this.db.getData(path);
89739
+ }
89740
+ catch (error) {
89741
+ console.warn(`Failed to get data from ${path}:`, error);
89742
+ return null;
89743
+ }
89744
+ },
89745
+ then: async () => {
89746
+ try {
89747
+ return await this.db.getData(path);
89748
+ }
89749
+ catch (error) {
89750
+ console.warn(`Failed to get data from ${path}:`, error);
89751
+ return null;
89752
+ }
89753
+ },
89754
+ map: (callback) => {
89755
+ return node.map ? node.map(callback) : null;
89756
+ },
89757
+ };
89758
+ }
89707
89759
  // Simple put - returns success boolean
89708
89760
  async put(path, data) {
89709
89761
  try {