Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Aug 19, 2024
1 parent f7ba098 commit d31dc5e
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,31 @@

> TypeScript implementation of the [Cap'n Proto](https://capnproto.org) serialization protocol.
Cap’n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think [Protocol Buffers](https://github.com/protocolbuffers/protobuf), except faster. In fact, in benchmarks, Cap’n Proto is INFINITY TIMES faster than Protocol Buffers, because there is no encoding/decoding step. Start with the [Cap'n Proto Introduction](https://capnproto.org/index.html) for more detailed information on what this is about.

## Status

> [!WARNING]
> WARNING: THIS IS ALPHA QUALITY SOFTWARE. USE AT YOUR OWN RISK. AUTHORS ARE NOT RESPONSIBLE FOR LOSS OF LIMB, LIFE, SANITY, OR RETIREMENT FUNDS DUE TO THE USE OF THIS SOFTWARE. Feedback and contributions are welcome.
This project is a rework<sup>1</sup> of [jdiaz5513/capnp-ts](https://github.com/jdiaz5513/capnp-ts/) by Julián Díaz and under development (honestly more a playground at this stage). Until version `1.x.x` lands, the API can change from `0.x` to `0.y`.
> This is an alpha-quality software. please use at your own risk ([project status](#status)).
- Serialization: working, may be missing features
- Schema Compiler: working, may be missing features
- RPC: not implemented yet
Cap’n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think [Protocol Buffers](https://github.com/protocolbuffers/protobuf), except faster. Cap’n Proto was built by [Kenton Varda](https://github.com/kentonv) to be used in [Sandstorm](https://capnproto.org/faq.html#sandstorm) and is now heavily used in [Cloudflare](https://capnproto.org/faq.html#cloudflare). Start with the [Cap'n Proto Introduction](https://capnproto.org/index.html) for more detailed information on what this is about.

**<sup>1</sup> Changes from `capnp-ts`:**

- [x] Internal refactors and simplifications as was playing around.
- [x] Compiler, runtime, and std lib published via a single and compact ESM-only package with subpath exports.
- [x] Compiler updated to use Typescript v5 API
- [x] Output files can be `.ts` (new), `.js` (ESM instead of CJS), and `.d.ts` and has no `.capnp` suffix.
- [x] Compiler API can be used via the `capnp-es/compiler` subpath export programmatically.
- [x] Use native `TextEncoder` and `TextDecoder` for utf8 encoding
- [x] Enums are typed plain JS objects (this way `.ts` files work with strip-only ts loaders without enum support.)
- [x] Compiler CLI can directly accept path to `.capnp` files and internally use `capnpc`
- [ ] (WIP) Use reflection (getter setters) to access structs.
- [ ] (TODO) Investigate performannce. Seems some language features (specially on older Node.js) make full traverse slow.
- [ ] (planned) Investigate RPC level 1 (some progress [here](https://github.com/jdiaz5513/capnp-ts/pull/169))
- [ ] (planned) Investigate possibility of bundling wasm version of `capnp`

## Usage

> [!NOTE]
> Make sure `capnpc` command is available. You can find install instructions [here](https://capnproto.org/capnp-tool.html) to install it.
Make sure `capnpc` command is available. You can find install instructions [here](https://capnproto.org/install.html) to install it.

Run the following to compile a schema file into typeScript/javascript source code:

```shell
npx capnp-es --ts --dts --js path/to/myschema.capnp
# or pipe
```
or
```shell
capnpc -o- path/to/myschema.capnp | npx capnp-es --ts --dts --js
```

This will generate `path/to/myschema.{ts,d.ts,js}` (ESM syntax).

See [playground](./playground/) for examples and learn more about `.capnp` schema in capnp language [docs](https://capnproto.org/language.html).

## Reading Messages
### Reading Messages

Here's a quick usage example:

Expand All @@ -68,6 +47,30 @@ const message = capnp.Message.fromArrayBuffer(buffer);
const struct = message.getRoot(MyStruct);
```

## Status

This project is a rework<sup>1</sup> of [jdiaz5513/capnp-ts](https://github.com/jdiaz5513/capnp-ts/) by Julián Díaz and is under development.

- [x] Schema Compiler: working, may be missing features
- [x] Serialization: working, may be missing features
- [ ] RPC: not yet

**<sup>1</sup> Changes from `capnp-ts`:**

- [x] Internal refactors and simplifications as was playing around.
- [x] Compiler, runtime, and std lib published via a single and compact ESM-only package with subpath exports.
- [x] Compiler updated to use Typescript v5 API
- [x] Output files can be `.ts` (new), `.js` (ESM instead of CJS), and `.d.ts` and has no `.capnp` suffix.
- [x] Compiler API can be used via the `capnp-es/compiler` subpath export programmatically.
- [x] Use native `TextEncoder` and `TextDecoder` for utf8 encoding
- [x] Enums are typed plain JS objects (this way `.ts` files work with strip-only ts loaders without enum support.)
- [x] Compiler CLI can directly accept a path to `.capnp` files and internally use `capnpc`
- [ ] [WIP] Use reflection (getter setters) to access structs.
- [ ] [TODO] Investigate runtime performance. Some language features make full traverse slow. (especially on Node 20, Bun is fast and all good)
- [ ] [PLANNED] Investigate RPC level 1 (some progress [here](https://github.com/jdiaz5513/capnp-ts/pull/169))
- [ ] [PLANNED] Investigate the possibility of bundling the wasm version of `capnp`


## Development

<details>
Expand Down

0 comments on commit d31dc5e

Please sign in to comment.