Merge pull request #22396 from DefinitelyTyped/not-needed-protobufjs

protobufjs: Provides its own types
This commit is contained in:
Paul van Brenk
2017-12-28 17:09:17 -08:00
committed by GitHub
5 changed files with 6 additions and 950 deletions

View File

@@ -780,6 +780,12 @@
"sourceRepoURL": "https://github.com/zeh/prando",
"asOfVersion": "1.0.0"
},
{
"libraryName": "ProtoBuf.js",
"typingsPackageName": "protobufjs",
"sourceRepoURL": "https://github.com/dcodeIO/ProtoBuf.js",
"asOfVersion": "6.0.0"
},
{
"libraryName": "Protractor",
"typingsPackageName": "protractor",

View File

@@ -1,426 +0,0 @@
// Type definitions for ProtoBuf.js 5.0.1
// Project: https://github.com/dcodeIO/ProtoBuf.js
// Definitions by: Panu Horsmalahti <https://github.com/panuhorsmalahti>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="bytebuffer" />
/// <reference types="node" />
declare namespace ProtoBuf {
// ==========
// protobufjs/src/ProtoBuf.js
var Builder: Builder;
var Long: LongStatic;
var DotProto: DotProto;
var Reflect: Reflect;
var Util: Util;
var convertFieldsToCamelCase: boolean;
// var Lang: Lang; TODO: implement interface Lang
export function loadJson(json: string, builder?: ProtoBuilder | string | {},
filename?: string | {}): ProtoBuilder;
export function loadJsonFile(filename: string | {},
callback?: (error: any, builder: ProtoBuilder) => void,
builder?: ProtoBuilder): ProtoBuilder;
export function loadProto(proto: string, builder?: ProtoBuilder | string | {},
filename?: string | {}): ProtoBuilder;
export function loadProtoFile(filePath: string | {},
callback?: (error: any, builder: ProtoBuilder) => void,
builder?: ProtoBuilder): ProtoBuilder;
export function newBuilder(options?: {[key: string]: any}): ProtoBuilder;
export interface LongStatic {
new(low?: number, high?: number, unsigned?:boolean): Long;
MAX_UNSIGNED_VALUE: Long;
MAX_VALUE: Long;
MIN_VALUE: Long;
NEG_ONE: Long;
ONE: Long;
UONE: Long;
UZERO: Long;
ZERO: Long;
fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long;
fromInt(value: number, unsigned?: boolean): Long;
fromNumber(value: number, unsigned?: boolean): Long;
fromString(str: string, unsigned?: boolean | number, radix?: number): Long;
fromValue(val: Long | number | string): Long;
isLong(obj: any): boolean;
}
// Based on https://github.com/dcodeIO/Long.js and https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/long/long.d.ts
export interface Long {
high: number;
low: number;
unsigned :boolean;
add(other: Long | number | string): Long;
and(other: Long | number | string): Long;
compare(other: Long | number | string): number;
div(divisor: Long | number | string): Long;
equals(other: Long | number | string): boolean;
getHighBits(): number;
getHighBitsUnsigned(): number;
getLowBits(): number;
getLowBitsUnsigned(): number;
getNumBitsAbs(): number;
greaterThan(other: Long | number | string): boolean;
greaterThanOrEqual(other: Long | number | string): boolean;
isEven(): boolean;
isNegative(): boolean;
isOdd(): boolean;
isPositive(): boolean;
isZero(): boolean;
lessThan(other: Long | number | string): boolean;
lessThanOrEqual(other: Long | number | string): boolean;
modulo(divisor: Long | number | string): Long;
multiply(multiplier: Long | number | string): Long;
negate(): Long;
not(): Long;
notEquals(other: Long | number | string): boolean;
or(other: Long | number | string): Long;
shiftLeft(numBits: number | Long): Long;
shiftRight(numBits: number | Long): Long;
shiftRightUnsigned(numBits: number | Long): Long;
subtract(other: Long | number | string): Long;
toInt(): number;
toNumber(): number;
toSigned(): Long;
toString(radix?: number): string;
toUnsigned(): Long;
xor(other: Long | number | string): Long;
}
// ==========
// protobufjs/src/ProtoBuf/Builder.js
export interface Builder {
new(options?: {[key: string]: any}): ProtoBuilder;
Message: Message;
Service: Service;
isValidMessage(def: {[key: string]: any}): boolean;
isValidMessageField(def: {[key: string]: any}): boolean;
isValidEnum(def: {[key: string]: any}): boolean;
isValidService(def: {[key: string]: any}): boolean;
isValidExtend(def: {[key: string]: any}): boolean;
}
/**
* TODO: Confirm that message needs no further implementation
*/
export interface Message {
new(values?: {[key: string]: any}, var_args?: string[]): Message;
$add(key: string, value: any, noAssert?: boolean): Message;
$get<T>(key: string): T;
$set(key: string | {[key: string]: any}, value?: any | boolean, noAssert?: boolean): void;
add(key: string, value: any, noAssert?: boolean): Message;
calculate(): number;
encode(buffer?: ByteBuffer | boolean, noVerify?: boolean): ByteBuffer;
encode64(): string;
encodeAB(): ArrayBuffer;
encodeNB(): Buffer;
encodeHex(): string;
encodeJSON(): string;
encodeDelimited(buffer?: ByteBuffer | boolean, noVerify?: boolean): ByteBuffer;
get<T>(key: string, noAssert?: boolean): T;
set(key: string | {[key: string]: any}, value?: any | boolean, noAssert?: boolean): void;
toArrayBuffer(): ArrayBuffer;
toBase64(): string;
toBuffer(): Buffer;
toHex(): string;
toRaw(binaryAsBase64?: boolean, longsAsStrings?: boolean): {[key: string]: any};
toString(): string;
[field: string]: any;
}
/**
* TODO: Implement service interface
*/
export interface Service {
new(rpcImpl?: Function): Service;
}
// ==========
// meta objects for constructing protobufs
export interface ProtoBuilder {
ns: ReflectNamespace;
ptr: ReflectNamespace;
resolved: boolean;
result: ProtoBuf;
files: string[];
importRoot: string;
options: {[key: string]: any};
syntax: string;
reset(): void;
define(pkg: string, options?: {[key: string]: any}): ProtoBuilder;
create(defs?: {[key: string]: any}[]): ProtoBuilder;
resolveAll(): void;
build(path?: string | [string]): MetaMessage<Message>;
build<T>(path?: string | [string]): MetaMessage<T>;
lookup(path?: string): ReflectT;
}
export interface ProtoBuf {
[package: string]: {[key: string]: MetaMessage<Message> | any};
}
export interface MetaMessage<T> {
new(values?: {[key: string]: any}, var_args?: string[]): T & Message;
decode(buffer: ArrayBuffer | ByteBuffer | Buffer | string, length?: number | string, enc?: string): T & Message;
decodeDelimited(buffer: ByteBuffer | ArrayBuffer | Buffer | string, enc?: string): T & Message;
decode64(str: string): T & Message;
decodeHex(str: string): T & Message;
decodeJSON(str: string): T & Message;
}
// ==========
// protobufjs/src/ProtoBuf/DotProto.js
export interface DotProto {
Parser: Parser;
Tokenizer: Tokenizer;
}
export interface Parser {
new(proto: string): Parser;
tn: Tokenizer;
parse(): MetaProto;
toString(): string;
}
export interface Tokenizer {
new(proto: string): Tokenizer;
source: string;
index: number;
line: number;
stack: string[];
readingString: boolean;
stringEndsWith: string;
next(): string;
peek(): string;
toString(): string;
}
// ==========
// proto meta information returned by the Parser
export interface MetaProto {
package: string;
messages: ProtoMessage[];
enums: ProtoEnum[];
imports: string[];
options: {[key: string]: any};
services: ProtoService[];
}
export interface ProtoEnum {
name: string;
values: ProtoEnumValue[];
options: {[key: string]: any};
}
export interface ProtoEnumValue {
name: string;
id: string;
}
export interface ProtoField {
rule: string;
options: {[key: string]: any};
type: string;
name: string;
id: number;
oneof?: string;
}
export interface ProtoMessage {
name: string;
isGroup?: boolean;
fields: ProtoField[];
enums: ProtoEnum[];
messages: ProtoMessage[];
options: {[key: string]: any};
oneofs: {[key: string]:number[]};
}
export interface ProtoRpcService {
request: string;
response: string;
options: {[key: string]: any};
}
export interface ProtoService {
name: string;
rpc: {[key: string]:ProtoRpcService};
options: {[key: string]: any};
}
// ==========
// protobufjs/src/ProtoBuf/Util.js
export interface Util {
IS_NODE: boolean
fetch(path: string, callback?: (data: string) => any): string;
toCamelCase(str: string): string;
XHR(): XMLHttpRequest;
}
// ==========
// protobufjs/src/ProtoBuf/Reflect.js
export interface Reflect {
T: ReflectT;
Namespace: ReflectNamespace;
Message: ReflectMessage;
Enum: ReflectEnum;
Extension: ReflectExtension;
Service: ReflectService;
}
export interface ReflectT {
new(builder?: ProtoBuilder, parent?: ReflectT, name?: string): ReflectT;
builder: ProtoBuilder;
parent: ReflectT;
name: string;
fqn(): string;
toString(includeClass?: boolean): string;
}
export interface ReflectNamespace extends ReflectT {
new(builder?: ProtoBuilder, parent?: ReflectNamespace, name?: string,
options?: {[key: string]: any}): ReflectNamespace;
className: string;
children: ReflectT[];
options: {[key: string]: any};
syntax: string;
getChildren(type?: ReflectT): ReflectT[];
addChild(child: ReflectT): void;
getChild(nameOrId?: string | number): ReflectT;
resolve(qn: string, excludeFields?: boolean): ReflectNamespace;
build(): ProtoBuf;
buildOpt(): {[key: string]: any};
getOption(name?: string): any;
}
export interface ReflectMessage extends ReflectNamespace {
new(builder?: ProtoBuilder, parent?: ReflectNamespace, name?: string,
options?: {[key: string]: any}, isGroup?: boolean): ReflectMessage;
Field: ReflectField; // NOTE: only for new ProtoBuf.Reflect.Message.Field();
ExtensionField: ReflectExtensionField; // NOTE: only for
// new ProtoBuf.Reflect.Message.ExtensionField();
OneOf: ReflectOneOf; // NOTE: only for new ProtoBuf.Reflect.Message.OneOf();
extensions: number[];
clazz(): MetaMessage<Message>;
isGroup: boolean;
build(rebuild?: boolean): MetaMessage<Message>|any;
build<T>(rebuild?: boolean): MetaMessage<T>|any;
encode(message: Message, buffer: Buffer, noVerify?: boolean): Buffer;
calculate(message: Message): number;
decode(buffer: Buffer, length?: number, expectedGroupEndId?: number): Message;
}
export interface ReflectEnum extends ReflectNamespace {
new(builder?: ProtoBuilder, parent?: ReflectT, name?: string,
options?: {[key: string]: any}): ReflectEnum;
Value: ReflectValue; // NOTE: only for new ProtoBuf.Reflect.Enum.Value();
object: {[key: string]:number};
build(): {[key: string]: any};
}
export interface ReflectExtension extends ReflectT {
new(builder?: ProtoBuilder, parent?: ReflectT, name?: string,
field?: ReflectField): ReflectExtension;
field: ReflectField;
}
export interface ReflectService extends ReflectNamespace {
new(): ReflectService;
Method: ReflectMethod; // NOTE: only for new ProtoBuf.Reflect.Service.Method();
RPCMethod: ReflectRPCMethod; // NOTE: only for new ProtoBuf.Reflect.Service.RPCMethod();
clazz(): Function;
build(rebuild?: boolean): Function|any;
}
// TODO: check that the runtime instance of this type reflects this definition
export interface ReflectField extends ReflectT {
new(builder: ProtoBuilder, message: ReflectMessage, rule: string, type: string,
name: string, id: number, options: {[key: string]: any}, oneof: ReflectOneOf): ReflectField;
className: string;
required: boolean;
repeated: boolean;
type: string | WireTuple;
resolvedType: ReflectT;
id: number;
options: {[key: string]: any};
defaultValue: any;
oneof: ReflectOneOf;
originalName: string;
build(): {[key: string]: any};
mkLong(value: any, unsigned?: boolean): number;
verifyValue(value: any, skipRepeated?: boolean): any;
encode(value: any, buffer: Buffer): Buffer;
encodeValue(value: any, buffer: Buffer): Buffer;
calculate(value: any): number;
calculateValue(value: any): number;
decode(wireType: number, buffer: Buffer, skipRepeated?: boolean): any;
}
export interface WireTuple {
name: string;
wireType: number;
}
// TODO: check that the runtime instance of this type reflects this definition
export interface ReflectExtensionField extends ReflectField {
new(builder: ProtoBuilder, message: ReflectMessage, rule: string, type: string,
name: string, id: number, options: {[key: string]: any}): ReflectExtensionField;
extension: ReflectExtension;
}
export interface ReflectOneOf extends ReflectT {
new(builder?: ProtoBuilder, message?: ReflectMessage, name?: string): ReflectOneOf;
fields: ReflectField[];
}
export interface ReflectValue extends ReflectT {
new(builder?: ProtoBuilder, enm?: ReflectEnum, name?: string, id?: number): ReflectValue;
className: string;
id: number;
}
export interface ReflectMethod extends ReflectT {
new(builder?: ProtoBuilder, svc?: ReflectService, name?: string,
options?: {[key: string]: any}): ReflectMethod;
className: string;
options: {[key: string]: any};
buildOpt(): {[key: string]: any};
}
export interface ReflectRPCMethod extends ReflectMethod {
new(builder?: ProtoBuilder, svc?: ReflectService, name?: string, request?: string,
response?: string, options?: {[key: string]: any}): ReflectRPCMethod;
requestName: string;
responseName: string;
resolvedRequestType: ReflectMessage;
resolvedResponseType: ReflectMessage;
}
}
declare module "protobufjs" {
export = ProtoBuf;
}
declare module "protobufjs/dist/protobuf-light" {
export = ProtoBuf;
}

View File

@@ -1,421 +0,0 @@
/// <reference types="chai" />
var assert = require('chai').assert;
var readFileSync = require('fs').readFileSync;
import ProtoBuf = require("protobufjs");
function testProtoBufJs() {
assert.ok("Builder" in ProtoBuf, "ProtoBuf should contain property Builder");
assert.ok("ByteBuffer" in ProtoBuf, "ProtoBuf should contain property ByteBuffer");
assert.ok("DotProto" in ProtoBuf, "ProtoBuf should contain property DotProto");
assert.ok("Reflect" in ProtoBuf, "ProtoBuf should contain property Reflect");
assert.ok("loadJson" in ProtoBuf, "ProtoBuf should contain property loadJson");
assert.ok("loadJsonFile" in ProtoBuf, "ProtoBuf should contain property loadJsonFile");
assert.ok("loadProto" in ProtoBuf, "ProtoBuf should contain property loadProto");
assert.ok("loadProtoFile" in ProtoBuf, "ProtoBuf should contain property loadProtoFile");
assert.ok("newBuilder" in ProtoBuf, "ProtoBuf should contain property newBuilder");
var jsonProto: ProtoBuf.ProtoBuilder = ProtoBuf.loadJson(readFileSync("test.json",
{"encoding": "utf8"}));
assertIsProtoBuilder(jsonProto, "loadJson");
var jsonFileProto: ProtoBuf.ProtoBuilder = ProtoBuf.loadJsonFile("test.json");
assertIsProtoBuilder(jsonFileProto, "loadJsonFile");
ProtoBuf.loadJsonFile("test.json", (error: any, builder: ProtoBuf.ProtoBuilder) => {
assertIsProtoBuilder(builder, "loadJsonFile callback");
});
var proto: ProtoBuf.ProtoBuilder = ProtoBuf.loadProto(readFileSync("test.proto",
{"encoding": "utf8"}));
assertIsProtoBuilder(proto, "loadProto");
var protoFile: ProtoBuf.ProtoBuilder = ProtoBuf.loadProtoFile("test.proto");
assertIsProtoBuilder(protoFile, "loadProtoFile");
ProtoBuf.loadProtoFile("test.proto", (error: any, builder: ProtoBuf.ProtoBuilder) => {
assertIsProtoBuilder(builder, "loadProtoFile callback");
});
var newBuilder: ProtoBuf.ProtoBuilder = ProtoBuf.newBuilder();
assertIsProtoBuilder(newBuilder, "newBuilder");
assertIsNamespace(protoFile.ns, "protoFile.ns");
assertIsNamespace(protoFile.ptr, "protoFile.ptr");
assertIsMetaMessage<any>(protoFile.build(), "protoFile.build()");
assertIsProtoBuf(protoFile.result, "protoFile.result");
assertIsProtoBuilder(protoFile.create(), "protoFile.create()");
assertIsProtoBuilder(protoFile.define("js"), "protoFile.define()");
assertIsT(protoFile.lookup(), "protoFile.lookup()");
}
function testBuilderJs() {
var Builder: ProtoBuf.Builder = ProtoBuf.Builder;
assertIsBuilder(Builder, "Builder");
var newBuilder: ProtoBuf.ProtoBuilder = new ProtoBuf.Builder();
assertIsProtoBuilder(newBuilder, "new Builder()");
var Message: ProtoBuf.Message = Builder.Message;
var Service: ProtoBuf.Service = Builder.Service;
}
function testDotProtoJs() {
var DotProto: ProtoBuf.DotProto = ProtoBuf.DotProto;
assertIsDotProto(DotProto, "DotProto");
}
function testReflectJs() {
var Reflect: ProtoBuf.Reflect = ProtoBuf.Reflect;
assertIsReflect(Reflect, "Reflect");
}
function assertIsProtoBuilder(pb: ProtoBuf.ProtoBuilder, name: string) {
if (pb != null && pb != undefined) {
assert.ok("ns" in pb, name + " should contain property ns");
assert.ok("ptr" in pb, name + " should contain property ptr");
assert.ok("resolved" in pb, name + " should contain property resolved");
assert.ok("result" in pb, name + " should contain property result");
assert.ok("files" in pb, name + " should contain property files");
assert.ok("importRoot" in pb, name + " should contain property importRoot");
assert.ok("options" in pb, name + " should contain property options");
assert.ok("reset" in pb, name + " should contain property reset");
assert.ok("define" in pb, name + " should contain property define");
assert.ok("create" in pb, name + " should contain property create");
assert.ok("resolveAll" in pb, name + " should contain property resolveAll");
assert.ok("build" in pb, name + " should contain property build");
assert.ok("lookup" in pb, name + " should contain property lookup");
assert.ok("syntax" in pb, name + " should contain property syntax");
}
}
function assertIsBuilder(b: ProtoBuf.Builder, name: string) {
assert.ok("Message" in b, name + " should contain property Message");
assert.ok("Service" in b, name + " should contain property Service");
assert.ok("isValidMessage" in b, name + " should contain property isValidMessage");
assert.ok("isValidMessageField" in b, name + " should contain property isValidMessageField");
assert.ok("isValidEnum" in b, name + " should contain property isValidEnum");
assert.ok("isValidService" in b, name + " should contain property isValidService");
assert.ok("isValidExtend" in b, name + " should contain property isValidExtend");
}
function assertIsProtoBuf(pb: ProtoBuf.ProtoBuf, name: string) {
for (var pkg in pb) {
if (pb.hasOwnProperty(pkg)) {
for (var property in pb[pkg]) {
if (typeof pb[pkg][property] == typeof Object
&& pb[pkg].hasOwnProperty(property)) {
assertIsMetaMessage(pb[pkg][property],
name + "." + pkg + "." + property);
}
}
}
}
}
function assertIsMetaMessage<T>(mm: ProtoBuf.MetaMessage<T>, name: string) {
assert.ok("decode" in mm, name + " should contain property decode");
assert.ok("decodeDelimited" in mm, name + " should contain property decodeDelimited");
assert.ok("decode64" in mm, name + " should contain property decode64");
assert.ok("decodeHex" in mm, name + " should contain property decodeHex");
assert.ok("decodeJSON" in mm, name + " should contain property decodeJSON");
}
function assertIsDotProto(dp: ProtoBuf.DotProto, name: string) {
assert.ok("Parser" in dp, name + " should contain property Parser");
assert.ok("Tokenizer" in dp, name + " should contain property Tokenizer");
assertIsParser(new dp.Parser(readFileSync("test.proto", {"encoding": "utf8"})),
name + ".Parser");
assertIsTokenizer(new dp.Tokenizer(readFileSync("test.proto", {"encoding": "utf8"})),
name + ".Tokenizer");
}
function assertIsParser(p: ProtoBuf.Parser, name: string) {
assert.ok("tn" in p, name + " should contain property tn");
assert.ok("parse" in p, name + " should contain property parse");
assert.ok("toString" in p, name + " should contain property toString");
assertIsTokenizer(p.tn, name + ".tn");
assertIsMetaProto(p.parse(), name + ".parse()");
}
function assertIsTokenizer(t: ProtoBuf.Tokenizer, name: string) {
assert.ok("source" in t, name + " should contain property source");
assert.ok("index" in t, name + " should contain property index");
assert.ok("line" in t, name + " should contain property line");
assert.ok("stack" in t, name + " should contain property stack");
assert.ok("readingString" in t, name + " should contain property readingString");
assert.ok("stringEndsWith" in t, name + " should contain property stringEndsWith");
assert.ok("next" in t, name + " should contain property next");
assert.ok("peek" in t, name + " should contain property peek");
assert.ok("toString" in t, name + " should contain property toString");
}
function assertIsMetaProto(mp: ProtoBuf.MetaProto, name: string) {
assert.ok("package" in mp, name + " should contain proeprty package");
assert.ok("messages" in mp, name + " should contain proeprty messages");
assert.ok("enums" in mp, name + " should contain proeprty enums");
assert.ok("imports" in mp, name + " should contain proeprty imports");
assert.ok("options" in mp, name + " should contain proeprty options");
assert.ok("services" in mp, name + " should contain proeprty services");
for (var message in mp.messages) {
assertIsProtoMessage(mp.messages[message], name + ".messages." + message);
}
for (var en in mp.enums) {
assertIsProtoEnum(mp.enums[en], name + ".enums." + en);
}
for (var serv in mp.services) {
assertIsProtoService(mp.services[serv], name + ".services." + serv);
}
}
function assertIsProtoEnum(pe: ProtoBuf.ProtoEnum, name: string) {
assert.ok("name" in pe, name + " should contain property name");
assert.ok("values" in pe, name + " should contain property values");
assert.ok("options" in pe, name + " should contain property options");
for (var value in pe.values) {
assertIsProtoEnumValue(pe.values[value], name + ".values." + value);
}
}
function assertIsProtoEnumValue(pev: ProtoBuf.ProtoEnumValue, name: string) {
assert.ok("name" in pev, name + " should contain property name");
assert.ok("id" in pev, name + " should contain property id");
}
function assertIsProtoField(pf: ProtoBuf.ProtoField, name: string) {
assert.ok("rule" in pf, name + " should contain property rule");
assert.ok("options" in pf, name + " should contain property options");
assert.ok("type" in pf, name + " should contain property type");
assert.ok("name" in pf, name + " should contain property name");
assert.ok("id" in pf, name + " should contain property id");
}
function assertIsProtoMessage(pm: ProtoBuf.ProtoMessage, name: string) {
assert.ok("name" in pm, name + " should contain property name");
assert.ok("fields" in pm, name + " should contain property fields");
assert.ok("enums" in pm, name + " should contain property enums");
assert.ok("messages" in pm, name + " should contain property messages");
assert.ok("options" in pm, name + " should contain property options");
assert.ok("oneofs" in pm, name + " should contain property oneofs");
for (var f in pm.fields) {
assertIsProtoField(pm.fields[f], name + ".fields." + f);
}
for (var en in pm.enums) {
assertIsProtoEnum(pm.enums[en], name + ".enums." + en);
}
for (var m in pm.messages) {
assertIsProtoMessage(pm.messages[m], name + ".messages." + m);
}
}
function assertIsProtoRpcService(rpc: ProtoBuf.ProtoRpcService, name: string) {
assert.ok("request" in rpc, name + " should contain property request");
assert.ok("response" in rpc, name + " should contain property response");
assert.ok("options" in rpc, name + " should contain property options");
}
function assertIsProtoService(ps: ProtoBuf.ProtoService, name: string) {
assert.ok("name" in ps, name + " should contain property name");
assert.ok("rpc" in ps, name + " should contain property rpc");
assert.ok("options" in ps, name + " should contain property options");
for (var rpc in ps.rpc) {
assertIsProtoRpcService(ps.rpc[rpc], name + ".rpc." + rpc);
}
}
function assertIsReflect(r: ProtoBuf.Reflect, name: string) {
assert.ok("T" in r, name + " should contain property T");
assert.ok("Namespace" in r, name + " should contain property Namespace");
assert.ok("Message" in r, name + " should contain property Message");
assert.ok("Enum" in r, name + " should contain property Enum");
assert.ok("Extension" in r, name + " should contain property Extension");
assert.ok("Service" in r, name + " should contain property Service");
assertIsT(new ProtoBuf.Reflect.T(), "new ProtoBuf.Reflect.T()");
assertIsNamespace(new ProtoBuf.Reflect.Namespace(), "new ProtoBuf.Reflect.Namespace()");
assertIsMessage(new ProtoBuf.Reflect.Message(), "new ProtoBuf.Reflect.Message()");
assertIsEnum(new ProtoBuf.Reflect.Enum(), "new ProtoBuf.Reflect.Enum()");
assertIsExtension(new ProtoBuf.Reflect.Extension(), "new ProtoBuf.Reflect.Extension()");
assertIsService(new ProtoBuf.Reflect.Service(), "new ProtoBuf.Reflect.Service()");
assertIsValue(new ProtoBuf.Reflect.Enum.Value(), "new ProtoBuf.Reflect.Enum.Value()");
assertIsOneOf(new ProtoBuf.Reflect.Message.OneOf(), "new ProtoBuf.Reflect.Message.OneOf()");
assertIsMethod(new ProtoBuf.Reflect.Service.Method(), "new ProtoBuf.Reflect.Service.Method()");
assertIsRPCMethod(new ProtoBuf.Reflect.Service.RPCMethod(),
"new ProtoBuf.Reflect.Service.RPCMethod()");
}
function assertIsT(t: ProtoBuf.ReflectT, name: string) {
if (t != null && t != undefined) {
assertIsTNoRecursion(t, name);
assertIsProtoBuilder(t.builder, name + ".builder");
assertIsTNoRecursion(t.parent, name + ".parent");
}
}
function assertIsTNoRecursion(t: ProtoBuf.ReflectT, name: string) {
if (t != null) {
assert.ok("builder" in t, name + " should contain property builder");
assert.ok("parent" in t, name + " should contain property parent");
assert.ok("name" in t, name + " should contain property name");
assert.ok("fqn" in t, name + " should contain property fqn");
assert.ok("toString" in t, name + " should contain property toString");
}
}
function assertIsNamespace(ns: ProtoBuf.ReflectNamespace, name: string) {
assertIsNamespaceNoRecursion(ns, name);
assertIsT(ns, name);
for (var child in ns.children) {
assertIsT(ns.children[child], name + ".children." + child);
}
for (var child in ns.getChildren()) {
assertIsT(ns.getChildren()[child], name + ".getChildren()." + child);
}
assertIsT(ns.getChild(), name + ".getChild()");
}
function assertIsNamespaceNoRecursion(ns: ProtoBuf.ReflectNamespace, name: string) {
assert.ok("className" in ns, name + " should contain property className");
assert.ok("children" in ns, name + " should contain property children");
assert.ok("options" in ns, name + " should contain property options");
assert.ok("syntax" in ns, name + " should contain property syntax");
assert.ok("getChildren" in ns, name + " should contain property getChildren");
assert.ok("addChild" in ns, name + " should contain property addChild");
assert.ok("getChild" in ns, name + " should contain property getChild");
assert.ok("resolve" in ns, name + " should contain property resolve");
assert.ok("build" in ns, name + " should contain property build");
assert.ok("buildOpt" in ns, name + " should contain property buildOpt");
assert.ok("getOption" in ns, name + " should contain property getOption");
}
function assertIsMessage(m: ProtoBuf.ReflectMessage, name: string) {
if (m != null && m != undefined) {
assert.ok("extensions" in m, name + " should contain property extensions");
assert.ok("clazz" in m, name + " should contain property clazz");
assert.ok("isGroup" in m, name + " should contain property isGroup");
assert.ok("build" in m, name + " should contain property build");
assert.ok("encode" in m, name + " should contain property encode");
assert.ok("calculate" in m, name + " should contain property calculate");
assert.ok("decode" in m, name + " should contain property decode");
assertIsNamespace(m, name);
}
}
function assertIsEnum(e: ProtoBuf.ReflectEnum, name: string) {
assert.ok("object" in e, name + " should contain property object");
assert.ok("build" in e, name + " should contain property build");
assertIsNamespace(e, name);
}
function assertIsExtension(e: ProtoBuf.ReflectExtension, name: string) {
assert.ok("field" in e, name + " should contain property field");
assertIsT(e, name);
assertIsField(e.field, name + ".field");
}
function assertIsService(s: ProtoBuf.ReflectService, name: string) {
assert.ok("clazz" in s, name + " should contain property clazz");
assert.ok("build" in s, name + " should contain property build");
assertIsNamespace(s, name);
}
function assertIsField(f: ProtoBuf.ReflectField, name: string) {
if (f != null && f != undefined) {
assert.ok("className" in f, name + " should contain property className");
assert.ok("required" in f, name + " should contain property required");
assert.ok("repeated" in f, name + " should contain property repeated");
assert.ok("type" in f, name + " should contain property type");
assert.ok("resolvedType" in f, name + " should contain property resolvedType");
assert.ok("id" in f, name + " should contain property id");
assert.ok("options" in f, name + " should contain property options");
assert.ok("defaultValue" in f, name + " should contain property defaultValue");
assert.ok("oneof" in f, name + " should contain property oneof");
assert.ok("originalName" in f, name + " should contain property originalName");
assert.ok("build" in f, name + " should contain property build");
assert.ok("mkLong" in f, name + " should contain property mkLong");
assert.ok("verifyValue" in f, name + " should contain property verifyValue");
assert.ok("encode" in f, name + " should contain property encode");
assert.ok("encodeValue" in f, name + " should contain property encodeValue");
assert.ok("calculate" in f, name + " should contain property calculate");
assert.ok("calculateValue" in f, name + " should contain property calculateValue");
assert.ok("decode" in f, name + " should contain property decode");
assertIsT(f, name);
assertIsT(f.resolvedType, name + ".resolvedType");
assertIsOneOf(f.oneof, name + ".oneof");
}
}
function assertIsWireTuple(wt: ProtoBuf.WireTuple, name: string) {
assert.ok("name" in wt, name + " should contain property name");
assert.ok("wireType" in wt, name + " should contain property wireType");
}
function assertIsExtensionField(ef: ProtoBuf.ReflectExtensionField, name: string) {
assert.ok("extension" in ef, name + " should contain property extension");
assertIsField(ef, name);
assertIsExtension(ef.extension, name + ".extension");
}
function assertIsOneOf(oo: ProtoBuf.ReflectOneOf, name: string) {
assert.ok("fields" in oo, name + " should contain property fields");
for (var f in oo.fields) {
assertIsField(oo.fields[f], name + ".fields." + f);
}
}
function assertIsValue(v: ProtoBuf.ReflectValue, name: string) {
assert.ok("className" in v, name + " should contain property className");
assert.ok("id" in v, name + " should contain property id");
assertIsT(v, name);
}
function assertIsMethod(m: ProtoBuf.ReflectMethod, name: string) {
assert.ok("className" in m, name + " should contain property className");
assert.ok("options" in m, name + " should contain property options");
assert.ok("buildOpt" in m, name + " should contain property buildOpt");
assertIsT(m, name);
}
function assertIsRPCMethod(rpc: ProtoBuf.ReflectRPCMethod, name: string) {
assert.ok("requestName" in rpc, name + " should contain property requestName");
assert.ok("responseName" in rpc, name + " should contain property responseName");
assert.ok("resolvedRequestType" in rpc, name + " should contain property resolvedRequestType");
assert.ok("resolvedResponseType" in rpc,
name + " should contain property resolvedResponseType");
assertIsMethod(rpc, name);
assertIsMessage(rpc.resolvedRequestType, name + ".resolvedRequestType");
assertIsMessage(rpc.resolvedResponseType, name + ".resolvedResponsetype");
}
testProtoBufJs();
testBuilderJs();
testDotProtoJs();
testReflectJs();

View File

@@ -1,24 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"protobufjs-tests.ts"
]
}

View File

@@ -1,79 +0,0 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}