github.com/ipld/go-ipld-prime@v0.21.0/README.md (about)

     1  go-ipld-prime
     2  =============
     3  
     4  `go-ipld-prime` is an implementation of the IPLD spec interfaces,
     5  a batteries-included codec implementations of IPLD for CBOR and JSON,
     6  and tooling for basic operations on IPLD objects (traversals, etc).
     7  
     8  
     9  
    10  API
    11  ---
    12  
    13  The API is split into several packages based on responsibly of the code.
    14  The most central interfaces are the base package,
    15  but you'll certainly need to import additional packages to get concrete implementations into action.
    16  
    17  Roughly speaking, the core package interfaces are all about the IPLD Data Model;
    18  the `codec/*` packages contain functions for parsing serial data into the IPLD Data Model,
    19  and converting Data Model content back into serial formats;
    20  the `traversal` package is an example of higher-order functions on the Data Model;
    21  concrete `ipld.Node` implementations ready to use can be found in packages in the `node/*` directory;
    22  and several additional packages contain advanced features such as IPLD Schemas.
    23  
    24  (Because the codecs, as well as higher-order features like traversals, are
    25  implemented in a separate package from the core interfaces or any of the Node implementations,
    26  you can be sure they're not doing any funky "magic" -- all this stuff will work the same
    27  if you want to write your own extensions, whether for new Node implementations
    28  or new codecs, or new higher-order order functions!)
    29  
    30  - `github.com/ipld/go-ipld-prime` -- imported as just `ipld` -- contains the core interfaces for IPLD.  The most important interfaces are `Node`, `NodeBuilder`, `Path`, and `Link`.
    31  - `github.com/ipld/go-ipld-prime/node/basicnode` -- provides concrete implementations of `Node` and `NodeBuilder` which work for any kind of data, using unstructured memory.
    32  - `github.com/ipld/go-ipld-prime/node/bindnode` -- provides concrete implementations of `Node` and `NodeBuilder` which store data in native golang structures, interacting with it via reflection.  Also supports IPLD Schemas!
    33  - `github.com/ipld/go-ipld-prime/traversal` -- contains higher-order functions for traversing graphs of data easily.
    34  - `github.com/ipld/go-ipld-prime/traversal/selector` -- contains selectors, which are sort of like regexps, but for trees and graphs of IPLD data!
    35  - `github.com/ipld/go-ipld-prime/codec` -- parent package of all the codec implementations!
    36  - `github.com/ipld/go-ipld-prime/codec/dagcbor` -- implementations of marshalling and unmarshalling as CBOR (a fast, binary serialization format).
    37  - `github.com/ipld/go-ipld-prime/codec/dagjson` -- implementations of marshalling and unmarshalling as JSON (a popular human readable format).
    38  - `github.com/ipld/go-ipld-prime/linking/cid` -- imported as `cidlink` -- provides concrete implementations of `Link` as a CID.  Also, the multicodec registry.
    39  - `github.com/ipld/go-ipld-prime/schema` -- contains the `schema.Type` and `schema.TypedNode` interface declarations, which represent IPLD Schema type information.
    40  - `github.com/ipld/go-ipld-prime/node/typed` -- provides concrete implementations of `schema.TypedNode` which decorate a basic `Node` at runtime to have additional features described by IPLD Schemas.
    41  
    42  
    43  Getting Started
    44  ---------------
    45  
    46  Let's say you want to create some data programmatically,
    47  and then serialize it, or save it as [blocks].
    48  
    49  You've got a ton of different options, depending on what golang convention you want to use:
    50  
    51  - the `qp` package -- [example](https://pkg.go.dev/github.com/ipld/go-ipld-prime/fluent/qp#example-package)
    52  - the `bindnode` system, if you want to use golang types -- [example](https://pkg.go.dev/github.com/ipld/go-ipld-prime/node/bindnode#example-Wrap-NoSchema), [example with schema](https://pkg.go.dev/github.com/ipld/go-ipld-prime/node/bindnode#example-Wrap-WithSchema)
    53  - or the [`NodeBuilder`](https://pkg.go.dev/github.com/ipld/go-ipld-prime/datamodel#NodeBuilder) interfaces, raw (verbose; not recommended)
    54  - or even some codegen systems!
    55  
    56  Once you've got a Node full of data,
    57  you can serialize it:
    58  
    59  https://pkg.go.dev/github.com/ipld/go-ipld-prime#example-package-CreateDataAndMarshal
    60  
    61  But probably you want to do more than that;
    62  probably you want to store this data as a block,
    63  and get a CID that links back to it.
    64  For this you use `LinkSystem`:
    65  
    66  https://pkg.go.dev/github.com/ipld/go-ipld-prime/linking#example-LinkSystem.Store
    67  
    68  Hopefully these pointers give you some useful getting-started focal points.
    69  The API docs should help from here on out.
    70  We also highly recommend scanning the [godocs](https://pkg.go.dev/github.com/ipld/go-ipld-prime) for other pieces of example code, in various packages!
    71  
    72  Let us know in [issues](https://github.com/ipld/go-ipld-prime/issues), [chat, or other community spaces](https://ipld.io/docs/intro/community/) if you need more help,
    73  or have suggestions on how we can improve the getting-started experiences!
    74  
    75  
    76  
    77  Other IPLD Libraries
    78  --------------------
    79  
    80  The IPLD specifications are designed to be language-agnostic.
    81  Many implementations exist in a variety of languages.
    82  
    83  For overall behaviors and specifications, refer to the IPLD website, or its source, in IPLD meta repo:
    84  - https://ipld.io/
    85  - https://github.com/ipld/ipld/
    86  You should find specs in the `specs/` dir there,
    87  human-friendly docs in the `docs/` dir,
    88  and information about _why_ things are designed the way they are mostly in the `design/` directories.
    89  
    90  There are also pages in the IPLD website specifically about golang IPLD libraries,
    91  and your alternatives: https://ipld.io/libraries/golang/
    92  
    93  
    94  ### distinctions from go-ipld-interface&go-ipld-cbor
    95  
    96  This library ("go ipld prime") is the current head of development for golang IPLD,
    97  and we recommend new developments in golang be done using this library as the basis.
    98  
    99  However, several other libraries exist in golang for working with IPLD data.
   100  Most of these predate go-ipld-prime and no longer receive active development,
   101  but since they do support a lot of other software, you may continue to seem them around for a while.
   102  go-ipld-prime is generally **serially compatible** with these -- just like it is with IPLD libraries in other languages.
   103  
   104  In terms of programmatic API and features, go-ipld-prime is a clean take on the IPLD interfaces,
   105  and chose to address several design decisions very differently than older generation of libraries:
   106  
   107  - **The Node interfaces map cleanly to the IPLD Data Model**;
   108  - Many features known to be legacy are dropped;
   109  - The Link implementations are purely CIDs (no "name" nor "size" properties);
   110  - The Path implementations are provided in the same box;
   111  - The JSON and CBOR implementations are provided in the same box;
   112  - Several odd dependencies on blockstore and other interfaces that were closely coupled with IPFS are replaced by simpler, less-coupled interfaces;
   113  - New features like IPLD Selectors are only available from go-ipld-prime;
   114  - New features like ADLs (Advanced Data Layouts), which provide features like transparent sharding and indexing for large data, are only available from go-ipld-prime;
   115  - Declarative transformations can be applied to IPLD data (defined in terms of the IPLD Data Model) using go-ipld-prime;
   116  - and many other small refinements.
   117  
   118  In particular, the clean and direct mapping of "Node" to concepts in the IPLD Data Model
   119  ensures a much more consistent set of rules when working with go-ipld-prime data, regardless of which codecs are involved.
   120  (Codec-specific embellishments and edge-cases were common in the previous generation of libraries.)
   121  This clarity is also what provides the basis for features like Selectors, ADLs, and operations such as declarative transformations.
   122  
   123  Many of these changes had been discussed for the other IPLD codebases as well,
   124  but we chose clean break v2 as a more viable project-management path.
   125  Both go-ipld-prime and these legacy libraries can co-exist on the same import path, and both refer to the same kinds of serial data.
   126  Projects wishing to migrate can do so smoothly and at their leisure.
   127  
   128  We now consider many of the earlier golang IPLD libraries to be defacto deprecated,
   129  and you should expect new features *here*, rather than in those libraries.
   130  (Those libraries still won't be going away anytime soon, but we really don't recomend new construction on them.)
   131  
   132  ### migrating
   133  
   134  **For recommendations on where to start when migrating:**
   135  see [README_migrationGuide](./README_migrationGuide.md).
   136  That document will provide examples of which old concepts and API names map to which new APIs,
   137  and should help set you on the right track.
   138  
   139  ### unixfsv1
   140  
   141  Lots of people who hear about IPLD have heard about it through IPFS.
   142  IPFS has IPLD-native APIs, but IPFS *also* makes heavy use of a specific system called "UnixFSv1",
   143  so people often wonder if UnixFSv1 is supported in IPLD libraries.
   144  
   145  The answer is "yes" -- but it's not part of the core.
   146  
   147  UnixFSv1 is now treated as an [ADL](https://ipld.io/glossary/#adl),
   148  and a go-ipld-prime compatible implementation can be found
   149  in the [ipfs/go-unixfsnode](https://github.com/ipfs/go-unixfsnode) repo.
   150  
   151  Additionally, the codec used in UnixFSv1 -- dag-pb --
   152  can be found implemented in the [ipld/go-codec-dagpb](https://github.com/ipld/go-codec-dagpb) repo.
   153  
   154  A "some assembly required" advisory may still be in effect for these pieces;
   155  check the readmes in those repos for details on what they support.
   156  
   157  The move to making UnixFSv1 a non-core system has been an arduous retrofit.
   158  However, framing it as an ADL also provides many advantages:
   159  
   160  - it demonstrates that ADLs as a plugin system _work_, and others can develop new systems in this pattern!
   161  - it has made pathing over UnixFSv1 much more standard and well-defined
   162  - this standardization means systems like [Selectors](https://ipld.io/glossary/#selectors) work naturally over UnixFSv1...
   163  - ... which in turn means anything using them (ex: CAR export; graphsync; etc) can very easily be asked to produce a merkle-proof
   164    for a path over UnixFSv1 data, without requiring the querier to know about the internals.  Whew!
   165  
   166  We hope users and developers alike will find value in how these systems are now layered.
   167  
   168  
   169  
   170  Change Policy
   171  -------------
   172  
   173  The go-ipld-prime library is ready to use, and we value stability highly.
   174  
   175  We make releases periodically.
   176  However, using a commit hash to pin versions precisely when depending on this library is also perfectly acceptable.
   177  (Only commit hashes on the master branch can be expected to persist, however;
   178  depending on a commit hash in a branch is not recommended.  See [development branches](#development-branches).)
   179  
   180  We maintain a [CHANGELOG](CHANGELOG.md)!
   181  Please read it, when updating!
   182  
   183  We do make reasonable attempts to minimize the degree of changes to the library which will create "breaking change" experiences for downstream consumers,
   184  and we do document these in the changelog (often, even with specific migration instructions).
   185  However, we do also still recommend running your own compile and test suites as a matter of course after updating.
   186  
   187  You can help make developing this library easier by staying up-to-date as a downstream consumer!
   188  When we do discover a need for API changes, we typically try to introduce the new API first,
   189  and do at least one release tag in which the old API is deprecated (but not yet removed).
   190  We will all be able to develop software faster, together, as an ecosystem,
   191  if libraries can keep reasonably closely up-to-date with the most recent tags.
   192  
   193  
   194  ### Version Names
   195  
   196  When a tag is made, version number steps in go-ipld-prime advance as follows:
   197  
   198  1. the number bumps when the lead maintainer says it does.
   199  2. even numbers should be easy upgrades; odd numbers may change things.
   200  3. the version will start with `v0.` until further notice.
   201  
   202  [This is WarpVer](https://gist.github.com/warpfork/98d2f4060c68a565e8ad18ea4814c25f).
   203  
   204  These version numbers are provided as hints about what to expect,
   205  but ultimately, you should always invoke your compiler and your tests to tell you about compatibility,
   206  as well as read the [changelog](CHANGELOG.md).
   207  
   208  
   209  ### Updating
   210  
   211  **Read the [CHANGELOG](CHANGELOG.md).**
   212  
   213  Really, read it.  We put exact migration instructions in there, as much as possible.  Even outright scripts, when feasible.
   214  
   215  An even-number release tag is usually made very shortly before an odd number tag,
   216  so if you're cautious about absorbing changes, you should update to the even number first,
   217  run all your tests, and *then* upgrade to the odd number.
   218  Usually the step to the even number should go off without a hitch, but if you *do* get problems from advancing to an even number tag,
   219  A) you can be pretty sure it's a bug, and B) you didn't have to edit a bunch of code before finding that out.
   220  
   221  
   222  ### Development branches
   223  
   224  The following are norms you can expect of changes to this codebase, and the treatment of branches:
   225  
   226  - The `master` branch will not be force-pushed.
   227      - (exceptional circumstances may exist, but such exceptions will only be considered valid for about as long after push as the "$N-second-rule" about dropped food).
   228      - Therefore, commit hashes on master are gold to link against.
   229  - All other branches *can* be force-pushed.
   230      - Therefore, commit hashes not reachable from the master branch are inadvisable to link against.
   231  - If it's on master, it's understood to be good, in as much as we can tell.
   232      - Changes and features don't get merged until their tests pass!
   233      - Packages of "alpha" developmental status may exist, and be more subject to change than other more finalized parts of the repo, but their self-tests will at least pass.
   234  - Development proceeds -- both starting from and ending on -- the `master` branch.
   235      - There are no other long-running supported-but-not-master branches.
   236      - The existence of tags at any particular commit do not indicate that we will consider starting a long running and supported diverged branch from that point, nor start doing backports, etc.