UNPKG

2.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var util_1 = require("../util");
4exports.MESSAGE_TYPE = 11;
5exports.BYTES_TYPE = 12;
6exports.ENUM_TYPE = 14;
7var TypeNumToTypeString = {};
8TypeNumToTypeString[1] = "number";
9TypeNumToTypeString[2] = "number";
10TypeNumToTypeString[3] = "number";
11TypeNumToTypeString[4] = "number";
12TypeNumToTypeString[5] = "number";
13TypeNumToTypeString[6] = "number";
14TypeNumToTypeString[7] = "number";
15TypeNumToTypeString[8] = "boolean";
16TypeNumToTypeString[9] = "string";
17TypeNumToTypeString[10] = "Object";
18TypeNumToTypeString[exports.MESSAGE_TYPE] = "Object";
19TypeNumToTypeString[exports.BYTES_TYPE] = "Uint8Array";
20TypeNumToTypeString[13] = "number";
21TypeNumToTypeString[exports.ENUM_TYPE] = "number";
22TypeNumToTypeString[15] = "number";
23TypeNumToTypeString[16] = "number";
24TypeNumToTypeString[17] = "number";
25TypeNumToTypeString[18] = "number";
26function getTypeName(fieldTypeNum) {
27 return TypeNumToTypeString[fieldTypeNum];
28}
29exports.getTypeName = getTypeName;
30function getFieldType(type, typeName, currentFileName, exportMap) {
31 if (type === exports.MESSAGE_TYPE) {
32 if (!typeName)
33 return util_1.throwError("Type was Message, but typeName is not set");
34 var fromExport = exportMap.getMessage(typeName);
35 if (!fromExport) {
36 return util_1.throwError("Could not getFieldType for message: " + typeName);
37 }
38 var withinNamespace = util_1.withinNamespaceFromExportEntry(typeName, fromExport);
39 if (fromExport.fileName === currentFileName) {
40 return withinNamespace;
41 }
42 else {
43 return util_1.filePathToPseudoNamespace(fromExport.fileName) + "." + withinNamespace;
44 }
45 }
46 else if (type === exports.ENUM_TYPE) {
47 if (!typeName)
48 return util_1.throwError("Type was Enum, but typeName is not set");
49 var fromExport = exportMap.getEnum(typeName);
50 if (!fromExport) {
51 return util_1.throwError("Could not getFieldType for enum: " + typeName);
52 }
53 var withinNamespace = util_1.withinNamespaceFromExportEntry(typeName, fromExport);
54 if (fromExport.fileName === currentFileName) {
55 return withinNamespace + "Map";
56 }
57 else {
58 return util_1.filePathToPseudoNamespace(fromExport.fileName) + "." + withinNamespace;
59 }
60 }
61 else {
62 return TypeNumToTypeString[type];
63 }
64}
65exports.getFieldType = getFieldType;
66//# sourceMappingURL=FieldTypes.js.map
\No newline at end of file