Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@yongenaelf/protobuf-generator-ts

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yongenaelf/protobuf-generator-ts

`@yongenaelf/protobuf-generator-ts` is an npm library designed to generate TypeScript code from Protocol Buffers (protobuf) definitions. This tool helps streamline the process of integrating protobuf with TypeScript projects.

  • 1.0.2
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@yongenaelf/protobuf-generator-ts

@yongenaelf/protobuf-generator-ts is an npm library designed to generate TypeScript code from Protocol Buffers (protobuf) definitions. This tool helps streamline the process of integrating protobuf with TypeScript projects.

Installation

To install the library, use npm or yarn:

npm install @yongenaelf/protobuf-generator-ts

Usage

import { generateProtoFile, ProtoFile } from '@yongenaelf/protobuf-generator-ts';

const testAST: ProtoFile = {
  syntax: "proto3",
  package: "",  // No package for this file
  imports: [
      "aelf/options.proto",
      "google/protobuf/empty.proto",
      "google/protobuf/wrappers.proto",
      "Protobuf/reference/acs12.proto"
  ],

  messages: [
      {
          name: "UpdatedMessage",
          fields: [
              { name: "value", type: "string", id: 1 }
          ],
          options: {
              "aelf.is_event": "true",
          }
      }
  ],

  services: [
      {
          name: "HelloWorld",
          options: [
              { key: "aelf.csharp_state", value: `"AElf.Contracts.HelloWorld.HelloWorldState"` },
              { key: "aelf.base", value: `"Protobuf/reference/acs12.proto"` }
          ],
          methods: [
              {
                  name: "Update",
                  inputType: "google.protobuf.StringValue",
                  outputType: "google.protobuf.Empty"
              },
              {
                  name: "Read",
                  inputType: "google.protobuf.Empty",
                  outputType: "google.protobuf.StringValue",
                  options: [
                      { key: "aelf.is_view", value: "true" }
                  ]
              }
          ]
      }
  ],

  options: {
      "csharp_namespace": `"AElf.Contracts.HelloWorld"`
  }
};

generateProtoFile(testAST)

Expected output:

syntax = "proto3";

import "aelf/options.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
import "Protobuf/reference/acs12.proto";

option csharp_namespace = "AElf.Contracts.HelloWorld";

service HelloWorld {
  option (aelf.csharp_state) = "AElf.Contracts.HelloWorld.HelloWorldState";
  option (aelf.base) = "Protobuf/reference/acs12.proto";

  rpc Update (google.protobuf.StringValue) returns (google.protobuf.Empty);
  rpc Read (google.protobuf.Empty) returns (google.protobuf.StringValue) {
    option (aelf.is_view) = true;
  }
}

message UpdatedMessage {
  option (aelf.is_event) = true;
  string value = 1;
}

FAQs

Package last updated on 02 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc