@rebasepro/client 0.17.3 → 0.18.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.
Files changed (63) hide show
  1. package/README.md +4 -0
  2. package/dist/auth.d.ts +80 -0
  3. package/dist/functions.d.ts +6 -1
  4. package/dist/index.d.ts +8 -0
  5. package/dist/index.es.js +471 -94
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/offline-connectivity.d.ts +12 -1
  8. package/dist/offline.d.ts +23 -1
  9. package/dist/query-contract.types.d.ts +30 -0
  10. package/dist/realtime-channel.d.ts +29 -1
  11. package/dist/sdk_query_builder.d.ts +21 -2
  12. package/dist/transport.d.ts +24 -0
  13. package/package.json +28 -15
  14. package/src/admin.ts +0 -90
  15. package/src/anonymous-client-guard.test.ts +0 -190
  16. package/src/api-keys.ts +0 -87
  17. package/src/auth-listener-errors.test.ts +0 -57
  18. package/src/auth-refresh-overflow.test.ts +0 -89
  19. package/src/auth.ts +0 -982
  20. package/src/backups.ts +0 -40
  21. package/src/client-close.test.ts +0 -80
  22. package/src/collection-listen-meta.test.ts +0 -105
  23. package/src/collection-observe.test.ts +0 -138
  24. package/src/collection.test.ts +0 -293
  25. package/src/collection.ts +0 -525
  26. package/src/cron.test.ts +0 -164
  27. package/src/cron.ts +0 -62
  28. package/src/data-proxy.test.ts +0 -183
  29. package/src/errors.ts +0 -9
  30. package/src/functions.ts +0 -82
  31. package/src/index.ts +0 -639
  32. package/src/like-pattern-redos.test.ts +0 -61
  33. package/src/offline-codec.ts +0 -79
  34. package/src/offline-connectivity.test.ts +0 -191
  35. package/src/offline-connectivity.ts +0 -255
  36. package/src/offline-idb-store.test.ts +0 -340
  37. package/src/offline-integration.test.ts +0 -180
  38. package/src/offline-query.test.ts +0 -431
  39. package/src/offline-query.ts +0 -529
  40. package/src/offline-store.ts +0 -357
  41. package/src/offline-sync-engine.test.ts +0 -857
  42. package/src/offline.test.ts +0 -897
  43. package/src/offline.ts +0 -1928
  44. package/src/query-contract.types.ts +0 -206
  45. package/src/query_builder.ts +0 -1
  46. package/src/realtime-channel.test.ts +0 -542
  47. package/src/realtime-channel.ts +0 -539
  48. package/src/realtime-concurrent-subscribe.test.ts +0 -102
  49. package/src/realtime-error-surfacing.test.ts +0 -105
  50. package/src/realtime-optout.test.ts +0 -279
  51. package/src/realtime-row-identity.test.ts +0 -254
  52. package/src/realtime-subscription-key.test.ts +0 -92
  53. package/src/reviver.ts +0 -39
  54. package/src/sdk_query_builder.ts +0 -206
  55. package/src/storage-key-encoding.test.ts +0 -65
  56. package/src/storage-registry.ts +0 -102
  57. package/src/storage.ts +0 -253
  58. package/src/transport-baseurl.test.ts +0 -101
  59. package/src/transport.ts +0 -505
  60. package/src/vector-search-listen.test.ts +0 -42
  61. package/src/vector-search-query.test.ts +0 -55
  62. package/src/websocket-url.test.ts +0 -97
  63. package/src/websocket.ts +0 -1837
@@ -1,97 +0,0 @@
1
- import { jest } from "@jest/globals";
2
- import { createRebaseClient } from "./index";
3
-
4
- /**
5
- * Where the realtime socket dials, given a `baseUrl`.
6
- *
7
- * The socket URL is derived rather than configured, so every disagreement
8
- * between how it is derived and where the API actually lives shows up only as
9
- * realtime not working — never as an error naming a cause.
10
- */
11
-
12
- function setWindow(origin: string | undefined) {
13
- if (origin === undefined) {
14
- delete (globalThis as never as { window?: unknown }).window;
15
- return;
16
- }
17
- (globalThis as never as { window: unknown }).window = {
18
- location: { origin, href: origin + "/" }
19
- };
20
- }
21
-
22
- function trackingWebSocket() {
23
- const opened: string[] = [];
24
- class FakeWebSocket {
25
- static readonly OPEN = 1;
26
- readyState = 0;
27
- onopen: (() => void) | null = null;
28
- onclose: (() => void) | null = null;
29
- onerror: (() => void) | null = null;
30
- onmessage: (() => void) | null = null;
31
- constructor(public url: string) { opened.push(url); }
32
- close() { /* no-op */ }
33
- send() { /* no-op */ }
34
- }
35
- return { FakeWebSocket: FakeWebSocket as unknown as typeof WebSocket, opened };
36
- }
37
-
38
- describe("realtime socket URL", () => {
39
- const originalWebSocket = globalThis.WebSocket;
40
-
41
- afterEach(() => {
42
- globalThis.WebSocket = originalWebSocket;
43
- setWindow(undefined);
44
- jest.restoreAllMocks();
45
- });
46
-
47
- it("keeps the path of a relative baseUrl, as it does for an absolute one", () => {
48
- // A backend mounted under a path is the reason `baseUrl` accepts one.
49
- // Resolving the relative form to `.origin` dropped it, so the same
50
- // deployment dialled two different URLs depending on whether its
51
- // baseUrl was written as "/backend" or "https://app.example.com/backend".
52
- const { FakeWebSocket, opened } = trackingWebSocket();
53
- globalThis.WebSocket = FakeWebSocket;
54
- setWindow("https://app.example.com");
55
-
56
- const relative = createRebaseClient({ baseUrl: "/backend" });
57
- relative.collection("posts").listen!(undefined, () => {});
58
-
59
- const absolute = createRebaseClient({ baseUrl: "https://app.example.com/backend" });
60
- absolute.collection("posts").listen!(undefined, () => {});
61
-
62
- expect(opened[0]).toBe("wss://app.example.com/backend");
63
- expect(opened[0]).toBe(opened[1]);
64
- });
65
-
66
- it("dials the page origin when no baseUrl is set in a browser", () => {
67
- const { FakeWebSocket, opened } = trackingWebSocket();
68
- globalThis.WebSocket = FakeWebSocket;
69
- setWindow("https://app.example.com");
70
-
71
- const client = createRebaseClient({});
72
- client.collection("posts").listen!(undefined, () => {});
73
-
74
- expect(opened[0]).toBe("wss://app.example.com");
75
- });
76
-
77
- it("says why realtime is unavailable when no URL could be derived", () => {
78
- // Node, with a relative baseUrl there is nothing to resolve against.
79
- // The client silently had no socket, and `realtime.channel()` then
80
- // blamed `realtime: false` — an option the caller never passed.
81
- setWindow(undefined);
82
- const warn = jest.spyOn(console, "warn").mockImplementation(() => {});
83
- const client = createRebaseClient({ baseUrl: "/backend" });
84
-
85
- expect(client.ws).toBeUndefined();
86
- expect(warn).toHaveBeenCalledWith(expect.stringContaining("websocketUrl"));
87
- expect(() => client.realtime.channel("room")).toThrow(/no WebSocket URL could be derived/i);
88
- // It may still *suggest* `realtime: false` as the way to make this
89
- // deliberate; what it must not do is claim that is what happened.
90
- expect(() => client.realtime.channel("room")).not.toThrow(/disabled on this client/);
91
- });
92
-
93
- it("still blames the opt-out when realtime really was switched off", () => {
94
- const client = createRebaseClient({ baseUrl: "https://api.example.com", realtime: false });
95
- expect(() => client.realtime.channel("room")).toThrow(/realtime: false/);
96
- });
97
- });