@debros/network-ts-sdk 0.2.5 → 0.3.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/index.d.ts CHANGED
@@ -32,6 +32,17 @@ declare class HttpClient {
32
32
  post<T = any>(path: string, body?: any, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<T>;
33
33
  put<T = any>(path: string, body?: any, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<T>;
34
34
  delete<T = any>(path: string, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<T>;
35
+ /**
36
+ * Upload a file using multipart/form-data
37
+ * This is a special method for file uploads that bypasses JSON serialization
38
+ */
39
+ uploadFile<T = any>(path: string, formData: FormData, options?: {
40
+ timeout?: number;
41
+ }): Promise<T>;
42
+ /**
43
+ * Get a binary response (returns Response object for streaming)
44
+ */
45
+ getBinary(path: string): Promise<Response>;
35
46
  getToken(): string | undefined;
36
47
  }
37
48
 
@@ -489,6 +500,201 @@ declare class NetworkClient {
489
500
  proxyAnon(request: ProxyRequest): Promise<ProxyResponse>;
490
501
  }
491
502
 
503
+ interface CacheGetRequest {
504
+ dmap: string;
505
+ key: string;
506
+ }
507
+ interface CacheGetResponse {
508
+ key: string;
509
+ value: any;
510
+ dmap: string;
511
+ }
512
+ interface CachePutRequest {
513
+ dmap: string;
514
+ key: string;
515
+ value: any;
516
+ ttl?: string;
517
+ }
518
+ interface CachePutResponse {
519
+ status: string;
520
+ key: string;
521
+ dmap: string;
522
+ }
523
+ interface CacheDeleteRequest {
524
+ dmap: string;
525
+ key: string;
526
+ }
527
+ interface CacheDeleteResponse {
528
+ status: string;
529
+ key: string;
530
+ dmap: string;
531
+ }
532
+ interface CacheMultiGetRequest {
533
+ dmap: string;
534
+ keys: string[];
535
+ }
536
+ interface CacheMultiGetResponse {
537
+ results: Array<{
538
+ key: string;
539
+ value: any;
540
+ }>;
541
+ dmap: string;
542
+ }
543
+ interface CacheScanRequest {
544
+ dmap: string;
545
+ match?: string;
546
+ }
547
+ interface CacheScanResponse {
548
+ keys: string[];
549
+ count: number;
550
+ dmap: string;
551
+ }
552
+ interface CacheHealthResponse {
553
+ status: string;
554
+ service: string;
555
+ }
556
+ declare class CacheClient {
557
+ private httpClient;
558
+ constructor(httpClient: HttpClient);
559
+ /**
560
+ * Check cache service health
561
+ */
562
+ health(): Promise<CacheHealthResponse>;
563
+ /**
564
+ * Get a value from cache
565
+ * Returns null if the key is not found (cache miss/expired), which is normal behavior
566
+ */
567
+ get(dmap: string, key: string): Promise<CacheGetResponse | null>;
568
+ /**
569
+ * Put a value into cache
570
+ */
571
+ put(dmap: string, key: string, value: any, ttl?: string): Promise<CachePutResponse>;
572
+ /**
573
+ * Delete a value from cache
574
+ */
575
+ delete(dmap: string, key: string): Promise<CacheDeleteResponse>;
576
+ /**
577
+ * Get multiple values from cache in a single request
578
+ * Returns a map of key -> value (or null if not found)
579
+ * Gracefully handles 404 errors (endpoint not implemented) by returning empty results
580
+ */
581
+ multiGet(dmap: string, keys: string[]): Promise<Map<string, any | null>>;
582
+ /**
583
+ * Scan keys in a distributed map, optionally matching a regex pattern
584
+ */
585
+ scan(dmap: string, match?: string): Promise<CacheScanResponse>;
586
+ }
587
+
588
+ interface StorageUploadResponse {
589
+ cid: string;
590
+ name: string;
591
+ size: number;
592
+ }
593
+ interface StoragePinRequest {
594
+ cid: string;
595
+ name?: string;
596
+ }
597
+ interface StoragePinResponse {
598
+ cid: string;
599
+ name: string;
600
+ }
601
+ interface StorageStatus {
602
+ cid: string;
603
+ name: string;
604
+ status: string;
605
+ replication_min: number;
606
+ replication_max: number;
607
+ replication_factor: number;
608
+ peers: string[];
609
+ error?: string;
610
+ }
611
+ declare class StorageClient {
612
+ private httpClient;
613
+ constructor(httpClient: HttpClient);
614
+ /**
615
+ * Upload content to IPFS and optionally pin it.
616
+ * Supports both File objects (browser) and Buffer/ReadableStream (Node.js).
617
+ *
618
+ * @param file - File to upload (File, Blob, or Buffer)
619
+ * @param name - Optional filename
620
+ * @param options - Optional upload options
621
+ * @param options.pin - Whether to pin the content (default: true). Pinning happens asynchronously on the backend.
622
+ * @returns Upload result with CID
623
+ *
624
+ * @example
625
+ * ```ts
626
+ * // Browser
627
+ * const fileInput = document.querySelector('input[type="file"]');
628
+ * const file = fileInput.files[0];
629
+ * const result = await client.storage.upload(file, file.name);
630
+ * console.log(result.cid);
631
+ *
632
+ * // Node.js
633
+ * const fs = require('fs');
634
+ * const fileBuffer = fs.readFileSync('image.jpg');
635
+ * const result = await client.storage.upload(fileBuffer, 'image.jpg', { pin: true });
636
+ * ```
637
+ */
638
+ upload(file: File | Blob | ArrayBuffer | Uint8Array | ReadableStream<Uint8Array>, name?: string, options?: {
639
+ pin?: boolean;
640
+ }): Promise<StorageUploadResponse>;
641
+ /**
642
+ * Pin an existing CID
643
+ *
644
+ * @param cid - Content ID to pin
645
+ * @param name - Optional name for the pin
646
+ * @returns Pin result
647
+ */
648
+ pin(cid: string, name?: string): Promise<StoragePinResponse>;
649
+ /**
650
+ * Get the pin status for a CID
651
+ *
652
+ * @param cid - Content ID to check
653
+ * @returns Pin status information
654
+ */
655
+ status(cid: string): Promise<StorageStatus>;
656
+ /**
657
+ * Retrieve content from IPFS by CID
658
+ *
659
+ * @param cid - Content ID to retrieve
660
+ * @returns ReadableStream of the content
661
+ *
662
+ * @example
663
+ * ```ts
664
+ * const stream = await client.storage.get(cid);
665
+ * const reader = stream.getReader();
666
+ * while (true) {
667
+ * const { done, value } = await reader.read();
668
+ * if (done) break;
669
+ * // Process chunk
670
+ * }
671
+ * ```
672
+ */
673
+ get(cid: string): Promise<ReadableStream<Uint8Array>>;
674
+ /**
675
+ * Retrieve content from IPFS by CID and return the full Response object
676
+ * Useful when you need access to response headers (e.g., content-length)
677
+ *
678
+ * @param cid - Content ID to retrieve
679
+ * @returns Response object with body stream and headers
680
+ *
681
+ * @example
682
+ * ```ts
683
+ * const response = await client.storage.getBinary(cid);
684
+ * const contentLength = response.headers.get('content-length');
685
+ * const reader = response.body.getReader();
686
+ * // ... read stream
687
+ * ```
688
+ */
689
+ getBinary(cid: string): Promise<Response>;
690
+ /**
691
+ * Unpin a CID
692
+ *
693
+ * @param cid - Content ID to unpin
694
+ */
695
+ unpin(cid: string): Promise<void>;
696
+ }
697
+
492
698
  declare class SDKError extends Error {
493
699
  readonly httpStatus: number;
494
700
  readonly code: string;
@@ -516,7 +722,9 @@ interface Client {
516
722
  db: DBClient;
517
723
  pubsub: PubSubClient;
518
724
  network: NetworkClient;
725
+ cache: CacheClient;
726
+ storage: StorageClient;
519
727
  }
520
728
  declare function createClient(config: ClientConfig): Client;
521
729
 
522
- export { AuthClient, type AuthConfig, type Client, type ClientConfig, type CloseHandler, type ColumnDefinition, DBClient, type Entity, type ErrorHandler, type FindOptions, HttpClient, LocalStorageAdapter, MemoryStorage, type Message, type MessageHandler, NetworkClient, type NetworkStatus, type PeerInfo, type ProxyRequest, type ProxyResponse, PubSubClient, QueryBuilder, type QueryResponse, Repository, SDKError, type SelectOptions, type StorageAdapter, Subscription, type TransactionOp, type TransactionRequest, WSClient, type WhoAmI, createClient, extractPrimaryKey, extractTableName };
730
+ export { AuthClient, type AuthConfig, CacheClient, type CacheDeleteRequest, type CacheDeleteResponse, type CacheGetRequest, type CacheGetResponse, type CacheHealthResponse, type CacheMultiGetRequest, type CacheMultiGetResponse, type CachePutRequest, type CachePutResponse, type CacheScanRequest, type CacheScanResponse, type Client, type ClientConfig, type CloseHandler, type ColumnDefinition, DBClient, type Entity, type ErrorHandler, type FindOptions, HttpClient, LocalStorageAdapter, MemoryStorage, type Message, type MessageHandler, NetworkClient, type NetworkStatus, type PeerInfo, type ProxyRequest, type ProxyResponse, PubSubClient, QueryBuilder, type QueryResponse, Repository, SDKError, type SelectOptions, type StorageAdapter, StorageClient, type StoragePinRequest, type StoragePinResponse, type StorageStatus, type StorageUploadResponse, Subscription, type TransactionOp, type TransactionRequest, WSClient, type WhoAmI, createClient, extractPrimaryKey, extractTableName };