shogun-core 3.0.4 → 3.0.6

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.
Files changed (93) hide show
  1. package/dist/browser/shogun-core.js +91002 -0
  2. package/dist/browser/shogun-core.js.map +1 -0
  3. package/dist/config/simplified-config.js +230 -0
  4. package/dist/core.js +338 -0
  5. package/dist/gundb/crypto.js +268 -0
  6. package/dist/gundb/db.js +1829 -0
  7. package/dist/gundb/derive.js +229 -0
  8. package/dist/gundb/errors.js +66 -0
  9. package/dist/gundb/index.js +6 -0
  10. package/dist/gundb/rxjs.js +445 -0
  11. package/dist/gundb/simple-api.js +438 -0
  12. package/dist/gundb/types.js +4 -0
  13. package/dist/index.js +16 -0
  14. package/dist/interfaces/common.js +1 -0
  15. package/dist/interfaces/events.js +36 -0
  16. package/dist/interfaces/plugin.js +1 -0
  17. package/dist/interfaces/shogun.js +34 -0
  18. package/dist/managers/AuthManager.js +225 -0
  19. package/dist/managers/CoreInitializer.js +227 -0
  20. package/dist/managers/EventManager.js +67 -0
  21. package/dist/managers/PluginManager.js +296 -0
  22. package/dist/migration-test.js +91 -0
  23. package/dist/plugins/base.js +47 -0
  24. package/dist/plugins/index.js +15 -0
  25. package/dist/plugins/nostr/index.js +4 -0
  26. package/dist/plugins/nostr/nostrConnector.js +413 -0
  27. package/dist/plugins/nostr/nostrConnectorPlugin.js +446 -0
  28. package/dist/plugins/nostr/nostrSigner.js +313 -0
  29. package/dist/plugins/nostr/types.js +1 -0
  30. package/dist/plugins/oauth/index.js +3 -0
  31. package/dist/plugins/oauth/oauthConnector.js +753 -0
  32. package/dist/plugins/oauth/oauthPlugin.js +396 -0
  33. package/dist/plugins/oauth/types.js +1 -0
  34. package/dist/plugins/web3/index.js +4 -0
  35. package/dist/plugins/web3/types.js +1 -0
  36. package/dist/plugins/web3/web3Connector.js +528 -0
  37. package/dist/plugins/web3/web3ConnectorPlugin.js +448 -0
  38. package/dist/plugins/web3/web3Signer.js +308 -0
  39. package/dist/plugins/webauthn/index.js +3 -0
  40. package/dist/plugins/webauthn/types.js +11 -0
  41. package/dist/plugins/webauthn/webauthn.js +478 -0
  42. package/dist/plugins/webauthn/webauthnPlugin.js +398 -0
  43. package/dist/plugins/webauthn/webauthnSigner.js +304 -0
  44. package/dist/storage/storage.js +147 -0
  45. package/dist/types/config/simplified-config.d.ts +114 -0
  46. package/dist/types/core.d.ts +305 -0
  47. package/dist/types/gundb/crypto.d.ts +95 -0
  48. package/dist/types/gundb/db.d.ts +401 -0
  49. package/dist/types/gundb/derive.d.ts +21 -0
  50. package/dist/types/gundb/errors.d.ts +42 -0
  51. package/dist/types/gundb/index.d.ts +3 -0
  52. package/dist/types/gundb/rxjs.d.ts +110 -0
  53. package/dist/types/gundb/simple-api.d.ts +90 -0
  54. package/dist/types/gundb/types.d.ts +264 -0
  55. package/dist/types/index.d.ts +14 -0
  56. package/dist/types/interfaces/common.d.ts +85 -0
  57. package/dist/types/interfaces/events.d.ts +131 -0
  58. package/dist/types/interfaces/plugin.d.ts +162 -0
  59. package/dist/types/interfaces/shogun.d.ts +215 -0
  60. package/dist/types/managers/AuthManager.d.ts +72 -0
  61. package/dist/types/managers/CoreInitializer.d.ts +40 -0
  62. package/dist/types/managers/EventManager.d.ts +49 -0
  63. package/dist/types/managers/PluginManager.d.ts +145 -0
  64. package/dist/types/migration-test.d.ts +16 -0
  65. package/dist/types/plugins/base.d.ts +35 -0
  66. package/dist/types/plugins/index.d.ts +14 -0
  67. package/dist/types/plugins/nostr/index.d.ts +4 -0
  68. package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
  69. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
  70. package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
  71. package/dist/types/plugins/nostr/types.d.ts +122 -0
  72. package/dist/types/plugins/oauth/index.d.ts +3 -0
  73. package/dist/types/plugins/oauth/oauthConnector.d.ts +110 -0
  74. package/dist/types/plugins/oauth/oauthPlugin.d.ts +91 -0
  75. package/dist/types/plugins/oauth/types.d.ts +114 -0
  76. package/dist/types/plugins/web3/index.d.ts +4 -0
  77. package/dist/types/plugins/web3/types.d.ts +107 -0
  78. package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
  79. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
  80. package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
  81. package/dist/types/plugins/webauthn/index.d.ts +3 -0
  82. package/dist/types/plugins/webauthn/types.d.ts +162 -0
  83. package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
  84. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +158 -0
  85. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
  86. package/dist/types/storage/storage.d.ts +50 -0
  87. package/dist/types/utils/errorHandler.d.ts +119 -0
  88. package/dist/types/utils/eventEmitter.d.ts +39 -0
  89. package/dist/types/utils/validation.d.ts +27 -0
  90. package/dist/utils/errorHandler.js +241 -0
  91. package/dist/utils/eventEmitter.js +76 -0
  92. package/dist/utils/validation.js +72 -0
  93. package/package.json +1 -1
@@ -0,0 +1,401 @@
1
+ /**
2
+ * GunDB class with enhanced features:
3
+ * - Dynamic peer linking
4
+ * - Support for remove/unset operations
5
+ * - Direct authentication through Gun.user()
6
+ */
7
+ import type { GunUser, UserInfo, AuthCallback, GunData, EventData, EventListener, GunOperationResult } from "./types";
8
+ import type { GunInstance, GunUserInstance, GunChain } from "./types";
9
+ import type { AuthResult, SignUpResult } from "../interfaces/shogun";
10
+ import Gun from "gun/gun";
11
+ import SEA from "gun/sea";
12
+ import "gun/lib/then";
13
+ import "gun/lib/radix";
14
+ import "gun/lib/radisk";
15
+ import "gun/lib/store";
16
+ import "gun/lib/rindexed";
17
+ import "gun/lib/webrtc";
18
+ import derive, { DeriveOptions } from "./derive";
19
+ import type { ISEAPair } from "gun/types";
20
+ import { GunDataEventData, GunPeerEventData } from "../interfaces/events";
21
+ import { RxJS } from "./rxjs";
22
+ import * as GunErrors from "./errors";
23
+ import * as crypto from "./crypto";
24
+ declare class DataBase {
25
+ gun: GunInstance;
26
+ user: GunUserInstance | null;
27
+ crypto: typeof crypto;
28
+ sea: typeof SEA;
29
+ node: GunChain;
30
+ private readonly onAuthCallbacks;
31
+ private readonly eventEmitter;
32
+ private _rxjs?;
33
+ constructor(gun: GunInstance, appScope?: string);
34
+ /**
35
+ * Initialize the GunInstance asynchronously
36
+ * This method should be called after construction to perform async operations
37
+ */
38
+ initialize(appScope?: string): Promise<void>;
39
+ private subscribeToAuthEvents;
40
+ private notifyAuthListeners;
41
+ /**
42
+ * Adds a new peer to the network
43
+ * @param peer URL of the peer to add
44
+ */
45
+ addPeer(peer: string): void;
46
+ /**
47
+ * Removes a peer from the network
48
+ * @param peer URL of the peer to remove
49
+ */
50
+ removePeer(peer: string): void;
51
+ /**
52
+ * Gets the list of currently connected peers
53
+ * @returns Array of peer URLs
54
+ */
55
+ getCurrentPeers(): string[];
56
+ /**
57
+ * Gets the list of all configured peers (connected and disconnected)
58
+ * @returns Array of peer URLs
59
+ */
60
+ getAllConfiguredPeers(): string[];
61
+ /**
62
+ * Gets detailed information about all peers
63
+ * @returns Object with peer information
64
+ */
65
+ getPeerInfo(): {
66
+ [peer: string]: {
67
+ connected: boolean;
68
+ status: string;
69
+ };
70
+ };
71
+ /**
72
+ * Reconnects to a specific peer
73
+ * @param peer URL of the peer to reconnect
74
+ */
75
+ reconnectToPeer(peer: string): void;
76
+ /**
77
+ * Clears all peers and optionally adds new ones
78
+ * @param newPeers Optional array of new peers to add
79
+ */
80
+ resetPeers(newPeers?: string[]): void;
81
+ /**
82
+ * Registers an authentication callback
83
+ * @param callback Function to call on auth events
84
+ * @returns Function to unsubscribe the callback
85
+ */
86
+ onAuth(callback: AuthCallback): () => void;
87
+ /**
88
+ * Helper method to navigate to a nested path by splitting and chaining .get() calls
89
+ * @param node Starting Gun node
90
+ * @param path Path string (e.g., "test/data/marco")
91
+ * @returns Gun node at the specified path
92
+ */
93
+ private navigateToPath;
94
+ /**
95
+ * Gets the Gun instance
96
+ * @returns Gun instance
97
+ */
98
+ getGun(): GunInstance;
99
+ /**
100
+ * Gets the current user
101
+ * @returns Current user object or null
102
+ */
103
+ getCurrentUser(): UserInfo | null;
104
+ /**
105
+ * Gets the current user instance
106
+ * @returns User instance
107
+ */
108
+ getUser(): GunUser;
109
+ /**
110
+ * Gets a node at the specified path
111
+ * @param path Path to the node
112
+ * @returns Gun node
113
+ */
114
+ get(path: string): any;
115
+ /**
116
+ * Gets data at the specified path (one-time read)
117
+ * @param path Path to get the data from
118
+ * @returns Promise resolving to the data
119
+ */
120
+ getData(path: string): Promise<GunData>;
121
+ /**
122
+ * Puts data at the specified path
123
+ * @param path Path to store data
124
+ * @param data Data to store
125
+ * @returns Promise resolving to operation result
126
+ */
127
+ put(path: string, data: GunData): Promise<GunOperationResult>;
128
+ /**
129
+ * Sets data at the specified path
130
+ * @param path Path to store data
131
+ * @param data Data to store
132
+ * @returns Promise resolving to operation result
133
+ */
134
+ set(path: string, data: GunData): Promise<GunOperationResult>;
135
+ /**
136
+ * Removes data at the specified path
137
+ * @param path Path to remove
138
+ * @returns Promise resolving to operation result
139
+ */
140
+ remove(path: string): Promise<GunOperationResult>;
141
+ /**
142
+ * Checks if a user is currently logged in
143
+ * @returns True if logged in
144
+ */
145
+ isLoggedIn(): boolean;
146
+ /**
147
+ * Attempts to restore user session from local storage
148
+ * @returns Promise resolving to session restoration result
149
+ */
150
+ restoreSession(): {
151
+ success: boolean;
152
+ userPub?: string;
153
+ error?: string;
154
+ };
155
+ logout(): void;
156
+ /**
157
+ * Accesses the RxJS module for reactive programming
158
+ * @returns GunRxJS instance
159
+ */
160
+ rx(): RxJS;
161
+ /**
162
+ * Validates password strength according to security requirements
163
+ */
164
+ private validatePasswordStrength;
165
+ /**
166
+ * Validates signup credentials with enhanced security
167
+ */
168
+ private validateSignupCredentials;
169
+ /**
170
+ * Creates a new user in Gun
171
+ */
172
+ private createNewUser;
173
+ /**
174
+ * Authenticates user after creation
175
+ */
176
+ private authenticateNewUser;
177
+ /**
178
+ * Signs up a new user using direct Gun authentication
179
+ * @param username Username
180
+ * @param password Password
181
+ * @param pair Optional SEA pair for Web3 login
182
+ * @returns Promise resolving to signup result
183
+ */
184
+ signUp(username: string, password: string, pair?: ISEAPair | null): Promise<SignUpResult>;
185
+ /**
186
+ * Creates a new user in Gun with pair-based authentication (for Web3/plugins)
187
+ */
188
+ private createNewUserWithPair;
189
+ private runPostAuthOnAuthResult;
190
+ /**
191
+ * Sets up comprehensive user tracking system for agile user lookup
192
+ * Creates multiple indexes for efficient user discovery
193
+ */
194
+ private setupComprehensiveUserTracking;
195
+ /**
196
+ * Creates alias index following GunDB pattern: ~@alias -> userPub
197
+ */
198
+ private createAliasIndex;
199
+ /**
200
+ * Creates username mapping: usernames/alias -> userPub
201
+ */
202
+ private createUsernameMapping;
203
+ /**
204
+ * Creates user registry: users/userPub -> user data
205
+ */
206
+ private createUserRegistry;
207
+ /**
208
+ * Creates reverse lookup: userPub -> alias
209
+ */
210
+ private createReverseLookup;
211
+ /**
212
+ * Creates epub index: epubKeys/epub -> userPub
213
+ */
214
+ private createEpubIndex;
215
+ /**
216
+ * Creates user metadata in user's own node
217
+ */
218
+ private createUserMetadata;
219
+ /**
220
+ * Gets user information by alias using the comprehensive tracking system
221
+ * @param alias Username/alias to lookup
222
+ * @returns Promise resolving to user information or null if not found
223
+ */
224
+ getUserByAlias(alias: string): Promise<{
225
+ userPub: string;
226
+ epub: string | null;
227
+ username: string;
228
+ registeredAt: number;
229
+ lastSeen: number;
230
+ } | null>;
231
+ /**
232
+ * Gets user information by public key
233
+ * @param userPub User's public key
234
+ * @returns Promise resolving to user information or null if not found
235
+ */
236
+ getUserDataByPub(userPub: string): Promise<{
237
+ userPub: string;
238
+ epub: string | null;
239
+ username: string;
240
+ registeredAt: number;
241
+ lastSeen: number;
242
+ } | null>;
243
+ /**
244
+ * Gets user public key by encryption public key (epub)
245
+ * @param epub User's encryption public key
246
+ * @returns Promise resolving to user public key or null if not found
247
+ */
248
+ getUserPubByEpub(epub: string): Promise<string | null>;
249
+ /**
250
+ * Gets user alias by public key
251
+ * @param userPub User's public key
252
+ * @returns Promise resolving to user alias or null if not found
253
+ */
254
+ getUserAliasByPub(userPub: string): Promise<string | null>;
255
+ /**
256
+ * Gets all registered users (for admin purposes)
257
+ * @returns Promise resolving to array of user information
258
+ */
259
+ getAllRegisteredUsers(): Promise<Array<{
260
+ userPub: string;
261
+ epub: string | null;
262
+ username: string;
263
+ registeredAt: number;
264
+ lastSeen: number;
265
+ }>>;
266
+ /**
267
+ * Updates user's last seen timestamp
268
+ * @param userPub User's public key
269
+ */
270
+ updateUserLastSeen(userPub: string): Promise<void>;
271
+ /**
272
+ * Performs authentication with Gun
273
+ */
274
+ private performAuthentication;
275
+ /**
276
+ * Builds login result object
277
+ */
278
+ private buildLoginResult;
279
+ login(username: string, password: string, pair?: ISEAPair | null): Promise<AuthResult>;
280
+ /**
281
+ * Encrypts session data before storage
282
+ */
283
+ private encryptSessionData;
284
+ /**
285
+ * Decrypts session data from storage
286
+ */
287
+ private decryptSessionData;
288
+ private saveCredentials;
289
+ /**
290
+ * Sets up security questions and password hint
291
+ * @param username Username
292
+ * @param password Current password
293
+ * @param hint Password hint
294
+ * @param securityQuestions Array of security questions
295
+ * @param securityAnswers Array of answers to security questions
296
+ * @returns Promise resolving with the operation result
297
+ */
298
+ setPasswordHintWithSecurity(username: string, password: string, hint: string, securityQuestions: string[], securityAnswers: string[]): Promise<{
299
+ success: boolean;
300
+ error?: string;
301
+ }>;
302
+ /**
303
+ * Recovers password hint using security question answers
304
+ * @param username Username
305
+ * @param securityAnswers Array of answers to security questions
306
+ * @returns Promise resolving with the password hint
307
+ */
308
+ forgotPassword(username: string, securityAnswers: string[]): Promise<{
309
+ success: boolean;
310
+ hint?: string;
311
+ error?: string;
312
+ }>;
313
+ /**
314
+ * Saves user data at the specified path
315
+ * @param path Path to save the data (supports nested paths like "test/data/marco")
316
+ * @param data Data to save
317
+ * @returns Promise that resolves when the data is saved
318
+ */
319
+ putUserData(path: string, data: any): Promise<void>;
320
+ /**
321
+ * Gets user data from the specified path
322
+ * @param path Path to get the data from (supports nested paths like "test/data/marco")
323
+ * @returns Promise that resolves with the data
324
+ */
325
+ getUserData(path: string): Promise<any>;
326
+ static Errors: typeof GunErrors;
327
+ /**
328
+ * Adds an event listener
329
+ * @param event Event name
330
+ * @param listener Event listener function
331
+ */
332
+ on(event: string | symbol, listener: EventListener): void;
333
+ /**
334
+ * Removes an event listener
335
+ * @param event Event name
336
+ * @param listener Event listener function
337
+ */
338
+ off(event: string | symbol, listener: EventListener): void;
339
+ /**
340
+ * Adds a one-time event listener
341
+ * @param event Event name
342
+ * @param listener Event listener function
343
+ */
344
+ once(event: string | symbol, listener: EventListener): void;
345
+ /**
346
+ * Emits an event
347
+ * @param event Event name
348
+ * @param data Event data
349
+ */
350
+ emit(event: string | symbol, data?: EventData): boolean;
351
+ /**
352
+ * Recall user session
353
+ */
354
+ recall(): void;
355
+ /**
356
+ * Leave user session
357
+ */
358
+ leave(): void;
359
+ /**
360
+ * Set user data
361
+ */
362
+ setUserData(data: any): void;
363
+ /**
364
+ * Set password hint
365
+ */
366
+ setPasswordHint(hint: string): void;
367
+ /**
368
+ * Get password hint
369
+ */
370
+ getPasswordHint(): string | null;
371
+ /**
372
+ * Save session to storage
373
+ */
374
+ saveSession(session: any): void;
375
+ /**
376
+ * Load session from storage
377
+ */
378
+ loadSession(): any;
379
+ /**
380
+ * Clear session
381
+ */
382
+ clearSession(): void;
383
+ /**
384
+ * Get app scope
385
+ */
386
+ getAppScope(): string;
387
+ /**
388
+ * Get user public key
389
+ */
390
+ getUserPub(): string | null;
391
+ /**
392
+ * Check if user is authenticated
393
+ */
394
+ isAuthenticated(): boolean;
395
+ }
396
+ declare const createGun: (config: any) => import("gun").IGunInstance<any>;
397
+ export { Gun, DataBase, SEA, RxJS, crypto, GunErrors, derive, createGun };
398
+ export default Gun;
399
+ export type { IGunUserInstance, IGunInstance, IGunChain } from "gun/types";
400
+ export type { GunDataEventData, GunPeerEventData };
401
+ export type { DeriveOptions };
@@ -0,0 +1,21 @@
1
+ export interface DeriveOptions {
2
+ includeSecp256k1Bitcoin?: boolean;
3
+ includeSecp256k1Ethereum?: boolean;
4
+ includeP256?: boolean;
5
+ }
6
+ export default function (pwd: any, extra: any, options?: DeriveOptions): Promise<{
7
+ pub: string;
8
+ priv: string;
9
+ epub: string;
10
+ epriv: string;
11
+ secp256k1Bitcoin: {
12
+ privateKey: string;
13
+ publicKey: string;
14
+ address: string;
15
+ };
16
+ secp256k1Ethereum: {
17
+ privateKey: string;
18
+ publicKey: string;
19
+ address: string;
20
+ };
21
+ }>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Error classes for Gun and Auth
3
+ */
4
+ /**
5
+ * Base error for Gun
6
+ */
7
+ export declare class GunError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ /**
11
+ * Generic authentication error
12
+ */
13
+ export declare class AuthError extends GunError {
14
+ constructor(message: string);
15
+ }
16
+ /**
17
+ * Invalid credentials error
18
+ */
19
+ export declare class InvalidCredentials extends AuthError {
20
+ constructor(message?: string);
21
+ }
22
+ /**
23
+ * User already exists error
24
+ */
25
+ export declare class UserExists extends AuthError {
26
+ constructor(message?: string);
27
+ }
28
+ /**
29
+ * Timeout error
30
+ */
31
+ export declare class TimeoutError extends GunError {
32
+ constructor(message?: string);
33
+ }
34
+ /**
35
+ * Multiple authentication error
36
+ */
37
+ export declare class MultipleAuthError extends AuthError {
38
+ constructor(message?: string);
39
+ }
40
+ /** Base error related to the network. */
41
+ export declare class NetworkError extends GunError {
42
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./db";
2
+ export * from "./types";
3
+ export * from "./simple-api";
@@ -0,0 +1,110 @@
1
+ import { Observable } from "rxjs";
2
+ import { GunInstance, GunUserInstance } from "./types";
3
+ /**
4
+ * RxJS Integration for GunDB
5
+ * Provides reactive programming capabilities for GunDB data
6
+ */
7
+ export declare class RxJS {
8
+ private readonly gun;
9
+ private readonly user;
10
+ /**
11
+ * Initialize GunRxJS with a GunDB instance
12
+ * @param gun - GunDB instance
13
+ */
14
+ constructor(gun: GunInstance);
15
+ /**
16
+ * Get the current user
17
+ * @returns The current user
18
+ */
19
+ getUser(): GunUserInstance;
20
+ /**
21
+ * Get the current user's public key
22
+ * @returns The current user's public key
23
+ */
24
+ getUserPub(): string | undefined;
25
+ /**
26
+ * Observe a Gun node for changes
27
+ * @param path - Path to observe (can be a string or a Gun chain)
28
+ * @returns Observable that emits whenever the node changes
29
+ */
30
+ observe<T>(path: string | any): Observable<T>;
31
+ /**
32
+ * Match data based on Gun's '.map()' and convert to Observable
33
+ * @param path - Path to the collection
34
+ * @param matchFn - Optional function to filter results
35
+ * @returns Observable array of matched items
36
+ */
37
+ match<T>(path: string | any, matchFn?: (data: any) => boolean): Observable<T[]>;
38
+ /**
39
+ * Put data and return an Observable
40
+ * @param path - Path where to put the data
41
+ * @param data - Data to put
42
+ * @returns Observable that completes when the put is acknowledged
43
+ */
44
+ put<T>(path: string | any, data?: T): Observable<T>;
45
+ /**
46
+ * Backward-compatible overload that accepts optional callback like tests expect
47
+ */
48
+ putCompat<T extends Partial<any> & Record<string, any>>(data: T, callback?: (ack: any) => void): Observable<T>;
49
+ /**
50
+ * Set data on a node and return an Observable
51
+ * @param path - Path to the collection
52
+ * @param data - Data to set
53
+ * @returns Observable that completes when the set is acknowledged
54
+ */
55
+ set<T>(path: string | any, data?: T): Observable<T>;
56
+ setCompat<T>(data: T, callback?: (ack: any) => void): Observable<T>;
57
+ /**
58
+ * Get data once and return as Observable
59
+ * @param path - Path to get data from
60
+ * @returns Observable that emits the data once
61
+ */
62
+ once<T>(path?: string | any): Observable<T>;
63
+ /**
64
+ * Compute derived values from gun data
65
+ * @param sources - Array of paths or observables to compute from
66
+ * @param computeFn - Function that computes a new value from the sources
67
+ * @returns Observable of computed values
68
+ */
69
+ compute<T, R>(sources: Array<string | Observable<any>>, computeFn: (...values: T[]) => R): Observable<R>;
70
+ /**
71
+ * User put data and return an Observable (for authenticated users)
72
+ * @param path - Path where to put the data
73
+ * @param data - Data to put
74
+ * @returns Observable that completes when the put is acknowledged
75
+ */
76
+ userPut<T extends Partial<any> & Record<string, any>>(dataOrPath: string | T, maybeData?: T, callback?: (ack: any) => void): Observable<T>;
77
+ /**
78
+ * User set data and return an Observable (for authenticated users)
79
+ * @param dataOrPath - Data to set or path where to set the data
80
+ * @param maybeData - Data to set (if first parameter is path)
81
+ * @param callback - Optional callback function
82
+ * @returns Observable that completes when the set is acknowledged
83
+ */
84
+ userSet<T extends Partial<any> & Record<string, any>>(dataOrPath: string | T, maybeData?: T, callback?: (ack: any) => void): Observable<T>;
85
+ /**
86
+ * User once data and return an Observable (for authenticated users)
87
+ * @param path - Optional path to get data from
88
+ * @param callback - Optional callback function
89
+ * @returns Observable that emits the data once
90
+ */
91
+ userOnce<T>(path?: string, callback?: (ack: any) => void): Observable<T>;
92
+ /**
93
+ * Get user data
94
+ * @param path - Path to get data from
95
+ * @returns Observable that emits the data once
96
+ */
97
+ userGet<T>(path: string): Observable<T>;
98
+ /**
99
+ * Observe user data
100
+ * @param path - Path to observe in user space
101
+ * @returns Observable that emits whenever the user data changes
102
+ */
103
+ observeUser<T>(path?: string): Observable<T>;
104
+ /**
105
+ * Remove Gun metadata from an object
106
+ * @param obj - Object to clean
107
+ * @returns Cleaned object without Gun metadata
108
+ */
109
+ private removeGunMeta;
110
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Simplified API layer to reduce complexity for common use cases
3
+ * Provides quick-start methods that wrap the full DataBase functionality
4
+ */
5
+ import { DataBase } from "./db";
6
+ /**
7
+ * Simple API wrapper that provides common operations with minimal complexity
8
+ */
9
+ export declare class SimpleGunAPI {
10
+ private db;
11
+ constructor(db: DataBase);
12
+ /**
13
+ * Quick data operations - simplified interface
14
+ */
15
+ get<T = unknown>(path: string): Promise<T | null>;
16
+ put<T = unknown>(path: string, data: T): Promise<boolean>;
17
+ set<T = unknown>(path: string, data: T): Promise<boolean>;
18
+ remove(path: string): Promise<boolean>;
19
+ /**
20
+ * Quick authentication - simplified interface
21
+ */
22
+ login(username: string, password: string): Promise<{
23
+ userPub: string;
24
+ username: string;
25
+ } | null>;
26
+ signup(username: string, password: string): Promise<{
27
+ userPub: string;
28
+ username: string;
29
+ } | null>;
30
+ logout(): void;
31
+ isLoggedIn(): boolean;
32
+ /**
33
+ * Quick user data operations - simplified interface
34
+ */
35
+ getUserData<T = unknown>(path: string): Promise<T | null>;
36
+ putUserData<T = unknown>(path: string, data: T): Promise<boolean>;
37
+ setUserData<T = unknown>(path: string, data: T): Promise<boolean>;
38
+ removeUserData(path: string): Promise<boolean>;
39
+ /**
40
+ * Quick utility methods
41
+ */
42
+ getCurrentUser(): {
43
+ pub: string;
44
+ username?: string;
45
+ } | null;
46
+ userExists(alias: string): Promise<boolean>;
47
+ getUser(alias: string): Promise<{
48
+ userPub: string;
49
+ username: string;
50
+ } | null>;
51
+ /**
52
+ * Advanced user space operations
53
+ */
54
+ getAllUserData(): Promise<Record<string, unknown> | null>;
55
+ updateProfile(profileData: {
56
+ name?: string;
57
+ email?: string;
58
+ bio?: string;
59
+ avatar?: string;
60
+ [key: string]: unknown;
61
+ }): Promise<boolean>;
62
+ getProfile(): Promise<Record<string, unknown> | null>;
63
+ saveSettings(settings: Record<string, unknown>): Promise<boolean>;
64
+ getSettings(): Promise<Record<string, unknown> | null>;
65
+ savePreferences(preferences: Record<string, unknown>): Promise<boolean>;
66
+ getPreferences(): Promise<Record<string, unknown> | null>;
67
+ createCollection<T = unknown>(collectionName: string, items: Record<string, T>): Promise<boolean>;
68
+ addToCollection<T = unknown>(collectionName: string, itemId: string, item: T): Promise<boolean>;
69
+ getCollection(collectionName: string): Promise<Record<string, unknown> | null>;
70
+ removeFromCollection(collectionName: string, itemId: string): Promise<boolean>;
71
+ }
72
+ /**
73
+ * Factory function to create a simple API instance
74
+ */
75
+ export declare function createSimpleAPI(db: DataBase): SimpleGunAPI;
76
+ /**
77
+ * Quick start helper - creates a simple API with minimal configuration
78
+ */
79
+ export declare class QuickStart {
80
+ private db;
81
+ private simpleAPI;
82
+ constructor(gunInstance: any, appScope?: string);
83
+ init(): Promise<void>;
84
+ get api(): SimpleGunAPI;
85
+ get database(): DataBase;
86
+ }
87
+ /**
88
+ * Global helper for quick setup
89
+ */
90
+ export declare function quickStart(gunInstance: any, appScope?: string): QuickStart;