lakebed-native-cli 0.1.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 (265) hide show
  1. package/dist/cli/apple/branding.d.ts +9 -0
  2. package/dist/cli/apple/branding.d.ts.map +1 -0
  3. package/dist/cli/apple/branding.js +40 -0
  4. package/dist/cli/apple/branding.js.map +1 -0
  5. package/dist/cli/apple/build-cloud.d.ts +6 -0
  6. package/dist/cli/apple/build-cloud.d.ts.map +1 -0
  7. package/dist/cli/apple/build-cloud.js +34 -0
  8. package/dist/cli/apple/build-cloud.js.map +1 -0
  9. package/dist/cli/apple/build-local.d.ts +16 -0
  10. package/dist/cli/apple/build-local.d.ts.map +1 -0
  11. package/dist/cli/apple/build-local.js +97 -0
  12. package/dist/cli/apple/build-local.js.map +1 -0
  13. package/dist/cli/apple/choose-path.d.ts +23 -0
  14. package/dist/cli/apple/choose-path.d.ts.map +1 -0
  15. package/dist/cli/apple/choose-path.js +78 -0
  16. package/dist/cli/apple/choose-path.js.map +1 -0
  17. package/dist/cli/apple/device-pack.d.ts +36 -0
  18. package/dist/cli/apple/device-pack.d.ts.map +1 -0
  19. package/dist/cli/apple/device-pack.js +210 -0
  20. package/dist/cli/apple/device-pack.js.map +1 -0
  21. package/dist/cli/apple/devices.d.ts +6 -0
  22. package/dist/cli/apple/devices.d.ts.map +1 -0
  23. package/dist/cli/apple/devices.js +49 -0
  24. package/dist/cli/apple/devices.js.map +1 -0
  25. package/dist/cli/apple/eas-delegate.d.ts +25 -0
  26. package/dist/cli/apple/eas-delegate.d.ts.map +1 -0
  27. package/dist/cli/apple/eas-delegate.js +63 -0
  28. package/dist/cli/apple/eas-delegate.js.map +1 -0
  29. package/dist/cli/apple/index.d.ts +9 -0
  30. package/dist/cli/apple/index.d.ts.map +1 -0
  31. package/dist/cli/apple/index.js +12 -0
  32. package/dist/cli/apple/index.js.map +1 -0
  33. package/dist/cli/apple/route-device-build.d.ts +16 -0
  34. package/dist/cli/apple/route-device-build.d.ts.map +1 -0
  35. package/dist/cli/apple/route-device-build.js +54 -0
  36. package/dist/cli/apple/route-device-build.js.map +1 -0
  37. package/dist/cli/apple/setup.d.ts +5 -0
  38. package/dist/cli/apple/setup.d.ts.map +1 -0
  39. package/dist/cli/apple/setup.js +69 -0
  40. package/dist/cli/apple/setup.js.map +1 -0
  41. package/dist/cli/apple/shell-ipa.d.ts +7 -0
  42. package/dist/cli/apple/shell-ipa.d.ts.map +1 -0
  43. package/dist/cli/apple/shell-ipa.js +73 -0
  44. package/dist/cli/apple/shell-ipa.js.map +1 -0
  45. package/dist/cli/apple/sign-ios.d.ts +24 -0
  46. package/dist/cli/apple/sign-ios.d.ts.map +1 -0
  47. package/dist/cli/apple/sign-ios.js +148 -0
  48. package/dist/cli/apple/sign-ios.js.map +1 -0
  49. package/dist/cli/apple/status.d.ts +64 -0
  50. package/dist/cli/apple/status.d.ts.map +1 -0
  51. package/dist/cli/apple/status.js +249 -0
  52. package/dist/cli/apple/status.js.map +1 -0
  53. package/dist/cli/bin.d.ts +3 -0
  54. package/dist/cli/bin.d.ts.map +1 -0
  55. package/dist/cli/bin.js +7 -0
  56. package/dist/cli/bin.js.map +1 -0
  57. package/dist/cli/bundler.d.ts +16 -0
  58. package/dist/cli/bundler.d.ts.map +1 -0
  59. package/dist/cli/bundler.js +109 -0
  60. package/dist/cli/bundler.js.map +1 -0
  61. package/dist/cli/capsule-eas.d.ts +27 -0
  62. package/dist/cli/capsule-eas.d.ts.map +1 -0
  63. package/dist/cli/capsule-eas.js +131 -0
  64. package/dist/cli/capsule-eas.js.map +1 -0
  65. package/dist/cli/cloud/index.d.ts +14 -0
  66. package/dist/cli/cloud/index.d.ts.map +1 -0
  67. package/dist/cli/cloud/index.js +118 -0
  68. package/dist/cli/cloud/index.js.map +1 -0
  69. package/dist/cli/cloud-client.d.ts +38 -0
  70. package/dist/cli/cloud-client.d.ts.map +1 -0
  71. package/dist/cli/cloud-client.js +71 -0
  72. package/dist/cli/cloud-client.js.map +1 -0
  73. package/dist/cli/commands/auth.d.ts +2 -0
  74. package/dist/cli/commands/auth.d.ts.map +1 -0
  75. package/dist/cli/commands/auth.js +18 -0
  76. package/dist/cli/commands/auth.js.map +1 -0
  77. package/dist/cli/commands/build-native.d.ts +18 -0
  78. package/dist/cli/commands/build-native.d.ts.map +1 -0
  79. package/dist/cli/commands/build-native.js +156 -0
  80. package/dist/cli/commands/build-native.js.map +1 -0
  81. package/dist/cli/commands/build.d.ts +6 -0
  82. package/dist/cli/commands/build.d.ts.map +1 -0
  83. package/dist/cli/commands/build.js +57 -0
  84. package/dist/cli/commands/build.js.map +1 -0
  85. package/dist/cli/commands/claim.d.ts +2 -0
  86. package/dist/cli/commands/claim.d.ts.map +1 -0
  87. package/dist/cli/commands/claim.js +2 -0
  88. package/dist/cli/commands/claim.js.map +1 -0
  89. package/dist/cli/commands/db.d.ts +7 -0
  90. package/dist/cli/commands/db.d.ts.map +1 -0
  91. package/dist/cli/commands/db.js +18 -0
  92. package/dist/cli/commands/db.js.map +1 -0
  93. package/dist/cli/commands/deploy.d.ts +10 -0
  94. package/dist/cli/commands/deploy.d.ts.map +1 -0
  95. package/dist/cli/commands/deploy.js +101 -0
  96. package/dist/cli/commands/deploy.js.map +1 -0
  97. package/dist/cli/commands/dev.d.ts +5 -0
  98. package/dist/cli/commands/dev.d.ts.map +1 -0
  99. package/dist/cli/commands/dev.js +46 -0
  100. package/dist/cli/commands/dev.js.map +1 -0
  101. package/dist/cli/commands/devices.d.ts +4 -0
  102. package/dist/cli/commands/devices.d.ts.map +1 -0
  103. package/dist/cli/commands/devices.js +27 -0
  104. package/dist/cli/commands/devices.js.map +1 -0
  105. package/dist/cli/commands/domains.d.ts +5 -0
  106. package/dist/cli/commands/domains.d.ts.map +1 -0
  107. package/dist/cli/commands/domains.js +36 -0
  108. package/dist/cli/commands/domains.js.map +1 -0
  109. package/dist/cli/commands/inspect.d.ts +7 -0
  110. package/dist/cli/commands/inspect.d.ts.map +1 -0
  111. package/dist/cli/commands/inspect.js +15 -0
  112. package/dist/cli/commands/inspect.js.map +1 -0
  113. package/dist/cli/commands/logs.d.ts +7 -0
  114. package/dist/cli/commands/logs.d.ts.map +1 -0
  115. package/dist/cli/commands/logs.js +15 -0
  116. package/dist/cli/commands/logs.js.map +1 -0
  117. package/dist/cli/commands/new.d.ts +6 -0
  118. package/dist/cli/commands/new.d.ts.map +1 -0
  119. package/dist/cli/commands/new.js +17 -0
  120. package/dist/cli/commands/new.js.map +1 -0
  121. package/dist/cli/commands/open.d.ts +5 -0
  122. package/dist/cli/commands/open.d.ts.map +1 -0
  123. package/dist/cli/commands/open.js +14 -0
  124. package/dist/cli/commands/open.js.map +1 -0
  125. package/dist/cli/commands/pack.d.ts +32 -0
  126. package/dist/cli/commands/pack.d.ts.map +1 -0
  127. package/dist/cli/commands/pack.js +273 -0
  128. package/dist/cli/commands/pack.js.map +1 -0
  129. package/dist/cli/commands/screenshot.d.ts +5 -0
  130. package/dist/cli/commands/screenshot.d.ts.map +1 -0
  131. package/dist/cli/commands/screenshot.js +8 -0
  132. package/dist/cli/commands/screenshot.js.map +1 -0
  133. package/dist/cli/commands/shell-fetch.d.ts +5 -0
  134. package/dist/cli/commands/shell-fetch.d.ts.map +1 -0
  135. package/dist/cli/commands/shell-fetch.js +123 -0
  136. package/dist/cli/commands/shell-fetch.js.map +1 -0
  137. package/dist/cli/commands/shell.d.ts +2 -0
  138. package/dist/cli/commands/shell.d.ts.map +1 -0
  139. package/dist/cli/commands/shell.js +2 -0
  140. package/dist/cli/commands/shell.js.map +1 -0
  141. package/dist/cli/commands/submit.d.ts +2 -0
  142. package/dist/cli/commands/submit.d.ts.map +1 -0
  143. package/dist/cli/commands/submit.js +2 -0
  144. package/dist/cli/commands/submit.js.map +1 -0
  145. package/dist/cli/commands/tree.d.ts +5 -0
  146. package/dist/cli/commands/tree.d.ts.map +1 -0
  147. package/dist/cli/commands/tree.js +23 -0
  148. package/dist/cli/commands/tree.js.map +1 -0
  149. package/dist/cli/deploy-metadata.d.ts +10 -0
  150. package/dist/cli/deploy-metadata.d.ts.map +1 -0
  151. package/dist/cli/deploy-metadata.js +50 -0
  152. package/dist/cli/deploy-metadata.js.map +1 -0
  153. package/dist/cli/deploy-runtime.d.ts +4 -0
  154. package/dist/cli/deploy-runtime.d.ts.map +1 -0
  155. package/dist/cli/deploy-runtime.js +14 -0
  156. package/dist/cli/deploy-runtime.js.map +1 -0
  157. package/dist/cli/dev-config.d.ts +2 -0
  158. package/dist/cli/dev-config.d.ts.map +1 -0
  159. package/dist/cli/dev-config.js +36 -0
  160. package/dist/cli/dev-config.js.map +1 -0
  161. package/dist/cli/hosted-client.d.ts +39 -0
  162. package/dist/cli/hosted-client.d.ts.map +1 -0
  163. package/dist/cli/hosted-client.js +275 -0
  164. package/dist/cli/hosted-client.js.map +1 -0
  165. package/dist/cli/hosted-v1-store.d.ts +73 -0
  166. package/dist/cli/hosted-v1-store.d.ts.map +1 -0
  167. package/dist/cli/hosted-v1-store.js +96 -0
  168. package/dist/cli/hosted-v1-store.js.map +1 -0
  169. package/dist/cli/hosted.d.ts +13 -0
  170. package/dist/cli/hosted.d.ts.map +1 -0
  171. package/dist/cli/hosted.js +337 -0
  172. package/dist/cli/hosted.js.map +1 -0
  173. package/dist/cli/index.d.ts +2 -0
  174. package/dist/cli/index.d.ts.map +1 -0
  175. package/dist/cli/index.js +261 -0
  176. package/dist/cli/index.js.map +1 -0
  177. package/dist/cli/kit-paths.d.ts +8 -0
  178. package/dist/cli/kit-paths.d.ts.map +1 -0
  179. package/dist/cli/kit-paths.js +67 -0
  180. package/dist/cli/kit-paths.js.map +1 -0
  181. package/dist/cli/loader.d.ts +2 -0
  182. package/dist/cli/loader.d.ts.map +1 -0
  183. package/dist/cli/loader.js +5 -0
  184. package/dist/cli/loader.js.map +1 -0
  185. package/dist/cli/native-deploy-payload.d.ts +17 -0
  186. package/dist/cli/native-deploy-payload.d.ts.map +1 -0
  187. package/dist/cli/native-deploy-payload.js +29 -0
  188. package/dist/cli/native-deploy-payload.js.map +1 -0
  189. package/dist/cli/platform-detect.d.ts +11 -0
  190. package/dist/cli/platform-detect.d.ts.map +1 -0
  191. package/dist/cli/platform-detect.js +54 -0
  192. package/dist/cli/platform-detect.js.map +1 -0
  193. package/dist/cli/site.d.ts +6 -0
  194. package/dist/cli/site.d.ts.map +1 -0
  195. package/dist/cli/site.js +9 -0
  196. package/dist/cli/site.js.map +1 -0
  197. package/dist/cli/util.d.ts +12 -0
  198. package/dist/cli/util.d.ts.map +1 -0
  199. package/dist/cli/util.js +118 -0
  200. package/dist/cli/util.js.map +1 -0
  201. package/dist/cli/web-deploy-envelope.d.ts +15 -0
  202. package/dist/cli/web-deploy-envelope.d.ts.map +1 -0
  203. package/dist/cli/web-deploy-envelope.js +156 -0
  204. package/dist/cli/web-deploy-envelope.js.map +1 -0
  205. package/metro.lakebed-native.cjs +94 -0
  206. package/package.json +38 -0
  207. package/templates/camera-note/.env.lakebed.native.server +1 -0
  208. package/templates/camera-note/.lakebed-native/dev.json +6 -0
  209. package/templates/camera-note/.lakebed-native/metro/.expo/README.md +8 -0
  210. package/templates/camera-note/.lakebed-native/metro/.expo/devices.json +3 -0
  211. package/templates/camera-note/.lakebed-native/metro/index.js +2 -0
  212. package/templates/camera-note/.lakebed-native/metro/metro.config.js +4 -0
  213. package/templates/camera-note/.lakebed-native/metro/package.json +4 -0
  214. package/templates/camera-note/AGENTS.md +1 -0
  215. package/templates/camera-note/README.md +1 -0
  216. package/templates/camera-note/app/index.tsx +64 -0
  217. package/templates/camera-note/server/index.ts +23 -0
  218. package/templates/error-fixture/.env.lakebed.native.server +1 -0
  219. package/templates/error-fixture/.lakebed-native/dev.json +6 -0
  220. package/templates/error-fixture/.lakebed-native/metro/.expo/README.md +8 -0
  221. package/templates/error-fixture/.lakebed-native/metro/.expo/devices.json +3 -0
  222. package/templates/error-fixture/.lakebed-native/metro/index.js +2 -0
  223. package/templates/error-fixture/.lakebed-native/metro/metro.config.js +4 -0
  224. package/templates/error-fixture/.lakebed-native/metro/package.json +4 -0
  225. package/templates/error-fixture/AGENTS.md +1 -0
  226. package/templates/error-fixture/README.md +1 -0
  227. package/templates/error-fixture/app/index.tsx +31 -0
  228. package/templates/error-fixture/server/index.ts +19 -0
  229. package/templates/form/.env.lakebed.native.server +1 -0
  230. package/templates/form/.lakebed-native/dev.json +6 -0
  231. package/templates/form/.lakebed-native/metro/.expo/README.md +8 -0
  232. package/templates/form/.lakebed-native/metro/.expo/devices.json +3 -0
  233. package/templates/form/.lakebed-native/metro/index.js +2 -0
  234. package/templates/form/.lakebed-native/metro/metro.config.js +4 -0
  235. package/templates/form/.lakebed-native/metro/package.json +4 -0
  236. package/templates/form/AGENTS.md +1 -0
  237. package/templates/form/README.md +1 -0
  238. package/templates/form/app/index.tsx +56 -0
  239. package/templates/form/server/index.ts +27 -0
  240. package/templates/guestbook/.env.lakebed.native.server +1 -0
  241. package/templates/guestbook/AGENTS.md +1 -0
  242. package/templates/guestbook/README.md +3 -0
  243. package/templates/guestbook/app/index.tsx +45 -0
  244. package/templates/guestbook/server/index.ts +31 -0
  245. package/templates/location-checkin/.env.lakebed.native.server +1 -0
  246. package/templates/location-checkin/.lakebed-native/dev.json +6 -0
  247. package/templates/location-checkin/.lakebed-native/metro/.expo/README.md +8 -0
  248. package/templates/location-checkin/.lakebed-native/metro/.expo/devices.json +3 -0
  249. package/templates/location-checkin/.lakebed-native/metro/index.js +2 -0
  250. package/templates/location-checkin/.lakebed-native/metro/metro.config.js +4 -0
  251. package/templates/location-checkin/.lakebed-native/metro/package.json +4 -0
  252. package/templates/location-checkin/AGENTS.md +1 -0
  253. package/templates/location-checkin/README.md +1 -0
  254. package/templates/location-checkin/app/index.tsx +52 -0
  255. package/templates/location-checkin/server/index.ts +34 -0
  256. package/templates/tabs/.env.lakebed.native.server +1 -0
  257. package/templates/tabs/AGENTS.md +1 -0
  258. package/templates/tabs/README.md +1 -0
  259. package/templates/tabs/app/index.tsx +39 -0
  260. package/templates/tabs/server/index.ts +9 -0
  261. package/templates/todo/.env.lakebed.native.server +1 -0
  262. package/templates/todo/AGENTS.md +27 -0
  263. package/templates/todo/README.md +18 -0
  264. package/templates/todo/app/index.tsx +112 -0
  265. package/templates/todo/server/index.ts +51 -0
@@ -0,0 +1 @@
1
+ # Location Check-in template
@@ -0,0 +1,52 @@
1
+ import React from "react";
2
+ import { Router, Stack, Route, Screen, Text, Button, List, Card } from "lakebed-native/ui";
3
+ import { useQuery, useMutation } from "lakebed-native/client";
4
+ import { location } from "lakebed-native/capabilities";
5
+
6
+ function Checkins() {
7
+ const { data: checkins, refetch } = useQuery<
8
+ Array<{ id: string; latitude: number; longitude: number; label: string }>
9
+ >("listCheckins");
10
+ const { mutate: addCheckin } = useMutation<{ latitude: number; longitude: number; label: string }>("addCheckin");
11
+
12
+ const checkIn = async () => {
13
+ const result = await location.getCurrent();
14
+ if (!result.ok) {
15
+ alert(result.message);
16
+ return;
17
+ }
18
+ await addCheckin({
19
+ latitude: result.data.latitude,
20
+ longitude: result.data.longitude,
21
+ label: "Here",
22
+ });
23
+ await refetch();
24
+ };
25
+
26
+ return (
27
+ <Screen title="Location Check-ins" testID="location-checkin-screen">
28
+ <Button title="Check In Here" onPress={checkIn} testID="checkin-button" />
29
+ <List
30
+ data={checkins ?? []}
31
+ keyExtractor={(c) => c.id}
32
+ testID="checkin-list"
33
+ renderItem={({ item }) => (
34
+ <Card testID={`checkin-${item.id}`}>
35
+ <Text>{item.label}</Text>
36
+ <Text>{item.latitude.toFixed(4)}, {item.longitude.toFixed(4)}</Text>
37
+ </Card>
38
+ )}
39
+ />
40
+ </Screen>
41
+ );
42
+ }
43
+
44
+ export default function App() {
45
+ return (
46
+ <Router>
47
+ <Stack>
48
+ <Route path="/" element={<Checkins />} />
49
+ </Stack>
50
+ </Router>
51
+ );
52
+ }
@@ -0,0 +1,34 @@
1
+ import { capsule, query, mutation, table, string, number } from "lakebed/server";
2
+
3
+ const checkins = table("checkins", {
4
+ userId: string(),
5
+ latitude: number(),
6
+ longitude: number(),
7
+ label: string(),
8
+ });
9
+
10
+ export default capsule({
11
+ name: "location-checkin",
12
+ tables: [checkins],
13
+ queries: [
14
+ query("listCheckins", (ctx) =>
15
+ ctx.db.table("checkins").orderBy("id", "desc").limit(20).all()
16
+ ),
17
+ ],
18
+ mutations: [
19
+ mutation("addCheckin", (ctx, args: { latitude?: number; longitude?: number; label?: string }) => {
20
+ if (args?.latitude == null || args?.longitude == null) {
21
+ throw new Error("Location required");
22
+ }
23
+ const userId = ctx.auth.user?.id ?? "guest";
24
+ ctx.log.info("Check-in", args);
25
+ return ctx.db.table("checkins").insert({
26
+ userId,
27
+ latitude: args.latitude,
28
+ longitude: args.longitude,
29
+ label: args.label?.trim() ?? "Check-in",
30
+ });
31
+ }),
32
+ ],
33
+ endpoints: [],
34
+ });
@@ -0,0 +1 @@
1
+ CAPSULE_NAME=tabs
@@ -0,0 +1 @@
1
+ Use lakebed-native/ui first.
@@ -0,0 +1 @@
1
+ # Tabs template
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+ import { Router, Tabs, Route, Screen, Text, Link } from "lakebed-native/ui";
3
+
4
+ function Home() {
5
+ return (
6
+ <Screen title="Home" testID="tabs-home">
7
+ <Text>Welcome to the tabs demo</Text>
8
+ <Link to="/profile/42" testID="go-profile">View Profile</Link>
9
+ </Screen>
10
+ );
11
+ }
12
+
13
+ function Explore() {
14
+ return (
15
+ <Screen title="Explore" testID="tabs-explore">
16
+ <Text>Explore tab content</Text>
17
+ </Screen>
18
+ );
19
+ }
20
+
21
+ function Profile() {
22
+ return (
23
+ <Screen title="Profile" testID="tabs-profile">
24
+ <Text>Dynamic profile route</Text>
25
+ </Screen>
26
+ );
27
+ }
28
+
29
+ export default function App() {
30
+ return (
31
+ <Router>
32
+ <Tabs>
33
+ <Route path="/" title="Home" element={<Home />} />
34
+ <Route path="/explore" title="Explore" element={<Explore />} />
35
+ <Route path="/profile/:id" title="Profile" element={<Profile />} />
36
+ </Tabs>
37
+ </Router>
38
+ );
39
+ }
@@ -0,0 +1,9 @@
1
+ import { capsule, query, mutation } from "lakebed/server";
2
+
3
+ export default capsule({
4
+ name: "tabs",
5
+ tables: [],
6
+ queries: [query("ping", () => ({ ok: true }))],
7
+ mutations: [],
8
+ endpoints: [],
9
+ });
@@ -0,0 +1 @@
1
+ CAPSULE_NAME=todo
@@ -0,0 +1,27 @@
1
+ # AGENTS.md — {{name}}
2
+
3
+ Use **lakebed-native/ui** first for all UI. Raw React Native is an escape hatch only.
4
+
5
+ ## Capsule shape
6
+
7
+ - `app/index.tsx` — client UI
8
+ - `server/index.ts` — server logic (queries, mutations, tables)
9
+ - `shared/` — shared types/helpers
10
+ - `.env.lakebed.native.server` — server env (CAPSULE_NAME required)
11
+
12
+ ## Imports
13
+
14
+ ```tsx
15
+ import { useQuery, useMutation, useAuth } from "lakebed-native/client";
16
+ import { Router, Tabs, Route, Screen, Text, Button, Input, List } from "lakebed-native/ui";
17
+ import { capsule, query, mutation, table, string, boolean, text } from "lakebed/server";
18
+ ```
19
+
20
+ ## Rules
21
+
22
+ 1. Never create ios/, android/, app.json, or metro.config.js
23
+ 2. Use lakebed-native/ui components before react-native primitives
24
+ 3. Server owns all persistent data via ctx.db
25
+ 4. Use ctx.auth.user for per-user scoping
26
+ 5. Run `npx lakebed-native dev` for local development
27
+ 6. Test with `npx lakebed-native open` in iOS simulator
@@ -0,0 +1,18 @@
1
+ # {{name}}
2
+
3
+ A Lakebed Native todo capsule with per-user todos, tabs, and auth switching.
4
+
5
+ ## Dev
6
+
7
+ ```sh
8
+ npx lakebed-native dev
9
+ npx lakebed-native open --url "lakebed-native://capsule?server=http://localhost:3000&bundle=http://localhost:3100"
10
+ ```
11
+
12
+ ## Inspect
13
+
14
+ ```sh
15
+ npx lakebed-native db list
16
+ npx lakebed-native inspect
17
+ npx lakebed-native logs
18
+ ```
@@ -0,0 +1,112 @@
1
+ import React, { useState } from "react";
2
+ import { Keyboard } from "react-native";
3
+ import {
4
+ Router,
5
+ Tabs,
6
+ Route,
7
+ Screen,
8
+ Text,
9
+ Button,
10
+ Input,
11
+ List,
12
+ Card,
13
+ Row,
14
+ Checkbox,
15
+ Link,
16
+ } from "lakebed-native/ui";
17
+ import { useQuery, useMutation, useAuth, getClientConfig } from "lakebed-native/client";
18
+
19
+ function HomeScreen() {
20
+ const { data: todos, refetch } = useQuery<Array<{ id: string; title: string; done: boolean }>>("listTodos");
21
+ const { mutate: addTodo } = useMutation<{ title: string }>("addTodo");
22
+ const { mutate: toggleTodo } = useMutation<{ id: string }>("toggleTodo");
23
+ const [title, setTitle] = useState("");
24
+
25
+ const handleAdd = async () => {
26
+ if (!title.trim()) return;
27
+ await addTodo({ title: title.trim() });
28
+ setTitle("");
29
+ Keyboard.dismiss();
30
+ await refetch();
31
+ };
32
+
33
+ return (
34
+ <Screen title="Todos" testID="todo-home-screen">
35
+ <Input
36
+ value={title}
37
+ onChangeText={setTitle}
38
+ placeholder="What needs doing?"
39
+ testID="todo-input"
40
+ />
41
+ <Button title="Add Todo" onPress={handleAdd} testID="add-todo-button" />
42
+ <List
43
+ data={todos ?? []}
44
+ keyExtractor={(item) => item.id}
45
+ testID="todo-list"
46
+ ListEmptyComponent={<Text testID="empty-todos">No todos yet</Text>}
47
+ renderItem={({ item }) => (
48
+ <Card testID={`todo-item-${item.id}`}>
49
+ <Row>
50
+ <Checkbox
51
+ checked={item.done}
52
+ onChange={() => toggleTodo({ id: item.id }).then(() => refetch())}
53
+ testID={`todo-check-${item.id}`}
54
+ />
55
+ <Text style={{ flex: 1, textDecorationLine: item.done ? "line-through" : "none" }}>
56
+ {item.title}
57
+ </Text>
58
+ </Row>
59
+ </Card>
60
+ )}
61
+ />
62
+ </Screen>
63
+ );
64
+ }
65
+
66
+ function SettingsScreen() {
67
+ const { user, refresh } = useAuth();
68
+
69
+ return (
70
+ <Screen title="Settings" testID="settings-screen">
71
+ <Text testID="current-user">Signed in as: {user?.name ?? "Guest"}</Text>
72
+ <Button
73
+ title="Switch to Alice"
74
+ testID="auth-alice"
75
+ onPress={async () => {
76
+ const { serverUrl } = getClientConfig();
77
+ await fetch(`${serverUrl}/auth/as`, {
78
+ method: "POST",
79
+ headers: { "Content-Type": "application/json" },
80
+ body: JSON.stringify({ name: "alice" }),
81
+ });
82
+ await refresh();
83
+ }}
84
+ />
85
+ <Button
86
+ title="Switch to Bob"
87
+ testID="auth-bob"
88
+ onPress={async () => {
89
+ const { serverUrl } = getClientConfig();
90
+ await fetch(`${serverUrl}/auth/as`, {
91
+ method: "POST",
92
+ headers: { "Content-Type": "application/json" },
93
+ body: JSON.stringify({ name: "bob" }),
94
+ });
95
+ await refresh();
96
+ }}
97
+ />
98
+ <Link to="/" testID="back-home">Back to Home</Link>
99
+ </Screen>
100
+ );
101
+ }
102
+
103
+ export default function App() {
104
+ return (
105
+ <Router>
106
+ <Tabs>
107
+ <Route path="/" title="Home" element={<HomeScreen />} />
108
+ <Route path="/settings" title="Settings" element={<SettingsScreen />} />
109
+ </Tabs>
110
+ </Router>
111
+ );
112
+ }
@@ -0,0 +1,51 @@
1
+ import {
2
+ capsule,
3
+ query,
4
+ mutation,
5
+ table,
6
+ string,
7
+ boolean,
8
+ text,
9
+ } from "lakebed/server";
10
+
11
+ const todos = table("todos", {
12
+ userId: string(),
13
+ title: text(),
14
+ done: boolean(),
15
+ });
16
+
17
+ export default capsule({
18
+ name: "todo",
19
+ tables: [todos],
20
+ queries: [
21
+ query("listTodos", (ctx) => {
22
+ const userId = ctx.auth.user?.id ?? "guest";
23
+ return ctx.db.table("todos").where("userId", userId).orderBy("title", "asc").all();
24
+ }),
25
+ query("me", (ctx) => ctx.auth.user),
26
+ ],
27
+ mutations: [
28
+ mutation("addTodo", (ctx, args: { title?: string }) => {
29
+ const title = args?.title?.trim();
30
+ if (!title) throw new Error("Title is required");
31
+ const userId = ctx.auth.user?.id ?? "guest";
32
+ ctx.log.info("Adding todo", { title, userId });
33
+ return ctx.db.table("todos").insert({ userId, title, done: false });
34
+ }),
35
+ mutation("toggleTodo", (ctx, args: { id?: string }) => {
36
+ if (!args?.id) throw new Error("id required");
37
+ const row = ctx.db.table("todos").get(args.id);
38
+ if (!row) throw new Error("Todo not found");
39
+ return ctx.db.table("todos").update(args.id, { done: !row.done });
40
+ }),
41
+ mutation("deleteTodo", (ctx, args: { id?: string }) => {
42
+ if (!args?.id) throw new Error("id required");
43
+ ctx.db.table("todos").delete(args.id);
44
+ return { ok: true };
45
+ }),
46
+ mutation("signInWithGoogle", (ctx) => {
47
+ return { id: "google-user", name: "Google User", email: "user@gmail.com" };
48
+ }),
49
+ ],
50
+ endpoints: [],
51
+ });