Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructuring prototype RFC #1584

Merged
merged 25 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
da8b259
Early prototype
sodic Nov 4, 2023
0d7087f
Add prototype migration script and fix some issues
sodic Nov 15, 2023
e3fdecc
Merge branch 'main' into filip-restructuring-prototype
sodic Nov 15, 2023
6789cd5
Update the todo-ts prototype version to match main
sodic Nov 16, 2023
eb338c6
Switch user files to the new (vertical) structure in prototype
sodic Nov 17, 2023
35c9efa
Prototype with direct imports works in development
sodic Nov 21, 2023
d51e64b
Fix typo in package.json
sodic Nov 21, 2023
22c7706
Revert cosmetic updates to todo-typescript example apps
sodic Nov 23, 2023
02bdcbe
Remove old queries files
sodic Nov 24, 2023
1002c4b
Remove extra dependencies from auth package
sodic Nov 24, 2023
8d39046
Remove completed todo
sodic Nov 24, 2023
3fd2f16
Remove redundant server types
sodic Nov 24, 2023
20b5ef7
Remove redundant exports from operations
sodic Nov 24, 2023
577c6cf
Remove redundant dependencies and package lock
sodic Nov 24, 2023
3da3f52
Remove npm install skip
sodic Nov 24, 2023
3ceb92d
Fix formatting
sodic Nov 24, 2023
1c6a12f
Make migrate script more portable
sodic Nov 24, 2023
d22922d
Turn scoped package into a single package
sodic Nov 30, 2023
49c85e0
Generate SDK from templates in prototype
sodic Dec 8, 2023
afdb509
Merge branch 'main' into filip-restructuring-prototype
sodic Jan 4, 2024
a5a7382
Make prototype work with inject auth changes
sodic Jan 8, 2024
667a31b
Merge branch 'main' into filip-restructuring-prototype
infomiho Jan 19, 2024
a35040e
Apply latest auth changes to the prototype (#1646)
infomiho Jan 19, 2024
66682ff
Fixes HttpError and AuthError instanceof bug (#1648)
infomiho Jan 21, 2024
8588660
Merge branch 'main' into filip-restructuring-prototype
sodic Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions waspc/cli/src/Wasp/Cli/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ dotWaspInfoFileInGeneratedCodeDir :: Path' (Rel Wasp.Generator.Common.ProjectRoo
dotWaspInfoFileInGeneratedCodeDir = [relfile|.waspinfo|]

extServerCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
extServerCodeDirInWaspProjectDir = [reldir|src/server|]
extServerCodeDirInWaspProjectDir = [reldir|src|]

extClientCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
extClientCodeDirInWaspProjectDir = [reldir|src/client|]
extClientCodeDirInWaspProjectDir = [reldir|src|]

extSharedCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
extSharedCodeDirInWaspProjectDir = [reldir|src/shared|]
extSharedCodeDirInWaspProjectDir = [reldir|src|]
sodic marked this conversation as resolved.
Show resolved Hide resolved

waspSays :: String -> IO ()
waspSays what = putStrLn $ Term.applyStyles [Term.Yellow] what
Expand Down
2 changes: 1 addition & 1 deletion waspc/data/Cli/templates/basic/src/client/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/// <reference types="../../.wasp/out/web-app/node_modules/vite/client" />
/// <reference types="vite/client" />
2 changes: 1 addition & 1 deletion waspc/data/Generator/templates/react-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import router from './router'
import {
initializeQueryClient,
queryClientInitialized,
} from './queryClient'
} from '@wasp/rpc/queryClient'
sodic marked this conversation as resolved.
Show resolved Hide resolved

{=# setupFn.isDefined =}
{=& setupFn.importStatement =}
Expand Down
2 changes: 1 addition & 1 deletion waspc/data/Generator/templates/react-app/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
{=/ rootComponent.isDefined =}

{=# isAuthEnabled =}
import createAuthRequiredPage from "./auth/pages/createAuthRequiredPage"
import createAuthRequiredPage from "@wasp/auth/pages/createAuthRequiredPage"
sodic marked this conversation as resolved.
Show resolved Hide resolved
{=/ isAuthEnabled =}

{=# pagesToImport =}
Expand Down
12 changes: 9 additions & 3 deletions waspc/data/Generator/templates/react-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
// Allow importing pages with the .tsx extension.
"allowImportingTsExtensions": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
"include": [
"src"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
3 changes: 3 additions & 0 deletions waspc/data/Generator/templates/react-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const _waspUserProvidedConfig = {};
const defaultViteConfig = {
base: "{= baseDir =}",
plugins: [react()],
optimizeDeps: {
exclude: ['@wasp']
},
Copy link
Contributor Author

@sodic sodic Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vite's dependency optimization was causing weird bugs.

Todo: describe

@infomiho knows what's up. @Martinsos take my word for it for now, I'll update the comment in a bit.

server: {
port: {= defaultClientPort =},
host: "0.0.0.0",
Expand Down
2 changes: 2 additions & 0 deletions waspc/data/Generator/templates/server/nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
},
"watch": [
"src/",
"../../../src/",
".env"
],
"comment-filip": "We now have to watch ../../../src/ because we're importing client files directly",
sodic marked this conversation as resolved.
Show resolved Hide resolved
"ext": "ts,mts,js,mjs,json"
}
3 changes: 2 additions & 1 deletion waspc/data/Generator/templates/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"version": "0.0.0",
"private": true,
"type": "module",
"comment-filip": "The server.js location changed because we have now included client source files above .wasp/out/server/src.",
sodic marked this conversation as resolved.
Show resolved Hide resolved
"scripts": {
"build": "npx tsc",
"start": "npm run validate-env && NODE_PATH=dist node -r dotenv/config dist/server.js",
"start": "npm run validate-env && NODE_PATH=dist node -r dotenv/config dist/.wasp/out/server/src/server.js",
sodic marked this conversation as resolved.
Show resolved Hide resolved
"build-and-start": "npm run build && npm run start",
"watch": "nodemon --exec 'npm run build-and-start || exit 1'",
"validate-env": "node -r dotenv/config ./scripts/validate-env.mjs",
Expand Down
16 changes: 13 additions & 3 deletions waspc/data/Generator/templates/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
// Overriding this until we implement more complete TypeScript support.
// Filip: begin client file hacks
// We need this to make server work with copied client files (we copy everything)
"jsx": "preserve",
"lib": [
"esnext",
"dom",
"DOM.Iterable"
],
// Filip: end client file hacks
sodic marked this conversation as resolved.
Show resolved Hide resolved
"strict": false,
// Overriding this because we want to use top-level await
"module": "esnext",
Expand All @@ -10,12 +19,13 @@
"sourceMap": true,
// The remaining settings should match node18/tsconfig.json, but I kept
// them here to be explicit.

// Enable default imports in TypeScript.
"esModuleInterop": true,
"moduleResolution": "node",
"outDir": "dist",
"allowJs": true
},
"include": ["src"]
}
"include": [
"src"
]
}
4 changes: 4 additions & 0 deletions waspc/examples/todo-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.wasp/
/.env.server
/.env.client
/node_modules/
1 change: 1 addition & 0 deletions waspc/examples/todo-typescript/.wasproot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File marking the root of Wasp project.
77 changes: 77 additions & 0 deletions waspc/examples/todo-typescript/main.wasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
app TodoTypescript {
wasp: {
version: "^0.11.0"
},
title: "ToDo TypeScript",

auth: {
userEntity: User,
methods: {
usernameAndPassword: {}, // this is a very naive implementation, use 'email' in production instead
//google: {}, //https://wasp-lang.dev/docs/integrations/google
//gitHub: {}, //https://wasp-lang.dev/docs/integrations/github
//email: {} //https://wasp-lang.dev/docs/guides/email-auth
},
onAuthFailedRedirectTo: "/login",
}
}

// Use Prisma Schema Language (PSL) to define our entities: https://www.prisma.io/docs/concepts/components/prisma-schema
// Run `wasp db migrate-dev` in the CLI to create the database tables
// Then run `wasp db studio` to open Prisma Studio and view your db models
entity User {=psl
id Int @id @default(autoincrement())
username String @unique
password String
tasks Task[]
psl=}

entity Task {=psl
id Int @id @default(autoincrement())
description String
isDone Boolean @default(false)
user User @relation(fields: [userId], references: [id])
userId Int
psl=}

route RootRoute { path: "/", to: MainPage }
page MainPage {
authRequired: true,
// todo(filip): LSP features are broken beucase I haven't yet updated LSP to the new structure.
component: import { MainPage } from "@src/MainPage.tsx"
}

route LoginRoute { path: "/login", to: LoginPage }
page LoginPage {
component: import { LoginPage } from "@src/user/LoginPage.tsx"
}

route SignupRoute { path: "/signup", to: SignupPage }
page SignupPage {
component: import { SignupPage } from "@src/user/SignupPage.tsx"
}

query getTasks {
// We specify the JS implementation of our query (which is an async JS function)
// Even if you use TS and have a queries.ts file, you will still need to import it using the .js extension.
// see here for more info: https://wasp-lang.dev/docs/tutorials/todo-app/03-listing-tasks#wasp-declaration
fn: import { getTasks } from "@src/task/queries.js",
// We tell Wasp that this query is doing something with the `Task` entity. With that, Wasp will
// automatically refresh the results of this query when tasks change.
entities: [Task]
}

action createTask {
fn: import { createTask } from "@src/task/actions.js",
entities: [Task]
}

action updateTask {
fn: import { updateTask } from "@src/task/actions.js",
entities: [Task]
}

action deleteTasks {
fn: import { deleteTasks } from "@src/task/actions.js",
entities: [Task],
}
6 changes: 6 additions & 0 deletions waspc/examples/todo-typescript/migrate
sodic marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rsync -a .wasp/out/web-app/node_modules/ node_modules/
rsync -a .wasp/out/server/node_modules/ node_modules/
# rsync -a node_modules_wasp/ node_modules
rw db migrate-dev
fd . '.wasp/out/server/node_modules' | grep -v prisma -i | xargs rm -r
rm -r .wasp/out/web-app/node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- CreateTable
CREATE TABLE "User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"username" TEXT NOT NULL,
"password" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "Task" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"description" TEXT NOT NULL,
"isDone" BOOLEAN NOT NULL DEFAULT false,
"userId" INTEGER,
CONSTRAINT "Task_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
3 changes: 3 additions & 0 deletions waspc/examples/todo-typescript/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
11 changes: 11 additions & 0 deletions waspc/examples/todo-typescript/node_modules/@wasp/api/events.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions waspc/examples/todo-typescript/node_modules/@wasp/api/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading