-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deps): update dependency gts to v1 (#21)
* chore(deps): update dependency gts to v1 * gts fix
- Loading branch information
1 parent
06576ee
commit 3715ec4
Showing
13 changed files
with
439 additions
and
262 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
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,41 +1,55 @@ | ||
import * as plugin from '../../../pbjs-genfiles/plugin'; | ||
|
||
import {Naming} from './naming'; | ||
import {Proto} from './proto'; | ||
import { Naming } from './naming'; | ||
import { Proto } from './proto'; | ||
|
||
export type ProtosMap = { | ||
[filename: string]: Proto | ||
}; | ||
export interface ProtosMap { | ||
[filename: string]: Proto; | ||
} | ||
|
||
export class API { | ||
naming: Naming; | ||
protos: ProtosMap; | ||
// TODO: subpackages | ||
|
||
constructor( | ||
fileDescriptors: plugin.google.protobuf.IFileDescriptorProto[], | ||
packageName: string) { | ||
this.naming = new Naming(fileDescriptors.filter( | ||
fd => fd.package && fd.package.startsWith(packageName))); | ||
this.protos = fileDescriptors.filter(fd => fd.name).reduce((map, fd) => { | ||
map[fd.name!] = new Proto(fd, packageName); | ||
return map; | ||
}, {} as ProtosMap); | ||
fileDescriptors: plugin.google.protobuf.IFileDescriptorProto[], | ||
packageName: string | ||
) { | ||
this.naming = new Naming( | ||
fileDescriptors.filter( | ||
fd => fd.package && fd.package.startsWith(packageName) | ||
) | ||
); | ||
this.protos = fileDescriptors | ||
.filter(fd => fd.name) | ||
.reduce( | ||
(map, fd) => { | ||
map[fd.name!] = new Proto(fd, packageName); | ||
return map; | ||
}, | ||
{} as ProtosMap | ||
); | ||
} | ||
|
||
get services() { | ||
return Object.keys(this.protos) | ||
.map(filename => this.protos[filename]) | ||
.filter(proto => proto.fileToGenerate) | ||
.reduce((retval, proto) => { | ||
.map(filename => this.protos[filename]) | ||
.filter(proto => proto.fileToGenerate) | ||
.reduce( | ||
(retval, proto) => { | ||
retval.push( | ||
...Object.keys(proto.services).map(name => proto.services[name])); | ||
...Object.keys(proto.services).map(name => proto.services[name]) | ||
); | ||
return retval; | ||
}, [] as plugin.google.protobuf.IServiceDescriptorProto[]); | ||
}, | ||
[] as plugin.google.protobuf.IServiceDescriptorProto[] | ||
); | ||
} | ||
|
||
get filesToGenerate() { | ||
return Object.keys(this.protos) | ||
.filter(proto => this.protos[proto].fileToGenerate); | ||
return Object.keys(this.protos).filter( | ||
proto => this.protos[proto].fileToGenerate | ||
); | ||
} | ||
} |
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
Oops, something went wrong.