@ahrefs/bs-atdgen-codec-runtime

中文文档
2.2.0发布于 2021/12/03MITCommonJS近 30 天下载 3259

bucklescript runtime for atdgen

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. Simple example
  4. Full example

bs-atdgen-codec-runtime

bs-atdgen-codec-runtime is a bucklescript runtime for atdgen. It is based on the json type provided by bucklescript and combinators of @glennsl/bs-json.

Installation

yarn add @ahrefs/bs-atdgen-codec-runtime

This package doesn't take care of running atdgen to derive code from type definitions. This step requires the atdgen binary which can be obtained using opam or esy.

Alternatively, if your project is using BuckleScript exclusively (i.e. not using native OCaml or Reason in the backend), you might consider using bs-atdgen-generator in combination with this runtime library, in order to generate the .ml and .mli files from .atd sources without having to use native package managers like esy or opam.

Usage

Add @ahrefs/bs-atdgen-codec-runtime to the bs-dependencies of bsconfig.json.

To write atd type definitions, please have a look at the great atd documentation.

Simple example

Reason code to query and deserialize the response of a REST API. It requires bs-fetch.

let get = (url, decode) =>
  Js.Promise.(
    Fetch.fetchWithInit(
      url,
      Fetch.RequestInit.make(~method_=Get, ()),
    )
    |> then_(Fetch.Response.json)
    |> then_(json => json |> decode |> resolve)
  );

let v: Meetup_t.events =
  get(
    "http://localhost:8000/events",
    Atdgen_codec_runtime.Decode.decode(Meetup_bs.read_events),
  );

Full example

The example directory contains a full example of a simple cli to read and write data in a JSON file.

For a complete introduction from atdgen installation to json manipulation, please refer to Getting started with atdgen and bucklescript.

版本与发布记录

@ahrefs/bs-atdgen-codec-runtime 共发布 18 个版本,首次发布于 2018/08/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.2.0latest2021/12/034 年前
2.0.12020/05/016 年前
2.0.02019/11/047 年前
1.4.42019/10/177 年前
1.4.32019/09/247 年前
1.4.22019/09/167 年前

关于 @ahrefs/bs-atdgen-codec-runtime 的常见问题

@ahrefs/bs-atdgen-codec-runtime 是什么?

bucklescript runtime for atdgen

如何安装 @ahrefs/bs-atdgen-codec-runtime?

在项目目录运行 npm install @ahrefs/bs-atdgen-codec-runtime,或使用 pnpm add / yarn add / bun add。

@ahrefs/bs-atdgen-codec-runtime 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ahrefs__bs-atdgen-codec-runtime 是否存在。

@ahrefs/bs-atdgen-codec-runtime 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ahrefs/bs-atdgen-codec-runtime 可以商用吗?

@ahrefs/bs-atdgen-codec-runtime 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ahrefs/bs-atdgen-codec-runtime 的下载量有多少?

根据 npm 官方下载统计,@ahrefs/bs-atdgen-codec-runtime 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,259 次,日均约 109 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ahrefs/bs-atdgen-codec-runtime 还在维护吗?

最新版本 2.2.0 发布于 2021/12/03(4 年前);至今共发布 18 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/08/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。