When considering the DSL’s design, I’ll assume we went with the Treating main.wasp.ts
as a program approach described in:
[RFC] Processing the TypeScript DSL
This RFC explores translating all Wasp DSL features into TypeScript without doing anything fancy (i.e., without interfacing the config file with the application code).
Each team member had their ideas about how the TS DSL should look like. You can find all of them here:
I’ll use an example Wasp file to explore the new syntax. I won’t consider entities since we will soon define them in a separate schema.prisma
file.
main.wasp
fileHere’s the original main.wasp
file I will translate into its equivalent TS DSL form.
The file is just complex enough to cover almost all relevant Wasp constructs.
app todoApp {
wasp: {
version: "^0.14.0"
},
title: "ToDo App",
webSocket: {
fn: import { webSocketFn } from "@src/webSocket",
autoConnect: false
},
auth: {
userEntity: User,
methods: {
google: {
configFn: import { config } from "@src/auth/google",
userSignupFields: import { userSignupFields } from "@src/auth/google"
},
email: {
userSignupFields: import { userSignupFields } from "@src/auth/email",
fromField: {
name: "ToDO App",
email: "[email protected]"
},
},
},
onAuthFailedRedirectTo: "/login",
onAuthSucceededRedirectTo: "/profile"
},
server: {
setupFn: import setup from "@src/serverSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup",
},
client: {
rootComponent: import { App } from "@src/App",
setupFn: import setup from "@src/clientSetup"
},
db: {
system: PostgreSQL,
seeds: [
import { devSeedSimple } from "@src/dbSeeds",
import { prodSeed } from "@src/dbSeeds"
]
},
emailSender: {
provider: SMTP,
defaultFrom: {
email: "[email protected]"
},
},
}
route ProfileRoute { path: "/profile", to: ProfilePage }
page ProfilePage {
component: import { Profile } from "@src/pages/Profile",
}
query getTasks {
fn: import { getTasks } from "@src/queries",
entities: [Task],
auth: true
}
action createTask {
fn: import { createTask } from "@src/actions",
entities: [Task],
auth: true
}
job mySpecialScheduledJob {
executor: PgBoss,
perform: {
fn: import { foo } from "@src/jobs/bar"
},
schedule: {
cron: "0 * * * *",
args: {=json { "foo": "bar" } json=},
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
}
}
api fooBar {
fn: import { fooBar } from "@src/apis",
middlewareConfigFn: import { fooBarMiddlewareFn } from "@src/apis",
entities: [Task],
httpRoute: (ALL, "/foo/bar")
}
apiNamespace bar {
middlewareConfigFn: import { barNamespaceMiddlewareFn } from "@src/apis",
path: "/bar"
}
main.wasp.ts
fileHere’s how we might define the same file in the new TypeScript SDK. This is a rough draft, so don’t hesitate to make suggestions.