@rebasepro/client 0.23.0 → 0.24.1-canary.g56af4a4

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.
@@ -1,4 +1,16 @@
1
+ import type { PendingMutation } from "./offline-store.js";
2
+ /**
3
+ * `out[key] = value`, as an own property whatever the key. Assigned, a key
4
+ * read from stored data that is literally `__proto__` (which `JSON.parse`
5
+ * creates as an own property) set the new object's prototype instead, and the
6
+ * column was gone from the row.
7
+ */
8
+ export declare function setOwn(out: Record<string, unknown>, key: string, value: unknown): void;
1
9
  /** Prepare a row for the store. */
2
10
  export declare function dehydrateRow<T extends Record<string, unknown>>(row: T): Record<string, unknown>;
3
11
  /** Restore a row read back from the store. */
4
12
  export declare function hydrateRow<T extends Record<string, unknown>>(row: Record<string, unknown>): T;
13
+ /** Prepare a queued write for the store. */
14
+ export declare function dehydrateMutation(op: PendingMutation): PendingMutation;
15
+ /** Restore a queued write read back from the store. */
16
+ export declare function hydrateMutation(op: PendingMutation): PendingMutation;
@@ -90,6 +90,12 @@ export declare class ConnectivityMonitor {
90
90
  private readonly clearTimer;
91
91
  /** Called when the backoff window expires, to drive an automatic retry. */
92
92
  onRetryDue?: () => void;
93
+ /**
94
+ * Called when the browser says the connection is back. Its own hook rather
95
+ * than {@link onRetryDue}: a client with automatic retries off sets no retry
96
+ * callback, and the `online` event has to wake it all the same.
97
+ */
98
+ onOnline?: () => void;
93
99
  private readonly handleOnline;
94
100
  private readonly handleOffline;
95
101
  constructor(options?: ConnectivityOptions);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * True when a read failed because there was neither network nor local data.
3
+ *
4
+ * The code is `OFFLINE`. It was `"offline"`, the one lowercase code in a
5
+ * surface whose every other code is `SCREAMING_SNAKE_CASE` — including the
6
+ * `NETWORK_ERROR` it sits next to — so `e.code === "OFFLINE"`, which is what
7
+ * anyone writes, never matched.
8
+ */
9
+ export declare function isOfflineError(error: unknown): boolean;
@@ -0,0 +1,58 @@
1
+ import { type SDKCollectionClient } from "@rebasepro/types";
2
+ import type { CollectionClient } from "./collection.js";
3
+ import type { OfflineApi, OfflineConfig } from "./offline.js";
4
+ type AnyRow = Record<string, unknown>;
5
+ type InnerFactory = (slug: string) => SDKCollectionClient<AnyRow>;
6
+ /**
7
+ * `createRebaseClient({ offline })`'s handle on the sync engine, which it
8
+ * fetches with `import()` the moment the client is created.
9
+ *
10
+ * The engine ({@link OfflineManager} and the local query evaluator, store and
11
+ * codec it brings) is most of the SDK's weight, and a client created without
12
+ * `offline` never runs a line of it. It used to be a static import of the
13
+ * client factory, so every app built on the SDK downloaded it before its first
14
+ * paint whether or not it turned offline on.
15
+ *
16
+ * Everything the factory and the app reach is here, with the same shape:
17
+ *
18
+ * - Calls made before the engine has arrived are queued and run, in the order
19
+ * they were made, the moment it does — the scope changes the factory makes
20
+ * from auth events, and every collection a client wrapped meanwhile.
21
+ * - What answers with a promise waits for the engine and then asks it.
22
+ * - What answers synchronously answers what the engine would have before
23
+ * anything ran: `status()` is the initial status, a subscription is
24
+ * registered as soon as there is something to register it with, and its
25
+ * unsubscribe works before and after.
26
+ *
27
+ * Once the engine is there every call goes straight to it.
28
+ *
29
+ * @internal
30
+ */
31
+ export declare class LazyOfflineManager {
32
+ private engine?;
33
+ private loadError?;
34
+ private queued;
35
+ private readonly failed;
36
+ readonly api: OfflineApi;
37
+ readonly keepsLastUser: boolean;
38
+ constructor(config: OfflineConfig, createInner: InnerFactory);
39
+ /**
40
+ * Run `op` on the engine: now if it is there, otherwise once it is, after
41
+ * everything queued before it.
42
+ */
43
+ private run;
44
+ /** A subscription made now, registered on the engine as soon as there is one. */
45
+ private subscribe;
46
+ holdScope(): void;
47
+ setScope(uid: string | undefined, options?: {
48
+ unverified?: boolean;
49
+ }): void;
50
+ resumeLastUser(): Promise<void>;
51
+ dispose(): void;
52
+ /**
53
+ * The engine's wrapper around `inner` — itself once the engine is there,
54
+ * and until then a client of the same shape that hands each call to it.
55
+ */
56
+ wrap<M extends AnyRow>(slug: string, inner: CollectionClient<M>): CollectionClient<M>;
57
+ }
58
+ export {};