All Projects → ButterCam → sisyphus-js

ButterCam / sisyphus-js

Licence: MIT license
Sisyphus customized protobuf and gRPC runtime and code generator for JavaScript/TypeScript

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sisyphus-js

Kroto Plus
gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc
Stars: ✭ 400 (+2005.26%)
Mutual labels:  protobuf, code-generation
gapic-generator-python
Generate Python API client libraries from Protocol Buffers.
Stars: ✭ 74 (+289.47%)
Mutual labels:  protobuf, code-generation
Clay
Proto-first minimal server platform for gRPС+REST+Swagger APIs
Stars: ✭ 212 (+1015.79%)
Mutual labels:  protobuf
go-recipes
🦩 Tools for Go projects
Stars: ✭ 2,490 (+13005.26%)
Mutual labels:  code-generation
Quick Protobuf
A rust implementation of protobuf parser
Stars: ✭ 244 (+1184.21%)
Mutual labels:  protobuf
Jackson Dataformats Binary
Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Stars: ✭ 221 (+1063.16%)
Mutual labels:  protobuf
JavaSteam
Java library that provides an interface to directly interact with Valve's Steam servers.
Stars: ✭ 70 (+268.42%)
Mutual labels:  protobuf
Gametracking
🛢 Dumping things, so you don't have to
Stars: ✭ 204 (+973.68%)
Mutual labels:  protobuf
GameTracking-HalfLifeAlyx
📥 Game Tracker: Half-Life: Alyx
Stars: ✭ 24 (+26.32%)
Mutual labels:  protobuf
Unitysocketprotobuf3demo
主要实现了用Unity对接了Leaf服务器。其次带了些小工具。
Stars: ✭ 244 (+1184.21%)
Mutual labels:  protobuf
raster
A micro server framework, support coroutine, and parallel-computing, used for building flatbuffers/thrift/protobuf/http protocol service.
Stars: ✭ 19 (+0%)
Mutual labels:  protobuf
Protoman
Postman for protobuf APIs
Stars: ✭ 241 (+1168.42%)
Mutual labels:  protobuf
Protobuf Jetbrains Plugin
Protobuf Support for JetBrains IDEs
Stars: ✭ 226 (+1089.47%)
Mutual labels:  protobuf
flyteidl
Specification of the IR for Flyte workflows and tasks. Also Interfaces for all backend services. https://docs.flyte.org/projects/flyteidl/en/stable/
Stars: ✭ 27 (+42.11%)
Mutual labels:  protobuf
Protoc Gen Lint
A plug-in for Google's Protocol Buffers (protobufs) compiler to lint .proto files for style violations.
Stars: ✭ 221 (+1063.16%)
Mutual labels:  protobuf
go-chat
go-chat.使用Go基于WebSocket开发的web聊天应用。单聊,群聊。文字,图片,语音,视频消息,屏幕共享,剪切板图片,基于WebRTC的P2P语音通话,视频聊天。
Stars: ✭ 516 (+2615.79%)
Mutual labels:  protobuf
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (+984.21%)
Mutual labels:  protobuf
Gordon cnn
A small convolution neural network deep learning framework implemented in c++.
Stars: ✭ 241 (+1168.42%)
Mutual labels:  protobuf
Play Store Api
Google Play Store protobuf API wrapper in java
Stars: ✭ 249 (+1210.53%)
Mutual labels:  protobuf
opensbli
A framework for the automated derivation and parallel execution of finite difference solvers on a range of computer architectures.
Stars: ✭ 56 (+194.74%)
Mutual labels:  code-generation

为 JavaScript/TypeScript 打造的 Sisyphus

sisyphus.js 是专为 JavaScript/TypeScript 编写的 Protobuf 运行时,专为减少生成代码的大小而优化,即便如此,仍然可以在 sisyphus.js 获得不打折扣的 Protobuf 体验。

当采用 HTTP 与 gRPC 转码 标准时,由于 sisyphus.js 通过 Json 接口 来访问 Protobuf 消息实体,sisyphus.js 能够最大程度的降低代码大小,但在此应用场景中不支持 Protobuf 二进制格式。

快速开始

1. 安装

通过以下指令安装 @sisyphus.js/cliTypeScript

npm i @sisyphus.js/cli typescript --save-dev

@sisyphus.js/cli 用于安装 sisygen 命令来生成 TypeScript 代码,typescript 用于编译生成的 TypeScript 为 JavaScript。

2. 生成代码

将需要编译的 .proto 文件放入项目下的 proto 文件夹中(也可以通过 package.jsondirectories 属性自定义 )

{
  "directories": {
    "proto": "other-proto-sources"
  }
}

将 sisygen 命令加入到工程脚本中,并且添加一些生成时使用的 protoc 编译插件。

{
  "scripts": {
    "protoc": "sisygen -O ./src"
  },
  "protobuf": {
    "plugins": [
      "core",
      "aip"
    ]
  }
}

sisyphus.js 内置三个编译插件:

  • core 用于生成基础的 Protobuf 消息实体访问 Json 接口,需要添加 @sisyphus.js/runtime 运行时依赖。
  • proto 用于生成支持 Protobuf 二进制格式的代码,需要添加 @sisyphus.js/runtime.proto 运行时依赖。
  • aip 用于生成基于 HTTP 与 gRPC 转码标准的客户端,需要添加 @sisyphus.js/transport-aip@sisyphus.js/google 运行时依赖,额外需要添加 @sisyphus.js/google.proto 作为编译时的依赖(devDependencies)。

安装生成的代码所需的运行时。

npm i @sisyphus.js/runtime @sisyphus.js/google @sisyphus.js/transport-aip --save
npm i @sisyphus.js/google.proto --save-dev

使用 npm run 来编译 proto 文件。

npm run protoc

3. 访问 Protobuf 消息实体

sisyphus.js 会将以下 Protobuf 代码生成为 TypeScript 接口。

message EchoRequest {
    oneof response {
        // The content to be echoed by the server.
        string content = 1;

        // The error to be thrown by the server.
        google.rpc.Status error = 2;
    }

    // The severity to be echoed by the server.
    Severity severity = 3;

    // Optional. This field can be set to test the routing annotation on the Echo method.
    string header = 4;

    // Optional. This field can be set to test the routing annotation on the Echo method.
    string other_header = 5;
}

sisyphus.js core 插件仅会为每个 Protobuf 消息生成一个接口与一个用于拓展的同名的 namespace。 生成的接口严格遵循 Json 映射标准

export interface EchoRequest {
    /**  The content to be echoed by the server. */
    content?: string

    /**  The error to be thrown by the server. */
    error?: Status

    /**  The severity to be echoed by the server. */
    severity?: Severity

    /**  Optional. This field can be set to test the routing annotation on the Echo method. */
    header?: string

    /**  Optional. This field can be set to test the routing annotation on the Echo method. */
    otherHeader?: string
}

export namespace EchoRequest {
    export const name = 'google.showcase.v1beta1.EchoRequest'
}

在 TypeScript 中使用类型标注与对象构建语法来创建 Protobuf 消息实体。

const message: EchoRequest = {
    content: "Hello world!"
}
  1. 通过 AIP 访问 gRPC API

使用 AIP 插件编译的代码可以简单访问 gRPC API(需要服务端支持)。

import {EchoResponse} from './google/showcase/v1beta1/echo'
import {Echo} from './google/showcase/v1beta1/echo.aip'
import {transcoding} from '@sisyphus.js/transport-aip'

const client = Echo.aipClient(transcoding('http://localhost:8080'))
const output: EchoResponse = await client.echo({
    content: "Hello world!"
})

通过 transcoding 方法指定一个 host 即可开始访问 API。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].