Comparing version 1.179.0 to 1.180.0
@@ -198,2 +198,23 @@ "use strict"; | ||
} | ||
else if (ctx.options.oneof === options_1.OneofOption.UNIONS_VALUE) { | ||
chunks.push((0, ts_poet_1.code) `wrap(value: any): Value { | ||
const result = createBaseValue()${maybeAsAny(ctx.options)}; | ||
if (value === null) { | ||
result.kind = {$case: '${fieldNames.nullValue}', value }; | ||
} else if (typeof value === 'boolean') { | ||
result.kind = {$case: '${fieldNames.boolValue}', value }; | ||
} else if (typeof value === 'number') { | ||
result.kind = {$case: '${fieldNames.numberValue}', value }; | ||
} else if (typeof value === 'string') { | ||
result.kind = {$case: '${fieldNames.stringValue}', value }; | ||
} else if (${ctx.utils.globalThis}.Array.isArray(value)) { | ||
result.kind = {$case: '${fieldNames.listValue}', value }; | ||
} else if (typeof value === 'object') { | ||
result.kind = {$case: '${fieldNames.structValue}', value }; | ||
} else if (typeof value !== 'undefined') { | ||
throw new ${ctx.utils.globalThis}.Error('Unsupported any value type: ' + typeof value); | ||
} | ||
return result; | ||
}`); | ||
} | ||
else { | ||
@@ -290,2 +311,7 @@ chunks.push((0, ts_poet_1.code) `wrap(value: any): Value { | ||
} | ||
else if (ctx.options.oneof === options_1.OneofOption.UNIONS_VALUE) { | ||
chunks.push((0, ts_poet_1.code) `unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined { | ||
return message.kind?.value; | ||
}`); | ||
} | ||
else { | ||
@@ -292,0 +318,0 @@ chunks.push((0, ts_poet_1.code) `unwrap(message: any): string | number | boolean | Object | null | Array<any> | undefined { |
@@ -25,3 +25,4 @@ import { ToStringOpts } from "ts-poet/build/Code"; | ||
PROPERTIES = "properties", | ||
UNIONS = "unions" | ||
UNIONS = "unions", | ||
UNIONS_VALUE = "unions-value" | ||
} | ||
@@ -28,0 +29,0 @@ export declare enum ServiceOption { |
@@ -33,2 +33,3 @@ "use strict"; | ||
OneofOption["UNIONS"] = "unions"; | ||
OneofOption["UNIONS_VALUE"] = "unions-value"; | ||
})(OneofOption || (exports.OneofOption = OneofOption = {})); | ||
@@ -35,0 +36,0 @@ var ServiceOption; |
@@ -410,3 +410,5 @@ "use strict"; | ||
function isWithinOneOfThatShouldBeUnion(options, field) { | ||
return isWithinOneOf(field) && options.oneof === options_1.OneofOption.UNIONS && !field.proto3Optional; | ||
return (isWithinOneOf(field) && | ||
(options.oneof === options_1.OneofOption.UNIONS || options.oneof === options_1.OneofOption.UNIONS_VALUE) && | ||
!field.proto3Optional); | ||
} | ||
@@ -413,0 +415,0 @@ exports.isWithinOneOfThatShouldBeUnion = isWithinOneOfThatShouldBeUnion; |
@@ -76,2 +76,3 @@ /// <reference types="node" /> | ||
export declare function maybeCheckIsNull(options: Pick<Options, "useNullAsOptional">, typeName: string, prefix?: string): string; | ||
export declare function oneofValueName(fieldName: string, options: Pick<Options, "oneof">): string; | ||
export declare function withOrMaybeCheckIsNotNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string; | ||
@@ -78,0 +79,0 @@ export declare function withOrMaybeCheckIsNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getVersions = exports.withAndMaybeCheckIsNull = exports.withAndMaybeCheckIsNotNull = exports.withOrMaybeCheckIsNull = exports.withOrMaybeCheckIsNotNull = exports.maybeCheckIsNull = exports.maybeCheckIsNotNull = exports.nullOrUndefined = exports.arrowFunction = exports.tryCatchBlock = exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.safeAccessor = exports.getFieldName = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.generateIndexFiles = exports.protoFilesToGenerate = void 0; | ||
exports.getVersions = exports.withAndMaybeCheckIsNull = exports.withAndMaybeCheckIsNotNull = exports.withOrMaybeCheckIsNull = exports.withOrMaybeCheckIsNotNull = exports.oneofValueName = exports.maybeCheckIsNull = exports.maybeCheckIsNotNull = exports.nullOrUndefined = exports.arrowFunction = exports.tryCatchBlock = exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.safeAccessor = exports.getFieldName = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.generateIndexFiles = exports.protoFilesToGenerate = void 0; | ||
const path = require("path"); | ||
@@ -269,2 +269,6 @@ const ts_poet_1 = require("ts-poet"); | ||
exports.maybeCheckIsNull = maybeCheckIsNull; | ||
function oneofValueName(fieldName, options) { | ||
return options.oneof === options_1.OneofOption.UNIONS ? fieldName : "value"; | ||
} | ||
exports.oneofValueName = oneofValueName; | ||
function withOrMaybeCheckIsNotNull(options, typeName) { | ||
@@ -271,0 +275,0 @@ return maybeCheckIsNotNull(options, typeName, "||"); |
{ | ||
"name": "ts-proto", | ||
"version": "1.179.0", | ||
"version": "1.180.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
399412
6877
1077