Metadata-Version: 2.1
Name: harf-serde
Version: 1.2a5
Summary: A library of classes for HAR data using pyserde.
Author-email: Brendan <brendandeleeuw@gmail.com>
License: MIT License
        
        Copyright (c) 2022 Brendan DeLeeuw
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/MystiriodisLykos/har-serde/tree/v1.2a5
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE

A library of classes for [HAR](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md) data using [pyserde](https://pypi.org/project/pyserde/).

The library is focused on providing a [F-Algebra](#f-algebra-classes) for `HAR` data and associated [morphisms](#morphisms) but also contains [canonical types](#CanonicalBasic-types) for basic usages.

## F-Algebra classes
There is one generic-ish class for every `HAR` type and are affixed with `F`.
All nested `HAR` types have been replaced with type parameters.
Some types have no nested `HAR` types and so have no generic parameters but are included for completeness.

There is one edge case for post data.
Since some of the parameters defined in the spec are mutually exclusive there are two classes for post data.
`PostDataParamF` for `ParamF` based post data, and `PostDataTextF` for text based post data.
There is a union type `PostDataF` combining the two for type hints but it cannot be constructed.

All of these types are Functory, by providing a `nmap` function that takes a function for each of the generic parameters.
For example, see the `ResponseF` class below.
```python
class ResponseF(Generic[A, B, C]):
   ...
   statusText: str
   httpVersion: str
   cookies: List[A]
   headers: List[B]
   content: C
   ...

   def nmap(
       self: "ResponseF[A, B, C]",
       f: Func[A, W],
       g: Func[B, X],
       h: Func[C, Y],
   ) -> "ResponseF[W, X, Y]":
       return replace(
           self,  # type: ignore[arg-type]
           cookies=list(map(f, self.cookies)),
           headers=list(map(g, self.headers)),
           content=h(self.content),
       )
```

## Morphisms
Currently there are just 2 helper morphisms.
`harf_cata` is a general catamorphsim, and `harf` which helps you build an algebra for `harf_cata` by taking explicit functions for each `HAR` type.

For example, if you wanted to count the number of times the string `"key"` is in headers you could do the following
```python
harf(
    default=0,
    header=lambda h: h.count("key"),
    request=lambda r: sum(r.headers),
    response=lambda r: sum(r.headers),
    entry=lambda e: e.request + e.response,
    log=lambda l: sum(l.entries),
)(har_data)
```

## Canonical/Basic types
For simple usages there are also type aliases for the canonical `HAR` structure.
I.E. `Response = ResponseF[Cookie, Header, Content]`
