@bounded-sh/core 0.0.1

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,89 @@
1
+ export type StorageTier = 'durable' | 'checkpointed' | 'ephemeral';
2
+ export type SubscriptionStatus = 'idle' | 'cached' | 'loading' | 'live' | 'error' | 'reconnecting';
3
+ export type DeltaChange = 'added' | 'modified' | 'removed';
4
+ export interface SubscriptionState<T = any> {
5
+ data: T[];
6
+ status: SubscriptionStatus;
7
+ isStale: boolean;
8
+ error: Error | null;
9
+ }
10
+ export interface SubscribeOptions {
11
+ tier?: StorageTier;
12
+ filter?: Record<string, any>;
13
+ prompt?: string;
14
+ includeSubPaths?: boolean;
15
+ limit?: number;
16
+ onData?: (data: any) => void;
17
+ onState?: (state: SubscriptionState) => void;
18
+ onError?: (error: Error) => void;
19
+ mode?: 'callback' | 'ref';
20
+ }
21
+ export declare class RealtimeStore {
22
+ private ws;
23
+ private wsUrl;
24
+ private appId;
25
+ private subscriptions;
26
+ private pendingRequests;
27
+ private connectPromise;
28
+ private reconnectTimer;
29
+ private reconnectDelay;
30
+ private maxReconnectDelay;
31
+ private idbFlushTimer;
32
+ private idbDirtyKeys;
33
+ private closed;
34
+ private authToken;
35
+ init(): Promise<void>;
36
+ private isServer;
37
+ private tokenRefreshTimer;
38
+ private refreshToken;
39
+ private startTokenRefresh;
40
+ private initPromise;
41
+ private ensureConnected;
42
+ private connect;
43
+ private scheduleReconnect;
44
+ private resubscribeAll;
45
+ private handleMessage;
46
+ private handleSnapshot;
47
+ private handleDelta;
48
+ private handleLegacyData;
49
+ private handleResult;
50
+ private handleError;
51
+ subscribe(path: string, opts?: SubscribeOptions): Promise<() => Promise<void>>;
52
+ getRef(path: string, opts?: SubscribeOptions): {
53
+ current: Map<string, any>;
54
+ };
55
+ set(path: string, doc: any): Promise<any>;
56
+ get(path: string): Promise<any>;
57
+ getMany(paths: string[]): Promise<Record<string, any>>;
58
+ delete(path: string): Promise<void>;
59
+ query(path: string, opts?: {
60
+ filter?: any;
61
+ sort?: any;
62
+ limit?: number;
63
+ includeSubPaths?: boolean;
64
+ }): Promise<any[]>;
65
+ count(path: string): Promise<number>;
66
+ aggregate(path: string, operation: string, opts?: {
67
+ field?: string;
68
+ }): Promise<any>;
69
+ private sendSubscribe;
70
+ private sendRequest;
71
+ private notifySubscription;
72
+ private notifyState;
73
+ private getState;
74
+ private docsToArray;
75
+ private findSubscriptionById;
76
+ private findSubscriptionByPath;
77
+ private getCollectionPath;
78
+ private getSubKey;
79
+ private idbKey;
80
+ private markIdbDirty;
81
+ private flushIdb;
82
+ private createUnsubscribe;
83
+ private resolveOperations;
84
+ private rejectAllPending;
85
+ private setAllSubscriptionStatus;
86
+ close(): void;
87
+ }
88
+ export declare function getRealtimeStore(): RealtimeStore;
89
+ export declare function resetRealtimeStore(): void;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * WebSocket v2 Subscription Manager
3
+ *
4
+ * This module implements multiplexed subscriptions over a single WebSocket connection.
5
+ * It maintains the same external API as v1 but uses the new v2 protocol internally.
6
+ */
7
+ import { SubscriptionOptions } from '../types';
8
+ /**
9
+ * Subscribe to data at a path using WebSocket v2.
10
+ * Returns an unsubscribe function.
11
+ */
12
+ /**
13
+ * @param roomRoutePath INTERNAL ONLY. A `<sessionCollection>/<roomId>` room path
14
+ * used by `live.subscribeView` to route this subscription's connection to the
15
+ * per-room DO (where live view fan-out lives). It is NOT part of the public
16
+ * subscribe API — app code never passes routing; the worker remains the
17
+ * authority on the destination DO (it derives the room from the `?path=` we
18
+ * attach). This argument only tells the client which connection to multiplex
19
+ * the subscription onto, since a WS connection routes to a single DO.
20
+ */
21
+ export declare function subscribeV2(path: string, subscriptionOptions: SubscriptionOptions, roomRoutePath?: string): Promise<() => Promise<void>>;
22
+ /**
23
+ * Close all v2 subscriptions.
24
+ */
25
+ export declare function closeAllSubscriptionsV2(): Promise<void>;
26
+ /**
27
+ * Clear the v2 cache.
28
+ */
29
+ export declare function clearCacheV2(path?: string): void;
30
+ /**
31
+ * Get cached data for a path (v2).
32
+ */
33
+ export declare function getCachedDataV2(path: string, prompt?: string): any | null;
34
+ /**
35
+ * Reconnect all v2 WebSocket connections with fresh authentication.
36
+ * Call this when the user's auth state changes (login/logout).
37
+ *
38
+ * This will:
39
+ * 1. Close existing connections
40
+ * 2. Re-establish with new auth token
41
+ * 3. Re-subscribe to all active paths
42
+ *
43
+ * Note: Existing subscriptions will receive new initial data after reconnection.
44
+ */
45
+ export declare function reconnectWithNewAuthV2(): Promise<void>;
46
+ /**
47
+ * Force close and reconnect all connections.
48
+ * This is more aggressive than reconnectWithNewAuthV2() and ensures
49
+ * a complete teardown and rebuild of connections.
50
+ */
51
+ export declare function forceReconnectV2(): Promise<void>;
52
+ /**
53
+ * Returns true if there is an active v2 WebSocket connection open.
54
+ */
55
+ export declare function hasActiveConnection(): boolean;
56
+ export declare function wsGet(path: string): Promise<any>;
57
+ /**
58
+ * Send a live-room intent over the EXISTING per-room socket (fire-and-forget).
59
+ * Returns true if it was sent over an open connection, false if there is no
60
+ * live socket for this room yet (caller falls back to HTTP). The worker is the
61
+ * room authority — the connection is already routed to the room DO, so the
62
+ * client never names a destination.
63
+ */
64
+ export declare function wsIntent(appId: string, roomRoutePath: string, intent: unknown): boolean;
65
+ /**
66
+ * Send a live-room intent over the EXISTING per-room socket and AWAIT the server
67
+ * ack — so a policy/auth denial (401/403/404/503) REJECTS instead of being
68
+ * silently dropped (the fire-and-forget `wsIntent` discards request-less error
69
+ * frames). Use for semantically important intents (join/ready/leave). Returns a
70
+ * Promise that resolves on ack / rejects on error, or `undefined` if no live
71
+ * socket exists yet (caller falls back to HTTP, which also surfaces errors).
72
+ */
73
+ export declare function wsIntentReliable(appId: string, roomRoutePath: string, intent: unknown): Promise<{
74
+ ok: true;
75
+ }> | undefined;
76
+ export declare function wsSet(documents: Array<{
77
+ destinationPath: string;
78
+ document: any;
79
+ }>): Promise<any>;
80
+ export declare function wsQuery(path: string, opts?: {
81
+ filter?: any;
82
+ sort?: any;
83
+ limit?: number;
84
+ includeSubPaths?: boolean;
85
+ }): Promise<any>;
86
+ export declare function wsDelete(path: string): Promise<any>;
87
+ export declare function wsGetMany(paths: string[]): Promise<any>;
88
+ declare global {
89
+ interface Window {
90
+ CUSTOM_TAROBASE_APP_ID_HEADER?: string;
91
+ }
92
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * WebSocket Subscription Module
3
+ *
4
+ * This module provides real-time data subscriptions using WebSocket v2 protocol
5
+ * with multiplexed connections (one connection per client, multiple subscriptions).
6
+ *
7
+ * The external API remains unchanged - just use subscribe(path, options) as before.
8
+ */
9
+ import { SubscriptionOptions } from '../types';
10
+ /**
11
+ * Subscribe to real-time updates for a path.
12
+ *
13
+ * @param path - The path to subscribe to (e.g., 'users/123' or 'posts')
14
+ * @param subscriptionOptions - Options including onData and onError callbacks
15
+ * @returns A function to unsubscribe
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const unsubscribe = await subscribe('users/123', {
20
+ * onData: (data) => console.log('User updated:', data),
21
+ * onError: (error) => console.error('Subscription error:', error),
22
+ * });
23
+ *
24
+ * // Later, to unsubscribe:
25
+ * await unsubscribe();
26
+ * ```
27
+ */
28
+ export declare function subscribe(path: string, subscriptionOptions: SubscriptionOptions | ((data: any) => void)): Promise<() => Promise<void>>;
29
+ /**
30
+ * Close all active subscriptions.
31
+ * Call this when cleaning up (e.g., on logout or component unmount).
32
+ */
33
+ export declare function closeAllSubscriptions(): Promise<void>;
34
+ /**
35
+ * Clear the subscription cache.
36
+ *
37
+ * @param path - Optional path to clear. If not provided, clears all cached data.
38
+ */
39
+ export declare function clearCache(path?: string): void;
40
+ /**
41
+ * Get cached data for a path without making a network request.
42
+ *
43
+ * @param path - The path to get cached data for
44
+ * @param prompt - Optional prompt that was used for the subscription
45
+ * @returns The cached data, or null if not cached or expired
46
+ */
47
+ export declare function getCachedData(path: string, prompt?: string): any | null;
48
+ /**
49
+ * Reconnect all WebSocket connections with fresh authentication.
50
+ * Call this when the user's auth state changes (login/logout).
51
+ *
52
+ * This will:
53
+ * 1. Close existing connections
54
+ * 2. Re-establish with new auth token
55
+ * 3. Re-subscribe to all active paths
56
+ *
57
+ * Existing subscriptions will receive new initial data after reconnection.
58
+ */
59
+ export declare function reconnectWithNewAuth(): Promise<void>;
60
+ declare global {
61
+ interface Window {
62
+ CUSTOM_TAROBASE_APP_ID_HEADER?: string;
63
+ }
64
+ }
@@ -0,0 +1,29 @@
1
+ export { init } from './client/config';
2
+ export { getConfig, ClientConfig } from './client/config';
3
+ export { getWebhookKeysUrl } from './client/config';
4
+ export { get, getMany, set, setMany, setFile, getFiles, search, queryAggregate, runQuery, runQueryMany, runExpression, runExpressionMany, signMessage, signTransaction, signAndSubmitTransaction, count, aggregate, RequestOverrides, SetOptions, GetOptions, SearchOptions, RunQueryOptions, CountOptions, AggregateOptions, AggregateOperation, AggregateResult, AggregateSpec, AggregateRow, QueryAggregateOptions, RunExpressionOptions, RunExpressionResult, InsufficientBalanceError, GetManyResult } from './client/operations';
5
+ export { subscribe, closeAllSubscriptions, clearCache, getCachedData, reconnectWithNewAuth } from './client/subscription';
6
+ export { hasActiveConnection, wsGet, wsSet, wsQuery, wsDelete, wsGetMany } from './client/subscription-v2';
7
+ export * from './types';
8
+ export { increment, serverTimestamp } from './client/field-values';
9
+ export type { FieldOperation } from './client/field-values';
10
+ export { getIdToken, deriveUserIdentityFromIdToken } from './utils/utils';
11
+ export type { UserIdentity } from './utils/utils';
12
+ export { WebSessionManager } from './utils/web-session-manager';
13
+ export { ReactNativeSessionManager } from './utils/rn-session-manager';
14
+ export type { RNStorageAdapter } from './utils/rn-session-manager';
15
+ export { getActiveSessionManager } from './utils/session-manager';
16
+ export type { ClientSessionManager } from './utils/session-manager';
17
+ export { ServerSessionManager } from './utils/server-session-manager';
18
+ export { createSessionWithSignature, refreshSession, revokeSession, signSessionCreateMessage, genAuthNonce } from './utils/auth-api';
19
+ export { Tarobase as Tarobase6 } from './utils/sol/taro6CvKqwrYrDc16ufYgzQ2NZcyyVKStffbtudrhRuDevnet-program';
20
+ export { Tarobase as TarobasePoof } from './utils/sol/poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZpMainnet-program';
21
+ export { buildSetDocumentsTransaction, convertRemainingAccounts, RemainingAccount, genSolanaMessage } from './utils/sol/sol-utils';
22
+ export { RealtimeStore, getRealtimeStore, resetRealtimeStore } from './client/realtime-store';
23
+ export type { StorageTier, SubscriptionStatus, SubscriptionState, SubscribeOptions, DeltaChange } from './client/realtime-store';
24
+ export { functions, invoke as invokeFunction, FunctionInvokeError } from './client/functions';
25
+ export type { InvokeOptions } from './client/functions';
26
+ export { live, intent as liveIntent, subscribeView as subscribeLiveView, LiveIntentError } from './client/live';
27
+ export type { LiveIntentOptions, SubscribeViewOptions } from './client/live';
28
+ export { withEffects, isEffectResult, defineLiveModule, EFFECT_INTENT_ADDRESS } from './client/live-effects';
29
+ export type { Effect, EffectKind, EffectResult, LiveIntent, LiveTickResult, LiveModule } from './client/live-effects';