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 +76 -121
- package/dist/browser/shogun-core.js +113 -470
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/core.js +2 -3
- package/dist/examples/simple-api-test.js +90 -65
- package/dist/gundb/api.js +111 -467
- package/dist/types/core.d.ts +1 -1
- package/dist/types/examples/simple-api-test.d.ts +6 -1
- package/dist/types/gundb/api.d.ts +77 -165
- package/package.json +1 -8
- package/dist/examples/api-test.js +0 -273
- package/dist/types/examples/api-test.d.ts +0 -12
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.
|
|
39
|
-
|
|
40
|
-
- **⭐
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
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
|
-
- **
|
|
51
|
-
- **
|
|
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
|
|
197
|
-
const loginResult = await
|
|
198
|
-
|
|
199
|
-
const 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
|
|
203
|
-
const data = await
|
|
204
|
-
await
|
|
205
|
-
await
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
|
|
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
|
-
//
|
|
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
|
|
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
|
|
224
|
+
const profile = await api.getProfile();
|
|
232
225
|
|
|
233
|
-
// Settings and preferences
|
|
234
|
-
await
|
|
235
|
-
const settings = await
|
|
226
|
+
// Settings and preferences (standardized locations)
|
|
227
|
+
await api.saveSettings({ language: 'en', notifications: true });
|
|
228
|
+
const settings = await api.getSettings();
|
|
236
229
|
|
|
237
|
-
await
|
|
238
|
-
const preferences = await
|
|
230
|
+
await api.savePreferences({ theme: 'dark', fontSize: 14 });
|
|
231
|
+
const preferences = await api.getPreferences();
|
|
239
232
|
|
|
240
|
-
// Collections (
|
|
241
|
-
|
|
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
|
|
239
|
+
await api.addToCollection('todos', '3', {
|
|
251
240
|
text: 'Deploy to production',
|
|
252
241
|
done: false
|
|
253
242
|
});
|
|
254
243
|
|
|
255
|
-
const todos = await
|
|
256
|
-
await
|
|
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
|
-
//
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
## 🔗 **
|
|
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
|
-
|
|
258
|
+
For advanced Gun.js operations, use the database instance directly via `api.database` or `shogun.database`:
|
|
277
259
|
|
|
278
260
|
```typescript
|
|
279
|
-
//
|
|
280
|
-
|
|
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
|
|
274
|
+
const profile = await db.get('users').get('alice').get('profile').once().then();
|
|
291
275
|
|
|
292
276
|
// Update specific fields
|
|
293
|
-
await
|
|
277
|
+
await db.get('users').get('alice').get('profile').get('preferences').get('theme').put('light');
|
|
294
278
|
|
|
295
|
-
// Iterate over collections
|
|
296
|
-
|
|
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
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
348
|
+
await db.get('shop').get('products').get('laptop-001').get('stock').put(12);
|
|
394
349
|
```
|
|
395
350
|
|
|
396
|
-
### Best Practices
|
|
351
|
+
### Best Practices
|
|
397
352
|
|
|
398
|
-
1. **Use `
|
|
399
|
-
2. **Use `
|
|
400
|
-
3. **
|
|
401
|
-
4. **
|
|
402
|
-
5. **
|
|
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
|
|