Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #44 from safareli/pathy
Browse files Browse the repository at this point in the history
update pathy
  • Loading branch information
safareli authored Mar 20, 2018
2 parents 2e2cd7a + 422a2c8 commit 34d6fd9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 29 additions & 23 deletions src/SqlSquared/Path.purs
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion src/SqlSquared/Signature.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion src/SqlSquared/Signature/Relation.purs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type VariRelR =
}

type TableRelR =
{ path Pt.AnyFilePath
{ path Pt.AnyFile
, alias Maybe String
}

Expand Down
21 changes: 10 additions & 11 deletions test/src/Constructors.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)) )
Expand All @@ -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))
Expand Down

0 comments on commit 34d6fd9

Please sign in to comment.