@protobuf-ts/plugin-framework
Advanced tools
Comparing version 2.0.0-alpha.27 to 2.0.0-alpha.28
@@ -38,6 +38,6 @@ "use strict"; | ||
* | ||
* Parameters: | ||
* Options: | ||
* | ||
* Use the `parseParameters()` method the parse the parameters | ||
* of a `CodeGeneratorRequest` to a map of flags. Parameters are | ||
* Use the `parseOptions()` method the parse the parameter | ||
* of a `CodeGeneratorRequest` to a map of flags. Options are | ||
* validated and usage is generated on error. | ||
@@ -74,2 +74,3 @@ * | ||
} | ||
this.setBlockingStdout(); | ||
process.stdout.write(plugin_1.CodeGeneratorResponse.toBinary(response)); | ||
@@ -88,5 +89,5 @@ } | ||
} | ||
parseParameters(spec, parameter) { | ||
parseOptions(spec, parameter) { | ||
var _a, _b, _c, _d; | ||
this.validateParameterSpec(spec); | ||
this.validateOptionsSpec(spec); | ||
let given = parameter ? parameter.split(',') : []; | ||
@@ -96,3 +97,3 @@ let known = Object.keys(spec); | ||
if (excess.length > 0) { | ||
this.throwParameterError(spec, `Parameter "${excess.join('", "')}" not recognized.`); | ||
this.throwOptionError(spec, `Option "${excess.join('", "')}" not recognized.`); | ||
} | ||
@@ -103,7 +104,7 @@ for (let [key, val] of Object.entries(spec)) { | ||
if (missing.length > 0) { | ||
this.throwParameterError(spec, `Parameter "${key}" requires parameter "${missing.join('", "')}" to be set.`); | ||
this.throwOptionError(spec, `Option "${key}" requires option "${missing.join('", "')}" to be set.`); | ||
} | ||
let excess = (_d = (_c = val.excludes) === null || _c === void 0 ? void 0 : _c.filter(i => given.includes(i))) !== null && _d !== void 0 ? _d : []; | ||
if (excess.length > 0) { | ||
this.throwParameterError(spec, `If parameter "${key}" is set, parameter "${excess.join('", "')}" cannot be set.`); | ||
this.throwOptionError(spec, `If option "${key}" is set, option "${excess.join('", "')}" cannot be set.`); | ||
} | ||
@@ -118,7 +119,7 @@ } | ||
} | ||
throwParameterError(spec, error) { | ||
throwOptionError(spec, error) { | ||
let text = ''; | ||
text += error + '\n'; | ||
text += `\n`; | ||
text += `Available parameters:\n`; | ||
text += `Available options:\n`; | ||
text += `\n`; | ||
@@ -136,3 +137,3 @@ for (let [key, val] of Object.entries(spec)) { | ||
} | ||
validateParameterSpec(spec) { | ||
validateOptionsSpec(spec) { | ||
var _a, _b; | ||
@@ -197,3 +198,14 @@ let known = Object.keys(spec); | ||
} | ||
setBlockingStdout() { | ||
// Fixes https://github.com/timostamm/protobuf-ts/issues/134 | ||
// Node is buffering chunks to stdout, meaning that for big generated | ||
// files the CodeGeneratorResponse will not reach protoc completely. | ||
// To fix this, we set stdout to block using the internal private | ||
// method setBlocking(true) | ||
const stdoutHandle = process.stdout._handle; | ||
if (stdoutHandle) { | ||
stdoutHandle.setBlocking(true); | ||
} | ||
} | ||
} | ||
exports.PluginBase = PluginBase; |
@@ -35,6 +35,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
* | ||
* Parameters: | ||
* Options: | ||
* | ||
* Use the `parseParameters()` method the parse the parameters | ||
* of a `CodeGeneratorRequest` to a map of flags. Parameters are | ||
* Use the `parseOptions()` method the parse the parameter | ||
* of a `CodeGeneratorRequest` to a map of flags. Options are | ||
* validated and usage is generated on error. | ||
@@ -71,2 +71,3 @@ * | ||
} | ||
this.setBlockingStdout(); | ||
process.stdout.write(CodeGeneratorResponse.toBinary(response)); | ||
@@ -85,5 +86,5 @@ } | ||
} | ||
parseParameters(spec, parameter) { | ||
parseOptions(spec, parameter) { | ||
var _a, _b, _c, _d; | ||
this.validateParameterSpec(spec); | ||
this.validateOptionsSpec(spec); | ||
let given = parameter ? parameter.split(',') : []; | ||
@@ -93,3 +94,3 @@ let known = Object.keys(spec); | ||
if (excess.length > 0) { | ||
this.throwParameterError(spec, `Parameter "${excess.join('", "')}" not recognized.`); | ||
this.throwOptionError(spec, `Option "${excess.join('", "')}" not recognized.`); | ||
} | ||
@@ -100,7 +101,7 @@ for (let [key, val] of Object.entries(spec)) { | ||
if (missing.length > 0) { | ||
this.throwParameterError(spec, `Parameter "${key}" requires parameter "${missing.join('", "')}" to be set.`); | ||
this.throwOptionError(spec, `Option "${key}" requires option "${missing.join('", "')}" to be set.`); | ||
} | ||
let excess = (_d = (_c = val.excludes) === null || _c === void 0 ? void 0 : _c.filter(i => given.includes(i))) !== null && _d !== void 0 ? _d : []; | ||
if (excess.length > 0) { | ||
this.throwParameterError(spec, `If parameter "${key}" is set, parameter "${excess.join('", "')}" cannot be set.`); | ||
this.throwOptionError(spec, `If option "${key}" is set, option "${excess.join('", "')}" cannot be set.`); | ||
} | ||
@@ -115,7 +116,7 @@ } | ||
} | ||
throwParameterError(spec, error) { | ||
throwOptionError(spec, error) { | ||
let text = ''; | ||
text += error + '\n'; | ||
text += `\n`; | ||
text += `Available parameters:\n`; | ||
text += `Available options:\n`; | ||
text += `\n`; | ||
@@ -133,3 +134,3 @@ for (let [key, val] of Object.entries(spec)) { | ||
} | ||
validateParameterSpec(spec) { | ||
validateOptionsSpec(spec) { | ||
var _a, _b; | ||
@@ -194,2 +195,13 @@ let known = Object.keys(spec); | ||
} | ||
setBlockingStdout() { | ||
// Fixes https://github.com/timostamm/protobuf-ts/issues/134 | ||
// Node is buffering chunks to stdout, meaning that for big generated | ||
// files the CodeGeneratorResponse will not reach protoc completely. | ||
// To fix this, we set stdout to block using the internal private | ||
// method setBlocking(true) | ||
const stdoutHandle = process.stdout._handle; | ||
if (stdoutHandle) { | ||
stdoutHandle.setBlocking(true); | ||
} | ||
} | ||
} |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import { GeneratedFile } from "./generated-file"; | ||
export declare type ParameterSpec = { | ||
export declare type OptionsSpec = { | ||
[key: string]: { | ||
@@ -13,3 +13,3 @@ description: string; | ||
}; | ||
export declare type ResolvedParameters<T extends ParameterSpec> = { | ||
export declare type ResolvedOptions<T extends OptionsSpec> = { | ||
[P in keyof T]: boolean; | ||
@@ -39,6 +39,6 @@ }; | ||
* | ||
* Parameters: | ||
* Options: | ||
* | ||
* Use the `parseParameters()` method the parse the parameters | ||
* of a `CodeGeneratorRequest` to a map of flags. Parameters are | ||
* Use the `parseOptions()` method the parse the parameter | ||
* of a `CodeGeneratorRequest` to a map of flags. Options are | ||
* validated and usage is generated on error. | ||
@@ -65,8 +65,9 @@ * | ||
protected getSupportedFeatures(): CodeGeneratorResponse_Feature[]; | ||
protected parseParameters<T extends ParameterSpec>(spec: T, parameter: string | undefined): ResolvedParameters<T>; | ||
private throwParameterError; | ||
private validateParameterSpec; | ||
protected parseOptions<T extends OptionsSpec>(spec: T, parameter: string | undefined): ResolvedOptions<T>; | ||
private throwOptionError; | ||
private validateOptionsSpec; | ||
protected readBytes(stream: ReadStream): Promise<Uint8Array>; | ||
protected createResponse(files: GeneratedFile[]): CodeGeneratorResponse; | ||
protected errorToString(error: any): string; | ||
private setBlockingStdout; | ||
} |
{ | ||
"name": "@protobuf-ts/plugin-framework", | ||
"version": "2.0.0-alpha.27", | ||
"version": "2.0.0-alpha.28", | ||
"description": "framework to create protoc plugins", | ||
@@ -36,6 +36,6 @@ "license": "(Apache-2.0 AND BSD-3-Clause)", | ||
"dependencies": { | ||
"@protobuf-ts/runtime": "^2.0.0-alpha.27", | ||
"@protobuf-ts/runtime": "^2.0.0-alpha.28", | ||
"typescript": ">=3.8.3 <4" | ||
}, | ||
"gitHead": "17619665a374d6f44962ba0b6f094637f7026c2e" | ||
"gitHead": "dfd0e333bc8ce4c2e045d443953ee7dcf7d50cca" | ||
} |
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
393146
9083