shogun-core 3.0.0 → 3.0.2

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
@@ -16,7 +16,7 @@ import { CoreInitializer } from "./managers/CoreInitializer";
16
16
  * @since 2.0.0
17
17
  */
18
18
  export class ShogunCore {
19
- static API_VERSION = "^1.6.6";
19
+ static API_VERSION = "^3.0.1";
20
20
  db;
21
21
  storage;
22
22
  provider;
package/dist/gundb/db.js CHANGED
@@ -951,11 +951,9 @@ class DataBase {
951
951
  async createAliasIndex(username, userPub) {
952
952
  try {
953
953
  const aliasNode = this.gun.get(`~@${username}`);
954
- const ack = await aliasNode
955
- .put({
956
- "~pubKeyOfUser": this.gun.get(userPub),
957
- })
958
- .then();
954
+ // For Gun.js alias validation to pass, the data must be exactly equal to the key
955
+ // The key is `~@${username}`, so we store that as the data
956
+ const ack = await aliasNode.put(`~@${username}`).then();
959
957
  if (ack.err) {
960
958
  console.error(`Error creating alias index: ${ack.err}`);
961
959
  }
@@ -1824,7 +1822,12 @@ class DataBase {
1824
1822
  }
1825
1823
  }
1826
1824
  const createGun = (config) => {
1827
- return new Gun(config);
1825
+ console.log("Creating Gun instance with config:", config);
1826
+ console.log("Config peers:", config?.peers);
1827
+ const gunInstance = new Gun(config);
1828
+ console.log("Created Gun instance:", gunInstance);
1829
+ console.log("Gun instance opt after creation:", gunInstance?.opt);
1830
+ return gunInstance;
1828
1831
  };
1829
1832
  export { Gun, DataBase, SEA, RxJS, crypto, GunErrors, derive, restrictedPut, createGun, };
1830
1833
  export default Gun;
@@ -1,6 +1,6 @@
1
1
  // Export the main class
2
2
  export * from "./db";
3
3
  // Export improved types
4
- export * from "./improved-types";
4
+ export * from "./types";
5
5
  // Export simplified API
6
6
  export * from "./simple-api";
@@ -50,7 +50,7 @@ export class CoreInitializer {
50
50
  // Setup wallet derivation
51
51
  this.setupWalletDerivation();
52
52
  // Initialize RxJS
53
- this.core.rx = new RxJS(this.core._gun);
53
+ this.core.rx = new RxJS(this.core.gun);
54
54
  // Register built-in plugins
55
55
  this.registerBuiltinPlugins(config);
56
56
  // Initialize async components
@@ -60,15 +60,25 @@ export class CoreInitializer {
60
60
  * Initialize Gun instance
61
61
  */
62
62
  async initializeGun(config) {
63
+ console.log("Initialize Gun instance", config);
63
64
  if (config.gunOptions.authToken) {
64
65
  restrictedPut(Gun, config.gunOptions.authToken);
65
66
  }
66
67
  try {
67
- if (config.gunInstance) {
68
+ if (config.gunInstance && config.gunInstance instanceof Gun) {
69
+ console.log("config.gunInstance", config.gunInstance);
68
70
  this.core._gun = config.gunInstance;
69
71
  }
70
72
  else {
73
+ console.log("config.gunOptions", config.gunOptions);
71
74
  this.core._gun = createGun(config.gunOptions);
75
+ // Explicitly apply peers configuration if not already set
76
+ if (config.gunOptions?.peers &&
77
+ Array.isArray(config.gunOptions.peers)) {
78
+ console.log("Applying peers configuration:", config.gunOptions.peers);
79
+ this.core._gun.opt({ peers: config.gunOptions.peers });
80
+ console.log("Peers after explicit application:", this.core._gun?.opt?.peers);
81
+ }
72
82
  }
73
83
  }
74
84
  catch (error) {
@@ -78,7 +88,8 @@ export class CoreInitializer {
78
88
  throw new Error(`Failed to create Gun instance: ${error}`);
79
89
  }
80
90
  try {
81
- this.core.db = new DataBase(this.core._gun, config.gunOptions.scope || "");
91
+ console.log("Initialize Gun instance", this.core.gun);
92
+ this.core.db = new DataBase(this.core.gun, config.gunOptions.scope || "");
82
93
  this.core._gun = this.core.db.gun;
83
94
  }
84
95
  catch (error) {
@@ -93,9 +104,7 @@ export class CoreInitializer {
93
104
  */
94
105
  async initializeGunUser() {
95
106
  try {
96
- this.core._user = this.core._gun
97
- .user()
98
- .recall({ sessionStorage: true });
107
+ this.core.user = this.core.gun.user().recall({ sessionStorage: true });
99
108
  }
100
109
  catch (error) {
101
110
  if (typeof console !== "undefined" && console.error) {
@@ -103,10 +112,8 @@ export class CoreInitializer {
103
112
  }
104
113
  throw new Error(`Failed to initialize Gun user: ${error}`);
105
114
  }
106
- this.core._gun.on("auth", (user) => {
107
- this.core._user = this.core._gun
108
- .user()
109
- .recall({ sessionStorage: true });
115
+ this.core.gun.on("auth", (user) => {
116
+ this.core.user = this.core.gun.user().recall({ sessionStorage: true });
110
117
  this.core.emit("auth:login", {
111
118
  userPub: user.pub,
112
119
  method: "password",
@@ -139,7 +146,7 @@ export class CoreInitializer {
139
146
  * Setup wallet derivation
140
147
  */
141
148
  setupWalletDerivation() {
142
- this.core._gun.on("auth", async (user) => {
149
+ this.core.gun.on("auth", async (user) => {
143
150
  if (!user)
144
151
  return;
145
152
  const priv = user._?.sea?.epriv;
@@ -6,6 +6,7 @@ import { ethers } from "ethers";
6
6
  import { ShogunPlugin } from "./interfaces/plugin";
7
7
  import { ISEAPair } from "gun";
8
8
  import { DataBase, RxJS, GunInstance, GunUserInstance } from "./gundb";
9
+ import { PluginManager } from "./managers/PluginManager";
9
10
  /**
10
11
  * Main ShogunCore class - implements the IShogunCore interface
11
12
  *
@@ -18,16 +19,16 @@ import { DataBase, RxJS, GunInstance, GunUserInstance } from "./gundb";
18
19
  * @since 2.0.0
19
20
  */
20
21
  export declare class ShogunCore implements IShogunCore {
21
- static readonly API_VERSION = "^1.6.6";
22
+ static readonly API_VERSION = "^3.0.1";
22
23
  db: DataBase;
23
24
  storage: ShogunStorage;
24
25
  provider?: ethers.Provider;
25
26
  config: ShogunCoreConfig;
26
27
  rx: RxJS;
27
- private _gun;
28
- private _user;
28
+ _gun: GunInstance;
29
+ _user: GunUserInstance | null;
29
30
  wallets: Wallets | undefined;
30
- private pluginManager;
31
+ pluginManager: PluginManager;
31
32
  private authManager;
32
33
  private eventManager;
33
34
  private coreInitializer;
@@ -197,7 +198,10 @@ export declare class ShogunCore implements IShogunCore {
197
198
  * @returns The authentication plugin or undefined if not available
198
199
  * This is a more modern approach to accessing authentication methods
199
200
  */
200
- getAuthenticationMethod(type: AuthMethod): unknown;
201
+ getAuthenticationMethod(type: AuthMethod): ShogunPlugin | {
202
+ login: (username: string, password: string) => Promise<AuthResult>;
203
+ signUp: (username: string, password: string, confirm?: string) => Promise<SignUpResult>;
204
+ } | undefined;
201
205
  /**
202
206
  * Retrieve recent errors logged by the system
203
207
  * @param count - Number of errors to retrieve (default: 10)
@@ -5,7 +5,7 @@
5
5
  * - Direct authentication through Gun.user()
6
6
  */
7
7
  import type { GunUser, UserInfo, AuthCallback, GunData, EventData, EventListener, GunOperationResult } from "./types";
8
- import type { GunInstance, GunUserInstance, GunChain } from "./improved-types";
8
+ import type { GunInstance, GunUserInstance, GunChain } from "./types";
9
9
  import type { AuthResult, SignUpResult } from "../interfaces/shogun";
10
10
  import Gun from "gun/gun";
11
11
  import SEA from "gun/sea";
@@ -19,7 +19,7 @@ import "gun/lib/wire";
19
19
  import "gun/lib/axe";
20
20
  import { restrictedPut } from "./restricted-put";
21
21
  import derive, { DeriveOptions } from "./derive";
22
- import type { IGunInstance, ISEAPair } from "gun/types";
22
+ import type { ISEAPair } from "gun/types";
23
23
  import { GunDataEventData, GunPeerEventData } from "../interfaces/events";
24
24
  import { RxJS } from "./rxjs";
25
25
  import * as GunErrors from "./errors";
@@ -396,7 +396,7 @@ declare class DataBase {
396
396
  */
397
397
  isAuthenticated(): boolean;
398
398
  }
399
- declare const createGun: (config: any) => IGunInstance<any>;
399
+ declare const createGun: (config: any) => import("gun").IGunInstance<any>;
400
400
  export { Gun, DataBase, SEA, RxJS, crypto, GunErrors, derive, restrictedPut, createGun, };
401
401
  export default Gun;
402
402
  export type { IGunUserInstance, IGunInstance, IGunChain } from "gun/types";
@@ -1,3 +1,3 @@
1
1
  export * from "./db";
2
- export * from "./improved-types";
2
+ export * from "./types";
3
3
  export * from "./simple-api";
@@ -1,5 +1,5 @@
1
1
  import { Observable } from "rxjs";
2
- import { GunInstance, GunUserInstance } from "./improved-types";
2
+ import { GunInstance, GunUserInstance } from "./types";
3
3
  /**
4
4
  * RxJS Integration for GunDB
5
5
  * Provides reactive programming capabilities for GunDB data
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Type definitions for GunDB to replace 'any' usage
3
3
  */
4
- import type { IGunUserInstance, IGunInstance } from "gun/types";
5
4
  export type GunType = (config?: any) => IGunInstance<any>;
6
5
  export type SEAType = any;
7
6
  export type GunUser = IGunUserInstance<any>;
@@ -156,3 +155,110 @@ export interface GunOperationResult {
156
155
  success: boolean;
157
156
  error?: string;
158
157
  }
158
+ /**
159
+ * Improved type definitions to reduce 'any' usage while maintaining GunDB compatibility
160
+ */
161
+ import type { IGunUserInstance, IGunInstance, IGunChain, ISEAPair } from "gun/types";
162
+ export type GunInstance = IGunInstance<any>;
163
+ export type GunUserInstance = IGunUserInstance<any>;
164
+ export type GunChain = IGunChain<any, IGunInstance<any>, IGunInstance<any>, string>;
165
+ export interface GunAckCallback {
166
+ (ack: {
167
+ err?: string;
168
+ ok?: number;
169
+ pub?: string;
170
+ }): void;
171
+ }
172
+ export interface TypedGunOperationResult<T = unknown> {
173
+ success: boolean;
174
+ data?: T;
175
+ error?: string;
176
+ ack?: {
177
+ err?: string;
178
+ ok?: number;
179
+ pub?: string;
180
+ };
181
+ }
182
+ export interface TypedUserInfo {
183
+ pub: string;
184
+ alias?: string;
185
+ timestamp?: number;
186
+ user?: GunUserInstance;
187
+ metadata?: Record<string, unknown>;
188
+ }
189
+ export interface TypedAuthCallback {
190
+ (user: GunUserInstance): void;
191
+ }
192
+ export interface TypedAuthResult {
193
+ success: boolean;
194
+ userPub?: string;
195
+ username?: string;
196
+ error?: string;
197
+ ack?: {
198
+ err?: string;
199
+ ok?: number;
200
+ pub?: string;
201
+ sea?: ISEAPair;
202
+ };
203
+ sea?: ISEAPair;
204
+ }
205
+ export interface TypedGunConfig {
206
+ peers?: string[];
207
+ localStorage?: boolean;
208
+ radisk?: boolean;
209
+ file?: string;
210
+ uuid?: () => string;
211
+ [key: string]: unknown;
212
+ }
213
+ export interface TypedEventData {
214
+ type: string;
215
+ data: unknown;
216
+ timestamp: number;
217
+ source?: string;
218
+ }
219
+ export type GunPath = string | string[];
220
+ export interface PathOperation<T = unknown> {
221
+ path: GunPath;
222
+ data?: T;
223
+ callback?: GunAckCallback;
224
+ }
225
+ export interface TypedRxJSObservable<T = unknown> {
226
+ subscribe: (observer: {
227
+ next: (value: T) => void;
228
+ error?: (error: Error) => void;
229
+ complete?: () => void;
230
+ }) => {
231
+ unsubscribe: () => void;
232
+ };
233
+ }
234
+ export interface TypedPluginConfig {
235
+ name: string;
236
+ version: string;
237
+ enabled: boolean;
238
+ config?: Record<string, unknown>;
239
+ }
240
+ export interface TypedStorageData {
241
+ key: string;
242
+ value: unknown;
243
+ timestamp: number;
244
+ ttl?: number;
245
+ }
246
+ export interface TypedGunError extends Error {
247
+ code?: string;
248
+ type: "GUN_ERROR" | "AUTH_ERROR" | "NETWORK_ERROR" | "VALIDATION_ERROR";
249
+ context?: Record<string, unknown>;
250
+ }
251
+ export type GunOperation = "get" | "put" | "set" | "remove" | "once" | "on" | "off";
252
+ export type GunAuthMethod = "password" | "pair" | "webauthn" | "web3" | "nostr";
253
+ export interface TypedGunWrapper<T = Record<string, unknown>> {
254
+ gun: GunInstance;
255
+ user: GunUserInstance | null;
256
+ get(path: GunPath): Promise<T>;
257
+ put(path: GunPath, data: T): Promise<TypedGunOperationResult<T>>;
258
+ set(path: GunPath, data: T): Promise<TypedGunOperationResult<T>>;
259
+ remove(path: GunPath): Promise<TypedGunOperationResult>;
260
+ getUserData(path: string): Promise<T>;
261
+ putUserData(path: string, data: T): Promise<void>;
262
+ login(username: string, password: string): Promise<TypedAuthResult>;
263
+ signUp(username: string, password: string): Promise<TypedAuthResult>;
264
+ }
@@ -42,7 +42,7 @@ export interface PluginManager {
42
42
  * @returns Il plugin richiesto o undefined se non trovato
43
43
  * @template T Tipo del plugin o dell'interfaccia pubblica del plugin
44
44
  */
45
- getPlugin<T>(name: string): T | undefined;
45
+ getPlugin<T = ShogunPlugin>(name: string): T | undefined;
46
46
  /**
47
47
  * Verifica se un plugin è registrato
48
48
  * @param name Nome del plugin da verificare
@@ -55,4 +55,108 @@ export interface PluginManager {
55
55
  * @returns Array di plugin della categoria specificata
56
56
  */
57
57
  getPluginsByCategory(category: PluginCategory): ShogunPlugin[];
58
+ /**
59
+ * Ottiene informazioni su tutti i plugin registrati
60
+ * @returns Array di oggetti con informazioni sui plugin
61
+ */
62
+ getPluginsInfo(): Array<{
63
+ name: string;
64
+ version: string;
65
+ category?: PluginCategory;
66
+ description?: string;
67
+ }>;
68
+ /**
69
+ * Ottiene il numero totale di plugin registrati
70
+ * @returns Numero di plugin registrati
71
+ */
72
+ getPluginCount(): number;
73
+ /**
74
+ * Verifica se tutti i plugin sono inizializzati correttamente
75
+ * @returns Oggetto con stato di inizializzazione per ogni plugin
76
+ */
77
+ getPluginsInitializationStatus(): Record<string, {
78
+ initialized: boolean;
79
+ error?: string;
80
+ }>;
81
+ /**
82
+ * Valida l'integrità del sistema di plugin
83
+ * @returns Oggetto con risultati della validazione
84
+ */
85
+ validatePluginSystem(): {
86
+ totalPlugins: number;
87
+ initializedPlugins: number;
88
+ failedPlugins: string[];
89
+ warnings: string[];
90
+ };
91
+ /**
92
+ * Tenta di reinizializzare i plugin falliti
93
+ * @returns Oggetto con risultati della reinizializzazione
94
+ */
95
+ reinitializeFailedPlugins(): {
96
+ success: string[];
97
+ failed: Array<{
98
+ name: string;
99
+ error: string;
100
+ }>;
101
+ };
102
+ /**
103
+ * Verifica la compatibilità dei plugin con la versione corrente di ShogunCore
104
+ * @returns Oggetto con informazioni sulla compatibilità
105
+ */
106
+ checkPluginCompatibility(): {
107
+ compatible: Array<{
108
+ name: string;
109
+ version: string;
110
+ }>;
111
+ incompatible: Array<{
112
+ name: string;
113
+ version: string;
114
+ reason: string;
115
+ }>;
116
+ unknown: Array<{
117
+ name: string;
118
+ version: string;
119
+ }>;
120
+ };
121
+ /**
122
+ * Ottiene informazioni complete di debug sul sistema di plugin
123
+ * @returns Informazioni complete di debug del sistema di plugin
124
+ */
125
+ getPluginSystemDebugInfo(): {
126
+ shogunCoreVersion: string;
127
+ totalPlugins: number;
128
+ plugins: Array<{
129
+ name: string;
130
+ version: string;
131
+ category?: PluginCategory;
132
+ description?: string;
133
+ initialized: boolean;
134
+ error?: string;
135
+ }>;
136
+ initializationStatus: Record<string, {
137
+ initialized: boolean;
138
+ error?: string;
139
+ }>;
140
+ validation: {
141
+ totalPlugins: number;
142
+ initializedPlugins: number;
143
+ failedPlugins: string[];
144
+ warnings: string[];
145
+ };
146
+ compatibility: {
147
+ compatible: Array<{
148
+ name: string;
149
+ version: string;
150
+ }>;
151
+ incompatible: Array<{
152
+ name: string;
153
+ version: string;
154
+ reason: string;
155
+ }>;
156
+ unknown: Array<{
157
+ name: string;
158
+ version: string;
159
+ }>;
160
+ };
161
+ };
58
162
  }
@@ -1,4 +1,4 @@
1
- import { GunInstance, GunUserInstance } from "../gundb/improved-types";
1
+ import { GunInstance, GunUserInstance } from "../gundb/types";
2
2
  import { ISEAPair } from "gun";
3
3
  import { ethers } from "ethers";
4
4
  import { ShogunError } from "../utils/errorHandler";
@@ -6,6 +6,7 @@ import { DataBase } from "../gundb/db";
6
6
  import { RxJS } from "../gundb/rxjs";
7
7
  import { ShogunPlugin, PluginManager } from "./plugin";
8
8
  import { ShogunStorage } from "../storage/storage";
9
+ import { ShogunEventMap } from "./events";
9
10
  /**
10
11
  * Standard plugin categories in ShogunCore
11
12
  */
@@ -114,6 +115,7 @@ export interface SignUpResult {
114
115
  }
115
116
  export interface IShogunCore extends PluginManager {
116
117
  gun: GunInstance;
118
+ _gun: GunInstance;
117
119
  user: GunUserInstance | null;
118
120
  db: DataBase;
119
121
  rx: RxJS;
@@ -121,21 +123,28 @@ export interface IShogunCore extends PluginManager {
121
123
  config: ShogunCoreConfig;
122
124
  provider?: ethers.Provider;
123
125
  signer?: ethers.Signer;
124
- on(eventName: string | symbol, listener: (...args: any[]) => void): any;
125
- off(eventName: string | symbol, listener: (...args: any[]) => void): any;
126
- once(eventName: string | symbol, listener: (...args: any[]) => void): any;
127
- removeAllListeners(eventName?: string | symbol): any;
128
- emit(eventName: string | symbol, ...args: any[]): boolean;
126
+ wallets?: Wallets;
127
+ pluginManager: any;
128
+ on<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
129
+ off<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
130
+ once<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
131
+ removeAllListeners(eventName?: string | symbol): this;
132
+ emit<K extends keyof ShogunEventMap>(eventName: K, data?: ShogunEventMap[K] extends void ? never : ShogunEventMap[K]): boolean;
129
133
  getRecentErrors(count?: number): ShogunError[];
130
- login(username: string, password: string): Promise<AuthResult>;
134
+ login(username: string, password: string, pair?: ISEAPair | null): Promise<AuthResult>;
135
+ loginWithPair(pair: ISEAPair): Promise<AuthResult>;
131
136
  signUp(username: string, password?: string, pair?: ISEAPair | null): Promise<SignUpResult>;
132
137
  getAuthenticationMethod(type: AuthMethod): any;
138
+ setAuthMethod(method: AuthMethod): void;
139
+ getAuthMethod(): AuthMethod | undefined;
133
140
  getCurrentUser(): {
134
141
  pub: string;
135
142
  user?: any;
136
143
  } | null;
144
+ getIsLoggedIn(): boolean;
137
145
  logout(): void;
138
146
  isLoggedIn(): boolean;
147
+ saveCredentials(credentials: any): Promise<void>;
139
148
  }
140
149
  /**
141
150
  * WebAuthn configuration
@@ -65,5 +65,8 @@ export declare class AuthManager {
65
65
  * @returns The authentication plugin or undefined if not available
66
66
  * This is a more modern approach to accessing authentication methods
67
67
  */
68
- getAuthenticationMethod(type: AuthMethod): unknown;
68
+ getAuthenticationMethod(type: AuthMethod): import("..").ShogunPlugin | {
69
+ login: (username: string, password: string) => Promise<AuthResult>;
70
+ signUp: (username: string, password: string, confirm?: string) => Promise<SignUpResult>;
71
+ } | undefined;
69
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "SHOGUN CORE - Core library for Shogun Ecosystem",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1,4 +0,0 @@
1
- /**
2
- * Improved type definitions to reduce 'any' usage while maintaining GunDB compatibility
3
- */
4
- export {};
@@ -1,123 +0,0 @@
1
- /**
2
- * Improved type definitions to reduce 'any' usage while maintaining GunDB compatibility
3
- */
4
- import type { IGunUserInstance, IGunInstance, IGunChain, ISEAPair } from "gun/types";
5
- export type GunInstance = IGunInstance<any>;
6
- export type GunUserInstance = IGunUserInstance<any>;
7
- export type GunChain = IGunChain<any, IGunInstance<any>, IGunInstance<any>, string>;
8
- export interface GunData {
9
- [key: string]: unknown;
10
- }
11
- export interface GunNodeData {
12
- [key: string]: unknown;
13
- _?: {
14
- "#": string;
15
- ">": Record<string, number>;
16
- };
17
- }
18
- export interface GunAckCallback {
19
- (ack: {
20
- err?: string;
21
- ok?: number;
22
- pub?: string;
23
- }): void;
24
- }
25
- export interface GunDataCallback<T = unknown> {
26
- (data: T, key: string): void;
27
- }
28
- export interface GunMapCallback<T = unknown> {
29
- (data: T, key: string): void;
30
- }
31
- export interface TypedGunOperationResult<T = unknown> {
32
- success: boolean;
33
- data?: T;
34
- error?: string;
35
- ack?: {
36
- err?: string;
37
- ok?: number;
38
- pub?: string;
39
- };
40
- }
41
- export interface TypedUserInfo {
42
- pub: string;
43
- alias?: string;
44
- timestamp?: number;
45
- user?: GunUserInstance;
46
- metadata?: Record<string, unknown>;
47
- }
48
- export interface TypedAuthCallback {
49
- (user: GunUserInstance): void;
50
- }
51
- export interface TypedAuthResult {
52
- success: boolean;
53
- userPub?: string;
54
- username?: string;
55
- error?: string;
56
- ack?: {
57
- err?: string;
58
- ok?: number;
59
- pub?: string;
60
- sea?: ISEAPair;
61
- };
62
- sea?: ISEAPair;
63
- }
64
- export interface TypedGunConfig {
65
- peers?: string[];
66
- localStorage?: boolean;
67
- radisk?: boolean;
68
- file?: string;
69
- uuid?: () => string;
70
- [key: string]: unknown;
71
- }
72
- export interface TypedEventData {
73
- type: string;
74
- data: unknown;
75
- timestamp: number;
76
- source?: string;
77
- }
78
- export type GunPath = string | string[];
79
- export interface PathOperation<T = unknown> {
80
- path: GunPath;
81
- data?: T;
82
- callback?: GunAckCallback;
83
- }
84
- export interface TypedRxJSObservable<T = unknown> {
85
- subscribe: (observer: {
86
- next: (value: T) => void;
87
- error?: (error: Error) => void;
88
- complete?: () => void;
89
- }) => {
90
- unsubscribe: () => void;
91
- };
92
- }
93
- export interface TypedPluginConfig {
94
- name: string;
95
- version: string;
96
- enabled: boolean;
97
- config?: Record<string, unknown>;
98
- }
99
- export interface TypedStorageData {
100
- key: string;
101
- value: unknown;
102
- timestamp: number;
103
- ttl?: number;
104
- }
105
- export interface TypedGunError extends Error {
106
- code?: string;
107
- type: "GUN_ERROR" | "AUTH_ERROR" | "NETWORK_ERROR" | "VALIDATION_ERROR";
108
- context?: Record<string, unknown>;
109
- }
110
- export type GunOperation = "get" | "put" | "set" | "remove" | "once" | "on" | "off";
111
- export type GunAuthMethod = "password" | "pair" | "webauthn" | "web3" | "nostr";
112
- export interface TypedGunWrapper<T = Record<string, unknown>> {
113
- gun: GunInstance;
114
- user: GunUserInstance | null;
115
- get(path: GunPath): Promise<T>;
116
- put(path: GunPath, data: T): Promise<TypedGunOperationResult<T>>;
117
- set(path: GunPath, data: T): Promise<TypedGunOperationResult<T>>;
118
- remove(path: GunPath): Promise<TypedGunOperationResult>;
119
- getUserData(path: string): Promise<T>;
120
- putUserData(path: string, data: T): Promise<void>;
121
- login(username: string, password: string): Promise<TypedAuthResult>;
122
- signUp(username: string, password: string): Promise<TypedAuthResult>;
123
- }