shogun-core 3.3.6 → 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/dist/core.js CHANGED
@@ -215,8 +215,8 @@ class ShogunCore {
215
215
  * @description Authenticates user using a GunDB pair directly.
216
216
  * Emits login event on success.
217
217
  */
218
- async loginWithPair(pair) {
219
- return this.authManager.loginWithPair(pair);
218
+ async loginWithPair(username, pair) {
219
+ return this.authManager.loginWithPair(username, pair);
220
220
  }
221
221
  /**
222
222
  * Register a new user with provided credentials
@@ -318,13 +318,12 @@ class ShogunCore {
318
318
  }
319
319
  }
320
320
  exports.ShogunCore = ShogunCore;
321
- ShogunCore.API_VERSION = "^3.0.11";
321
+ ShogunCore.API_VERSION = "^3.3.8";
322
322
  // Global declarations are handled in the original core.ts file
323
323
  // to avoid conflicts, we only set the window properties here
324
324
  if (typeof window !== "undefined") {
325
- window.SHOGUN_CORE = (config) => {
325
+ window.ShogunCore = (config) => {
326
326
  return new ShogunCore(config);
327
327
  };
328
- window.SHOGUN_CORE_CLASS = ShogunCore;
329
328
  }
330
329
  exports.default = ShogunCore;
@@ -1,87 +1,112 @@
1
1
  "use strict";
2
2
  /**
3
- * Esempio semplice che mostra le differenze principali tra i metodi API
3
+ * Example showing how to use the simplified ShogunCore API
4
+ *
5
+ * The API has been streamlined:
6
+ * - AutoQuickStart: Quick initialization helper
7
+ * - api.database: Direct access to DataBase for basic operations (get, put, set, remove, auth)
8
+ * - api helper methods: High-level helpers for profile, settings, collections, and array utilities
4
9
  */
5
10
  Object.defineProperty(exports, "__esModule", { value: true });
6
11
  exports.simpleAPITest = simpleAPITest;
7
12
  const api_1 = require("../gundb/api");
8
13
  async function simpleAPITest() {
9
- console.log("šŸš€ Test semplice API ShogunCore\n");
10
- // Setup
14
+ console.log("šŸš€ ShogunCore Simplified API Example\n");
15
+ // === QUICK START ===
16
+ console.log("šŸ“¦ === INITIALIZATION ===\n");
17
+ // Use AutoQuickStart for easy setup
11
18
  const quickStart = new api_1.AutoQuickStart({
12
19
  peers: ["https://peer.wallie.io/gun"],
13
20
  appScope: "simple-test",
14
21
  });
15
22
  await quickStart.init();
23
+ // Access the API and database
16
24
  const api = quickStart.api;
17
- // === DIFFERENZE PRINCIPALI ===
18
- console.log("šŸ“Š === DIFFERENZE GET ===\n");
19
- // 1. get() - restituisce dati direttamente
20
- const data1 = await api.get("test/path");
21
- console.log('get("test/path"):', data1); // null o dati
22
- // 2. getNode() - restituisce nodo Gun per chaining
23
- const node1 = api.getNode("test/path");
24
- console.log('getNode("test/path"):', typeof node1); // "object" (Gun node)
25
- // 3. node() - alias di getNode()
26
- const node2 = api.node("test/path");
27
- console.log('node("test/path"):', typeof node2); // "object" (Gun node)
28
- // 4. chain() - wrapper con metodi di convenienza
29
- const chain1 = api.chain("test/path");
30
- console.log('chain("test/path"):', Object.keys(chain1)); // ['get', 'put', 'set', 'once', 'then', 'map']
31
- console.log("\nšŸ’¾ === DIFFERENZE PUT/SET ===\n");
25
+ const db = api.database; // Direct access to DataBase for basic operations
26
+ console.log("Initialized successfully!");
27
+ console.log("- api: provides helper methods");
28
+ console.log("- db (api.database): provides full DataBase functionality\n");
29
+ // === BASIC OPERATIONS (via database) ===
30
+ console.log("šŸ’¾ === BASIC OPERATIONS (use api.database) ===\n");
32
31
  const testData = { message: "Hello World", timestamp: Date.now() };
33
- // 1. put() - salva dati globali
34
- const putResult = await api.put("global/data", testData);
35
- console.log("put() result:", putResult); // true/false
36
- // 2. set() - come put() ma semantica diversa
37
- const setResult = await api.set("global/data2", {
38
- ...testData,
39
- method: "set",
40
- });
41
- console.log("set() result:", setResult); // true/false
42
- // Verifica
43
- const retrieved1 = await api.get("global/data");
44
- const retrieved2 = await api.get("global/data2");
45
- console.log("Retrieved put data:", retrieved1);
46
- console.log("Retrieved set data:", retrieved2);
47
- console.log("\nšŸ—‘ļø === DIFFERENZE REMOVE ===\n");
48
- // remove() - rimuove dati globali
49
- const removeResult = await api.remove("global/data2");
50
- console.log("remove() result:", removeResult); // true/false
51
- const afterRemove = await api.get("global/data2");
52
- console.log("Data after remove:", afterRemove); // null
53
- console.log("\nšŸ” === TEST AUTENTICAZIONE ===\n");
54
- // Signup e login
32
+ // Use db for basic operations
33
+ await db.put("global/data", testData);
34
+ console.log("āœ“ Saved data with db.put()");
35
+ const retrieved = await db.getData("global/data");
36
+ console.log("āœ“ Retrieved data with db.getData():", retrieved);
37
+ await db.remove("global/data");
38
+ console.log("āœ“ Removed data with db.remove()\n");
39
+ // === AUTHENTICATION (via database) ===
40
+ console.log("šŸ” === AUTHENTICATION (use api.database) ===\n");
55
41
  const username = "testuser_" + Date.now();
56
42
  const password = "testpass123";
57
- const signupResult = await api.signup(username, password);
58
- console.log("Signup result:", signupResult);
59
- if (signupResult) {
60
- const loginResult = await api.login(username, password);
61
- console.log("Login result:", loginResult);
62
- if (loginResult) {
63
- console.log("\nšŸ‘¤ === OPERAZIONI UTENTE ===\n");
64
- // getUserData() - per dati utente
65
- const userData = await api.getUserData("profile");
66
- console.log('getUserData("profile"):', userData); // null o dati utente
67
- // putUserData() - salva dati utente
68
- const profileData = { name: "Test User", email: "test@example.com" };
69
- const putUserResult = await api.putUserData("profile", profileData);
70
- console.log("putUserData() result:", putUserResult); // true/false
71
- // Verifica dati utente
72
- const retrievedProfile = await api.getUserData("profile");
73
- console.log("Retrieved profile:", retrievedProfile);
74
- // removeUserData() - rimuove dati utente
75
- const removeUserResult = await api.removeUserData("profile");
76
- console.log("removeUserData() result:", removeUserResult); // true/false
77
- const afterRemoveUser = await api.getUserData("profile");
78
- console.log("User data after remove:", afterRemoveUser); // null
43
+ const signupResult = await db.signUp(username, password);
44
+ console.log("āœ“ Signup:", signupResult.success ? "Success" : "Failed");
45
+ if (signupResult.success) {
46
+ const loginResult = await db.login(username, password);
47
+ console.log("āœ“ Login:", loginResult.success ? "Success" : "Failed");
48
+ if (loginResult.success) {
49
+ console.log("āœ“ Current user:", db.getCurrentUser()?.alias, "\n");
50
+ // === HELPER METHODS (via api) ===
51
+ console.log("⭐ === HELPER METHODS (use api helpers) ===\n");
52
+ // Profile helper
53
+ await api.updateProfile({
54
+ name: "Test User",
55
+ email: "test@example.com",
56
+ bio: "Testing the simplified API",
57
+ });
58
+ console.log("āœ“ Profile updated with api.updateProfile()");
59
+ const profile = await api.getProfile();
60
+ console.log("āœ“ Profile retrieved:", profile);
61
+ // Settings helper
62
+ await api.saveSettings({
63
+ theme: "dark",
64
+ language: "en",
65
+ notifications: true,
66
+ });
67
+ console.log("āœ“ Settings saved with api.saveSettings()");
68
+ const settings = await api.getSettings();
69
+ console.log("āœ“ Settings retrieved:", settings);
70
+ // Collections helper
71
+ await api.createCollection("favorites", {
72
+ item1: { id: "item1", title: "First Item" },
73
+ item2: { id: "item2", title: "Second Item" },
74
+ });
75
+ console.log("āœ“ Collection created with api.createCollection()");
76
+ await api.addToCollection("favorites", "item3", {
77
+ id: "item3",
78
+ title: "Third Item",
79
+ });
80
+ console.log("āœ“ Item added with api.addToCollection()");
81
+ const collection = await api.getCollection("favorites");
82
+ console.log("āœ“ Collection retrieved:", collection);
83
+ // === ARRAY UTILITIES ===
84
+ console.log("\nšŸ”§ === ARRAY UTILITIES ===\n");
85
+ const items = [
86
+ { id: "1", name: "Item 1", value: 100 },
87
+ { id: "2", name: "Item 2", value: 200 },
88
+ { id: "3", name: "Item 3", value: 300 },
89
+ ];
90
+ // Convert array to GunDB-friendly indexed object
91
+ const indexed = api.arrayToIndexedObject(items);
92
+ console.log("āœ“ Array converted to indexed object:", indexed);
93
+ // Convert back to array
94
+ const restored = api.indexedObjectToArray(indexed);
95
+ console.log("āœ“ Indexed object converted back to array:", restored);
79
96
  // Logout
80
- api.logout();
81
- console.log("Logged out");
97
+ db.logout();
98
+ console.log("\nāœ“ Logged out");
82
99
  }
83
100
  }
84
- console.log("\nāœ… Test completato!");
101
+ console.log("\nāœ… Example completed!");
102
+ console.log("\nSummary:");
103
+ console.log("- Use AutoQuickStart for easy initialization");
104
+ console.log("- Use api.database for basic operations (get, put, auth, etc.)");
105
+ console.log("- Use api helper methods for high-level operations:");
106
+ console.log(" • updateProfile(), getProfile()");
107
+ console.log(" • saveSettings(), getSettings()");
108
+ console.log(" • createCollection(), addToCollection(), getCollection()");
109
+ console.log(" • arrayToIndexedObject(), indexedObjectToArray()");
85
110
  }
86
111
  // Esegui il test
87
112
  if (require.main === module) {