diff --git a/.gitignore b/.gitignore index 679e2e2..7eb4586 100644 --- a/.gitignore +++ b/.gitignore @@ -46,7 +46,6 @@ yarn-error.log* # typescript *.tsbuildinfo -dist/ # turbo .turbo diff --git a/.vscode/settings.json b/.vscode/settings.json index e274cb9..22989b4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,9 +12,5 @@ { "pattern": "tooling/*/" } ], "typescript.enablePromptUseWorkspaceTsdk": true, - "typescript.preferences.autoImportFileExcludePatterns": [ - "next/router.d.ts", - "next/dist/client/router.d.ts" - ], "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/apps/api/.gitignore b/apps/api/.gitignore index 5f61035..6e7091b 100644 --- a/apps/api/.gitignore +++ b/apps/api/.gitignore @@ -12,7 +12,6 @@ # production /build -/dist /out # misc diff --git a/apps/api/package.json b/apps/api/package.json index aec89fc..c80697b 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -4,6 +4,11 @@ "main": "build/index.mjs", "private": true, "type": "module", + "exports": { + "./router": { + "types": "./build/src/web/router.d.ts" + } + }, "scripts": { "start": "node build/index.mjs", "dev": "pnpm with-env run-p dev:*", @@ -43,6 +48,7 @@ "@types/jest": "^29.5.12", "@types/node": "^18.19.31", "@vercel/node": "^2.15.10", + "dotenv-cli": "^7.4.1", "jest": "^29.7.0", "npm-run-all": "^4.1.5", "prettier": "^3.2.5", diff --git a/apps/api/src/web/endpoint.ts b/apps/api/src/web/endpoint.ts index fe64353..f2870c4 100644 --- a/apps/api/src/web/endpoint.ts +++ b/apps/api/src/web/endpoint.ts @@ -12,7 +12,7 @@ import { authPlugin, } from '@splitter/package-auth' -import { router } from '@/web/router' +import router from '@/web/router' import { createContext } from '@/web/trpc' const app = fastify({ logger: true }) diff --git a/apps/api/src/web/router.ts b/apps/api/src/web/router.ts index 513dbdd..9cd4ba7 100644 --- a/apps/api/src/web/router.ts +++ b/apps/api/src/web/router.ts @@ -1,3 +1,5 @@ +import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server' + import { CreateUserSchema, FindBillsSchema, @@ -24,6 +26,12 @@ const users = createRouter({ .mutation(async ({ input }) => await Users.create(input)), }) -export const router = createRouter({ bills, users }) +const router = createRouter({ bills, users }) + +export default router export type Router = typeof router + +export type RouterInputs = inferRouterInputs + +export type RouterOutputs = inferRouterOutputs diff --git a/apps/mobile/.gitignore b/apps/mobile/.gitignore index 7bce1e5..b29de07 100644 --- a/apps/mobile/.gitignore +++ b/apps/mobile/.gitignore @@ -1,6 +1,5 @@ node_modules/ .expo/ -dist/ npm-debug.* *.jks *.p8 diff --git a/apps/mobile/app.config.ts b/apps/mobile/app.config.ts index fd3af86..9893b9f 100644 --- a/apps/mobile/app.config.ts +++ b/apps/mobile/app.config.ts @@ -50,7 +50,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({ android: { package: getBundleIdentifier(), adaptiveIcon: { - foregroundImage: './assets/adaptive-icon.png', + foregroundImage: './assets/images/adaptive-icon.png', backgroundColor: '#ffffff', }, }, @@ -65,7 +65,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({ // // Environment extra: { - // ...process.env, + ...process.env, eas: { projectId: '916828f4-940a-42fa-a42d-a662c47baf27', }, diff --git a/apps/mobile/package.json b/apps/mobile/package.json index 3574012..ae11eb3 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -1,10 +1,10 @@ { - "name": "splitter", + "name": "@splitter/mobile", "main": "expo-router/entry", "version": "1.0.0", "private": true, "scripts": { - "dev": "expo start", + "dev": "pnpm with-env expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", @@ -15,7 +15,8 @@ "lint:ts": "tsc", "lint:eslint": "eslint", "lint:prettier": "prettier --check . --ignore-path ../../.gitignore", - "clean": "git clean -xdf node_modules .turbo build" + "clean": "git clean -xdf node_modules .turbo build", + "with-env": "dotenv -e ../../.env --" }, "dependencies": { "@expo/metro-config": "~0.18.1", @@ -44,7 +45,8 @@ "react-native-safe-area-context": "4.10.1", "react-native-screens": "3.31.1", "react-native-web": "~0.19.10", - "superjson": "^2.2.1" + "superjson": "^2.2.1", + "zod": "^3.23.4" }, "devDependencies": { "@babel/core": "^7.20.0", @@ -56,6 +58,7 @@ "@types/jest": "^29.5.12", "@types/react": "~18.2.45", "@types/react-test-renderer": "^18.0.7", + "dotenv-cli": "^7.4.1", "jest": "^29.2.1", "jest-expo": "~51.0.2", "npm-run-all": "^4.1.5", diff --git a/apps/mobile/src/app/_layout.tsx b/apps/mobile/src/app/_layout.tsx index b2a2b29..a1adb62 100644 --- a/apps/mobile/src/app/_layout.tsx +++ b/apps/mobile/src/app/_layout.tsx @@ -2,10 +2,14 @@ import '@/styles.css' import { Stack } from 'expo-router' +import Provider from '@/services/providers' + export default function RootLayout() { return ( - - - + + + + + ) } diff --git a/apps/mobile/src/app/index.tsx b/apps/mobile/src/app/index.tsx index f692e7e..f874d49 100644 --- a/apps/mobile/src/app/index.tsx +++ b/apps/mobile/src/app/index.tsx @@ -1,6 +1,14 @@ import { Text, View } from 'react-native' +import { api } from '@/services/api' + export default function Index() { + const bills = api.bills.list.useQuery() + + if (bills.error) console.log(bills.error) + + if (bills.isLoading) return Loading... + return ( () + +export const TRPCProvider = api.Provider + +export const createTRPCClient = () => + api.createClient({ + transformer: superjson, + links: [ + loggerLink({ + colorMode: 'ansi', + enabled: (opts) => opts.direction === 'down' && !opts.result, + }), + httpBatchLink({ + url: TRPC_API_URL, + headers() { + const headers = new Map() + headers.set('x-trpc-source', 'expo-react') + return Object.fromEntries(headers) + }, + }), + ], + }) + +export { type RouterInputs, type RouterOutputs } from '@splitter/api/router' diff --git a/apps/mobile/src/services/env.ts b/apps/mobile/src/services/env.ts new file mode 100644 index 0000000..dd6ba4f --- /dev/null +++ b/apps/mobile/src/services/env.ts @@ -0,0 +1,18 @@ +import Constants from 'expo-constants' +import z from 'zod' + +export function isProductionEnv(env: 'development' | 'production') { + return env === 'production' +} + +const schema = z.object({ + ENV: z.union([z.literal('development'), z.literal('production')]), + API_HOST: z.string(), + API_PORT: z.string(), + DEBUGGER_HOST: z.string(), +}) + +export default schema.parse({ + ...Constants.expoConfig?.extra, + DEBUGGER_HOST: Constants.expoConfig?.hostUri?.split(':').at(0) ?? '', +}) diff --git a/apps/mobile/src/services/providers.tsx b/apps/mobile/src/services/providers.tsx new file mode 100644 index 0000000..e6e9000 --- /dev/null +++ b/apps/mobile/src/services/providers.tsx @@ -0,0 +1,20 @@ +import { useState } from 'react' + +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' + +import { TRPCProvider, createTRPCClient } from '@/services/api' + +interface Props { + children: JSX.Element | JSX.Element[] +} + +export default function Provider({ children }: Props) { + const [queryClient] = useState(() => new QueryClient()) + const [trpcClient] = useState(() => createTRPCClient()) + + return ( + + {children} + + ) +} diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json index 5ebf222..844bad4 100644 --- a/packages/db/tsconfig.json +++ b/packages/db/tsconfig.json @@ -9,5 +9,5 @@ } }, "include": ["*.ts", "src"], - "exclude": ["node_modules"] + "exclude": ["node_modules", "build"] } diff --git a/packages/validators/tsconfig.json b/packages/validators/tsconfig.json index 3b41ae4..5ebf222 100644 --- a/packages/validators/tsconfig.json +++ b/packages/validators/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@splitter/tooling-typescript/internal-package.json", "compilerOptions": { - "outDir": "dist", + "outDir": "build", "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json", "baseUrl": ".", "paths": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3ed6ecf..d28cc46 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -84,6 +84,9 @@ importers: '@vercel/node': specifier: ^2.15.10 version: 2.15.10 + dotenv-cli: + specifier: ^7.4.1 + version: 7.4.1 jest: specifier: ^29.7.0 version: 29.7.0(@types/node@18.19.31)(ts-node@10.9.2(@types/node@18.19.31)(typescript@5.4.5)) @@ -195,6 +198,9 @@ importers: superjson: specifier: ^2.2.1 version: 2.2.1 + zod: + specifier: ^3.23.4 + version: 3.23.4 devDependencies: '@babel/core': specifier: ^7.20.0 @@ -223,6 +229,9 @@ importers: '@types/react-test-renderer': specifier: ^18.0.7 version: 18.3.0 + dotenv-cli: + specifier: ^7.4.1 + version: 7.4.1 jest: specifier: ^29.2.1 version: 29.7.0(@types/node@18.19.31)(ts-node@10.9.2(@types/node@18.19.31)(typescript@5.4.5)) @@ -238,9 +247,6 @@ importers: tailwindcss: specifier: ^3.4.3 version: 3.4.3(ts-node@10.9.2(@types/node@18.19.31)(typescript@5.4.5)) - ts-node: - specifier: ^10.9.2 - version: 10.9.2(@types/node@18.19.31)(typescript@5.4.5) typescript: specifier: ^5.4.5 version: 5.4.5 diff --git a/tooling/eslint/src/base.js b/tooling/eslint/src/base.js index a862087..6d1d32b 100644 --- a/tooling/eslint/src/base.js +++ b/tooling/eslint/src/base.js @@ -25,9 +25,11 @@ export default tseslint.config( ...tseslint.configs.stylisticTypeChecked, ], rules: { - // Typescript Eslint 'no-unused-vars': 'error', + // Typescript Eslint '@typescript-eslint/no-unused-vars': 'error', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-return': 'off', '@typescript-eslint/consistent-type-imports': [ 'warn', { prefer: 'type-imports', fixStyle: 'separate-type-imports' }, diff --git a/tooling/typescript/base.json b/tooling/typescript/base.json index 6a517e1..1d7cb02 100644 --- a/tooling/typescript/base.json +++ b/tooling/typescript/base.json @@ -21,5 +21,5 @@ "moduleResolution": "Bundler", "noEmit": true }, - "exclude": ["node_modules", "build", "dist", ".expo"] + "exclude": ["node_modules", "build", ".expo"] }