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

Bringing Prisma entities to the frontend #962

Merged
merged 63 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
4eb5fce
Support typing backend queries
sodic Jan 10, 2023
c418d43
Implement types for actions and extract entities
sodic Jan 12, 2023
b9f68e4
Merge remote-tracking branch 'origin/main' into filip-types-for-queri…
sodic Jan 19, 2023
2d45fb6
Add Prisma entities to the frontend
sodic Jan 20, 2023
3441e73
Add frontend types to internal todoApp
sodic Jan 20, 2023
7e9a8a4
Merge remote-tracking branch 'origin/main' into filip-frontend-entities
sodic Jan 30, 2023
994c64a
Undo moving for easier review
sodic Jan 30, 2023
807f58c
Revert back to generating a query.js file
sodic Jan 30, 2023
917299a
Rename buildEntityData
sodic Jan 30, 2023
693a9c3
Remove solved todo in schema template
sodic Feb 1, 2023
acdea9a
Fix docs in method
sodic Feb 1, 2023
8464fec
Adding uninstall command (#953)
infomiho Feb 1, 2023
adf2ac9
Use StrongPath instead of FilePath
sodic Feb 1, 2023
e7a3386
Fix review feedback
sodic Feb 1, 2023
b3a9c99
Merge remote-tracking branch 'origin/main' into filip-frontend-entities
sodic Feb 2, 2023
9fed4c9
Move prisma client generation messages
sodic Feb 2, 2023
3c0e9fd
Generalize FileDraft functions
sodic Feb 3, 2023
38c7b55
Generate prisma clients using ENV
sodic Feb 3, 2023
7714d56
Fix schema checksum check
sodic Feb 4, 2023
7b1b08b
Small refactor in db generator
sodic Feb 6, 2023
acc3e0f
Run prisma generate from server root dir
sodic Feb 6, 2023
46ca1a9
Fix types for useAction
sodic Feb 6, 2023
d714717
Fix type error for useAction
sodic Feb 7, 2023
7b17987
Fix schema generation in Dockerfile
sodic Feb 7, 2023
30fe6fc
Refactor passing env vars to prisma schema
sodic Feb 7, 2023
1ce7aae
Fix useAction types
sodic Feb 8, 2023
c75cd3c
Replace Prelude readFile with SP readFile
sodic Feb 8, 2023
fba3e46
Add comment for prisma/client in web app
sodic Feb 8, 2023
b51b631
Replace Prelude writeFile with SP writeFile
sodic Feb 8, 2023
5cba399
Replace do and if with ifM
sodic Feb 8, 2023
4ccbe72
Rename readProjectTelemetryFile
sodic Feb 8, 2023
7cc9541
Refactor readOrCreateUserSignatureFile
sodic Feb 8, 2023
43516f5
Remove redundant comment
sodic Feb 8, 2023
f6dc618
Fix typo in variable name
sodic Feb 8, 2023
f82922a
Simulate unions with a type class
sodic Feb 8, 2023
f49ecf8
Further improve strongpath types
sodic Feb 8, 2023
ccd3548
Generate prisma clients after migration
sodic Feb 10, 2023
d8750a8
Change ModuleRootDir to ComponentRootDir
sodic Feb 10, 2023
77ad8a7
Remove solved todo
sodic Feb 10, 2023
eff0595
Merge remote-tracking branch 'origin/main' into filip-frontend-entities
sodic Feb 10, 2023
c01f0af
Improve naming
sodic Feb 10, 2023
d817192
Remove redundant env variable
sodic Feb 10, 2023
1c73bf6
Improve formatting
sodic Feb 10, 2023
beaaabe
Merge remote-tracking branch 'origin/main' into filip-frontend-entities
sodic Feb 10, 2023
1435a70
Fix errors after merging
sodic Feb 10, 2023
5a3b4f8
Change local function name
sodic Feb 10, 2023
8b78054
Rename local function again
sodic Feb 10, 2023
533ef8a
Update changelog
sodic Feb 13, 2023
0b3eafb
Fix error type in useQuery
sodic Feb 13, 2023
c754861
Rename Component to AppComponent
sodic Feb 13, 2023
ddf6113
Refactor DbGenerator
sodic Feb 13, 2023
6f61e31
Explain Abs paths in SP helpers
sodic Feb 13, 2023
95a747b
Update e2e tests
sodic Feb 13, 2023
89a8e53
Fix formatting
sodic Feb 13, 2023
a70c86c
Change signature for doesFileExist
sodic Feb 13, 2023
8c74e6b
Change signature for SP functions
sodic Feb 13, 2023
2eb4c9d
Remove redundant do block
sodic Feb 13, 2023
c376d78
Fix formatting
sodic Feb 13, 2023
105f5c6
Reorder functions
sodic Feb 13, 2023
bddc967
Rename module to appComponent in functions
sodic Feb 13, 2023
5b089c3
Rename module to component in functions
sodic Feb 13, 2023
3fcdd53
Rename telemetry cache function
sodic Feb 13, 2023
5c92849
Fix formatting
sodic Feb 13, 2023
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
35 changes: 32 additions & 3 deletions waspc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,44 @@
### `wasp deploy` CLI command added
We have made it much easier to deploy your Wasp apps via a new CLI command, `wasp deploy`. 🚀 This release adds support for Fly.io, but we hope to add more hosting providers soon!

### Import Wasp entity types on the backend
You can now import and use the types of Wasp entities in your backend code:
### Import Wasp entity types (on frontend and backend)
You can now import and use the types of Wasp entities anywhere in your code.

Let's assume your Wasp file contains the following entity:
```c
entity Task {=psl
id Int @id @default(autoincrement())
description String
isDone Boolean @default(false)
user User @relation(fields: [userId], references: [id])
userId Int
psl=}
```
Here's how a file on your backend can use it:
```typescript
import { Task } from '@wasp/entities/Task'

const getTasks = (args, context): Task[] => {
const getTasks = (args, context) => {
const tasks: Task[] = // ...
// ...
}
```
And here's how a frontend component can use it:

```typescript
// ...
import { useQuery } from '@wasp/queries'
import getTasks from '@wasp/queries/getTasks.js'
import { Task } from '@wasp/entities'

type TaskPayload = Pick<Task, "id">

const Todo = (props: any) => {
// The variable 'task' will now have the type Task.
const { data: task } = useQuery<TaskPayload, Task>(getTask, { id: taskId })
// ...
}

```

### TypeScript support for Queries and Actions
Expand Down
7 changes: 4 additions & 3 deletions waspc/cli/src/Wasp/Cli/Command/CreateNewProject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Control.Monad.Except (throwError)
import Control.Monad.IO.Class (liftIO)
import Data.List (intercalate)
import Path.IO (copyDirRecur, doesDirExist)
import StrongPath (Abs, Dir, Path, Path', System, fromAbsFile, parseAbsDir, reldir, relfile, (</>))
import StrongPath (Abs, Dir, Path, Path', System, parseAbsDir, reldir, relfile, (</>))
import StrongPath.Path (toPathAbsDir)
import System.Directory (getCurrentDirectory)
import qualified System.FilePath as FP
Expand All @@ -18,6 +18,7 @@ import Wasp.Common (WaspProjectDir)
import qualified Wasp.Common as Common (WaspProjectDir)
import qualified Wasp.Data as Data
import Wasp.Util (indent, kebabToCamelCase)
import qualified Wasp.Util.IO as IOUtil
import qualified Wasp.Util.Terminal as Term
import qualified Wasp.Version as WV

Expand Down Expand Up @@ -85,9 +86,9 @@ initializeProjectFromSkeleton absWaspProjectDir = do
copyDirRecur (toPathAbsDir absSkeletonDir) (toPathAbsDir absWaspProjectDir)

writeMainWaspFile :: Path System Abs (Dir WaspProjectDir) -> ProjectInfo -> IO ()
writeMainWaspFile waspProjectDir (ProjectInfo projectName appName) = writeFile absMainWaspFile mainWaspFileContent
writeMainWaspFile waspProjectDir (ProjectInfo projectName appName) = IOUtil.writeFile absMainWaspFile mainWaspFileContent
where
absMainWaspFile = fromAbsFile $ waspProjectDir </> [relfile|main.wasp|]
absMainWaspFile = waspProjectDir </> [relfile|main.wasp|]
mainWaspFileContent =
unlines
[ "app %s {" `printf` appName,
Expand Down
45 changes: 26 additions & 19 deletions waspc/cli/src/Wasp/Cli/Command/Db/Migrate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ module Wasp.Cli.Command.Db.Migrate
)
where

import Control.Monad.Except (throwError)
import Control.Monad.Except (ExceptT (ExceptT), liftEither, runExceptT, throwError)
import Control.Monad.IO.Class (liftIO)
-- Wasp generator interface.

import StrongPath ((</>))
import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Cli.Command (Command, CommandError (..))
import Wasp.Cli.Command.Common
( findWaspProjectRootDirFromCwd,
)
import Wasp.Cli.Command.Message (cliSendMessageC)
import qualified Wasp.Cli.Common as Cli.Common
import Wasp.Common (DbMigrationsDir)
import qualified Wasp.Common
import Wasp.Generator.Common (ProjectRootDir)
import Wasp.Generator.DbGenerator.Common (MigrateArgs (..), defaultMigrateArgs)
import qualified Wasp.Generator.DbGenerator.Operations as DbOps
import qualified Wasp.Message as Msg
Expand All @@ -26,26 +26,33 @@ import qualified Wasp.Message as Msg
migrateDev :: [String] -> Command ()
migrateDev optionalMigrateArgs = do
waspProjectDir <- findWaspProjectRootDirFromCwd
let genProjectRootDir =
let waspDbMigrationsDir = waspProjectDir </> Wasp.Common.dbMigrationsDirInWaspProjectDir
let projectRootDir =
waspProjectDir
</> Cli.Common.dotWaspDirInWaspProjectDir
</> Cli.Common.generatedCodeDirInDotWaspDir

let waspDbMigrationsDir =
waspProjectDir
</> Wasp.Common.dbMigrationsDirInWaspProjectDir
migrateDatabase optionalMigrateArgs projectRootDir waspDbMigrationsDir
generatePrismaClients projectRootDir

migrateDatabase :: [String] -> Path' Abs (Dir ProjectRootDir) -> Path' Abs (Dir DbMigrationsDir) -> Command ()
migrateDatabase optionalMigrateArgs projectRootDir dbMigrationsDir = do
cliSendMessageC $ Msg.Start "Starting database migration..."
liftIO tryMigrate >>= \case
Left err -> throwError $ CommandError "Migrate dev failed" err
Right () -> cliSendMessageC $ Msg.Success "Database successfully migrated."
where
tryMigrate = runExceptT $ do
migrateArgs <- liftEither $ parseMigrateArgs optionalMigrateArgs
ExceptT $ DbOps.migrateDevAndCopyToSource dbMigrationsDir projectRootDir migrateArgs

let parsedMigrateArgs = parseMigrateArgs optionalMigrateArgs
case parsedMigrateArgs of
Left parseError ->
throwError $ CommandError "Migrate dev failed" parseError
Right migrateArgs -> do
cliSendMessageC $ Msg.Start "Performing migration..."
migrateResult <- liftIO $ DbOps.migrateDevAndCopyToSource waspDbMigrationsDir genProjectRootDir migrateArgs
case migrateResult of
Left migrateError ->
throwError $ CommandError "Migrate dev failed" migrateError
Right () -> cliSendMessageC $ Msg.Success "Migration done."
generatePrismaClients :: Path' Abs (Dir ProjectRootDir) -> Command ()
generatePrismaClients projectRootDir = do
cliSendMessageC $ Msg.Start "Generating prisma clients..."
generatePrismaClientsResult <- liftIO $ DbOps.generatePrismaClients projectRootDir
case generatePrismaClientsResult of
Left err -> throwError $ CommandError "Could not generate Prisma clients" err
Right () -> cliSendMessageC $ Msg.Success "Prisma clients successfully generated."

-- | Basic parsing of db-migrate args. In the future, we could use a smarter parser
-- for this (and all other CLI arg parsing).
Expand Down
33 changes: 18 additions & 15 deletions waspc/cli/src/Wasp/Cli/Command/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ where

import Control.Arrow
import Control.Monad.Except
import StrongPath (Abs, Dir, Path', fromAbsFile, fromRelFile, toFilePath)
import StrongPath (Abs, Dir, Path', fromRelFile)
import StrongPath.Operations
import System.Directory (doesFileExist, getFileSize)
import System.Directory (getFileSize)
import qualified Wasp.Analyzer as Analyzer
import qualified Wasp.AppSpec.App as AS.App
import qualified Wasp.AppSpec.Core.Decl as AS (Decl, takeDecls)
Expand All @@ -22,7 +22,8 @@ import Wasp.Common (WaspProjectDir)
import Wasp.Error (showCompilerErrorForTerminal)
import Wasp.Lib (findWaspFile)
import qualified Wasp.Message as Msg
import Wasp.Util.IO (listDirectoryDeep)
import Wasp.Util (ifM)
import qualified Wasp.Util.IO as IOUtil
import qualified Wasp.Util.Terminal as Term

info :: Command ()
Expand All @@ -48,24 +49,26 @@ printInfo :: String -> String -> String
printInfo key value = Term.applyStyles [Term.Cyan] key ++ ": " <> Term.applyStyles [Term.White] value

readDirectorySizeMB :: Path' Abs (Dir WaspProjectDir) -> IO String
readDirectorySizeMB path = (++ " MB") . show . (`div` 1000000) . sum <$> (listDirectoryDeep path >>= mapM (getFileSize . fromRelFile))
readDirectorySizeMB path = (++ " MB") . show . (`div` 1000000) . sum <$> allFileSizes
where
allFileSizes = IOUtil.listDirectoryDeep path >>= mapM (getFileSize . fromRelFile)

readCompileInformation :: Path' Abs (Dir WaspProjectDir) -> IO String
readCompileInformation waspDir = do
let dotWaspInfoFile =
fromAbsFile $
waspDir </> Cli.Common.dotWaspDirInWaspProjectDir
</> Cli.Common.generatedCodeDirInDotWaspDir
</> Cli.Common.dotWaspInfoFileInGeneratedCodeDir
dotWaspInfoFileExists <- doesFileExist dotWaspInfoFile
if dotWaspInfoFileExists
then do readFile dotWaspInfoFile
else return "No compile information found"
readCompileInformation waspDir =
ifM
(IOUtil.doesFileExist dotWaspInfoFile)
(IOUtil.readFile dotWaspInfoFile)
(return "No compile information found")
where
dotWaspInfoFile =
waspDir </> Cli.Common.dotWaspDirInWaspProjectDir
</> Cli.Common.generatedCodeDirInDotWaspDir
</> Cli.Common.dotWaspInfoFileInGeneratedCodeDir

parseWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String [AS.Decl])
parseWaspFile waspDir = runExceptT $ do
waspFile <- ExceptT $ findWaspFile waspDir
waspStr <- liftIO $ readFile $ toFilePath waspFile
waspStr <- liftIO $ IOUtil.readFile waspFile
liftEither $ left (annotateErrorForCli waspFile waspStr) $ Analyzer.analyze waspStr
where
annotateErrorForCli waspFile waspStr =
Expand Down
2 changes: 1 addition & 1 deletion waspc/cli/src/Wasp/Cli/Command/Telemetry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ telemetry = do

maybeProjectHash <- (Just <$> TlmProject.getWaspProjectPathHash) `catchError` const (return Nothing)
for_ maybeProjectHash $ \projectHash -> do
maybeProjectCache <- liftIO $ TlmProject.readProjectTelemetryFile telemetryCacheDirPath projectHash
maybeProjectCache <- liftIO $ TlmProject.readProjectTelemetryCache telemetryCacheDirPath projectHash
for_ maybeProjectCache $ \projectCache -> do
let maybeTimeOfLastSending = TlmProject.getTimeOfLastTelemetryDataSent projectCache
for_ maybeTimeOfLastSending $ \timeOfLastSending -> do
Expand Down
25 changes: 14 additions & 11 deletions waspc/cli/src/Wasp/Cli/Command/Telemetry/Project.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Wasp.Cli.Command.Telemetry.Project
( getWaspProjectPathHash,
considerSendingData,
readProjectTelemetryFile,
readProjectTelemetryCache,
getTimeOfLastTelemetryDataSent,
-- NOTE: for testing only
checkIfEnvValueIsTruthy,
Expand All @@ -27,14 +27,15 @@ import qualified Network.HTTP.Simple as HTTP
import Paths_waspc (version)
import StrongPath (Abs, Dir, File', Path')
import qualified StrongPath as SP
import qualified System.Directory as SD
import qualified System.Environment as ENV
import qualified System.Info
import Wasp.Cli.Command (Command)
import qualified Wasp.Cli.Command.Call as Command.Call
import Wasp.Cli.Command.Common (findWaspProjectRootDirFromCwd)
import Wasp.Cli.Command.Telemetry.Common (TelemetryCacheDir)
import Wasp.Cli.Command.Telemetry.User (UserSignature (..))
import Wasp.Util (ifM)
import qualified Wasp.Util.IO as IOUtil

considerSendingData :: Path' Abs (Dir TelemetryCacheDir) -> UserSignature -> ProjectHash -> Command.Call.Call -> IO ()
considerSendingData telemetryCacheDirPath userSignature projectHash cmdCall = do
Expand Down Expand Up @@ -125,26 +126,28 @@ initialCache = ProjectTelemetryCache {_lastCheckIn = Nothing, _lastCheckInBuild
getTimeOfLastTelemetryDataSent :: ProjectTelemetryCache -> Maybe T.UTCTime
getTimeOfLastTelemetryDataSent cache = maximum [_lastCheckIn cache, _lastCheckInBuild cache]

readProjectTelemetryFile :: Path' Abs (Dir TelemetryCacheDir) -> ProjectHash -> IO (Maybe ProjectTelemetryCache)
readProjectTelemetryFile telemetryCacheDirPath projectHash = do
fileExists <- SD.doesFileExist filePathFP
if fileExists then readCacheFile else return Nothing
readProjectTelemetryCache :: Path' Abs (Dir TelemetryCacheDir) -> ProjectHash -> IO (Maybe ProjectTelemetryCache)
Copy link
Member

Choose a reason for hiding this comment

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

Nit.: I think the point of having File in the name was to indicate this function reads a file, which is now not evident any more. Maybe it is not important though. But I would consider leaving it. So you could just add File at the end. But ok, if you like this better that is also ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can change it back.

readProjectTelemetryCache telemetryCacheDirPath projectHash =
ifM
(IOUtil.doesFileExist projectTelemetryFile)
parseProjectTelemetryFile
(return Nothing)
where
filePathFP = SP.fromAbsFile $ getProjectTelemetryFilePath telemetryCacheDirPath projectHash
readCacheFile = Aeson.decode . ByteStringLazyUTF8.fromString <$> readFile filePathFP
projectTelemetryFile = getProjectTelemetryFilePath telemetryCacheDirPath projectHash
parseProjectTelemetryFile = Aeson.decode . ByteStringLazyUTF8.fromString <$> IOUtil.readFile projectTelemetryFile

readOrCreateProjectTelemetryFile :: Path' Abs (Dir TelemetryCacheDir) -> ProjectHash -> IO ProjectTelemetryCache
readOrCreateProjectTelemetryFile telemetryCacheDirPath projectHash = do
maybeProjectTelemetryCache <- readProjectTelemetryFile telemetryCacheDirPath projectHash
maybeProjectTelemetryCache <- readProjectTelemetryCache telemetryCacheDirPath projectHash
case maybeProjectTelemetryCache of
Just cache -> return cache
Nothing -> writeProjectTelemetryFile telemetryCacheDirPath projectHash initialCache >> return initialCache

writeProjectTelemetryFile :: Path' Abs (Dir TelemetryCacheDir) -> ProjectHash -> ProjectTelemetryCache -> IO ()
writeProjectTelemetryFile telemetryCacheDirPath projectHash cache = do
writeFile filePathFP (ByteStringLazyUTF8.toString $ Aeson.encode cache)
IOUtil.writeFile projectTelemetryFile (ByteStringLazyUTF8.toString $ Aeson.encode cache)
where
filePathFP = SP.fromAbsFile $ getProjectTelemetryFilePath telemetryCacheDirPath projectHash
projectTelemetryFile = getProjectTelemetryFilePath telemetryCacheDirPath projectHash

getProjectTelemetryFilePath :: Path' Abs (Dir TelemetryCacheDir) -> ProjectHash -> Path' Abs File'
getProjectTelemetryFilePath telemetryCacheDir (ProjectHash projectHash) =
Expand Down
25 changes: 13 additions & 12 deletions waspc/cli/src/Wasp/Cli/Command/Telemetry/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ where
import qualified Data.UUID.V4 as UUID
import StrongPath (Abs, Dir, File', Path', relfile)
import qualified StrongPath as SP
import qualified System.Directory as SD
import qualified System.Environment as ENV
import Wasp.Cli.Command.Telemetry.Common (TelemetryCacheDir)
import Wasp.Util (checksumFromString, hexToString, orIfNothingM)
import Wasp.Util (checksumFromString, hexToString, ifM, orIfNothingM)
import qualified Wasp.Util.IO as IOUtil

-- Random, non-identifyable UUID used to represent user in analytics.
newtype UserSignature = UserSignature {_userSignatureValue :: String} deriving (Show)
Expand All @@ -22,17 +22,18 @@ obtainUserSignature telemetryCacheDirPath =
getUserSignatureFromEnv `orIfNothingM` readOrCreateUserSignatureFile telemetryCacheDirPath

readOrCreateUserSignatureFile :: Path' Abs (Dir TelemetryCacheDir) -> IO UserSignature
readOrCreateUserSignatureFile telemetryCacheDirPath = do
let filePath = getUserSignatureFilePath telemetryCacheDirPath
let filePathFP = SP.fromAbsFile filePath
fileExists <- SD.doesFileExist filePathFP
readOrCreateUserSignatureFile telemetryCacheDirPath =
UserSignature
<$> if fileExists
then readFile filePathFP
else do
userSignature <- show <$> UUID.nextRandom
writeFile filePathFP userSignature
return userSignature
<$> ifM
(IOUtil.doesFileExist userSignatureFile)
(IOUtil.readFile userSignatureFile)
createUserSignatureFile
where
userSignatureFile = getUserSignatureFilePath telemetryCacheDirPath
createUserSignatureFile = do
userSignature <- show <$> UUID.nextRandom
IOUtil.writeFile userSignatureFile userSignature
return userSignature

getUserSignatureFilePath :: Path' Abs (Dir TelemetryCacheDir) -> Path' Abs File'
getUserSignatureFilePath telemetryCacheDir = telemetryCacheDir SP.</> [relfile|signature|]
Expand Down
2 changes: 1 addition & 1 deletion waspc/data/Generator/templates/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ COPY server/package*.json ./server/
RUN cd server && npm install
{=# usingPrisma =}
COPY db/schema.prisma ./db/
RUN cd server && npx prisma generate --schema=../db/schema.prisma
RUN cd server && {= serverPrismaClientOutputDirEnv =} npx prisma generate --schema='{= dbSchemaFileFromServerDir =}'
{=/ usingPrisma =}


Expand Down
3 changes: 1 addition & 2 deletions waspc/data/Generator/templates/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ datasource db {

generator client {
sodic marked this conversation as resolved.
Show resolved Hide resolved
provider = "prisma-client-js"
{=! TODO(matija): this shouldn't be hardcoded, generator should provide this path. =}
output = "../server/node_modules/.prisma/client"
output = {=& prismaClientOutputDir =}
}

{=# modelSchemas =}
Expand Down
10 changes: 5 additions & 5 deletions waspc/data/Generator/templates/react-app/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export type Action<Input, Output> = (args?: Input) => Promise<Output>;
* action with extra options.
*
*/
export type ActionOptions<ActionInput, CachedData> = {
optimisticUpdates: OptimisticUpdateDefinition<ActionInput, CachedData>[]
export type ActionOptions<ActionInput> = {
optimisticUpdates: OptimisticUpdateDefinition<ActionInput, any>[]
}

/**
* A documented (public) way to define optimistic updates.
*/
export type OptimisticUpdateDefinition<ActionInput, CachedData = unknown> = {
export type OptimisticUpdateDefinition<ActionInput, CachedData> = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file contains unrelated fixes for a bug that came to light when I introduced the entities to the frontend.

getQuerySpecifier: GetQuerySpecifier<ActionInput, CachedData>
updateQuery: UpdateQuery<ActionInput, CachedData>
}
Expand Down Expand Up @@ -50,9 +50,9 @@ export type QuerySpecifier<Input, Output> = [Query<Input, Output>, ...any[]]
* @param actionOptions An options object for enhancing/decorating the given Action.
* @returns A decorated Action with added behavior but an unchanged API.
*/
export function useAction<Input = unknown, Output = unknown, CachedData = unknown>(
export function useAction<Input = unknown, Output = unknown>(
actionFn: Action<Input, Output>,
actionOptions?: ActionOptions<Input, CachedData>
actionOptions?: ActionOptions<Input>
): typeof actionFn {
const queryClient = useQueryClient();

Expand Down
18 changes: 18 additions & 0 deletions waspc/data/Generator/templates/react-app/src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{={= =}=}}
sodic marked this conversation as resolved.
Show resolved Hide resolved
shayneczyzewski marked this conversation as resolved.
Show resolved Hide resolved
import {
{=# entities =}
{= name =},
{=/ entities =}
} from '@prisma/client'

export type {
{=# entities =}
{= name =},
{=/ entities =}
} from '@prisma/client'

export type WaspEntity =
{=# entities =}
| {= name =}
{=/ entities =}
| never
Loading