shogun-core 3.3.7 → 3.3.8

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
@@ -35,21 +35,21 @@ Shogun Core is a comprehensive SDK for building decentralized applications (dApp
35
35
  - **🔧 IMPROVED: User Data Operations**: Rewrote all user data methods to use direct Gun user node for better reliability and error handling
36
36
  - **🔧 ENHANCED: Error Handling**: Added proper null checking and improved error logging throughout the user data operations
37
37
 
38
- ### ✅ **Major API Improvements & Simplification (v2.0.0)**
39
-
40
- - **⭐ NEW: Simple API Layer**: Added `SimpleGunAPI` with simplified methods for common operations
41
- - **⭐ NEW: Advanced Chaining**: Added `node()`, `chain()`, and `getNode()` methods for powerful data chaining
42
- - **⭐ NEW: User Space Management**: Complete CRUD operations for user-specific data storage
43
- - **⭐ NEW: Quick Start Functions**: `quickStart()` and `QuickStart` class for rapid initialization
38
+ ### ✅ **Major API Improvements & Simplification (v2.1.0)**
39
+
40
+ - **⭐ STREAMLINED: Simple API Layer**: Simplified `SimpleGunAPI` to focus on high-level helpers only
41
+ - Direct database access via `api.database` for basic operations (get, put, auth, etc.)
42
+ - Helper methods for standardized data: profile, settings, preferences, collections
43
+ - Array/Object conversion utilities for GunDB
44
+ - Removed redundant wrapper methods to reduce complexity
45
+ - **⭐ NEW: Quick Start Functions**: `quickStart()`, `autoQuickStart()` classes for rapid initialization
44
46
  - **⭐ NEW: Improved Type System**: Reduced `any` usage with better TypeScript types
45
47
  - **⭐ NEW: Configuration Presets**: Pre-built configurations for common use cases
46
48
  - **⭐ NEW: Advanced API Features**: Comprehensive plugin management, peer network control, advanced user management, and security systems
47
- - **Removed Non-Essential Functions**: Eliminated debug/testing functions, rate limiting system, frozen space system, and complex username management
48
49
  - **Enhanced Advanced Features**: Maintained and improved advanced plugin management, peer network management, and user tracking systems
49
50
  - **Streamlined Event System**: Enhanced event system with better type safety and comprehensive event handling
50
- - **Enhanced Core Focus**: Maintained password hint system with security questions and comprehensive user management
51
- - **Improved Maintainability**: Better organized codebase with clear separation between simple and advanced APIs
52
- - **Better Performance**: Optimized operations with advanced peer management and user tracking
51
+ - **Improved Maintainability**: Better organized codebase with clear separation of concerns
52
+ - **Better Performance**: Optimized operations with reduced abstraction layers
53
53
 
54
54
  ### 🔧 **Bug Fixes & Improvements**
55
55
 
@@ -192,92 +192,76 @@ const gun = Gun({ peers: ['https://gun-manhattan.herokuapp.com/gun'] });
192
192
  const shogun = quickStart(gun, 'my-app');
193
193
  await shogun.init();
194
194
 
195
+ const api = shogun.api;
196
+ const db = api.database; // Access database directly for basic operations
197
+
198
+ // ===== BASIC OPERATIONS (use database) =====
199
+
195
200
  // Authentication
196
- const user = await shogun.api.signup('username', 'password');
197
- const loginResult = await shogun.api.login('username', 'password');
198
- shogun.api.logout();
199
- const isLoggedIn = shogun.api.isLoggedIn();
201
+ const user = await db.signUp('username', 'password');
202
+ const loginResult = await db.login('username', 'password');
203
+ db.logout();
204
+ const isLoggedIn = db.isLoggedIn();
200
205
 
201
206
  // Basic data operations
202
- await shogun.api.put('path/to/data', { value: 'hello' });
203
- const data = await shogun.api.get('path/to/data');
204
- await shogun.api.set('path/to/data', { value: 'updated' });
205
- await shogun.api.remove('path/to/data');
206
-
207
- // Advanced chaining operations (NEW!)
208
- // Direct Gun node chaining - recommended for complex operations
209
- await shogun.api.node('users').get('alice').get('profile').put({ name: 'Alice' });
210
- const profile = await shogun.api.node('users').get('alice').get('profile').once();
211
-
212
- // Simplified chaining wrapper
213
- await shogun.api.chain('users').get('alice').get('settings').put({ theme: 'dark' });
214
- const settings = await shogun.api.chain('users').get('alice').get('settings').once();
215
-
216
- // Get Gun node for advanced operations like .map()
217
- const userNode = shogun.api.getNode('users');
207
+ await db.put('path/to/data', { value: 'hello' });
208
+ const data = await db.getData('path/to/data');
209
+ await db.set('path/to/data', { value: 'updated' });
210
+ await db.remove('path/to/data');
211
+
212
+ // Gun node for advanced operations like .map()
213
+ const userNode = db.get('users');
218
214
  userNode.map((user, userId) => console.log(`User ${userId}:`, user));
219
215
 
220
- // User space operations (requires login)
221
- await shogun.api.putUserData('preferences', { theme: 'dark' });
222
- const prefs = await shogun.api.getUserData('preferences');
223
- await shogun.api.removeUserData('preferences');
216
+ // ===== HELPER METHODS (use api) =====
224
217
 
225
- // Profile management
226
- await shogun.api.updateProfile({
218
+ // Profile management (standardized location)
219
+ await api.updateProfile({
227
220
  name: 'John Doe',
228
221
  email: 'john@example.com',
229
222
  bio: 'Developer'
230
223
  });
231
- const profile = await shogun.api.getProfile();
224
+ const profile = await api.getProfile();
232
225
 
233
- // Settings and preferences
234
- await shogun.api.saveSettings({ language: 'en', notifications: true });
235
- const settings = await shogun.api.getSettings();
226
+ // Settings and preferences (standardized locations)
227
+ await api.saveSettings({ language: 'en', notifications: true });
228
+ const settings = await api.getSettings();
236
229
 
237
- await shogun.api.savePreferences({ theme: 'dark', fontSize: 14 });
238
- const preferences = await shogun.api.getPreferences();
230
+ await api.savePreferences({ theme: 'dark', fontSize: 14 });
231
+ const preferences = await api.getPreferences();
239
232
 
240
- // Collections (recommended for structured data)
241
- // Note: Array functions (putUserArray, getUserArray, etc.) have been removed due to GunDB compatibility issues
242
- // Use collections or direct GunDB operations instead:
243
-
244
- // Option 1: Collections (recommended for most use cases)
245
- await shogun.api.createCollection('todos', {
233
+ // Collections (standardized location for user collections)
234
+ await api.createCollection('todos', {
246
235
  '1': { text: 'Learn Shogun Core', done: false },
247
236
  '2': { text: 'Build dApp', done: false }
248
237
  });
249
238
 
250
- await shogun.api.addToCollection('todos', '3', {
239
+ await api.addToCollection('todos', '3', {
251
240
  text: 'Deploy to production',
252
241
  done: false
253
242
  });
254
243
 
255
- const todos = await shogun.api.getCollection('todos');
256
- await shogun.api.removeFromCollection('todos', '2');
257
-
258
- // Option 2: Direct GunDB operations for complex nested data
259
- await shogun.api.node('users').get('alice').get('todos').get('1').put({
260
- text: 'Learn Shogun Core',
261
- done: false
262
- });
244
+ const todos = await api.getCollection('todos');
245
+ await api.removeFromCollection('todos', '2');
263
246
 
264
- // Utility methods
265
- const currentUser = shogun.api.getCurrentUser();
266
- const userExists = await shogun.api.userExists('username');
267
- const user = await shogun.api.getUser('username');
247
+ // Array utilities for GunDB
248
+ const items = [
249
+ { id: '1', name: 'Item 1' },
250
+ { id: '2', name: 'Item 2' }
251
+ ];
252
+ const indexed = api.arrayToIndexedObject(items); // Convert for GunDB storage
253
+ const restored = api.indexedObjectToArray(indexed); // Convert back
268
254
  ```
269
255
 
270
- ## 🔗 **NEW: Advanced Chaining Operations**
271
-
272
- Shogun Core now supports powerful chaining operations for complex data structures. You have three options depending on your needs:
273
-
274
- ### 1. **Direct Gun Node Chaining (Recommended)**
256
+ ## 🔗 **Advanced Gun Operations**
275
257
 
276
- Use `node()` for full Gun.js functionality with chaining:
258
+ For advanced Gun.js operations, use the database instance directly via `api.database` or `shogun.database`:
277
259
 
278
260
  ```typescript
279
- // Store nested data
280
- await shogun.api.node('users').get('alice').get('profile').put({
261
+ const db = api.database; // or shogun.database
262
+
263
+ // Store nested data with Gun chaining
264
+ await db.get('users').get('alice').get('profile').put({
281
265
  name: 'Alice Smith',
282
266
  email: 'alice@example.com',
283
267
  preferences: {
@@ -287,66 +271,37 @@ await shogun.api.node('users').get('alice').get('profile').put({
287
271
  });
288
272
 
289
273
  // Read nested data
290
- const profile = await shogun.api.node('users').get('alice').get('profile').once();
274
+ const profile = await db.get('users').get('alice').get('profile').once().then();
291
275
 
292
276
  // Update specific fields
293
- await shogun.api.node('users').get('alice').get('profile').get('preferences').get('theme').put('light');
277
+ await db.get('users').get('alice').get('profile').get('preferences').get('theme').put('light');
294
278
 
295
- // Iterate over collections
296
- shogun.api.node('users').map((user, userId) => {
279
+ // Iterate over collections with .map()
280
+ db.get('users').map((user, userId) => {
297
281
  console.log(`User ${userId}:`, user);
298
282
  });
299
283
 
300
- // Complex chaining
301
- await shogun.api.node('projects').get('my-app').get('tasks').get('1').put({
284
+ // Complex chaining for nested structures
285
+ await db.get('projects').get('my-app').get('tasks').get('1').put({
302
286
  title: 'Implement authentication',
303
287
  status: 'completed',
304
288
  assignee: 'alice'
305
289
  });
306
- ```
307
-
308
- ### 2. **Simplified Chaining Wrapper**
309
-
310
- Use `chain()` for simplified chaining with error handling:
311
-
312
- ```typescript
313
- // Simplified chaining with built-in error handling
314
- const success = await shogun.api.chain('users').get('alice').get('settings').put({
315
- notifications: true,
316
- privacy: 'private'
317
- });
318
-
319
- if (success) {
320
- console.log('Settings saved successfully');
321
- }
322
-
323
- // Read with simplified chaining
324
- const settings = await shogun.api.chain('users').get('alice').get('settings').once();
325
- ```
326
-
327
- ### 3. **Get Gun Node for Advanced Operations**
328
290
 
329
- Use `getNode()` for advanced Gun.js operations:
330
-
331
- ```typescript
332
- // Get node for advanced operations
333
- const usersNode = shogun.api.getNode('users');
334
-
335
- // Use all Gun.js methods
336
- usersNode.map((user, userId) => {
337
- console.log(`Processing user ${userId}`);
338
- return user;
291
+ // Access Gun instance directly if needed
292
+ const gunInstance = db.gun;
293
+ gunInstance.get('some-path').on((data) => {
294
+ console.log('Real-time data:', data);
339
295
  });
340
-
341
- // Chain from the node
342
- const aliceProfile = await usersNode.get('alice').get('profile').once();
343
296
  ```
344
297
 
345
298
  ### Chaining Examples
346
299
 
347
300
  ```typescript
301
+ const db = shogun.database; // or api.database
302
+
348
303
  // User management system
349
- await shogun.api.node('users').get('alice').put({
304
+ await db.get('users').get('alice').put({
350
305
  profile: {
351
306
  name: 'Alice',
352
307
  email: 'alice@example.com'
@@ -362,7 +317,7 @@ await shogun.api.node('users').get('alice').put({
362
317
  });
363
318
 
364
319
  // Blog system
365
- await shogun.api.node('blog').get('posts').get('2024-01-15').put({
320
+ await db.get('blog').get('posts').get('2024-01-15').put({
366
321
  title: 'Getting Started with Shogun Core',
367
322
  author: 'alice',
368
323
  content: 'Shogun Core makes decentralized apps easy...',
@@ -374,7 +329,7 @@ await shogun.api.node('blog').get('posts').get('2024-01-15').put({
374
329
  });
375
330
 
376
331
  // E-commerce system
377
- await shogun.api.node('shop').get('products').get('laptop-001').put({
332
+ await db.get('shop').get('products').get('laptop-001').put({
378
333
  name: 'Gaming Laptop',
379
334
  price: 1299.99,
380
335
  stock: 15,
@@ -385,21 +340,21 @@ await shogun.api.node('shop').get('products').get('laptop-001').put({
385
340
  });
386
341
 
387
342
  // Read complex nested data
388
- const product = await shogun.api.node('shop').get('products').get('laptop-001').once();
343
+ const product = await db.get('shop').get('products').get('laptop-001').once().then();
389
344
  console.log('Product:', product.name);
390
345
  console.log('Reviews:', product.reviews);
391
346
 
392
347
  // Update nested data
393
- await shogun.api.node('shop').get('products').get('laptop-001').get('stock').put(12);
348
+ await db.get('shop').get('products').get('laptop-001').get('stock').put(12);
394
349
  ```
395
350
 
396
- ### Best Practices for Chaining
351
+ ### Best Practices
397
352
 
398
- 1. **Use `node()` for most operations** - It provides full Gun.js functionality
399
- 2. **Use `chain()` for simplified error handling** - Good for beginners
400
- 3. **Use `getNode()` for advanced operations** - When you need Gun.js methods like `.map()`
401
- 4. **Keep paths descriptive** - Use meaningful path segments like `users/alice/profile`
402
- 5. **Handle errors appropriately** - Chaining operations can fail, always check results
353
+ 1. **Use `api.database` or `shogun.database` for direct Gun operations**
354
+ 2. **Use `api` helper methods for standardized data** - profile, settings, collections
355
+ 3. **Keep paths descriptive** - Use meaningful path segments like `users/alice/profile`
356
+ 4. **Handle errors appropriately** - Chaining operations can fail, always check results
357
+ 5. **Use helper methods for conventions** - updateProfile(), saveSettings(), etc. provide standardized locations
403
358
 
404
359
  ## Plugin Authentication APIs
405
360