mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-11 02:35:32 +03:00
remove homebrew NESeq, use vendored
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5094 GitOrigin-RevId: 3342e571d3574a4d94fe3bfedb60f332b8c10853
This commit is contained in:
parent
d66abcefab
commit
187bf385fc
@ -404,7 +404,6 @@ library
|
||||
, Data.Parser.CacheControl
|
||||
, Data.Parser.Expires
|
||||
, Data.Parser.JSONPath
|
||||
, Data.Sequence.NESeq
|
||||
, Data.SqlCommenter
|
||||
, Data.SerializableBlob
|
||||
, Data.Text.Casing
|
||||
|
@ -1,93 +0,0 @@
|
||||
{-# LANGUAGE PatternSynonyms #-}
|
||||
{-# LANGUAGE ViewPatterns #-}
|
||||
|
||||
-- we can't use onNothing without creating a dependency cycle
|
||||
{- HLINT ignore "Use onNothing" -}
|
||||
|
||||
module Data.Sequence.NESeq
|
||||
( NESeq,
|
||||
pattern (:<||),
|
||||
pattern (:||>),
|
||||
singleton,
|
||||
head,
|
||||
tail,
|
||||
toSeq,
|
||||
fromSeq,
|
||||
toNonEmpty,
|
||||
)
|
||||
where
|
||||
|
||||
import Control.DeepSeq (NFData)
|
||||
import Data.Aeson
|
||||
import Data.Foldable
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Data.Sequence qualified as Seq
|
||||
import GHC.Generics (Generic)
|
||||
import Prelude hiding (head, tail)
|
||||
|
||||
data NESeq a = NESeq
|
||||
{ head :: a,
|
||||
tail :: Seq.Seq a
|
||||
}
|
||||
deriving (Show, Eq, Functor, Traversable, Generic)
|
||||
|
||||
instance (NFData a) => NFData (NESeq a)
|
||||
|
||||
instance Semigroup (NESeq a) where
|
||||
NESeq x xs <> NESeq y ys = NESeq x (xs Seq.>< y Seq.<| ys)
|
||||
|
||||
instance Foldable NESeq where
|
||||
null _ = False
|
||||
toList (NESeq x xs) = x : toList xs
|
||||
length (NESeq _ xs) = 1 + length xs
|
||||
foldl1 f (NESeq x xs) = foldl f x xs
|
||||
|
||||
fold = fold . toSeq
|
||||
foldMap f = foldMap f . toSeq
|
||||
foldl f v = foldl f v . toSeq
|
||||
foldl' f v = foldl' f v . toSeq
|
||||
foldr f v = foldr f v . toSeq
|
||||
foldr' f v = foldr' f v . toSeq
|
||||
foldr1 f = foldr1 f . toSeq
|
||||
|
||||
instance FromJSON a => FromJSON (NESeq a) where
|
||||
parseJSON v = do
|
||||
seqList <- parseJSON v
|
||||
maybe (fail "expected non empty list") pure $ fromSeq seqList
|
||||
|
||||
instance ToJSON a => ToJSON (NESeq a) where
|
||||
toJSON = toJSON . toSeq
|
||||
|
||||
singleton :: a -> NESeq a
|
||||
singleton a = NESeq a Seq.empty
|
||||
|
||||
toSeq :: NESeq a -> Seq.Seq a
|
||||
toSeq (NESeq v l) = v Seq.<| l
|
||||
|
||||
fromSeq :: Seq.Seq a -> Maybe (NESeq a)
|
||||
fromSeq = \case
|
||||
Seq.Empty -> Nothing
|
||||
h Seq.:<| l -> Just $ NESeq h l
|
||||
|
||||
pattern (:<||) :: a -> Seq.Seq a -> NESeq a
|
||||
pattern x :<|| xs = NESeq x xs
|
||||
|
||||
{-# COMPLETE (:<||) #-}
|
||||
|
||||
unsnoc :: NESeq a -> (Seq.Seq a, a)
|
||||
unsnoc (x :<|| (xs Seq.:|> y)) = (x Seq.:<| xs, y)
|
||||
unsnoc (x :<|| Seq.Empty) = (Seq.Empty, x)
|
||||
{-# INLINE unsnoc #-}
|
||||
|
||||
pattern (:||>) :: Seq.Seq a -> a -> NESeq a
|
||||
pattern xs :||> x <-
|
||||
(unsnoc -> (!xs, x))
|
||||
where
|
||||
(x Seq.:<| xs) :||> y = x :<|| (xs Seq.:|> y)
|
||||
Seq.Empty :||> y = y :<|| Seq.Empty
|
||||
|
||||
{-# COMPLETE (:||>) #-}
|
||||
|
||||
toNonEmpty :: NESeq a -> NE.NonEmpty a
|
||||
toNonEmpty (NESeq head tail) =
|
||||
head NE.:| toList tail
|
@ -9,7 +9,7 @@ import Data.Environment (Environment)
|
||||
import Data.HashMap.Strict qualified as Map
|
||||
import Data.HashMap.Strict.InsOrd qualified as OMap
|
||||
import Data.Sequence qualified as Seq
|
||||
import Data.Sequence.NESeq qualified as NESeq
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Data.Text qualified as Text
|
||||
import Data.Text.Extended (toTxt, (<<>), (<>>))
|
||||
import Hasura.Backends.DataConnector.API qualified as API
|
||||
@ -143,7 +143,7 @@ resolveDatabaseMetadata' _ sc@(DC.SourceConfig {_scSchema = API.SchemaResponse {
|
||||
-- TODO: Add Column Mutability to the 'TableInfo'
|
||||
rciMutability = RQL.T.C.ColumnMutability False False
|
||||
},
|
||||
_ptmiPrimaryKey = RQL.T.T.PrimaryKey (RQL.T.T.Constraint () (OID 0)) <$> NESeq.fromSeq primaryKeyColumns,
|
||||
_ptmiPrimaryKey = RQL.T.T.PrimaryKey (RQL.T.T.Constraint () (OID 0)) <$> NESeq.nonEmptySeq primaryKeyColumns,
|
||||
_ptmiUniqueConstraints = mempty,
|
||||
_ptmiForeignKeys = mempty,
|
||||
_ptmiViewInfo = Just $ RQL.T.T.ViewInfo False False False,
|
||||
|
@ -11,7 +11,7 @@ import Data.FileEmbed (embedFile, makeRelativeToProject)
|
||||
import Data.HashMap.Strict qualified as HM
|
||||
import Data.HashMap.Strict.NonEmpty qualified as NEHashMap
|
||||
import Data.HashSet qualified as HS
|
||||
import Data.Sequence.NESeq qualified as SNE
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Data.String (fromString)
|
||||
import Database.MySQL.Base (Connection)
|
||||
import Database.MySQL.Base.Types (Field (..))
|
||||
@ -62,7 +62,7 @@ mergeMetadata InformationSchema {..} =
|
||||
(ConstraintName $ fromMaybe "" isConstraintName)
|
||||
(OID $ fromIntegral $ fromMaybe 0 isConstraintOrdinalPosition)
|
||||
)
|
||||
(SNE.singleton (Column isColumnName))
|
||||
(NESeq.singleton (Column isColumnName))
|
||||
else Nothing,
|
||||
_ptmiUniqueConstraints =
|
||||
if isColumnKey == UNI
|
||||
|
@ -14,7 +14,7 @@ import Data.HashMap.Strict qualified as Map
|
||||
import Data.List (delete)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Data.Sequence qualified as Seq
|
||||
import Data.Sequence.NESeq qualified as NESeq
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Data.Text.Extended
|
||||
import Database.PG.Query qualified as Q
|
||||
import Hasura.Backends.Postgres.Connection
|
||||
|
@ -23,7 +23,7 @@ import Data.Aeson qualified as J
|
||||
import Data.Aeson.Types qualified as J
|
||||
import Data.HashMap.Strict qualified as Map
|
||||
import Data.Sequence qualified as Seq
|
||||
import Data.Sequence.NESeq qualified as NESeq
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Hasura.Backends.Postgres.SQL.Types qualified as PG
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR qualified as IR
|
||||
@ -128,7 +128,7 @@ data V1NodeId = V1NodeId
|
||||
data V2NodeId b = V2NodeId
|
||||
{ _ni2Source :: SourceName,
|
||||
_ni2Table :: TableName b,
|
||||
_ni2Columns :: !(NESeq.NESeq J.Value)
|
||||
_ni2Columns :: NESeq.NESeq J.Value
|
||||
}
|
||||
|
||||
instance J.FromJSON NodeId where
|
||||
|
@ -14,7 +14,7 @@ import Data.Aeson.Types qualified as J
|
||||
import Data.Align (align)
|
||||
import Data.Has
|
||||
import Data.HashMap.Strict.Extended qualified as Map
|
||||
import Data.Sequence.NESeq qualified as NESeq
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Data.Text qualified as T
|
||||
import Data.These (partitionThese)
|
||||
import Hasura.Base.Error
|
||||
|
@ -35,7 +35,6 @@ import Data.Has
|
||||
import Data.HashMap.Strict.Extended qualified as Map
|
||||
import Data.Int (Int64)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Data.Sequence.NESeq qualified as NESeq
|
||||
import Data.Text.Extended
|
||||
import Hasura.Backends.Postgres.SQL.Types qualified as PG
|
||||
import Hasura.Base.Error
|
||||
@ -766,7 +765,7 @@ tableConnectionArgs pkeyColumns sourceInfo tableInfo = do
|
||||
parseConnectionSplit maybeOrderBys splitKind cursorSplit = do
|
||||
cursorValue <- J.eitherDecode cursorSplit `onLeft` const throwInvalidCursor
|
||||
case maybeOrderBys of
|
||||
Nothing -> forM (NESeq.toNonEmpty pkeyColumns) $
|
||||
Nothing -> forM (nonEmptySeqToNonEmptyList pkeyColumns) $
|
||||
\columnInfo -> do
|
||||
let columnJsonPath = [J.Key $ K.fromText $ toTxt $ ciColumn columnInfo]
|
||||
columnType = ciType columnInfo
|
||||
|
@ -29,6 +29,7 @@ import Data.HashSet.InsOrd qualified as OSet
|
||||
import Data.Int
|
||||
import Data.Map.Strict as M
|
||||
import Data.Scientific (Scientific)
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Data.Set (Set)
|
||||
import Data.Text.NonEmpty
|
||||
import Data.Time
|
||||
@ -118,6 +119,9 @@ class (Eq a) => Cacheable a where
|
||||
unchanged accesses a b = gunchanged (from a) (from b) accesses
|
||||
{-# INLINEABLE unchanged #-}
|
||||
|
||||
instance (Cacheable a) => Cacheable (NESeq a) where
|
||||
unchanged access = unchanged access `on` NESeq.toSeq
|
||||
|
||||
-- | A mapping from root 'Dependency' keys to the accesses made against those dependencies.
|
||||
newtype Accesses = Accesses {unAccesses :: DM.DMap UniqueS Access}
|
||||
|
||||
@ -355,8 +359,6 @@ instance (Cacheable a) => Cacheable (Maybe a)
|
||||
|
||||
instance (Cacheable a, Cacheable b) => Cacheable (Either a b)
|
||||
|
||||
instance (Cacheable a) => Cacheable (NESeq a)
|
||||
|
||||
instance Cacheable a => Cacheable [a]
|
||||
|
||||
instance Cacheable a => Cacheable (NonEmpty a)
|
||||
|
@ -49,6 +49,9 @@ module Hasura.Prelude
|
||||
-- * Aeson options
|
||||
hasuraJSON,
|
||||
|
||||
-- * NonEmpty.Seq
|
||||
nonEmptySeqToNonEmptyList,
|
||||
|
||||
-- * Extensions to @Data.Foldable@
|
||||
module Data.Time.Clock.Units,
|
||||
)
|
||||
@ -128,7 +131,8 @@ import Data.Monoid as M (getAlt)
|
||||
import Data.Ord as M (comparing)
|
||||
import Data.Semigroup as M (Semigroup (..))
|
||||
import Data.Sequence as M (Seq)
|
||||
import Data.Sequence.NESeq as M (NESeq)
|
||||
import Data.Sequence.NonEmpty as M (NESeq)
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Data.String as M (IsString)
|
||||
import Data.Text as M (Text)
|
||||
import Data.Text qualified as T
|
||||
@ -334,3 +338,8 @@ traceToFileM filepath x =
|
||||
-- [0,1,2,3,4,5,7,9]
|
||||
hashNub :: (Hashable a, Eq a) => [a] -> [a]
|
||||
hashNub = HSet.toList . HSet.fromList
|
||||
|
||||
-- | Convert a non-empty sequence to a non-empty list.
|
||||
nonEmptySeqToNonEmptyList :: NESeq a -> NonEmpty a
|
||||
nonEmptySeqToNonEmptyList (x NESeq.:<|| xs) =
|
||||
x M.:| toList xs
|
||||
|
@ -17,7 +17,7 @@ where
|
||||
import Data.HashMap.Strict qualified as M
|
||||
import Data.HashMap.Strict.NonEmpty qualified as NEHashMap
|
||||
import Data.Sequence qualified as Seq
|
||||
import Data.Sequence.NESeq qualified as NESeq
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.Column
|
||||
|
@ -11,7 +11,7 @@ where
|
||||
|
||||
import Data.HashMap.Strict qualified as HM
|
||||
import Data.HashSet qualified as HS
|
||||
import Data.Sequence.NESeq qualified as NESeq
|
||||
import Data.Sequence.NonEmpty qualified as NESeq
|
||||
import Data.Text.Casing qualified as C
|
||||
import Hasura.Backends.Postgres.Instances.Schema ()
|
||||
import Hasura.Backends.Postgres.SQL.Types (ConstraintName (..), QualifiedObject (..), QualifiedTable, TableName (..), unsafePGCol)
|
||||
@ -112,7 +112,7 @@ mkParser table cib =
|
||||
columnInfos :: [ColumnInfo PG]
|
||||
columnInfos = mkColumnInfo <$> cib
|
||||
|
||||
pks :: Maybe (NESeq (ColumnInfo PG))
|
||||
pks :: Maybe (NESeq.NESeq (ColumnInfo PG))
|
||||
pks = case mkColumnInfo <$> filter cibIsPrimaryKey cib of
|
||||
[] -> Nothing
|
||||
(x : xs) -> Just $ foldl (<>) (NESeq.singleton x) $ fmap NESeq.singleton xs
|
||||
|
@ -16,7 +16,6 @@
|
||||
, "^Data.Aeson.Ordered.*"
|
||||
, "^Data.HashMap.Strict.Multi.*"
|
||||
, "^Data.HashMap.Strict.NonEmpty.*"
|
||||
, "^Data.Sequence.NESeq.*"
|
||||
, "^Data.Text.Casing.*"
|
||||
, "^Data.Text.Extended.*"
|
||||
, "^Data.Trie.*"
|
||||
|
Loading…
Reference in New Issue
Block a user