-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(labs): introduce a new ts_proto_library with grpc support
This version of ts_proto_library is generated using the more standard grpc/grpc-web package.
- Loading branch information
Showing
37 changed files
with
1,258 additions
and
73 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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import {Proto} from './car'; | ||
import {Car} from 'examples_protocol_buffers/car_pb'; | ||
|
||
const car = new Car(); | ||
car.setMake('Porsche'); | ||
|
||
const serverResponse = `{"make": "Porsche"}`; | ||
const car = Proto.Car.create(JSON.parse(serverResponse)); | ||
const el: HTMLDivElement = document.createElement('div'); | ||
el.innerText = `Car from server: ${car.make}`; | ||
el.innerText = `Car from server: ${car.getMake()}`; | ||
el.className = 'ts1'; | ||
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 |
---|---|---|
@@ -1,34 +1,18 @@ | ||
import {Proto} from './car'; | ||
import Long = require('long'); | ||
import {Car} from 'examples_protocol_buffers/car_pb'; | ||
import {Tire} from 'examples_protocol_buffers/tire_pb'; | ||
|
||
describe('protocol buffers', () => { | ||
it('allows creation of an object described by proto', () => { | ||
const pontiac = Proto.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); | ||
} | ||
}); | ||
const tires = new Tire(); | ||
tires.setAspectRatio(65); | ||
tires.setWidth(225); | ||
tires.setConstruction('R'); | ||
tires.setDiameter(17); | ||
|
||
const pontiac = new Car(); | ||
pontiac.setMake('pontiac'); | ||
pontiac.setFrontTires(tires) | ||
|
||
// Asserts that longs are handled correctly. | ||
// This value comes from https://github.com/dcodeIO/long.js#background | ||
it('handles long values correctly', () => { | ||
const pontiac = Proto.Car.create({ | ||
make: 'pontiac', | ||
// Long.MAX_VALUE | ||
mileage: new Long(0xFFFFFFFF, 0x7FFFFFFF), | ||
}); | ||
const object = Proto.Car.toObject(pontiac, {longs: String}); | ||
expect(object['mileage']).toEqual('9223372036854775807'); | ||
expect(pontiac.getMake()).toEqual('pontiac'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
const commonjs = require('rollup-plugin-commonjs'); | ||
const nodeRequire = require('rollup-plugin-node-resolve'); | ||
|
||
module.exports = { | ||
// indicate which modules should be treated as external | ||
external: [ | ||
'long', | ||
'protobufjs/minimal', | ||
plugins: [ | ||
nodeRequire(), | ||
commonjs(), | ||
], | ||
output: {globals: {long: 'Long', 'protobufjs/minimal': 'protobuf'}} | ||
}; | ||
}; |
Oops, something went wrong.