Skip to content

Commit

Permalink
Breaking: Everything uses interfaces now instead of typedefs (Somethi…
Browse files Browse the repository at this point in the history
…ngProperties is now ISomething)
  • Loading branch information
dcodeIO committed Apr 15, 2017
1 parent 5bc3541 commit c97b618
Show file tree
Hide file tree
Showing 37 changed files with 2,333 additions and 1,891 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/node_modules/*
bin/*
cli/wrappers/*
coverage/*
Expand Down
8 changes: 7 additions & 1 deletion cli/lib/tsd-jsdoc/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ function writeInterface(element) {
function writeInterfaceBody(element) {
writeln("{");
++indent;
element.properties.forEach(writeProperty);
if (element.tsType)
writeln(element.tsType);
else if (element.properties && element.properties.length)
element.properties.forEach(writeProperty);
--indent;
write("}");
}
Expand Down Expand Up @@ -429,6 +432,9 @@ function handleClass(element, parent) {
writeln("{");
++indent;

if (element.tsType)
writeln(element.tsType);

// constructor
if (!is_interface && !element.virtual)
handleFunction(element, parent, true);
Expand Down
129 changes: 64 additions & 65 deletions cli/targets/static.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion config/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"array-type": [ true, "array" ],
"no-namespace": false,
"interface-name": [ false ],
"interface-over-type-literal": false,
"interface-over-type-literal": true,
"no-empty-interface": false,
"max-line-length": [ false ],
"trailing-comma": [ true, "never" ],
"variable-name": [ false ],
Expand Down
66 changes: 33 additions & 33 deletions ext/descriptor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ API

The extension adds `.fromDescriptor(descriptor[, syntax])` and `#toDescriptor([syntax])` methods to reflection objects and exports the `.google.protobuf` namespace of the internally used `Root` instance containing the following types present in descriptor.proto:

| Descriptor type | protobuf.js type | Remarks
|--------------------------------|------------------|---------
| **FileDescriptorSet** | Root |
| FileDescriptorProto | | dependencies are not supported
| FileOptions | |
| FileOptions_OptimizeMode | |
| SourceCodeInfo | | not supported
| SourceCodeInfo_Location | |
| GeneratedCodeInfo | | not supported
| GeneratedCodeInfo_Annotation | |
| **DescriptorProto** | Type |
| MessageOptions | |
| DescriptorProto_ExtensionRange | |
| DescriptorProto_ReservedRange | |
| **FieldDescriptorProto** | Field |
| FieldDescriptorProto_Label | |
| FieldDescriptorProto_Type | |
| FieldOptions | |
| FieldOptions_CType | |
| FieldOptions_JSType | |
| **OneofDescriptorProto** | OneOf |
| OneofOptions | |
| **EnumDescriptorProto** | Enum |
| EnumOptions | |
| EnumValueDescriptorProto | |
| EnumValueOptions | | not supported
| **ServiceDescriptorProto** | Service |
| ServiceOptions | |
| **MethodDescriptorProto** | Method |
| MethodOptions | |
| UninterpretedOption | | not supported
| UninterpretedOption_NamePart | |
| Descriptor type | protobuf.js type | Remarks
|-------------------------------|------------------|---------
| **FileDescriptorSet** | Root |
| FileDescriptorProto | | dependencies are not supported
| FileOptions | |
| FileOptionsOptimizeMode | |
| SourceCodeInfo | | not supported
| SourceCodeInfoLocation | |
| GeneratedCodeInfo | | not supported
| GeneratedCodeInfoAnnotation | |
| **DescriptorProto** | Type |
| MessageOptions | |
| DescriptorProtoExtensionRange | |
| DescriptorProtoReservedRange | |
| **FieldDescriptorProto** | Field |
| FieldDescriptorProtoLabel | |
| FieldDescriptorProtoType | |
| FieldOptions | |
| FieldOptionsCType | |
| FieldOptionsJSType | |
| **OneofDescriptorProto** | OneOf |
| OneofOptions | |
| **EnumDescriptorProto** | Enum |
| EnumOptions | |
| EnumValueDescriptorProto | |
| EnumValueOptions | | not supported
| **ServiceDescriptorProto** | Service |
| ServiceOptions | |
| **MethodDescriptorProto** | Method |
| MethodOptions | |
| UninterpretedOption | | not supported
| UninterpretedOptionNamePart | |

Note that not all features of descriptor.proto translate perfectly to a protobuf.js root instance. A root instance has only limited knowlege of packages or individual files for example, which is then compensated by guessing and generating fictional file names.

When using TypeScript, the respective `...$Properties` types can be used to reference specific message types (i.e. `protobuf.Message<DescriptorProto$Properties>`).
When using TypeScript, the respective interface types can be used to reference specific message instances (i.e. `protobuf.Message<IDescriptorProto>`).
144 changes: 72 additions & 72 deletions ext/descriptor/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import * as $protobuf from "../..";

type FileDescriptorSet$Properties = {
file: FileDescriptorProto$Properties[];
};
export interface IFileDescriptorSet {
file: IFileDescriptorProto[];
}

type FileDescriptorProto$Properties = {
export interface IFileDescriptorProto {
name?: string;
package?: string;
dependency?: any;
publicDependency?: any;
weakDependency?: any;
messageType?: DescriptorProto$Properties[];
enumType?: EnumDescriptorProto$Properties[];
service?: ServiceDescriptorProto$Properties[];
extension?: FieldDescriptorProto$Properties[];
options?: FileOptions$Properties;
messageType?: IDescriptorProto[];
enumType?: IEnumDescriptorProto[];
service?: IServiceDescriptorProto[];
extension?: IFieldDescriptorProto[];
options?: IFileOptions;
sourceCodeInfo?: any;
syntax?: string;
};
}

type FileOptions$Properties = {
export interface IFileOptions {
javaPackage?: string;
javaOuterClassname?: string;
javaMultipleFiles?: boolean;
javaGenerateEqualsAndHash?: boolean;
javaStringCheckUtf8?: boolean;
optimizeFor?: FileOptions$OptimizeMode;
optimizeFor?: IFileOptionsOptimizeMode;
goPackage?: string;
ccGenericServices?: boolean;
javaGenericServices?: boolean;
Expand All @@ -34,121 +34,121 @@ type FileOptions$Properties = {
ccEnableArenas?: boolean;
objcClassPrefix?: string;
csharpNamespace?: string;
};
}

type FileOptions$OptimizeMode = number;
type IFileOptionsOptimizeMode = number;

type DescriptorProto$Properties = {
export interface IDescriptorProto {
name?: string;
field?: FieldDescriptorProto$Properties[];
extension?: FieldDescriptorProto$Properties[];
nestedType?: DescriptorProto$Properties[];
enumType?: EnumDescriptorProto$Properties[];
extensionRange?: ExtensionRange$Properties[];
oneofDecl?: OneofDescriptorProto$Properties[];
options?: MessageOptions$Properties;
reservedRange?: ReservedRange$Properties[];
field?: IFieldDescriptorProto[];
extension?: IFieldDescriptorProto[];
nestedType?: IDescriptorProto[];
enumType?: IEnumDescriptorProto[];
extensionRange?: IDescriptorProtoExtensionRange[];
oneofDecl?: IOneofDescriptorProto[];
options?: IMessageOptions;
reservedRange?: IDescriptorProtoReservedRange[];
reservedName?: string[];
};
}

type MessageOptions$Properties = {
export interface IMessageOptions {
mapEntry?: boolean;
};
}

type ExtensionRange$Properties = {
export interface IDescriptorProtoExtensionRange {
start?: number;
end?: number;
};
}

type ReservedRange$Properties = {
export interface IDescriptorProtoReservedRange {
start?: number;
end?: number;
};
}

type FieldDescriptorProto$Properties = {
export interface IFieldDescriptorProto {
name?: string;
number?: number;
label?: FieldDescriptorProto$Label;
type?: FieldDescriptorProto$Type;
label?: IFieldDescriptorProtoLabel;
type?: IFieldDescriptorProtoType;
typeName?: string;
extendee?: string;
defaultValue?: string;
oneofIndex?: number;
jsonName?: any;
options?: FieldOptions$Properties;
};
options?: IFieldOptionsProperties;
}

type FieldDescriptorProto$Label = number;
type IFieldDescriptorProtoLabel = number;

type FieldDescriptorProto$Type = number;
type IFieldDescriptorProtoType = number;

type FieldOptions$Properties = {
export interface IFieldOptions {
packed?: boolean;
jstype?: FieldOptions$JSType;
};
jstype?: IFieldOptionsJSType;
}

type FieldOptions$JSType = number;
type IFieldOptionsJSType = number;

type EnumDescriptorProto$Properties = {
export interface IEnumDescriptorProto {
name?: string;
value?: EnumValueDescriptorProto$Properties[];
options?: EnumOptions$Properties;
};
value?: IEnumValueDescriptorProto[];
options?: IEnumOptions;
}

type EnumValueDescriptorProto$Properties = {
export interface IEnumValueDescriptorProto {
name?: string;
number?: number;
options?: any;
};
}

type EnumOptions$Properties = {
export interface IEnumOptions {
allowAlias?: boolean;
deprecated?: boolean;
};
}

type OneofDescriptorProto$Properties = {
export interface IOneofDescriptorProto {
name?: string;
options?: any;
};
}

type ServiceDescriptorProto$Properties = {
export interface IServiceDescriptorProto {
name?: string;
method?: MethodDescriptorProto$Properties[];
options?: ServiceOptions$Properties;
};
method?: IMethodDescriptorProto[];
options?: IServiceOptions;
}

type ServiceOptions$Properties = {
export interface IServiceOptions {
deprecated?: boolean;
};
}

type MethodDescriptorProto$Properties = {
export interface IMethodDescriptorProto {
name?: string;
inputType?: string;
outputType?: string;
options?: MethodOptions$Properties;
options?: IMethodOptions;
clientStreaming?: boolean;
serverStreaming?: boolean;
};
}

type MethodOptions$Properties = {
export interface IMethodOptions {
deprecated?: boolean;
};
}

export const FileDescriptorSet: $protobuf.Type;

export const FileDescriptorProto: $protobuf.Type;

export const DescriptorProto: $protobuf.Type;

export const DescriptorProto_ExtensionRange: $protobuf.Type;
export const DescriptorProtoExtensionRange: $protobuf.Type;

export const DescriptorProto_ReservedRange: $protobuf.Type;
export const DescriptorProtoReservedRange: $protobuf.Type;

export const FieldDescriptorProto: $protobuf.Type;

export const FieldDescriptorProto_Label: $protobuf.Enum;
export const FieldDescriptorProtoLabel: $protobuf.Enum;

export const FieldDescriptorProto_Type: $protobuf.Enum;
export const FieldDescriptorProtoType: $protobuf.Enum;

export const OneofDescriptorProto: $protobuf.Type;

Expand All @@ -162,15 +162,15 @@ export const MethodDescriptorProto: $protobuf.Type;

export const FileOptions: $protobuf.Type;

export const FileOptions_OptimizeMode: $protobuf.Enum;
export const FileOptionsOptimizeMode: $protobuf.Enum;

export const MessageOptions: $protobuf.Type;

export const FieldOptions: $protobuf.Type;

export const FieldOptions_CType: $protobuf.Enum;
export const FieldOptionsCType: $protobuf.Enum;

export const FieldOptions_JSType: $protobuf.Enum;
export const FieldOptionsJSType: $protobuf.Enum;

export const OneofOptions: $protobuf.Type;

Expand All @@ -184,12 +184,12 @@ export const MethodOptions: $protobuf.Type;

export const UninterpretedOption: $protobuf.Type;

export const UninterpretedOption_NamePart: $protobuf.Type;
export const UninterpretedOptionNamePart: $protobuf.Type;

export const SourceCodeInfo: $protobuf.Type;

export const SourceCodeInfo_Location: $protobuf.Type;
export const SourceCodeInfoLocation: $protobuf.Type;

export const GeneratedCodeInfo: $protobuf.Type;

export const GeneratedCodeInfo_Annotation: $protobuf.Type;
export const GeneratedCodeInfoAnnotation: $protobuf.Type;
Loading

0 comments on commit c97b618

Please sign in to comment.