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

Using TS SDK from waspc #2276

Merged
merged 41 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e228263
Successfully get spec from stdout
sodic Sep 6, 2024
664eafe
Successfully read spec from file
sodic Sep 6, 2024
1b75ab9
Clean up code in Analyze.hs
sodic Sep 10, 2024
0c7b901
Move outDir source of truth into Haskell
sodic Sep 10, 2024
b7c4800
Add extra context to Analyze.hs
sodic Sep 11, 2024
68bfe30
Improve TS SDK analysis
sodic Sep 11, 2024
0758747
Put config dir back in .wasp dir
sodic Sep 11, 2024
b7ecab4
Add more comments
sodic Sep 12, 2024
e2e802e
Update Analyze.hs
sodic Sep 18, 2024
2d27900
Merge branch 'main' into filip-ts-sdk
sodic Sep 25, 2024
987243d
Remove todo for duplication
sodic Sep 25, 2024
15e3e68
Remove the duplication in templating
sodic Sep 25, 2024
7600288
Rearrange analyze.hs
sodic Sep 25, 2024
2b0c0ff
Remove todo after adding it to GitHub
sodic Sep 25, 2024
7ec9356
Remove one more todo
sodic Sep 25, 2024
1597f4b
Remove todo after adding it to GitHub
sodic Sep 25, 2024
b887cd8
Resolve some more todos
sodic Sep 25, 2024
1bdc871
Remove another todo
sodic Sep 25, 2024
52378c4
Send prisma models to JS runtime
sodic Sep 26, 2024
115dce5
Merge branch 'main' into filip-ts-sdk
sodic Sep 26, 2024
2617b6f
Properly parse decls.json
sodic Sep 26, 2024
32275e5
Improve error messages
sodic Sep 26, 2024
b673308
Merge branch 'main' into filip-ts-sdk
sodic Sep 30, 2024
3513b68
Fix ext import parsing and inject entities
sodic Oct 5, 2024
e9ef283
Fail if you find both wasp files
sodic Oct 7, 2024
0dc7435
Change tsconfig file name
sodic Oct 7, 2024
3e9efc8
Clean up imports
sodic Oct 7, 2024
24f65ec
Fix some more imports
sodic Oct 7, 2024
edd7a85
Change type name
sodic Oct 7, 2024
ae76820
Implement review changes
sodic Oct 7, 2024
7eab0bc
Fix failing tests
sodic Oct 7, 2024
8c8cb4f
Remove duplication when parsing ext imports
sodic Oct 7, 2024
d0ba9e5
Remove redundant variable
sodic Oct 7, 2024
4eec3c1
Remove trailling space
sodic Oct 7, 2024
1699df2
Revert Show instance for Decl
sodic Oct 7, 2024
5a6719e
Add module to package.json and remove mts
sodic Oct 8, 2024
3f48b98
Merge branch 'main' into filip-ts-sdk
sodic Oct 8, 2024
67f1f9e
Differentiate between different tsconfigs
sodic Oct 9, 2024
522e131
Fix tsconfig stuff
sodic Oct 9, 2024
8ab0b3f
Update e2e tests
sodic Oct 9, 2024
d90b235
Rename tsconfig constants and refactor
sodic Oct 9, 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
2 changes: 1 addition & 1 deletion waspc/cli/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ main = withUtf8 . (`E.catch` handleInternalErrors) $ do

handleInternalErrors :: E.ErrorCall -> IO ()
handleInternalErrors e = do
putStrLn $ "\nInternal Wasp error (bug in compiler):\n" ++ indent 2 (show e)
putStrLn $ "\nInternal Wasp error (bug in the compiler):\n" ++ indent 2 (show e)
exitFailure

-- | Sets env variables that are visible to the commands run by the CLI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import qualified Data.Text as T
import StrongPath (Abs, Dir, File, Path')
import Wasp.Cli.Command.CreateNewProject.Common (defaultWaspVersionBounds)
import Wasp.Cli.Command.CreateNewProject.ProjectDescription (NewProjectAppName, NewProjectName)
import Wasp.Project.Analyze (findPackageJsonFile, findWaspFile)
import Wasp.Project.Analyze (WaspFile (..), findPackageJsonFile, findWaspFile)
import Wasp.Project.Common (WaspProjectDir)
import qualified Wasp.Util.IO as IOUtil

Expand All @@ -26,7 +26,10 @@ replaceTemplatePlaceholdersInWaspFile ::
replaceTemplatePlaceholdersInWaspFile appName projectName projectDir =
findWaspFile projectDir >>= \case
Nothing -> return ()
Just absMainWaspFile -> replaceTemplatePlaceholdersInFileOnDisk appName projectName absMainWaspFile
Just (WaspLang absMainWaspFile) -> replaceTemplatePlaceholders absMainWaspFile
Just (WaspTs absMainTsFile) -> replaceTemplatePlaceholders absMainTsFile
where
replaceTemplatePlaceholders = replaceTemplatePlaceholdersInFileOnDisk appName projectName

-- | Template file for package.json file has placeholders in it that we want to replace
-- in the package.json file we have written to the disk.
Expand Down
5 changes: 3 additions & 2 deletions waspc/src/Wasp/Error.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Wasp.Error (showCompilerErrorForTerminal) where

import Data.List (intercalate)
import StrongPath (Abs, File', Path')
import StrongPath (Abs, Path')
import qualified StrongPath as SP
import StrongPath.Types (File)
import Wasp.Analyzer.Parser.Ctx (Ctx, getCtxRgn)
import Wasp.Analyzer.Parser.SourcePosition (SourcePosition (..))
import Wasp.Analyzer.Parser.SourceRegion (SourceRegion (..))
Expand All @@ -12,7 +13,7 @@ import qualified Wasp.Util.Terminal as T
-- | Transforms compiler error (error with parse context) into an informative, pretty String that
-- can be printed directly into the terminal. It uses terminal features like escape codes
-- (colors, styling, ...).
showCompilerErrorForTerminal :: (Path' Abs File', String) -> (String, Ctx) -> String
showCompilerErrorForTerminal :: (Path' Abs (File f), String) -> (String, Ctx) -> String
Copy link
Member

Choose a reason for hiding this comment

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

We don't have something like data WaspFile, so that we could do Path' Abs (File WaspFile)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. We didn't before, but we'll have it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take care of this later. It requires dealing with cyclic dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved in #2407

showCompilerErrorForTerminal (waspFilePath, waspFileContent) (errMsg, errCtx) =
let srcRegion = getCtxRgn errCtx
in intercalate
Expand Down
135 changes: 124 additions & 11 deletions waspc/src/Wasp/Project/Analyze.hs
Copy link
Member

Choose a reason for hiding this comment

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

This file has a lot of diverse imports, indicating that it might want to be split into multiple files. I think we should split it probably -> we could certainly separate the logic that deals with WaspFile, and maybe then further split that into WaspLang and WaspTs logic, but not yet sure about that.

Copy link
Contributor Author

@sodic sodic Sep 30, 2024

Choose a reason for hiding this comment

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

I thought about extracting a Project.WaspFile module but wasn't sure if it's necessary (thought I mentioned it in a comment somewhere, but looks like I didn't).

But yeah, if you like it too, I'll do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving this one for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in #2407

Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
module Wasp.Project.Analyze
( analyzeWaspProject,
readPackageJsonFile,
analyzeWaspFileContent,
findWaspFile,
findPackageJsonFile,
analyzePrismaSchema,
WaspFile (..),
)
where

import Control.Applicative ((<|>))
import Control.Arrow (ArrowChoice (left))
import Control.Concurrent (newChan)
import Control.Concurrent.Async (concurrently)
import Control.Monad.Except (ExceptT (..), runExceptT)
import qualified Data.Aeson as Aeson
import Data.Conduit.Process.Typed (ExitCode (..))
import Data.List (find, isSuffixOf)
import StrongPath (Abs, Dir, File', Path', toFilePath, (</>))
import StrongPath (Abs, Dir, File', Path', Rel, basename, toFilePath, (</>))
import qualified StrongPath as SP
import StrongPath.TH (relfile)
import StrongPath.Types (File)
sodic marked this conversation as resolved.
Show resolved Hide resolved
import qualified Wasp.Analyzer as Analyzer
import Wasp.Analyzer.AnalyzeError (getErrorMessageAndCtx)
import Wasp.Analyzer.Parser.Ctx (Ctx)
import qualified Wasp.AppSpec as AS
import Wasp.AppSpec.Core.Decl.JSON ()
import Wasp.AppSpec.PackageJson (PackageJson)
import qualified Wasp.AppSpec.Valid as ASV
import Wasp.CompileOptions (CompileOptions)
import qualified Wasp.CompileOptions as CompileOptions
import qualified Wasp.ConfigFile as CF
import Wasp.Error (showCompilerErrorForTerminal)
import qualified Wasp.Generator.ConfigFile as G.CF
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
Comment on lines +43 to +45
Copy link
Member

Choose a reason for hiding this comment

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

If this is used here, then it sounds like it maybe shouldn't be in the Generator hm. What do you think? I didn't check the code though to see if there is anything Generator specific about it really or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, nice catch. I didn't notice it was there.

And there's nothing generator-specific about it. I think it's just there because the generator used to be the only one running jobs. I'll move it somewhere more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving this one for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in #2407

import Wasp.Project.Common
( CompileError,
CompileWarning,
WaspProjectDir,
dotWaspDirInWaspProjectDir,
findFileInWaspProjectDir,
packageJsonInWaspProjectDir,
prismaSchemaFileInWaspProjectDir,
Expand All @@ -42,7 +55,9 @@ import qualified Wasp.Psl.Parser.Schema as Psl.Parser
import Wasp.Psl.Valid (getValidDbSystemFromPrismaSchema)
import qualified Wasp.Psl.Valid as PslV
import Wasp.Util (maybeToEither)
import Wasp.Util.Aeson (encodeToString)
import qualified Wasp.Util.IO as IOUtil
import Wasp.Util.StrongPath (replaceRelExtension)
import Wasp.Valid (ValidationError)
import qualified Wasp.Valid as Valid

Expand All @@ -60,7 +75,7 @@ analyzeWaspProject waspDir options = do
(Left prismaSchemaErrors, prismaSchemaWarnings) -> return (Left prismaSchemaErrors, prismaSchemaWarnings)
-- NOTE: we are ignoring prismaSchemaWarnings if the schema was parsed successfully
(Right prismaSchemaAst, _) ->
analyzeWaspFile prismaSchemaAst waspFilePath >>= \case
analyzeWaspFile waspDir prismaSchemaAst waspFilePath >>= \case
Copy link
Contributor

Choose a reason for hiding this comment

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

waspFilePath -> waspFile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I prefer keeping the Path. I think it's our general convention too.

Left errors -> return (Left errors, [])
Right declarations ->
analyzePackageJsonContent waspDir >>= \case
Expand All @@ -69,8 +84,107 @@ analyzeWaspProject waspDir options = do
where
fileNotFoundMessage = "Couldn't find the *.wasp file in the " ++ toFilePath waspDir ++ " directory"

analyzeWaspFile :: Psl.Schema.Schema -> Path' Abs File' -> IO (Either [CompileError] [AS.Decl])
analyzeWaspFile prismaSchemaAst waspFilePath = do
data WaspFile
sodic marked this conversation as resolved.
Show resolved Hide resolved
= WaspLang !(Path' Abs (File WaspLangFile))
| WaspTs !(Path' Abs (File WaspTsFile))

data WaspLangFile

data WaspTsFile
sodic marked this conversation as resolved.
Show resolved Hide resolved

data CompiledWaspJsFile

data DeclsJsonFile
sodic marked this conversation as resolved.
Show resolved Hide resolved

analyzeWaspFile :: Path' Abs (Dir WaspProjectDir) -> Psl.Schema.Schema -> WaspFile -> IO (Either [CompileError] [AS.Decl])
analyzeWaspFile waspDir prismaSchemaAst = \case
WaspLang waspFilePath -> analyzeWaspLangFile prismaSchemaAst waspFilePath
WaspTs waspFilePath -> analyzeWaspTsFile waspDir prismaSchemaAst waspFilePath

analyzeWaspTsFile :: Path' Abs (Dir WaspProjectDir) -> Psl.Schema.Schema -> Path' Abs (File WaspTsFile) -> IO (Either [CompileError] [AS.Decl])
analyzeWaspTsFile waspProjectDir prismaSchemaAst waspFilePath = runExceptT $ do
-- TODO: I'm not yet sure where tsconfig.node.json location should come from
-- because we also need that knowledge when generating a TS SDK project.
sodic marked this conversation as resolved.
Show resolved Hide resolved
compiledWaspJsFile <- ExceptT $ compileWaspTsFile waspProjectDir [relfile|tsconfig.node.json|] waspFilePath
sodic marked this conversation as resolved.
Show resolved Hide resolved
declsJsonFile <- ExceptT $ executeMainWaspJsFile waspProjectDir prismaSchemaAst compiledWaspJsFile
ExceptT $ readDeclsFromJsonFile declsJsonFile

compileWaspTsFile ::
Path' Abs (Dir WaspProjectDir) ->
Path' (Rel WaspProjectDir) File' ->
Path' Abs (File WaspTsFile) ->
IO (Either [CompileError] (Path' Abs (File CompiledWaspJsFile)))
sodic marked this conversation as resolved.
Show resolved Hide resolved
compileWaspTsFile waspProjectDir tsconfigNodeFileInWaspProjectDir waspFilePath = do
chan <- newChan
(_, tscExitCode) <-
concurrently
(readJobMessagesAndPrintThemPrefixed chan)
( runNodeCommandAsJob
sodic marked this conversation as resolved.
Show resolved Hide resolved
sodic marked this conversation as resolved.
Show resolved Hide resolved
waspProjectDir
"npx"
[ "tsc",
"-p",
toFilePath (waspProjectDir </> tsconfigNodeFileInWaspProjectDir),
sodic marked this conversation as resolved.
Show resolved Hide resolved
"--noEmit",
"false",
"--outDir",
toFilePath outDir
sodic marked this conversation as resolved.
Show resolved Hide resolved
]
sodic marked this conversation as resolved.
Show resolved Hide resolved
J.Wasp
chan
)
case tscExitCode of
ExitFailure _status -> return $ Left ["Got TypeScript compiler errors for " ++ toFilePath waspFilePath ++ "."]
ExitSuccess -> return $ Right absCompiledWaspJsFile
where
outDir = waspProjectDir </> dotWaspDirInWaspProjectDir
absCompiledWaspJsFile = outDir </> compiledWaspJsFileInDotWaspDir
compiledWaspJsFileInDotWaspDir = SP.castFile $ case replaceRelExtension (basename waspFilePath) ".mjs" of
sodic marked this conversation as resolved.
Show resolved Hide resolved
Just path -> path
Nothing -> error $ "Couldn't calculate the compiled JS file path for " ++ toFilePath waspFilePath ++ "."

executeMainWaspJsFile ::
Copy link
Member

Choose a reason for hiding this comment

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

This is quite specific for Wasp TS story, so I think it would make sense to have a WaspTsFile module and have this in that module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I probably wouldn't go for the WaspTsFile module (too granular for now IMO), but I'm all for the WaspFile module.

I'll extract that one, and if you still want the WaspTsFile, we can do that too.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let' see what happens when you extract it, we will see if it makes sense to go further or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving this for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted in #2407

sodic marked this conversation as resolved.
Show resolved Hide resolved
Path' Abs (Dir WaspProjectDir) ->
Psl.Schema.Schema ->
Path' Abs (File CompiledWaspJsFile) ->
IO (Either [CompileError] (Path' Abs (File DeclsJsonFile)))
executeMainWaspJsFile waspProjectDir prismaSchemaAst absCompiledMainWaspJsFile = do
chan <- newChan
(_, runExitCode) <- do
concurrently
(readJobMessagesAndPrintThemPrefixed chan)
( runNodeCommandAsJob
waspProjectDir
"npx"
-- TODO: Figure out how to keep running instructions in a single
-- place (e.g., this is string the same as the package name, but it's
-- repeated in two places).
-- Before this, I had the entrypoint file hardcoded, which was bad
-- too: waspProjectDir </> [relfile|node_modules/wasp-config/dist/run.js|]
sodic marked this conversation as resolved.
Show resolved Hide resolved
[ "wasp-config",
SP.fromAbsFile absCompiledMainWaspJsFile,
sodic marked this conversation as resolved.
Show resolved Hide resolved
SP.fromAbsFile absDeclsOutputFile,
encodeToString allowedEntityNames
sodic marked this conversation as resolved.
Show resolved Hide resolved
]
J.Wasp
chan
)
case runExitCode of
ExitFailure _status -> return $ Left ["Error while running the compiled *.wasp.mts file."]
ExitSuccess -> return $ Right absDeclsOutputFile
sodic marked this conversation as resolved.
Show resolved Hide resolved
where
absDeclsOutputFile = waspProjectDir </> dotWaspDirInWaspProjectDir </> [relfile|decls.json|]
allowedEntityNames = Psl.Schema.getModelNames prismaSchemaAst

readDeclsFromJsonFile :: Path' Abs (File DeclsJsonFile) -> IO (Either [CompileError] [AS.Decl])
readDeclsFromJsonFile declsJsonFile = do
declsBytestring <- IOUtil.readFileBytes declsJsonFile
case Aeson.eitherDecode declsBytestring of
Right value -> return $ Right value
Left err -> return $ Left ["Error while parsing the declarations from JSON: " ++ err]
sodic marked this conversation as resolved.
Show resolved Hide resolved

analyzeWaspLangFile :: Psl.Schema.Schema -> Path' Abs (File WaspLangFile) -> IO (Either [CompileError] [AS.Decl])
analyzeWaspLangFile prismaSchemaAst waspFilePath = do
waspFileContent <- IOUtil.readFile waspFilePath
left (map $ showCompilerErrorForTerminal (waspFilePath, waspFileContent))
<$> analyzeWaspFileContent prismaSchemaAst waspFileContent
Expand Down Expand Up @@ -118,15 +232,14 @@ constructAppSpec waspDir options packageJson parsedPrismaSchema decls = do

return $ runValidation ASV.validateAppSpec appSpec

findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe (Path' Abs File'))
findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe WaspFile)
findWaspFile waspDir = do
files <- fst <$> IOUtil.listDirectory waspDir
return $ (waspDir </>) <$> find isWaspFile files
return $ findWaspTsFile files <|> findWaspLangFile files
sodic marked this conversation as resolved.
Show resolved Hide resolved
where
isWaspFile path =
".wasp"
`isSuffixOf` toFilePath path
&& (length (toFilePath path) > length (".wasp" :: String))
findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.mts" files
sodic marked this conversation as resolved.
Show resolved Hide resolved
findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files
findFileThatEndsWith suffix files = SP.castFile . (waspDir </>) <$> find ((suffix `isSuffixOf`) . toFilePath) files
infomiho marked this conversation as resolved.
Show resolved Hide resolved

analyzePackageJsonContent :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] PackageJson)
analyzePackageJsonContent waspProjectDir =
Expand Down
5 changes: 3 additions & 2 deletions waspc/src/Wasp/Project/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Wasp.Project.Common
where

import StrongPath (Abs, Dir, File', Path', Rel, reldir, relfile, toFilePath, (</>))
import StrongPath.Types (File)
import System.Directory (doesFileExist)
import Wasp.AppSpec.ExternalFiles (SourceExternalCodeDir, SourceExternalPublicDir)
import qualified Wasp.Generator.Common
Expand Down Expand Up @@ -86,8 +87,8 @@ tsconfigInWaspProjectDir = [relfile|tsconfig.json|]

findFileInWaspProjectDir ::
Path' Abs (Dir WaspProjectDir) ->
Path' (Rel WaspProjectDir) File' ->
IO (Maybe (Path' Abs File'))
Path' (Rel WaspProjectDir) (File f) ->
Martinsos marked this conversation as resolved.
Show resolved Hide resolved
IO (Maybe (Path' Abs (File f)))
findFileInWaspProjectDir waspDir file = do
let fileAbsFp = waspDir </> file
fileExists <- doesFileExist $ toFilePath fileAbsFp
Expand Down
6 changes: 3 additions & 3 deletions waspc/src/Wasp/Psl/Ast/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Wasp.Psl.Ast.Model
Field (..),
FieldType (..),
FieldTypeModifier (..),
getFields,
getName,
)
where

Expand Down Expand Up @@ -60,5 +60,5 @@ data FieldTypeModifier
| Optional
deriving (Show, Eq, Data)

getFields :: Model -> [Field]
infomiho marked this conversation as resolved.
Show resolved Hide resolved
getFields (Model _ (Body elements)) = [field | ElementField field <- elements]
getName :: Model -> Name
getName (Model name _) = name
5 changes: 5 additions & 0 deletions waspc/src/Wasp/Psl/Ast/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ module Wasp.Psl.Ast.Schema
getEnums,
getDatasources,
getGenerators,
getModelNames,
)
where

import Wasp.Psl.Ast.ConfigBlock (ConfigBlock)
import qualified Wasp.Psl.Ast.ConfigBlock as Psl.ConfigBlock
import Wasp.Psl.Ast.Enum (Enum)
import Wasp.Psl.Ast.Model (Model)
import qualified Wasp.Psl.Ast.Model as Model
import Wasp.Psl.Ast.Type (Type)
import Wasp.Psl.Ast.View (View)
import Prelude hiding (Enum)
Expand Down Expand Up @@ -49,3 +51,6 @@ getGenerators schema = [generator | generator@((Psl.ConfigBlock.ConfigBlock Psl.

getConfigBlocks :: Schema -> [ConfigBlock]
getConfigBlocks (Schema blocks) = [configBlock | ConfigBlock configBlock <- blocks]

getModelNames :: Schema -> [String]
getModelNames schema = map Model.getName $ getModels schema
sodic marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion waspc/src/Wasp/Util/Aeson.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module Wasp.Util.Aeson
( encodeToText,
decodeFromString,
encodeToString,
)
where

import Data.Aeson (FromJSON, ToJSON, eitherDecode)
import Data.Aeson (FromJSON, ToJSON, eitherDecode, encode)
import Data.Aeson.Text (encodeToTextBuilder)
import qualified Data.ByteString.Lazy.UTF8 as BS
import Data.Text (Text)
Expand All @@ -16,3 +17,6 @@ encodeToText = toStrict . toLazyText . encodeToTextBuilder

decodeFromString :: FromJSON a => String -> Either String a
decodeFromString = eitherDecode . BS.fromString

encodeToString :: ToJSON a => a -> String
encodeToString = BS.toString . encode
10 changes: 0 additions & 10 deletions waspc/test/AppSpec/FromJSONTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ spec_AppSpecFromJSON = do
}
|]
`shouldDecodeTo` Just (Ref.Ref "foo" :: Ref Query)
it "fails to parse an invalid declType" $ do
[trimming|
{
"name": "foo",
"declType": "IMadeThisUp"
}
|]
-- NOTE: We are using `Ref Entity` here, because the Show instance in
-- shouldDecodeTo demands a proper type.
`shouldDecodeTo` (Nothing :: Maybe (Ref Entity))
sodic marked this conversation as resolved.
Show resolved Hide resolved
describe "Query" $ do
it "parses a valid Query JSON with auth and entities" $ do
[trimming|
Expand Down
1 change: 0 additions & 1 deletion waspc/waspc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ library waspls
Wasp.LSP.TypeInference
Wasp.LSP.Util
Wasp.LSP.Prisma.Analyze
Wasp.LSP.Prisma.Util
build-depends:
base
, aeson
Expand Down
4 changes: 2 additions & 2 deletions waspc/waspls/src/Wasp/LSP/Prisma/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import Control.Lens ((.~))
import Control.Monad.Cont (liftIO)
import Control.Monad.Log.Class (logM)
import StrongPath (Abs, Dir, Path')
import Wasp.LSP.Prisma.Util (showModelNames)
import Wasp.LSP.ServerMonads (ServerM, modify)
import qualified Wasp.LSP.ServerState as State
import Wasp.Project (WaspProjectDir)
import Wasp.Project.Analyze (analyzePrismaSchema)
import Wasp.Psl.Ast.Schema (getModelNames)

analyzeAndSetPrismaSchema :: Path' Abs (Dir WaspProjectDir) -> ServerM ()
analyzeAndSetPrismaSchema waspDir = do
Expand All @@ -18,7 +18,7 @@ analyzeAndSetPrismaSchema waspDir = do
logOutput "warnings" $ show warnings
(Right prismaSchemaAst, warnings) -> do
logOutput "warnings" $ show warnings
logOutput "models" $ showModelNames prismaSchemaAst
logOutput "models" $ show $ getModelNames prismaSchemaAst
modify (State.prismaSchemaAst .~ prismaSchemaAst)
where
logOutput :: String -> String -> ServerM ()
Expand Down
13 changes: 0 additions & 13 deletions waspc/waspls/src/Wasp/LSP/Prisma/Util.hs
sodic marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Loading