Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass proto root and proto file to grpc.load #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,56 @@ yarn-error.log*
# System Files
.DS_Store
Thumbs.db

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/
cmake-build-release/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"main": "js/index",
"typings": "js/index",
"name": "rxjs-grpc",
"version": "0.1.7",
"name": "@lexset/rxjs-grpc",
"version": "0.1.89",
"description": "Typesafe gRPC with RxJS in TypeScript",
"license": "MIT",
"keywords": [],
Expand All @@ -27,29 +27,29 @@
"setupTestFrameworkScriptFile": "./setup-jest"
},
"dependencies": {
"bluebird": "^3.4.7",
"grpc": "^1.1.2",
"jscodeshift": "^0.3.30",
"minimist": "^1.2.0",
"mz": "^2.6.0",
"protobufjs": "~6.6.5",
"tmp": "^0.0.31"
"bluebird": "3.4.7",
"grpc": "1.11.1",
"jscodeshift": "0.3.30",
"minimist": "1.2.0",
"mz": "2.6.0",
"protobufjs": "6.6.5",
"tmp": "0.0.31"
},
"devDependencies": {
"@types/bluebird": "^3.0.37",
"@types/glob": "^5.0.30",
"@types/jasmine": "^2.5.43",
"@types/minimist": "^1.2.0",
"@types/mz": "^0.0.30",
"@types/node": "^7.0.5",
"@types/tmp": "^0.0.32",
"glob": "^7.1.1",
"grpc": "^1.1.2",
"jasmine": "^2.5.3",
"jest": "^21.2.1",
"rxjs": "^5.2.0",
"tslint": "^4.5.1",
"typescript": "^2.2.1"
"@types/bluebird": "3.0.37",
"@types/glob": "5.0.30",
"@types/jasmine": "2.5.43",
"@types/minimist": "1.2.0",
"@types/mz": "0.0.30",
"@types/node": "7.0.5",
"@types/tmp": "0.0.32",
"glob": "7.1.1",
"grpc": "1.1.2",
"jasmine": "2.5.3",
"jest": "21.2.1",
"rxjs": "5.2.0",
"tslint": "4.5.1",
"typescript": "2.2.1"
},
"peerDependencies": {
"rxjs": "^5.2.0"
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface GenericServerBuilder<T> {
forceShutdown(): void;
}

export function serverBuilder<T>(protoPath: string, packageName: string): T & GenericServerBuilder<T> {
export function serverBuilder<T>(protoRoot: string, protoFile: string, packageName: string): T & GenericServerBuilder<T> {
const server = new grpc.Server();

const builder: DynamicMethods = <GenericServerBuilder<T>> {
Expand All @@ -23,7 +23,9 @@ export function serverBuilder<T>(protoPath: string, packageName: string): T & Ge
}
};

const pkg = lookupPackage(grpc.load(protoPath), packageName)
const pkg = lookupPackage(grpc.load({
root: protoRoot,
file: protoFile}), packageName);
for (const name of getServiceNames(pkg)) {
builder[`add${name}`] = function(rxImpl: DynamicMethods) {
server.addProtoService(pkg[name].service, createService(pkg[name], rxImpl));
Expand Down Expand Up @@ -70,7 +72,7 @@ function createStreamingMethod(rxImpl: DynamicMethods, name: string) {

export type ClientFactoryConstructor<T> = new(address: string, credentials?: any, options?: any) => T;

export function clientFactory<T>(protoPath: string, packageName: string) {
export function clientFactory<T>(protoRoot: string, protoFile: string, packageName: string) {
class Constructor {

readonly __args: any[];
Expand All @@ -85,7 +87,9 @@ export function clientFactory<T>(protoPath: string, packageName: string) {
}

const prototype: DynamicMethods = Constructor.prototype;
const pkg = lookupPackage(grpc.load(protoPath), packageName)
const pkg = lookupPackage(grpc.load({
root: protoRoot,
file: protoFile}), packageName);
for (const name of getServiceNames(pkg)) {
prototype[`get${name}`] = function(this: Constructor) {
return createServiceClient(pkg[name], this.__args);
Expand Down
8 changes: 7 additions & 1 deletion src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

declare module 'grpc' {

namespace grpc {
function load(protoPath: string): any;
function load(options: LoadOptions): any;

class Server {
addProtoService(service: any, impl: any): void;
Expand All @@ -17,6 +18,11 @@ declare module 'grpc' {
class ServerCredentials {
static createInsecure(): any;
}

interface LoadOptions {
root: string;
file: string;
}
}

export = grpc;
Expand Down