Comparing version
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.detectBatchMethod = exports.responsePromiseOrObservable = exports.responseObservable = exports.responsePromise = exports.responseType = exports.requestType = exports.observableType = exports.rawRequestType = exports.detectMapType = exports.toTypeName = exports.getEnumMethod = exports.messageToTypeName = exports.wrapperTypeName = exports.valueTypeName = exports.isEmptyType = exports.isLongValueType = exports.isStructTypeName = exports.isStructType = exports.isListValueTypeName = exports.isListValueType = exports.isFieldMaskTypeName = exports.isFieldMaskType = exports.isBytesValueType = exports.isAnyValueTypeName = exports.isAnyValueType = exports.isValueType = exports.isTimestamp = exports.isObjectId = exports.isMapType = exports.isWholeNumber = exports.isLong = exports.isRepeated = exports.isWithinOneOfThatShouldBeUnion = exports.isWithinOneOf = exports.isEnum = exports.isMessage = exports.isBytes = exports.isPrimitive = exports.isOptionalProperty = exports.isScalar = exports.createTypeMap = exports.notDefaultCheck = exports.defaultValue = exports.packedType = exports.toReaderCall = exports.basicTypeName = exports.basicLongWireType = exports.basicWireType = void 0; | ||
exports.detectBatchMethod = exports.responsePromiseOrObservable = exports.responseObservable = exports.responsePromise = exports.responseType = exports.requestType = exports.observableType = exports.rawRequestType = exports.detectMapType = exports.shouldGenerateJSMapType = exports.toTypeName = exports.getEnumMethod = exports.messageToTypeName = exports.wrapperTypeName = exports.valueTypeName = exports.isEmptyType = exports.isLongValueType = exports.isStructTypeName = exports.isStructType = exports.isListValueTypeName = exports.isListValueType = exports.isFieldMaskTypeName = exports.isFieldMaskType = exports.isBytesValueType = exports.isAnyValueTypeName = exports.isAnyValueType = exports.isValueType = exports.isTimestamp = exports.isObjectId = exports.isMapType = exports.isWholeNumber = exports.isLong = exports.isRepeated = exports.isWithinOneOfThatShouldBeUnion = exports.isWithinOneOf = exports.isEnum = exports.isMessage = exports.isBytes = exports.isPrimitive = exports.isOptionalProperty = exports.isScalar = exports.createTypeMap = exports.notDefaultCheck = exports.defaultValue = exports.packedType = exports.toReaderCall = exports.basicTypeName = exports.basicLongWireType = exports.basicWireType = void 0; | ||
const ts_proto_descriptors_1 = require("ts-proto-descriptors"); | ||
@@ -590,3 +590,3 @@ const ts_poet_1 = require("ts-poet"); | ||
const { keyType, valueType } = mapType; | ||
if (ctx.options.useMapType) { | ||
if (shouldGenerateJSMapType(ctx, messageDesc, field)) { | ||
return finalize((0, ts_poet_1.code) `Map<${keyType}, ${valueType}>`, ensureOptional); | ||
@@ -626,2 +626,25 @@ } | ||
exports.toTypeName = toTypeName; | ||
/** | ||
* For a protobuf map field, if the generated code should use the javascript Map type. | ||
* | ||
* If the type of a protobuf map key corresponds to the Long type, we always use the Map type. This avoids generating | ||
* invalid code such as below (using Long as key of a javascript object): | ||
* | ||
* export interface Foo { | ||
* bar: { [key: Long]: Long } | ||
* } | ||
* | ||
* See https://github.com/stephenh/ts-proto/issues/708 for more details. | ||
*/ | ||
function shouldGenerateJSMapType(ctx, message, field) { | ||
if (ctx.options.useMapType) { | ||
return true; | ||
} | ||
const mapType = detectMapType(ctx, message, field); | ||
if (!mapType) { | ||
return false; | ||
} | ||
return isLong(mapType.keyField) && ctx.options.forceLong === options_1.LongOption.LONG; | ||
} | ||
exports.shouldGenerateJSMapType = shouldGenerateJSMapType; | ||
function detectMapType(ctx, messageDesc, fieldDesc) { | ||
@@ -628,0 +651,0 @@ var _a; |
{ | ||
"name": "ts-proto", | ||
"version": "1.156.6", | ||
"version": "1.156.7", | ||
"description": "", | ||
@@ -57,3 +57,3 @@ "main": "build/plugin.js", | ||
"object-hash": "^3.0.0", | ||
"prettier": "^3.0.0", | ||
"prettier": "^2.8.8", | ||
"protobufjs-cli": "^1.1.1", | ||
@@ -60,0 +60,0 @@ "reflect-metadata": "^0.1.13", |
Sorry, the diff of this file is too big to display
324683
0.44%5658
0.53%