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(ts): adds connect-es generated code (#184) #157

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion make/codegen.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.PHONY: proto-gen
ifeq ($(PROTO_LEGACY), true)
proto-gen: modvendor $(PROTOC) $(PROTOC_GEN_GOCOSMOS) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_DOC) $(AKASH_TS_NODE_MODULES) clean-codegen
mkdir -p $(AKASH_TS_ROOT)/src/generated
mkdir -p $(AKASH_TS_ROOT)/src/generated/ts-proto
mkdir -p $(AKASH_TS_ROOT)/src/generated/connect-es
./script/protocgen-legacy.sh
else
proto-gen: modvendor gogoproto $(BUF) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_GO)
Expand Down
16 changes: 14 additions & 2 deletions script/protocgen-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ for dir in $proto_dirs; do
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated/ts-proto" \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done
Expand Down Expand Up @@ -71,9 +71,21 @@ for dir in $proto_dirs; do
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated/ts-proto" \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true \
$(find "${dir}" -maxdepth 1 -name '*.proto')

.cache/bin/protoc \
-I "proto/provider" \
-I "proto/node" \
-I ".cache/include" \
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--es_out "${AKASH_TS_ROOT}/src/generated/connect-es" \
--es_opt target=ts \
--connect-es_out "${AKASH_TS_ROOT}/src/generated/connect-es" \
--connect-es_opt target=ts \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

# move proto files to the right places
Expand Down
3 changes: 2 additions & 1 deletion ts/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = {
collectCoverageFrom: [
'<rootDir>/src/**/*.{js,ts}',
'!<rootDir>/src/generated/**/*',
'!<rootDir>/src/patch/index.*',
'!<rootDir>/src/patch/**/index.*',
'!<rootDir>/src/connect-es-exports/index.*',
],
projects: [
{
Expand Down
93 changes: 93 additions & 0 deletions ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
},
"description": "Akash API TypeScript client",
"devDependencies": {
"@bufbuild/protoc-gen-es": "^1.9.0",
"@connectrpc/protoc-gen-connect-es": "^1.4.0",
"@semantic-release/commit-analyzer": "^12.0.0",
"@semantic-release/github": "^10.0.3",
"@semantic-release/release-notes-generator": "^13.0.0",
Expand Down Expand Up @@ -62,4 +64,4 @@
},
"types": "dist/index.d.ts",
"version": "0.0.0"
}
}
48 changes: 17 additions & 31 deletions ts/script/generate-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,28 @@

const fs = require('fs');
const path = require('path');
const staticExports = require('../static-exports.json');

const distDir = path.resolve(__dirname, '../dist/generated');
const distDir = path.resolve(__dirname, '../dist/generated/ts-proto');
const files = fs.readdirSync(distDir);
const TYPE_REGISTRY_PATH = './dist/generated/typeRegistry';
const paths = files.reduce(
(acc, file) => {
const match = file.match(/index.(.*)\.d\.ts/);
const paths = files.reduce((acc, file) => {
const match = file.match(/index.(.*)\.d\.ts/);

if (match) {
const dottedPath = match[1];
const slashedPath = dottedPath.replace(/\./g, '/');
const resolvedPath = fs.existsSync(`./dist/patch/index.${dottedPath}.js`)
? `./dist/patch/index.${dottedPath}`
: `./dist/generated/index.${dottedPath}`;
if (match) {
const dottedPath = match[1];
const slashedPath = dottedPath.replace(/\./g, '/');
const resolvedPath = fs.existsSync(
`./dist/patch/ts-proto/index.${dottedPath}.js`,
)
? `./dist/patch/ts-proto/index.${dottedPath}`
: `./dist/generated/ts-proto/index.${dottedPath}`;

acc.tsconfig[`@akashnetwork/akash-api/${slashedPath}`] = [resolvedPath];
acc.package[`./${slashedPath}`] = `${resolvedPath}.js`;
}
acc.tsconfig[`@akashnetwork/akash-api/${slashedPath}`] = [resolvedPath];
acc.package[`./${slashedPath}`] = `${resolvedPath}.js`;
}

return acc;
},
{
package: {
'./': './dist/index.js',
'./typeRegistry': `${TYPE_REGISTRY_PATH}.js`,
'./akash/deployment/v1beta3/query':
'./dist/generated/akash/deployment/v1beta3/query.js',
},
tsconfig: {
'@akashnetwork/akash-api/typeRegistry': [TYPE_REGISTRY_PATH],
'@akashnetwork/akash-api/akash/deployment/v1beta3/query': [
'./dist/generated/akash/deployment/v1beta3/query',
],
},
},
);
return acc;
}, staticExports);

const tsconfigPaths = path.resolve(__dirname, '../tsconfig.paths.json');
fs.writeFileSync(
Expand Down
1 change: 1 addition & 0 deletions ts/src/connect-es-exports/index.akash.inventory.v1.es.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../generated/connect-es/akash/inventory/v1/resources_pb';
2 changes: 2 additions & 0 deletions ts/src/connect-es-exports/index.akash.provider.v1.es.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../generated/connect-es/akash/provider/v1/service_connect';
export * from '../generated/connect-es/akash/provider/v1/status_pb';
73 changes: 73 additions & 0 deletions ts/src/generated/connect-es/akash/inventory/v1/cluster_pb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// @generated by protoc-gen-es v1.9.0 with parameter "target=ts"
// @generated from file akash/inventory/v1/cluster.proto (package akash.inventory.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type {
BinaryReadOptions,
FieldList,
JsonReadOptions,
JsonValue,
PartialMessage,
PlainMessage,
} from '@bufbuild/protobuf';
import { Message, proto3 } from '@bufbuild/protobuf';
import { Node } from './node_pb.js';
import { Storage } from './storage_pb.js';

/**
* Cluster reports inventory across entire cluster
*
* @generated from message akash.inventory.v1.Cluster
*/
export class Cluster extends Message<Cluster> {
/**
* @generated from field: repeated akash.inventory.v1.Node nodes = 1;
*/
nodes: Node[] = [];

/**
* @generated from field: repeated akash.inventory.v1.Storage storage = 2;
*/
storage: Storage[] = [];

constructor(data?: PartialMessage<Cluster>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = 'akash.inventory.v1.Cluster';
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'nodes', kind: 'message', T: Node, repeated: true },
{ no: 2, name: 'storage', kind: 'message', T: Storage, repeated: true },
]);

static fromBinary(
bytes: Uint8Array,
options?: Partial<BinaryReadOptions>,
): Cluster {
return new Cluster().fromBinary(bytes, options);
}

static fromJson(
jsonValue: JsonValue,
options?: Partial<JsonReadOptions>,
): Cluster {
return new Cluster().fromJson(jsonValue, options);
}

static fromJsonString(
jsonString: string,
options?: Partial<JsonReadOptions>,
): Cluster {
return new Cluster().fromJsonString(jsonString, options);
}

static equals(
a: Cluster | PlainMessage<Cluster> | undefined,
b: Cluster | PlainMessage<Cluster> | undefined,
): boolean {
return proto3.util.equals(Cluster, a, b);
}
}
Loading
Loading