UNPKG

3.62 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var util_1 = require("./util");
4var ExportMap = (function () {
5 function ExportMap() {
6 this.messageMap = {};
7 this.enumMap = {};
8 }
9 ExportMap.prototype.exportNested = function (scope, fileDescriptor, message) {
10 var _this = this;
11 var messageName = message.getName() || util_1.throwError("Missing message name for message. Scope: " + scope);
12 var messageOptions = message.getOptions();
13 var mapFieldOptions = undefined;
14 if (messageOptions && messageOptions.getMapEntry()) {
15 var keyType = message.getFieldList()[0].getType() || util_1.throwError("Missing map key type for message. Scope: " + scope + " Message: " + messageName);
16 var keyTypeName = message.getFieldList()[0].getTypeName();
17 var valueType = message.getFieldList()[1].getType() || util_1.throwError("Missing map value type for message. Scope: " + scope + " Message: " + messageName);
18 var valueTypeName = message.getFieldList()[1].getTypeName();
19 mapFieldOptions = {
20 key: [
21 keyType,
22 keyTypeName ? keyTypeName.slice(1) : null,
23 ],
24 value: [
25 valueType,
26 valueTypeName ? valueTypeName.slice(1) : null,
27 ],
28 };
29 }
30 var pkg = fileDescriptor.getPackage() || "";
31 var fileName = fileDescriptor.getName() || util_1.throwError("Missing file name for message. Scope: " + scope + " Message: " + messageName);
32 var messageEntry = {
33 pkg: pkg,
34 fileName: fileName,
35 messageOptions: messageOptions,
36 mapFieldOptions: mapFieldOptions,
37 };
38 var packagePrefix = scope ? scope + "." : "";
39 var entryName = "" + packagePrefix + messageName;
40 this.messageMap[entryName] = messageEntry;
41 message.getNestedTypeList().forEach(function (nested) {
42 _this.exportNested("" + packagePrefix + messageName, fileDescriptor, nested);
43 });
44 message.getEnumTypeList().forEach(function (enumType) {
45 var enumName = enumType.getName();
46 var identifier = "" + packagePrefix + messageName + "." + enumName;
47 _this.enumMap[identifier] = {
48 pkg: pkg,
49 fileName: fileName,
50 enumOptions: enumType.getOptions(),
51 };
52 });
53 };
54 ExportMap.prototype.addFileDescriptor = function (fileDescriptor) {
55 var _this = this;
56 var scope = fileDescriptor.getPackage() || "";
57 fileDescriptor.getMessageTypeList().forEach(function (messageType) {
58 _this.exportNested(scope, fileDescriptor, messageType);
59 });
60 fileDescriptor.getEnumTypeList().forEach(function (enumType) {
61 var packagePrefix = scope ? scope + "." : "";
62 var enumName = enumType.getName();
63 _this.enumMap[packagePrefix + enumName] = {
64 pkg: scope,
65 fileName: fileDescriptor.getName() || util_1.throwError("Missing file descriptor name for enum. Scope: " + scope + " Enum: " + enumName),
66 enumOptions: enumType.getOptions(),
67 };
68 });
69 };
70 ExportMap.prototype.getMessage = function (str) {
71 return this.messageMap[str];
72 };
73 ExportMap.prototype.getEnum = function (str) {
74 return this.enumMap[str];
75 };
76 return ExportMap;
77}());
78exports.ExportMap = ExportMap;
79//# sourceMappingURL=ExportMap.js.map
\No newline at end of file