You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ADR-X-cardano-api-exports-convention.md
+66-15Lines changed: 66 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,8 @@
4
4
5
5
# Context
6
6
7
+
TODO
8
+
7
9
# Proposed Design
8
10
9
11
## Top level exports
@@ -12,32 +14,81 @@ Each top level export should export distinct symbols.
12
14
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`.
13
15
14
16
*`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`.
22
17
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.
26
53
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.
27
73
28
74
## Deeper level exports
29
75
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.
32
78
This however depends on the specific use case.
33
79
`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.
34
80
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.
0 commit comments