-
Notifications
You must be signed in to change notification settings - Fork 22
/
model.ts
155 lines (138 loc) · 3.42 KB
/
model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { ParseResult } from "../parser/proto.ts";
export interface Schema {
files: { [filePath: string]: File };
types: { [typePath: string]: Type }; // type name is included in typePath
extends: { [typePath: string]: Extend[] };
services: { [typePath: string]: Service }; // service name is included in typePath
}
export type OptionValue = boolean | number | string;
export interface Options {
[optionName: string]: OptionValue;
}
export interface File {
parseResult?: ParseResult;
importPath: string;
syntax: "proto2" | "proto3";
package: string;
imports: Import[];
options: Options;
typePaths: string[];
servicePaths: string[];
}
export interface Import {
kind: "" | "public" | "weak";
importPath: string;
filePath?: string;
}
export type Type = Message | Enum;
interface TypeBase<TKind extends string> {
kind: TKind;
filePath: string;
options: Options;
description: Description;
}
interface FieldBase {
description: Description;
}
export interface Description {
leading: string[];
trailing: string[];
leadingDetached: string[];
}
export interface Message extends TypeBase<"message"> {
fields: { [fieldNumber: number]: MessageField };
groups: { [groupName: string]: Group };
reservedFieldNumberRanges: Range[];
reservedFieldNames: string[];
extensions: Range[];
}
export interface Group {
kind: "required" | "optional" | "repeated";
options: Options;
description: Description;
fieldNumber: number;
fields: { [fieldNumber: number]: MessageField };
groups: { [groupName: string]: Group };
reservedFieldNumberRanges: Range[];
reservedFieldNames: string[];
extensions: Range[];
}
export interface Extend {
filePath: string;
message: string;
description: Description;
fields: { [fieldNumber: number]: ExtendField };
groups: { [groupName: string]: Group };
}
export interface Enum extends TypeBase<"enum"> {
fields: { [fieldNumber: number]: EnumField };
}
export interface EnumField extends FieldBase {
name: string;
options: Options;
}
export type ExtendField =
| NormalField
| RequiredField
| OptionalField
| RepeatedField;
export type MessageField =
| NormalField
| RequiredField
| OptionalField
| RepeatedField
| OneofField
| MapField;
interface MessageFieldBase<TKind extends string> extends FieldBase {
kind: TKind;
name: string;
options: Options;
}
export interface NormalField extends MessageFieldBase<"normal"> {
type: string;
typePath?: string;
}
export interface RequiredField extends MessageFieldBase<"required"> {
type: string;
typePath?: string;
}
export interface OptionalField extends MessageFieldBase<"optional"> {
type: string;
typePath?: string;
}
export interface RepeatedField extends MessageFieldBase<"repeated"> {
type: string;
typePath?: string;
}
export interface OneofField extends MessageFieldBase<"oneof"> {
type: string;
typePath?: string;
oneof: string;
}
export interface MapField extends MessageFieldBase<"map"> {
keyType: string;
keyTypePath?: string;
valueType: string;
valueTypePath?: string;
}
export interface Range {
from: number;
to: number; // max: Infinity
}
export interface Service {
filePath: string;
options: Options;
description: Description;
rpcs: { [rpcName: string]: Rpc };
}
export interface Rpc {
options: Options;
description: Description;
reqType: RpcType;
resType: RpcType;
}
export interface RpcType {
stream: boolean;
type: string;
typePath?: string;
}