Comparing version 2.0.4 to 2.1.0
@@ -35,2 +35,7 @@ import { ToStringOpts } from "ts-poet/build/Code"; | ||
} | ||
export declare enum OutputSchemaOption { | ||
TRUE = "true", | ||
NO_FILE_DESCRIPTOR = "no-file-descriptor", | ||
CONST = "const" | ||
} | ||
export type Options = { | ||
@@ -73,3 +78,3 @@ context: boolean; | ||
exportCommonSymbols: boolean; | ||
outputSchema: boolean | "no-file-descriptor"; | ||
outputSchema: false | OutputSchemaOption[]; | ||
onlyTypes: boolean; | ||
@@ -76,0 +81,0 @@ emitImportedFiles: boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ServiceOption = exports.OneofOption = exports.EnvOption = exports.JsonTimestampOption = exports.DateOption = exports.LongOption = void 0; | ||
exports.OutputSchemaOption = exports.ServiceOption = exports.OneofOption = exports.EnvOption = exports.JsonTimestampOption = exports.DateOption = exports.LongOption = void 0; | ||
exports.defaultOptions = defaultOptions; | ||
@@ -47,2 +47,8 @@ exports.optionsFromParameter = optionsFromParameter; | ||
})(ServiceOption || (exports.ServiceOption = ServiceOption = {})); | ||
var OutputSchemaOption; | ||
(function (OutputSchemaOption) { | ||
OutputSchemaOption["TRUE"] = "true"; | ||
OutputSchemaOption["NO_FILE_DESCRIPTOR"] = "no-file-descriptor"; | ||
OutputSchemaOption["CONST"] = "const"; | ||
})(OutputSchemaOption || (exports.OutputSchemaOption = OutputSchemaOption = {})); | ||
function defaultOptions() { | ||
@@ -169,2 +175,9 @@ return { | ||
} | ||
// Handle outputSchema=true | ||
if (options.outputSchema === true) { | ||
options.outputSchema = []; | ||
} | ||
if (typeof options.outputSchema === "string") { | ||
options.outputSchema = [options.outputSchema]; | ||
} | ||
if (options.useDate === true) { | ||
@@ -171,0 +184,0 @@ // Treat useDate=true as DATE |
@@ -10,2 +10,3 @@ "use strict"; | ||
const wire_1 = require("@bufbuild/protobuf/wire"); | ||
const options_1 = require("./options"); | ||
const fileDescriptorProto = (0, ts_poet_1.imp)("FileDescriptorProto@ts-proto-descriptors"); | ||
@@ -22,2 +23,5 @@ const extensionCache = {}; | ||
}); | ||
const outputSchemaOptions = ctx.options.outputSchema ? ctx.options.outputSchema : []; | ||
const outputFileDescriptor = !outputSchemaOptions.includes(options_1.OutputSchemaOption.NO_FILE_DESCRIPTOR); | ||
const outputAsConst = outputSchemaOptions.includes(options_1.OutputSchemaOption.CONST); | ||
chunks.push((0, ts_poet_1.code) ` | ||
@@ -32,3 +36,3 @@ type ProtoMetaMessageOptions = { | ||
export interface ProtoMetadata { | ||
${ctx.options.outputSchema !== "no-file-descriptor" ? (0, ts_poet_1.code) `fileDescriptor: ${fileDescriptorProto};\n` : ""}references: { [key: string]: any }; | ||
${outputFileDescriptor ? (0, ts_poet_1.code) `fileDescriptor: ${fileDescriptorProto};\n` : ""}references: { [key: string]: any }; | ||
dependencies?: ProtoMetadata[]; | ||
@@ -112,3 +116,3 @@ options?: { | ||
'${service.name}': { | ||
options: ${serviceOptions}, | ||
${serviceOptions ? (0, ts_poet_1.code) `options: ${serviceOptions},` : ""} | ||
methods: {${(0, ts_poet_1.joinCode)(methodsOptions, { on: "," })}} | ||
@@ -139,3 +143,3 @@ } | ||
'${Enum.name}': { | ||
options: ${enumOptions}, | ||
${enumOptions ? (0, ts_poet_1.code) `options: ${enumOptions},` : ""} | ||
values: {${(0, ts_poet_1.joinCode)(valuesOptions, { on: "," })}} | ||
@@ -147,6 +151,6 @@ } | ||
chunks.push((0, ts_poet_1.code) ` | ||
export const ${(0, ts_poet_1.def)("protoMetadata")}: ProtoMetadata = { | ||
${ctx.options.outputSchema !== "no-file-descriptor" | ||
? (0, ts_poet_1.code) `fileDescriptor: ${fileDescriptorProto}.fromPartial(${descriptor}),\n` | ||
: ""}references: { ${(0, ts_poet_1.joinCode)(references, { on: "," })} }, | ||
export const ${(0, ts_poet_1.def)("protoMetadata")}${outputAsConst ? "" : ": ProtoMetadata"} = { | ||
${outputFileDescriptor ? (0, ts_poet_1.code) `fileDescriptor: ${descriptor},\n` : ""}references: { ${(0, ts_poet_1.joinCode)(references, { | ||
on: ",", | ||
})} }, | ||
dependencies: [${(0, ts_poet_1.joinCode)(dependencies, { on: "," })}], | ||
@@ -161,3 +165,3 @@ ${fileOptions || messagesOptions.length > 0 || servicesOptions.length > 0 || enumsOptions.length > 0 | ||
: ""} | ||
} | ||
}${outputAsConst ? " as const satisfies ProtoMetadata" : ""} | ||
`); | ||
@@ -164,0 +168,0 @@ return chunks; |
{ | ||
"name": "ts-proto", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/src/plugin.js", |
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
645491
12975
1110