Skip to content

Commit e165f8c

Browse files
committed
address remarks
1 parent 33911d2 commit e165f8c

File tree

1 file changed

+66
-15
lines changed

1 file changed

+66
-15
lines changed

docs/ADR-X-cardano-api-exports-convention.md

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# Context
66

7+
TODO
8+
79
# Proposed Design
810

911
## Top level exports
@@ -12,32 +14,81 @@ Each top level export should export distinct symbols.
1214
This may depend on the case, for example: `Cardano.Api.Byron` symbols which are still in use in current eras, can be reexported through `Cardano.Api`.
1315

1416
* `Cardano.Api` - everything domain related for the currently used and upcoming eras
15-
* `Cardano.Api.E` - everything for the obsoleted `E` era, for example `Cardano.Api.Byron`.
16-
1. Any symbol from era `E`, not in use in current era, should be exported through `Cardano.Api.E`.
17-
2. Any symbol from era `E` and still in use in current era, should be exported through `Cardano.Api` and additionally through `Cardano.Api.E`.
18-
If that's not possible to move it to a module under `Cardano.Api` module, the symbol should be copied to a module under `Cardano.Api`.
19-
* `Cardano.Api.U` utility module, related to `U` feature set like, like `Cardano.Api.Pretty`, `Cardano.Api.Monad.Error`.
20-
Those should **not** be reexported from `Cardano.Api`, because they would pollute symbol namespace, and are not required for using `cardano-api` core features but can be useful for the advanced users.
21-
1. Reexports from upstream libraries like consensus, network or ledger, also fall into this category e.g. `Cardano.Api.Ledger`.
2217

23-
Modules which are exposing general purpose classes and functions should go also into a separate module, and they not need to be reexported through `Cardano.Api`, for example:
24-
* `Cardano.Api.Tx.UTxO` - a wrapper type, with functions common to maps which would clash with other map data structures.
25-
A good example from Hackage is [`Data.Aeson.KeyMap`](https://hackage.haskell.org/package/aeson-2.2.3.0/docs/Data-Aeson-KeyMap.html).
18+
* `Cardano.Api.<F>`, where `<F>` represents a feature.
19+
An aggregate module providing one of core `cardano-api` functionalities.
20+
The name has to be a singular noun.
21+
The purpose of this export is to provide users a more granular control of imports if they don't want to import a catch-all `Cardano.Api` module.
22+
For example:
23+
24+
* `Cardano.Api.Address`
25+
* `Cardano.Api.Block`
26+
* `Cardano.Api.Certificate`
27+
* `Cardano.Api.Eon`
28+
* `Cardano.Api.Genesis`
29+
* `Cardano.Api.Governance`
30+
* `Cardano.Api.IPC`
31+
* `Cardano.Api.Key`
32+
* `Cardano.Api.LedgerState`
33+
* `Cardano.Api.Query`
34+
* `Cardano.Api.Serialisation`
35+
* `Cardano.Api.Tx`
36+
37+
The following rules apply:
38+
39+
1. The modules should not be very granular, only related to a particular feature set.
40+
For example
41+
42+
* `Cardano.Api.Governance.Actions.ProposalProcedure` should not be a top level export and should be exported through `Cardano.Api.Governance`.
43+
* `Cardano.Api.LedgerEvents` should not be a top level export and should be exported through `Cardano.Api.LedgerState`.
44+
45+
1. The module should be reexported through `Cardano.Api`.
46+
This makes using `cardano-api` easier, by not forcing users to decide what to import, and allowing them to just simply write `import Cardano.Api`.
47+
48+
* `Cardano.Api.Byron` - everything for the obsoleted Byron era
49+
50+
* `Cardano.Api.Compatible` - everything for the older eras.
51+
The purpose of this module to provide a limited backwards compatibility for eras not in use on Cardano mainnet.
52+
This is meant only for supporting of tests which hardfork through eras.
2653

54+
For both `Cardano.Api.Byron` and `Cardano.Api.Compatible` the following rules apply:
55+
56+
1. Any symbol from previous era, not in use in current era, should be exported through the respective module for older eras.
57+
2. Any symbol from previous era and still in use in the current era, should be exported through `Cardano.Api` and additionally through `Cardano.Api.(Byron|Compatible)`.
58+
59+
* `Cardano.Api.Experimental` - a transient module for implementing new not yet stabilised APIs.
60+
Not meant to be used by `cardan-api` users directly.
61+
62+
* `Cardano.Api.<U>` utility module, where `<U>` represents a utilities set.
63+
For example `Cardano.Api.Pretty`, `Cardano.Api.Monad.Error`.
64+
65+
* Reexports from upstream libraries like consensus, network or ledger, also fall into this category e.g. `Cardano.Api.Ledger`.
66+
67+
* Modules which are exposing general purpose classes and functions should go also into a separate module, and they don't need to be reexported through `Cardano.Api`.
68+
For example `Cardano.Api.Tx.UTxO` - a wrapper type, with functions common to maps which would clash with other map data structures.
69+
A good example of this pattern from Hackage is [`Data.Aeson.KeyMap`](https://hackage.haskell.org/package/aeson-2.2.3.0/docs/Data-Aeson-KeyMap.html).
70+
71+
In principle, those should not be reexported from `Cardano.Api`, because they would pollute symbol namespace, and are not required for using `cardano-api` core features but can be useful for the advanced users.
72+
In certain situations, parts of those modules can be reexported from `Cardano.Api`, to provide more seamless experience of using the main `Cardano.Api` module.
2773

2874
## Deeper level exports
2975

30-
Any other modules not meant to be a top level export, should be placed inside `Cardano.Api.Internal` and be reexported through a suitable top level module.
31-
In general `Cardano.Api.Internal.*` modules shouldn't be exposed in cabal package.
76+
Any other modules not meant to be a top level export, should be placed inside `Cardano.Api.Internal` or `Cardano.Api.<X>.Internal` and be reexported through a suitable top level module.
77+
In general internal modules shouldn't be exposed in cabal package, but it may be necessary for using them from other components in `cardano-api`, like tests.
3278
This however depends on the specific use case.
3379
`Internal` in the module name should indicate that the module isn't really meant to be used directly, and users can expect more frequent breakage when relying on it.
3480

35-
* `Cardano.Api.Internal.X` should contain everything related to the domain `X`.
36-
For example `Cardano.Api.Address`.
37-
A good example from Hackage how to nest `Internal` modules is [`bytestring`](https://github.com/haskell/text/blob/master/src/Data/Text/Internal/Builder/RealFloat/Functions.hs) package.
81+
* `Cardano.Api.<X>.Internal` or `Cardano.Api.Internal.<X>` or should contain everything related to the domain `<X>`.
82+
* If `Cardano.Api.<X>` is a top level export, internal functions should go to `Cardano.Api.<X>.Internal` (e.g. `Cardano.Api.Address.Internal`), otherwise
83+
* if there's no `Cardano.Api.<X>` top level export, internal functions should go to `Cardano.Api.Internal.<X>` (e.g. `Cardano.Api.Internal.Orphans`).
84+
85+
A good example from Hackage how to nest `Internal` modules is [`text`](https://github.com/haskell/text/blob/master/src/Data/Text/Internal/Builder/RealFloat/Functions.hs) package.
3886

3987
# Decision
4088

89+
TODO
4190

4291
# Consequences
4392

93+
TODO
94+

0 commit comments

Comments
 (0)