├── BUILD.bazel ├── .nvmrc ├── .gitattributes ├── bin ├── protoc-gen-ts └── protoc-gen-ts.cmd ├── .npmignore ├── examples ├── generated-grpc-node │ └── proto │ │ ├── examplecom │ │ ├── casing_grpc_pb.js │ │ ├── simple_grpc_pb.js │ │ ├── annotations_grpc_pb.js │ │ ├── casing_grpc_pb.d.ts │ │ ├── enum_message_grpc_pb.js │ │ ├── map_message_grpc_pb.js │ │ ├── oneof_message_grpc_pb.js │ │ ├── reserved_words_grpc_pb.js │ │ ├── simple_grpc_pb.d.ts │ │ ├── simplevalue_grpc_pb.js │ │ ├── annotations_grpc_pb.d.ts │ │ ├── enum_message_grpc_pb.d.ts │ │ ├── map_message_grpc_pb.d.ts │ │ ├── oneof_message_grpc_pb.d.ts │ │ ├── parent_message_v2_grpc_pb.js │ │ ├── parent_message_v3_grpc_pb.js │ │ ├── primitive_message_v2_grpc_pb.js │ │ ├── primitive_message_v3_grpc_pb.js │ │ ├── simplevalue_grpc_pb.d.ts │ │ ├── well_known_message_grpc_pb.js │ │ ├── empty_message_no_service_grpc_pb.js │ │ ├── parent_message_v2_grpc_pb.d.ts │ │ ├── parent_message_v3_grpc_pb.d.ts │ │ ├── reserved_words_grpc_pb.d.ts │ │ ├── well_known_message_grpc_pb.d.ts │ │ ├── primitive_message_v2_grpc_pb.d.ts │ │ ├── primitive_message_v3_grpc_pb.d.ts │ │ ├── repeated_primitive_message_grpc_pb.js │ │ ├── empty_message_no_service_grpc_pb.d.ts │ │ ├── repeated_primitive_message_grpc_pb.d.ts │ │ ├── empty_message_no_service_pb.d.ts │ │ ├── annotations_pb.d.ts │ │ ├── casing_pb.d.ts │ │ ├── simplevalue_pb.d.ts │ │ ├── primitive_message_v3_pb.d.ts │ │ ├── enum_message_pb.d.ts │ │ ├── simple_service_pb.d.ts │ │ ├── map_message_pb.d.ts │ │ ├── parent_message_v3_pb.d.ts │ │ ├── simple_service_grpc_pb.d.ts │ │ ├── parent_message_v2_pb.d.ts │ │ └── repeated_primitive_message_pb.d.ts │ │ ├── othercom │ │ ├── external_enum_grpc_pb.js │ │ ├── external_child_message_grpc_pb.js │ │ ├── external_enum_grpc_pb.d.ts │ │ ├── external_child_message_grpc_pb.d.ts │ │ ├── external_enum_pb.d.ts │ │ ├── external_enum_pb.js │ │ └── external_child_message_pb.d.ts │ │ ├── orphan_grpc_pb.d.ts │ │ ├── orphan_grpc_pb.js │ │ └── orphan_pb.d.ts ├── generated-grpc-web │ └── proto │ │ ├── examplecom │ │ ├── casing_pb_service.d.ts │ │ ├── casing_pb_service.js │ │ ├── simple_pb_service.d.ts │ │ ├── simple_pb_service.js │ │ ├── annotations_pb_service.d.ts │ │ ├── annotations_pb_service.js │ │ ├── enum_message_pb_service.js │ │ ├── map_message_pb_service.d.ts │ │ ├── map_message_pb_service.js │ │ ├── simplevalue_pb_service.d.ts │ │ ├── simplevalue_pb_service.js │ │ ├── enum_message_pb_service.d.ts │ │ ├── oneof_message_pb_service.d.ts │ │ ├── oneof_message_pb_service.js │ │ ├── reserved_words_pb_service.d.ts │ │ ├── reserved_words_pb_service.js │ │ ├── parent_message_v2_pb_service.js │ │ ├── parent_message_v3_pb_service.js │ │ ├── parent_message_v2_pb_service.d.ts │ │ ├── parent_message_v3_pb_service.d.ts │ │ ├── primitive_message_v2_pb_service.js │ │ ├── primitive_message_v3_pb_service.js │ │ ├── well_known_message_pb_service.d.ts │ │ ├── well_known_message_pb_service.js │ │ ├── primitive_message_v2_pb_service.d.ts │ │ ├── primitive_message_v3_pb_service.d.ts │ │ ├── empty_message_no_service_pb_service.d.ts │ │ ├── empty_message_no_service_pb_service.js │ │ ├── repeated_primitive_message_pb_service.d.ts │ │ ├── repeated_primitive_message_pb_service.js │ │ ├── empty_message_no_service_pb.d.ts │ │ ├── annotations_pb.d.ts │ │ ├── casing_pb.d.ts │ │ ├── simplevalue_pb.d.ts │ │ ├── primitive_message_v3_pb.d.ts │ │ ├── enum_message_pb.d.ts │ │ ├── simple_service_pb.d.ts │ │ ├── map_message_pb.d.ts │ │ ├── parent_message_v3_pb.d.ts │ │ └── parent_message_v2_pb.d.ts │ │ ├── othercom │ │ ├── external_enum_pb_service.js │ │ ├── external_enum_pb_service.d.ts │ │ ├── external_child_message_pb_service.d.ts │ │ ├── external_child_message_pb_service.js │ │ ├── external_enum_pb.d.ts │ │ ├── external_enum_pb.js │ │ └── external_child_message_pb.d.ts │ │ ├── orphan_pb_service.d.ts │ │ ├── orphan_pb_service.js │ │ └── orphan_pb.d.ts └── generated │ └── proto │ ├── othercom │ ├── external_enum_pb.d.ts │ ├── external_enum_pb.js │ └── external_child_message_pb.d.ts │ ├── examplecom │ ├── empty_message_no_service_pb.d.ts │ ├── annotations_pb.d.ts │ ├── casing_pb.d.ts │ ├── simplevalue_pb.d.ts │ ├── primitive_message_v3_pb.d.ts │ ├── enum_message_pb.d.ts │ ├── simple_service_pb.d.ts │ ├── map_message_pb.d.ts │ ├── parent_message_v3_pb.d.ts │ ├── parent_message_v2_pb.d.ts │ └── repeated_primitive_message_pb.d.ts │ └── orphan_pb.d.ts ├── proto ├── examplecom │ ├── empty_message_no_service.proto │ ├── casing.proto │ ├── annotations.proto │ ├── parent_message_v3.proto │ ├── enum_message.proto │ ├── primitive_message_v3.proto │ ├── parent_message_v2.proto │ ├── repeated_primitive_message.proto │ ├── map_message.proto │ ├── simplevalue.proto │ ├── oneof_message.proto │ ├── simple_service.proto │ ├── well_known_message.proto │ ├── primitive_message_v2.proto │ ├── simple.proto │ └── reserved_words.proto ├── othercom │ ├── external_child_message.proto │ └── external_enum.proto └── orphan.proto ├── .gitignore ├── WORKSPACE ├── travis-ci-build.sh ├── src ├── Printer.ts ├── CodePrinter.ts ├── ts │ ├── enum.ts │ ├── oneof.ts │ ├── extensions.ts │ ├── fileDescriptorTSD.ts │ └── FieldTypes.ts ├── WellKnown.ts ├── ExportMap.ts ├── index.ts └── util.ts ├── defs.bzl ├── test ├── integration │ ├── casing.ts │ ├── annotations.ts │ ├── orphan.ts │ ├── enums.ts │ ├── oneof.ts │ └── repeatedPrimitives.ts ├── mocha-check-report.js ├── mocha-run-suite.js └── unit │ └── util.ts ├── tsconfig.json ├── .github └── stale.yml ├── CONTRIBUTING.md ├── tslint.json ├── package.json ├── release.sh ├── .travis.yml ├── CODE_OF_CONDUCT.md └── generate.js /BUILD.bazel: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v12.13.0 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | examples/generated/** linguist-generated=true -------------------------------------------------------------------------------- /bin/protoc-gen-ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/index'); 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test/ 2 | src/ 3 | .* 4 | release.sh 5 | generate.sh 6 | examples/ 7 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/casing_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/simple_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/annotations_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/casing_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/enum_message_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/map_message_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/oneof_message_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/reserved_words_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/simple_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/simplevalue_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/othercom/external_enum_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/annotations_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/enum_message_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/map_message_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/oneof_message_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/parent_message_v2_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/parent_message_v3_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/primitive_message_v2_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/primitive_message_v3_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/simplevalue_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/well_known_message_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/othercom/external_child_message_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/othercom/external_enum_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/empty_message_no_service_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/parent_message_v2_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/parent_message_v3_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/reserved_words_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/well_known_message_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/primitive_message_v2_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/primitive_message_v3_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/repeated_primitive_message_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/othercom/external_child_message_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /proto/examplecom/empty_message_no_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | message NoService {} -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/empty_message_no_service_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/repeated_primitive_message_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- NO SERVICES IN PROTO 2 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/casing_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/casing.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/casing_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/casing.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/simple_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simple.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/simple_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simple.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/othercom/external_enum_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_enum.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/annotations_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/annotations.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/annotations_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/annotations.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/enum_message_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/enum_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/map_message_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/map_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/map_message_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/map_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/simplevalue_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simplevalue.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/simplevalue_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simplevalue.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/othercom/external_enum_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_enum.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/enum_message_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/enum_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/oneof_message_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/oneof_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/oneof_message_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/oneof_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/reserved_words_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/reserved_words.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/reserved_words_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/reserved_words.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/parent_message_v2_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v2.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/parent_message_v3_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v3.proto 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | node_modules 3 | node-debug.log 4 | .idea/ 5 | npm-debug* 6 | lib/ 7 | **/mocha-report.json 8 | bazel-* 9 | protoc/ 10 | .ijwb/ 11 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/parent_message_v2_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v2.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/parent_message_v3_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v3.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/primitive_message_v2_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/primitive_message_v2.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/primitive_message_v3_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/primitive_message_v3.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/well_known_message_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/well_known_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/well_known_message_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/well_known_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/othercom/external_child_message_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_child_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/othercom/external_child_message_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_child_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/primitive_message_v2_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/primitive_message_v2.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/primitive_message_v3_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/primitive_message_v3.proto 3 | 4 | -------------------------------------------------------------------------------- /proto/othercom/external_child_message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package othercom; 4 | 5 | message ExternalChildMessage { 6 | string my_string = 1; 7 | } 8 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/empty_message_no_service_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/empty_message_no_service.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/empty_message_no_service_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/empty_message_no_service.proto 3 | 4 | -------------------------------------------------------------------------------- /proto/othercom/external_enum.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package othercom; 4 | 5 | enum ExternalEnum { 6 | DEFAULT = 0; 7 | FIRST = 1; 8 | SECOND = 2; 9 | } -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace( 2 | name = "ts_protoc_gen", 3 | ) 4 | 5 | load("@ts_protoc_gen//:defs.bzl", "typescript_proto_dependencies") 6 | 7 | typescript_proto_dependencies() 8 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/repeated_primitive_message_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/repeated_primitive_message.proto 3 | 4 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/repeated_primitive_message_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/repeated_primitive_message.proto 3 | 4 | -------------------------------------------------------------------------------- /bin/protoc-gen-ts.cmd: -------------------------------------------------------------------------------- 1 | @IF EXIST "%~dp0\node.exe" ( 2 | "%~dp0\node.exe" "%~dp0\..\lib\index.js" %* 3 | ) ELSE ( 4 | @SETLOCAL 5 | @SET PATHEXT=%PATHEXT:;.JS;=;% 6 | node "%~dp0\..\lib\index.js" %* 7 | ) 8 | -------------------------------------------------------------------------------- /proto/examplecom/casing.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | message CasingMessage { 6 | string TitleCase = 1; 7 | string camelCase = 2; 8 | string snake_case = 3; 9 | string _leadingUnderscoreCamelCase = 4; 10 | string _LeadingUnderscoreTitleCase = 5; 11 | } 12 | -------------------------------------------------------------------------------- /travis-ci-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | 4 | npm run lint 5 | npm test 6 | 7 | npm run generate 8 | MODIFIED_FILES=$(git diff --name-only) 9 | if [[ -n $MODIFIED_FILES ]]; then 10 | echo "ERROR: Changes detected in generated code, please run 'npm run generate' and check-in the changes." 11 | exit 1 12 | fi 13 | -------------------------------------------------------------------------------- /examples/generated/proto/othercom/external_enum_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_enum.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export interface ExternalEnumMap { 7 | DEFAULT: 0; 8 | FIRST: 1; 9 | SECOND: 2; 10 | } 11 | 12 | export const ExternalEnum: ExternalEnumMap; 13 | 14 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/othercom/external_enum_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_enum.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export interface ExternalEnumMap { 7 | DEFAULT: 0; 8 | FIRST: 1; 9 | SECOND: 2; 10 | } 11 | 12 | export const ExternalEnum: ExternalEnumMap; 13 | 14 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/othercom/external_enum_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_enum.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export interface ExternalEnumMap { 7 | DEFAULT: 0; 8 | FIRST: 1; 9 | SECOND: 2; 10 | } 11 | 12 | export const ExternalEnum: ExternalEnumMap; 13 | 14 | -------------------------------------------------------------------------------- /proto/examplecom/annotations.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | message AnnotatedMessage { 6 | uint64 myUnit64 = 1 [jstype = JS_STRING]; 7 | int64 myInt64 = 2 [jstype = JS_STRING]; 8 | fixed64 myFixed64 = 3 [jstype = JS_STRING]; 9 | sint64 mySint64 = 4 [jstype = JS_STRING]; 10 | sfixed64 mySfixed64 = 5 [jstype = JS_STRING]; 11 | } 12 | -------------------------------------------------------------------------------- /proto/examplecom/parent_message_v3.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | import "proto/othercom/external_child_message.proto"; 6 | 7 | message ParentMessageV3 { 8 | message InternalChildMessage { 9 | string my_string = 1; 10 | } 11 | 12 | InternalChildMessage internal_child_message = 1; 13 | repeated InternalChildMessage internal_children = 2; 14 | 15 | othercom.ExternalChildMessage external_child_message = 3; 16 | repeated othercom.ExternalChildMessage external_children = 4; 17 | } 18 | -------------------------------------------------------------------------------- /proto/examplecom/enum_message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | import "proto/othercom/external_enum.proto"; 6 | 7 | message EnumMessage { 8 | enum InternalEnum { 9 | DEFAULT = 0; 10 | FIRST = 1; 11 | SECOND = 2; 12 | Third = 3; // protoc will convert to ALL_CAPS. 13 | } 14 | 15 | InternalEnum internal_enum = 1; 16 | repeated InternalEnum internal_enums = 2; 17 | 18 | othercom.ExternalEnum external_enum = 3; 19 | repeated othercom.ExternalEnum external_enums = 4; 20 | } 21 | -------------------------------------------------------------------------------- /proto/examplecom/primitive_message_v3.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | message PrimitiveMessageV3 { 6 | double my_double = 1; 7 | float my_float = 2; 8 | int32 my_int32 = 3; 9 | int64 my_int64 = 4; 10 | uint32 my_uint32 = 5; 11 | uint64 my_uint64 = 6; 12 | sint32 my_sint32 = 7; 13 | sint64 my_sint64 = 8; 14 | fixed32 my_fixed32 = 9; 15 | fixed64 my_fixed64 = 10; 16 | sfixed32 my_sfixed32 = 11; 17 | sfixed64 my_sfixed64 = 12; 18 | bool my_bool = 13; 19 | string my_string = 14; 20 | bytes my_bytes = 15; 21 | 22 | int32 my_NUMBER = 16; 23 | } 24 | -------------------------------------------------------------------------------- /src/Printer.ts: -------------------------------------------------------------------------------- 1 | import {generateIndent} from "./util"; 2 | 3 | export class Printer { 4 | indentStr: string; 5 | output: string = ""; 6 | 7 | constructor(indentLevel: number) { 8 | this.indentStr = generateIndent(indentLevel); 9 | } 10 | 11 | printLn(str: string) { 12 | this.output += this.indentStr + str + "\n"; 13 | } 14 | 15 | print(str: string) { 16 | this.output += str; 17 | } 18 | 19 | printEmptyLn() { 20 | this.output += "\n"; 21 | } 22 | 23 | printIndentedLn(str: string) { 24 | this.output += this.indentStr + " " + str + "\n"; 25 | } 26 | 27 | getOutput(): string { 28 | return this.output; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CodePrinter.ts: -------------------------------------------------------------------------------- 1 | import {Printer} from "./Printer"; 2 | import {generateIndent} from "./util"; 3 | 4 | export class CodePrinter { 5 | private indentation: string; 6 | constructor(private depth: number, private printer: Printer) { 7 | this.indentation = generateIndent(1); 8 | } 9 | indent() { 10 | this.depth++; 11 | return this; 12 | } 13 | dedent() { 14 | this.depth--; 15 | return this; 16 | } 17 | printLn(line: string) { 18 | this.printer.printLn(new Array(this.depth + 1).join(this.indentation) + line); 19 | return this; 20 | } 21 | 22 | printEmptyLn() { 23 | this.printer.printEmptyLn(); 24 | return this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /defs.bzl: -------------------------------------------------------------------------------- 1 | DEPRECATION_WARNING = """ 2 | ################################################################################################### 3 | 4 | The bazel rules have been moved to a separate project: 5 | https://github.com/Dig-Doug/rules_typescript_proto 6 | 7 | For a migration guide, see: 8 | https://github.com/Dig-Doug/rules_typescript_proto/blob/master/docs/migrating_from_ts_protoc_gen.md 9 | 10 | ################################################################################################### 11 | """ 12 | 13 | def typescript_proto_library(name, proto): 14 | print(DEPRECATION_WARNING) 15 | 16 | def typescript_proto_dependencies(): 17 | print(DEPRECATION_WARNING) 18 | -------------------------------------------------------------------------------- /proto/orphan.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | enum OrphanEnum { 4 | UNKNOWN = 0; 5 | ONE = 1; 6 | TWO = 2; 7 | } 8 | 9 | message OrphanMapMessage { 10 | map primitive_ints = 1; 11 | } 12 | 13 | message OrphanMessage { 14 | string my_string = 1; 15 | bool my_bool = 2; 16 | OrphanEnum my_enum = 3; 17 | } 18 | 19 | message OrphanUnaryRequest { 20 | int64 some_int64 = 1; 21 | } 22 | 23 | message OrphanStreamRequest { 24 | string some_string = 1; 25 | } 26 | 27 | service OrphanService { 28 | rpc DoUnary(OrphanUnaryRequest) returns (OrphanMessage) {} 29 | rpc DoStream(OrphanStreamRequest) returns (stream OrphanMessage) {} 30 | } 31 | -------------------------------------------------------------------------------- /examples/generated/proto/othercom/external_enum_pb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview 3 | * @enhanceable 4 | * @suppress {messageConventions} JS Compiler reports an error if a variable or 5 | * field starts with 'MSG_' and isn't a translatable message. 6 | * @public 7 | */ 8 | // GENERATED CODE -- DO NOT EDIT! 9 | 10 | var jspb = require('google-protobuf'); 11 | var goog = jspb; 12 | var global = Function('return this')(); 13 | 14 | goog.exportSymbol('proto.othercom.ExternalEnum', null, global); 15 | /** 16 | * @enum {number} 17 | */ 18 | proto.othercom.ExternalEnum = { 19 | DEFAULT: 0, 20 | FIRST: 1, 21 | SECOND: 2 22 | }; 23 | 24 | goog.object.extend(exports, proto.othercom); 25 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/othercom/external_enum_pb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview 3 | * @enhanceable 4 | * @suppress {messageConventions} JS Compiler reports an error if a variable or 5 | * field starts with 'MSG_' and isn't a translatable message. 6 | * @public 7 | */ 8 | // GENERATED CODE -- DO NOT EDIT! 9 | 10 | var jspb = require('google-protobuf'); 11 | var goog = jspb; 12 | var global = Function('return this')(); 13 | 14 | goog.exportSymbol('proto.othercom.ExternalEnum', null, global); 15 | /** 16 | * @enum {number} 17 | */ 18 | proto.othercom.ExternalEnum = { 19 | DEFAULT: 0, 20 | FIRST: 1, 21 | SECOND: 2 22 | }; 23 | 24 | goog.object.extend(exports, proto.othercom); 25 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/othercom/external_enum_pb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview 3 | * @enhanceable 4 | * @suppress {messageConventions} JS Compiler reports an error if a variable or 5 | * field starts with 'MSG_' and isn't a translatable message. 6 | * @public 7 | */ 8 | // GENERATED CODE -- DO NOT EDIT! 9 | 10 | var jspb = require('google-protobuf'); 11 | var goog = jspb; 12 | var global = Function('return this')(); 13 | 14 | goog.exportSymbol('proto.othercom.ExternalEnum', null, global); 15 | /** 16 | * @enum {number} 17 | */ 18 | proto.othercom.ExternalEnum = { 19 | DEFAULT: 0, 20 | FIRST: 1, 21 | SECOND: 2 22 | }; 23 | 24 | goog.object.extend(exports, proto.othercom); 25 | -------------------------------------------------------------------------------- /test/integration/casing.ts: -------------------------------------------------------------------------------- 1 | import {assert} from "chai"; 2 | import {CasingMessage} from "../../examples/generated/proto/examplecom/casing_pb"; 3 | 4 | describe("casing", () => { 5 | 6 | describe("toObject", () => { 7 | it("generate the correct definitions based on the code the protoc-gen-js plugin generates", () => { 8 | const message = new CasingMessage(); 9 | const obj = message.toObject(); 10 | 11 | assert.equal(obj.titlecase, ""); 12 | assert.equal(obj.camelcase, ""); 13 | assert.equal(obj.snakeCase, ""); 14 | assert.equal(obj.leadingunderscorecamelcase, ""); 15 | assert.equal(obj.leadingunderscoretitlecase, ""); 16 | }); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /proto/examplecom/parent_message_v2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package examplecom; 4 | 5 | import "proto/othercom/external_child_message.proto"; 6 | 7 | message ParentMessageV2 { 8 | message InternalChildMessage { 9 | required string my_string = 1; 10 | } 11 | 12 | required InternalChildMessage internal_child_message = 1; 13 | optional InternalChildMessage opt_internal_child_message = 2; 14 | repeated InternalChildMessage internal_children = 3; 15 | 16 | required othercom.ExternalChildMessage external_child_message = 4; 17 | optional othercom.ExternalChildMessage opt_external_child_message = 5; 18 | repeated othercom.ExternalChildMessage external_children = 6; 19 | } 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "alwaysStrict": true, 4 | "sourceMap": true, 5 | "declaration": true, 6 | "declarationDir": "lib", 7 | "target": "es5", 8 | "removeComments": true, 9 | "noImplicitReturns": true, 10 | "noImplicitAny": true, 11 | "noUnusedLocals": true, 12 | "noUnusedParameters": true, 13 | "strictNullChecks": true, 14 | "stripInternal": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "outDir": "lib", 17 | "noEmitOnError": true, 18 | "types": [ 19 | "mocha", 20 | "node", 21 | "google-protobuf" 22 | ] 23 | }, 24 | "include": [ 25 | "src" 26 | ], 27 | "exclude": [ 28 | "node_modules" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /proto/examplecom/repeated_primitive_message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | message RepeatedPrimitiveMessage { 6 | repeated double my_double = 1; 7 | repeated float my_float = 2; 8 | repeated int32 my_int32 = 3; 9 | repeated int64 my_int64 = 4; 10 | repeated uint32 my_uint32 = 5; 11 | repeated uint64 my_uint64 = 6; 12 | repeated sint32 my_sint32 = 7; 13 | repeated sint64 my_sint64 = 8; 14 | repeated fixed32 my_fixed32 = 9; 15 | repeated fixed64 my_fixed64 = 10; 16 | repeated sfixed32 my_sfixed32 = 11; 17 | repeated sfixed64 my_sfixed64 = 12; 18 | repeated bool my_bool = 13; 19 | repeated string my_string = 14; 20 | repeated bytes my_bytes = 15; 21 | } 22 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 90 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | # Label to use when marking an issue as stale 9 | staleLabel: wontfix 10 | # Comment to post when marking an issue as stale. Set to `false` to disable 11 | markComment: > 12 | This issue has been automatically marked as stale because it has not had 13 | recent activity. It will be closed if no further activity occurs. Thank you 14 | for your contributions. 15 | # Comment to post when closing a stale issue. Set to `false` to disable 16 | closeComment: false 17 | -------------------------------------------------------------------------------- /proto/examplecom/map_message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | import "proto/othercom/external_enum.proto"; 6 | import "proto/othercom/external_child_message.proto"; 7 | 8 | message MapMessage { 9 | enum InternalEnum { 10 | DEFAULT = 0; 11 | FIRST = 1; 12 | SECOND = 2; 13 | } 14 | 15 | message InternalChildMessage { 16 | string my_string = 1; 17 | } 18 | 19 | map internal_enums = 1; 20 | map internal_children = 2; 21 | 22 | map external_enums = 3; 23 | map external_children = 4; 24 | 25 | map primitive_ints = 5; 26 | } 27 | -------------------------------------------------------------------------------- /src/ts/enum.ts: -------------------------------------------------------------------------------- 1 | import {EnumDescriptorProto} from "google-protobuf/google/protobuf/descriptor_pb"; 2 | import {Printer} from "../Printer"; 3 | 4 | export function printEnum(enumDescriptor: EnumDescriptorProto, indentLevel: number) { 5 | const printer = new Printer(indentLevel); 6 | const enumInterfaceName = `${enumDescriptor.getName()}Map`; 7 | printer.printEmptyLn(); 8 | printer.printLn(`export interface ${enumInterfaceName} {`); 9 | enumDescriptor.getValueList().forEach(value => { 10 | printer.printIndentedLn(`${value.getName().toUpperCase()}: ${value.getNumber()};`); 11 | }); 12 | printer.printLn(`}`); 13 | printer.printEmptyLn(); 14 | printer.printLn(`export const ${enumDescriptor.getName()}: ${enumInterfaceName};`); 15 | return printer.getOutput(); 16 | } 17 | -------------------------------------------------------------------------------- /src/ts/oneof.ts: -------------------------------------------------------------------------------- 1 | import {Printer} from "../Printer"; 2 | import {OneofDescriptorProto, FieldDescriptorProto} from "google-protobuf/google/protobuf/descriptor_pb"; 3 | import {oneOfName} from "../util"; 4 | 5 | export function printOneOfDecl(oneOfDecl: OneofDescriptorProto, oneOfFields: Array, indentLevel: number) { 6 | const printer = new Printer(indentLevel); 7 | printer.printEmptyLn(); 8 | printer.printLn(`export enum ${oneOfName(oneOfDecl.getName())}Case {`); 9 | printer.printIndentedLn(`${oneOfDecl.getName().toUpperCase()}_NOT_SET = 0,`); 10 | oneOfFields.forEach(field => { 11 | printer.printIndentedLn(`${field.getName().toUpperCase()} = ${field.getNumber()},`); 12 | }); 13 | printer.printLn("}"); 14 | 15 | return printer.output; 16 | } 17 | -------------------------------------------------------------------------------- /proto/examplecom/simplevalue.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | message SimpleValue { 6 | string first_field = 1; 7 | int64 second_field = 2; 8 | 9 | // The kind of value. 10 | oneof kind { 11 | // Represents a double value. 12 | double number_value = 3; 13 | // Represents a string value. 14 | string string_value = 6; 15 | // Represents a boolean value. 16 | bool bool_value = 8; 17 | } 18 | // The kind of value. 19 | oneof another { 20 | // Represents a double value. 21 | double number2_value = 4; 22 | // Represents a string value. 23 | string string2_value = 5; 24 | // Represents a boolean value. 25 | bool bool2_value = 7; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/ts/extensions.ts: -------------------------------------------------------------------------------- 1 | import {Printer} from "../Printer"; 2 | import {ExportMap} from "../ExportMap"; 3 | import {FieldDescriptorProto} from "google-protobuf/google/protobuf/descriptor_pb"; 4 | import {snakeToCamel} from "../util"; 5 | import {getFieldType} from "./FieldTypes"; 6 | 7 | export function printExtension(fileName: string, exportMap: ExportMap, extension: FieldDescriptorProto, indentLevel: number): string { 8 | const printer = new Printer(indentLevel + 1); 9 | printer.printEmptyLn(); 10 | const extensionName = snakeToCamel(extension.getName()); 11 | const fieldType = getFieldType(extension.getType(), extension.getTypeName().slice(1), fileName, exportMap); 12 | printer.printLn(`export const ${extensionName}: jspb.ExtensionFieldInfo<${fieldType}>;`); 13 | return printer.output; 14 | } 15 | -------------------------------------------------------------------------------- /test/mocha-check-report.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | 3 | const reportFile = process.argv[2]; 4 | let reportContents = ""; 5 | let report = null; 6 | 7 | function die(msg) { 8 | console.log(msg); 9 | process.exit(1); 10 | } 11 | 12 | if (!reportFile) { 13 | die("Expected report filename to be supplied as an argument"); 14 | } 15 | 16 | try { 17 | reportContents = fs.readFileSync(reportFile).toString('utf8'); 18 | } 19 | catch (err) { 20 | die("Failed to open mocha report file " + reportFile + ": " + err.message); 21 | } 22 | 23 | try { 24 | report = JSON.parse(reportContents); 25 | } 26 | catch (err) { 27 | die("Failed to parse mocha report as JSON: " + err.message); 28 | } 29 | 30 | if (!report || !report.stats || report.stats.tests === 0) { 31 | die("No test results found in " + reportFile); 32 | } -------------------------------------------------------------------------------- /proto/examplecom/oneof_message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | import "proto/othercom/external_child_message.proto"; 6 | 7 | message OneOfMessage { 8 | message InternalChildMessage { 9 | string my_string = 1; 10 | } 11 | 12 | oneof group { 13 | InternalChildMessage internal_child_message = 1; 14 | othercom.ExternalChildMessage external_child_message = 2; 15 | string my_string = 3; 16 | int64 my_int64 = 4; 17 | } 18 | } 19 | 20 | message CamelCasedOneOfMessage { 21 | oneof camelCasedMessage { 22 | int32 anInt = 1; 23 | string theString = 2; 24 | } 25 | } 26 | 27 | message SnakeCasedOneOfMessage { 28 | oneof snake_cased_message { 29 | int32 anint = 1; 30 | string theString = 2; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/integration/annotations.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "chai"; 2 | import { AnnotatedMessage } from "../../examples/generated/proto/examplecom/annotations_pb"; 3 | 4 | describe("annotations", () => { 5 | it("should detect and honor the `jstype` annotation", () => { 6 | const unsafeInteger = Number.MAX_VALUE.toString() + "9999"; 7 | const msg = new AnnotatedMessage(); 8 | 9 | msg.setMyfixed64(unsafeInteger); 10 | assert.strictEqual(msg.getMyfixed64(), unsafeInteger); 11 | 12 | msg.setMyunit64(unsafeInteger); 13 | assert.strictEqual(msg.getMyunit64(), unsafeInteger); 14 | 15 | msg.setMyint64(unsafeInteger); 16 | assert.strictEqual(msg.getMyint64(), unsafeInteger); 17 | 18 | msg.setMysfixed64(unsafeInteger); 19 | assert.strictEqual(msg.getMysfixed64(), unsafeInteger); 20 | 21 | msg.setMysint64(unsafeInteger); 22 | assert.strictEqual(msg.getMysint64(), unsafeInteger); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/empty_message_no_service_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/empty_message_no_service.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class NoService extends jspb.Message { 7 | serializeBinary(): Uint8Array; 8 | toObject(includeInstance?: boolean): NoService.AsObject; 9 | static toObject(includeInstance: boolean, msg: NoService): NoService.AsObject; 10 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 11 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 12 | static serializeBinaryToWriter(message: NoService, writer: jspb.BinaryWriter): void; 13 | static deserializeBinary(bytes: Uint8Array): NoService; 14 | static deserializeBinaryFromReader(message: NoService, reader: jspb.BinaryReader): NoService; 15 | } 16 | 17 | export namespace NoService { 18 | export type AsObject = { 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/empty_message_no_service_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/empty_message_no_service.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class NoService extends jspb.Message { 7 | serializeBinary(): Uint8Array; 8 | toObject(includeInstance?: boolean): NoService.AsObject; 9 | static toObject(includeInstance: boolean, msg: NoService): NoService.AsObject; 10 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 11 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 12 | static serializeBinaryToWriter(message: NoService, writer: jspb.BinaryWriter): void; 13 | static deserializeBinary(bytes: Uint8Array): NoService; 14 | static deserializeBinaryFromReader(message: NoService, reader: jspb.BinaryReader): NoService; 15 | } 16 | 17 | export namespace NoService { 18 | export type AsObject = { 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /test/mocha-run-suite.js: -------------------------------------------------------------------------------- 1 | const { spawnSync } = require("child_process"); 2 | const { resolve } = require("path"); 3 | 4 | const testSuite = process.argv[2]; 5 | if (!testSuite) { 6 | throw new Error("No mocha test suite specified."); 7 | } 8 | 9 | const mochaPath = 10 | resolve(__dirname, "..", "node_modules", ".bin", "mocha") + 11 | (process.platform === "win32" ? ".cmd" : ""); 12 | 13 | const mochaArgs = [ 14 | "--reporter", "mocha-spec-json-output-reporter", 15 | "--reporter-options", "fileName=./test/mocha-report.json", 16 | "--require", "ts-node/register/type-check", 17 | "--require", "source-map-support/register", 18 | ]; 19 | 20 | if (process.env.MOCHA_DEBUG) { 21 | mochaArgs.push("--inspect-brk"); 22 | } 23 | 24 | mochaArgs.push(testSuite); 25 | 26 | spawnSync(mochaPath, mochaArgs, { stdio: "inherit" }); 27 | 28 | spawnSync( 29 | "node", 30 | ["./test/mocha-check-report", "./test/mocha-report.json"], 31 | { stdio: "inherit" } 32 | ); 33 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/empty_message_no_service_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/empty_message_no_service.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class NoService extends jspb.Message { 7 | serializeBinary(): Uint8Array; 8 | toObject(includeInstance?: boolean): NoService.AsObject; 9 | static toObject(includeInstance: boolean, msg: NoService): NoService.AsObject; 10 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 11 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 12 | static serializeBinaryToWriter(message: NoService, writer: jspb.BinaryWriter): void; 13 | static deserializeBinary(bytes: Uint8Array): NoService; 14 | static deserializeBinaryFromReader(message: NoService, reader: jspb.BinaryReader): NoService; 15 | } 16 | 17 | export namespace NoService { 18 | export type AsObject = { 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /proto/examplecom/simple_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | import "proto/othercom/external_child_message.proto"; 6 | 7 | // these imports should not be output in the generated typescript service 8 | import "google/protobuf/empty.proto"; 9 | import "google/protobuf/timestamp.proto"; 10 | 11 | message UnaryRequest { 12 | int64 some_int64 = 1; 13 | google.protobuf.Timestamp some_timestamp = 2; 14 | } 15 | 16 | message UnaryResponse {} 17 | 18 | message StreamRequest { 19 | string some_string = 1; 20 | } 21 | 22 | service SimpleService { 23 | rpc DoUnary(UnaryRequest) returns (othercom.ExternalChildMessage) {} 24 | rpc DoServerStream(StreamRequest) returns (stream othercom.ExternalChildMessage) {} 25 | rpc DoClientStream(stream StreamRequest) returns (google.protobuf.Empty) {} 26 | rpc DoBidiStream(stream StreamRequest) returns (stream othercom.ExternalChildMessage) {} 27 | 28 | // checks that rpc methods that use reserved JS words don't generate invalid code 29 | rpc Delete(UnaryRequest) returns (UnaryResponse) {} 30 | } 31 | -------------------------------------------------------------------------------- /src/WellKnown.ts: -------------------------------------------------------------------------------- 1 | export const WellKnownTypesMap: {[key: string]: string} = { 2 | "google/protobuf/compiler/plugin.proto": "google-protobuf/google/protobuf/compiler/plugin_pb", 3 | "google/protobuf/any.proto": "google-protobuf/google/protobuf/any_pb", 4 | "google/protobuf/api.proto": "google-protobuf/google/protobuf/api_pb", 5 | "google/protobuf/descriptor.proto": "google-protobuf/google/protobuf/descriptor_pb", 6 | "google/protobuf/duration.proto": "google-protobuf/google/protobuf/duration_pb", 7 | "google/protobuf/empty.proto": "google-protobuf/google/protobuf/empty_pb", 8 | "google/protobuf/field_mask.proto": "google-protobuf/google/protobuf/field_mask_pb", 9 | "google/protobuf/source_context.proto": "google-protobuf/google/protobuf/source_context_pb", 10 | "google/protobuf/struct.proto": "google-protobuf/google/protobuf/struct_pb", 11 | "google/protobuf/timestamp.proto": "google-protobuf/google/protobuf/timestamp_pb", 12 | "google/protobuf/type.proto": "google-protobuf/google/protobuf/type_pb", 13 | "google/protobuf/wrappers.proto": "google-protobuf/google/protobuf/wrappers_pb" 14 | }; 15 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Firstly, thanks for taking the time to contribute. 4 | 5 | The following is a set of guidelines for contributing to `ts-protoc-gen`. 6 | 7 | ## Pull Request Process 8 | 1. Implement your changes. If you're unsure how or would like clarification, please raise an [issue](https://github.com/improbable-eng/ts-protoc-gen/issues/new). 9 | 2. Ensure your change has sufficient test coverage. 10 | 3. Ensure all changes pass the lint check. 11 | 2. Maintainers will look to review the PR as soon as possible. If there is no traction for some time, you're welcome to bump the thread. 12 | 3. All PRs require at least one reviewer. 13 | 14 | ## Code of Conduct 15 | Please review and follow our [Code of Conduct](https://github.com/improbable-eng/ts-protoc-gen/blob/master/CODE_OF_CONDUCT.md). 16 | 17 | ## Releasing 18 | Your changes will be released with the next version release. 19 | 20 | ## Debugging 21 | You can attach the Chrome Inspector when running the tests by setting the `MOCHA_DEBUG` environment variable before running the tests, ie: 22 | 23 | ``` 24 | MOCHA_DEBUG=true npm test 25 | ``` 26 | -------------------------------------------------------------------------------- /examples/generated/proto/othercom/external_child_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_child_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class ExternalChildMessage extends jspb.Message { 7 | getMyString(): string; 8 | setMyString(value: string): void; 9 | 10 | serializeBinary(): Uint8Array; 11 | toObject(includeInstance?: boolean): ExternalChildMessage.AsObject; 12 | static toObject(includeInstance: boolean, msg: ExternalChildMessage): ExternalChildMessage.AsObject; 13 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 14 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 15 | static serializeBinaryToWriter(message: ExternalChildMessage, writer: jspb.BinaryWriter): void; 16 | static deserializeBinary(bytes: Uint8Array): ExternalChildMessage; 17 | static deserializeBinaryFromReader(message: ExternalChildMessage, reader: jspb.BinaryReader): ExternalChildMessage; 18 | } 19 | 20 | export namespace ExternalChildMessage { 21 | export type AsObject = { 22 | myString: string, 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/othercom/external_child_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_child_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class ExternalChildMessage extends jspb.Message { 7 | getMyString(): string; 8 | setMyString(value: string): void; 9 | 10 | serializeBinary(): Uint8Array; 11 | toObject(includeInstance?: boolean): ExternalChildMessage.AsObject; 12 | static toObject(includeInstance: boolean, msg: ExternalChildMessage): ExternalChildMessage.AsObject; 13 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 14 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 15 | static serializeBinaryToWriter(message: ExternalChildMessage, writer: jspb.BinaryWriter): void; 16 | static deserializeBinary(bytes: Uint8Array): ExternalChildMessage; 17 | static deserializeBinaryFromReader(message: ExternalChildMessage, reader: jspb.BinaryReader): ExternalChildMessage; 18 | } 19 | 20 | export namespace ExternalChildMessage { 21 | export type AsObject = { 22 | myString: string, 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/othercom/external_child_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: othercom 2 | // file: proto/othercom/external_child_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class ExternalChildMessage extends jspb.Message { 7 | getMyString(): string; 8 | setMyString(value: string): void; 9 | 10 | serializeBinary(): Uint8Array; 11 | toObject(includeInstance?: boolean): ExternalChildMessage.AsObject; 12 | static toObject(includeInstance: boolean, msg: ExternalChildMessage): ExternalChildMessage.AsObject; 13 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 14 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 15 | static serializeBinaryToWriter(message: ExternalChildMessage, writer: jspb.BinaryWriter): void; 16 | static deserializeBinary(bytes: Uint8Array): ExternalChildMessage; 17 | static deserializeBinaryFromReader(message: ExternalChildMessage, reader: jspb.BinaryReader): ExternalChildMessage; 18 | } 19 | 20 | export namespace ExternalChildMessage { 21 | export type AsObject = { 22 | myString: string, 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /proto/examplecom/well_known_message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | import "google/protobuf/any.proto"; 6 | import "google/protobuf/api.proto"; 7 | import "google/protobuf/compiler/plugin.proto"; 8 | import "google/protobuf/descriptor.proto"; 9 | import "google/protobuf/duration.proto"; 10 | import "google/protobuf/empty.proto"; 11 | import "google/protobuf/field_mask.proto"; 12 | import "google/protobuf/source_context.proto"; 13 | import "google/protobuf/struct.proto"; 14 | import "google/protobuf/timestamp.proto"; 15 | import "google/protobuf/type.proto"; 16 | import "google/protobuf/wrappers.proto"; 17 | 18 | message WellKnownMessage { 19 | google.protobuf.compiler.CodeGeneratorRequest my_code_generator_request = 1; 20 | google.protobuf.Any my_any = 2; 21 | google.protobuf.Method my_method = 3; 22 | google.protobuf.GeneratedCodeInfo my_generated_code_info = 4; 23 | google.protobuf.Duration my_duration = 5; 24 | google.protobuf.Empty my_empty = 6; 25 | google.protobuf.FieldMask my_field_mask = 7; 26 | google.protobuf.SourceContext my_source_context = 8; 27 | google.protobuf.Struct my_struct = 9; 28 | google.protobuf.Timestamp my_timestamp = 10; 29 | google.protobuf.Type my_type = 11; 30 | google.protobuf.DoubleValue my_double_value = 12; 31 | } -------------------------------------------------------------------------------- /proto/examplecom/primitive_message_v2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package examplecom; 4 | 5 | message PrimitiveMessageV2 { 6 | required double my_double = 1; 7 | required float my_float = 2; 8 | required int32 my_int32 = 3; 9 | required int64 my_int64 = 4; 10 | required uint32 my_uint32 = 5; 11 | required uint64 my_uint64 = 6; 12 | required sint32 my_sint32 = 7; 13 | required sint64 my_sint64 = 8; 14 | required fixed32 my_fixed32 = 9; 15 | required fixed64 my_fixed64 = 10; 16 | required sfixed32 my_sfixed32 = 11; 17 | required sfixed64 my_sfixed64 = 12; 18 | required bool my_bool = 13; 19 | required string my_string = 14; 20 | required bytes my_bytes = 15; 21 | 22 | optional double opt_double = 16; 23 | optional float opt_float = 17; 24 | optional int32 opt_int32 = 18; 25 | optional int64 opt_int64 = 19; 26 | optional uint32 opt_uint32 = 20; 27 | optional uint64 opt_uint64 = 21; 28 | optional sint32 opt_sint32 = 22; 29 | optional sint64 opt_sint64 = 23; 30 | optional fixed32 opt_fixed32 = 24; 31 | optional fixed64 opt_fixed64 = 25; 32 | optional sfixed32 opt_sfixed32 = 26; 33 | optional sfixed64 opt_sfixed64 = 27; 34 | optional bool opt_bool = 28; 35 | optional string opt_string = 29; 36 | optional bytes opt_bytes = 30; 37 | 38 | optional int32 opt_NUMBER = 31; 39 | } 40 | -------------------------------------------------------------------------------- /proto/examplecom/simple.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | import "google/protobuf/compiler/plugin.proto"; 6 | import "google/protobuf/any.proto"; 7 | import "google/protobuf/api.proto"; 8 | import "google/protobuf/descriptor.proto"; 9 | import "google/protobuf/duration.proto"; 10 | import "google/protobuf/empty.proto"; 11 | import "google/protobuf/field_mask.proto"; 12 | import "google/protobuf/source_context.proto"; 13 | import "google/protobuf/struct.proto"; 14 | import "google/protobuf/timestamp.proto"; 15 | import "google/protobuf/type.proto"; 16 | import "google/protobuf/wrappers.proto"; 17 | 18 | message MySimple { 19 | string my_string = 1; 20 | bool my_bool = 2; 21 | repeated string some_labels = 3; 22 | google.protobuf.compiler.CodeGeneratorRequest some_code_generator_request = 4; 23 | google.protobuf.Any some_any = 5; 24 | google.protobuf.Method some_method = 6; 25 | google.protobuf.GeneratedCodeInfo some_generated_code_info = 7; 26 | google.protobuf.Duration some_duration = 8; 27 | google.protobuf.Empty some_empty = 9; 28 | google.protobuf.FieldMask some_field_mask = 10; 29 | google.protobuf.SourceContext some_source_context = 11; 30 | google.protobuf.Struct some_struct = 12; 31 | google.protobuf.Timestamp some_timestamp = 13; 32 | google.protobuf.Type some_type = 14; 33 | google.protobuf.DoubleValue some_double_value = 15; 34 | } 35 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/annotations_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/annotations.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class AnnotatedMessage extends jspb.Message { 7 | getMyunit64(): string; 8 | setMyunit64(value: string): void; 9 | 10 | getMyint64(): string; 11 | setMyint64(value: string): void; 12 | 13 | getMyfixed64(): string; 14 | setMyfixed64(value: string): void; 15 | 16 | getMysint64(): string; 17 | setMysint64(value: string): void; 18 | 19 | getMysfixed64(): string; 20 | setMysfixed64(value: string): void; 21 | 22 | serializeBinary(): Uint8Array; 23 | toObject(includeInstance?: boolean): AnnotatedMessage.AsObject; 24 | static toObject(includeInstance: boolean, msg: AnnotatedMessage): AnnotatedMessage.AsObject; 25 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 26 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 27 | static serializeBinaryToWriter(message: AnnotatedMessage, writer: jspb.BinaryWriter): void; 28 | static deserializeBinary(bytes: Uint8Array): AnnotatedMessage; 29 | static deserializeBinaryFromReader(message: AnnotatedMessage, reader: jspb.BinaryReader): AnnotatedMessage; 30 | } 31 | 32 | export namespace AnnotatedMessage { 33 | export type AsObject = { 34 | myunit64: string, 35 | myint64: string, 36 | myfixed64: string, 37 | mysint64: string, 38 | mysfixed64: string, 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/annotations_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/annotations.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class AnnotatedMessage extends jspb.Message { 7 | getMyunit64(): string; 8 | setMyunit64(value: string): void; 9 | 10 | getMyint64(): string; 11 | setMyint64(value: string): void; 12 | 13 | getMyfixed64(): string; 14 | setMyfixed64(value: string): void; 15 | 16 | getMysint64(): string; 17 | setMysint64(value: string): void; 18 | 19 | getMysfixed64(): string; 20 | setMysfixed64(value: string): void; 21 | 22 | serializeBinary(): Uint8Array; 23 | toObject(includeInstance?: boolean): AnnotatedMessage.AsObject; 24 | static toObject(includeInstance: boolean, msg: AnnotatedMessage): AnnotatedMessage.AsObject; 25 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 26 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 27 | static serializeBinaryToWriter(message: AnnotatedMessage, writer: jspb.BinaryWriter): void; 28 | static deserializeBinary(bytes: Uint8Array): AnnotatedMessage; 29 | static deserializeBinaryFromReader(message: AnnotatedMessage, reader: jspb.BinaryReader): AnnotatedMessage; 30 | } 31 | 32 | export namespace AnnotatedMessage { 33 | export type AsObject = { 34 | myunit64: string, 35 | myint64: string, 36 | myfixed64: string, 37 | mysint64: string, 38 | mysfixed64: string, 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/annotations_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/annotations.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class AnnotatedMessage extends jspb.Message { 7 | getMyunit64(): string; 8 | setMyunit64(value: string): void; 9 | 10 | getMyint64(): string; 11 | setMyint64(value: string): void; 12 | 13 | getMyfixed64(): string; 14 | setMyfixed64(value: string): void; 15 | 16 | getMysint64(): string; 17 | setMysint64(value: string): void; 18 | 19 | getMysfixed64(): string; 20 | setMysfixed64(value: string): void; 21 | 22 | serializeBinary(): Uint8Array; 23 | toObject(includeInstance?: boolean): AnnotatedMessage.AsObject; 24 | static toObject(includeInstance: boolean, msg: AnnotatedMessage): AnnotatedMessage.AsObject; 25 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 26 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 27 | static serializeBinaryToWriter(message: AnnotatedMessage, writer: jspb.BinaryWriter): void; 28 | static deserializeBinary(bytes: Uint8Array): AnnotatedMessage; 29 | static deserializeBinaryFromReader(message: AnnotatedMessage, reader: jspb.BinaryReader): AnnotatedMessage; 30 | } 31 | 32 | export namespace AnnotatedMessage { 33 | export type AsObject = { 34 | myunit64: string, 35 | myint64: string, 36 | myfixed64: string, 37 | mysint64: string, 38 | mysfixed64: string, 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "class-name": true, 4 | "comment-format": [true, "check-space"], 5 | "indent": [true, "spaces"], 6 | "no-duplicate-variable": true, 7 | "no-eval": true, 8 | "no-internal-module": true, 9 | "no-trailing-whitespace": true, 10 | "no-var-keyword": true, 11 | "one-line": [true, "check-open-brace", "check-whitespace"], 12 | "quotemark": [true, "double"], 13 | "semicolon": true, 14 | "triple-equals": [true, "allow-null-check"], 15 | "typedef-whitespace": [true, { 16 | "call-signature": "nospace", 17 | "index-signature": "nospace", 18 | "parameter": "nospace", 19 | "property-declaration": "nospace", 20 | "variable-declaration": "nospace" 21 | }], 22 | "variable-name": [true, "ban-keywords"], 23 | "whitespace": [true, 24 | "check-branch", 25 | "check-decl", 26 | "check-operator", 27 | "check-separator", 28 | "check-type" 29 | ] 30 | }, 31 | "jsRules": { 32 | "indent": [true, "spaces"], 33 | "no-duplicate-variable": true, 34 | "no-eval": true, 35 | "no-trailing-whitespace": true, 36 | "one-line": [true, "check-open-brace", "check-whitespace"], 37 | "quotemark": [true, "double"], 38 | "semicolon": false, 39 | "triple-equals": [true, "allow-null-check"], 40 | "variable-name": [true, "ban-keywords"], 41 | "whitespace": [true, 42 | "check-branch", 43 | "check-decl", 44 | "check-operator", 45 | "check-separator", 46 | "check-type" 47 | ] 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/casing_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/casing.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class CasingMessage extends jspb.Message { 7 | getTitlecase(): string; 8 | setTitlecase(value: string): void; 9 | 10 | getCamelcase(): string; 11 | setCamelcase(value: string): void; 12 | 13 | getSnakeCase(): string; 14 | setSnakeCase(value: string): void; 15 | 16 | getLeadingunderscorecamelcase(): string; 17 | setLeadingunderscorecamelcase(value: string): void; 18 | 19 | getLeadingunderscoretitlecase(): string; 20 | setLeadingunderscoretitlecase(value: string): void; 21 | 22 | serializeBinary(): Uint8Array; 23 | toObject(includeInstance?: boolean): CasingMessage.AsObject; 24 | static toObject(includeInstance: boolean, msg: CasingMessage): CasingMessage.AsObject; 25 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 26 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 27 | static serializeBinaryToWriter(message: CasingMessage, writer: jspb.BinaryWriter): void; 28 | static deserializeBinary(bytes: Uint8Array): CasingMessage; 29 | static deserializeBinaryFromReader(message: CasingMessage, reader: jspb.BinaryReader): CasingMessage; 30 | } 31 | 32 | export namespace CasingMessage { 33 | export type AsObject = { 34 | titlecase: string, 35 | camelcase: string, 36 | snakeCase: string, 37 | leadingunderscorecamelcase: string, 38 | leadingunderscoretitlecase: string, 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/casing_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/casing.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class CasingMessage extends jspb.Message { 7 | getTitlecase(): string; 8 | setTitlecase(value: string): void; 9 | 10 | getCamelcase(): string; 11 | setCamelcase(value: string): void; 12 | 13 | getSnakeCase(): string; 14 | setSnakeCase(value: string): void; 15 | 16 | getLeadingunderscorecamelcase(): string; 17 | setLeadingunderscorecamelcase(value: string): void; 18 | 19 | getLeadingunderscoretitlecase(): string; 20 | setLeadingunderscoretitlecase(value: string): void; 21 | 22 | serializeBinary(): Uint8Array; 23 | toObject(includeInstance?: boolean): CasingMessage.AsObject; 24 | static toObject(includeInstance: boolean, msg: CasingMessage): CasingMessage.AsObject; 25 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 26 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 27 | static serializeBinaryToWriter(message: CasingMessage, writer: jspb.BinaryWriter): void; 28 | static deserializeBinary(bytes: Uint8Array): CasingMessage; 29 | static deserializeBinaryFromReader(message: CasingMessage, reader: jspb.BinaryReader): CasingMessage; 30 | } 31 | 32 | export namespace CasingMessage { 33 | export type AsObject = { 34 | titlecase: string, 35 | camelcase: string, 36 | snakeCase: string, 37 | leadingunderscorecamelcase: string, 38 | leadingunderscoretitlecase: string, 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/casing_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/casing.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class CasingMessage extends jspb.Message { 7 | getTitlecase(): string; 8 | setTitlecase(value: string): void; 9 | 10 | getCamelcase(): string; 11 | setCamelcase(value: string): void; 12 | 13 | getSnakeCase(): string; 14 | setSnakeCase(value: string): void; 15 | 16 | getLeadingunderscorecamelcase(): string; 17 | setLeadingunderscorecamelcase(value: string): void; 18 | 19 | getLeadingunderscoretitlecase(): string; 20 | setLeadingunderscoretitlecase(value: string): void; 21 | 22 | serializeBinary(): Uint8Array; 23 | toObject(includeInstance?: boolean): CasingMessage.AsObject; 24 | static toObject(includeInstance: boolean, msg: CasingMessage): CasingMessage.AsObject; 25 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 26 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 27 | static serializeBinaryToWriter(message: CasingMessage, writer: jspb.BinaryWriter): void; 28 | static deserializeBinary(bytes: Uint8Array): CasingMessage; 29 | static deserializeBinaryFromReader(message: CasingMessage, reader: jspb.BinaryReader): CasingMessage; 30 | } 31 | 32 | export namespace CasingMessage { 33 | export type AsObject = { 34 | titlecase: string, 35 | camelcase: string, 36 | snakeCase: string, 37 | leadingunderscorecamelcase: string, 38 | leadingunderscoretitlecase: string, 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /test/integration/orphan.ts: -------------------------------------------------------------------------------- 1 | import {assert} from "chai"; 2 | import * as orphan_pb_service from "../../examples/generated-grpc-web/proto/orphan_pb_service"; 3 | import * as orphan_pb from "../../examples/generated-grpc-web/proto/orphan_pb"; 4 | 5 | describe("ts orphan service", () => { 6 | it("should generate a service definition that does not have a package", () => { 7 | assert.strictEqual(orphan_pb_service.OrphanService.serviceName, "OrphanService"); 8 | 9 | assert.strictEqual(orphan_pb_service.OrphanService.DoUnary.methodName, "DoUnary"); 10 | assert.strictEqual(orphan_pb_service.OrphanService.DoUnary.service, orphan_pb_service.OrphanService); 11 | assert.strictEqual(orphan_pb_service.OrphanService.DoUnary.requestStream, false); 12 | assert.strictEqual(orphan_pb_service.OrphanService.DoUnary.responseStream, false); 13 | assert.strictEqual(orphan_pb_service.OrphanService.DoUnary.requestType, orphan_pb.OrphanUnaryRequest); 14 | assert.strictEqual(orphan_pb_service.OrphanService.DoUnary.responseType, orphan_pb.OrphanMessage); 15 | 16 | assert.strictEqual(orphan_pb_service.OrphanService.DoStream.methodName, "DoStream"); 17 | assert.strictEqual(orphan_pb_service.OrphanService.DoStream.service, orphan_pb_service.OrphanService); 18 | assert.strictEqual(orphan_pb_service.OrphanService.DoStream.requestStream, false); 19 | assert.strictEqual(orphan_pb_service.OrphanService.DoStream.responseStream, true); 20 | assert.strictEqual(orphan_pb_service.OrphanService.DoStream.requestType, orphan_pb.OrphanStreamRequest); 21 | assert.strictEqual(orphan_pb_service.OrphanService.DoStream.responseType, orphan_pb.OrphanMessage); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/orphan_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- DO NOT EDIT! 2 | 3 | // package: 4 | // file: proto/orphan.proto 5 | 6 | import * as proto_orphan_pb from "../proto/orphan_pb"; 7 | import * as grpc from "grpc"; 8 | 9 | interface IOrphanServiceService extends grpc.ServiceDefinition { 10 | doUnary: grpc.MethodDefinition; 11 | doStream: grpc.MethodDefinition; 12 | } 13 | 14 | export const OrphanServiceService: IOrphanServiceService; 15 | 16 | export class OrphanServiceClient extends grpc.Client { 17 | constructor(address: string, credentials: grpc.ChannelCredentials, options?: object); 18 | doUnary(argument: proto_orphan_pb.OrphanUnaryRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; 19 | doUnary(argument: proto_orphan_pb.OrphanUnaryRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; 20 | doUnary(argument: proto_orphan_pb.OrphanUnaryRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; 21 | doStream(argument: proto_orphan_pb.OrphanStreamRequest, metadataOrOptions?: grpc.Metadata | grpc.CallOptions | null): grpc.ClientReadableStream; 22 | doStream(argument: proto_orphan_pb.OrphanStreamRequest, metadata?: grpc.Metadata | null, options?: grpc.CallOptions | null): grpc.ClientReadableStream; 23 | } 24 | -------------------------------------------------------------------------------- /proto/examplecom/reserved_words.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examplecom; 4 | 5 | message ReservedWordsMessage { 6 | string abstract = 1; 7 | string boolean = 2; 8 | string break = 3; 9 | string byte = 4; 10 | string case = 5; 11 | string catch = 6; 12 | string char = 7; 13 | string class = 8; 14 | string const = 9; 15 | string continue = 10; 16 | string debugger = 11; 17 | string default = 12; 18 | string delete = 13; 19 | string do = 14; 20 | string double = 15; 21 | string else = 16; 22 | string enum = 17; 23 | string export = 18; 24 | string extends = 19; 25 | string false = 20; 26 | string final = 21; 27 | string finally = 22; 28 | string float = 23; 29 | string for = 24; 30 | string function = 25; 31 | string goto = 26; 32 | string if = 27; 33 | string implements = 28; 34 | string import = 29; 35 | string in = 30; 36 | string instanceof = 31; 37 | string int = 32; 38 | string interface = 33; 39 | string long = 34; 40 | string native = 35; 41 | string new = 36; 42 | string null = 37; 43 | string package = 38; 44 | string private = 39; 45 | string protected = 40; 46 | string public = 41; 47 | string return = 42; 48 | string short = 43; 49 | string static = 44; 50 | string super = 45; 51 | string switch = 46; 52 | string synchronized = 47; 53 | string this = 48; 54 | string throw = 49; 55 | string throws = 50; 56 | string transient = 51; 57 | string try = 52; 58 | string typeof = 53; 59 | string var = 54; 60 | string void = 55; 61 | string volatile = 56; 62 | string while = 57; 63 | string with = 58; 64 | } 65 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-protoc-gen", 3 | "version": "0.12.1-pre", 4 | "description": "Protoc Plugin for TypeScript Declarations and Service Definitions", 5 | "scripts": { 6 | "lint": "tslint -c tslint.json \"test/**/*.ts\" \"src/**/*.ts\"", 7 | "lint:fix": "npm run lint -- --fix", 8 | "clean": "rimraf lib", 9 | "build": "run-s clean tsc", 10 | "generate": "node generate.js", 11 | "tsc": "tsc", 12 | "test": "run-s test:unit test:integration", 13 | "test:unit": "node test/mocha-run-suite.js \"test/unit/**/*.ts\"", 14 | "test:integration": "node test/mocha-run-suite.js \"test/integration/**/*.ts\"", 15 | "prepublishOnly": "npm run build" 16 | }, 17 | "bin": { 18 | "protoc-gen-ts": "bin/protoc-gen-ts" 19 | }, 20 | "repository": "https://github.com/improbable-eng/ts-protoc-gen", 21 | "keywords": [ 22 | "protobuf", 23 | "protoc", 24 | "typescript", 25 | "ts", 26 | "grpc", 27 | "service", 28 | "proto3" 29 | ], 30 | "author": "Improbable", 31 | "license": "Apache-2.0", 32 | "dependencies": { 33 | "google-protobuf": "^3.6.1" 34 | }, 35 | "devDependencies": { 36 | "@improbable-eng/grpc-web": "^0.9.1", 37 | "@types/chai": "^3.5.2", 38 | "@types/google-protobuf": "^3.2.7", 39 | "@types/lodash": "^4.14.106", 40 | "@types/mocha": "^2.2.46", 41 | "@types/node": "^7.0.52", 42 | "babel": "^6.5.2", 43 | "browser-headers": "^0.4.1", 44 | "chai": "^3.5.0", 45 | "download-cli": "^1.1.1", 46 | "glob": "^7.1.4", 47 | "grpc": "^1.22.2", 48 | "grpc-tools": "^1.8.0", 49 | "lodash": "^4.17.5", 50 | "lodash.isequal": "^4.5.0", 51 | "mocha": "^5.2.0", 52 | "mocha-spec-json-output-reporter": "^1.1.6", 53 | "npm-run-all": "^4.1.5", 54 | "rimraf": "^2.6.3", 55 | "source-map-support": "^0.4.18", 56 | "ts-node": "^8.3.0", 57 | "tslint": "^5.9.1", 58 | "tsutils": "2.27.2", 59 | "typescript": "~3.1.6" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/ts/fileDescriptorTSD.ts: -------------------------------------------------------------------------------- 1 | import {filePathToPseudoNamespace, replaceProtoSuffix, getPathToRoot} from "../util"; 2 | import {ExportMap} from "../ExportMap"; 3 | import {Printer} from "../Printer"; 4 | import {FileDescriptorProto} from "google-protobuf/google/protobuf/descriptor_pb"; 5 | import {WellKnownTypesMap} from "../WellKnown"; 6 | import {printMessage} from "./message"; 7 | import {printEnum} from "./enum"; 8 | import {printExtension} from "./extensions"; 9 | 10 | export function printFileDescriptorTSD(fileDescriptor: FileDescriptorProto, exportMap: ExportMap) { 11 | const fileName = fileDescriptor.getName(); 12 | const packageName = fileDescriptor.getPackage(); 13 | 14 | const printer = new Printer(0); 15 | 16 | printer.printLn(`// package: ${packageName}`); 17 | printer.printLn(`// file: ${fileDescriptor.getName()}`); 18 | 19 | const upToRoot = getPathToRoot(fileName); 20 | 21 | printer.printEmptyLn(); 22 | printer.printLn(`import * as jspb from "google-protobuf";`); 23 | 24 | fileDescriptor.getDependencyList().forEach((dependency: string) => { 25 | const pseudoNamespace = filePathToPseudoNamespace(dependency); 26 | if (dependency in WellKnownTypesMap) { 27 | printer.printLn(`import * as ${pseudoNamespace} from "${WellKnownTypesMap[dependency]}";`); 28 | } else { 29 | const filePath = replaceProtoSuffix(dependency); 30 | printer.printLn(`import * as ${pseudoNamespace} from "${upToRoot}${filePath}";`); 31 | } 32 | }); 33 | 34 | fileDescriptor.getMessageTypeList().forEach(enumType => { 35 | printer.print(printMessage(fileName, exportMap, enumType, 0, fileDescriptor)); 36 | }); 37 | 38 | fileDescriptor.getExtensionList().forEach(extension => { 39 | printer.print(printExtension(fileName, exportMap, extension, 0)); 40 | }); 41 | 42 | fileDescriptor.getEnumTypeList().forEach(enumType => { 43 | printer.print(printEnum(enumType, 0)); 44 | }); 45 | 46 | printer.printEmptyLn(); 47 | 48 | return printer.getOutput(); 49 | } 50 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # release.sh 3 | # Automates releases of ts-protoc-gen 4 | 5 | function die() { 6 | echo ERROR: "$1" 7 | exit 1 8 | } 9 | 10 | function workspace_is_clean() { 11 | git diff-index --quiet HEAD 12 | return $? 13 | } 14 | 15 | function git_branch_name() { 16 | git rev-parse --abbrev-ref HEAD 17 | } 18 | 19 | function is_up_to_date() { 20 | git fetch 21 | [[ $(git rev-parse HEAD) == $(git rev-parse @{u}) ]] 22 | } 23 | 24 | if ! workspace_is_clean; then 25 | die "workspace has uncommitted changes, please commit them and try again" 26 | fi 27 | 28 | if [[ "$(git_branch_name)" != "master" ]]; then 29 | die "releases can only be made from the 'master' branch, you currently have '$(git_branch_name)' checked out" 30 | fi 31 | 32 | if ! is_up_to_date; then 33 | die "workspace has un-pushed commits, please push them and try again" 34 | fi 35 | 36 | PKG_VERSION=$(node -p "require('./package.json').version") 37 | if [[ "${PKG_VERSION}" = *-pre ]]; then 38 | die "package.json version (${PKG_VERSION}) must not end with a '-pre' suffix for a production release" 39 | fi 40 | 41 | npm install 42 | if ! workspace_is_clean; then 43 | die "workspace changes detected after npm install; please commit these changes and try again" 44 | fi 45 | 46 | CHANGELOG_FIRST_LINE=$(head -n 1 CHANGELOG.md) 47 | if [[ "${CHANGELOG_FIRST_LINE}" != "## ${PKG_VERSION}" ]]; then 48 | die "Expected first line of the CHANGELOG to be '## ${PKG_VERSION}' but was '${CHANGELOG_FIRST_LINE}'" 49 | fi 50 | 51 | echo 52 | head -n 10 CHANGELOG.md | sed 's/^/> /' 53 | echo 54 | read -p "Above are the first 10 lines of the CHANGELOG; does this look correct? " -n 1 -r 55 | echo 56 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then 57 | die "Aborting based on user input" 58 | fi 59 | 60 | git tag "${PKG_VERSION}" 61 | git push origin "refs/tags/${PKG_VERSION}" 62 | 63 | echo "Rolling to the next version" 64 | npm version patch 65 | BUMPED_PKG_VERSION=$(node -p "require('./package.json').version + '-pre'"); 66 | npm version ${BUMPED_PKG_VERSION} 67 | git reset --soft HEAD~2 68 | 69 | echo -e "## ${BUMPED_PKG_VERSION}\n" | cat - CHANGELOG.md > tmp.md 70 | mv tmp.md CHANGELOG.md 71 | git add CHANGELOG.md 72 | 73 | git commit -m "Bumped to v${BUMPED_PKG_VERSION}" 74 | git push origin master 75 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | before_deploy: | 3 | PKG_VERSION=$(node -p "require('./package.json').version") 4 | SHORT_COMMIT_HASH=$(git rev-parse --short HEAD) 5 | NPM_TAG="latest" 6 | 7 | if [[ "${PKG_VERSION}" = *-pre ]]; then 8 | NPM_TAG="next" 9 | fi 10 | echo "NPM_TAG=${NPM_TAG}" 11 | 12 | # If this is a pre-release version, give the package a unique version so we can publish it to npm 13 | # (as npm does not allow us to overwrite previously published packages) 14 | if [ "$NPM_TAG" == "next" ]; then 15 | UNIQUE_PKG_VERSION="${PKG_VERSION}.${SHORT_COMMIT_HASH}" 16 | npm version ${UNIQUE_PKG_VERSION} 17 | echo "Set package version to ${UNIQUE_PKG_VERSION}" 18 | cat package.json 19 | fi 20 | deploy: 21 | skip_cleanup: true 22 | provider: npm 23 | email: 24 | secure: WRWu/LodEL9DQO/p65MwFzOOAmfezOOVB7N7Wh56NImUSX0/Ves4Uuzm1yWhqb/OuonW3Ofm3wxmLiwjpJpiNf45OivI1N2Z/noKn+ZiAC/beuHUYXDR5FlHZvf0VmXXhjFnJPu1cRGHdTD2RIloL4z5TUajNta4FZdIo37lLfNodafaiTd+F/OQR3LsC7R7oyMKH3MLDbEEAZkfCv7Vfk+kxLhSezWJuy24APGG856oOEj49sy6s27hWsX89SruOQggbZFnw8yxWC0rkEp4ACNhdWx3FxhoQ5XR5AT4OB2Ydfgr8+YHQReBqZnHBn0RAQ5qLc+hJUhLGZZlw0WCbuAc8W+zd2IH5ufLUzTn3RfMCeDb50cfX9Dz7Zi9wPJDxCE8DMFJfHuCEV6GEuso5bu9vB175lGrwuOrkpvLlen/5HykLKSobAZ7gixnsg7F6oVV+CgM1xA7eN6oA2KPWzudMtydJ7aRDkHMyyHN7LsTMUmE5iTWTBZV0+o3x6dskc3xfSfXHjUuD3qefdraW0cV4gFrpq7r+dB3x6jUfKlwPeQkPb0RMsOw+v179kYmbS5M+ejvNI3Ta9ffrOvTZyEOq3b6WXJZU2TGa1hIazP8BXzZ6AEh6Oq7tRczlyNT9DM0bpocwPyPUF1+dduBxa10PJGkoRbBYT4abk2e7MI= 25 | api_key: 26 | secure: V5ha4R/5SByBygSa5V9Tm9gpxY3RhmPJueboD8gRIJ952IddUPwCL0wd3yp1Sln0/Ppeh9T6mAl3zCVCqGc4GTwpgh7CwhjXDQZ9kdjixqD464Giv2cxyQ2ZFDO7HDHbQyk+yLIFCQZr1CVMoMkkPxLx72zcJRVuISEITckeYozs32Fn3QciefJqzXr1l2BIQFtCV23StVx4QykPVyY/0l50xAoY3AJudh0MJYQ9gQBfCLgm8SCD0kVf5uAx1mowUDk+AjEbaYuxevZ6ovjuMt/CPzOoYSSOSgh+4///VtBxHcsk+8pGeamgZ0x6CDS9CVQ7tqydXWLrteB6qbkLsegJCcLZYGDHeaIaV+WQbyCzOD41G9hrFUFp49x0zb5XFvdZn7YKViRdeMrdS2yZdyj7gYLo/Cmkn86dvlSpoUx5ic0L5cEMhBHWIntRgyrSwR8zrxwOD+70Fq/nmAzRzN1qsgOIo5aqoVQakEMEFa5SQznE6Zw4skAxW8RtLQQfBbPWegwGVm/Ph9ERbcN1ZGCtQANW1gNPh0LmquiITGO5TH00uAOBoUoQ8X5LTFxmK5tihJX7gtAzWEg1N+JziLiJEEU6dJZqYa/HB5PQe/+uy89Tk2y4nk+S5U3iZuC0y7dbmfyNAmdDOEu38GL9wMSLrDDO3Uq/97QdQnaofVk= 27 | tag: "$NPM_TAG" 28 | on: 29 | branch: master 30 | cache: 31 | directories: 32 | - node_modules 33 | install: 34 | - npm install 35 | script: 36 | - "./travis-ci-build.sh" 37 | -------------------------------------------------------------------------------- /test/integration/enums.ts: -------------------------------------------------------------------------------- 1 | import {assert} from "chai"; 2 | import {EnumMessage} from "../../examples/generated/proto/examplecom/enum_message_pb"; 3 | import {ExternalEnum} from "../../examples/generated/proto/othercom/external_enum_pb"; 4 | import InternalEnum = EnumMessage.InternalEnum; 5 | 6 | describe("internal enums", () => { 7 | it("should allow getting internal enum fields on an empty enum", () => { 8 | const parentMsg = new EnumMessage(); 9 | assert.strictEqual(parentMsg.getInternalEnum(), 0); 10 | assert.deepEqual(parentMsg.getInternalEnumsList(), []); 11 | }); 12 | 13 | it("should allow setting and getting internal enum fields", () => { 14 | const parentMsg = new EnumMessage(); 15 | parentMsg.setInternalEnum(InternalEnum.FIRST); 16 | assert.strictEqual(parentMsg.getInternalEnum(), InternalEnum.FIRST); 17 | }); 18 | 19 | it("should allow setting and getting repeated internal enum fields", () => { 20 | const parentMsg = new EnumMessage(); 21 | parentMsg.setInternalEnumsList([InternalEnum.FIRST, InternalEnum.SECOND]); 22 | assert.deepEqual(parentMsg.getInternalEnumsList(), [InternalEnum.FIRST, InternalEnum.SECOND]); 23 | }); 24 | }); 25 | 26 | describe("external enums", () => { 27 | it("should allow getting external enum fields on an empty enum", () => { 28 | const parentMsg = new EnumMessage(); 29 | assert.strictEqual(parentMsg.getExternalEnum(), 0); 30 | assert.deepEqual(parentMsg.getExternalEnumsList(), []); 31 | }); 32 | 33 | it("should allow setting and getting external enum fields", () => { 34 | const parentMsg = new EnumMessage(); 35 | parentMsg.setExternalEnum(ExternalEnum.FIRST); 36 | assert.strictEqual(parentMsg.getExternalEnum(), ExternalEnum.FIRST); 37 | }); 38 | 39 | it("should allow setting and getting repeated external enum fields", () => { 40 | const parentMsg = new EnumMessage(); 41 | parentMsg.setExternalEnumsList([ExternalEnum.FIRST, ExternalEnum.SECOND]); 42 | assert.deepEqual(parentMsg.getExternalEnumsList(), [ExternalEnum.FIRST, ExternalEnum.SECOND]); 43 | }); 44 | }); 45 | 46 | describe("enum casing", () => { 47 | it("should export enums as ALL_CAPS in proto definitions (#21)", () => { 48 | const parentMsg = new EnumMessage(); 49 | parentMsg.setInternalEnum(InternalEnum.THIRD); // should compile. 50 | assert.ok(true, ".d.ts file should export the enum definition in ALL_CAPS"); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/orphan_grpc_pb.js: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- DO NOT EDIT! 2 | 3 | 'use strict'; 4 | var grpc = require('grpc'); 5 | var proto_orphan_pb = require('../proto/orphan_pb.js'); 6 | 7 | function serialize_OrphanMessage(arg) { 8 | if (!(arg instanceof proto_orphan_pb.OrphanMessage)) { 9 | throw new Error('Expected argument of type OrphanMessage'); 10 | } 11 | return Buffer.from(arg.serializeBinary()); 12 | } 13 | 14 | function deserialize_OrphanMessage(buffer_arg) { 15 | return proto_orphan_pb.OrphanMessage.deserializeBinary(new Uint8Array(buffer_arg)); 16 | } 17 | 18 | function serialize_OrphanStreamRequest(arg) { 19 | if (!(arg instanceof proto_orphan_pb.OrphanStreamRequest)) { 20 | throw new Error('Expected argument of type OrphanStreamRequest'); 21 | } 22 | return Buffer.from(arg.serializeBinary()); 23 | } 24 | 25 | function deserialize_OrphanStreamRequest(buffer_arg) { 26 | return proto_orphan_pb.OrphanStreamRequest.deserializeBinary(new Uint8Array(buffer_arg)); 27 | } 28 | 29 | function serialize_OrphanUnaryRequest(arg) { 30 | if (!(arg instanceof proto_orphan_pb.OrphanUnaryRequest)) { 31 | throw new Error('Expected argument of type OrphanUnaryRequest'); 32 | } 33 | return Buffer.from(arg.serializeBinary()); 34 | } 35 | 36 | function deserialize_OrphanUnaryRequest(buffer_arg) { 37 | return proto_orphan_pb.OrphanUnaryRequest.deserializeBinary(new Uint8Array(buffer_arg)); 38 | } 39 | 40 | 41 | var OrphanServiceService = exports.OrphanServiceService = { 42 | doUnary: { 43 | path: '/OrphanService/DoUnary', 44 | requestStream: false, 45 | responseStream: false, 46 | requestType: proto_orphan_pb.OrphanUnaryRequest, 47 | responseType: proto_orphan_pb.OrphanMessage, 48 | requestSerialize: serialize_OrphanUnaryRequest, 49 | requestDeserialize: deserialize_OrphanUnaryRequest, 50 | responseSerialize: serialize_OrphanMessage, 51 | responseDeserialize: deserialize_OrphanMessage, 52 | }, 53 | doStream: { 54 | path: '/OrphanService/DoStream', 55 | requestStream: false, 56 | responseStream: true, 57 | requestType: proto_orphan_pb.OrphanStreamRequest, 58 | responseType: proto_orphan_pb.OrphanMessage, 59 | requestSerialize: serialize_OrphanStreamRequest, 60 | requestDeserialize: deserialize_OrphanStreamRequest, 61 | responseSerialize: serialize_OrphanMessage, 62 | responseDeserialize: deserialize_OrphanMessage, 63 | }, 64 | }; 65 | 66 | exports.OrphanServiceClient = grpc.makeGenericClientConstructor(OrphanServiceService); 67 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/simplevalue_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simplevalue.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class SimpleValue extends jspb.Message { 7 | getFirstField(): string; 8 | setFirstField(value: string): void; 9 | 10 | getSecondField(): number; 11 | setSecondField(value: number): void; 12 | 13 | hasNumberValue(): boolean; 14 | clearNumberValue(): void; 15 | getNumberValue(): number; 16 | setNumberValue(value: number): void; 17 | 18 | hasStringValue(): boolean; 19 | clearStringValue(): void; 20 | getStringValue(): string; 21 | setStringValue(value: string): void; 22 | 23 | hasBoolValue(): boolean; 24 | clearBoolValue(): void; 25 | getBoolValue(): boolean; 26 | setBoolValue(value: boolean): void; 27 | 28 | hasNumber2Value(): boolean; 29 | clearNumber2Value(): void; 30 | getNumber2Value(): number; 31 | setNumber2Value(value: number): void; 32 | 33 | hasString2Value(): boolean; 34 | clearString2Value(): void; 35 | getString2Value(): string; 36 | setString2Value(value: string): void; 37 | 38 | hasBool2Value(): boolean; 39 | clearBool2Value(): void; 40 | getBool2Value(): boolean; 41 | setBool2Value(value: boolean): void; 42 | 43 | getKindCase(): SimpleValue.KindCase; 44 | getAnotherCase(): SimpleValue.AnotherCase; 45 | serializeBinary(): Uint8Array; 46 | toObject(includeInstance?: boolean): SimpleValue.AsObject; 47 | static toObject(includeInstance: boolean, msg: SimpleValue): SimpleValue.AsObject; 48 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 49 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 50 | static serializeBinaryToWriter(message: SimpleValue, writer: jspb.BinaryWriter): void; 51 | static deserializeBinary(bytes: Uint8Array): SimpleValue; 52 | static deserializeBinaryFromReader(message: SimpleValue, reader: jspb.BinaryReader): SimpleValue; 53 | } 54 | 55 | export namespace SimpleValue { 56 | export type AsObject = { 57 | firstField: string, 58 | secondField: number, 59 | numberValue: number, 60 | stringValue: string, 61 | boolValue: boolean, 62 | number2Value: number, 63 | string2Value: string, 64 | bool2Value: boolean, 65 | } 66 | 67 | export enum KindCase { 68 | KIND_NOT_SET = 0, 69 | NUMBER_VALUE = 3, 70 | STRING_VALUE = 6, 71 | BOOL_VALUE = 8, 72 | } 73 | 74 | export enum AnotherCase { 75 | ANOTHER_NOT_SET = 0, 76 | NUMBER2_VALUE = 4, 77 | STRING2_VALUE = 5, 78 | BOOL2_VALUE = 7, 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /test/unit/util.ts: -------------------------------------------------------------------------------- 1 | import {assert} from "chai"; 2 | import {oneOfName, replaceProtoSuffix, stripPrefix} from "../../src/util"; 3 | 4 | describe("util", () => { 5 | 6 | describe("replaceProtoSuffix", () => { 7 | [{ 8 | in: "github.com/improbable-eng/ts-protoc-gen/test/proto/examplecom/enum_message.proto", 9 | out: "github.com/improbable-eng/ts-protoc-gen/test/proto/examplecom/enum_message_pb", 10 | }, { 11 | in: "enum_message.proto", 12 | out: "enum_message_pb", 13 | }, { 14 | in: "enum_message.js", 15 | out: "enum_message.js", 16 | }, { 17 | in: ".proto/enum_message.proto", 18 | out: ".proto/enum_message_pb", 19 | }, { 20 | in: "protos/.proto/enum_message.proto", 21 | out: "protos/.proto/enum_message_pb", 22 | }, { 23 | in: "", 24 | out: "", 25 | }].forEach(scenario => { 26 | it(`should map '${scenario.in}' to '${scenario.out}'`, () => { 27 | const actual = replaceProtoSuffix(scenario.in); 28 | assert.equal(actual, scenario.out); 29 | }); 30 | }); 31 | }); 32 | 33 | describe("oneOfName", () => { 34 | [{ 35 | in: "one_of_name", 36 | out: "OneOfName", 37 | }, { 38 | in: "ONE_OF_NAME", 39 | out: "OneOfName", 40 | }, { 41 | in: "OneOfName", 42 | out: "Oneofname" 43 | }].forEach(senario => { 44 | it(`should map '${senario.in}' to '${senario.out}'`, () => { 45 | const actual = oneOfName(senario.in); 46 | assert.equal(actual, senario.out); 47 | }); 48 | }); 49 | }); 50 | 51 | describe("stripPrefix", () => { 52 | [ 53 | { 54 | input: "_foo", 55 | prefixToStrip: "_", 56 | expected: "foo", 57 | }, 58 | { 59 | input: "__foo", 60 | prefixToStrip: "__", 61 | expected: "foo" 62 | }, 63 | { 64 | input: "foo", 65 | prefixToStrip: "_", 66 | expected: "foo" 67 | }, 68 | { 69 | input: "a", 70 | prefixToStrip: "__", 71 | expected: "a" 72 | }, 73 | { 74 | input: "foo", 75 | prefixToStrip: "", 76 | expected: "foo" 77 | }, 78 | { 79 | input: "_", 80 | prefixToStrip: "_", 81 | expected: "" 82 | } 83 | ].forEach(scenario => { 84 | it(`should correctly strip '${scenario.prefixToStrip}' from '${scenario.input}'`, () => { 85 | const actual = stripPrefix(scenario.input, scenario.prefixToStrip); 86 | assert.equal(actual, scenario.expected); 87 | }); 88 | }); 89 | }); 90 | 91 | }); 92 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/simplevalue_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simplevalue.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class SimpleValue extends jspb.Message { 7 | getFirstField(): string; 8 | setFirstField(value: string): void; 9 | 10 | getSecondField(): number; 11 | setSecondField(value: number): void; 12 | 13 | hasNumberValue(): boolean; 14 | clearNumberValue(): void; 15 | getNumberValue(): number; 16 | setNumberValue(value: number): void; 17 | 18 | hasStringValue(): boolean; 19 | clearStringValue(): void; 20 | getStringValue(): string; 21 | setStringValue(value: string): void; 22 | 23 | hasBoolValue(): boolean; 24 | clearBoolValue(): void; 25 | getBoolValue(): boolean; 26 | setBoolValue(value: boolean): void; 27 | 28 | hasNumber2Value(): boolean; 29 | clearNumber2Value(): void; 30 | getNumber2Value(): number; 31 | setNumber2Value(value: number): void; 32 | 33 | hasString2Value(): boolean; 34 | clearString2Value(): void; 35 | getString2Value(): string; 36 | setString2Value(value: string): void; 37 | 38 | hasBool2Value(): boolean; 39 | clearBool2Value(): void; 40 | getBool2Value(): boolean; 41 | setBool2Value(value: boolean): void; 42 | 43 | getKindCase(): SimpleValue.KindCase; 44 | getAnotherCase(): SimpleValue.AnotherCase; 45 | serializeBinary(): Uint8Array; 46 | toObject(includeInstance?: boolean): SimpleValue.AsObject; 47 | static toObject(includeInstance: boolean, msg: SimpleValue): SimpleValue.AsObject; 48 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 49 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 50 | static serializeBinaryToWriter(message: SimpleValue, writer: jspb.BinaryWriter): void; 51 | static deserializeBinary(bytes: Uint8Array): SimpleValue; 52 | static deserializeBinaryFromReader(message: SimpleValue, reader: jspb.BinaryReader): SimpleValue; 53 | } 54 | 55 | export namespace SimpleValue { 56 | export type AsObject = { 57 | firstField: string, 58 | secondField: number, 59 | numberValue: number, 60 | stringValue: string, 61 | boolValue: boolean, 62 | number2Value: number, 63 | string2Value: string, 64 | bool2Value: boolean, 65 | } 66 | 67 | export enum KindCase { 68 | KIND_NOT_SET = 0, 69 | NUMBER_VALUE = 3, 70 | STRING_VALUE = 6, 71 | BOOL_VALUE = 8, 72 | } 73 | 74 | export enum AnotherCase { 75 | ANOTHER_NOT_SET = 0, 76 | NUMBER2_VALUE = 4, 77 | STRING2_VALUE = 5, 78 | BOOL2_VALUE = 7, 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/simplevalue_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simplevalue.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class SimpleValue extends jspb.Message { 7 | getFirstField(): string; 8 | setFirstField(value: string): void; 9 | 10 | getSecondField(): number; 11 | setSecondField(value: number): void; 12 | 13 | hasNumberValue(): boolean; 14 | clearNumberValue(): void; 15 | getNumberValue(): number; 16 | setNumberValue(value: number): void; 17 | 18 | hasStringValue(): boolean; 19 | clearStringValue(): void; 20 | getStringValue(): string; 21 | setStringValue(value: string): void; 22 | 23 | hasBoolValue(): boolean; 24 | clearBoolValue(): void; 25 | getBoolValue(): boolean; 26 | setBoolValue(value: boolean): void; 27 | 28 | hasNumber2Value(): boolean; 29 | clearNumber2Value(): void; 30 | getNumber2Value(): number; 31 | setNumber2Value(value: number): void; 32 | 33 | hasString2Value(): boolean; 34 | clearString2Value(): void; 35 | getString2Value(): string; 36 | setString2Value(value: string): void; 37 | 38 | hasBool2Value(): boolean; 39 | clearBool2Value(): void; 40 | getBool2Value(): boolean; 41 | setBool2Value(value: boolean): void; 42 | 43 | getKindCase(): SimpleValue.KindCase; 44 | getAnotherCase(): SimpleValue.AnotherCase; 45 | serializeBinary(): Uint8Array; 46 | toObject(includeInstance?: boolean): SimpleValue.AsObject; 47 | static toObject(includeInstance: boolean, msg: SimpleValue): SimpleValue.AsObject; 48 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 49 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 50 | static serializeBinaryToWriter(message: SimpleValue, writer: jspb.BinaryWriter): void; 51 | static deserializeBinary(bytes: Uint8Array): SimpleValue; 52 | static deserializeBinaryFromReader(message: SimpleValue, reader: jspb.BinaryReader): SimpleValue; 53 | } 54 | 55 | export namespace SimpleValue { 56 | export type AsObject = { 57 | firstField: string, 58 | secondField: number, 59 | numberValue: number, 60 | stringValue: string, 61 | boolValue: boolean, 62 | number2Value: number, 63 | string2Value: string, 64 | bool2Value: boolean, 65 | } 66 | 67 | export enum KindCase { 68 | KIND_NOT_SET = 0, 69 | NUMBER_VALUE = 3, 70 | STRING_VALUE = 6, 71 | BOOL_VALUE = 8, 72 | } 73 | 74 | export enum AnotherCase { 75 | ANOTHER_NOT_SET = 0, 76 | NUMBER2_VALUE = 4, 77 | STRING2_VALUE = 5, 78 | BOOL2_VALUE = 7, 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/primitive_message_v3_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/primitive_message_v3.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class PrimitiveMessageV3 extends jspb.Message { 7 | getMyDouble(): number; 8 | setMyDouble(value: number): void; 9 | 10 | getMyFloat(): number; 11 | setMyFloat(value: number): void; 12 | 13 | getMyInt32(): number; 14 | setMyInt32(value: number): void; 15 | 16 | getMyInt64(): number; 17 | setMyInt64(value: number): void; 18 | 19 | getMyUint32(): number; 20 | setMyUint32(value: number): void; 21 | 22 | getMyUint64(): number; 23 | setMyUint64(value: number): void; 24 | 25 | getMySint32(): number; 26 | setMySint32(value: number): void; 27 | 28 | getMySint64(): number; 29 | setMySint64(value: number): void; 30 | 31 | getMyFixed32(): number; 32 | setMyFixed32(value: number): void; 33 | 34 | getMyFixed64(): number; 35 | setMyFixed64(value: number): void; 36 | 37 | getMySfixed32(): number; 38 | setMySfixed32(value: number): void; 39 | 40 | getMySfixed64(): number; 41 | setMySfixed64(value: number): void; 42 | 43 | getMyBool(): boolean; 44 | setMyBool(value: boolean): void; 45 | 46 | getMyString(): string; 47 | setMyString(value: string): void; 48 | 49 | getMyBytes(): Uint8Array | string; 50 | getMyBytes_asU8(): Uint8Array; 51 | getMyBytes_asB64(): string; 52 | setMyBytes(value: Uint8Array | string): void; 53 | 54 | getMyNumber(): number; 55 | setMyNumber(value: number): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): PrimitiveMessageV3.AsObject; 59 | static toObject(includeInstance: boolean, msg: PrimitiveMessageV3): PrimitiveMessageV3.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: PrimitiveMessageV3, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): PrimitiveMessageV3; 64 | static deserializeBinaryFromReader(message: PrimitiveMessageV3, reader: jspb.BinaryReader): PrimitiveMessageV3; 65 | } 66 | 67 | export namespace PrimitiveMessageV3 { 68 | export type AsObject = { 69 | myDouble: number, 70 | myFloat: number, 71 | myInt32: number, 72 | myInt64: number, 73 | myUint32: number, 74 | myUint64: number, 75 | mySint32: number, 76 | mySint64: number, 77 | myFixed32: number, 78 | myFixed64: number, 79 | mySfixed32: number, 80 | mySfixed64: number, 81 | myBool: boolean, 82 | myString: string, 83 | myBytes: Uint8Array | string, 84 | myNumber: number, 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/primitive_message_v3_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/primitive_message_v3.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class PrimitiveMessageV3 extends jspb.Message { 7 | getMyDouble(): number; 8 | setMyDouble(value: number): void; 9 | 10 | getMyFloat(): number; 11 | setMyFloat(value: number): void; 12 | 13 | getMyInt32(): number; 14 | setMyInt32(value: number): void; 15 | 16 | getMyInt64(): number; 17 | setMyInt64(value: number): void; 18 | 19 | getMyUint32(): number; 20 | setMyUint32(value: number): void; 21 | 22 | getMyUint64(): number; 23 | setMyUint64(value: number): void; 24 | 25 | getMySint32(): number; 26 | setMySint32(value: number): void; 27 | 28 | getMySint64(): number; 29 | setMySint64(value: number): void; 30 | 31 | getMyFixed32(): number; 32 | setMyFixed32(value: number): void; 33 | 34 | getMyFixed64(): number; 35 | setMyFixed64(value: number): void; 36 | 37 | getMySfixed32(): number; 38 | setMySfixed32(value: number): void; 39 | 40 | getMySfixed64(): number; 41 | setMySfixed64(value: number): void; 42 | 43 | getMyBool(): boolean; 44 | setMyBool(value: boolean): void; 45 | 46 | getMyString(): string; 47 | setMyString(value: string): void; 48 | 49 | getMyBytes(): Uint8Array | string; 50 | getMyBytes_asU8(): Uint8Array; 51 | getMyBytes_asB64(): string; 52 | setMyBytes(value: Uint8Array | string): void; 53 | 54 | getMyNumber(): number; 55 | setMyNumber(value: number): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): PrimitiveMessageV3.AsObject; 59 | static toObject(includeInstance: boolean, msg: PrimitiveMessageV3): PrimitiveMessageV3.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: PrimitiveMessageV3, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): PrimitiveMessageV3; 64 | static deserializeBinaryFromReader(message: PrimitiveMessageV3, reader: jspb.BinaryReader): PrimitiveMessageV3; 65 | } 66 | 67 | export namespace PrimitiveMessageV3 { 68 | export type AsObject = { 69 | myDouble: number, 70 | myFloat: number, 71 | myInt32: number, 72 | myInt64: number, 73 | myUint32: number, 74 | myUint64: number, 75 | mySint32: number, 76 | mySint64: number, 77 | myFixed32: number, 78 | myFixed64: number, 79 | mySfixed32: number, 80 | mySfixed64: number, 81 | myBool: boolean, 82 | myString: string, 83 | myBytes: Uint8Array | string, 84 | myNumber: number, 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/primitive_message_v3_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/primitive_message_v3.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class PrimitiveMessageV3 extends jspb.Message { 7 | getMyDouble(): number; 8 | setMyDouble(value: number): void; 9 | 10 | getMyFloat(): number; 11 | setMyFloat(value: number): void; 12 | 13 | getMyInt32(): number; 14 | setMyInt32(value: number): void; 15 | 16 | getMyInt64(): number; 17 | setMyInt64(value: number): void; 18 | 19 | getMyUint32(): number; 20 | setMyUint32(value: number): void; 21 | 22 | getMyUint64(): number; 23 | setMyUint64(value: number): void; 24 | 25 | getMySint32(): number; 26 | setMySint32(value: number): void; 27 | 28 | getMySint64(): number; 29 | setMySint64(value: number): void; 30 | 31 | getMyFixed32(): number; 32 | setMyFixed32(value: number): void; 33 | 34 | getMyFixed64(): number; 35 | setMyFixed64(value: number): void; 36 | 37 | getMySfixed32(): number; 38 | setMySfixed32(value: number): void; 39 | 40 | getMySfixed64(): number; 41 | setMySfixed64(value: number): void; 42 | 43 | getMyBool(): boolean; 44 | setMyBool(value: boolean): void; 45 | 46 | getMyString(): string; 47 | setMyString(value: string): void; 48 | 49 | getMyBytes(): Uint8Array | string; 50 | getMyBytes_asU8(): Uint8Array; 51 | getMyBytes_asB64(): string; 52 | setMyBytes(value: Uint8Array | string): void; 53 | 54 | getMyNumber(): number; 55 | setMyNumber(value: number): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): PrimitiveMessageV3.AsObject; 59 | static toObject(includeInstance: boolean, msg: PrimitiveMessageV3): PrimitiveMessageV3.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: PrimitiveMessageV3, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): PrimitiveMessageV3; 64 | static deserializeBinaryFromReader(message: PrimitiveMessageV3, reader: jspb.BinaryReader): PrimitiveMessageV3; 65 | } 66 | 67 | export namespace PrimitiveMessageV3 { 68 | export type AsObject = { 69 | myDouble: number, 70 | myFloat: number, 71 | myInt32: number, 72 | myInt64: number, 73 | myUint32: number, 74 | myUint64: number, 75 | mySint32: number, 76 | mySint64: number, 77 | myFixed32: number, 78 | myFixed64: number, 79 | mySfixed32: number, 80 | mySfixed64: number, 81 | myBool: boolean, 82 | myString: string, 83 | myBytes: Uint8Array | string, 84 | myNumber: number, 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /src/ts/FieldTypes.ts: -------------------------------------------------------------------------------- 1 | import {filePathToPseudoNamespace, withinNamespaceFromExportEntry} from "../util"; 2 | import {ExportMap} from "../ExportMap"; 3 | import {FieldDescriptorProto} from "google-protobuf/google/protobuf/descriptor_pb"; 4 | 5 | export const MESSAGE_TYPE = 11; 6 | export const BYTES_TYPE = 12; 7 | export const ENUM_TYPE = 14; 8 | 9 | const TypeNumToTypeString: {[key: number]: string} = {}; 10 | TypeNumToTypeString[1] = "number"; // TYPE_DOUBLE 11 | TypeNumToTypeString[2] = "number"; // TYPE_FLOAT 12 | TypeNumToTypeString[3] = "number"; // TYPE_INT64 13 | TypeNumToTypeString[4] = "number"; // TYPE_UINT64 14 | TypeNumToTypeString[5] = "number"; // TYPE_INT32 15 | TypeNumToTypeString[6] = "number"; // TYPE_FIXED64 16 | TypeNumToTypeString[7] = "number"; // TYPE_FIXED32 17 | TypeNumToTypeString[8] = "boolean"; // TYPE_BOOL 18 | TypeNumToTypeString[9] = "string"; // TYPE_STRING 19 | TypeNumToTypeString[10] = "Object"; // TYPE_GROUP 20 | TypeNumToTypeString[MESSAGE_TYPE] = "Object"; // TYPE_MESSAGE - Length-delimited aggregate. 21 | TypeNumToTypeString[BYTES_TYPE] = "Uint8Array"; // TYPE_BYTES 22 | TypeNumToTypeString[13] = "number"; // TYPE_UINT32 23 | TypeNumToTypeString[ENUM_TYPE] = "number"; // TYPE_ENUM 24 | TypeNumToTypeString[15] = "number"; // TYPE_SFIXED32 25 | TypeNumToTypeString[16] = "number"; // TYPE_SFIXED64 26 | TypeNumToTypeString[17] = "number"; // TYPE_SINT32 - Uses ZigZag encoding. 27 | TypeNumToTypeString[18] = "number"; // TYPE_SINT64 - Uses ZigZag encoding. 28 | 29 | export function getTypeName(fieldTypeNum: number): string { 30 | return TypeNumToTypeString[fieldTypeNum]; 31 | } 32 | 33 | export function getFieldType(type: FieldDescriptorProto.Type, typeName: string, currentFileName: string, exportMap: ExportMap): string { 34 | if (type === MESSAGE_TYPE) { 35 | const fromExport = exportMap.getMessage(typeName); 36 | if (!fromExport) { 37 | throw new Error("Could not getFieldType for message: " + typeName); 38 | } 39 | const withinNamespace = withinNamespaceFromExportEntry(typeName, fromExport); 40 | if (fromExport.fileName === currentFileName) { 41 | return withinNamespace; 42 | } else { 43 | return filePathToPseudoNamespace(fromExport.fileName) + "." + withinNamespace; 44 | } 45 | } else if (type === ENUM_TYPE) { 46 | const fromExport = exportMap.getEnum(typeName); 47 | if (!fromExport) { 48 | throw new Error("Could not getFieldType for enum: " + typeName); 49 | } 50 | const withinNamespace = withinNamespaceFromExportEntry(typeName, fromExport); 51 | if (fromExport.fileName === currentFileName) { 52 | return `${withinNamespace}Map`; 53 | } else { 54 | return filePathToPseudoNamespace(fromExport.fileName) + "." + withinNamespace; 55 | } 56 | } else { 57 | return TypeNumToTypeString[type]; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/ExportMap.ts: -------------------------------------------------------------------------------- 1 | import { 2 | FileDescriptorProto, 3 | DescriptorProto, 4 | MessageOptions, 5 | EnumOptions, 6 | FieldDescriptorProto 7 | } from "google-protobuf/google/protobuf/descriptor_pb"; 8 | 9 | import Type = FieldDescriptorProto.Type; 10 | 11 | export type ExportMessageEntry = { 12 | pkg: string, 13 | fileName: string, 14 | messageOptions: MessageOptions, 15 | mapFieldOptions?: { 16 | key: [Type, string], 17 | value: [Type, string], 18 | } 19 | }; 20 | 21 | export type ExportEnumEntry = { 22 | pkg: string, 23 | fileName: string, 24 | enumOptions: EnumOptions, 25 | }; 26 | 27 | export class ExportMap { 28 | messageMap: {[key: string]: ExportMessageEntry} = {}; 29 | enumMap: {[key: string]: ExportEnumEntry} = {}; 30 | 31 | exportNested(scope: string, fileDescriptor: FileDescriptorProto, message: DescriptorProto) { 32 | const messageEntry: ExportMessageEntry = { 33 | pkg: fileDescriptor.getPackage(), 34 | fileName: fileDescriptor.getName(), 35 | messageOptions: message.getOptions(), 36 | mapFieldOptions: message.getOptions() && message.getOptions().getMapEntry() ? { 37 | key: [message.getFieldList()[0].getType(), message.getFieldList()[0].getTypeName().slice(1)], 38 | value: [message.getFieldList()[1].getType(), message.getFieldList()[1].getTypeName().slice(1)], 39 | } : undefined, 40 | }; 41 | 42 | const packagePrefix = scope ? scope + "." : ""; 43 | 44 | const entryName = `${packagePrefix}${message.getName()}`; 45 | this.messageMap[entryName] = messageEntry; 46 | 47 | message.getNestedTypeList().forEach(nested => { 48 | this.exportNested(`${packagePrefix}${message.getName()}`, fileDescriptor, nested); 49 | }); 50 | 51 | message.getEnumTypeList().forEach(enumType => { 52 | const identifier = `${packagePrefix}${message.getName()}.${enumType.getName()}`; 53 | this.enumMap[identifier] = { 54 | pkg: fileDescriptor.getPackage(), 55 | fileName: fileDescriptor.getName(), 56 | enumOptions: enumType.getOptions(), 57 | }; 58 | }); 59 | } 60 | 61 | addFileDescriptor(fileDescriptor: FileDescriptorProto) { 62 | const scope = fileDescriptor.getPackage(); 63 | fileDescriptor.getMessageTypeList().forEach(messageType => { 64 | this.exportNested(scope, fileDescriptor, messageType); 65 | }); 66 | 67 | fileDescriptor.getEnumTypeList().forEach(enumType => { 68 | const packagePrefix = scope ? scope + "." : ""; 69 | this.enumMap[packagePrefix + enumType.getName()] = { 70 | pkg: fileDescriptor.getPackage(), 71 | fileName: fileDescriptor.getName(), 72 | enumOptions: enumType.getOptions(), 73 | }; 74 | }); 75 | } 76 | 77 | getMessage(str: string): ExportMessageEntry | undefined { 78 | return this.messageMap[str]; 79 | } 80 | 81 | getEnum(str: string): ExportEnumEntry | undefined { 82 | return this.enumMap[str]; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/orphan_pb_service.d.ts: -------------------------------------------------------------------------------- 1 | // package: 2 | // file: proto/orphan.proto 3 | 4 | import * as proto_orphan_pb from "../proto/orphan_pb"; 5 | import {grpc} from "@improbable-eng/grpc-web"; 6 | 7 | type OrphanServiceDoUnary = { 8 | readonly methodName: string; 9 | readonly service: typeof OrphanService; 10 | readonly requestStream: false; 11 | readonly responseStream: false; 12 | readonly requestType: typeof proto_orphan_pb.OrphanUnaryRequest; 13 | readonly responseType: typeof proto_orphan_pb.OrphanMessage; 14 | }; 15 | 16 | type OrphanServiceDoStream = { 17 | readonly methodName: string; 18 | readonly service: typeof OrphanService; 19 | readonly requestStream: false; 20 | readonly responseStream: true; 21 | readonly requestType: typeof proto_orphan_pb.OrphanStreamRequest; 22 | readonly responseType: typeof proto_orphan_pb.OrphanMessage; 23 | }; 24 | 25 | export class OrphanService { 26 | static readonly serviceName: string; 27 | static readonly DoUnary: OrphanServiceDoUnary; 28 | static readonly DoStream: OrphanServiceDoStream; 29 | } 30 | 31 | export type ServiceError = { message: string, code: number; metadata: grpc.Metadata } 32 | export type Status = { details: string, code: number; metadata: grpc.Metadata } 33 | 34 | interface UnaryResponse { 35 | cancel(): void; 36 | } 37 | interface ResponseStream { 38 | cancel(): void; 39 | on(type: 'data', handler: (message: T) => void): ResponseStream; 40 | on(type: 'end', handler: (status?: Status) => void): ResponseStream; 41 | on(type: 'status', handler: (status: Status) => void): ResponseStream; 42 | } 43 | interface RequestStream { 44 | write(message: T): RequestStream; 45 | end(): void; 46 | cancel(): void; 47 | on(type: 'end', handler: (status?: Status) => void): RequestStream; 48 | on(type: 'status', handler: (status: Status) => void): RequestStream; 49 | } 50 | interface BidirectionalStream { 51 | write(message: ReqT): BidirectionalStream; 52 | end(): void; 53 | cancel(): void; 54 | on(type: 'data', handler: (message: ResT) => void): BidirectionalStream; 55 | on(type: 'end', handler: (status?: Status) => void): BidirectionalStream; 56 | on(type: 'status', handler: (status: Status) => void): BidirectionalStream; 57 | } 58 | 59 | export class OrphanServiceClient { 60 | readonly serviceHost: string; 61 | 62 | constructor(serviceHost: string, options?: grpc.RpcOptions); 63 | doUnary( 64 | requestMessage: proto_orphan_pb.OrphanUnaryRequest, 65 | metadata: grpc.Metadata, 66 | callback: (error: ServiceError|null, responseMessage: proto_orphan_pb.OrphanMessage|null) => void 67 | ): UnaryResponse; 68 | doUnary( 69 | requestMessage: proto_orphan_pb.OrphanUnaryRequest, 70 | callback: (error: ServiceError|null, responseMessage: proto_orphan_pb.OrphanMessage|null) => void 71 | ): UnaryResponse; 72 | doStream(requestMessage: proto_orphan_pb.OrphanStreamRequest, metadata?: grpc.Metadata): ResponseStream; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/enum_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/enum_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_enum_pb from "../../proto/othercom/external_enum_pb"; 6 | 7 | export class EnumMessage extends jspb.Message { 8 | getInternalEnum(): EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]; 9 | setInternalEnum(value: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]): void; 10 | 11 | clearInternalEnumsList(): void; 12 | getInternalEnumsList(): Array; 13 | setInternalEnumsList(value: Array): void; 14 | addInternalEnums(value: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap], index?: number): EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]; 15 | 16 | getExternalEnum(): proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]; 17 | setExternalEnum(value: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]): void; 18 | 19 | clearExternalEnumsList(): void; 20 | getExternalEnumsList(): Array; 21 | setExternalEnumsList(value: Array): void; 22 | addExternalEnums(value: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap], index?: number): proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]; 23 | 24 | serializeBinary(): Uint8Array; 25 | toObject(includeInstance?: boolean): EnumMessage.AsObject; 26 | static toObject(includeInstance: boolean, msg: EnumMessage): EnumMessage.AsObject; 27 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 28 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 29 | static serializeBinaryToWriter(message: EnumMessage, writer: jspb.BinaryWriter): void; 30 | static deserializeBinary(bytes: Uint8Array): EnumMessage; 31 | static deserializeBinaryFromReader(message: EnumMessage, reader: jspb.BinaryReader): EnumMessage; 32 | } 33 | 34 | export namespace EnumMessage { 35 | export type AsObject = { 36 | internalEnum: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap], 37 | internalEnumsList: Array, 38 | externalEnum: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap], 39 | externalEnumsList: Array, 40 | } 41 | 42 | export interface InternalEnumMap { 43 | DEFAULT: 0; 44 | FIRST: 1; 45 | SECOND: 2; 46 | THIRD: 3; 47 | } 48 | 49 | export const InternalEnum: InternalEnumMap; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/enum_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/enum_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_enum_pb from "../../proto/othercom/external_enum_pb"; 6 | 7 | export class EnumMessage extends jspb.Message { 8 | getInternalEnum(): EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]; 9 | setInternalEnum(value: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]): void; 10 | 11 | clearInternalEnumsList(): void; 12 | getInternalEnumsList(): Array; 13 | setInternalEnumsList(value: Array): void; 14 | addInternalEnums(value: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap], index?: number): EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]; 15 | 16 | getExternalEnum(): proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]; 17 | setExternalEnum(value: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]): void; 18 | 19 | clearExternalEnumsList(): void; 20 | getExternalEnumsList(): Array; 21 | setExternalEnumsList(value: Array): void; 22 | addExternalEnums(value: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap], index?: number): proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]; 23 | 24 | serializeBinary(): Uint8Array; 25 | toObject(includeInstance?: boolean): EnumMessage.AsObject; 26 | static toObject(includeInstance: boolean, msg: EnumMessage): EnumMessage.AsObject; 27 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 28 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 29 | static serializeBinaryToWriter(message: EnumMessage, writer: jspb.BinaryWriter): void; 30 | static deserializeBinary(bytes: Uint8Array): EnumMessage; 31 | static deserializeBinaryFromReader(message: EnumMessage, reader: jspb.BinaryReader): EnumMessage; 32 | } 33 | 34 | export namespace EnumMessage { 35 | export type AsObject = { 36 | internalEnum: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap], 37 | internalEnumsList: Array, 38 | externalEnum: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap], 39 | externalEnumsList: Array, 40 | } 41 | 42 | export interface InternalEnumMap { 43 | DEFAULT: 0; 44 | FIRST: 1; 45 | SECOND: 2; 46 | THIRD: 3; 47 | } 48 | 49 | export const InternalEnum: InternalEnumMap; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/enum_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/enum_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_enum_pb from "../../proto/othercom/external_enum_pb"; 6 | 7 | export class EnumMessage extends jspb.Message { 8 | getInternalEnum(): EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]; 9 | setInternalEnum(value: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]): void; 10 | 11 | clearInternalEnumsList(): void; 12 | getInternalEnumsList(): Array; 13 | setInternalEnumsList(value: Array): void; 14 | addInternalEnums(value: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap], index?: number): EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap]; 15 | 16 | getExternalEnum(): proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]; 17 | setExternalEnum(value: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]): void; 18 | 19 | clearExternalEnumsList(): void; 20 | getExternalEnumsList(): Array; 21 | setExternalEnumsList(value: Array): void; 22 | addExternalEnums(value: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap], index?: number): proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap]; 23 | 24 | serializeBinary(): Uint8Array; 25 | toObject(includeInstance?: boolean): EnumMessage.AsObject; 26 | static toObject(includeInstance: boolean, msg: EnumMessage): EnumMessage.AsObject; 27 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 28 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 29 | static serializeBinaryToWriter(message: EnumMessage, writer: jspb.BinaryWriter): void; 30 | static deserializeBinary(bytes: Uint8Array): EnumMessage; 31 | static deserializeBinaryFromReader(message: EnumMessage, reader: jspb.BinaryReader): EnumMessage; 32 | } 33 | 34 | export namespace EnumMessage { 35 | export type AsObject = { 36 | internalEnum: EnumMessage.InternalEnumMap[keyof EnumMessage.InternalEnumMap], 37 | internalEnumsList: Array, 38 | externalEnum: proto_othercom_external_enum_pb.ExternalEnumMap[keyof proto_othercom_external_enum_pb.ExternalEnumMap], 39 | externalEnumsList: Array, 40 | } 41 | 42 | export interface InternalEnumMap { 43 | DEFAULT: 0; 44 | FIRST: 1; 45 | SECOND: 2; 46 | THIRD: 3; 47 | } 48 | 49 | export const InternalEnum: InternalEnumMap; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import {printFileDescriptorTSD} from "./ts/fileDescriptorTSD"; 2 | import {ExportMap} from "./ExportMap"; 3 | import {replaceProtoSuffix, withAllStdIn} from "./util"; 4 | import {CodeGeneratorRequest, CodeGeneratorResponse} from "google-protobuf/google/protobuf/compiler/plugin_pb"; 5 | import {FileDescriptorProto} from "google-protobuf/google/protobuf/descriptor_pb"; 6 | import {generateGrpcWebService} from "./service/grpcweb"; 7 | import {generateGrpcNodeService} from "./service/grpcnode"; 8 | 9 | /** 10 | * This is the ProtoC compiler plugin. 11 | * 12 | * The Protocol Buffers Compiler can be extended to [support new languages via plugins](https://developers.google.com/protocol-buffers/docs/reference/other). 13 | * A plugin is just a program which reads a CodeGeneratorRequest protocol buffer from standard input 14 | * and then writes a CodeGeneratorResponse protocol buffer to standard output. 15 | * These message types are defined in [plugin.proto](https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/plugin.proto). 16 | * 17 | */ 18 | withAllStdIn((inputBuff: Buffer) => { 19 | try { 20 | const typedInputBuff = new Uint8Array(inputBuff.length); 21 | typedInputBuff.set(inputBuff); 22 | 23 | const codeGenRequest = CodeGeneratorRequest.deserializeBinary(typedInputBuff); 24 | const codeGenResponse = new CodeGeneratorResponse(); 25 | const exportMap = new ExportMap(); 26 | const fileNameToDescriptor: {[key: string]: FileDescriptorProto} = {}; 27 | 28 | // Generate separate `.ts` files for services if param is set 29 | const parameter = codeGenRequest.getParameter(); 30 | const generateGrpcWebServices = parameter === "service=grpc-web" || parameter === "service=true"; 31 | const generateGrpcNodeServices = parameter === "service=grpc-node"; 32 | 33 | if (parameter === "service=true") { 34 | console.warn("protoc-gen-ts warning: The service=true parameter has been deprecated. Use service=grpc-web instead."); 35 | } 36 | 37 | codeGenRequest.getProtoFileList().forEach(protoFileDescriptor => { 38 | fileNameToDescriptor[protoFileDescriptor.getName()] = protoFileDescriptor; 39 | exportMap.addFileDescriptor(protoFileDescriptor); 40 | }); 41 | 42 | codeGenRequest.getFileToGenerateList().forEach(fileName => { 43 | const outputFileName = replaceProtoSuffix(fileName); 44 | const thisFile = new CodeGeneratorResponse.File(); 45 | thisFile.setName(outputFileName + ".d.ts"); 46 | thisFile.setContent(printFileDescriptorTSD(fileNameToDescriptor[fileName], exportMap)); 47 | codeGenResponse.addFile(thisFile); 48 | 49 | if (generateGrpcWebServices) { 50 | generateGrpcWebService(outputFileName, fileNameToDescriptor[fileName], exportMap) 51 | .forEach(file => codeGenResponse.addFile(file)); 52 | } else if (generateGrpcNodeServices) { 53 | const file = generateGrpcNodeService(outputFileName, fileNameToDescriptor[fileName], exportMap); 54 | codeGenResponse.addFile(file); 55 | } 56 | }); 57 | 58 | process.stdout.write(Buffer.from(codeGenResponse.serializeBinary())); 59 | } catch (err) { 60 | console.error("protoc-gen-ts error: " + err.stack + "\n"); 61 | process.exit(1); 62 | } 63 | }); 64 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/simple_service_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simple_service.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | import * as google_protobuf_empty_pb from "google-protobuf/google/protobuf/empty_pb"; 7 | import * as google_protobuf_timestamp_pb from "google-protobuf/google/protobuf/timestamp_pb"; 8 | 9 | export class UnaryRequest extends jspb.Message { 10 | getSomeInt64(): number; 11 | setSomeInt64(value: number): void; 12 | 13 | hasSomeTimestamp(): boolean; 14 | clearSomeTimestamp(): void; 15 | getSomeTimestamp(): google_protobuf_timestamp_pb.Timestamp | undefined; 16 | setSomeTimestamp(value?: google_protobuf_timestamp_pb.Timestamp): void; 17 | 18 | serializeBinary(): Uint8Array; 19 | toObject(includeInstance?: boolean): UnaryRequest.AsObject; 20 | static toObject(includeInstance: boolean, msg: UnaryRequest): UnaryRequest.AsObject; 21 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 22 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 23 | static serializeBinaryToWriter(message: UnaryRequest, writer: jspb.BinaryWriter): void; 24 | static deserializeBinary(bytes: Uint8Array): UnaryRequest; 25 | static deserializeBinaryFromReader(message: UnaryRequest, reader: jspb.BinaryReader): UnaryRequest; 26 | } 27 | 28 | export namespace UnaryRequest { 29 | export type AsObject = { 30 | someInt64: number, 31 | someTimestamp?: google_protobuf_timestamp_pb.Timestamp.AsObject, 32 | } 33 | } 34 | 35 | export class UnaryResponse extends jspb.Message { 36 | serializeBinary(): Uint8Array; 37 | toObject(includeInstance?: boolean): UnaryResponse.AsObject; 38 | static toObject(includeInstance: boolean, msg: UnaryResponse): UnaryResponse.AsObject; 39 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 40 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 41 | static serializeBinaryToWriter(message: UnaryResponse, writer: jspb.BinaryWriter): void; 42 | static deserializeBinary(bytes: Uint8Array): UnaryResponse; 43 | static deserializeBinaryFromReader(message: UnaryResponse, reader: jspb.BinaryReader): UnaryResponse; 44 | } 45 | 46 | export namespace UnaryResponse { 47 | export type AsObject = { 48 | } 49 | } 50 | 51 | export class StreamRequest extends jspb.Message { 52 | getSomeString(): string; 53 | setSomeString(value: string): void; 54 | 55 | serializeBinary(): Uint8Array; 56 | toObject(includeInstance?: boolean): StreamRequest.AsObject; 57 | static toObject(includeInstance: boolean, msg: StreamRequest): StreamRequest.AsObject; 58 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 59 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 60 | static serializeBinaryToWriter(message: StreamRequest, writer: jspb.BinaryWriter): void; 61 | static deserializeBinary(bytes: Uint8Array): StreamRequest; 62 | static deserializeBinaryFromReader(message: StreamRequest, reader: jspb.BinaryReader): StreamRequest; 63 | } 64 | 65 | export namespace StreamRequest { 66 | export type AsObject = { 67 | someString: string, 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/simple_service_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simple_service.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | import * as google_protobuf_empty_pb from "google-protobuf/google/protobuf/empty_pb"; 7 | import * as google_protobuf_timestamp_pb from "google-protobuf/google/protobuf/timestamp_pb"; 8 | 9 | export class UnaryRequest extends jspb.Message { 10 | getSomeInt64(): number; 11 | setSomeInt64(value: number): void; 12 | 13 | hasSomeTimestamp(): boolean; 14 | clearSomeTimestamp(): void; 15 | getSomeTimestamp(): google_protobuf_timestamp_pb.Timestamp | undefined; 16 | setSomeTimestamp(value?: google_protobuf_timestamp_pb.Timestamp): void; 17 | 18 | serializeBinary(): Uint8Array; 19 | toObject(includeInstance?: boolean): UnaryRequest.AsObject; 20 | static toObject(includeInstance: boolean, msg: UnaryRequest): UnaryRequest.AsObject; 21 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 22 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 23 | static serializeBinaryToWriter(message: UnaryRequest, writer: jspb.BinaryWriter): void; 24 | static deserializeBinary(bytes: Uint8Array): UnaryRequest; 25 | static deserializeBinaryFromReader(message: UnaryRequest, reader: jspb.BinaryReader): UnaryRequest; 26 | } 27 | 28 | export namespace UnaryRequest { 29 | export type AsObject = { 30 | someInt64: number, 31 | someTimestamp?: google_protobuf_timestamp_pb.Timestamp.AsObject, 32 | } 33 | } 34 | 35 | export class UnaryResponse extends jspb.Message { 36 | serializeBinary(): Uint8Array; 37 | toObject(includeInstance?: boolean): UnaryResponse.AsObject; 38 | static toObject(includeInstance: boolean, msg: UnaryResponse): UnaryResponse.AsObject; 39 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 40 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 41 | static serializeBinaryToWriter(message: UnaryResponse, writer: jspb.BinaryWriter): void; 42 | static deserializeBinary(bytes: Uint8Array): UnaryResponse; 43 | static deserializeBinaryFromReader(message: UnaryResponse, reader: jspb.BinaryReader): UnaryResponse; 44 | } 45 | 46 | export namespace UnaryResponse { 47 | export type AsObject = { 48 | } 49 | } 50 | 51 | export class StreamRequest extends jspb.Message { 52 | getSomeString(): string; 53 | setSomeString(value: string): void; 54 | 55 | serializeBinary(): Uint8Array; 56 | toObject(includeInstance?: boolean): StreamRequest.AsObject; 57 | static toObject(includeInstance: boolean, msg: StreamRequest): StreamRequest.AsObject; 58 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 59 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 60 | static serializeBinaryToWriter(message: StreamRequest, writer: jspb.BinaryWriter): void; 61 | static deserializeBinary(bytes: Uint8Array): StreamRequest; 62 | static deserializeBinaryFromReader(message: StreamRequest, reader: jspb.BinaryReader): StreamRequest; 63 | } 64 | 65 | export namespace StreamRequest { 66 | export type AsObject = { 67 | someString: string, 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/simple_service_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/simple_service.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | import * as google_protobuf_empty_pb from "google-protobuf/google/protobuf/empty_pb"; 7 | import * as google_protobuf_timestamp_pb from "google-protobuf/google/protobuf/timestamp_pb"; 8 | 9 | export class UnaryRequest extends jspb.Message { 10 | getSomeInt64(): number; 11 | setSomeInt64(value: number): void; 12 | 13 | hasSomeTimestamp(): boolean; 14 | clearSomeTimestamp(): void; 15 | getSomeTimestamp(): google_protobuf_timestamp_pb.Timestamp | undefined; 16 | setSomeTimestamp(value?: google_protobuf_timestamp_pb.Timestamp): void; 17 | 18 | serializeBinary(): Uint8Array; 19 | toObject(includeInstance?: boolean): UnaryRequest.AsObject; 20 | static toObject(includeInstance: boolean, msg: UnaryRequest): UnaryRequest.AsObject; 21 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 22 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 23 | static serializeBinaryToWriter(message: UnaryRequest, writer: jspb.BinaryWriter): void; 24 | static deserializeBinary(bytes: Uint8Array): UnaryRequest; 25 | static deserializeBinaryFromReader(message: UnaryRequest, reader: jspb.BinaryReader): UnaryRequest; 26 | } 27 | 28 | export namespace UnaryRequest { 29 | export type AsObject = { 30 | someInt64: number, 31 | someTimestamp?: google_protobuf_timestamp_pb.Timestamp.AsObject, 32 | } 33 | } 34 | 35 | export class UnaryResponse extends jspb.Message { 36 | serializeBinary(): Uint8Array; 37 | toObject(includeInstance?: boolean): UnaryResponse.AsObject; 38 | static toObject(includeInstance: boolean, msg: UnaryResponse): UnaryResponse.AsObject; 39 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 40 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 41 | static serializeBinaryToWriter(message: UnaryResponse, writer: jspb.BinaryWriter): void; 42 | static deserializeBinary(bytes: Uint8Array): UnaryResponse; 43 | static deserializeBinaryFromReader(message: UnaryResponse, reader: jspb.BinaryReader): UnaryResponse; 44 | } 45 | 46 | export namespace UnaryResponse { 47 | export type AsObject = { 48 | } 49 | } 50 | 51 | export class StreamRequest extends jspb.Message { 52 | getSomeString(): string; 53 | setSomeString(value: string): void; 54 | 55 | serializeBinary(): Uint8Array; 56 | toObject(includeInstance?: boolean): StreamRequest.AsObject; 57 | static toObject(includeInstance: boolean, msg: StreamRequest): StreamRequest.AsObject; 58 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 59 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 60 | static serializeBinaryToWriter(message: StreamRequest, writer: jspb.BinaryWriter): void; 61 | static deserializeBinary(bytes: Uint8Array): StreamRequest; 62 | static deserializeBinaryFromReader(message: StreamRequest, reader: jspb.BinaryReader): StreamRequest; 63 | } 64 | 65 | export namespace StreamRequest { 66 | export type AsObject = { 67 | someString: string, 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/orphan_pb_service.js: -------------------------------------------------------------------------------- 1 | // package: 2 | // file: proto/orphan.proto 3 | 4 | var proto_orphan_pb = require("../proto/orphan_pb"); 5 | var grpc = require("@improbable-eng/grpc-web").grpc; 6 | 7 | var OrphanService = (function () { 8 | function OrphanService() {} 9 | OrphanService.serviceName = "OrphanService"; 10 | return OrphanService; 11 | }()); 12 | 13 | OrphanService.DoUnary = { 14 | methodName: "DoUnary", 15 | service: OrphanService, 16 | requestStream: false, 17 | responseStream: false, 18 | requestType: proto_orphan_pb.OrphanUnaryRequest, 19 | responseType: proto_orphan_pb.OrphanMessage 20 | }; 21 | 22 | OrphanService.DoStream = { 23 | methodName: "DoStream", 24 | service: OrphanService, 25 | requestStream: false, 26 | responseStream: true, 27 | requestType: proto_orphan_pb.OrphanStreamRequest, 28 | responseType: proto_orphan_pb.OrphanMessage 29 | }; 30 | 31 | exports.OrphanService = OrphanService; 32 | 33 | function OrphanServiceClient(serviceHost, options) { 34 | this.serviceHost = serviceHost; 35 | this.options = options || {}; 36 | } 37 | 38 | OrphanServiceClient.prototype.doUnary = function doUnary(requestMessage, metadata, callback) { 39 | if (arguments.length === 2) { 40 | callback = arguments[1]; 41 | } 42 | var client = grpc.unary(OrphanService.DoUnary, { 43 | request: requestMessage, 44 | host: this.serviceHost, 45 | metadata: metadata, 46 | transport: this.options.transport, 47 | debug: this.options.debug, 48 | onEnd: function (response) { 49 | if (callback) { 50 | if (response.status !== grpc.Code.OK) { 51 | var err = new Error(response.statusMessage); 52 | err.code = response.status; 53 | err.metadata = response.trailers; 54 | callback(err, null); 55 | } else { 56 | callback(null, response.message); 57 | } 58 | } 59 | } 60 | }); 61 | return { 62 | cancel: function () { 63 | callback = null; 64 | client.close(); 65 | } 66 | }; 67 | }; 68 | 69 | OrphanServiceClient.prototype.doStream = function doStream(requestMessage, metadata) { 70 | var listeners = { 71 | data: [], 72 | end: [], 73 | status: [] 74 | }; 75 | var client = grpc.invoke(OrphanService.DoStream, { 76 | request: requestMessage, 77 | host: this.serviceHost, 78 | metadata: metadata, 79 | transport: this.options.transport, 80 | debug: this.options.debug, 81 | onMessage: function (responseMessage) { 82 | listeners.data.forEach(function (handler) { 83 | handler(responseMessage); 84 | }); 85 | }, 86 | onEnd: function (status, statusMessage, trailers) { 87 | listeners.status.forEach(function (handler) { 88 | handler({ code: status, details: statusMessage, metadata: trailers }); 89 | }); 90 | listeners.end.forEach(function (handler) { 91 | handler({ code: status, details: statusMessage, metadata: trailers }); 92 | }); 93 | listeners = null; 94 | } 95 | }); 96 | return { 97 | on: function (type, handler) { 98 | listeners[type].push(handler); 99 | return this; 100 | }, 101 | cancel: function () { 102 | listeners = null; 103 | client.close(); 104 | } 105 | }; 106 | }; 107 | 108 | exports.OrphanServiceClient = OrphanServiceClient; 109 | 110 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/map_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/map_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_enum_pb from "../../proto/othercom/external_enum_pb"; 6 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 7 | 8 | export class MapMessage extends jspb.Message { 9 | getInternalEnumsMap(): jspb.Map; 10 | clearInternalEnumsMap(): void; 11 | getInternalChildrenMap(): jspb.Map; 12 | clearInternalChildrenMap(): void; 13 | getExternalEnumsMap(): jspb.Map; 14 | clearExternalEnumsMap(): void; 15 | getExternalChildrenMap(): jspb.Map; 16 | clearExternalChildrenMap(): void; 17 | getPrimitiveIntsMap(): jspb.Map; 18 | clearPrimitiveIntsMap(): void; 19 | serializeBinary(): Uint8Array; 20 | toObject(includeInstance?: boolean): MapMessage.AsObject; 21 | static toObject(includeInstance: boolean, msg: MapMessage): MapMessage.AsObject; 22 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 23 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 24 | static serializeBinaryToWriter(message: MapMessage, writer: jspb.BinaryWriter): void; 25 | static deserializeBinary(bytes: Uint8Array): MapMessage; 26 | static deserializeBinaryFromReader(message: MapMessage, reader: jspb.BinaryReader): MapMessage; 27 | } 28 | 29 | export namespace MapMessage { 30 | export type AsObject = { 31 | internalEnumsMap: Array<[number, MapMessage.InternalEnumMap[keyof MapMessage.InternalEnumMap]]>, 32 | internalChildrenMap: Array<[string, MapMessage.InternalChildMessage.AsObject]>, 33 | externalEnumsMap: Array<[number, proto_othercom_external_enum_pb.ExternalEnum[keyof proto_othercom_external_enum_pb.ExternalEnum]]>, 34 | externalChildrenMap: Array<[string, proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject]>, 35 | primitiveIntsMap: Array<[string, number]>, 36 | } 37 | 38 | export class InternalChildMessage extends jspb.Message { 39 | getMyString(): string; 40 | setMyString(value: string): void; 41 | 42 | serializeBinary(): Uint8Array; 43 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 44 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 45 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 46 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 47 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 48 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 49 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 50 | } 51 | 52 | export namespace InternalChildMessage { 53 | export type AsObject = { 54 | myString: string, 55 | } 56 | } 57 | 58 | export interface InternalEnumMap { 59 | DEFAULT: 0; 60 | FIRST: 1; 61 | SECOND: 2; 62 | } 63 | 64 | export const InternalEnum: InternalEnumMap; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/map_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/map_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_enum_pb from "../../proto/othercom/external_enum_pb"; 6 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 7 | 8 | export class MapMessage extends jspb.Message { 9 | getInternalEnumsMap(): jspb.Map; 10 | clearInternalEnumsMap(): void; 11 | getInternalChildrenMap(): jspb.Map; 12 | clearInternalChildrenMap(): void; 13 | getExternalEnumsMap(): jspb.Map; 14 | clearExternalEnumsMap(): void; 15 | getExternalChildrenMap(): jspb.Map; 16 | clearExternalChildrenMap(): void; 17 | getPrimitiveIntsMap(): jspb.Map; 18 | clearPrimitiveIntsMap(): void; 19 | serializeBinary(): Uint8Array; 20 | toObject(includeInstance?: boolean): MapMessage.AsObject; 21 | static toObject(includeInstance: boolean, msg: MapMessage): MapMessage.AsObject; 22 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 23 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 24 | static serializeBinaryToWriter(message: MapMessage, writer: jspb.BinaryWriter): void; 25 | static deserializeBinary(bytes: Uint8Array): MapMessage; 26 | static deserializeBinaryFromReader(message: MapMessage, reader: jspb.BinaryReader): MapMessage; 27 | } 28 | 29 | export namespace MapMessage { 30 | export type AsObject = { 31 | internalEnumsMap: Array<[number, MapMessage.InternalEnumMap[keyof MapMessage.InternalEnumMap]]>, 32 | internalChildrenMap: Array<[string, MapMessage.InternalChildMessage.AsObject]>, 33 | externalEnumsMap: Array<[number, proto_othercom_external_enum_pb.ExternalEnum[keyof proto_othercom_external_enum_pb.ExternalEnum]]>, 34 | externalChildrenMap: Array<[string, proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject]>, 35 | primitiveIntsMap: Array<[string, number]>, 36 | } 37 | 38 | export class InternalChildMessage extends jspb.Message { 39 | getMyString(): string; 40 | setMyString(value: string): void; 41 | 42 | serializeBinary(): Uint8Array; 43 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 44 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 45 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 46 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 47 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 48 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 49 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 50 | } 51 | 52 | export namespace InternalChildMessage { 53 | export type AsObject = { 54 | myString: string, 55 | } 56 | } 57 | 58 | export interface InternalEnumMap { 59 | DEFAULT: 0; 60 | FIRST: 1; 61 | SECOND: 2; 62 | } 63 | 64 | export const InternalEnum: InternalEnumMap; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/map_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/map_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_enum_pb from "../../proto/othercom/external_enum_pb"; 6 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 7 | 8 | export class MapMessage extends jspb.Message { 9 | getInternalEnumsMap(): jspb.Map; 10 | clearInternalEnumsMap(): void; 11 | getInternalChildrenMap(): jspb.Map; 12 | clearInternalChildrenMap(): void; 13 | getExternalEnumsMap(): jspb.Map; 14 | clearExternalEnumsMap(): void; 15 | getExternalChildrenMap(): jspb.Map; 16 | clearExternalChildrenMap(): void; 17 | getPrimitiveIntsMap(): jspb.Map; 18 | clearPrimitiveIntsMap(): void; 19 | serializeBinary(): Uint8Array; 20 | toObject(includeInstance?: boolean): MapMessage.AsObject; 21 | static toObject(includeInstance: boolean, msg: MapMessage): MapMessage.AsObject; 22 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 23 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 24 | static serializeBinaryToWriter(message: MapMessage, writer: jspb.BinaryWriter): void; 25 | static deserializeBinary(bytes: Uint8Array): MapMessage; 26 | static deserializeBinaryFromReader(message: MapMessage, reader: jspb.BinaryReader): MapMessage; 27 | } 28 | 29 | export namespace MapMessage { 30 | export type AsObject = { 31 | internalEnumsMap: Array<[number, MapMessage.InternalEnumMap[keyof MapMessage.InternalEnumMap]]>, 32 | internalChildrenMap: Array<[string, MapMessage.InternalChildMessage.AsObject]>, 33 | externalEnumsMap: Array<[number, proto_othercom_external_enum_pb.ExternalEnum[keyof proto_othercom_external_enum_pb.ExternalEnum]]>, 34 | externalChildrenMap: Array<[string, proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject]>, 35 | primitiveIntsMap: Array<[string, number]>, 36 | } 37 | 38 | export class InternalChildMessage extends jspb.Message { 39 | getMyString(): string; 40 | setMyString(value: string): void; 41 | 42 | serializeBinary(): Uint8Array; 43 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 44 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 45 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 46 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 47 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 48 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 49 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 50 | } 51 | 52 | export namespace InternalChildMessage { 53 | export type AsObject = { 54 | myString: string, 55 | } 56 | } 57 | 58 | export interface InternalEnumMap { 59 | DEFAULT: 0; 60 | FIRST: 1; 61 | SECOND: 2; 62 | } 63 | 64 | export const InternalEnum: InternalEnumMap; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | 3 | ### Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ### Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ### Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ### Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ### Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [Improbable](https://improbable.io/company/contact-us). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ### Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/parent_message_v3_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v3.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | 7 | export class ParentMessageV3 extends jspb.Message { 8 | hasInternalChildMessage(): boolean; 9 | clearInternalChildMessage(): void; 10 | getInternalChildMessage(): ParentMessageV3.InternalChildMessage | undefined; 11 | setInternalChildMessage(value?: ParentMessageV3.InternalChildMessage): void; 12 | 13 | clearInternalChildrenList(): void; 14 | getInternalChildrenList(): Array; 15 | setInternalChildrenList(value: Array): void; 16 | addInternalChildren(value?: ParentMessageV3.InternalChildMessage, index?: number): ParentMessageV3.InternalChildMessage; 17 | 18 | hasExternalChildMessage(): boolean; 19 | clearExternalChildMessage(): void; 20 | getExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage | undefined; 21 | setExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 22 | 23 | clearExternalChildrenList(): void; 24 | getExternalChildrenList(): Array; 25 | setExternalChildrenList(value: Array): void; 26 | addExternalChildren(value?: proto_othercom_external_child_message_pb.ExternalChildMessage, index?: number): proto_othercom_external_child_message_pb.ExternalChildMessage; 27 | 28 | serializeBinary(): Uint8Array; 29 | toObject(includeInstance?: boolean): ParentMessageV3.AsObject; 30 | static toObject(includeInstance: boolean, msg: ParentMessageV3): ParentMessageV3.AsObject; 31 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 32 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 33 | static serializeBinaryToWriter(message: ParentMessageV3, writer: jspb.BinaryWriter): void; 34 | static deserializeBinary(bytes: Uint8Array): ParentMessageV3; 35 | static deserializeBinaryFromReader(message: ParentMessageV3, reader: jspb.BinaryReader): ParentMessageV3; 36 | } 37 | 38 | export namespace ParentMessageV3 { 39 | export type AsObject = { 40 | internalChildMessage?: ParentMessageV3.InternalChildMessage.AsObject, 41 | internalChildrenList: Array, 42 | externalChildMessage?: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 43 | externalChildrenList: Array, 44 | } 45 | 46 | export class InternalChildMessage extends jspb.Message { 47 | getMyString(): string; 48 | setMyString(value: string): void; 49 | 50 | serializeBinary(): Uint8Array; 51 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 52 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 53 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 54 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 55 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 56 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 57 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 58 | } 59 | 60 | export namespace InternalChildMessage { 61 | export type AsObject = { 62 | myString: string, 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/parent_message_v3_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v3.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | 7 | export class ParentMessageV3 extends jspb.Message { 8 | hasInternalChildMessage(): boolean; 9 | clearInternalChildMessage(): void; 10 | getInternalChildMessage(): ParentMessageV3.InternalChildMessage | undefined; 11 | setInternalChildMessage(value?: ParentMessageV3.InternalChildMessage): void; 12 | 13 | clearInternalChildrenList(): void; 14 | getInternalChildrenList(): Array; 15 | setInternalChildrenList(value: Array): void; 16 | addInternalChildren(value?: ParentMessageV3.InternalChildMessage, index?: number): ParentMessageV3.InternalChildMessage; 17 | 18 | hasExternalChildMessage(): boolean; 19 | clearExternalChildMessage(): void; 20 | getExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage | undefined; 21 | setExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 22 | 23 | clearExternalChildrenList(): void; 24 | getExternalChildrenList(): Array; 25 | setExternalChildrenList(value: Array): void; 26 | addExternalChildren(value?: proto_othercom_external_child_message_pb.ExternalChildMessage, index?: number): proto_othercom_external_child_message_pb.ExternalChildMessage; 27 | 28 | serializeBinary(): Uint8Array; 29 | toObject(includeInstance?: boolean): ParentMessageV3.AsObject; 30 | static toObject(includeInstance: boolean, msg: ParentMessageV3): ParentMessageV3.AsObject; 31 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 32 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 33 | static serializeBinaryToWriter(message: ParentMessageV3, writer: jspb.BinaryWriter): void; 34 | static deserializeBinary(bytes: Uint8Array): ParentMessageV3; 35 | static deserializeBinaryFromReader(message: ParentMessageV3, reader: jspb.BinaryReader): ParentMessageV3; 36 | } 37 | 38 | export namespace ParentMessageV3 { 39 | export type AsObject = { 40 | internalChildMessage?: ParentMessageV3.InternalChildMessage.AsObject, 41 | internalChildrenList: Array, 42 | externalChildMessage?: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 43 | externalChildrenList: Array, 44 | } 45 | 46 | export class InternalChildMessage extends jspb.Message { 47 | getMyString(): string; 48 | setMyString(value: string): void; 49 | 50 | serializeBinary(): Uint8Array; 51 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 52 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 53 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 54 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 55 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 56 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 57 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 58 | } 59 | 60 | export namespace InternalChildMessage { 61 | export type AsObject = { 62 | myString: string, 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/parent_message_v3_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v3.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | 7 | export class ParentMessageV3 extends jspb.Message { 8 | hasInternalChildMessage(): boolean; 9 | clearInternalChildMessage(): void; 10 | getInternalChildMessage(): ParentMessageV3.InternalChildMessage | undefined; 11 | setInternalChildMessage(value?: ParentMessageV3.InternalChildMessage): void; 12 | 13 | clearInternalChildrenList(): void; 14 | getInternalChildrenList(): Array; 15 | setInternalChildrenList(value: Array): void; 16 | addInternalChildren(value?: ParentMessageV3.InternalChildMessage, index?: number): ParentMessageV3.InternalChildMessage; 17 | 18 | hasExternalChildMessage(): boolean; 19 | clearExternalChildMessage(): void; 20 | getExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage | undefined; 21 | setExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 22 | 23 | clearExternalChildrenList(): void; 24 | getExternalChildrenList(): Array; 25 | setExternalChildrenList(value: Array): void; 26 | addExternalChildren(value?: proto_othercom_external_child_message_pb.ExternalChildMessage, index?: number): proto_othercom_external_child_message_pb.ExternalChildMessage; 27 | 28 | serializeBinary(): Uint8Array; 29 | toObject(includeInstance?: boolean): ParentMessageV3.AsObject; 30 | static toObject(includeInstance: boolean, msg: ParentMessageV3): ParentMessageV3.AsObject; 31 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 32 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 33 | static serializeBinaryToWriter(message: ParentMessageV3, writer: jspb.BinaryWriter): void; 34 | static deserializeBinary(bytes: Uint8Array): ParentMessageV3; 35 | static deserializeBinaryFromReader(message: ParentMessageV3, reader: jspb.BinaryReader): ParentMessageV3; 36 | } 37 | 38 | export namespace ParentMessageV3 { 39 | export type AsObject = { 40 | internalChildMessage?: ParentMessageV3.InternalChildMessage.AsObject, 41 | internalChildrenList: Array, 42 | externalChildMessage?: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 43 | externalChildrenList: Array, 44 | } 45 | 46 | export class InternalChildMessage extends jspb.Message { 47 | getMyString(): string; 48 | setMyString(value: string): void; 49 | 50 | serializeBinary(): Uint8Array; 51 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 52 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 53 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 54 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 55 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 56 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 57 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 58 | } 59 | 60 | export namespace InternalChildMessage { 61 | export type AsObject = { 62 | myString: string, 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /test/integration/oneof.ts: -------------------------------------------------------------------------------- 1 | import {assert} from "chai"; 2 | import {OneOfMessage, CamelCasedOneOfMessage, SnakeCasedOneOfMessage} from "../../examples/generated/proto/examplecom/oneof_message_pb"; 3 | import {ExternalChildMessage} from "../../examples/generated/proto/othercom/external_child_message_pb"; 4 | import InternalChildMessage = OneOfMessage.InternalChildMessage; 5 | 6 | describe("oneofs", () => { 7 | it("should allow getting oneof fields on an empty message", () => { 8 | const parentMsg = new OneOfMessage(); 9 | assert.strictEqual(parentMsg.getInternalChildMessage() as InternalChildMessage, undefined); 10 | assert.strictEqual(parentMsg.getExternalChildMessage() as ExternalChildMessage, undefined); 11 | assert.strictEqual(parentMsg.getMyInt64() as number, 0); 12 | assert.strictEqual(parentMsg.getMyString() as string, ""); 13 | assert.strictEqual(parentMsg.getGroupCase() as OneOfMessage.GroupCase, OneOfMessage.GroupCase.GROUP_NOT_SET); 14 | }); 15 | 16 | it("should allow setting and getting oneof fields", () => { 17 | const parentMsg = new OneOfMessage(); 18 | const internalChildMessage = new InternalChildMessage(); 19 | internalChildMessage.setMyString("internal"); 20 | parentMsg.setInternalChildMessage(internalChildMessage); 21 | assert.strictEqual(parentMsg.getGroupCase() as OneOfMessage.GroupCase, OneOfMessage.GroupCase.INTERNAL_CHILD_MESSAGE); 22 | assert.strictEqual(parentMsg.getInternalChildMessage()!.getMyString() as string, "internal"); 23 | 24 | const externalChildMessage = new ExternalChildMessage(); 25 | externalChildMessage.setMyString("external"); 26 | parentMsg.setExternalChildMessage(externalChildMessage); 27 | assert.strictEqual(parentMsg.getGroupCase() as OneOfMessage.GroupCase, OneOfMessage.GroupCase.EXTERNAL_CHILD_MESSAGE); 28 | assert.strictEqual(parentMsg.getExternalChildMessage()!.getMyString() as string, "external"); 29 | assert.strictEqual(parentMsg.getInternalChildMessage() as InternalChildMessage, undefined); 30 | 31 | parentMsg.setExternalChildMessage(undefined); 32 | assert.strictEqual(parentMsg.getGroupCase() as OneOfMessage.GroupCase, OneOfMessage.GroupCase.GROUP_NOT_SET); 33 | assert.strictEqual(parentMsg.getExternalChildMessage() as ExternalChildMessage, undefined); 34 | assert.strictEqual(parentMsg.getInternalChildMessage() as InternalChildMessage, undefined); 35 | }); 36 | 37 | it("should only show one of the fields in toObject", () => { 38 | const parentMsg = new OneOfMessage(); 39 | const internalChildMessage = new InternalChildMessage(); 40 | internalChildMessage.setMyString("internal"); 41 | parentMsg.setInternalChildMessage(internalChildMessage); 42 | assert.strictEqual(parentMsg.getGroupCase() as OneOfMessage.GroupCase, OneOfMessage.GroupCase.INTERNAL_CHILD_MESSAGE); 43 | assert.strictEqual(parentMsg.getInternalChildMessage()!.getMyString() as string, "internal"); 44 | assert.deepEqual(parentMsg.toObject() as { 45 | externalChildMessage?: { 46 | myString: string, 47 | }, 48 | internalChildMessage?: { 49 | myString: string, 50 | }, 51 | myInt64: number, 52 | myString: string, 53 | }, { 54 | externalChildMessage: undefined, 55 | internalChildMessage: { 56 | myString: "internal", 57 | }, 58 | myInt64: 0, 59 | myString: "", 60 | }); 61 | 62 | parentMsg.setMyString("hello world"); 63 | assert.deepEqual(parentMsg.toObject() as { 64 | externalChildMessage?: { 65 | myString: string, 66 | }, 67 | internalChildMessage?: { 68 | myString: string, 69 | }, 70 | myInt64: number, 71 | myString: string, 72 | }, { 73 | externalChildMessage: undefined, 74 | internalChildMessage: undefined, 75 | myInt64: 0, 76 | myString: "hello world", 77 | }); 78 | }); 79 | 80 | it("should handle casing inconsistencies present in protoc-gen's javascript implementation (see #63)", () => { 81 | assert.strictEqual(typeof CamelCasedOneOfMessage.CamelcasedmessageCase, "object"); 82 | assert.strictEqual(typeof SnakeCasedOneOfMessage.SnakeCasedMessageCase, "object"); 83 | }); 84 | }); 85 | -------------------------------------------------------------------------------- /generate.js: -------------------------------------------------------------------------------- 1 | const { spawnSync } = require("child_process"); 2 | 3 | const { existsSync, mkdirSync } = require("fs"); 4 | const { resolve } = require("path"); 5 | 6 | const protocVersion = "3.5.1"; 7 | 8 | const examplesGeneratedPath = resolve(__dirname, "examples", "generated"); 9 | const examplesGeneratedGrpcWebPath = resolve(__dirname, "examples", "generated-grpc-web"); 10 | const examplesGeneratedGrpcNodePath = resolve(__dirname, "examples", "generated-grpc-node"); 11 | 12 | const binSuffix = process.platform === "win32" ? ".cmd" : ""; 13 | const nodeModulesBin = resolve(__dirname, "node_modules", ".bin"); 14 | 15 | const downloadPath = resolve(nodeModulesBin, "download") + binSuffix; 16 | 17 | const protocRoot = resolve(__dirname, "protoc"); 18 | const protocPath = resolve(protocRoot, "bin", "protoc"); 19 | 20 | const protocPluginPath = resolve(__dirname, "bin", "protoc-gen-ts") + binSuffix; 21 | 22 | const rimrafPath = resolve(nodeModulesBin, "rimraf") + binSuffix; 23 | 24 | const supportedPlatforms = { 25 | darwin: { 26 | downloadSuffix: "osx-x86_64", 27 | name: "Mac" 28 | }, 29 | linux: { 30 | downloadSuffix: "linux-x86_64", 31 | name: "Linux" 32 | }, 33 | win32: { 34 | downloadSuffix: "win32", 35 | name: "Windows" 36 | } 37 | }; 38 | 39 | const platform = supportedPlatforms[process.platform]; 40 | const platformName = platform ? 41 | platform.name : 42 | `UNKNOWN:${process.platform}`; 43 | console.log("You appear to be running on", platformName); 44 | 45 | requireBuild(); 46 | 47 | const glob = require("glob"); 48 | 49 | requireProtoc(); 50 | 51 | requireDir(examplesGeneratedPath); 52 | requireDir(examplesGeneratedGrpcWebPath); 53 | requireDir(examplesGeneratedGrpcNodePath); 54 | 55 | // Generate no services 56 | 57 | run(protocPath, 58 | `--proto_path=${__dirname}`, 59 | `--plugin=protoc-gen-ts=${protocPluginPath}`, 60 | `--js_out=import_style=commonjs,binary:${examplesGeneratedPath}`, 61 | `--ts_out=${examplesGeneratedPath}`, 62 | ...glob.sync(resolve(__dirname, "proto", "**/*.proto")) 63 | ); 64 | 65 | // Generate grpc-web services 66 | 67 | run(protocPath, 68 | `--proto_path=${__dirname}`, 69 | `--plugin=protoc-gen-ts=${protocPluginPath}`, 70 | `--js_out=import_style=commonjs,binary:${examplesGeneratedGrpcWebPath}`, 71 | `--ts_out=service=grpc-web:${examplesGeneratedGrpcWebPath}`, 72 | ...glob.sync(resolve(__dirname, "proto", "**/*.proto")) 73 | ); 74 | 75 | // Generate grpc-node services 76 | 77 | run(protocPath, 78 | `--proto_path=${__dirname}`, 79 | `--plugin=protoc-gen-ts=${protocPluginPath}`, 80 | `--plugin=protoc-gen-grpc=node_modules/.bin/grpc_tools_node_protoc_plugin`, 81 | `--js_out=import_style=commonjs,binary:${examplesGeneratedGrpcNodePath}`, 82 | `--ts_out=service=grpc-node:${examplesGeneratedGrpcNodePath}`, 83 | `--grpc_out=${examplesGeneratedGrpcNodePath}`, 84 | ...glob.sync(resolve(__dirname, "proto", "**/*.proto")) 85 | ); 86 | 87 | run(rimrafPath, protocRoot); 88 | 89 | function requireBuild() { 90 | console.log("Ensuring we have NPM packages installed..."); 91 | run("npm", "install"); 92 | 93 | console.log("Compiling ts-protoc-gen..."); 94 | run("npm", "run", "build"); 95 | } 96 | 97 | function requireProtoc() { 98 | if (existsSync(protocPath)) { 99 | return; 100 | } 101 | 102 | if (!platform) { 103 | throw new Error( 104 | "Cannot download protoc. " + 105 | platformName + 106 | " is not currently supported by ts-protoc-gen" 107 | ); 108 | } 109 | 110 | console.log(`Downloading protoc v${protocVersion} for ${platform.name}`); 111 | const protocUrl = 112 | `https://github.com/google/protobuf/releases/download/v${protocVersion}/protoc-${protocVersion}-${platform.downloadSuffix}.zip`; 113 | 114 | run(downloadPath, 115 | "--extract", 116 | "--out", protocRoot, 117 | protocUrl); 118 | } 119 | 120 | function requireDir(path) { 121 | if (existsSync(path)) { 122 | run(rimrafPath, path); 123 | } 124 | 125 | mkdirSync(path); 126 | } 127 | 128 | function run(executablePath, ...args) { 129 | const result = spawnSync(executablePath, args, { shell: true, stdio: "inherit" }); 130 | if (result.status !== 0) { 131 | throw new Error(`Exited ${executablePath} with status ${result.status}`); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /examples/generated/proto/orphan_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: 2 | // file: proto/orphan.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class OrphanMapMessage extends jspb.Message { 7 | getPrimitiveIntsMap(): jspb.Map; 8 | clearPrimitiveIntsMap(): void; 9 | serializeBinary(): Uint8Array; 10 | toObject(includeInstance?: boolean): OrphanMapMessage.AsObject; 11 | static toObject(includeInstance: boolean, msg: OrphanMapMessage): OrphanMapMessage.AsObject; 12 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 13 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 14 | static serializeBinaryToWriter(message: OrphanMapMessage, writer: jspb.BinaryWriter): void; 15 | static deserializeBinary(bytes: Uint8Array): OrphanMapMessage; 16 | static deserializeBinaryFromReader(message: OrphanMapMessage, reader: jspb.BinaryReader): OrphanMapMessage; 17 | } 18 | 19 | export namespace OrphanMapMessage { 20 | export type AsObject = { 21 | primitiveIntsMap: Array<[string, number]>, 22 | } 23 | } 24 | 25 | export class OrphanMessage extends jspb.Message { 26 | getMyString(): string; 27 | setMyString(value: string): void; 28 | 29 | getMyBool(): boolean; 30 | setMyBool(value: boolean): void; 31 | 32 | getMyEnum(): OrphanEnumMap[keyof OrphanEnumMap]; 33 | setMyEnum(value: OrphanEnumMap[keyof OrphanEnumMap]): void; 34 | 35 | serializeBinary(): Uint8Array; 36 | toObject(includeInstance?: boolean): OrphanMessage.AsObject; 37 | static toObject(includeInstance: boolean, msg: OrphanMessage): OrphanMessage.AsObject; 38 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 39 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 40 | static serializeBinaryToWriter(message: OrphanMessage, writer: jspb.BinaryWriter): void; 41 | static deserializeBinary(bytes: Uint8Array): OrphanMessage; 42 | static deserializeBinaryFromReader(message: OrphanMessage, reader: jspb.BinaryReader): OrphanMessage; 43 | } 44 | 45 | export namespace OrphanMessage { 46 | export type AsObject = { 47 | myString: string, 48 | myBool: boolean, 49 | myEnum: OrphanEnumMap[keyof OrphanEnumMap], 50 | } 51 | } 52 | 53 | export class OrphanUnaryRequest extends jspb.Message { 54 | getSomeInt64(): number; 55 | setSomeInt64(value: number): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): OrphanUnaryRequest.AsObject; 59 | static toObject(includeInstance: boolean, msg: OrphanUnaryRequest): OrphanUnaryRequest.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: OrphanUnaryRequest, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): OrphanUnaryRequest; 64 | static deserializeBinaryFromReader(message: OrphanUnaryRequest, reader: jspb.BinaryReader): OrphanUnaryRequest; 65 | } 66 | 67 | export namespace OrphanUnaryRequest { 68 | export type AsObject = { 69 | someInt64: number, 70 | } 71 | } 72 | 73 | export class OrphanStreamRequest extends jspb.Message { 74 | getSomeString(): string; 75 | setSomeString(value: string): void; 76 | 77 | serializeBinary(): Uint8Array; 78 | toObject(includeInstance?: boolean): OrphanStreamRequest.AsObject; 79 | static toObject(includeInstance: boolean, msg: OrphanStreamRequest): OrphanStreamRequest.AsObject; 80 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 81 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 82 | static serializeBinaryToWriter(message: OrphanStreamRequest, writer: jspb.BinaryWriter): void; 83 | static deserializeBinary(bytes: Uint8Array): OrphanStreamRequest; 84 | static deserializeBinaryFromReader(message: OrphanStreamRequest, reader: jspb.BinaryReader): OrphanStreamRequest; 85 | } 86 | 87 | export namespace OrphanStreamRequest { 88 | export type AsObject = { 89 | someString: string, 90 | } 91 | } 92 | 93 | export interface OrphanEnumMap { 94 | UNKNOWN: 0; 95 | ONE: 1; 96 | TWO: 2; 97 | } 98 | 99 | export const OrphanEnum: OrphanEnumMap; 100 | 101 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/orphan_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: 2 | // file: proto/orphan.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class OrphanMapMessage extends jspb.Message { 7 | getPrimitiveIntsMap(): jspb.Map; 8 | clearPrimitiveIntsMap(): void; 9 | serializeBinary(): Uint8Array; 10 | toObject(includeInstance?: boolean): OrphanMapMessage.AsObject; 11 | static toObject(includeInstance: boolean, msg: OrphanMapMessage): OrphanMapMessage.AsObject; 12 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 13 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 14 | static serializeBinaryToWriter(message: OrphanMapMessage, writer: jspb.BinaryWriter): void; 15 | static deserializeBinary(bytes: Uint8Array): OrphanMapMessage; 16 | static deserializeBinaryFromReader(message: OrphanMapMessage, reader: jspb.BinaryReader): OrphanMapMessage; 17 | } 18 | 19 | export namespace OrphanMapMessage { 20 | export type AsObject = { 21 | primitiveIntsMap: Array<[string, number]>, 22 | } 23 | } 24 | 25 | export class OrphanMessage extends jspb.Message { 26 | getMyString(): string; 27 | setMyString(value: string): void; 28 | 29 | getMyBool(): boolean; 30 | setMyBool(value: boolean): void; 31 | 32 | getMyEnum(): OrphanEnumMap[keyof OrphanEnumMap]; 33 | setMyEnum(value: OrphanEnumMap[keyof OrphanEnumMap]): void; 34 | 35 | serializeBinary(): Uint8Array; 36 | toObject(includeInstance?: boolean): OrphanMessage.AsObject; 37 | static toObject(includeInstance: boolean, msg: OrphanMessage): OrphanMessage.AsObject; 38 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 39 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 40 | static serializeBinaryToWriter(message: OrphanMessage, writer: jspb.BinaryWriter): void; 41 | static deserializeBinary(bytes: Uint8Array): OrphanMessage; 42 | static deserializeBinaryFromReader(message: OrphanMessage, reader: jspb.BinaryReader): OrphanMessage; 43 | } 44 | 45 | export namespace OrphanMessage { 46 | export type AsObject = { 47 | myString: string, 48 | myBool: boolean, 49 | myEnum: OrphanEnumMap[keyof OrphanEnumMap], 50 | } 51 | } 52 | 53 | export class OrphanUnaryRequest extends jspb.Message { 54 | getSomeInt64(): number; 55 | setSomeInt64(value: number): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): OrphanUnaryRequest.AsObject; 59 | static toObject(includeInstance: boolean, msg: OrphanUnaryRequest): OrphanUnaryRequest.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: OrphanUnaryRequest, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): OrphanUnaryRequest; 64 | static deserializeBinaryFromReader(message: OrphanUnaryRequest, reader: jspb.BinaryReader): OrphanUnaryRequest; 65 | } 66 | 67 | export namespace OrphanUnaryRequest { 68 | export type AsObject = { 69 | someInt64: number, 70 | } 71 | } 72 | 73 | export class OrphanStreamRequest extends jspb.Message { 74 | getSomeString(): string; 75 | setSomeString(value: string): void; 76 | 77 | serializeBinary(): Uint8Array; 78 | toObject(includeInstance?: boolean): OrphanStreamRequest.AsObject; 79 | static toObject(includeInstance: boolean, msg: OrphanStreamRequest): OrphanStreamRequest.AsObject; 80 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 81 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 82 | static serializeBinaryToWriter(message: OrphanStreamRequest, writer: jspb.BinaryWriter): void; 83 | static deserializeBinary(bytes: Uint8Array): OrphanStreamRequest; 84 | static deserializeBinaryFromReader(message: OrphanStreamRequest, reader: jspb.BinaryReader): OrphanStreamRequest; 85 | } 86 | 87 | export namespace OrphanStreamRequest { 88 | export type AsObject = { 89 | someString: string, 90 | } 91 | } 92 | 93 | export interface OrphanEnumMap { 94 | UNKNOWN: 0; 95 | ONE: 1; 96 | TWO: 2; 97 | } 98 | 99 | export const OrphanEnum: OrphanEnumMap; 100 | 101 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/orphan_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: 2 | // file: proto/orphan.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class OrphanMapMessage extends jspb.Message { 7 | getPrimitiveIntsMap(): jspb.Map; 8 | clearPrimitiveIntsMap(): void; 9 | serializeBinary(): Uint8Array; 10 | toObject(includeInstance?: boolean): OrphanMapMessage.AsObject; 11 | static toObject(includeInstance: boolean, msg: OrphanMapMessage): OrphanMapMessage.AsObject; 12 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 13 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 14 | static serializeBinaryToWriter(message: OrphanMapMessage, writer: jspb.BinaryWriter): void; 15 | static deserializeBinary(bytes: Uint8Array): OrphanMapMessage; 16 | static deserializeBinaryFromReader(message: OrphanMapMessage, reader: jspb.BinaryReader): OrphanMapMessage; 17 | } 18 | 19 | export namespace OrphanMapMessage { 20 | export type AsObject = { 21 | primitiveIntsMap: Array<[string, number]>, 22 | } 23 | } 24 | 25 | export class OrphanMessage extends jspb.Message { 26 | getMyString(): string; 27 | setMyString(value: string): void; 28 | 29 | getMyBool(): boolean; 30 | setMyBool(value: boolean): void; 31 | 32 | getMyEnum(): OrphanEnumMap[keyof OrphanEnumMap]; 33 | setMyEnum(value: OrphanEnumMap[keyof OrphanEnumMap]): void; 34 | 35 | serializeBinary(): Uint8Array; 36 | toObject(includeInstance?: boolean): OrphanMessage.AsObject; 37 | static toObject(includeInstance: boolean, msg: OrphanMessage): OrphanMessage.AsObject; 38 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 39 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 40 | static serializeBinaryToWriter(message: OrphanMessage, writer: jspb.BinaryWriter): void; 41 | static deserializeBinary(bytes: Uint8Array): OrphanMessage; 42 | static deserializeBinaryFromReader(message: OrphanMessage, reader: jspb.BinaryReader): OrphanMessage; 43 | } 44 | 45 | export namespace OrphanMessage { 46 | export type AsObject = { 47 | myString: string, 48 | myBool: boolean, 49 | myEnum: OrphanEnumMap[keyof OrphanEnumMap], 50 | } 51 | } 52 | 53 | export class OrphanUnaryRequest extends jspb.Message { 54 | getSomeInt64(): number; 55 | setSomeInt64(value: number): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): OrphanUnaryRequest.AsObject; 59 | static toObject(includeInstance: boolean, msg: OrphanUnaryRequest): OrphanUnaryRequest.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: OrphanUnaryRequest, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): OrphanUnaryRequest; 64 | static deserializeBinaryFromReader(message: OrphanUnaryRequest, reader: jspb.BinaryReader): OrphanUnaryRequest; 65 | } 66 | 67 | export namespace OrphanUnaryRequest { 68 | export type AsObject = { 69 | someInt64: number, 70 | } 71 | } 72 | 73 | export class OrphanStreamRequest extends jspb.Message { 74 | getSomeString(): string; 75 | setSomeString(value: string): void; 76 | 77 | serializeBinary(): Uint8Array; 78 | toObject(includeInstance?: boolean): OrphanStreamRequest.AsObject; 79 | static toObject(includeInstance: boolean, msg: OrphanStreamRequest): OrphanStreamRequest.AsObject; 80 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 81 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 82 | static serializeBinaryToWriter(message: OrphanStreamRequest, writer: jspb.BinaryWriter): void; 83 | static deserializeBinary(bytes: Uint8Array): OrphanStreamRequest; 84 | static deserializeBinaryFromReader(message: OrphanStreamRequest, reader: jspb.BinaryReader): OrphanStreamRequest; 85 | } 86 | 87 | export namespace OrphanStreamRequest { 88 | export type AsObject = { 89 | someString: string, 90 | } 91 | } 92 | 93 | export interface OrphanEnumMap { 94 | UNKNOWN: 0; 95 | ONE: 1; 96 | TWO: 2; 97 | } 98 | 99 | export const OrphanEnum: OrphanEnumMap; 100 | 101 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/simple_service_grpc_pb.d.ts: -------------------------------------------------------------------------------- 1 | // GENERATED CODE -- DO NOT EDIT! 2 | 3 | // package: examplecom 4 | // file: proto/examplecom/simple_service.proto 5 | 6 | import * as proto_examplecom_simple_service_pb from "../../proto/examplecom/simple_service_pb"; 7 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 8 | import * as google_protobuf_empty_pb from "google-protobuf/google/protobuf/empty_pb"; 9 | import * as grpc from "grpc"; 10 | 11 | interface ISimpleServiceService extends grpc.ServiceDefinition { 12 | doUnary: grpc.MethodDefinition; 13 | doServerStream: grpc.MethodDefinition; 14 | doClientStream: grpc.MethodDefinition; 15 | doBidiStream: grpc.MethodDefinition; 16 | delete: grpc.MethodDefinition; 17 | } 18 | 19 | export const SimpleServiceService: ISimpleServiceService; 20 | 21 | export class SimpleServiceClient extends grpc.Client { 22 | constructor(address: string, credentials: grpc.ChannelCredentials, options?: object); 23 | doUnary(argument: proto_examplecom_simple_service_pb.UnaryRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; 24 | doUnary(argument: proto_examplecom_simple_service_pb.UnaryRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; 25 | doUnary(argument: proto_examplecom_simple_service_pb.UnaryRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; 26 | doServerStream(argument: proto_examplecom_simple_service_pb.StreamRequest, metadataOrOptions?: grpc.Metadata | grpc.CallOptions | null): grpc.ClientReadableStream; 27 | doServerStream(argument: proto_examplecom_simple_service_pb.StreamRequest, metadata?: grpc.Metadata | null, options?: grpc.CallOptions | null): grpc.ClientReadableStream; 28 | doClientStream(callback: grpc.requestCallback): grpc.ClientWritableStream; 29 | doClientStream(metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientWritableStream; 30 | doClientStream(metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientWritableStream; 31 | doBidiStream(metadataOrOptions?: grpc.Metadata | grpc.CallOptions | null): grpc.ClientDuplexStream; 32 | doBidiStream(metadata?: grpc.Metadata | null, options?: grpc.CallOptions | null): grpc.ClientDuplexStream; 33 | delete(argument: proto_examplecom_simple_service_pb.UnaryRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; 34 | delete(argument: proto_examplecom_simple_service_pb.UnaryRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; 35 | delete(argument: proto_examplecom_simple_service_pb.UnaryRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; 36 | } 37 | -------------------------------------------------------------------------------- /src/util.ts: -------------------------------------------------------------------------------- 1 | import {FileDescriptorProto} from "google-protobuf/google/protobuf/descriptor_pb"; 2 | import {ExportEnumEntry, ExportMessageEntry} from "./ExportMap"; 3 | export function filePathToPseudoNamespace(filePath: string): string { 4 | return filePath.replace(".proto", "").replace(/\//g, "_").replace(/\./g, "_").replace(/\-/g, "_") + "_pb"; 5 | } 6 | 7 | export function stripPrefix(str: string, prefix: string) { 8 | if (str.substr(0, prefix.length) === prefix) { 9 | return str.substr(prefix.length); 10 | } 11 | return str; 12 | } 13 | 14 | export function snakeToCamel(str: string): string { 15 | return str.replace(/(\_\w)/g, function(m) { 16 | return m[1].toUpperCase(); 17 | }); 18 | } 19 | 20 | export function uppercaseFirst(str: string): string { 21 | return str.charAt(0).toUpperCase() + str.slice(1); 22 | } 23 | 24 | const PROTO2_SYNTAX = "proto2"; 25 | export function isProto2(fileDescriptor: FileDescriptorProto): boolean { 26 | // Empty syntax defaults to proto2 27 | return (fileDescriptor.getSyntax() === "" || fileDescriptor.getSyntax() === PROTO2_SYNTAX); 28 | } 29 | 30 | export function oneOfName(name: string) { 31 | return uppercaseFirst(snakeToCamel(name.toLowerCase())); 32 | } 33 | 34 | export function generateIndent(indentLevel: number): string { 35 | let indent = ""; 36 | for (let i = 0; i < indentLevel; i++) { 37 | indent += " "; 38 | } 39 | return indent; 40 | } 41 | 42 | export function getPathToRoot(fileName: string) { 43 | const depth = fileName.split("/").length; 44 | return depth === 1 ? "./" : new Array(depth).join("../"); 45 | } 46 | 47 | export function withinNamespaceFromExportEntry(name: string, exportEntry: ExportMessageEntry | ExportEnumEntry) { 48 | return exportEntry.pkg ? name.substring(exportEntry.pkg.length + 1) : name; 49 | } 50 | 51 | export function replaceProtoSuffix(protoFilePath: string): string { 52 | const suffix = ".proto"; 53 | const hasProtoSuffix = protoFilePath.slice(protoFilePath.length - suffix.length) === suffix; 54 | return hasProtoSuffix 55 | ? protoFilePath.slice(0, -suffix.length) + "_pb" 56 | : protoFilePath; 57 | } 58 | 59 | export function withAllStdIn(callback: (buffer: Buffer) => void): void { 60 | const ret: Buffer[] = []; 61 | let len = 0; 62 | 63 | const stdin = process.stdin; 64 | stdin.on("readable", function () { 65 | let chunk; 66 | 67 | while ((chunk = stdin.read())) { 68 | if (!(chunk instanceof Buffer)) throw new Error("Did not receive buffer"); 69 | ret.push(chunk); 70 | len += chunk.length; 71 | } 72 | }); 73 | 74 | stdin.on("end", function () { 75 | callback(Buffer.concat(ret, len)); 76 | }); 77 | } 78 | 79 | // normaliseFieldObjectName modifies the field name that appears in the `asObject` representation 80 | // to match the logic found in `protobuf/compiler/js/js_generator.cc`. See: https://goo.gl/tX1dPQ 81 | export function normaliseFieldObjectName(name: string): string { 82 | switch (name) { 83 | case "abstract": 84 | case "boolean": 85 | case "break": 86 | case "byte": 87 | case "case": 88 | case "catch": 89 | case "char": 90 | case "class": 91 | case "const": 92 | case "continue": 93 | case "debugger": 94 | case "default": 95 | case "delete": 96 | case "do": 97 | case "double": 98 | case "else": 99 | case "enum": 100 | case "export": 101 | case "extends": 102 | case "false": 103 | case "final": 104 | case "finally": 105 | case "float": 106 | case "for": 107 | case "function": 108 | case "goto": 109 | case "if": 110 | case "implements": 111 | case "import": 112 | case "in": 113 | case "instanceof": 114 | case "int": 115 | case "interface": 116 | case "long": 117 | case "native": 118 | case "new": 119 | case "null": 120 | case "package": 121 | case "private": 122 | case "protected": 123 | case "public": 124 | case "return": 125 | case "short": 126 | case "static": 127 | case "super": 128 | case "switch": 129 | case "synchronized": 130 | case "this": 131 | case "throw": 132 | case "throws": 133 | case "transient": 134 | case "try": 135 | case "typeof": 136 | case "var": 137 | case "void": 138 | case "volatile": 139 | case "while": 140 | case "with": 141 | return `pb_${name}`; 142 | } 143 | return name; 144 | } 145 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/parent_message_v2_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v2.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | 7 | export class ParentMessageV2 extends jspb.Message { 8 | hasInternalChildMessage(): boolean; 9 | clearInternalChildMessage(): void; 10 | getInternalChildMessage(): ParentMessageV2.InternalChildMessage; 11 | setInternalChildMessage(value?: ParentMessageV2.InternalChildMessage): void; 12 | 13 | hasOptInternalChildMessage(): boolean; 14 | clearOptInternalChildMessage(): void; 15 | getOptInternalChildMessage(): ParentMessageV2.InternalChildMessage | undefined; 16 | setOptInternalChildMessage(value?: ParentMessageV2.InternalChildMessage): void; 17 | 18 | clearInternalChildrenList(): void; 19 | getInternalChildrenList(): Array; 20 | setInternalChildrenList(value: Array): void; 21 | addInternalChildren(value?: ParentMessageV2.InternalChildMessage, index?: number): ParentMessageV2.InternalChildMessage; 22 | 23 | hasExternalChildMessage(): boolean; 24 | clearExternalChildMessage(): void; 25 | getExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage; 26 | setExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 27 | 28 | hasOptExternalChildMessage(): boolean; 29 | clearOptExternalChildMessage(): void; 30 | getOptExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage | undefined; 31 | setOptExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 32 | 33 | clearExternalChildrenList(): void; 34 | getExternalChildrenList(): Array; 35 | setExternalChildrenList(value: Array): void; 36 | addExternalChildren(value?: proto_othercom_external_child_message_pb.ExternalChildMessage, index?: number): proto_othercom_external_child_message_pb.ExternalChildMessage; 37 | 38 | serializeBinary(): Uint8Array; 39 | toObject(includeInstance?: boolean): ParentMessageV2.AsObject; 40 | static toObject(includeInstance: boolean, msg: ParentMessageV2): ParentMessageV2.AsObject; 41 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 42 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 43 | static serializeBinaryToWriter(message: ParentMessageV2, writer: jspb.BinaryWriter): void; 44 | static deserializeBinary(bytes: Uint8Array): ParentMessageV2; 45 | static deserializeBinaryFromReader(message: ParentMessageV2, reader: jspb.BinaryReader): ParentMessageV2; 46 | } 47 | 48 | export namespace ParentMessageV2 { 49 | export type AsObject = { 50 | internalChildMessage: ParentMessageV2.InternalChildMessage.AsObject, 51 | optInternalChildMessage?: ParentMessageV2.InternalChildMessage.AsObject, 52 | internalChildrenList: Array, 53 | externalChildMessage: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 54 | optExternalChildMessage?: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 55 | externalChildrenList: Array, 56 | } 57 | 58 | export class InternalChildMessage extends jspb.Message { 59 | hasMyString(): boolean; 60 | clearMyString(): void; 61 | getMyString(): string | undefined; 62 | setMyString(value: string): void; 63 | 64 | serializeBinary(): Uint8Array; 65 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 66 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 67 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 68 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 69 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 70 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 71 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 72 | } 73 | 74 | export namespace InternalChildMessage { 75 | export type AsObject = { 76 | myString?: string, 77 | } 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/parent_message_v2_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v2.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | 7 | export class ParentMessageV2 extends jspb.Message { 8 | hasInternalChildMessage(): boolean; 9 | clearInternalChildMessage(): void; 10 | getInternalChildMessage(): ParentMessageV2.InternalChildMessage; 11 | setInternalChildMessage(value?: ParentMessageV2.InternalChildMessage): void; 12 | 13 | hasOptInternalChildMessage(): boolean; 14 | clearOptInternalChildMessage(): void; 15 | getOptInternalChildMessage(): ParentMessageV2.InternalChildMessage | undefined; 16 | setOptInternalChildMessage(value?: ParentMessageV2.InternalChildMessage): void; 17 | 18 | clearInternalChildrenList(): void; 19 | getInternalChildrenList(): Array; 20 | setInternalChildrenList(value: Array): void; 21 | addInternalChildren(value?: ParentMessageV2.InternalChildMessage, index?: number): ParentMessageV2.InternalChildMessage; 22 | 23 | hasExternalChildMessage(): boolean; 24 | clearExternalChildMessage(): void; 25 | getExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage; 26 | setExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 27 | 28 | hasOptExternalChildMessage(): boolean; 29 | clearOptExternalChildMessage(): void; 30 | getOptExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage | undefined; 31 | setOptExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 32 | 33 | clearExternalChildrenList(): void; 34 | getExternalChildrenList(): Array; 35 | setExternalChildrenList(value: Array): void; 36 | addExternalChildren(value?: proto_othercom_external_child_message_pb.ExternalChildMessage, index?: number): proto_othercom_external_child_message_pb.ExternalChildMessage; 37 | 38 | serializeBinary(): Uint8Array; 39 | toObject(includeInstance?: boolean): ParentMessageV2.AsObject; 40 | static toObject(includeInstance: boolean, msg: ParentMessageV2): ParentMessageV2.AsObject; 41 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 42 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 43 | static serializeBinaryToWriter(message: ParentMessageV2, writer: jspb.BinaryWriter): void; 44 | static deserializeBinary(bytes: Uint8Array): ParentMessageV2; 45 | static deserializeBinaryFromReader(message: ParentMessageV2, reader: jspb.BinaryReader): ParentMessageV2; 46 | } 47 | 48 | export namespace ParentMessageV2 { 49 | export type AsObject = { 50 | internalChildMessage: ParentMessageV2.InternalChildMessage.AsObject, 51 | optInternalChildMessage?: ParentMessageV2.InternalChildMessage.AsObject, 52 | internalChildrenList: Array, 53 | externalChildMessage: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 54 | optExternalChildMessage?: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 55 | externalChildrenList: Array, 56 | } 57 | 58 | export class InternalChildMessage extends jspb.Message { 59 | hasMyString(): boolean; 60 | clearMyString(): void; 61 | getMyString(): string | undefined; 62 | setMyString(value: string): void; 63 | 64 | serializeBinary(): Uint8Array; 65 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 66 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 67 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 68 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 69 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 70 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 71 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 72 | } 73 | 74 | export namespace InternalChildMessage { 75 | export type AsObject = { 76 | myString?: string, 77 | } 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /examples/generated-grpc-web/proto/examplecom/parent_message_v2_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/parent_message_v2.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as proto_othercom_external_child_message_pb from "../../proto/othercom/external_child_message_pb"; 6 | 7 | export class ParentMessageV2 extends jspb.Message { 8 | hasInternalChildMessage(): boolean; 9 | clearInternalChildMessage(): void; 10 | getInternalChildMessage(): ParentMessageV2.InternalChildMessage; 11 | setInternalChildMessage(value?: ParentMessageV2.InternalChildMessage): void; 12 | 13 | hasOptInternalChildMessage(): boolean; 14 | clearOptInternalChildMessage(): void; 15 | getOptInternalChildMessage(): ParentMessageV2.InternalChildMessage | undefined; 16 | setOptInternalChildMessage(value?: ParentMessageV2.InternalChildMessage): void; 17 | 18 | clearInternalChildrenList(): void; 19 | getInternalChildrenList(): Array; 20 | setInternalChildrenList(value: Array): void; 21 | addInternalChildren(value?: ParentMessageV2.InternalChildMessage, index?: number): ParentMessageV2.InternalChildMessage; 22 | 23 | hasExternalChildMessage(): boolean; 24 | clearExternalChildMessage(): void; 25 | getExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage; 26 | setExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 27 | 28 | hasOptExternalChildMessage(): boolean; 29 | clearOptExternalChildMessage(): void; 30 | getOptExternalChildMessage(): proto_othercom_external_child_message_pb.ExternalChildMessage | undefined; 31 | setOptExternalChildMessage(value?: proto_othercom_external_child_message_pb.ExternalChildMessage): void; 32 | 33 | clearExternalChildrenList(): void; 34 | getExternalChildrenList(): Array; 35 | setExternalChildrenList(value: Array): void; 36 | addExternalChildren(value?: proto_othercom_external_child_message_pb.ExternalChildMessage, index?: number): proto_othercom_external_child_message_pb.ExternalChildMessage; 37 | 38 | serializeBinary(): Uint8Array; 39 | toObject(includeInstance?: boolean): ParentMessageV2.AsObject; 40 | static toObject(includeInstance: boolean, msg: ParentMessageV2): ParentMessageV2.AsObject; 41 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 42 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 43 | static serializeBinaryToWriter(message: ParentMessageV2, writer: jspb.BinaryWriter): void; 44 | static deserializeBinary(bytes: Uint8Array): ParentMessageV2; 45 | static deserializeBinaryFromReader(message: ParentMessageV2, reader: jspb.BinaryReader): ParentMessageV2; 46 | } 47 | 48 | export namespace ParentMessageV2 { 49 | export type AsObject = { 50 | internalChildMessage: ParentMessageV2.InternalChildMessage.AsObject, 51 | optInternalChildMessage?: ParentMessageV2.InternalChildMessage.AsObject, 52 | internalChildrenList: Array, 53 | externalChildMessage: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 54 | optExternalChildMessage?: proto_othercom_external_child_message_pb.ExternalChildMessage.AsObject, 55 | externalChildrenList: Array, 56 | } 57 | 58 | export class InternalChildMessage extends jspb.Message { 59 | hasMyString(): boolean; 60 | clearMyString(): void; 61 | getMyString(): string | undefined; 62 | setMyString(value: string): void; 63 | 64 | serializeBinary(): Uint8Array; 65 | toObject(includeInstance?: boolean): InternalChildMessage.AsObject; 66 | static toObject(includeInstance: boolean, msg: InternalChildMessage): InternalChildMessage.AsObject; 67 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 68 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 69 | static serializeBinaryToWriter(message: InternalChildMessage, writer: jspb.BinaryWriter): void; 70 | static deserializeBinary(bytes: Uint8Array): InternalChildMessage; 71 | static deserializeBinaryFromReader(message: InternalChildMessage, reader: jspb.BinaryReader): InternalChildMessage; 72 | } 73 | 74 | export namespace InternalChildMessage { 75 | export type AsObject = { 76 | myString?: string, 77 | } 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /test/integration/repeatedPrimitives.ts: -------------------------------------------------------------------------------- 1 | import {assert} from "chai"; 2 | import {RepeatedPrimitiveMessage} from "../../examples/generated/proto/examplecom/repeated_primitive_message_pb"; 3 | 4 | describe("repeated primitives", () => { 5 | it("should allow getting repeated primitive fields", () => { 6 | const msg = new RepeatedPrimitiveMessage(); 7 | assert.deepEqual(msg.getMyDoubleList() as Array, []); 8 | assert.deepEqual(msg.getMyFloatList() as Array, []); 9 | assert.deepEqual(msg.getMyInt32List() as Array, []); 10 | assert.deepEqual(msg.getMyInt64List() as Array, []); 11 | assert.deepEqual(msg.getMyUint32List() as Array, []); 12 | assert.deepEqual(msg.getMyUint64List() as Array, []); 13 | assert.deepEqual(msg.getMySint32List() as Array, []); 14 | assert.deepEqual(msg.getMySint64List() as Array, []); 15 | assert.deepEqual(msg.getMyFixed32List() as Array, []); 16 | assert.deepEqual(msg.getMyFixed64List() as Array, []); 17 | assert.deepEqual(msg.getMySfixed32List() as Array, []); 18 | assert.deepEqual(msg.getMySfixed64List() as Array, []); 19 | assert.deepEqual(msg.getMyBoolList() as Array, []); 20 | assert.deepEqual(msg.getMyStringList() as Array, []); 21 | assert.deepEqual(msg.getMyBytesList() as Array, []); 22 | }); 23 | 24 | it("should allow setting and getting repeated primitive fields", () => { 25 | const msg = new RepeatedPrimitiveMessage(); 26 | msg.setMyDoubleList([123, 456]); 27 | assert.deepEqual(msg.getMyDoubleList() as Array, [123, 456]); 28 | msg.setMyFloatList([123, 456]); 29 | assert.deepEqual(msg.getMyFloatList() as Array, [123, 456]); 30 | msg.setMyInt32List([123, 456]); 31 | assert.deepEqual(msg.getMyInt32List() as Array, [123, 456]); 32 | msg.setMyInt64List([123, 456]); 33 | assert.deepEqual(msg.getMyInt64List() as Array, [123, 456]); 34 | msg.setMyUint32List([123, 456]); 35 | assert.deepEqual(msg.getMyUint32List() as Array, [123, 456]); 36 | msg.setMyUint64List([123, 456]); 37 | assert.deepEqual(msg.getMyUint64List() as Array, [123, 456]); 38 | msg.setMySint32List([123, 456]); 39 | assert.deepEqual(msg.getMySint32List() as Array, [123, 456]); 40 | msg.setMySint64List([123, 456]); 41 | assert.deepEqual(msg.getMySint64List() as Array, [123, 456]); 42 | msg.setMyFixed32List([123, 456]); 43 | assert.deepEqual(msg.getMyFixed32List() as Array, [123, 456]); 44 | msg.setMyFixed64List([123, 456]); 45 | assert.deepEqual(msg.getMyFixed64List() as Array, [123, 456]); 46 | msg.setMySfixed32List([123, 456]); 47 | assert.deepEqual(msg.getMySfixed32List() as Array, [123, 456]); 48 | msg.setMySfixed64List([123, 456]); 49 | assert.deepEqual(msg.getMySfixed64List() as Array, [123, 456]); 50 | msg.setMyBoolList([true, false]); 51 | assert.deepEqual(msg.getMyBoolList() as Array, [true, false]); 52 | msg.setMyStringList(["one", "two"]); 53 | assert.deepEqual(msg.getMyStringList() as Array, ["one", "two"]); 54 | msg.setMyBytesList(["AAECAwQFBgcICQ=="]); 55 | assert.deepEqual(msg.getMyBytesList() as Array, ["AAECAwQFBgcICQ=="]); 56 | }); 57 | 58 | it("should allow setting and getting byte values", () => { 59 | const asUint8ArrayOne = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); 60 | const asUint8ArrayTwo = new Uint8Array([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]); 61 | const asStringOne = "AAECAwQFBgcICQ=="; 62 | const asStringTwo = "CQgHBgUEAwIBAA=="; 63 | 64 | const msg = new RepeatedPrimitiveMessage(); 65 | 66 | msg.setMyBytesList([asUint8ArrayOne, asUint8ArrayTwo]); 67 | assert.deepEqual(msg.getMyBytesList_asU8() as Array, [asUint8ArrayOne, asUint8ArrayTwo]); 68 | assert.deepEqual(msg.getMyBytesList_asB64() as Array, [asStringOne, asStringTwo]); 69 | const myBytesListA: Array = msg.getMyBytesList(); 70 | assert.deepEqual(myBytesListA, [asUint8ArrayOne, asUint8ArrayTwo]); 71 | 72 | msg.setMyBytesList([asStringOne, asStringTwo]); 73 | assert.deepEqual(msg.getMyBytesList_asB64() as Array, [asStringOne, asStringTwo]); 74 | assert.deepEqual(msg.getMyBytesList_asU8() as Array, [asUint8ArrayOne, asUint8ArrayTwo]); 75 | const myBytesListB: Array = msg.getMyBytesList(); 76 | assert.deepEqual(myBytesListB, [asStringOne, asStringTwo]); 77 | }); 78 | }); 79 | -------------------------------------------------------------------------------- /examples/generated/proto/examplecom/repeated_primitive_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/repeated_primitive_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class RepeatedPrimitiveMessage extends jspb.Message { 7 | clearMyDoubleList(): void; 8 | getMyDoubleList(): Array; 9 | setMyDoubleList(value: Array): void; 10 | addMyDouble(value: number, index?: number): number; 11 | 12 | clearMyFloatList(): void; 13 | getMyFloatList(): Array; 14 | setMyFloatList(value: Array): void; 15 | addMyFloat(value: number, index?: number): number; 16 | 17 | clearMyInt32List(): void; 18 | getMyInt32List(): Array; 19 | setMyInt32List(value: Array): void; 20 | addMyInt32(value: number, index?: number): number; 21 | 22 | clearMyInt64List(): void; 23 | getMyInt64List(): Array; 24 | setMyInt64List(value: Array): void; 25 | addMyInt64(value: number, index?: number): number; 26 | 27 | clearMyUint32List(): void; 28 | getMyUint32List(): Array; 29 | setMyUint32List(value: Array): void; 30 | addMyUint32(value: number, index?: number): number; 31 | 32 | clearMyUint64List(): void; 33 | getMyUint64List(): Array; 34 | setMyUint64List(value: Array): void; 35 | addMyUint64(value: number, index?: number): number; 36 | 37 | clearMySint32List(): void; 38 | getMySint32List(): Array; 39 | setMySint32List(value: Array): void; 40 | addMySint32(value: number, index?: number): number; 41 | 42 | clearMySint64List(): void; 43 | getMySint64List(): Array; 44 | setMySint64List(value: Array): void; 45 | addMySint64(value: number, index?: number): number; 46 | 47 | clearMyFixed32List(): void; 48 | getMyFixed32List(): Array; 49 | setMyFixed32List(value: Array): void; 50 | addMyFixed32(value: number, index?: number): number; 51 | 52 | clearMyFixed64List(): void; 53 | getMyFixed64List(): Array; 54 | setMyFixed64List(value: Array): void; 55 | addMyFixed64(value: number, index?: number): number; 56 | 57 | clearMySfixed32List(): void; 58 | getMySfixed32List(): Array; 59 | setMySfixed32List(value: Array): void; 60 | addMySfixed32(value: number, index?: number): number; 61 | 62 | clearMySfixed64List(): void; 63 | getMySfixed64List(): Array; 64 | setMySfixed64List(value: Array): void; 65 | addMySfixed64(value: number, index?: number): number; 66 | 67 | clearMyBoolList(): void; 68 | getMyBoolList(): Array; 69 | setMyBoolList(value: Array): void; 70 | addMyBool(value: boolean, index?: number): boolean; 71 | 72 | clearMyStringList(): void; 73 | getMyStringList(): Array; 74 | setMyStringList(value: Array): void; 75 | addMyString(value: string, index?: number): string; 76 | 77 | clearMyBytesList(): void; 78 | getMyBytesList(): Array; 79 | getMyBytesList_asU8(): Array; 80 | getMyBytesList_asB64(): Array; 81 | setMyBytesList(value: Array): void; 82 | addMyBytes(value: Uint8Array | string, index?: number): Uint8Array | string; 83 | 84 | serializeBinary(): Uint8Array; 85 | toObject(includeInstance?: boolean): RepeatedPrimitiveMessage.AsObject; 86 | static toObject(includeInstance: boolean, msg: RepeatedPrimitiveMessage): RepeatedPrimitiveMessage.AsObject; 87 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 88 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 89 | static serializeBinaryToWriter(message: RepeatedPrimitiveMessage, writer: jspb.BinaryWriter): void; 90 | static deserializeBinary(bytes: Uint8Array): RepeatedPrimitiveMessage; 91 | static deserializeBinaryFromReader(message: RepeatedPrimitiveMessage, reader: jspb.BinaryReader): RepeatedPrimitiveMessage; 92 | } 93 | 94 | export namespace RepeatedPrimitiveMessage { 95 | export type AsObject = { 96 | myDoubleList: Array, 97 | myFloatList: Array, 98 | myInt32List: Array, 99 | myInt64List: Array, 100 | myUint32List: Array, 101 | myUint64List: Array, 102 | mySint32List: Array, 103 | mySint64List: Array, 104 | myFixed32List: Array, 105 | myFixed64List: Array, 106 | mySfixed32List: Array, 107 | mySfixed64List: Array, 108 | myBoolList: Array, 109 | myStringList: Array, 110 | myBytesList: Array, 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /examples/generated-grpc-node/proto/examplecom/repeated_primitive_message_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: examplecom 2 | // file: proto/examplecom/repeated_primitive_message.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class RepeatedPrimitiveMessage extends jspb.Message { 7 | clearMyDoubleList(): void; 8 | getMyDoubleList(): Array; 9 | setMyDoubleList(value: Array): void; 10 | addMyDouble(value: number, index?: number): number; 11 | 12 | clearMyFloatList(): void; 13 | getMyFloatList(): Array; 14 | setMyFloatList(value: Array): void; 15 | addMyFloat(value: number, index?: number): number; 16 | 17 | clearMyInt32List(): void; 18 | getMyInt32List(): Array; 19 | setMyInt32List(value: Array): void; 20 | addMyInt32(value: number, index?: number): number; 21 | 22 | clearMyInt64List(): void; 23 | getMyInt64List(): Array; 24 | setMyInt64List(value: Array): void; 25 | addMyInt64(value: number, index?: number): number; 26 | 27 | clearMyUint32List(): void; 28 | getMyUint32List(): Array; 29 | setMyUint32List(value: Array): void; 30 | addMyUint32(value: number, index?: number): number; 31 | 32 | clearMyUint64List(): void; 33 | getMyUint64List(): Array; 34 | setMyUint64List(value: Array): void; 35 | addMyUint64(value: number, index?: number): number; 36 | 37 | clearMySint32List(): void; 38 | getMySint32List(): Array; 39 | setMySint32List(value: Array): void; 40 | addMySint32(value: number, index?: number): number; 41 | 42 | clearMySint64List(): void; 43 | getMySint64List(): Array; 44 | setMySint64List(value: Array): void; 45 | addMySint64(value: number, index?: number): number; 46 | 47 | clearMyFixed32List(): void; 48 | getMyFixed32List(): Array; 49 | setMyFixed32List(value: Array): void; 50 | addMyFixed32(value: number, index?: number): number; 51 | 52 | clearMyFixed64List(): void; 53 | getMyFixed64List(): Array; 54 | setMyFixed64List(value: Array): void; 55 | addMyFixed64(value: number, index?: number): number; 56 | 57 | clearMySfixed32List(): void; 58 | getMySfixed32List(): Array; 59 | setMySfixed32List(value: Array): void; 60 | addMySfixed32(value: number, index?: number): number; 61 | 62 | clearMySfixed64List(): void; 63 | getMySfixed64List(): Array; 64 | setMySfixed64List(value: Array): void; 65 | addMySfixed64(value: number, index?: number): number; 66 | 67 | clearMyBoolList(): void; 68 | getMyBoolList(): Array; 69 | setMyBoolList(value: Array): void; 70 | addMyBool(value: boolean, index?: number): boolean; 71 | 72 | clearMyStringList(): void; 73 | getMyStringList(): Array; 74 | setMyStringList(value: Array): void; 75 | addMyString(value: string, index?: number): string; 76 | 77 | clearMyBytesList(): void; 78 | getMyBytesList(): Array; 79 | getMyBytesList_asU8(): Array; 80 | getMyBytesList_asB64(): Array; 81 | setMyBytesList(value: Array): void; 82 | addMyBytes(value: Uint8Array | string, index?: number): Uint8Array | string; 83 | 84 | serializeBinary(): Uint8Array; 85 | toObject(includeInstance?: boolean): RepeatedPrimitiveMessage.AsObject; 86 | static toObject(includeInstance: boolean, msg: RepeatedPrimitiveMessage): RepeatedPrimitiveMessage.AsObject; 87 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 88 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 89 | static serializeBinaryToWriter(message: RepeatedPrimitiveMessage, writer: jspb.BinaryWriter): void; 90 | static deserializeBinary(bytes: Uint8Array): RepeatedPrimitiveMessage; 91 | static deserializeBinaryFromReader(message: RepeatedPrimitiveMessage, reader: jspb.BinaryReader): RepeatedPrimitiveMessage; 92 | } 93 | 94 | export namespace RepeatedPrimitiveMessage { 95 | export type AsObject = { 96 | myDoubleList: Array, 97 | myFloatList: Array, 98 | myInt32List: Array, 99 | myInt64List: Array, 100 | myUint32List: Array, 101 | myUint64List: Array, 102 | mySint32List: Array, 103 | mySint64List: Array, 104 | myFixed32List: Array, 105 | myFixed64List: Array, 106 | mySfixed32List: Array, 107 | mySfixed64List: Array, 108 | myBoolList: Array, 109 | myStringList: Array, 110 | myBytesList: Array, 111 | } 112 | } 113 | 114 | --------------------------------------------------------------------------------