Skip to content

Commit

Permalink
Merge pull request #2 from bitnomial/ghc-9.6.4
Browse files Browse the repository at this point in the history
Sync from Source Repo and Upgrade to GHC 9.6.4
  • Loading branch information
GambolingPangolin authored Jan 29, 2024
2 parents 55f5cf3 + 987b8eb commit 8edecd0
Show file tree
Hide file tree
Showing 58 changed files with 2,303 additions and 607 deletions.
7 changes: 7 additions & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
((haskell-mode
. (
(haskell-process-args-stack-ghci . ("--ghci-options=-ferror-spans" "--no-build" "--no-load"
"aeson-typescript:lib"
"aeson-typescript:aeson-typescript-tests"
))
)))
105 changes: 105 additions & 0 deletions .github/workflows/aeson-typescript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: aeson-typescript

on:
pull_request:
push:

jobs:
cabal:
name: ${{ matrix.os }} / ghc ${{ matrix.ghc }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
ghc:
- "8.10.7"
- "9.0.2"
- "9.2.8"
- "9.4.7"
- "9.6.3"

steps:
- uses: actions/checkout@v2

- uses: haskell/actions/setup@v2
id: setup-haskell-cabal
name: Setup Haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: "latest"

- name: Freeze
run: |
cabal freeze
- uses: actions/cache@v3
name: Cache ~/.cabal/store
with:
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}

- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install TSC
run: |
npm install -g typescript
- name: Build
run: |
cabal configure --enable-tests --enable-benchmarks --test-show-details=direct
cabal build all
- name: Test
run: |
cabal test all
stack:
name: stack / ghc ${{ matrix.ghc }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- ghc: "8.10.7"
yaml: "stack-8.10.7.yaml"
- ghc: "9.0.2"
yaml: "stack-9.0.2.yaml"
- ghc: "9.2.8"
yaml: "stack-9.2.8.yaml"
- ghc: "9.4.7"
yaml: "stack-9.4.7.yaml"
- ghc: "9.6.3"
yaml: "stack.yaml"

steps:
- uses: actions/checkout@v3

- uses: haskell/actions/setup@v2
name: Setup Haskell Stack
with:
ghc-version: ${{ matrix.ghc }}
enable-stack: true
stack-version: "latest"

- uses: actions/cache@v3
name: Cache ~/.stack
with:
path: ~/.stack
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ matrix.yaml }}

- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install TSC
run: |
npm install -g typescript
- name: Build
run: |
stack build --stack-yaml ${{matrix.yaml}} --system-ghc --test --bench --no-run-tests --no-run-benchmarks
- name: Test
run: |
stack test --stack-yaml ${{matrix.yaml}} --system-ghc
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.stack-work/
*~
.dir-locals.el
dist-newstyle
dist-newstyle
*.hie
dev/
69 changes: 69 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# HLint configuration file
# https://github.com/ndmitchell/hlint
##########################

# This file contains a template configuration file, which is typically
# placed as .hlint.yaml in the root of your project


# Warnings currently triggered by your code
- ignore: {name: "Redundant bracket"}
- ignore: {name: "Redundant do"}
- ignore: {name: "Use if"}
- ignore: {name: "Move brackets to avoid $"}
- ignore: {name: "Use <$>"}
- ignore: {name: "Reduce duplication"}
- ignore: {name: "Redundant multi-way if"}

# Specify additional command line arguments
#
# - arguments: [--color, -XQuasiQuotes]


# Control which extensions/flags/modules/functions can be used
#
# - extensions:
# - default: false # all extension are banned by default
# - name: [PatternGuards, ViewPatterns] # only these listed extensions can be used
# - {name: CPP, within: CrossPlatform} # CPP can only be used in a given module
#
# - flags:
# - {name: -w, within: []} # -w is allowed nowhere
#
# - modules:
# - {name: [Data.Set, Data.HashSet], as: Set} # if you import Data.Set qualified, it must be as 'Set'
# - {name: Control.Arrow, within: []} # Certain modules are banned entirely
#
# - functions:
# - {name: unsafePerformIO, within: []} # unsafePerformIO can only appear in no modules


# Add custom hints for this project
#
# Will suggest replacing "wibbleMany [myvar]" with "wibbleOne myvar"
# - error: {lhs: "wibbleMany [x]", rhs: wibbleOne x}


# Turn on hints that are off by default
#
# Ban "module X(module X) where", to require a real export list
# - warn: {name: Use explicit module export list}
#
# Replace a $ b $ c with a . b $ c
# - group: {name: dollar, enabled: true}
#
# Generalise map to fmap, ++ to <>
# - group: {name: generalise, enabled: true}


# Ignore some builtin hints
# - ignore: {name: Use let}
# - ignore: {name: Use const, within: SpecialModule} # Only within certain modules


# Define some custom infix operators
# - fixity: infixr 3 ~^#^~


# To generate a suitable file for HLint do:
# $ hlint --default > .hlint.yaml
72 changes: 72 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Change log

## Unreleased

## 0.7.0.0

Represents optional fields (according to the Haskell model) as required fields
with type `A | null` rather than optional fields.

## 0.6.2.0

* Expose generic type constructors `T4` through `T10`. (We only exposed `T`, `T1`, `T2`, and `T3` before.)

## 0.6.1.0

* Fix a bug which caused enum formatting mode to turn off when multiple declarations were provided (#41)
* Fix some mismatch issues where an enum value doesn't match the desired string.

## 0.6.0.0

* New word instances: Word, Word16, Word32, Word64
* New instances from Data.Functor: Compose, Const, Identity, Product

## 0.5.0.0

* [#35](https://github.com/codedownio/aeson-typescript/pull/35)
* Add `Data.Aeson.TypeScript.LegalName` module for checking whether a name is a legal JavaScript name or not.
* The `defaultFormatter` will `error` if the name contains illegal characters.
* Be able to transfer Haddock comments to emitted TypeScript (requires GHC >= 9.2 and `-haddock` flag)
* Add support for @no-emit-typescript in Haddocks for constructors and record fields (requires GHC >= 9.2 and `-haddock` flag)
* Support GHC 9.6.1

## 0.4.2.0

* Fix TypeScript (A.KeyMap a) instance

## 0.4.1.0

* Add TypeScript Int16
* Add TypeScript (A.KeyMap a) instance for aeson 2

## 0.4.0.0

* Add new built-in instances (Word8, Int32, Int64, Map, HashSet)
* Export TSField in the Internal module
* Avoid producing redundant constraints (for fewer warnings when using -Wredundant-constraints)
* Encode maps as mapped types (allows you to have unions as keys)
* Support mapping open type families to lookup types (+ progress on handling promoted types)
* Improve propagation of T variables in declarations
* Add support for "key types", in case you have custom implementations of FromJSONKey/ToJSONKey
* Add ability to recursively derive missing instances (fragile)

## 0.3.0.1

* Support GHC 9.0.1

## 0.3.0.0

* Update th-abstraction dependency to < 0.5 to support working with newer Stack LTS.
* Major refactors to improve TH quality.
* Tracking of parent types to allow recursive deriving
* The `getParentTypes` function was added to the main typeclass.
* The new `Data.Aeson.TypeScript.Recursive` module for working with recursive definitions.
* New support for mapping Haskell closed type families to TypeScript lookup types.

## 0.2.0.0

* New formatting option `interfaceNameModifier`.

## 0.1.0.0

* Initial release.
8 changes: 0 additions & 8 deletions ChangeLog.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright Tom McLaughlin (c) 2017
Copyright Tom McLaughlin (c) 2022

All rights reserved.

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Welcome to `aeson-typescript` [![Hackage](https://img.shields.io/hackage/v/aeson-typescript.svg)](https://hackage.haskell.org/package/aeson-typescript) [![Build Status](https://travis-ci.org/codedownio/aeson-typescript.svg)](https://travis-ci.org/codedownio/aeson-typescript)
# Welcome to `aeson-typescript` [![Hackage](https://img.shields.io/hackage/v/aeson-typescript.svg)](https://hackage.haskell.org/package/aeson-typescript) ![aeson-typescript](https://github.com/codedownio/aeson-typescript/workflows/aeson-typescript/badge.svg)

This library provides a way to generate TypeScript `.d.ts` files that match your existing Aeson `ToJSON` instances.
If you already use Aeson's Template Haskell support to derive your instances, then deriving TypeScript is as simple as
Expand All @@ -16,6 +16,7 @@ data D a = Nullary
| Product String Char a
| Record { testOne :: Double
, testTwo :: Bool
-- | This docstring will go into the generated TypeScript!
, testThree :: D a
} deriving Eq
```
Expand All @@ -29,7 +30,7 @@ $(deriveTypeScript (defaultOptions {fieldLabelModifier = drop 4, constructorTagM
Now we can use the newly created instances.

```haskell
>>> putStrLn $ formatTSDeclarations $ getTypeScriptDeclaration (Proxy :: Proxy D)
>>> putStrLn $ formatTSDeclarations $ getTypeScriptDeclarations (Proxy :: Proxy (D T))

type D<T> = "nullary" | IUnary<T> | IProduct<T> | IRecord<T>;

Expand All @@ -41,6 +42,7 @@ interface IRecord<T> {
tag: "record";
One: number;
Two: boolean;
// This docstring will go into the generated TypeScript!
Three: D<T>;
}
```
Expand Down Expand Up @@ -112,6 +114,6 @@ Now you can generate the types by running `stack runhaskell tsdef/Main.hs > type

# See also

If you want a much more opinionated web framework for generating APIs, check out [servant](http://haskell-servant.readthedocs.io/en/stable/). (Although it doesn't seem to support TypeScript client generation at the moment.)
If you want a more opinionated web framework for generating APIs, check out [servant](http://haskell-servant.readthedocs.io/en/stable/). If you use Servant, you may enjoy [servant-typescript](https://github.com/codedownio/servant-typescript), which is based on `aeson-typescript`! This companion package also has the advantage of magically collecting all the types used in your API, so you don't have to list them out manually.

For another very powerful framework that can generate TypeScript client code based on an API specification, see [Swagger/OpenAPI](https://github.com/swagger-api/swagger-codegen).
Loading

0 comments on commit 8edecd0

Please sign in to comment.