@supatype/solid 0.9.1 → 0.10.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 (38) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +19 -11
  3. package/.turbo/turbo-typecheck.log +1 -1
  4. package/CHANGELOG.md +40 -1
  5. package/dist/createChannel.d.ts +26 -0
  6. package/dist/createChannel.d.ts.map +1 -0
  7. package/dist/createChannel.js +40 -0
  8. package/dist/createChannel.js.map +1 -0
  9. package/dist/createQuery.d.ts +1 -1
  10. package/dist/createQuery.d.ts.map +1 -1
  11. package/dist/createQuery.js +21 -7
  12. package/dist/createQuery.js.map +1 -1
  13. package/dist/createRealtimeConnection.d.ts +14 -0
  14. package/dist/createRealtimeConnection.d.ts.map +1 -0
  15. package/dist/createRealtimeConnection.js +16 -0
  16. package/dist/createRealtimeConnection.js.map +1 -0
  17. package/dist/createSubscription.d.ts.map +1 -1
  18. package/dist/createSubscription.js +1 -1
  19. package/dist/createSubscription.js.map +1 -1
  20. package/dist/index.d.ts +4 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -0
  23. package/dist/index.js.map +1 -1
  24. package/package.json +3 -3
  25. package/src/createChannel.ts +56 -0
  26. package/src/createQuery.ts +22 -7
  27. package/src/createRealtimeConnection.ts +27 -0
  28. package/src/createSubscription.ts +2 -2
  29. package/src/index.ts +6 -0
  30. package/tests/createChannel-private.test.ts +61 -0
  31. package/tests/createChannel-reactive-name.test.ts +68 -0
  32. package/tests/createChannel-typed-name.test.ts +15 -0
  33. package/tests/createChannel.test.ts +61 -0
  34. package/tests/createQuery-first-render.test.ts +44 -0
  35. package/tests/createQuery-reactive-options.test.ts +40 -0
  36. package/tests/createSubscription-status.test.ts +19 -4
  37. package/tests/solid-browser-build.d.ts +6 -0
  38. package/tsconfig.tsbuildinfo +1 -1
@@ -1,4 +1,4 @@
1
1
 
2
- > @supatype/solid@0.9.1 build /home/runner/work/supatype/supatype/packages/solid
2
+ > @supatype/solid@0.10.0 build /home/runner/work/supatype/supatype/packages/solid
3
3
  > tsc --project tsconfig.json
4
4
 
@@ -1,19 +1,27 @@
1
1
 
2
- > @supatype/solid@0.9.1 test /home/runner/work/supatype/supatype/packages/solid
2
+ > @supatype/solid@0.10.0 test /home/runner/work/supatype/supatype/packages/solid
3
3
  > vitest run --maxWorkers=50%
4
4
 
5
5
 
6
6
   RUN  v4.0.18 /home/runner/work/supatype/supatype/packages/solid
7
7
 
8
- ✓ tests/createSubscription-status.test.ts (2 tests) 207ms
9
- ✓ tests/thrown-errors.test.ts (5 tests) 279ms
10
- ✓ tests/createAuth-oauth.test.ts (3 tests) 73ms
11
- ✓ tests/createQuery-stale.test.ts (4 tests) 68ms
12
- ✓ tests/createAuth-signup.test.ts (2 tests) 28ms
13
- ✓ tests/createAuth-unmount.test.ts (1 test) 20ms
8
+ ✓ tests/createChannel-reactive-name.test.ts (2 tests) 339ms
9
+ ✓ moves to the new channel when the accessor changes, leaving the old channel behind  307ms
10
+ ✓ tests/createChannel-private.test.ts (3 tests) 126ms
11
+ ✓ tests/createSubscription-status.test.ts (3 tests) 339ms
12
+ ✓ tests/createChannel.test.ts (3 tests) 374ms
13
+ ✓ tests/createQuery-first-render.test.ts (2 tests) 44ms
14
+ ✓ tests/thrown-errors.test.ts (5 tests) 501ms
15
+ ✓ a query still holds a returned error, unreported  385ms
16
+ ✓ tests/createQuery-reactive-options.test.ts (5 tests) 410ms
17
+ ✓ tests/createAuth-oauth.test.ts (3 tests) 78ms
18
+ ✓ tests/createAuth-signup.test.ts (2 tests) 83ms
19
+ ✓ tests/createQuery-stale.test.ts (4 tests) 36ms
20
+ ✓ tests/createAuth-unmount.test.ts (1 test) 35ms
21
+ ✓ tests/createChannel-typed-name.test.ts (1 test) 22ms
14
22
 
15
-  Test Files  6 passed (6)
16
-  Tests  17 passed (17)
17
-  Start at  09:14:25
18
-  Duration  8.35s (transform 6.02s, setup 0ms, import 9.08s, tests 676ms, environment 4ms)
23
+  Test Files  12 passed (12)
24
+  Tests  34 passed (34)
25
+  Start at  15:46:23
26
+  Duration  16.66s (transform 8.73s, setup 0ms, import 16.96s, tests 2.39s, environment 13ms)
19
27
 
@@ -1,4 +1,4 @@
1
1
 
2
- > @supatype/solid@0.9.1 typecheck /home/runner/work/supatype/supatype/packages/solid
2
+ > @supatype/solid@0.10.0 typecheck /home/runner/work/supatype/supatype/packages/solid
3
3
  > tsc --project tests/tsconfig.json --noEmit
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,6 +1,33 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.9.3
4
+
5
+ ### Features
6
+
7
+ * **createChannel:** the channel name is a `ChannelName`: a topic the schema declares autocompletes (`lot:${string}`), and any other string is still accepted, since an `open` server admits it.
8
+ * **createChannel:** `createChannel(name, setup)` joins one channel and hands it to `setup` to add any number of
9
+ row, presence and broadcast listeners, which `createSubscription` (one table, one listener) cannot. It returns
10
+ `status` and `error` as `createSubscription` does, and `isConnected` and `connectionState`. `name` is a string or
11
+ an accessor: when it changes the old channel is left, its listeners go with it, and `setup` runs on the
12
+ new one. The channel is left on teardown.
13
+ * **createRealtimeConnection:** `isConnected` and `connectionState` for the realtime socket itself.
14
+ * **createChannel:** takes `{ private: true }` as a third argument, passed to the channel join (see the
15
+ client changelog). A refused or withdrawn private join is status "error" with `error` a
16
+ `RealtimeChannelError` whose `reason` says why.
17
+ * **createChannel:** returns `refusal`, the latest broadcast, presence track or payload the server refused on the
18
+ channel (`{ channel, code, message }`, `code` one of `send_denied`, `track_denied`,
19
+ `payload_refused`), or null. The channel stays joined: `status` does not change for it.
20
+
21
+ ### Bug Fixes
22
+
23
+ * **createSubscription:** `data` is the table's rows. It is read once the subscription has joined and again after
24
+ each re-join, so rows that existed before subscribing are held and changes made while the socket was
25
+ down are not lost. Each change is then an upsert by key (`id`, or the new `key` option, a column or
26
+ an array of them): a row seen twice is listed once, an update to a row not held adds it, and a delete
27
+ of a key not held does nothing. A `filter` narrows the read too. Before this `data` started empty,
28
+ so an update or delete of a pre-existing row was dropped and a repeated insert was listed twice.
29
+
30
+ ## 0.9.1 (2026-11-09)
4
31
 
5
32
  ### Breaking Changes
6
33
 
@@ -25,3 +52,15 @@
25
52
  * **createQuery:** only the newest read is shown. A refetch while a read was in flight let the older
26
53
  read finish last and replace the newer rows with its own rows, its error or its throw, and end
27
54
  loading while the newer read was still out. A throw from a replaced read is still logged.
55
+
56
+ ## 0.9.0 (2026-11-04)
57
+
58
+ ### Breaking Changes
59
+
60
+ * **createMutation:** `mutate` returns no rows unless asked: `data` is `null` after an insert, update,
61
+ upsert or delete, as with the client's own writes. Pass `{ select: true }` for every column or
62
+ `{ select: "id,title" }` for some, as `.select()` takes them. Returning a row needs the right
63
+ to read it, so a table whose rules let a caller create but not read refused every insert made
64
+ through `createMutation`. A delete returns `null` rather than `[]`, and its rows with `select`.
65
+
66
+
@@ -0,0 +1,26 @@
1
+ import type { Accessor } from "solid-js";
2
+ import type { AugmentedDatabase, AnyDatabase, ChannelActionRefusal, ChannelName, ChannelOptions, ChannelSubscription, SupatypeError } from "@supatype/client";
3
+ import { type SubscriptionState } from "@supatype/client/bindings";
4
+ import { type RealtimeConnectionResult } from "./createRealtimeConnection.js";
5
+ export interface ChannelResult extends RealtimeConnectionResult {
6
+ /** This channel's join: "connecting", "connected", "disconnected" or "error". */
7
+ status: Accessor<SubscriptionState>;
8
+ /** Why the server refused the join, while the status is "error"; null otherwise. */
9
+ error: Accessor<SupatypeError | null>;
10
+ /** The latest send, track or payload the server refused on this channel; the status does not move for it. */
11
+ refusal: Accessor<ChannelActionRefusal | null>;
12
+ }
13
+ /**
14
+ * Join one channel and register whatever listeners `setup` adds to it: row changes, presence and
15
+ * broadcast together, which `createSubscription` (one table, one listener) cannot do.
16
+ *
17
+ * `name` may be a string or an accessor. `setup` runs on mount, and again on the new channel
18
+ * whenever the accessor's value changes, after the old channel is left and its listeners with it.
19
+ * The channel is left when the owner is disposed.
20
+ *
21
+ * `options.private` asks for a private channel (a schema `Channel` declaration guards it): see
22
+ * `ChannelOptions`. A refused or withdrawn join shows as `error`, a `RealtimeChannelError` whose `reason`
23
+ * says why.
24
+ */
25
+ export declare function createChannel<TRow = Record<string, unknown>, TDatabase extends AnyDatabase = AugmentedDatabase>(name: ChannelName | Accessor<ChannelName>, setup: (channel: ChannelSubscription<TRow>) => void, options?: ChannelOptions | undefined): ChannelResult;
26
+ //# sourceMappingURL=createChannel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createChannel.d.ts","sourceRoot":"","sources":["../src/createChannel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,cAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAC7J,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAE/E,OAAO,EAA4B,KAAK,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAEvG,MAAM,WAAW,aAAc,SAAQ,wBAAwB;IAC7D,iFAAiF;IACjF,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAA;IACnC,oFAAoF;IACpF,KAAK,EAAE,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IACrC,6GAA6G;IAC7G,OAAO,EAAE,QAAQ,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAA;CAC/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,SAAS,WAAW,GAAG,iBAAiB,EAC7G,IAAI,EAAE,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,EACzC,KAAK,EAAE,CAAC,OAAO,EAAE,mBAAmB,CAAC,IAAI,CAAC,KAAK,IAAI,EACnD,OAAO,CAAC,EAAE,cAAc,GAAG,SAAS,GACnC,aAAa,CAuBf"}
@@ -0,0 +1,40 @@
1
+ import { createEffect, createSignal, on, onCleanup, onMount } from "solid-js";
2
+ import { channelSlot } from "@supatype/client/bindings";
3
+ import { useSupatype } from "./context.js";
4
+ import { createRealtimeConnection } from "./createRealtimeConnection.js";
5
+ /**
6
+ * Join one channel and register whatever listeners `setup` adds to it: row changes, presence and
7
+ * broadcast together, which `createSubscription` (one table, one listener) cannot do.
8
+ *
9
+ * `name` may be a string or an accessor. `setup` runs on mount, and again on the new channel
10
+ * whenever the accessor's value changes, after the old channel is left and its listeners with it.
11
+ * The channel is left when the owner is disposed.
12
+ *
13
+ * `options.private` asks for a private channel (a schema `Channel` declaration guards it): see
14
+ * `ChannelOptions`. A refused or withdrawn join shows as `error`, a `RealtimeChannelError` whose `reason`
15
+ * says why.
16
+ */
17
+ export function createChannel(name, setup, options) {
18
+ const client = useSupatype();
19
+ const connection = createRealtimeConnection();
20
+ const [status, setStatus] = createSignal("connecting");
21
+ const [error, setError] = createSignal(null);
22
+ const [refusal, setRefusal] = createSignal(null);
23
+ const slot = channelSlot(client.realtime, setup, (view) => {
24
+ setStatus(view.status);
25
+ setError(view.error);
26
+ if (view.status === "connecting")
27
+ setRefusal(null);
28
+ }, options, (refused) => {
29
+ setRefusal(refused);
30
+ });
31
+ const current = () => (typeof name === "function" ? name() : name);
32
+ onMount(() => {
33
+ slot.join(current());
34
+ onCleanup(slot.leave);
35
+ });
36
+ // Deferred, because `onMount` above makes the first join; `on` runs the move only when the name changes.
37
+ createEffect(on(current, (next) => slot.join(next), { defer: true }));
38
+ return { status, error, refusal, ...connection };
39
+ }
40
+ //# sourceMappingURL=createChannel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createChannel.js","sourceRoot":"","sources":["../src/createChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY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AE,CAAC,CAAA;QACpB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;IACF,yGAAyG;IACzG,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAErE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,CAAA;AAClD,CAAC"}
@@ -17,5 +17,5 @@ export interface QueryResult<TRow> {
17
17
  loading: Accessor<boolean>;
18
18
  refetch: () => Promise<void>;
19
19
  }
20
- export declare function createQuery<TDatabase extends AnyDatabase = AugmentedDatabase, TTable extends keyof TDatabase["public"]["Tables"] & string = keyof TDatabase["public"]["Tables"] & string, TRow = TDatabase["public"]["Tables"][TTable]["Row"]>(table: TTable, options?: QueryOptions | undefined): QueryResult<TRow>;
20
+ export declare function createQuery<TDatabase extends AnyDatabase = AugmentedDatabase, TTable extends keyof TDatabase["public"]["Tables"] & string = keyof TDatabase["public"]["Tables"] & string, TRow = TDatabase["public"]["Tables"][TTable]["Row"]>(table: TTable, options?: QueryOptions | Accessor<QueryOptions | undefined> | undefined): QueryResult<TRow>;
21
21
  //# sourceMappingURL=createQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createQuery.d.ts","sourceRoot":"","sources":["../src/createQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAa,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAKhG,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;I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,SAAS,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IAC5C,KAAK,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAA;IAC3D,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC9B;AAED,MAAM,WAAW,WAAW,CAAC,IAAI;IAC/B,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;IAC7B,KAAK,EAAE,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IACrC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED,wBAAgB,WAAW,CACzB,SAAS,SAAS,WAAW,GAAG,iBAAiB,EACjD,MAAM,SAAS,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC1G,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAEnD,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAC,YAAY,GAAG,SAAS,CAAC,GAAG,SAAS,GACtE,WAAW,CAAC,IAAI,CAAC,CAyBnB"}
@@ -1,27 +1,41 @@
1
- import { createSignal, onCleanup, onMount } from "solid-js";
1
+ import { createEffect, createSignal, on, onCleanup, onMount, untrack } from "solid-js";
2
2
  import { onIdentityChange } from "@supatype/client";
3
3
  import { useSupatype } from "./context.js";
4
4
  import { latestRowsReader } from "@supatype/client/bindings";
5
5
  export function createQuery(table, options) {
6
6
  const client = useSupatype();
7
- const { data, error, loading, read } = latestRows(client, table);
7
+ const current = () => (typeof options === "function" ? options() : options);
8
+ const enabledAtSetup = untrack(current)?.enabled !== false;
9
+ const { data, error, loading, read } = latestRows(client, table, enabledAtSetup);
8
10
  const fetchData = async () => {
9
- if (options?.enabled !== false)
10
- await read(options);
11
+ const now = current();
12
+ if (now?.enabled !== false)
13
+ await read(now);
11
14
  };
12
15
  onMount(() => {
13
16
  void fetchData();
14
17
  });
18
+ // 0.9.1 release test (FF25): the options were read once, so a sort, page or filter held in a
19
+ // signal changed nothing. Given as an accessor, the signals it reads are tracked and a change
20
+ // reads again. Deferred, because `onMount` above makes the first read; `on` runs the read
21
+ // untracked, so the signals the read itself touches are not dependencies.
22
+ createEffect(on(current, () => void fetchData(), { defer: true }));
15
23
  // Re-run when the signed-in identity changes. See `onIdentityChange` for which changes count,
16
24
  // and why the fetch above is not enough on its own.
17
25
  onCleanup(onIdentityChange(client.auth, () => void fetchData()));
18
26
  return { data, error, loading, refetch: fetchData };
19
27
  }
20
- /** The signals a query shows, fed by reads of which only the newest may change them. */
21
- function latestRows(client, table) {
28
+ /**
29
+ * The signals a query shows, fed by reads of which only the newest may change them.
30
+ *
31
+ * `loading` starts as `firstReadComing`. 0.9.2 release test (N-FF9): it started false, so the
32
+ * render before `onMount` began the read showed `loading: false, data: null`, which an app reads
33
+ * as "done, nothing found".
34
+ */
35
+ function latestRows(client, table, firstReadComing) {
22
36
  const [data, setData] = createSignal(null);
23
37
  const [error, setError] = createSignal(null);
24
- const [loading, setLoading] = createSignal(false);
38
+ const [loading, setLoading] = createSignal(firstReadComing);
25
39
  const read = latestRowsReader(client, table, `createQuery("${table}")`, {
26
40
  started: () => {
27
41
  setLoading(true);
@@ -1 +1 @@
1
- {"version":3,"file":"createQuery.js","sourceRoot":"","sources":["../src/createQuery.ts"],"names":[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,CAAC,CAAA;QAChB,CAAC;QACD,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YACzB,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;YACnB,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAA;YACvB,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;KACF,CAAC,CAAA;IACF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AACvC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Accessor } from "solid-js";
2
+ import type { AugmentedDatabase, AnyDatabase, RealtimeConnectionState } from "@supatype/client";
3
+ export interface RealtimeConnectionResult {
4
+ /** "connecting" covers the first connect, a reconnect after a drop, and the sign-in swap. */
5
+ connectionState: Accessor<RealtimeConnectionState>;
6
+ /** True while the realtime socket is open. A channel may still be waiting on its join. */
7
+ isConnected: Accessor<boolean>;
8
+ }
9
+ /**
10
+ * The realtime socket's own state, which no channel status reports: a drop and a first connect both
11
+ * read "connecting" on a channel. Reported by `watchConnection`, shared with Vue and Svelte.
12
+ */
13
+ export declare function createRealtimeConnection<TDatabase extends AnyDatabase = AugmentedDatabase>(): RealtimeConnectionResult;
14
+ //# sourceMappingURL=createRealtimeConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRealtimeConnection.d.ts","sourceRoot":"","sources":["../src/createRealtimeConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAI/F,MAAM,WAAW,wBAAwB;IACvC,6FAA6F;IAC7F,eAAe,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAA;IAClD,0FAA0F;IAC1F,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;CAC/B;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,SAAS,WAAW,GAAG,iBAAiB,KAAK,wBAAwB,CAStH"}
@@ -0,0 +1,16 @@
1
+ import { createSignal, onMount, onCleanup } from "solid-js";
2
+ import { watchConnection } from "@supatype/client/bindings";
3
+ import { useSupatype } from "./context.js";
4
+ /**
5
+ * The realtime socket's own state, which no channel status reports: a drop and a first connect both
6
+ * read "connecting" on a channel. Reported by `watchConnection`, shared with Vue and Svelte.
7
+ */
8
+ export function createRealtimeConnection() {
9
+ const client = useSupatype();
10
+ const [connectionState, setState] = createSignal(client.realtime.connectionState);
11
+ onMount(() => {
12
+ onCleanup(watchConnection(client.realtime, setState));
13
+ });
14
+ return { connectionState, isConnected: () => connectionState() === "connected" };
15
+ }
16
+ //# sourceMappingURL=createRealtimeConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRealtimeConnection.js","sourceRoot":"","sources":["../src/createRealtimeConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAG3D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAS1C;;;GAGG;AACH,MAAM,UAAU,wBAAwB;IACtC,MAAM,MAAM,GAAG,WAAW,EAAa,CAAA;IACvC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,GAAG,YAAY,CAA0B,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAA;IAE1G,OAAO,CAAC,GAAG,EAAE;QACX,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE,KAAK,WAAW,EAAE,CAAA;AAClF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createSubscription.d.ts","sourceRoot":"","sources":["../src/createSubscription.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrF,OAAO,EAAc,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAGtG,mGAAmG;AACnG,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,CAAA;AAEnD,MAAM,WAAW,kBAAkB,CAAC,IAAI;IACtC,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;IAC7B,KAAK,EAAE,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IACrC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAA;CACpC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,SAAS,WAAW,GAAG,iBAAiB,EACjD,MAAM,SAAS,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC1G,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAEnD,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,GACxC,kBAAkB,CAAC,IAAI,CAAC,CAkB1B"}
1
+ {"version":3,"file":"createSubscription.d.ts","sourceRoot":"","sources":["../src/createSubscription.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAa,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChG,OAAO,EAAc,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAGtG,mGAAmG;AACnG,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,CAAA;AAEnD,MAAM,WAAW,kBAAkB,CAAC,IAAI;IACtC,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;IAC7B,KAAK,EAAE,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IACrC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAA;CACpC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,SAAS,WAAW,GAAG,iBAAiB,EACjD,MAAM,SAAS,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC1G,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAEnD,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,GACxC,kBAAkB,CAAC,IAAI,CAAC,CAkB1B"}
@@ -13,7 +13,7 @@ export function createSubscription(table, options) {
13
13
  const [error, setError] = createSignal(null);
14
14
  const [status, setStatus] = createSignal("connecting");
15
15
  onMount(() => {
16
- const unsubscribe = watchTable(client.realtime, table, options, {
16
+ const unsubscribe = watchTable(client, table, options, {
17
17
  rows: (rows) => setData(() => rows),
18
18
  status: (view) => {
19
19
  setStatus(view.status);
@@ -1 +1 @@
1
- {"version":3,"file":"createSubscription.js","sourceRoot":"","sources":["../src/createSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAG3D,OAAO,EAAE,UAAU,EAAkD,MAAM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AyC;IAEzC,MAAM,MAAM,GAAG,WAAW,EAAa,CAAA;IACvC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,YAAY,CAAgB,IAAI,CAAC,CAAA;IACzD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,YAAY,CAAuB,IAAI,CAAC,CAAA;IAClE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,YAAY,CAAoB,YAAY,CAAC,CAAA;IAEzE,OAAO,CAAC,GAAG,EAAE;QACX,MAAM,WAAW,GAAG,UAAU,CAAO,MAAmB,EAAE,KAAK,EAAE,OAAO,EAAE;YACxE,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;YACnC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;gBACf,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBACtB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACtB,CAAC;SACF,CAAC,CAAA;QACF,SAAS,CAAC,WAAW,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;AAChC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -9,4 +9,8 @@ export { createSubscription } from "./createSubscription.js";
9
9
  export type { SubscriptionOptions, SubscriptionResult } from "./createSubscription.js";
10
10
  export { createFunction } from "./createFunction.js";
11
11
  export type { FunctionResult } from "./createFunction.js";
12
+ export { createChannel } from "./createChannel.js";
13
+ export type { ChannelResult } from "./createChannel.js";
14
+ export { createRealtimeConnection } from "./createRealtimeConnection.js";
15
+ export type { RealtimeConnectionResult } from "./createRealtimeConnection.js";
12
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,WA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AM,qBAAqB,CAAA;AACpD,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AACxE,YAAY,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA"}
package/dist/index.js CHANGED
@@ -5,4 +5,6 @@ export { createMutation } from "./createMutation.js";
5
5
  export { createAuth } from "./createAuth.js";
6
6
  export { createSubscription } from "./createSubscription.js";
7
7
  export { createFunction } from "./createFunction.js";
8
+ export { createChannel } from "./createChannel.js";
9
+ export { createRealtimeConnection } from "./createRealtimeConnection.js";
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oDAAoD;AAEpD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oDAAoD;AAEpD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supatype/solid",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
5
  "description": "Solid.js primitives for Supatype, createQuery, createMutation, createAuth, createSubscription",
6
6
  "type": "module",
@@ -14,14 +14,14 @@
14
14
  },
15
15
  "peerDependencies": {
16
16
  "solid-js": "^1.8.0",
17
- "@supatype/client": "0.9.1"
17
+ "@supatype/client": "0.10.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "^22",
21
21
  "solid-js": "^1.9.0",
22
22
  "typescript": "^5",
23
23
  "vitest": "^4.0.18",
24
- "@supatype/client": "0.9.1"
24
+ "@supatype/client": "0.10.0"
25
25
  },
26
26
  "scripts": {
27
27
  "build": "tsc --project tsconfig.json",
@@ -0,0 +1,56 @@
1
+ import { createEffect, createSignal, on, onCleanup, onMount } from "solid-js"
2
+ import type { Accessor } from "solid-js"
3
+ import type { AugmentedDatabase, AnyDatabase, ChannelActionRefusal, ChannelName, ChannelOptions, ChannelSubscription, SupatypeError } from "@supatype/client"
4
+ import { channelSlot, type SubscriptionState } from "@supatype/client/bindings"
5
+ import { useSupatype } from "./context.js"
6
+ import { createRealtimeConnection, type RealtimeConnectionResult } from "./createRealtimeConnection.js"
7
+
8
+ export interface ChannelResult extends RealtimeConnectionResult {
9
+ /** This channel's join: "connecting", "connected", "disconnected" or "error". */
10
+ status: Accessor<SubscriptionState>
11
+ /** Why the server refused the join, while the status is "error"; null otherwise. */
12
+ error: Accessor<SupatypeError | null>
13
+ /** The latest send, track or payload the server refused on this channel; the status does not move for it. */
14
+ refusal: Accessor<ChannelActionRefusal | null>
15
+ }
16
+
17
+ /**
18
+ * Join one channel and register whatever listeners `setup` adds to it: row changes, presence and
19
+ * broadcast together, which `createSubscription` (one table, one listener) cannot do.
20
+ *
21
+ * `name` may be a string or an accessor. `setup` runs on mount, and again on the new channel
22
+ * whenever the accessor's value changes, after the old channel is left and its listeners with it.
23
+ * The channel is left when the owner is disposed.
24
+ *
25
+ * `options.private` asks for a private channel (a schema `Channel` declaration guards it): see
26
+ * `ChannelOptions`. A refused or withdrawn join shows as `error`, a `RealtimeChannelError` whose `reason`
27
+ * says why.
28
+ */
29
+ export function createChannel<TRow = Record<string, unknown>, TDatabase extends AnyDatabase = AugmentedDatabase>(
30
+ name: ChannelName | Accessor<ChannelName>,
31
+ setup: (channel: ChannelSubscription<TRow>) => void,
32
+ options?: ChannelOptions | undefined,
33
+ ): ChannelResult {
34
+ const client = useSupatype<TDatabase>()
35
+ const connection = createRealtimeConnection<TDatabase>()
36
+ const [status, setStatus] = createSignal<SubscriptionState>("connecting")
37
+ const [error, setError] = createSignal<SupatypeError | null>(null)
38
+ const [refusal, setRefusal] = createSignal<ChannelActionRefusal | null>(null)
39
+ const slot = channelSlot<TRow>(client.realtime, setup, (view) => {
40
+ setStatus(view.status)
41
+ setError(view.error)
42
+ if (view.status === "connecting") setRefusal(null)
43
+ }, options, (refused) => {
44
+ setRefusal(refused)
45
+ })
46
+ const current = (): ChannelName => (typeof name === "function" ? name() : name)
47
+
48
+ onMount(() => {
49
+ slot.join(current())
50
+ onCleanup(slot.leave)
51
+ })
52
+ // Deferred, because `onMount` above makes the first join; `on` runs the move only when the name changes.
53
+ createEffect(on(current, (next) => slot.join(next), { defer: true }))
54
+
55
+ return { status, error, refusal, ...connection }
56
+ }
@@ -1,4 +1,4 @@
1
- import { createSignal, onCleanup, onMount } from "solid-js"
1
+ import { createEffect, createSignal, on, onCleanup, onMount, untrack } from "solid-js"
2
2
  import type { Accessor } from "solid-js"
3
3
  import type { AugmentedDatabase, AnyClient, AnyDatabase, SupatypeError } from "@supatype/client"
4
4
  import { onIdentityChange } from "@supatype/client"
@@ -27,18 +27,27 @@ export function createQuery<
27
27
  TRow = TDatabase["public"]["Tables"][TTable]["Row"],
28
28
  >(
29
29
  table: TTable,
30
- options?: QueryOptions | undefined,
30
+ options?: QueryOptions | Accessor<QueryOptions | undefined> | undefined,
31
31
  ): QueryResult<TRow> {
32
32
  const client = useSupatype<TDatabase>()
33
- const { data, error, loading, read } = latestRows<TRow>(client as AnyClient, table)
33
+ const current = (): QueryOptions | undefined => (typeof options === "function" ? options() : options)
34
+ const enabledAtSetup = untrack(current)?.enabled !== false
35
+ const { data, error, loading, read } = latestRows<TRow>(client as AnyClient, table, enabledAtSetup)
34
36
  const fetchData = async () => {
35
- if (options?.enabled !== false) await read(options)
37
+ const now = current()
38
+ if (now?.enabled !== false) await read(now)
36
39
  }
37
40
 
38
41
  onMount(() => {
39
42
  void fetchData()
40
43
  })
41
44
 
45
+ // 0.9.1 release test (FF25): the options were read once, so a sort, page or filter held in a
46
+ // signal changed nothing. Given as an accessor, the signals it reads are tracked and a change
47
+ // reads again. Deferred, because `onMount` above makes the first read; `on` runs the read
48
+ // untracked, so the signals the read itself touches are not dependencies.
49
+ createEffect(on(current, () => void fetchData(), { defer: true }))
50
+
42
51
  // Re-run when the signed-in identity changes. See `onIdentityChange` for which changes count,
43
52
  // and why the fetch above is not enough on its own.
44
53
  onCleanup(onIdentityChange(client.auth, () => void fetchData()))
@@ -46,11 +55,17 @@ export function createQuery<
46
55
  return { data, error, loading, refetch: fetchData }
47
56
  }
48
57
 
49
- /** The signals a query shows, fed by reads of which only the newest may change them. */
50
- function latestRows<TRow>(client: AnyClient, table: string) {
58
+ /**
59
+ * The signals a query shows, fed by reads of which only the newest may change them.
60
+ *
61
+ * `loading` starts as `firstReadComing`. 0.9.2 release test (N-FF9): it started false, so the
62
+ * render before `onMount` began the read showed `loading: false, data: null`, which an app reads
63
+ * as "done, nothing found".
64
+ */
65
+ function latestRows<TRow>(client: AnyClient, table: string, firstReadComing: boolean) {
51
66
  const [data, setData] = createSignal<TRow[] | null>(null)
52
67
  const [error, setError] = createSignal<SupatypeError | null>(null)
53
- const [loading, setLoading] = createSignal(false)
68
+ const [loading, setLoading] = createSignal(firstReadComing)
54
69
  const read = latestRowsReader<TRow>(client, table, `createQuery("${table}")`, {
55
70
  started: () => {
56
71
  setLoading(true)
@@ -0,0 +1,27 @@
1
+ import { createSignal, onMount, onCleanup } from "solid-js"
2
+ import type { Accessor } from "solid-js"
3
+ import type { AugmentedDatabase, AnyDatabase, RealtimeConnectionState } from "@supatype/client"
4
+ import { watchConnection } from "@supatype/client/bindings"
5
+ import { useSupatype } from "./context.js"
6
+
7
+ export interface RealtimeConnectionResult {
8
+ /** "connecting" covers the first connect, a reconnect after a drop, and the sign-in swap. */
9
+ connectionState: Accessor<RealtimeConnectionState>
10
+ /** True while the realtime socket is open. A channel may still be waiting on its join. */
11
+ isConnected: Accessor<boolean>
12
+ }
13
+
14
+ /**
15
+ * The realtime socket's own state, which no channel status reports: a drop and a first connect both
16
+ * read "connecting" on a channel. Reported by `watchConnection`, shared with Vue and Svelte.
17
+ */
18
+ export function createRealtimeConnection<TDatabase extends AnyDatabase = AugmentedDatabase>(): RealtimeConnectionResult {
19
+ const client = useSupatype<TDatabase>()
20
+ const [connectionState, setState] = createSignal<RealtimeConnectionState>(client.realtime.connectionState)
21
+
22
+ onMount(() => {
23
+ onCleanup(watchConnection(client.realtime, setState))
24
+ })
25
+
26
+ return { connectionState, isConnected: () => connectionState() === "connected" }
27
+ }
@@ -1,6 +1,6 @@
1
1
  import { createSignal, onMount, onCleanup } from "solid-js"
2
2
  import type { Accessor } from "solid-js"
3
- import type { AugmentedDatabase, AnyDatabase, SupatypeError } from "@supatype/client"
3
+ import type { AugmentedDatabase, AnyClient, AnyDatabase, SupatypeError } from "@supatype/client"
4
4
  import { watchTable, type SubscriptionState, type TableWatchOptions } from "@supatype/client/bindings"
5
5
  import { useSupatype } from "./context.js"
6
6
 
@@ -33,7 +33,7 @@ export function createSubscription<
33
33
  const [status, setStatus] = createSignal<SubscriptionState>("connecting")
34
34
 
35
35
  onMount(() => {
36
- const unsubscribe = watchTable<TRow>(client.realtime, table, options, {
36
+ const unsubscribe = watchTable<TRow>(client as AnyClient, table, options, {
37
37
  rows: (rows) => setData(() => rows),
38
38
  status: (view) => {
39
39
  setStatus(view.status)
package/src/index.ts CHANGED
@@ -16,3 +16,9 @@ export type { SubscriptionOptions, SubscriptionResult } from "./createSubscripti
16
16
 
17
17
  export { createFunction } from "./createFunction.js"
18
18
  export type { FunctionResult } from "./createFunction.js"
19
+
20
+ export { createChannel } from "./createChannel.js"
21
+ export type { ChannelResult } from "./createChannel.js"
22
+
23
+ export { createRealtimeConnection } from "./createRealtimeConnection.js"
24
+ export type { RealtimeConnectionResult } from "./createRealtimeConnection.js"