@bounded-sh/core 0.0.52 → 0.0.53-next.0

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.
Files changed (31) hide show
  1. package/dist/client/operations.d.ts +2 -0
  2. package/dist/client/subscribe-query.d.ts +101 -0
  3. package/dist/{index-DpfaeNTQ.mjs → index-DHigIn6m.mjs} +598 -11
  4. package/dist/index-DHigIn6m.mjs.map +1 -0
  5. package/dist/{index-BaSw33ec.js → index-Dmnzhzk1.js} +603 -10
  6. package/dist/index-Dmnzhzk1.js.map +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +7 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +1 -1
  11. package/dist/{realtime-store-PVPxsvPr.js → realtime-store-4Yr6LyTX.js} +2 -2
  12. package/dist/{realtime-store-PVPxsvPr.js.map → realtime-store-4Yr6LyTX.js.map} +1 -1
  13. package/dist/{realtime-store-CBdRkQfZ.mjs → realtime-store-DkvVNYdn.mjs} +2 -2
  14. package/dist/{realtime-store-CBdRkQfZ.mjs.map → realtime-store-DkvVNYdn.mjs.map} +1 -1
  15. package/dist/{sol-utils-pVrt7VOx.js → sol-utils-Dni65Z63.js} +3 -4
  16. package/dist/sol-utils-Dni65Z63.js.map +1 -0
  17. package/dist/{sol-utils-D0Tdlpsc.mjs → sol-utils-v8cCs2pm.mjs} +3 -4
  18. package/dist/sol-utils-v8cCs2pm.mjs.map +1 -0
  19. package/dist/{solana-message-BVJWVB6C.js → solana-message-BP0L24CQ.js} +2 -2
  20. package/dist/{solana-message-BVJWVB6C.js.map → solana-message-BP0L24CQ.js.map} +1 -1
  21. package/dist/{solana-message-kTeT43eQ.mjs → solana-message-DoiFXEx_.mjs} +2 -2
  22. package/dist/{solana-message-kTeT43eQ.mjs.map → solana-message-DoiFXEx_.mjs.map} +1 -1
  23. package/dist/{solana-operations-bXuuPlov.js → solana-operations-DZldDVeJ.js} +2 -2
  24. package/dist/{solana-operations-bXuuPlov.js.map → solana-operations-DZldDVeJ.js.map} +1 -1
  25. package/dist/{solana-operations-B8UyHL26.mjs → solana-operations-SSv6xHs-.mjs} +2 -2
  26. package/dist/{solana-operations-B8UyHL26.mjs.map → solana-operations-SSv6xHs-.mjs.map} +1 -1
  27. package/package.json +2 -2
  28. package/dist/index-BaSw33ec.js.map +0 -1
  29. package/dist/index-DpfaeNTQ.mjs.map +0 -1
  30. package/dist/sol-utils-D0Tdlpsc.mjs.map +0 -1
  31. package/dist/sol-utils-pVrt7VOx.js.map +0 -1
@@ -274,6 +274,8 @@ export declare function setMany(many: {
274
274
  export declare function clearCache(path?: string, opts?: {
275
275
  prompt?: string;
276
276
  }): void;
277
+ /** Register a callback invoked after `clearReadCacheForAuthChange`. Returns an unregister fn. */
278
+ export declare function onReadCacheAuthChange(listener: () => void): () => void;
277
279
  /**
278
280
  * SECURITY (H1): Wipe ALL HTTP read caches + in-flight reads. Call this whenever
279
281
  * the logged-in identity changes (login / logout / switch identity) so a freshly
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Live named-query subscriptions (subscribeQuery) - HTTP client poller (v1).
3
+ *
4
+ * A standardized client-side poller for a policy's computed/named queries. Same
5
+ * callback contract as `subscribe()` (onData/onError), but instead of a socket it
6
+ * polls `runQuery` on an interval. It exists to replace ad-hoc app-side polling
7
+ * with one controlled, deduped, backoff-aware poller.
8
+ *
9
+ * v1 is HTTP-only and requires ZERO server change: it rides the existing
10
+ * `runQuery` microtask coalescer (operations.ts), which batches due keys into
11
+ * <=10-per-POST chunks, surfaces per-row errors, and (via utils/api) does a
12
+ * bounded in-request 429 retry. The websocket transport and true server-push are
13
+ * deferred; see LIVE-QUERIES-SDK-PLAN.md section 9. The public contract here is
14
+ * pinned so either upgrade stays transparent.
15
+ *
16
+ * Design notes that are load-bearing (do not "simplify" away):
17
+ * - The coalescer does NOT dedupe; the manager's refcount dedupe below is the
18
+ * ONLY dedupe, so it is load-bearing for billed-read correctness.
19
+ * - There is no durable transport backoff: `utils/api` retries twice then
20
+ * rejects. Steady-state backoff on a rejected poll is owned HERE.
21
+ * - A transport rejection (429/network/chunk) must NOT reach onError - it would
22
+ * blast the whole up-to-10-key chunk every interval and rebuild the exact 429
23
+ * noise this feature removes. Only a genuine per-row query error / policy
24
+ * decline reaches onError.
25
+ */
26
+ /** Default poll cadence. Sits on the hot named-query cadence oapps already runs. */
27
+ export declare const DEFAULT_QUERY_POLL_INTERVAL_MS = 5000;
28
+ /** Hard lower clamp so an app cannot rebuild the 429 storm. */
29
+ export declare const MIN_QUERY_POLL_INTERVAL_MS = 1000;
30
+ export interface QuerySubscriptionOptions {
31
+ /** Called with the computed value on the first fetch and on every CHANGE. */
32
+ onData?: (data: any) => void;
33
+ /**
34
+ * Called advisory-only on a genuine query error / policy decline; the last
35
+ * good value stays on screen (never cleared). NOT called for transient
36
+ * transport failures (429/network) - those back off silently. The error
37
+ * carries `.phase: 'initial' | 'refresh'` and `.willRetry: boolean` (plus the
38
+ * usual `.isQueryError/.queryName/.path` or `.decline/.isBoundedDecline`).
39
+ */
40
+ onError?: (error: any) => void;
41
+ /** Poll cadence in ms. Defaults to 5000, clamped to a 1000 floor. */
42
+ intervalMs?: number;
43
+ }
44
+ type ResolvedIdentity = {
45
+ bucket: string;
46
+ token: string | null;
47
+ };
48
+ /** Deterministic key-sorted serialization of query args. */
49
+ export declare function canonicalizeArgs(args: any): string;
50
+ /**
51
+ * Deterministic key-sorted serialization of a query RESULT for change detection.
52
+ * Robust to shuffled object key order and the JSON-wire shapes the endpoint
53
+ * yields (string u64, ISO-date string). BigInt/Date OBJECTS never cross the HTTP
54
+ * boundary, so they are intentionally not handled here.
55
+ */
56
+ export declare function canonicalizeResult(result: any): string;
57
+ /**
58
+ * Subscribe to the live value of a named (computed) query.
59
+ *
60
+ * @param path - The document path the query is declared on (e.g. 'market/mytoken').
61
+ * @param queryName - The named query to run (e.g. 'tokensForOneSol').
62
+ * @param args - Query arguments (canonicalized; drives the dedupe key).
63
+ * @param options - onData/onError callbacks and optional intervalMs; a bare
64
+ * function is coerced to `{ onData }` (mirrors subscribe()).
65
+ * @returns An async unsubscribe function.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const unsubscribe = await subscribeQuery('market/mytoken', 'tokensForOneSol', {}, {
70
+ * onData: (price) => setPrice(price),
71
+ * onError: (err) => { if (err.phase === 'initial') showSpinnerError(); },
72
+ * });
73
+ * await unsubscribe();
74
+ * ```
75
+ */
76
+ export declare function subscribeQuery(path: string, queryName: string, args: any, options?: QuerySubscriptionOptions | ((data: any) => void)): Promise<() => Promise<void>>;
77
+ /**
78
+ * Wired to the SDK's auth-change chokepoint (operations.clearReadCacheForAuthChange,
79
+ * driven by reconnectWithNewAuth). That chokepoint fires on ANY reconnect - including
80
+ * a transient browser `online` nudge - not only on a real identity change, so this
81
+ * MUST be idempotent when the principal is unchanged: it re-resolves identity per
82
+ * key and re-keys ONLY the entries whose principal actually changed, preserving the
83
+ * timer and backoff of every unchanged entry (otherwise a flaky connection would
84
+ * rebuild the exact 429 re-poll storm this feature removes).
85
+ */
86
+ export declare function notifyQueryAuthChanged(): void;
87
+ /** Tear down every query subscription: cancel timers, clear the registry. */
88
+ export declare function closeAllQuerySubscriptions(): void;
89
+ /** @internal Reset all manager state between test scenarios. */
90
+ export declare function __resetForTest(): void;
91
+ /** @internal Force an out-of-band tick on a key (single-flight assertions). Returns whether a matching entry was found. */
92
+ export declare function __pollNowForTest(appId: string, path: string, queryName: string, args: any, identity: ResolvedIdentity): boolean;
93
+ /** @internal Drive visibility without a DOM. */
94
+ export declare function __setVisibilityForTest(nextHidden: boolean): void;
95
+ /** @internal Snapshot registry state for assertions. */
96
+ export declare function __inspectForTest(): {
97
+ keys: string[];
98
+ hidden: boolean;
99
+ liveSubscribers: number;
100
+ };
101
+ export {};