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.
- package/dist/cli/apple/branding.d.ts +9 -0
- package/dist/cli/apple/branding.d.ts.map +1 -0
- package/dist/cli/apple/branding.js +40 -0
- package/dist/cli/apple/branding.js.map +1 -0
- package/dist/cli/apple/build-cloud.d.ts +6 -0
- package/dist/cli/apple/build-cloud.d.ts.map +1 -0
- package/dist/cli/apple/build-cloud.js +34 -0
- package/dist/cli/apple/build-cloud.js.map +1 -0
- package/dist/cli/apple/build-local.d.ts +16 -0
- package/dist/cli/apple/build-local.d.ts.map +1 -0
- package/dist/cli/apple/build-local.js +97 -0
- package/dist/cli/apple/build-local.js.map +1 -0
- package/dist/cli/apple/choose-path.d.ts +23 -0
- package/dist/cli/apple/choose-path.d.ts.map +1 -0
- package/dist/cli/apple/choose-path.js +78 -0
- package/dist/cli/apple/choose-path.js.map +1 -0
- package/dist/cli/apple/device-pack.d.ts +36 -0
- package/dist/cli/apple/device-pack.d.ts.map +1 -0
- package/dist/cli/apple/device-pack.js +210 -0
- package/dist/cli/apple/device-pack.js.map +1 -0
- package/dist/cli/apple/devices.d.ts +6 -0
- package/dist/cli/apple/devices.d.ts.map +1 -0
- package/dist/cli/apple/devices.js +49 -0
- package/dist/cli/apple/devices.js.map +1 -0
- package/dist/cli/apple/eas-delegate.d.ts +25 -0
- package/dist/cli/apple/eas-delegate.d.ts.map +1 -0
- package/dist/cli/apple/eas-delegate.js +63 -0
- package/dist/cli/apple/eas-delegate.js.map +1 -0
- package/dist/cli/apple/index.d.ts +9 -0
- package/dist/cli/apple/index.d.ts.map +1 -0
- package/dist/cli/apple/index.js +12 -0
- package/dist/cli/apple/index.js.map +1 -0
- package/dist/cli/apple/route-device-build.d.ts +16 -0
- package/dist/cli/apple/route-device-build.d.ts.map +1 -0
- package/dist/cli/apple/route-device-build.js +54 -0
- package/dist/cli/apple/route-device-build.js.map +1 -0
- package/dist/cli/apple/setup.d.ts +5 -0
- package/dist/cli/apple/setup.d.ts.map +1 -0
- package/dist/cli/apple/setup.js +69 -0
- package/dist/cli/apple/setup.js.map +1 -0
- package/dist/cli/apple/shell-ipa.d.ts +7 -0
- package/dist/cli/apple/shell-ipa.d.ts.map +1 -0
- package/dist/cli/apple/shell-ipa.js +73 -0
- package/dist/cli/apple/shell-ipa.js.map +1 -0
- package/dist/cli/apple/sign-ios.d.ts +24 -0
- package/dist/cli/apple/sign-ios.d.ts.map +1 -0
- package/dist/cli/apple/sign-ios.js +148 -0
- package/dist/cli/apple/sign-ios.js.map +1 -0
- package/dist/cli/apple/status.d.ts +64 -0
- package/dist/cli/apple/status.d.ts.map +1 -0
- package/dist/cli/apple/status.js +249 -0
- package/dist/cli/apple/status.js.map +1 -0
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +7 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/bundler.d.ts +16 -0
- package/dist/cli/bundler.d.ts.map +1 -0
- package/dist/cli/bundler.js +109 -0
- package/dist/cli/bundler.js.map +1 -0
- package/dist/cli/capsule-eas.d.ts +27 -0
- package/dist/cli/capsule-eas.d.ts.map +1 -0
- package/dist/cli/capsule-eas.js +131 -0
- package/dist/cli/capsule-eas.js.map +1 -0
- package/dist/cli/cloud/index.d.ts +14 -0
- package/dist/cli/cloud/index.d.ts.map +1 -0
- package/dist/cli/cloud/index.js +118 -0
- package/dist/cli/cloud/index.js.map +1 -0
- package/dist/cli/cloud-client.d.ts +38 -0
- package/dist/cli/cloud-client.d.ts.map +1 -0
- package/dist/cli/cloud-client.js +71 -0
- package/dist/cli/cloud-client.js.map +1 -0
- package/dist/cli/commands/auth.d.ts +2 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/auth.js +18 -0
- package/dist/cli/commands/auth.js.map +1 -0
- package/dist/cli/commands/build-native.d.ts +18 -0
- package/dist/cli/commands/build-native.d.ts.map +1 -0
- package/dist/cli/commands/build-native.js +156 -0
- package/dist/cli/commands/build-native.js.map +1 -0
- package/dist/cli/commands/build.d.ts +6 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +57 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/claim.d.ts +2 -0
- package/dist/cli/commands/claim.d.ts.map +1 -0
- package/dist/cli/commands/claim.js +2 -0
- package/dist/cli/commands/claim.js.map +1 -0
- package/dist/cli/commands/db.d.ts +7 -0
- package/dist/cli/commands/db.d.ts.map +1 -0
- package/dist/cli/commands/db.js +18 -0
- package/dist/cli/commands/db.js.map +1 -0
- package/dist/cli/commands/deploy.d.ts +10 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.js +101 -0
- package/dist/cli/commands/deploy.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +5 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +46 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/devices.d.ts +4 -0
- package/dist/cli/commands/devices.d.ts.map +1 -0
- package/dist/cli/commands/devices.js +27 -0
- package/dist/cli/commands/devices.js.map +1 -0
- package/dist/cli/commands/domains.d.ts +5 -0
- package/dist/cli/commands/domains.d.ts.map +1 -0
- package/dist/cli/commands/domains.js +36 -0
- package/dist/cli/commands/domains.js.map +1 -0
- package/dist/cli/commands/inspect.d.ts +7 -0
- package/dist/cli/commands/inspect.d.ts.map +1 -0
- package/dist/cli/commands/inspect.js +15 -0
- package/dist/cli/commands/inspect.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +7 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +15 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/new.d.ts +6 -0
- package/dist/cli/commands/new.d.ts.map +1 -0
- package/dist/cli/commands/new.js +17 -0
- package/dist/cli/commands/new.js.map +1 -0
- package/dist/cli/commands/open.d.ts +5 -0
- package/dist/cli/commands/open.d.ts.map +1 -0
- package/dist/cli/commands/open.js +14 -0
- package/dist/cli/commands/open.js.map +1 -0
- package/dist/cli/commands/pack.d.ts +32 -0
- package/dist/cli/commands/pack.d.ts.map +1 -0
- package/dist/cli/commands/pack.js +273 -0
- package/dist/cli/commands/pack.js.map +1 -0
- package/dist/cli/commands/screenshot.d.ts +5 -0
- package/dist/cli/commands/screenshot.d.ts.map +1 -0
- package/dist/cli/commands/screenshot.js +8 -0
- package/dist/cli/commands/screenshot.js.map +1 -0
- package/dist/cli/commands/shell-fetch.d.ts +5 -0
- package/dist/cli/commands/shell-fetch.d.ts.map +1 -0
- package/dist/cli/commands/shell-fetch.js +123 -0
- package/dist/cli/commands/shell-fetch.js.map +1 -0
- package/dist/cli/commands/shell.d.ts +2 -0
- package/dist/cli/commands/shell.d.ts.map +1 -0
- package/dist/cli/commands/shell.js +2 -0
- package/dist/cli/commands/shell.js.map +1 -0
- package/dist/cli/commands/submit.d.ts +2 -0
- package/dist/cli/commands/submit.d.ts.map +1 -0
- package/dist/cli/commands/submit.js +2 -0
- package/dist/cli/commands/submit.js.map +1 -0
- package/dist/cli/commands/tree.d.ts +5 -0
- package/dist/cli/commands/tree.d.ts.map +1 -0
- package/dist/cli/commands/tree.js +23 -0
- package/dist/cli/commands/tree.js.map +1 -0
- package/dist/cli/deploy-metadata.d.ts +10 -0
- package/dist/cli/deploy-metadata.d.ts.map +1 -0
- package/dist/cli/deploy-metadata.js +50 -0
- package/dist/cli/deploy-metadata.js.map +1 -0
- package/dist/cli/deploy-runtime.d.ts +4 -0
- package/dist/cli/deploy-runtime.d.ts.map +1 -0
- package/dist/cli/deploy-runtime.js +14 -0
- package/dist/cli/deploy-runtime.js.map +1 -0
- package/dist/cli/dev-config.d.ts +2 -0
- package/dist/cli/dev-config.d.ts.map +1 -0
- package/dist/cli/dev-config.js +36 -0
- package/dist/cli/dev-config.js.map +1 -0
- package/dist/cli/hosted-client.d.ts +39 -0
- package/dist/cli/hosted-client.d.ts.map +1 -0
- package/dist/cli/hosted-client.js +275 -0
- package/dist/cli/hosted-client.js.map +1 -0
- package/dist/cli/hosted-v1-store.d.ts +73 -0
- package/dist/cli/hosted-v1-store.d.ts.map +1 -0
- package/dist/cli/hosted-v1-store.js +96 -0
- package/dist/cli/hosted-v1-store.js.map +1 -0
- package/dist/cli/hosted.d.ts +13 -0
- package/dist/cli/hosted.d.ts.map +1 -0
- package/dist/cli/hosted.js +337 -0
- package/dist/cli/hosted.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +261 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/kit-paths.d.ts +8 -0
- package/dist/cli/kit-paths.d.ts.map +1 -0
- package/dist/cli/kit-paths.js +67 -0
- package/dist/cli/kit-paths.js.map +1 -0
- package/dist/cli/loader.d.ts +2 -0
- package/dist/cli/loader.d.ts.map +1 -0
- package/dist/cli/loader.js +5 -0
- package/dist/cli/loader.js.map +1 -0
- package/dist/cli/native-deploy-payload.d.ts +17 -0
- package/dist/cli/native-deploy-payload.d.ts.map +1 -0
- package/dist/cli/native-deploy-payload.js +29 -0
- package/dist/cli/native-deploy-payload.js.map +1 -0
- package/dist/cli/platform-detect.d.ts +11 -0
- package/dist/cli/platform-detect.d.ts.map +1 -0
- package/dist/cli/platform-detect.js +54 -0
- package/dist/cli/platform-detect.js.map +1 -0
- package/dist/cli/site.d.ts +6 -0
- package/dist/cli/site.d.ts.map +1 -0
- package/dist/cli/site.js +9 -0
- package/dist/cli/site.js.map +1 -0
- package/dist/cli/util.d.ts +12 -0
- package/dist/cli/util.d.ts.map +1 -0
- package/dist/cli/util.js +118 -0
- package/dist/cli/util.js.map +1 -0
- package/dist/cli/web-deploy-envelope.d.ts +15 -0
- package/dist/cli/web-deploy-envelope.d.ts.map +1 -0
- package/dist/cli/web-deploy-envelope.js +156 -0
- package/dist/cli/web-deploy-envelope.js.map +1 -0
- package/metro.lakebed-native.cjs +94 -0
- package/package.json +38 -0
- package/templates/camera-note/.env.lakebed.native.server +1 -0
- package/templates/camera-note/.lakebed-native/dev.json +6 -0
- package/templates/camera-note/.lakebed-native/metro/.expo/README.md +8 -0
- package/templates/camera-note/.lakebed-native/metro/.expo/devices.json +3 -0
- package/templates/camera-note/.lakebed-native/metro/index.js +2 -0
- package/templates/camera-note/.lakebed-native/metro/metro.config.js +4 -0
- package/templates/camera-note/.lakebed-native/metro/package.json +4 -0
- package/templates/camera-note/AGENTS.md +1 -0
- package/templates/camera-note/README.md +1 -0
- package/templates/camera-note/app/index.tsx +64 -0
- package/templates/camera-note/server/index.ts +23 -0
- package/templates/error-fixture/.env.lakebed.native.server +1 -0
- package/templates/error-fixture/.lakebed-native/dev.json +6 -0
- package/templates/error-fixture/.lakebed-native/metro/.expo/README.md +8 -0
- package/templates/error-fixture/.lakebed-native/metro/.expo/devices.json +3 -0
- package/templates/error-fixture/.lakebed-native/metro/index.js +2 -0
- package/templates/error-fixture/.lakebed-native/metro/metro.config.js +4 -0
- package/templates/error-fixture/.lakebed-native/metro/package.json +4 -0
- package/templates/error-fixture/AGENTS.md +1 -0
- package/templates/error-fixture/README.md +1 -0
- package/templates/error-fixture/app/index.tsx +31 -0
- package/templates/error-fixture/server/index.ts +19 -0
- package/templates/form/.env.lakebed.native.server +1 -0
- package/templates/form/.lakebed-native/dev.json +6 -0
- package/templates/form/.lakebed-native/metro/.expo/README.md +8 -0
- package/templates/form/.lakebed-native/metro/.expo/devices.json +3 -0
- package/templates/form/.lakebed-native/metro/index.js +2 -0
- package/templates/form/.lakebed-native/metro/metro.config.js +4 -0
- package/templates/form/.lakebed-native/metro/package.json +4 -0
- package/templates/form/AGENTS.md +1 -0
- package/templates/form/README.md +1 -0
- package/templates/form/app/index.tsx +56 -0
- package/templates/form/server/index.ts +27 -0
- package/templates/guestbook/.env.lakebed.native.server +1 -0
- package/templates/guestbook/AGENTS.md +1 -0
- package/templates/guestbook/README.md +3 -0
- package/templates/guestbook/app/index.tsx +45 -0
- package/templates/guestbook/server/index.ts +31 -0
- package/templates/location-checkin/.env.lakebed.native.server +1 -0
- package/templates/location-checkin/.lakebed-native/dev.json +6 -0
- package/templates/location-checkin/.lakebed-native/metro/.expo/README.md +8 -0
- package/templates/location-checkin/.lakebed-native/metro/.expo/devices.json +3 -0
- package/templates/location-checkin/.lakebed-native/metro/index.js +2 -0
- package/templates/location-checkin/.lakebed-native/metro/metro.config.js +4 -0
- package/templates/location-checkin/.lakebed-native/metro/package.json +4 -0
- package/templates/location-checkin/AGENTS.md +1 -0
- package/templates/location-checkin/README.md +1 -0
- package/templates/location-checkin/app/index.tsx +52 -0
- package/templates/location-checkin/server/index.ts +34 -0
- package/templates/tabs/.env.lakebed.native.server +1 -0
- package/templates/tabs/AGENTS.md +1 -0
- package/templates/tabs/README.md +1 -0
- package/templates/tabs/app/index.tsx +39 -0
- package/templates/tabs/server/index.ts +9 -0
- package/templates/todo/.env.lakebed.native.server +1 -0
- package/templates/todo/AGENTS.md +27 -0
- package/templates/todo/README.md +18 -0
- package/templates/todo/app/index.tsx +112 -0
- 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 @@
|
|
|
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
|
+
});
|