@@ -196,9 +196,20 @@ instance ToJSON Name where
196
196
toEncoding = toEncoding . Name. toText
197
197
toJSON = toJSON . Name. toText
198
198
199
+ instance FromJSON Name where
200
+ parseJSON = Aeson. withText " Name" \ txt -> case Name. parseTextEither txt of
201
+ Left err -> fail $ " Invalid Name: " <> Text. unpack err
202
+ Right name -> pure name
203
+
199
204
instance ToJSONKey Name where
200
205
toJSONKey = contramap Name. toText (toJSONKey @ Text )
201
206
207
+ instance FromJSONKey Name where
208
+ fromJSONKey =
209
+ Aeson. FromJSONKeyTextParser \ txt -> case Name. parseTextEither txt of
210
+ Left err -> fail $ " Invalid Name: " <> Text. unpack err
211
+ Right name -> pure name
212
+
202
213
instance ToSchema Name where
203
214
declareNamedSchema _ = declareNamedSchema (Proxy @ Text )
204
215
@@ -208,6 +219,11 @@ instance ToJSON NameSegment where
208
219
instance ToJSONKey NameSegment where
209
220
toJSONKey = contramap NameSegment. toEscapedText (toJSONKey @ Text )
210
221
222
+ instance FromJSON NameSegment where
223
+ parseJSON = Aeson. withText " NameSegment" \ txt -> case NameSegment. parseText txt of
224
+ Left err -> fail $ " Invalid NameSegment: " <> Text. unpack err
225
+ Right ns -> pure ns
226
+
211
227
deriving anyclass instance ToParamSchema ShortCausalHash
212
228
213
229
instance ToParamSchema ShortHash where
@@ -268,6 +284,12 @@ instance ToJSON ConstructorType where
268
284
CT. Data -> String " Data"
269
285
CT. Effect -> String " Effect"
270
286
287
+ instance FromJSON ConstructorType where
288
+ parseJSON = Aeson. withText " ConstructorType" \ txt -> case txt of
289
+ " Data" -> pure CT. Data
290
+ " Effect" -> pure CT. Effect
291
+ _ -> fail $ " Invalid ConstructorType: " <> Text. unpack txt
292
+
271
293
instance FromHttpApiData Path. Relative where
272
294
parseUrlPiece txt = case Path. parsePath' (Text. unpack txt) of
273
295
Left s -> Left s
@@ -298,6 +320,9 @@ instance FromHttpApiData Path.Path where
298
320
Right (Path. RelativePath' p) -> Right (Path. unrelative p)
299
321
Right (Path. AbsolutePath' _) -> Left $ " Expected relative path, but " <> txt <> " was absolute."
300
322
323
+ instance ToHttpApiData Path. Path where
324
+ toUrlPiece = tShow
325
+
301
326
instance ToCapture (Capture " hash" ShortHash ) where
302
327
toCapture _ =
303
328
DocCapture
@@ -391,12 +416,18 @@ instance FromHttpApiData (HQ.HashQualified Name) where
391
416
& HQ. parseText
392
417
& maybe (Left " Invalid Hash Qualified Name. Expected one of the following forms: name@hash, name, @hash" ) Right
393
418
419
+ instance ToHttpApiData (HQ. HashQualified Name ) where
420
+ toQueryParam = HQ. toTextWith Name. toText
421
+
394
422
instance FromHttpApiData (HQ'. HashQualified Name ) where
395
423
parseQueryParam txt =
396
424
Text. replace " @" " #" txt
397
425
& HQ'. parseText
398
426
& maybe (Left " Invalid Hash Qualified Name. Expected one of the following forms: name@hash, name" ) Right
399
427
428
+ instance ToHttpApiData (HQ'. HashQualified Name ) where
429
+ toQueryParam = HQ'. toTextWith Name. toText
430
+
400
431
instance ToParamSchema (HQ. HashQualified n ) where
401
432
toParamSchema _ =
402
433
mempty
@@ -423,6 +454,9 @@ deriving via Text instance Sqlite.FromField ProjectName
423
454
instance FromHttpApiData ProjectName where
424
455
parseQueryParam = mapLeft tShow . tryInto @ ProjectName
425
456
457
+ instance ToHttpApiData ProjectName where
458
+ toQueryParam name = into @ Text name
459
+
426
460
instance ToParamSchema ProjectName where
427
461
toParamSchema _ =
428
462
mempty
@@ -446,6 +480,9 @@ deriving via Text instance Sqlite.FromField ProjectBranchName
446
480
instance FromHttpApiData ProjectBranchName where
447
481
parseQueryParam = mapLeft tShow . tryInto @ ProjectBranchName
448
482
483
+ instance ToHttpApiData ProjectBranchName where
484
+ toQueryParam name = into @ Text name
485
+
449
486
instance ToSchema ProjectBranchName
450
487
451
488
instance ToParamSchema ProjectBranchName where
0 commit comments