Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-proto

Package Overview
Dependencies
Maintainers
1
Versions
359
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-proto - npm Package Compare versions

Comparing version 1.164.2 to 1.165.0

67

build/generate-services.js

@@ -90,19 +90,28 @@ "use strict";

const maybeAbortSignal = options.useAbortSignal ? "abortSignal || undefined," : "";
let errorHandler;
if (options.rpcErrorHandler) {
errorHandler = (0, ts_poet_1.code) `
if (error instanceof Error && this.rpc.handleError) {
return Promise.reject(this.rpc.handleError(this.service, "${methodDesc.name}", error));
}
return Promise.reject(error);
`;
}
let encode = (0, ts_poet_1.code) `${rawInputType}.encode(request).finish()`;
let beforeRequest;
if (options.outputBeforeRequest) {
if (options.rpcBeforeRequest) {
beforeRequest = (0, ts_poet_1.code) `
if (this.rpc.beforeRequest) {
this.rpc.beforeRequest(request);
this.rpc.beforeRequest(this.service, "${methodDesc.name}", request);
}`;
}
let decode = (0, ts_poet_1.code) `data => ${rawOutputType}.decode(${Reader}.create(data))`;
if (options.outputAfterResponse) {
decode = (0, ts_poet_1.code) `data => {
let decode = (0, ts_poet_1.code) `${rawOutputType}.decode(${Reader}.create(data))`;
if (options.rpcAfterResponse) {
decode = (0, ts_poet_1.code) `
const response = ${rawOutputType}.decode(${Reader}.create(data));
if (this.rpc.afterResponse) {
this.rpc.afterResponse(response);
this.rpc.afterResponse(this.service, "${methodDesc.name}", response);
}
return response;
}`;
`;
}

@@ -120,15 +129,9 @@ // if (options.useDate && rawOutputType.toString().includes("Timestamp")) {

}
const returnStatement = createDefaultServiceReturn(ctx, methodDesc, decode, errorHandler);
let returnVariable;
if (options.returnObservable || methodDesc.serverStreaming) {
returnVariable = "result";
if (options.useAsyncIterable) {
decode = (0, ts_poet_1.code) `${rawOutputType}.decodeTransform(result)`;
}
else {
decode = (0, ts_poet_1.code) `result.pipe(${(0, ts_poet_1.imp)("map@rxjs/operators")}(${decode}))`;
}
}
else {
returnVariable = "promise";
decode = (0, ts_poet_1.code) `promise.then(${decode})`;
}

@@ -160,6 +163,29 @@ let rpcMethod;

);
return ${decode};
return ${returnStatement};
}
`;
}
function createDefaultServiceReturn(ctx, methodDesc, decode, errorHandler) {
const { options } = ctx;
const rawOutputType = (0, types_1.responseType)(ctx, methodDesc, { keepValueType: true });
if (options.returnObservable || methodDesc.serverStreaming) {
if (options.useAsyncIterable) {
return (0, ts_poet_1.code) `${rawOutputType}.decodeTransform(result)`;
}
else {
return (0, ts_poet_1.code) `result.pipe(${(0, ts_poet_1.imp)("map@rxjs/operators")}(data => ${decode}))`;
}
}
if (errorHandler) {
let tryBlock = decode;
if (!options.rpcAfterResponse) {
tryBlock = (0, ts_poet_1.code) `return ${decode}`;
}
return (0, ts_poet_1.code) `promise.then(data => { ${(0, utils_1.tryCatchBlock)(tryBlock, (0, ts_poet_1.code) `return Promise.reject(error);`)}}).catch((error) => { ${errorHandler} })`;
}
else if (options.rpcAfterResponse) {
return (0, ts_poet_1.code) `promise.then(data => { ${decode} } )`;
}
return (0, ts_poet_1.code) `promise.then(data => ${decode})`;
}
function generateServiceClientImpl(ctx, fileDesc, serviceDesc) {

@@ -308,8 +334,11 @@ const { options } = ctx;

const additionalMethods = [];
if (options.outputBeforeRequest) {
additionalMethods.push((0, ts_poet_1.code) `beforeRequest?<T extends { [k in keyof T]: unknown }>(request: T): void;`);
if (options.rpcBeforeRequest) {
additionalMethods.push((0, ts_poet_1.code) `beforeRequest?<T extends { [k in keyof T]: unknown }>(service: string, method: string, request: T): void;`);
}
if (options.outputAfterResponse) {
additionalMethods.push((0, ts_poet_1.code) `afterResponse?<T extends { [k in keyof T]: unknown }>(response: T): void;`);
if (options.rpcAfterResponse) {
additionalMethods.push((0, ts_poet_1.code) `afterResponse?<T extends { [k in keyof T]: unknown }>(service: string, method: string, response: T): void;`);
}
if (options.rpcErrorHandler) {
additionalMethods.push((0, ts_poet_1.code) `handleError?(service: string, method: string, error: Error): Error;`);
}
if (hasStreamingMethods) {

@@ -316,0 +345,0 @@ const observable = (0, types_1.observableType)(ctx, true);

@@ -96,4 +96,5 @@ "use strict";

M: {},
outputBeforeRequest: false,
outputAfterResponse: false,
rpcBeforeRequest: false,
rpcAfterResponse: false,
rpcErrorHandler: false,
};

@@ -187,4 +188,8 @@ }

}
if (options.outputBeforeRequest || options.outputAfterResponse) {
if (options.rpcBeforeRequest || options.rpcAfterResponse || options.rpcErrorHandler) {
const includesGeneric = options.outputServices.includes(ServiceOption.GENERIC);
options.outputServices = [ServiceOption.DEFAULT];
if (includesGeneric) {
options.outputServices.push(ServiceOption.GENERIC);
}
}

@@ -191,0 +196,0 @@ if (options.unrecognizedEnumValue) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.safeAccessor = exports.getFieldName = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.generateIndexFiles = exports.protoFilesToGenerate = void 0;
exports.tryCatchBlock = exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.safeAccessor = exports.getFieldName = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.generateIndexFiles = exports.protoFilesToGenerate = void 0;
const path = require("path");

@@ -246,1 +246,9 @@ const ts_poet_1 = require("ts-poet");

exports.impProto = impProto;
function tryCatchBlock(tryBlock, handleErrorBlock) {
return (0, ts_poet_1.code) `try {
${tryBlock}
} catch (error) {
${handleErrorBlock}
}`;
}
exports.tryCatchBlock = tryCatchBlock;
{
"name": "ts-proto",
"version": "1.164.2",
"version": "1.165.0",
"description": "",

@@ -18,3 +18,3 @@ "main": "build/plugin.js",

"bin2ts": "docker compose run --rm protoc codegen.sh",
"test": "yarn jest -c jest.config.js --maxWorkers=2",
"test": "yarn jest -c jest.config.js",
"tsc:check": "./tsc-check.sh tsconfig.json tests/tsconfig.json integration/tsconfig.json integration/tsconfig.proto.json protos/tsconfig.json",

@@ -21,0 +21,0 @@ "format": "prettier --write {src,tests}/**/*.ts integration/*.ts",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc