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/README.md +76 -121
- package/dist/browser/shogun-core.js +164 -491
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/core.js +4 -5
- package/dist/examples/simple-api-test.js +90 -65
- package/dist/gundb/api.js +111 -467
- package/dist/gundb/db.js +44 -15
- package/dist/managers/AuthManager.js +4 -3
- package/dist/managers/CoreInitializer.js +1 -1
- package/dist/types/core.d.ts +2 -2
- package/dist/types/examples/simple-api-test.d.ts +6 -1
- package/dist/types/gundb/api.d.ts +77 -165
- package/dist/types/gundb/db.d.ts +15 -6
- package/dist/types/interfaces/events.d.ts +1 -1
- package/dist/types/interfaces/shogun.d.ts +7 -1
- package/dist/types/managers/AuthManager.d.ts +1 -1
- package/package.json +1 -8
- package/dist/examples/api-test.js +0 -273
- package/dist/types/events.js +0 -70
- package/dist/types/examples/api-test.d.ts +0 -12
- package/dist/types/shogun.js +0 -21
- package/dist/types/types/events.d.ts +0 -59
- package/dist/types/types/shogun.d.ts +0 -188
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.
|
|
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.
|
|
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
|
-
*
|
|
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("š
|
|
10
|
-
//
|
|
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
|
-
//
|
|
18
|
-
console.log("
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
//
|
|
34
|
-
|
|
35
|
-
console.log("put()
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.log("
|
|
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
|
|
58
|
-
console.log("Signup
|
|
59
|
-
if (signupResult) {
|
|
60
|
-
const loginResult = await
|
|
61
|
-
console.log("Login
|
|
62
|
-
if (loginResult) {
|
|
63
|
-
console.log("
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
console.log("Logged out");
|
|
97
|
+
db.logout();
|
|
98
|
+
console.log("\nā Logged out");
|
|
82
99
|
}
|
|
83
100
|
}
|
|
84
|
-
console.log("\nā
|
|
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) {
|