Skip to content

Commit

Permalink
feat(ts): adds connect-es generated code (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Apr 24, 2024
1 parent b7813c9 commit 6c3667b
Show file tree
Hide file tree
Showing 247 changed files with 4,105 additions and 54 deletions.
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.

76 changes: 74 additions & 2 deletions 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 @@ -61,5 +63,75 @@
"test:watch": "jest --selectProjects unit functional --watch"
},
"types": "dist/index.d.ts",
"version": "0.0.0"
}
"version": "0.0.0",
"exports": {
"./": "./dist/index.js",
"./typeRegistry": "./dist/generated/typeRegistry",
"./akash/deployment/v1beta3/query": "./dist/generated/akash/deployment/v1beta3/query.js",
"./akash/provider/v1/es": "./dist/connect-es-exports/index.akash.provider.v1.es.js",
"./akash/inventory/v1/es": "./dist/connect-es-exports/index.akash.inventory.v1.es.js",
"./akash/audit": "./dist/generated/ts-proto/index.akash.audit.js",
"./akash/audit/v1beta1": "./dist/generated/ts-proto/index.akash.audit.v1beta1.js",
"./akash/audit/v1beta2": "./dist/generated/ts-proto/index.akash.audit.v1beta2.js",
"./akash/audit/v1beta3": "./dist/generated/ts-proto/index.akash.audit.v1beta3.js",
"./akash/base": "./dist/generated/ts-proto/index.akash.base.js",
"./akash/base/v1beta1": "./dist/generated/ts-proto/index.akash.base.v1beta1.js",
"./akash/base/v1beta2": "./dist/generated/ts-proto/index.akash.base.v1beta2.js",
"./akash/base/v1beta3": "./dist/patch/ts-proto/index.akash.base.v1beta3.js",
"./akash/cert": "./dist/generated/ts-proto/index.akash.cert.js",
"./akash/cert/v1beta2": "./dist/generated/ts-proto/index.akash.cert.v1beta2.js",
"./akash/cert/v1beta3": "./dist/generated/ts-proto/index.akash.cert.v1beta3.js",
"./akash": "./dist/generated/ts-proto/index.akash.js",
"./akash/deployment": "./dist/generated/ts-proto/index.akash.deployment.js",
"./akash/deployment/v1beta1": "./dist/generated/ts-proto/index.akash.deployment.v1beta1.js",
"./akash/deployment/v1beta2": "./dist/patch/ts-proto/index.akash.deployment.v1beta2.js",
"./akash/deployment/v1beta3": "./dist/patch/ts-proto/index.akash.deployment.v1beta3.js",
"./akash/discovery": "./dist/generated/ts-proto/index.akash.discovery.js",
"./akash/discovery/v1": "./dist/generated/ts-proto/index.akash.discovery.v1.js",
"./akash/escrow": "./dist/generated/ts-proto/index.akash.escrow.js",
"./akash/escrow/v1beta1": "./dist/generated/ts-proto/index.akash.escrow.v1beta1.js",
"./akash/escrow/v1beta2": "./dist/generated/ts-proto/index.akash.escrow.v1beta2.js",
"./akash/escrow/v1beta3": "./dist/generated/ts-proto/index.akash.escrow.v1beta3.js",
"./akash/gov": "./dist/generated/ts-proto/index.akash.gov.js",
"./akash/gov/v1beta3": "./dist/generated/ts-proto/index.akash.gov.v1beta3.js",
"./akash/inflation": "./dist/generated/ts-proto/index.akash.inflation.js",
"./akash/inflation/v1beta2": "./dist/generated/ts-proto/index.akash.inflation.v1beta2.js",
"./akash/inflation/v1beta3": "./dist/generated/ts-proto/index.akash.inflation.v1beta3.js",
"./akash/inventory": "./dist/generated/ts-proto/index.akash.inventory.js",
"./akash/inventory/v1": "./dist/generated/ts-proto/index.akash.inventory.v1.js",
"./akash/manifest": "./dist/generated/ts-proto/index.akash.manifest.js",
"./akash/manifest/v2beta1": "./dist/generated/ts-proto/index.akash.manifest.v2beta1.js",
"./akash/manifest/v2beta2": "./dist/generated/ts-proto/index.akash.manifest.v2beta2.js",
"./akash/market": "./dist/generated/ts-proto/index.akash.market.js",
"./akash/market/v1beta2": "./dist/generated/ts-proto/index.akash.market.v1beta2.js",
"./akash/market/v1beta3": "./dist/generated/ts-proto/index.akash.market.v1beta3.js",
"./akash/market/v1beta4": "./dist/generated/ts-proto/index.akash.market.v1beta4.js",
"./akash/provider": "./dist/generated/ts-proto/index.akash.provider.js",
"./akash/provider/lease": "./dist/generated/ts-proto/index.akash.provider.lease.js",
"./akash/provider/lease/v1": "./dist/generated/ts-proto/index.akash.provider.lease.v1.js",
"./akash/provider/v1": "./dist/generated/ts-proto/index.akash.provider.v1.js",
"./akash/provider/v1beta1": "./dist/generated/ts-proto/index.akash.provider.v1beta1.js",
"./akash/provider/v1beta2": "./dist/generated/ts-proto/index.akash.provider.v1beta2.js",
"./akash/provider/v1beta3": "./dist/generated/ts-proto/index.akash.provider.v1beta3.js",
"./akash/staking": "./dist/generated/ts-proto/index.akash.staking.js",
"./akash/staking/v1beta3": "./dist/generated/ts-proto/index.akash.staking.v1beta3.js",
"./akash/take": "./dist/generated/ts-proto/index.akash.take.js",
"./akash/take/v1beta3": "./dist/generated/ts-proto/index.akash.take.v1beta3.js",
"./cosmos/base": "./dist/generated/ts-proto/index.cosmos.base.js",
"./cosmos/base/query": "./dist/generated/ts-proto/index.cosmos.base.query.js",
"./cosmos/base/query/v1beta1": "./dist/generated/ts-proto/index.cosmos.base.query.v1beta1.js",
"./cosmos/base/v1beta1": "./dist/generated/ts-proto/index.cosmos.base.v1beta1.js",
"./cosmos": "./dist/generated/ts-proto/index.cosmos.js",
"./cosmos_proto": "./dist/generated/ts-proto/index.cosmos_proto.js",
"./gogoproto": "./dist/generated/ts-proto/index.gogoproto.js",
"./google/api": "./dist/generated/ts-proto/index.google.api.js",
"./google": "./dist/generated/ts-proto/index.google.js",
"./google/protobuf": "./dist/generated/ts-proto/index.google.protobuf.js",
"./k8s": "./dist/generated/ts-proto/index.k8s.js",
"./k8s/io/apimachinery": "./dist/generated/ts-proto/index.k8s.io.apimachinery.js",
"./k8s/io/apimachinery/pkg/api": "./dist/generated/ts-proto/index.k8s.io.apimachinery.pkg.api.js",
"./k8s/io/apimachinery/pkg/api/resource": "./dist/generated/ts-proto/index.k8s.io.apimachinery.pkg.api.resource.js",
"./k8s/io/apimachinery/pkg": "./dist/generated/ts-proto/index.k8s.io.apimachinery.pkg.js",
"./k8s/io": "./dist/generated/ts-proto/index.k8s.io.js"
}
}
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

0 comments on commit 6c3667b

Please sign in to comment.