ts-proto
Advanced tools
Comparing version 1.176.3 to 1.177.0
@@ -99,2 +99,3 @@ import { ToStringOpts } from "ts-poet/build/Code"; | ||
annotateFilesWithVersion: boolean; | ||
noDefaultsForOptionals: boolean; | ||
}; | ||
@@ -101,0 +102,0 @@ export declare function defaultOptions(): Options; |
@@ -106,2 +106,3 @@ "use strict"; | ||
annotateFilesWithVersion: true, | ||
noDefaultsForOptionals: false, | ||
}; | ||
@@ -108,0 +109,0 @@ } |
@@ -0,5 +1,5 @@ | ||
import { Code, Import } from "ts-poet"; | ||
import { CodeGeneratorRequest, DescriptorProto, EnumDescriptorProto, FieldDescriptorProto, FieldDescriptorProto_Type, FileDescriptorProto, MessageOptions, MethodDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors"; | ||
import { Code, Import } from "ts-poet"; | ||
import { Context } from "./context"; | ||
import { Options } from "./options"; | ||
import { Context } from "./context"; | ||
/** Based on https://github.com/dcodeIO/protobuf.js/blob/master/src/types.js#L37. */ | ||
@@ -6,0 +6,0 @@ export declare function basicWireType(type: FieldDescriptorProto_Type): number; |
@@ -5,10 +5,10 @@ "use strict"; | ||
exports.isJsTypeFieldOption = void 0; | ||
const ts_poet_1 = require("ts-poet"); | ||
const ts_proto_descriptors_1 = require("ts-proto-descriptors"); | ||
const ts_poet_1 = require("ts-poet"); | ||
const case_1 = require("./case"); | ||
const enums_1 = require("./enums"); | ||
const options_1 = require("./options"); | ||
const sourceInfo_1 = require("./sourceInfo"); | ||
const utils_1 = require("./utils"); | ||
const visit_1 = require("./visit"); | ||
const utils_1 = require("./utils"); | ||
const sourceInfo_1 = require("./sourceInfo"); | ||
const case_1 = require("./case"); | ||
const enums_1 = require("./enums"); | ||
/** Based on https://github.com/dcodeIO/protobuf.js/blob/master/src/types.js#L37. */ | ||
@@ -193,2 +193,5 @@ function basicWireType(type) { | ||
const { typeMap, options, utils, currentFile } = ctx; | ||
if (options.noDefaultsForOptionals) { | ||
return options.useNullAsOptional ? null : undefined; | ||
} | ||
const useDefaultValue = !currentFile.isProto3Syntax && !options.disableProto2DefaultValues && field.defaultValue; | ||
@@ -270,2 +273,7 @@ const numericDefaultVal = useDefaultValue ? field.defaultValue : 0; | ||
const isOptional = isOptionalProperty(field, messageOptions, options, currentFile.isProto3Syntax); | ||
if (options.noDefaultsForOptionals) { | ||
return isOptional | ||
? (0, ts_poet_1.code) `${place} !== undefined ${(0, utils_1.withAndMaybeCheckIsNotNull)(options, place)}` | ||
: (0, ts_poet_1.code) `${place} !== undefined`; | ||
} | ||
const maybeNotUndefinedAnd = isOptional | ||
@@ -374,2 +382,3 @@ ? `${place} !== undefined ${(0, utils_1.withAndMaybeCheckIsNotNull)(options, place)} &&` | ||
((optionalAll || deprecatedOnly) && !(messageOptions === null || messageOptions === void 0 ? void 0 : messageOptions.mapEntry)) || | ||
(options.noDefaultsForOptionals && !isRepeated(field) && (isScalar(field) || isEnum(field))) || | ||
// file is proto2, we have enabled proto2 optionals, and the field itself is optional | ||
@@ -376,0 +385,0 @@ (!isProto3Syntax && |
{ | ||
"name": "ts-proto", | ||
"version": "1.176.3", | ||
"version": "1.177.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/plugin.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
397268
6857
1039