Replace index.d.ts with self-contained type declarations
- Remove obsolete index.d.ts with relative imports - Use self-contained type declarations for IOR compatibility - Keep native/libp2p.d.ts for internal use
This commit is contained in:
238
index.d.ts
vendored
238
index.d.ts
vendored
@@ -1,40 +1,212 @@
|
|||||||
/**
|
/**
|
||||||
* Type declarations for @metatrom/libp2p-native-bridge
|
* Type declarations for @metatrom/libp2p-native-bridge
|
||||||
|
* Self-contained for IOR type generation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Main component exports
|
// Core types
|
||||||
export { Libp2pComponent, SimplePeerId, SimpleMultiaddr } from './implementations/Libp2pComponent';
|
export interface PeerId {
|
||||||
|
toString(): string;
|
||||||
|
toBytes(): Uint8Array;
|
||||||
|
equals(other: PeerId): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
// Settings exports
|
export interface Multiaddr {
|
||||||
export {
|
toString(): string;
|
||||||
SettingsService,
|
bytes: Uint8Array;
|
||||||
getSettingsService,
|
protos(): Array<{ code: number; name: string }>;
|
||||||
DEFAULT_SETTINGS,
|
getPeerId(): string | null;
|
||||||
type AppSettings,
|
}
|
||||||
type INativeModules
|
|
||||||
} from './implementations/SettingsService';
|
export interface Connection {
|
||||||
|
id: string;
|
||||||
|
remotePeer: PeerId;
|
||||||
|
remoteAddr: Multiaddr;
|
||||||
|
stat: {
|
||||||
|
direction: 'inbound' | 'outbound';
|
||||||
|
status: 'pending' | 'open' | 'closing' | 'closed';
|
||||||
|
timeline: {
|
||||||
|
open: number;
|
||||||
|
upgraded?: number;
|
||||||
|
close?: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PeerInfo {
|
||||||
|
id: PeerId;
|
||||||
|
multiaddrs: Multiaddr[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProtocolHandler {
|
||||||
|
protocolId: string;
|
||||||
|
handler: (data: { peerId: string; data?: Uint8Array }) => void | Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ILibp2pComponent {
|
||||||
|
peerId: PeerId | null;
|
||||||
|
multiaddrs: Multiaddr[];
|
||||||
|
|
||||||
|
start(): Promise<void>;
|
||||||
|
stop(): Promise<void>;
|
||||||
|
dial(multiaddr: string): Promise<Connection>;
|
||||||
|
hangUp(peerId: string): Promise<void>;
|
||||||
|
getConnections(peerId?: string): Promise<Connection[]>;
|
||||||
|
sendProtocolData(peerId: string, protocolId: string, data: Uint8Array): Promise<void>;
|
||||||
|
refreshDiscovery(): Promise<void>;
|
||||||
|
pingPeer(peerId: string): Promise<{ success: boolean; rtt?: number; peerId: string }>;
|
||||||
|
|
||||||
|
addEventListener<K extends keyof Libp2pEvents>(
|
||||||
|
event: K,
|
||||||
|
handler: (evt: Libp2pEvents[K]) => void,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
removeEventListener<K extends keyof Libp2pEvents>(
|
||||||
|
event: K,
|
||||||
|
handler: (evt: Libp2pEvents[K]) => void,
|
||||||
|
): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Libp2pEvents {
|
||||||
|
'peer:discovery': CustomEvent<PeerInfo>;
|
||||||
|
'peer:lost': CustomEvent<{ id: PeerId }>;
|
||||||
|
'peer:connect': CustomEvent<Connection>;
|
||||||
|
'peer:disconnect': CustomEvent<Connection>;
|
||||||
|
'connection:open': CustomEvent<Connection>;
|
||||||
|
'connection:close': CustomEvent<Connection>;
|
||||||
|
'self:peer:update': CustomEvent<{ peerId: PeerId; multiaddrs: Multiaddr[] }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Libp2pOptions {
|
||||||
|
config?: {
|
||||||
|
tcpPort?: number;
|
||||||
|
wsPort?: number;
|
||||||
|
};
|
||||||
|
protocols?: ProtocolHandler[];
|
||||||
|
keypair?: {
|
||||||
|
privateKey: Uint8Array;
|
||||||
|
publicKey: Uint8Array;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Event types
|
||||||
|
export interface ConnectionStatusEvent {
|
||||||
|
peerId: string;
|
||||||
|
status: string;
|
||||||
|
direction?: 'inbound' | 'outbound';
|
||||||
|
multiaddr?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PeerDiscoveredEvent {
|
||||||
|
peerId: string;
|
||||||
|
addresses?: string[];
|
||||||
|
multiaddrs?: string[];
|
||||||
|
metadata?: {
|
||||||
|
userName?: string;
|
||||||
|
deviceName?: string;
|
||||||
|
timestamp?: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PeerInfoEvent {
|
||||||
|
peerId: string;
|
||||||
|
multiaddrs: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings types
|
||||||
|
export interface AppSettings {
|
||||||
|
tcpPort: number;
|
||||||
|
wsPort: number;
|
||||||
|
discoveryTimeout: number;
|
||||||
|
enableDebugLogs: boolean;
|
||||||
|
autoDiscovery: boolean;
|
||||||
|
useCustomPorts: boolean;
|
||||||
|
dhtServerUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface INativeModules {
|
||||||
|
Libp2pModule?: any;
|
||||||
|
DiscoveryModule?: any;
|
||||||
|
SecureStorageModule?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
export declare const LIBP2P_CONFIG: {
|
||||||
|
CONNECTION_STATUS: {
|
||||||
|
CONNECTED: string;
|
||||||
|
PENDING: string;
|
||||||
|
DISCONNECTED: string;
|
||||||
|
FAILED: string;
|
||||||
|
};
|
||||||
|
DEFAULT_TCP_PORT: number;
|
||||||
|
DEFAULT_WS_PORT: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export declare const DEFAULT_SETTINGS: AppSettings;
|
||||||
|
|
||||||
|
// Component classes
|
||||||
|
export declare class SimplePeerId implements PeerId {
|
||||||
|
constructor(id: string);
|
||||||
|
toString(): string;
|
||||||
|
toBytes(): Uint8Array;
|
||||||
|
equals(other: PeerId): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare class SimpleMultiaddr implements Multiaddr {
|
||||||
|
bytes: Uint8Array;
|
||||||
|
constructor(addr: string);
|
||||||
|
toString(): string;
|
||||||
|
protos(): Array<{ code: number; name: string }>;
|
||||||
|
getPeerId(): string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare class Libp2pComponent implements ILibp2pComponent {
|
||||||
|
constructor(options?: Libp2pOptions, nativeModules?: any);
|
||||||
|
|
||||||
|
peerId: PeerId | null;
|
||||||
|
multiaddrs: Multiaddr[];
|
||||||
|
|
||||||
|
start(): Promise<void>;
|
||||||
|
stop(): Promise<void>;
|
||||||
|
dial(multiaddr: string): Promise<Connection>;
|
||||||
|
hangUp(peerId: string): Promise<void>;
|
||||||
|
getConnections(peerId?: string): Promise<Connection[]>;
|
||||||
|
sendProtocolData(peerId: string, protocolId: string, data: Uint8Array): Promise<void>;
|
||||||
|
refreshDiscovery(): Promise<void>;
|
||||||
|
pingPeer(peerId: string): Promise<{ success: boolean; rtt?: number; peerId: string }>;
|
||||||
|
|
||||||
|
addEventListener<K extends keyof Libp2pEvents>(
|
||||||
|
event: K,
|
||||||
|
handler: (evt: Libp2pEvents[K]) => void,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
removeEventListener<K extends keyof Libp2pEvents>(
|
||||||
|
event: K,
|
||||||
|
handler: (evt: Libp2pEvents[K]) => void,
|
||||||
|
): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare class SettingsService {
|
||||||
|
static getInstance(nativeModules?: INativeModules): SettingsService;
|
||||||
|
static resetInstance(): void;
|
||||||
|
|
||||||
|
initialize(): Promise<AppSettings>;
|
||||||
|
loadSettings(): Promise<AppSettings>;
|
||||||
|
saveSettings(settings: AppSettings): Promise<void>;
|
||||||
|
getSettings(): AppSettings;
|
||||||
|
getSetting<K extends keyof AppSettings>(key: K): AppSettings[K];
|
||||||
|
updateSetting<K extends keyof AppSettings>(key: K, value: AppSettings[K]): Promise<void>;
|
||||||
|
resetAllData(): Promise<void>;
|
||||||
|
exportDebugData(): Promise<object>;
|
||||||
|
isFirstLaunch(): Promise<boolean>;
|
||||||
|
getStorageInfo(): Promise<{ keys: string[]; totalSize: number; }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare function getSettingsService(nativeModules?: INativeModules): SettingsService;
|
||||||
|
|
||||||
// UI Components
|
// UI Components
|
||||||
export { SettingsUI } from './implementations/SettingsUI';
|
export declare const SettingsUI: React.FC<{
|
||||||
|
initialSettings?: AppSettings;
|
||||||
// Interface exports
|
onSettingsChange?: (settings: AppSettings) => void;
|
||||||
export type {
|
onPortsSaved?: () => void;
|
||||||
Connection,
|
onReset?: () => void;
|
||||||
ILibp2pComponent,
|
}>;
|
||||||
Libp2pEvents,
|
|
||||||
Libp2pOptions,
|
|
||||||
Multiaddr,
|
|
||||||
PeerId,
|
|
||||||
PeerInfo,
|
|
||||||
ProtocolHandler,
|
|
||||||
} from './interfaces/ILibp2pComponent';
|
|
||||||
|
|
||||||
// Type exports
|
|
||||||
export type {
|
|
||||||
ConnectionStatusEvent,
|
|
||||||
PeerDiscoveredEvent,
|
|
||||||
PeerInfoEvent
|
|
||||||
} from './utils/types';
|
|
||||||
|
|
||||||
// Constant exports
|
|
||||||
export { LIBP2P_CONFIG } from './utils/constants';
|
|
||||||
212
libp2p-native-bridge.d.ts
vendored
212
libp2p-native-bridge.d.ts
vendored
@@ -1,212 +0,0 @@
|
|||||||
/**
|
|
||||||
* Type declarations for @metatrom/libp2p-native-bridge
|
|
||||||
* Self-contained for IOR type generation
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Core types
|
|
||||||
export interface PeerId {
|
|
||||||
toString(): string;
|
|
||||||
toBytes(): Uint8Array;
|
|
||||||
equals(other: PeerId): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Multiaddr {
|
|
||||||
toString(): string;
|
|
||||||
bytes: Uint8Array;
|
|
||||||
protos(): Array<{ code: number; name: string }>;
|
|
||||||
getPeerId(): string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Connection {
|
|
||||||
id: string;
|
|
||||||
remotePeer: PeerId;
|
|
||||||
remoteAddr: Multiaddr;
|
|
||||||
stat: {
|
|
||||||
direction: 'inbound' | 'outbound';
|
|
||||||
status: 'pending' | 'open' | 'closing' | 'closed';
|
|
||||||
timeline: {
|
|
||||||
open: number;
|
|
||||||
upgraded?: number;
|
|
||||||
close?: number;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PeerInfo {
|
|
||||||
id: PeerId;
|
|
||||||
multiaddrs: Multiaddr[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ProtocolHandler {
|
|
||||||
protocolId: string;
|
|
||||||
handler: (data: { peerId: string; data?: Uint8Array }) => void | Promise<void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ILibp2pComponent {
|
|
||||||
peerId: PeerId | null;
|
|
||||||
multiaddrs: Multiaddr[];
|
|
||||||
|
|
||||||
start(): Promise<void>;
|
|
||||||
stop(): Promise<void>;
|
|
||||||
dial(multiaddr: string): Promise<Connection>;
|
|
||||||
hangUp(peerId: string): Promise<void>;
|
|
||||||
getConnections(peerId?: string): Promise<Connection[]>;
|
|
||||||
sendProtocolData(peerId: string, protocolId: string, data: Uint8Array): Promise<void>;
|
|
||||||
refreshDiscovery(): Promise<void>;
|
|
||||||
pingPeer(peerId: string): Promise<{ success: boolean; rtt?: number; peerId: string }>;
|
|
||||||
|
|
||||||
addEventListener<K extends keyof Libp2pEvents>(
|
|
||||||
event: K,
|
|
||||||
handler: (evt: Libp2pEvents[K]) => void,
|
|
||||||
): void;
|
|
||||||
|
|
||||||
removeEventListener<K extends keyof Libp2pEvents>(
|
|
||||||
event: K,
|
|
||||||
handler: (evt: Libp2pEvents[K]) => void,
|
|
||||||
): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Libp2pEvents {
|
|
||||||
'peer:discovery': CustomEvent<PeerInfo>;
|
|
||||||
'peer:lost': CustomEvent<{ id: PeerId }>;
|
|
||||||
'peer:connect': CustomEvent<Connection>;
|
|
||||||
'peer:disconnect': CustomEvent<Connection>;
|
|
||||||
'connection:open': CustomEvent<Connection>;
|
|
||||||
'connection:close': CustomEvent<Connection>;
|
|
||||||
'self:peer:update': CustomEvent<{ peerId: PeerId; multiaddrs: Multiaddr[] }>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Libp2pOptions {
|
|
||||||
config?: {
|
|
||||||
tcpPort?: number;
|
|
||||||
wsPort?: number;
|
|
||||||
};
|
|
||||||
protocols?: ProtocolHandler[];
|
|
||||||
keypair?: {
|
|
||||||
privateKey: Uint8Array;
|
|
||||||
publicKey: Uint8Array;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Event types
|
|
||||||
export interface ConnectionStatusEvent {
|
|
||||||
peerId: string;
|
|
||||||
status: string;
|
|
||||||
direction?: 'inbound' | 'outbound';
|
|
||||||
multiaddr?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PeerDiscoveredEvent {
|
|
||||||
peerId: string;
|
|
||||||
addresses?: string[];
|
|
||||||
multiaddrs?: string[];
|
|
||||||
metadata?: {
|
|
||||||
userName?: string;
|
|
||||||
deviceName?: string;
|
|
||||||
timestamp?: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PeerInfoEvent {
|
|
||||||
peerId: string;
|
|
||||||
multiaddrs: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Settings types
|
|
||||||
export interface AppSettings {
|
|
||||||
tcpPort: number;
|
|
||||||
wsPort: number;
|
|
||||||
discoveryTimeout: number;
|
|
||||||
enableDebugLogs: boolean;
|
|
||||||
autoDiscovery: boolean;
|
|
||||||
useCustomPorts: boolean;
|
|
||||||
dhtServerUrl: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface INativeModules {
|
|
||||||
Libp2pModule?: any;
|
|
||||||
DiscoveryModule?: any;
|
|
||||||
SecureStorageModule?: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
export declare const LIBP2P_CONFIG: {
|
|
||||||
CONNECTION_STATUS: {
|
|
||||||
CONNECTED: string;
|
|
||||||
PENDING: string;
|
|
||||||
DISCONNECTED: string;
|
|
||||||
FAILED: string;
|
|
||||||
};
|
|
||||||
DEFAULT_TCP_PORT: number;
|
|
||||||
DEFAULT_WS_PORT: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export declare const DEFAULT_SETTINGS: AppSettings;
|
|
||||||
|
|
||||||
// Component classes
|
|
||||||
export declare class SimplePeerId implements PeerId {
|
|
||||||
constructor(id: string);
|
|
||||||
toString(): string;
|
|
||||||
toBytes(): Uint8Array;
|
|
||||||
equals(other: PeerId): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare class SimpleMultiaddr implements Multiaddr {
|
|
||||||
bytes: Uint8Array;
|
|
||||||
constructor(addr: string);
|
|
||||||
toString(): string;
|
|
||||||
protos(): Array<{ code: number; name: string }>;
|
|
||||||
getPeerId(): string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare class Libp2pComponent implements ILibp2pComponent {
|
|
||||||
constructor(options?: Libp2pOptions, nativeModules?: any);
|
|
||||||
|
|
||||||
peerId: PeerId | null;
|
|
||||||
multiaddrs: Multiaddr[];
|
|
||||||
|
|
||||||
start(): Promise<void>;
|
|
||||||
stop(): Promise<void>;
|
|
||||||
dial(multiaddr: string): Promise<Connection>;
|
|
||||||
hangUp(peerId: string): Promise<void>;
|
|
||||||
getConnections(peerId?: string): Promise<Connection[]>;
|
|
||||||
sendProtocolData(peerId: string, protocolId: string, data: Uint8Array): Promise<void>;
|
|
||||||
refreshDiscovery(): Promise<void>;
|
|
||||||
pingPeer(peerId: string): Promise<{ success: boolean; rtt?: number; peerId: string }>;
|
|
||||||
|
|
||||||
addEventListener<K extends keyof Libp2pEvents>(
|
|
||||||
event: K,
|
|
||||||
handler: (evt: Libp2pEvents[K]) => void,
|
|
||||||
): void;
|
|
||||||
|
|
||||||
removeEventListener<K extends keyof Libp2pEvents>(
|
|
||||||
event: K,
|
|
||||||
handler: (evt: Libp2pEvents[K]) => void,
|
|
||||||
): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare class SettingsService {
|
|
||||||
static getInstance(nativeModules?: INativeModules): SettingsService;
|
|
||||||
static resetInstance(): void;
|
|
||||||
|
|
||||||
initialize(): Promise<AppSettings>;
|
|
||||||
loadSettings(): Promise<AppSettings>;
|
|
||||||
saveSettings(settings: AppSettings): Promise<void>;
|
|
||||||
getSettings(): AppSettings;
|
|
||||||
getSetting<K extends keyof AppSettings>(key: K): AppSettings[K];
|
|
||||||
updateSetting<K extends keyof AppSettings>(key: K, value: AppSettings[K]): Promise<void>;
|
|
||||||
resetAllData(): Promise<void>;
|
|
||||||
exportDebugData(): Promise<object>;
|
|
||||||
isFirstLaunch(): Promise<boolean>;
|
|
||||||
getStorageInfo(): Promise<{ keys: string[]; totalSize: number; }>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare function getSettingsService(nativeModules?: INativeModules): SettingsService;
|
|
||||||
|
|
||||||
// UI Components
|
|
||||||
export declare const SettingsUI: React.FC<{
|
|
||||||
initialSettings?: AppSettings;
|
|
||||||
onSettingsChange?: (settings: AppSettings) => void;
|
|
||||||
onPortsSaved?: () => void;
|
|
||||||
onReset?: () => void;
|
|
||||||
}>;
|
|
||||||
Reference in New Issue
Block a user