@gusto/create-baerly-storage 0.1.2 → 0.2.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.
@@ -611,17 +611,19 @@ the cache key changes when the filter does:
611
611
 
612
612
  ```tsx
613
613
  import { useState } from "react";
614
- import { useQuery } from "@gusto/baerly-storage/client/react";
615
614
  import { STATUSES, type Note } from "../../baerly.config.ts";
615
+ import { useQuery } from "./client.ts";
616
616
 
617
617
  type Filter = "all" | Note["status"];
618
618
 
619
619
  const [filter, setFilter] = useState<Filter>("all");
620
+ // `useQuery` comes from the bound factory in `client.ts`, so
621
+ // `c.collection("notes")` infers the `Note` row — no `<Note>`, no cast.
620
622
  const result = useQuery(
621
623
  (c) =>
622
624
  filter === "all"
623
- ? c.collection<Note>("notes").all()
624
- : c.collection<Note>("notes").where({ status: filter }).all(),
625
+ ? c.collection("notes").all()
626
+ : c.collection("notes").where({ status: filter }).all(),
625
627
  [filter],
626
628
  );
627
629
  ```
@@ -641,7 +643,7 @@ const filtered = useQuery(
641
643
  (c) =>
642
644
  filter === "all"
643
645
  ? useQuery.skip
644
- : c.collection<Note>("notes").where({ status: filter }).all(),
646
+ : c.collection("notes").where({ status: filter }).all(),
645
647
  [filter],
646
648
  );
647
649
  if (filtered.status === "skipped") return <FullList />;
@@ -651,7 +653,9 @@ For dependent reads, compose two `useQuery` calls — the second one
651
653
  returns `useQuery.skip` until the first resolves to `"ok"`:
652
654
 
653
655
  ```tsx
654
- const parent = useQuery((c) => c.collection<Note>("notes").get(id), [id]);
656
+ // `comments` must be declared in baerly.config.ts — the bound hooks
657
+ // only know your declared collections (an undeclared name is a type error).
658
+ const parent = useQuery((c) => c.collection("notes").get(id), [id]);
655
659
  const replies = useQuery(
656
660
  (c) =>
657
661
  parent.status === "ok"
@@ -1,5 +1,4 @@
1
- import { BaerlyProvider, useMutation } from "@gusto/baerly-storage/client/react";
2
- import { client } from "./client.ts";
1
+ import { BaerlyProvider, client, useMutation } from "./client.ts";
3
2
  import { NoteList } from "./NoteList.tsx";
4
3
 
5
4
  const NewNoteForm = () => {
@@ -1,6 +1,6 @@
1
1
  import { useState } from "react";
2
- import { useMutation, useQuery } from "@gusto/baerly-storage/client/react";
3
2
  import type { Note } from "../../baerly.config.ts";
3
+ import { useMutation, useQuery } from "./client.ts";
4
4
 
5
5
  const NoteRow = ({ note }: { note: Note }) => {
6
6
  const [isEditing, setIsEditing] = useState(false);
@@ -68,7 +68,7 @@ const NoteRow = ({ note }: { note: Note }) => {
68
68
  };
69
69
 
70
70
  export const NoteList = () => {
71
- const result = useQuery((c) => c.collection("notes").all() as Promise<Note[]>, []);
71
+ const result = useQuery((c) => c.collection("notes").all(), []);
72
72
  if (result.status === "error") {
73
73
  return <p className="error">Error: {result.error.message}</p>;
74
74
  }
@@ -1,4 +1,5 @@
1
1
  import { createBaerlyClient } from "@gusto/baerly-storage/client";
2
+ import { createBaerlyReact } from "@gusto/baerly-storage/client/react";
2
3
  import config from "../../baerly.config.ts";
3
4
 
4
5
  // Same-origin baseUrl works in both dev and production. With
@@ -11,3 +12,10 @@ export const client = createBaerlyClient({
11
12
  baseUrl: "",
12
13
  config,
13
14
  });
15
+
16
+ // The bound React surface. `createBaerlyReact<typeof config>()` pins
17
+ // every hook to your collections, so inside a `useQuery` /
18
+ // `useMutation` callback `c.collection("notes")` infers the `Note`
19
+ // row type — no casts. Import these hooks from this module (not from
20
+ // the package) so they stay bound.
21
+ export const { BaerlyProvider, useQuery, useMutation } = createBaerlyReact<typeof config>();
@@ -544,17 +544,19 @@ the cache key changes when the filter does:
544
544
 
545
545
  ```tsx
546
546
  import { useState } from "react";
547
- import { useQuery } from "@gusto/baerly-storage/client/react";
548
547
  import { STATUSES, type Note } from "../../baerly.config.ts";
548
+ import { useQuery } from "./client.ts";
549
549
 
550
550
  type Filter = "all" | Note["status"];
551
551
 
552
552
  const [filter, setFilter] = useState<Filter>("all");
553
+ // `useQuery` comes from the bound factory in `client.ts`, so
554
+ // `c.collection("notes")` infers the `Note` row — no `<Note>`, no cast.
553
555
  const result = useQuery(
554
556
  (c) =>
555
557
  filter === "all"
556
- ? c.collection<Note>("notes").all()
557
- : c.collection<Note>("notes").where({ status: filter }).all(),
558
+ ? c.collection("notes").all()
559
+ : c.collection("notes").where({ status: filter }).all(),
558
560
  [filter],
559
561
  );
560
562
  ```
@@ -574,7 +576,7 @@ const filtered = useQuery(
574
576
  (c) =>
575
577
  filter === "all"
576
578
  ? useQuery.skip
577
- : c.collection<Note>("notes").where({ status: filter }).all(),
579
+ : c.collection("notes").where({ status: filter }).all(),
578
580
  [filter],
579
581
  );
580
582
  if (filtered.status === "skipped") return <FullList />;
@@ -584,7 +586,9 @@ For dependent reads, compose two `useQuery` calls — the second one
584
586
  returns `useQuery.skip` until the first resolves to `"ok"`:
585
587
 
586
588
  ```tsx
587
- const parent = useQuery((c) => c.collection<Note>("notes").get(id), [id]);
589
+ // `comments` must be declared in baerly.config.ts — the bound hooks
590
+ // only know your declared collections (an undeclared name is a type error).
591
+ const parent = useQuery((c) => c.collection("notes").get(id), [id]);
588
592
  const replies = useQuery(
589
593
  (c) =>
590
594
  parent.status === "ok"
@@ -1,5 +1,4 @@
1
- import { BaerlyProvider, useMutation } from "@gusto/baerly-storage/client/react";
2
- import { client } from "./client.ts";
1
+ import { BaerlyProvider, client, useMutation } from "./client.ts";
3
2
  import { NoteList } from "./NoteList.tsx";
4
3
 
5
4
  const NewNoteForm = () => {
@@ -1,6 +1,6 @@
1
1
  import { useState } from "react";
2
- import { useMutation, useQuery } from "@gusto/baerly-storage/client/react";
3
2
  import type { Note } from "../../baerly.config.ts";
3
+ import { useMutation, useQuery } from "./client.ts";
4
4
 
5
5
  const NoteRow = ({ note }: { note: Note }) => {
6
6
  const [isEditing, setIsEditing] = useState(false);
@@ -68,7 +68,7 @@ const NoteRow = ({ note }: { note: Note }) => {
68
68
  };
69
69
 
70
70
  export const NoteList = () => {
71
- const result = useQuery((c) => c.collection("notes").all() as Promise<Note[]>, []);
71
+ const result = useQuery((c) => c.collection("notes").all(), []);
72
72
  if (result.status === "error") {
73
73
  return <p className="error">Error: {result.error.message}</p>;
74
74
  }
@@ -1,4 +1,5 @@
1
1
  import { createBaerlyClient } from "@gusto/baerly-storage/client";
2
+ import { createBaerlyReact } from "@gusto/baerly-storage/client/react";
2
3
  import config from "../../baerly.config.ts";
3
4
 
4
5
  // Same-origin baseUrl works in both dev and production. With
@@ -11,3 +12,10 @@ export const client = createBaerlyClient({
11
12
  baseUrl: "",
12
13
  config,
13
14
  });
15
+
16
+ // The bound React surface. `createBaerlyReact<typeof config>()` pins
17
+ // every hook to your collections, so inside a `useQuery` /
18
+ // `useMutation` callback `c.collection("notes")` infers the `Note`
19
+ // row type — no casts. Import these hooks from this module (not from
20
+ // the package) so they stay bound.
21
+ export const { BaerlyProvider, useQuery, useMutation } = createBaerlyReact<typeof config>();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gusto/create-baerly-storage",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Scaffold a new baerly-storage app. Run via `pnpm create @gusto/baerly-storage@latest -- my-app --target=cloudflare`.",
5
5
  "homepage": "https://github.com/Gusto/baerly-storage#readme",
6
6
  "bugs": {