This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #193 PiperOrigin-RevId: 195706451
- Loading branch information
Showing
18 changed files
with
874 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
load("@build_bazel_rules_typescript//:defs.bzl", | ||
"ts_library", | ||
"ts_proto_library", | ||
"ts_web_test", | ||
"ts_devserver", | ||
) | ||
|
||
proto_library( | ||
name = "tire_proto", | ||
srcs = ["tire.proto"], | ||
) | ||
|
||
proto_library( | ||
name = "car_proto", | ||
srcs = ["car.proto"], | ||
deps = [":tire_proto"], | ||
) | ||
|
||
ts_proto_library( | ||
# The result will be "car.d.ts" named after this target. | ||
# We could use the output_name attribute if we want the output named | ||
# differently than the target. | ||
name = "car", | ||
deps = [":car_proto"], | ||
) | ||
|
||
ts_library( | ||
name = "test_lib", | ||
testonly = True, | ||
srcs = ["car.spec.ts"], | ||
deps = [":car"], | ||
) | ||
|
||
ts_web_test( | ||
name = "test", | ||
deps = ["test_lib"], | ||
bootstrap = ["@build_bazel_rules_typescript//:protobufjs_bootstrap_scripts"], | ||
) | ||
|
||
ts_library( | ||
name = "app", | ||
srcs = ["app.ts"], | ||
deps = [":car"], | ||
) | ||
|
||
ts_devserver( | ||
name = "devserver", | ||
deps = [":app"], | ||
entry_module = "build_bazel_rules_typescript/examples/protocol_buffers/app", | ||
bootstrap = ["@build_bazel_rules_typescript//:protobufjs_bootstrap_scripts"], | ||
) | ||
|
||
# Test for production mode | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle") | ||
|
||
rollup_bundle( | ||
name = "bundle", | ||
deps = [":app"], | ||
entry_point = "examples/protocol_buffers/app", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Car} from './car'; | ||
|
||
const serverResponse = `{"make": "Porsche"}`; | ||
const car = Car.create(JSON.parse(serverResponse)); | ||
const el: HTMLDivElement = document.createElement('div'); | ||
el.innerText = `Car from server: ${car.make}`; | ||
document.body.appendChild(el); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
syntax = "proto3"; | ||
|
||
import "examples/protocol_buffers/tire.proto"; | ||
|
||
message Car { | ||
string make = 1; | ||
string model = 2; | ||
int32 year = 3; | ||
Tire front_tires = 4; | ||
Tire rear_tires = 5; | ||
int64 mileage = 6; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Car} from './car'; | ||
import Long = require('long'); | ||
|
||
describe('protocol buffers', () => { | ||
|
||
it('allows creation of an object described by proto', () => { | ||
const pontiac = Car.create({ | ||
make: "pontiac", | ||
frontTires: { | ||
width: 225, | ||
aspectRatio: 65, | ||
construction: 'R', | ||
diameter: 17, | ||
}, | ||
}); | ||
expect(pontiac.make).toEqual('pontiac'); | ||
if (!pontiac.frontTires) { | ||
fail('Should have frontTires set'); | ||
} else { | ||
expect(pontiac.frontTires.width).toEqual(225); | ||
} | ||
}); | ||
|
||
// Asserts that longs are handled correctly. | ||
// This value comes from https://github.com/dcodeIO/long.js#background | ||
it('handles long values correctly', () => { | ||
const pontiac = Car.create({ | ||
make: "pontiac", | ||
// Long.MAX_VALUE | ||
mileage: new Long(0xFFFFFFFF, 0x7FFFFFFF), | ||
}); | ||
const object = Car.toObject(pontiac, {longs: String}); | ||
expect(object["mileage"]).toEqual("9223372036854775807"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
|
||
message Tire { | ||
string type = 1; | ||
int32 width = 2; | ||
int32 aspect_ratio = 3; | ||
string construction = 4; | ||
int32 diameter = 5; | ||
int32 load_index = 6; | ||
string speed_rating = 7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"lib": ["es2015.promise", "dom", "es5"] | ||
"lib": ["es2015.promise", "dom", "es5"], | ||
// Include the output directory in rootDirs so that generated .d.ts files | ||
// can be used for type-checking in the editor, for example the car.proto | ||
// produces a car.d.ts. | ||
"rootDirs": [".", "../bazel-bin/examples"] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package(default_visibility=["//visibility:public"]) | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") | ||
|
||
exports_files([ | ||
"node_modules/protobufjs/dist/minimal/protobuf.min.js", | ||
# Exported to be consumed for generating skydoc. | ||
"ts_proto_library.bzl", | ||
]) | ||
|
||
nodejs_binary( | ||
name = "pbjs", | ||
node_modules = "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules", | ||
entry_point = "protobufjs/bin/pbjs", | ||
) | ||
nodejs_binary( | ||
name = "pbts", | ||
node_modules = "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules", | ||
entry_point = "protobufjs/bin/pbts", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "protobufjs", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"chalk": "^1.1.3", | ||
"escodegen": "^1.9.0", | ||
"espree": "^3.5.3", | ||
"estraverse": "^4.2.0", | ||
"glob": "^7.1.2", | ||
"jsdoc": "^3.5.5", | ||
"minimist": "^1.2.0", | ||
"protobufjs": "Use HEAD to pick up fix for https://github.com/dcodeIO/protobuf.js/pull/1018", | ||
"protobufjs": "github:dcodeIO/protobuf.js#65d113b0079fa2570837f3cf95268ce24714a248", | ||
"semver": "^5.5.0", | ||
"tmp": "0.0.33", | ||
"uglify-js": "^2.8.29" | ||
} | ||
} |
Oops, something went wrong.