diff --git a/bower.json b/bower.json index 66a932b..e53cf7c 100644 --- a/bower.json +++ b/bower.json @@ -17,7 +17,7 @@ "dependencies": { "purescript-prelude": "^3.1.0", "purescript-matryoshka": "^0.3.0", - "purescript-pathy": "^4.0.0", + "purescript-pathy": "^5.0.0", "purescript-profunctor": "^3.2.0", "purescript-profunctor-lenses": "^3.2.0", "purescript-ejson": "^10.0.1", diff --git a/src/SqlSquared/Path.purs b/src/SqlSquared/Path.purs index 116eb6b..294afe0 100644 --- a/src/SqlSquared/Path.purs +++ b/src/SqlSquared/Path.purs @@ -1,52 +1,58 @@ module SqlSquared.Path - ( AnyFilePath - , AnyDirPath - , parseAnyFilePath + ( parseAnyFilePath , printAnyFilePath , parseAnyDirPath , printAnyDirPath , genAnyFilePath , genAnyDirPath + , module PathyTypeReexprts ) where import Prelude -import Data.Either as E -import Data.NonEmpty ((:|)) -import Data.Path.Pathy as Pt -import Data.Path.Pathy.Gen as PtGen + import Control.Monad.Gen as Gen import Control.Monad.Rec.Class (class MonadRec) +import Data.Either as E +import Data.NonEmpty ((:|)) +import Pathy as Pt +import Pathy (AnyDir, AnyFile) as PathyTypeReexprts +import Pathy (AnyDir, AnyFile) +import Pathy.Gen as PtGen import SqlSquared.Utils ((∘)) -type AnyDirPath = E.Either (Pt.AbsDir Pt.Unsandboxed) (Pt.RelDir Pt.Unsandboxed) -type AnyFilePath = E.Either (Pt.AbsFile Pt.Unsandboxed) (Pt.RelFile Pt.Unsandboxed) -printAnyDirPath :: AnyDirPath -> String -printAnyDirPath = E.either Pt.unsafePrintPath Pt.unsafePrintPath +printAnyDirPath :: AnyDir -> String +printAnyDirPath = E.either + (Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter) + (Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter) -parseAnyDirPath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyDirPath -parseAnyDirPath fail = Pt.parsePath +parseAnyDirPath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyDir +parseAnyDirPath fail = Pt.parsePath Pt.posixParser (pure ∘ E.Right) (pure ∘ E.Left) (const $ fail "Expected a directory path") (const $ fail "Expected a directory path") + (fail "Expected valid path") -printAnyFilePath :: AnyFilePath -> String -printAnyFilePath = E.either Pt.unsafePrintPath Pt.unsafePrintPath +printAnyFilePath :: AnyFile -> String +printAnyFilePath = E.either + (Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter) + (Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter) -parseAnyFilePath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyFilePath -parseAnyFilePath fail = Pt.parsePath +parseAnyFilePath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyFile +parseAnyFilePath fail = Pt.parsePath Pt.posixParser (const $ fail "Expected a file path") (const $ fail "Expected a file path") (pure ∘ E.Right) (pure ∘ E.Left) + (fail "Expected valid path") -genAnyFilePath :: forall m. Gen.MonadGen m => MonadRec m => m AnyFilePath +genAnyFilePath :: forall m. Gen.MonadGen m => MonadRec m => m AnyFile genAnyFilePath = Gen.oneOf - $ (E.Left ∘ Pt.unsandbox <$> PtGen.genAbsFilePath) - :| [E.Right ∘ Pt.unsandbox <$> PtGen.genRelFilePath] + $ (E.Left <$> PtGen.genAbsFilePath) + :| [E.Right <$> PtGen.genRelFilePath] -genAnyDirPath :: forall m. Gen.MonadGen m => MonadRec m => m AnyDirPath +genAnyDirPath :: forall m. Gen.MonadGen m => MonadRec m => m AnyDir genAnyDirPath = Gen.oneOf - $ (E.Left ∘ Pt.unsandbox <$> PtGen.genAbsDirPath) - :| [E.Right ∘ Pt.unsandbox <$> PtGen.genRelDirPath] + $ (E.Left <$> PtGen.genAbsDirPath) + :| [E.Right <$> PtGen.genRelDirPath] diff --git a/src/SqlSquared/Signature.purs b/src/SqlSquared/Signature.purs index cca8758..08fb7fa 100644 --- a/src/SqlSquared/Signature.purs +++ b/src/SqlSquared/Signature.purs @@ -140,7 +140,7 @@ data SqlF literal a | Parens a data SqlDeclF a - = Import Pt.AnyDirPath + = Import Pt.AnyDir | FunctionDecl (FunctionDeclR a) newtype SqlModuleF a = diff --git a/src/SqlSquared/Signature/Relation.purs b/src/SqlSquared/Signature/Relation.purs index 5ed38de..60cba33 100644 --- a/src/SqlSquared/Signature/Relation.purs +++ b/src/SqlSquared/Signature/Relation.purs @@ -36,7 +36,7 @@ type VariRelR = } type TableRelR = - { path ∷ Pt.AnyFilePath + { path ∷ Pt.AnyFile , alias ∷ Maybe String } diff --git a/test/src/Constructors.purs b/test/src/Constructors.purs index b681d29..38a241c 100644 --- a/test/src/Constructors.purs +++ b/test/src/Constructors.purs @@ -2,16 +2,15 @@ module Test.Constructors where import Prelude -import Data.List as L +import Data.Either as E import Data.Lens ((.~), (<>~), (?~)) +import Data.List as L import Data.Maybe (Maybe(..)) import Data.NonEmpty as NE -import Data.Either as E -import Data.Path.Pathy as Pt - +import Data.Symbol (SProxy(..)) +import Pathy as Pt import SqlSquared as S import SqlSquared.Utils ((×), (∘)) - import Test.Unit (suite, test, TestSuite) import Test.Unit.Assert as Assert @@ -26,9 +25,9 @@ selectQuery = { alias: Nothing , path: E.Left $ Pt.rootDir - Pt. Pt.dir "mongo" - Pt. Pt.dir "testDb" - Pt. Pt.file "patients" + Pt. Pt.dir (SProxy :: SProxy "mongo") + Pt. Pt.dir (SProxy :: SProxy "testDb") + Pt. Pt.file (SProxy :: SProxy "patients") }) ( Just $ S.binop S.Eq (S.ident "quux") (S.num 12.0) ) ( Just $ S.groupBy [ S.ident "zzz" ] # S.having ( S.binop S.Gt (S.ident "ooo") ( S.int 2)) ) @@ -53,9 +52,9 @@ buildSelectQuery = { alias: Nothing , path: E.Left $ Pt.rootDir - Pt. Pt.dir "mongo" - Pt. Pt.dir "testDb" - Pt. Pt.file "patients" + Pt. Pt.dir (SProxy :: SProxy "mongo") + Pt. Pt.dir (SProxy :: SProxy "testDb") + Pt. Pt.file (SProxy :: SProxy "patients") })) ∘ (S._filter ?~ S.binop S.Eq (S.ident "quux") (S.num 12.0))