From 6eb94df2937f3ca9cebdbe6ff9bc40b213a522ab Mon Sep 17 00:00:00 2001 From: Ian Denhardt Date: Mon, 21 Sep 2020 15:56:16 -0400 Subject: [PATCH] Add a typescript declaration file. This covers most of the API that is documented in the README, though I see that there are some things exposed in `capnp.js` but not documented -- the declaration file does not currently cover those. This is designed to work with the output of: https://github.com/zenhack/capnpc-node-typescript ...which is nearing completion. --- package.json | 1 + src/node-capnp/capnp.d.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/node-capnp/capnp.d.ts diff --git a/package.json b/package.json index 841e7c4..14bbda3 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ } ], "main": "src/node-capnp/capnp.js", + "types": "src/node-capnp/capnp.d.ts", "scripts": { "install": "node ./build.js", "test": "node src/node-capnp/capnp-test.js" diff --git a/src/node-capnp/capnp.d.ts b/src/node-capnp/capnp.d.ts new file mode 100644 index 0000000..708948b --- /dev/null +++ b/src/node-capnp/capnp.d.ts @@ -0,0 +1,35 @@ +declare module Capnp { + type Id = string; + + abstract class StructSchema { + typeId: Id; + } + + abstract class InterfaceSchema { + typeId: Id; + } + + interface AnyServer { + close?: () => void; + } + + interface AnyClient { + close(): void; + closed: boolean; + castAs(schema: InterfaceSchema): Client; + } + + const Capability: { + new(server: Server, schema: InterfaceSchema): Client; + } + + abstract class Connection { + restore(exportName: string, type: InterfaceSchema): Client; + close(): void; + } + + function parse(type: StructSchema, buffer: Buffer): Reader; + function serialize(type: StructSchema, reader: Reader): Buffer; + function connect(addr: string): Connection; +} +export default Capnp;