-
Notifications
You must be signed in to change notification settings - Fork 2
/
Class.purs
156 lines (112 loc) · 4.95 KB
/
Class.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
module TsBridge.Class where
import Prelude
import Control.Promise (Promise)
import DTS as DTS
import Data.Either (Either)
import Data.Function.Uncurried (Fn2, Fn3, Fn4)
import Data.Maybe (Maybe)
import Data.Nullable (Nullable)
import Data.Reflectable (class Reflectable)
import Data.Symbol (class IsSymbol)
import Data.Tuple (Tuple)
import Data.Variant (Variant)
import Data.Variant.Encodings.Flat (VariantEncodedFlat)
import Data.Variant.Encodings.Nested (VariantEncodedNested)
import Effect (Effect)
import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4)
import Foreign.Object (Object)
import Literals (StringLit, BooleanLit)
import Literals.Null (Null)
import Literals.Undefined (Undefined)
import TsBridge.Types.NTuple (NTuple)
import TsBridge.Core (class TsBridgeBy)
import TsBridge.DefaultImpls as TSB
import TsBridge.Monad (TsBridgeM)
import TsBridge.Types.Intersection (Intersection, tsBridgeIntersection)
import TsBridge.Types.Lit (Lit)
import TsBridge.Types.TsRecord (TsRecord, class TsBridgeTsRecord, tsBridgeTsRecord)
import Type.Proxy (Proxy)
import Untagged.Union (OneOf)
class TsBridge (a :: Type) where
tsBridge :: Proxy a -> TsBridgeM DTS.TsType
data Tok = Tok
instance TsBridge a => TsBridgeBy Tok a where
tsBridgeBy _ = tsBridge
instance (TsBridge a, TsBridge b) => TsBridge (Either a b) where
tsBridge = TSB.tsBridgeEither Tok
instance (TsBridge a, TsBridge b) => TsBridge (Tuple a b) where
tsBridge = TSB.tsBridgeTuple Tok
instance TsBridge Number where
tsBridge = TSB.tsBridgeNumber
instance (TSB.TsBridgeRecord Tok r) => TsBridge (Record r) where
tsBridge = TSB.tsBridgeRecord Tok
instance (TsBridgeTsRecord Tok r) => TsBridge (TsRecord r) where
tsBridge = tsBridgeTsRecord Tok
instance (TSB.TsBridgeVariant Tok r) => TsBridge (Variant r) where
tsBridge = TSB.tsBridgeVariant Tok
instance TsBridge String where
tsBridge = TSB.tsBridgeString
instance TsBridge Boolean where
tsBridge = TSB.tsBridgeBoolean
instance TsBridge Int where
tsBridge = TSB.tsBridgeInt
instance TsBridge Char where
tsBridge = TSB.tsBridgeChar
instance TsBridge Unit where
tsBridge = TSB.tsBridgeUnit
instance TsBridge a => TsBridge (Array a) where
tsBridge = TSB.tsBridgeArray Tok
instance TsBridge a => TsBridge (Object a) where
tsBridge = TSB.tsBridgeObject Tok
instance TsBridge a => TsBridge (Effect a) where
tsBridge = TSB.tsBridgeEffect Tok
instance TsBridge a => TsBridge (Nullable a) where
tsBridge = TSB.tsBridgeNullable Tok
instance (TsBridge a, TsBridge b) => TsBridge (a -> b) where
tsBridge = TSB.tsBridgeFunction Tok
instance (TsBridge a, TsBridge b, TsBridge c) => TsBridge (Fn2 a b c) where
tsBridge = TSB.tsBridgeFn2 Tok
instance (TsBridge a, TsBridge b, TsBridge c, TsBridge d) => TsBridge (Fn3 a b c d) where
tsBridge = TSB.tsBridgeFn3 Tok
instance (TsBridge a, TsBridge b, TsBridge c, TsBridge d, TsBridge e) => TsBridge (Fn4 a b c d e) where
tsBridge = TSB.tsBridgeFn4 Tok
instance (TsBridge a, TsBridge b) => TsBridge (EffectFn1 a b) where
tsBridge = TSB.tsBridgeEffectFn1 Tok
instance (TsBridge a, TsBridge b, TsBridge c) => TsBridge (EffectFn2 a b c) where
tsBridge = TSB.tsBridgeEffectFn2 Tok
instance (TsBridge a, TsBridge b, TsBridge c, TsBridge d) => TsBridge (EffectFn3 a b c d) where
tsBridge = TSB.tsBridgeEffectFn3 Tok
instance (TsBridge a, TsBridge b, TsBridge c, TsBridge d, TsBridge e) => TsBridge (EffectFn4 a b c d e) where
tsBridge = TSB.tsBridgeEffectFn4 Tok
instance TsBridge a => TsBridge (Maybe a) where
tsBridge = TSB.tsBridgeMaybe Tok
instance TsBridge a => TsBridge (Promise a) where
tsBridge = TSB.tsBridgePromise Tok
instance IsSymbol sym => TsBridge (TSB.TypeVar sym) where
tsBridge = TSB.tsBridgeTypeVar
instance (TsBridge a, TsBridge b) => TsBridge (OneOf a b) where
tsBridge = TSB.tsBridgeOneOf Tok
instance (TsBridge a, TsBridge b) => TsBridge (Intersection a b) where
tsBridge = tsBridgeIntersection Tok
instance (TSB.TsBridgeVariantEncodedFlat Tok symTag r) => TsBridge (VariantEncodedFlat symTag r) where
tsBridge = TSB.tsBridgeVariantEncodedFlat Tok
instance (TSB.TsBridgeVariantEncodedNested Tok symTag symVal r) => TsBridge (VariantEncodedNested symTag symVal r) where
tsBridge = TSB.tsBridgeVariantEncodedNested Tok
instance TsBridge Undefined where
tsBridge = TSB.tsBridgeUndefined
instance TsBridge Null where
tsBridge = TSB.tsBridgeNull
instance (TSB.NTupleList Tok as) => TsBridge (NTuple as) where
tsBridge = TSB.tsBridgeNTuple Tok
instance IsSymbol sym => TsBridge (StringLit sym) where
tsBridge = TSB.tsBridgeStringLit
instance TsBridge (BooleanLit "true") where
tsBridge = TSB.tsBridgeBooleanLitTrue
instance TsBridge (BooleanLit "false") where
tsBridge = TSB.tsBridgeBooleanLitFalse
instance Reflectable h String => TsBridge (Lit h String) where
tsBridge = TSB.tsBridgeStringLit'
instance Reflectable h Boolean => TsBridge (Lit h Boolean) where
tsBridge = TSB.tsBridgeBooleanLit'
instance Reflectable h Int => TsBridge (Lit h Int) where
tsBridge = TSB.tsBridgeIntLit'