@rljson/bs 0.0.18 → 0.0.20

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.
@@ -0,0 +1,96 @@
1
+ import { BlobProperties, Bs, DownloadBlobOptions, ListBlobsOptions, ListBlobsResult } from './bs.js';
2
+ /**
3
+ * Type representing a Bs instance along with its capabilities and priority.
4
+ */
5
+ export type BsMultiBs = {
6
+ bs: Bs;
7
+ id?: string;
8
+ priority: number;
9
+ read: boolean;
10
+ write: boolean;
11
+ };
12
+ /**
13
+ * Multi-tier Bs implementation that combines multiple underlying Bs instances
14
+ * with different capabilities (read, write) and priorities.
15
+ *
16
+ * Pattern: Local cache + remote server fallback
17
+ * - Lower priority number = checked first
18
+ * - Reads from highest priority readable, with hot-swapping to cache
19
+ * - Writes to all writable instances in parallel
20
+ */
21
+ export declare class BsMulti implements Bs {
22
+ private _stores;
23
+ constructor(_stores: Array<BsMultiBs>);
24
+ /**
25
+ * Initializes the BsMulti by assigning IDs to all underlying Bs instances.
26
+ * All underlying Bs instances must already be initialized.
27
+ */
28
+ init(): Promise<void>;
29
+ /**
30
+ * Stores a blob in all writable Bs instances in parallel.
31
+ * @param content - The blob content to store
32
+ * @returns Promise resolving to blob properties from the first successful write
33
+ */
34
+ setBlob(content: Buffer | string | ReadableStream<Uint8Array>): Promise<BlobProperties>;
35
+ /**
36
+ * Retrieves a blob from the highest priority readable Bs instance.
37
+ * Hot-swaps the blob to all writable instances for caching.
38
+ * @param blobId - The blob identifier
39
+ * @param options - Download options
40
+ * @returns Promise resolving to blob content and properties
41
+ */
42
+ getBlob(blobId: string, options?: DownloadBlobOptions): Promise<{
43
+ content: Buffer;
44
+ properties: BlobProperties;
45
+ }>;
46
+ /**
47
+ * Retrieves a blob as a ReadableStream from the highest priority readable Bs instance.
48
+ * @param blobId - The blob identifier
49
+ * @returns Promise resolving to a ReadableStream
50
+ */
51
+ getBlobStream(blobId: string): Promise<ReadableStream<Uint8Array>>;
52
+ /**
53
+ * Deletes a blob from all writable Bs instances in parallel.
54
+ * @param blobId - The blob identifier
55
+ */
56
+ deleteBlob(blobId: string): Promise<void>;
57
+ /**
58
+ * Checks if a blob exists in any readable Bs instance.
59
+ * @param blobId - The blob identifier
60
+ * @returns Promise resolving to true if blob exists in any readable
61
+ */
62
+ blobExists(blobId: string): Promise<boolean>;
63
+ /**
64
+ * Gets blob properties from the highest priority readable Bs instance.
65
+ * @param blobId - The blob identifier
66
+ * @returns Promise resolving to blob properties
67
+ */
68
+ getBlobProperties(blobId: string): Promise<BlobProperties>;
69
+ /**
70
+ * Lists blobs by merging results from all readable Bs instances.
71
+ * Deduplicates by blobId (content-addressable).
72
+ * @param options - Listing options
73
+ * @returns Promise resolving to list of blobs
74
+ */
75
+ listBlobs(options?: ListBlobsOptions): Promise<ListBlobsResult>;
76
+ /**
77
+ * Generates a signed URL from the highest priority readable Bs instance.
78
+ * @param blobId - The blob identifier
79
+ * @param expiresIn - Expiration time in seconds
80
+ * @param permissions - Access permissions
81
+ * @returns Promise resolving to signed URL
82
+ */
83
+ generateSignedUrl(blobId: string, expiresIn: number, permissions?: 'read' | 'delete'): Promise<string>;
84
+ /**
85
+ * Gets the list of underlying readable Bs instances, sorted by priority.
86
+ */
87
+ get readables(): Array<BsMultiBs>;
88
+ /**
89
+ * Gets the list of underlying writable Bs instances, sorted by priority.
90
+ */
91
+ get writables(): Array<BsMultiBs>;
92
+ /**
93
+ * Example: Local cache (BsMem) + Remote server (BsPeer)
94
+ */
95
+ static example: () => Promise<BsMulti>;
96
+ }
@@ -0,0 +1,72 @@
1
+ import { Bs } from './bs.js';
2
+ import { Socket } from './socket.js';
3
+ /**
4
+ * Bridges Socket events to Bs method calls.
5
+ *
6
+ * This class listens to socket events and translates them into corresponding
7
+ * Bs method calls, automatically registering all Bs interface methods.
8
+ */
9
+ export declare class BsPeerBridge {
10
+ private _bs;
11
+ private _socket;
12
+ private _eventHandlers;
13
+ private _handleConnectBound;
14
+ private _handleDisconnectBound;
15
+ constructor(_bs: Bs, _socket: Socket);
16
+ /**
17
+ * Starts the bridge by setting up connection event handlers and
18
+ * automatically registering all Bs methods.
19
+ */
20
+ start(): void;
21
+ /**
22
+ * Stops the bridge by removing all event handlers.
23
+ */
24
+ stop(): void;
25
+ /**
26
+ * Automatically registers all Bs interface methods as socket event handlers.
27
+ */
28
+ private _registerBsMethods;
29
+ /**
30
+ * Registers a socket event to be translated to a Bs method call.
31
+ * @param eventName - The socket event name (should match a Bs method name)
32
+ * @param bsMethodName - (Optional) The Bs method name if different from eventName
33
+ */
34
+ registerEvent(eventName: string, bsMethodName?: string): void;
35
+ /**
36
+ * Registers multiple socket events at once.
37
+ * @param eventNames - Array of event names to register
38
+ */
39
+ registerEvents(eventNames: string[]): void;
40
+ /**
41
+ * Unregisters a socket event handler.
42
+ * @param eventName - The event name to unregister
43
+ */
44
+ unregisterEvent(eventName: string | symbol): void;
45
+ /**
46
+ * Emits a result back through the socket.
47
+ * @param eventName - The event name to emit
48
+ * @param data - The data to send
49
+ */
50
+ emitToSocket(eventName: string | symbol, ...data: any[]): void;
51
+ /**
52
+ * Calls a Bs method directly and emits the result through the socket.
53
+ * @param bsMethodName - The Bs method to call
54
+ * @param socketEventName - The socket event to emit with the result
55
+ * @param args - Arguments to pass to the Bs method
56
+ */
57
+ callBsAndEmit(bsMethodName: string, socketEventName: string | symbol, ...args: any[]): Promise<void>;
58
+ private _handleConnect;
59
+ private _handleDisconnect;
60
+ /**
61
+ * Gets the current socket instance.
62
+ */
63
+ get socket(): Socket;
64
+ /**
65
+ * Gets the current Bs instance.
66
+ */
67
+ get bs(): Bs;
68
+ /**
69
+ * Returns whether the socket is currently connected.
70
+ */
71
+ get isConnected(): boolean;
72
+ }
@@ -0,0 +1,77 @@
1
+ import { BlobProperties, Bs, DownloadBlobOptions, ListBlobsOptions, ListBlobsResult } from './bs.ts';
2
+ import { Socket } from './socket.ts';
3
+ /**
4
+ * Peer implementation of the Bs interface that communicates over a socket.
5
+ * Allows remote access to a blob storage instance.
6
+ */
7
+ export declare class BsPeer implements Bs {
8
+ private _socket;
9
+ isOpen: boolean;
10
+ constructor(_socket: Socket);
11
+ /**
12
+ * Initializes the Peer connection.
13
+ */
14
+ init(): Promise<void>;
15
+ /**
16
+ * Closes the Peer connection.
17
+ */
18
+ close(): Promise<void>;
19
+ /**
20
+ * Returns a promise that resolves once the Peer connection is ready.
21
+ */
22
+ isReady(): Promise<void>;
23
+ /**
24
+ * Stores a blob from Buffer, string, or ReadableStream and returns properties.
25
+ * @param content - The blob content to store
26
+ * @returns Promise resolving to blob properties
27
+ */
28
+ setBlob(content: Buffer | string | ReadableStream<Uint8Array>): Promise<BlobProperties>;
29
+ /**
30
+ * Retrieves a blob by its ID as a Buffer.
31
+ * @param blobId - The unique identifier of the blob
32
+ * @param options - Download options
33
+ * @returns Promise resolving to blob content and properties
34
+ */
35
+ getBlob(blobId: string, options?: DownloadBlobOptions): Promise<{
36
+ content: Buffer;
37
+ properties: BlobProperties;
38
+ }>;
39
+ /**
40
+ * Retrieves a blob by its ID as a ReadableStream.
41
+ * @param blobId - The unique identifier of the blob
42
+ * @returns Promise resolving to readable stream
43
+ */
44
+ getBlobStream(blobId: string): Promise<ReadableStream<Uint8Array>>;
45
+ /**
46
+ * Deletes a blob by its ID.
47
+ * @param blobId - The unique identifier of the blob
48
+ * @returns Promise that resolves when deletion is complete
49
+ */
50
+ deleteBlob(blobId: string): Promise<void>;
51
+ /**
52
+ * Checks if a blob exists.
53
+ * @param blobId - The unique identifier of the blob
54
+ * @returns Promise resolving to true if blob exists
55
+ */
56
+ blobExists(blobId: string): Promise<boolean>;
57
+ /**
58
+ * Gets blob properties (size, createdAt) without retrieving content.
59
+ * @param blobId - The unique identifier of the blob
60
+ * @returns Promise resolving to blob properties
61
+ */
62
+ getBlobProperties(blobId: string): Promise<BlobProperties>;
63
+ /**
64
+ * Lists all blobs with optional filtering and pagination.
65
+ * @param options - Optional listing configuration
66
+ * @returns Promise resolving to list of blobs
67
+ */
68
+ listBlobs(options?: ListBlobsOptions): Promise<ListBlobsResult>;
69
+ /**
70
+ * Generates a signed URL for temporary blob access.
71
+ * @param blobId - The unique identifier of the blob
72
+ * @param expiresIn - Expiration time in seconds
73
+ * @param permissions - Permissions for the URL
74
+ * @returns Promise resolving to signed URL
75
+ */
76
+ generateSignedUrl(blobId: string, expiresIn: number, permissions?: 'read' | 'delete'): Promise<string>;
77
+ }
@@ -0,0 +1,32 @@
1
+ import { Bs } from './bs.ts';
2
+ import { Socket } from './socket.ts';
3
+ /**
4
+ * Server implementation that exposes a Bs instance over socket connections.
5
+ * Allows multiple clients to access the same blob storage instance remotely.
6
+ */
7
+ export declare class BsServer {
8
+ private readonly _bs;
9
+ private _sockets;
10
+ constructor(_bs: Bs);
11
+ /**
12
+ * Adds a socket to the BsServer instance.
13
+ * @param socket - The socket to add.
14
+ */
15
+ addSocket(socket: Socket): Promise<void>;
16
+ /**
17
+ * Removes a socket from the BsServer instance.
18
+ * @param socket - The socket to remove.
19
+ */
20
+ removeSocket(socket: Socket): void;
21
+ /**
22
+ * Adds a transport layer to the given socket.
23
+ * @param socket - The socket to add the transport layer to.
24
+ */
25
+ private _addTransportLayer;
26
+ /**
27
+ * Generates a transport layer object for the given Bs instance.
28
+ * @param bs - The Bs instance to generate the transport layer for.
29
+ * @returns An object containing methods that correspond to the Bs interface.
30
+ */
31
+ private _generateTransportLayer;
32
+ }