Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate typescript bindings #825

Merged
merged 12 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ proto:
@buf format -w
.PHONY: proto

typescript:
lumtis marked this conversation as resolved.
Show resolved Hide resolved
@echo "--> Generating TypeScript bindings"
@bash ./scripts/protoc-gen-typescript.sh
.PHONY: typescript

proto-format:
@bash ./scripts/proto-format.sh

Expand All @@ -179,14 +184,14 @@ docs-zetacored:
@bash ./scripts/gen-docs-zetacored.sh
.PHONY: docs-zetacored

generate: proto openapi specs docs-zetacored
.PHONY: generate

mocks:
@echo "--> Generating mocks"
@bash ./scripts/mocks-generate.sh
.PHONY: mocks

generate: proto openapi specs typescript docs-zetacored
.PHONY: generate

###############################################################################
### Docker Images ###
###############################################################################
Expand Down
7 changes: 7 additions & 0 deletions proto/buf.ts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
managed:
enabled: true
plugins:
- plugin: buf.build/bufbuild/es:v1.3.0
out: ../typescript
opt: target=dts
38 changes: 38 additions & 0 deletions scripts/protoc-gen-typescript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

DIR="typescript"

rm -rf $DIR

(cd proto && buf generate --template buf.ts.yaml)

cat <<EOL > $DIR/package.json
{
"name": "@zetachain/blockchain-types",
"version": "0.0.0-set-on-publish",
"description": "",
"main": "",
"keywords": [],
"author": "ZetaChain",
"license": "MIT"
}
EOL

# Loop through all directories recursively
find "$DIR" -type d | while read -r dir; do
# Check if there are any .d.ts files in the directory
if ls "$dir"/*.d.ts &> /dev/null; then
# Create or clear index.d.ts in the directory
> "$dir/index.d.ts"

# Loop through all .d.ts files in the directory
for file in "$dir"/*.d.ts; do
# Extract the base filename without the .d.ts extension
base_name=$(basename "$file" .d.ts)
# If the base name is not 'index', append the export line to index.d.ts
if [ "$base_name" != "index" ]; then
echo "export * from \"./$base_name\";" >> "$dir/index.d.ts"
fi
done
fi
done
42 changes: 42 additions & 0 deletions typescript/common/bitcoin/bitcoin_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @generated by protoc-gen-es v1.3.0 with parameter "target=dts"
// @generated from file common/bitcoin/bitcoin.proto (package bitcoin, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";

/**
* @generated from message bitcoin.Proof
*/
export declare class Proof extends Message<Proof> {
/**
* @generated from field: bytes tx_bytes = 1;
*/
txBytes: Uint8Array;

/**
* @generated from field: bytes path = 2;
*/
path: Uint8Array;

/**
* @generated from field: uint32 index = 3;
*/
index: number;

constructor(data?: PartialMessage<Proof>);

static readonly runtime: typeof proto3;
static readonly typeName = "bitcoin.Proof";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Proof;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Proof;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Proof;

static equals(a: Proof | PlainMessage<Proof> | undefined, b: Proof | PlainMessage<Proof> | undefined): boolean;
}

1 change: 1 addition & 0 deletions typescript/common/bitcoin/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./bitcoin_pb";
Loading
Loading