shogun-core 3.0.7 → 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
@@ -42808,6 +42808,7 @@ __webpack_require__.r(__webpack_exports__);
42808
42808
 
42809
42809
  // EXPORTS
42810
42810
  __webpack_require__.d(__webpack_exports__, {
42811
+ AutoQuickStart: () => (/* reexport */ AutoQuickStart),
42811
42812
  BasePlugin: () => (/* reexport */ BasePlugin),
42812
42813
  ConfigHelpers: () => (/* reexport */ ConfigHelpers),
42813
42814
  CorePlugins: () => (/* reexport */ CorePlugins),
@@ -42833,6 +42834,7 @@ __webpack_require__.d(__webpack_exports__, {
42833
42834
  Web3ConnectorPlugin: () => (/* reexport */ Web3ConnectorPlugin),
42834
42835
  Webauthn: () => (/* reexport */ Webauthn),
42835
42836
  WebauthnPlugin: () => (/* reexport */ WebauthnPlugin),
42837
+ autoQuickStart: () => (/* reexport */ autoQuickStart),
42836
42838
  createError: () => (/* reexport */ createError),
42837
42839
  createSimpleAPI: () => (/* reexport */ createSimpleAPI),
42838
42840
  crypto: () => (/* reexport */ gundb_crypto_namespaceObject),
@@ -89670,7 +89672,7 @@ const createGun = (config) => {
89670
89672
  */
89671
89673
 
89672
89674
 
89673
- ;// ./src/gundb/simple-api.ts
89675
+ ;// ./src/gundb/api.ts
89674
89676
  /**
89675
89677
  * Simplified API layer to reduce complexity for common use cases
89676
89678
  * Provides quick-start methods that wrap the full DataBase functionality
@@ -89702,6 +89704,58 @@ class SimpleGunAPI {
89702
89704
  getNode(path) {
89703
89705
  return this.db.get(path);
89704
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
+ }
89705
89759
  // Simple put - returns success boolean
89706
89760
  async put(path, data) {
89707
89761
  try {
@@ -90804,7 +90858,7 @@ const ShogunPresets = {
90804
90858
  */
90805
90859
  minimal: () => ({
90806
90860
  gunOptions: {
90807
- peers: ["https://gunjs.herokuapp.com/gun"],
90861
+ peers: ["https://relay.shogun-eco.xyz/gun"],
90808
90862
  localStorage: true,
90809
90863
  },
90810
90864
  }),
@@ -90813,7 +90867,7 @@ const ShogunPresets = {
90813
90867
  */
90814
90868
  development: () => ({
90815
90869
  gunOptions: {
90816
- peers: ["https://gunjs.herokuapp.com/gun"],
90870
+ peers: ["https://relay.shogun-eco.xyz/gun"],
90817
90871
  localStorage: true,
90818
90872
  radisk: false,
90819
90873
  },
@@ -90829,8 +90883,8 @@ const ShogunPresets = {
90829
90883
  production: (customPeers) => ({
90830
90884
  gunOptions: {
90831
90885
  peers: customPeers || [
90832
- "https://gunjs.herokuapp.com/gun",
90833
- "https://gun-manhattan.herokuapp.com/gun",
90886
+ "https://relay.shogun-eco.xyz/gun",
90887
+ "https://peer.wallie.io/gun",
90834
90888
  ],
90835
90889
  localStorage: true,
90836
90890
  radisk: true,
@@ -90856,7 +90910,7 @@ const ShogunPresets = {
90856
90910
  */
90857
90911
  web3: () => ({
90858
90912
  gunOptions: {
90859
- peers: ["https://gunjs.herokuapp.com/gun"],
90913
+ peers: ["https://relay.shogun-eco.xyz/gun"],
90860
90914
  localStorage: true,
90861
90915
  },
90862
90916
  web3: {
@@ -90868,7 +90922,7 @@ const ShogunPresets = {
90868
90922
  */
90869
90923
  webauthn: () => ({
90870
90924
  gunOptions: {
90871
- peers: ["https://gunjs.herokuapp.com/gun"],
90925
+ peers: ["https://relay.shogun-eco.xyz/gun"],
90872
90926
  localStorage: true,
90873
90927
  },
90874
90928
  webauthn: {
@@ -91027,14 +91081,12 @@ const QuickConfig = {
91027
91081
 
91028
91082
  // Import Simple API and improved types
91029
91083
 
91030
- // Import Gun as default export
91031
-
91032
91084
 
91033
91085
 
91034
91086
 
91035
- // Export simplified configuration
91036
91087
 
91037
91088
 
91089
+ // Export simplified configuration
91038
91090
 
91039
91091
 
91040
91092