New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bufbuild/protoc-gen-es

Package Overview
Dependencies
Maintainers
6
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bufbuild/protoc-gen-es - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

6

dist/cjs/package.json
{
"name": "@bufbuild/protoc-gen-es",
"version": "0.1.1",
"version": "0.2.0",
"description": "Protocol Buffers code generator for ECMAScript",

@@ -23,6 +23,6 @@ "license": "Apache-2.0",

"dependencies": {
"@bufbuild/protoplugin": "0.1.1"
"@bufbuild/protoplugin": "0.2.0"
},
"peerDependencies": {
"@bufbuild/protobuf": "0.1.1"
"@bufbuild/protobuf": "0.2.0"
},

@@ -29,0 +29,0 @@ "peerDependenciesMeta": {

@@ -16,11 +16,19 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.declaration = void 0;
exports.generateDts = void 0;
const ecmascript_1 = require("@bufbuild/protoplugin/ecmascript");
const match_wkt_js_1 = require("./match-wkt.js");
exports.declaration = {
target: "dts",
extension: "_pb.d.ts",
generateEnum,
generateMessage,
};
function generateDts(schema) {
for (const file of schema.files) {
const f = schema.generateFile(file.name + "_pb.d.ts");
f.preamble(file);
for (const enumeration of file.enums) {
generateEnum(schema, f, enumeration);
}
for (const message of file.messages) {
generateMessage(schema, f, message);
}
// We do not generate anything for services, and we do not support extensions at this time
}
}
exports.generateDts = generateDts;
// prettier-ignore

@@ -27,0 +35,0 @@ function generateEnum(schema, f, enumeration) {

@@ -16,12 +16,20 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.generateFieldInfo = exports.javascript = void 0;
exports.generateFieldInfo = exports.generateJs = void 0;
const protobuf_1 = require("@bufbuild/protobuf");
const ecmascript_1 = require("@bufbuild/protoplugin/ecmascript");
const match_wkt_js_1 = require("./match-wkt.js");
exports.javascript = {
target: "js",
extension: "_pb.js",
generateEnum,
generateMessage,
};
function generateJs(schema) {
for (const file of schema.files) {
const f = schema.generateFile(file.name + "_pb.js");
f.preamble(file);
for (const enumeration of file.enums) {
generateEnum(schema, f, enumeration);
}
for (const message of file.messages) {
generateMessage(schema, f, message);
}
// We do not generate anything for services, and we do not support extensions at this time
}
}
exports.generateJs = generateJs;
// prettier-ignore

@@ -92,7 +100,7 @@ function generateEnum(schema, f, enumeration) {

}
switch (field.kind) {
case "scalar_field":
switch (field.fieldKind) {
case "scalar":
e.push(`kind: "scalar", T: `, field.scalar, ` /* ScalarType.`, protobuf_1.ScalarType[field.scalar], ` */, `);
break;
case "map_field":
case "map":
e.push(`kind: "map", K: `, field.mapKey, ` /* ScalarType.`, protobuf_1.ScalarType[field.mapKey], ` */, `);

@@ -111,6 +119,6 @@ switch (field.mapValue.kind) {

break;
case "message_field":
case "message":
e.push(`kind: "message", T: `, field.message, `, `);
break;
case "enum_field":
case "enum":
e.push(`kind: "enum", T: `, protoN, `.getEnumType(`, field.enum, `), `);

@@ -117,0 +125,0 @@ break;

@@ -22,6 +22,6 @@ "use strict";

const typeUrl = message.fields.find((f) => f.number == 1 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.STRING);
const value = message.fields.find((f) => f.number == 2 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.BYTES);

@@ -39,6 +39,6 @@ if (typeUrl && value) {

const seconds = message.fields.find((f) => f.number == 1 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.INT64);
const nanos = message.fields.find((f) => f.number == 2 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.INT32);

@@ -56,6 +56,6 @@ if (seconds && nanos) {

const seconds = message.fields.find((f) => f.number == 1 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.INT64);
const nanos = message.fields.find((f) => f.number == 2 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.INT32);

@@ -73,3 +73,3 @@ if (seconds && nanos) {

const fields = message.fields.find((f) => f.number == 1 && !f.repeated);
if ((fields === null || fields === void 0 ? void 0 : fields.kind) !== "map_field" ||
if ((fields === null || fields === void 0 ? void 0 : fields.fieldKind) !== "map" ||
fields.mapValue.kind !== "message" ||

@@ -84,3 +84,3 @@ fields.mapValue.message.typeName !== "google.protobuf.Value") {

const nullValue = message.fields.find((f) => f.number == 1 && f.oneof === kind);
if ((nullValue === null || nullValue === void 0 ? void 0 : nullValue.kind) !== "enum_field" ||
if ((nullValue === null || nullValue === void 0 ? void 0 : nullValue.fieldKind) !== "enum" ||
nullValue.enum.typeName !== "google.protobuf.NullValue") {

@@ -90,15 +90,15 @@ return undefined;

const numberValue = message.fields.find((f) => f.number == 2 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.DOUBLE &&
f.oneof === kind);
const stringValue = message.fields.find((f) => f.number == 3 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.STRING &&
f.oneof === kind);
const boolValue = message.fields.find((f) => f.number == 4 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.BOOL &&
f.oneof === kind);
const structValue = message.fields.find((f) => f.number == 5 && f.oneof === kind);
if ((structValue === null || structValue === void 0 ? void 0 : structValue.kind) !== "message_field" ||
if ((structValue === null || structValue === void 0 ? void 0 : structValue.fieldKind) !== "message" ||
structValue.message.typeName !== "google.protobuf.Struct") {

@@ -108,3 +108,3 @@ return undefined;

const listValue = message.fields.find((f) => f.number == 6 && f.oneof === kind);
if ((listValue === null || listValue === void 0 ? void 0 : listValue.kind) !== "message_field" ||
if ((listValue === null || listValue === void 0 ? void 0 : listValue.fieldKind) !== "message" ||
listValue.message.typeName !== "google.protobuf.ListValue") {

@@ -129,3 +129,3 @@ return undefined;

const values = message.fields.find((f) => f.number == 1 && f.repeated);
if ((values === null || values === void 0 ? void 0 : values.kind) != "message_field" ||
if ((values === null || values === void 0 ? void 0 : values.fieldKind) != "message" ||
values.message.typeName !== "google.protobuf.Value") {

@@ -138,3 +138,3 @@ break;

const paths = message.fields.find((f) => f.number == 1 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === protobuf_1.ScalarType.STRING &&

@@ -160,3 +160,3 @@ f.repeated);

}
if (value.kind !== "scalar_field") {
if (value.fieldKind !== "scalar") {
break;

@@ -163,0 +163,0 @@ }

@@ -20,3 +20,3 @@ "use strict";

const javascript_js_1 = require("./javascript.js");
const declaration_1 = require("./declaration");
const declaration_js_1 = require("./declaration.js");
const package_json_1 = require("../package.json");

@@ -26,17 +26,5 @@ exports.protocGenEs = (0, protoplugin_1.createEcmaScriptPlugin)({

version: `v${String(package_json_1.version)}`,
}, (schema) => {
const targets = [typescript_js_1.typescript, javascript_js_1.javascript, declaration_1.declaration].filter((gen) => schema.targets.includes(gen.target));
for (const target of targets) {
for (const file of schema.files) {
const f = schema.generateFile(file.name + target.extension);
f.preamble(file);
for (const enumeration of file.enums) {
target.generateEnum(schema, f, enumeration);
}
for (const message of file.messages) {
target.generateMessage(schema, f, message);
}
// We do not generate anything for services, and we do not support extensions at this time
}
}
generateTs: typescript_js_1.generateTs,
generateJs: javascript_js_1.generateJs,
generateDts: declaration_js_1.generateDts,
});

@@ -16,3 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.typescript = void 0;
exports.generateTs = void 0;
const protobuf_1 = require("@bufbuild/protobuf");

@@ -23,8 +23,16 @@ const ecmascript_1 = require("@bufbuild/protoplugin/ecmascript");

const ecmascript_2 = require("@bufbuild/protoplugin/ecmascript");
exports.typescript = {
target: "ts",
extension: "_pb.ts",
generateEnum,
generateMessage,
};
function generateTs(schema) {
for (const file of schema.files) {
const f = schema.generateFile(file.name + "_pb.ts");
f.preamble(file);
for (const enumeration of file.enums) {
generateEnum(schema, f, enumeration);
}
for (const message of file.messages) {
generateMessage(schema, f, message);
}
// We do not generate anything for services, and we do not support extensions at this time
}
}
exports.generateTs = generateTs;
// prettier-ignore

@@ -31,0 +39,0 @@ function generateEnum(schema, f, enumeration) {

{
"name": "@bufbuild/protoc-gen-es",
"version": "0.1.1",
"version": "0.2.0",
"description": "Protocol Buffers code generator for ECMAScript",

@@ -23,6 +23,6 @@ "license": "Apache-2.0",

"dependencies": {
"@bufbuild/protoplugin": "0.1.1"
"@bufbuild/protoplugin": "0.2.0"
},
"peerDependencies": {
"@bufbuild/protobuf": "0.1.1"
"@bufbuild/protobuf": "0.2.0"
},

@@ -29,0 +29,0 @@ "peerDependenciesMeta": {

@@ -127,1 +127,9 @@ # @bufbuild/protoc-gen-es

### `keep_empty_files=true`
By default, [protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-es)
(and all other plugins based on [@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin))
omit empty files from the plugin output. This option disables pruning of
empty files, to allow for smooth interoperation with Bazel and similar
tooling that requires all output files to be declared ahead of time.
Unless you use Bazel, it is very unlikely that you need this option.

@@ -21,3 +21,7 @@ // Copyright 2021-2022 Buf Technologies, Inc.

} from "@bufbuild/protobuf";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import type {
GeneratedFile,
Printable,
Schema,
} from "@bufbuild/protoplugin/ecmascript";
import {

@@ -31,8 +35,15 @@ getFieldTyping,

export const declaration = {
target: "dts",
extension: "_pb.d.ts",
generateEnum,
generateMessage,
} as const;
export function generateDts(schema: Schema) {
for (const file of schema.files) {
const f = schema.generateFile(file.name + "_pb.d.ts");
f.preamble(file);
for (const enumeration of file.enums) {
generateEnum(schema, f, enumeration);
}
for (const message of file.messages) {
generateMessage(schema, f, message);
}
// We do not generate anything for services, and we do not support extensions at this time
}
}

@@ -125,3 +136,3 @@ // prettier-ignore

f.print(makeJsDoc(field, " "));
const e: Parameters<typeof f.print> = [];
const e: Printable = [];
e.push(" ", localName(field));

@@ -128,0 +139,0 @@ const { typing, optional } = getFieldTyping(field, f);

@@ -17,3 +17,7 @@ // Copyright 2021-2022 Buf Technologies, Inc.

import { proto2, proto3, ScalarType } from "@bufbuild/protobuf";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import type {
GeneratedFile,
Printable,
Schema,
} from "@bufbuild/protoplugin/ecmascript";
import {

@@ -27,8 +31,15 @@ getFieldExplicitDefaultValue,

export const javascript = {
target: "js",
extension: "_pb.js",
generateEnum,
generateMessage,
} as const;
export function generateJs(schema: Schema) {
for (const file of schema.files) {
const f = schema.generateFile(file.name + "_pb.js");
f.preamble(file);
for (const enumeration of file.enums) {
generateEnum(schema, f, enumeration);
}
for (const message of file.messages) {
generateMessage(schema, f, message);
}
// We do not generate anything for services, and we do not support extensions at this time
}
}

@@ -95,3 +106,3 @@ // prettier-ignore

const protoN = schema.runtime[field.parent.file.syntax];
const e: Parameters<typeof f.print> = [];
const e: Printable = [];
e.push(" { no: ", field.number, `, name: "`, field.name, `", `);

@@ -101,7 +112,7 @@ if (field.jsonName !== undefined) {

}
switch (field.kind) {
case "scalar_field":
switch (field.fieldKind) {
case "scalar":
e.push(`kind: "scalar", T: `, field.scalar, ` /* ScalarType.`, ScalarType[field.scalar], ` */, `);
break;
case "map_field":
case "map":
e.push(`kind: "map", K: `, field.mapKey, ` /* ScalarType.`, ScalarType[field.mapKey], ` */, `);

@@ -120,6 +131,6 @@ switch (field.mapValue.kind) {

break;
case "message_field":
case "message":
e.push(`kind: "message", T: `, field.message, `, `);
break;
case "enum_field":
case "enum":
e.push(`kind: "enum", T: `, protoN, `.getEnumType(`, field.enum, `), `);

@@ -126,0 +137,0 @@ break;

@@ -40,3 +40,3 @@ // Copyright 2021-2022 Buf Technologies, Inc.

typeName: "google.protobuf.Struct";
fields: DescField & { kind: "map_field" };
fields: DescField & { fieldKind: "map" };
}

@@ -46,12 +46,12 @@ | {

kind: DescOneof;
nullValue: DescField & { kind: "enum_field" };
nullValue: DescField & { fieldKind: "enum" };
numberValue: DescField;
stringValue: DescField;
boolValue: DescField;
structValue: DescField & { kind: "message_field" };
listValue: DescField & { kind: "message_field" };
structValue: DescField & { fieldKind: "message" };
listValue: DescField & { fieldKind: "message" };
}
| {
typeName: "google.protobuf.ListValue";
values: DescField & { kind: "message_field" };
values: DescField & { fieldKind: "message" };
}

@@ -64,35 +64,35 @@ | {

typeName: "google.protobuf.DoubleValue";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
}
| {
typeName: "google.protobuf.FloatValue";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
}
| {
typeName: "google.protobuf.Int64Value";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
}
| {
typeName: "google.protobuf.UInt64Value";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
}
| {
typeName: "google.protobuf.Int32Value";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
}
| {
typeName: "google.protobuf.UInt32Value";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
}
| {
typeName: "google.protobuf.BoolValue";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
}
| {
typeName: "google.protobuf.StringValue";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
}
| {
typeName: "google.protobuf.BytesValue";
value: DescField & { kind: "scalar_field" };
value: DescField & { fieldKind: "scalar" };
};

@@ -106,3 +106,3 @@

f.number == 1 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.STRING

@@ -113,3 +113,3 @@ );

f.number == 2 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.BYTES

@@ -130,3 +130,3 @@ );

f.number == 1 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.INT64

@@ -137,3 +137,3 @@ );

f.number == 2 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.INT32

@@ -154,3 +154,3 @@ );

f.number == 1 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.INT64

@@ -161,3 +161,3 @@ );

f.number == 2 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.INT32

@@ -177,3 +177,3 @@ );

if (
fields?.kind !== "map_field" ||
fields?.fieldKind !== "map" ||
fields.mapValue.kind !== "message" ||

@@ -192,3 +192,3 @@ fields.mapValue.message.typeName !== "google.protobuf.Value"

if (
nullValue?.kind !== "enum_field" ||
nullValue?.fieldKind !== "enum" ||
nullValue.enum.typeName !== "google.protobuf.NullValue"

@@ -201,3 +201,3 @@ ) {

f.number == 2 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.DOUBLE &&

@@ -209,3 +209,3 @@ f.oneof === kind

f.number == 3 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.STRING &&

@@ -217,3 +217,3 @@ f.oneof === kind

f.number == 4 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.BOOL &&

@@ -226,3 +226,3 @@ f.oneof === kind

if (
structValue?.kind !== "message_field" ||
structValue?.fieldKind !== "message" ||
structValue.message.typeName !== "google.protobuf.Struct"

@@ -236,3 +236,3 @@ ) {

if (
listValue?.kind !== "message_field" ||
listValue?.fieldKind !== "message" ||
listValue.message.typeName !== "google.protobuf.ListValue"

@@ -259,3 +259,3 @@ ) {

if (
values?.kind != "message_field" ||
values?.fieldKind != "message" ||
values.message.typeName !== "google.protobuf.Value"

@@ -271,3 +271,3 @@ ) {

f.number == 1 &&
f.kind == "scalar_field" &&
f.fieldKind == "scalar" &&
f.scalar === ScalarType.STRING &&

@@ -296,3 +296,3 @@ f.repeated

}
if (value.kind !== "scalar_field") {
if (value.fieldKind !== "scalar") {
break;

@@ -299,0 +299,0 @@ }

@@ -16,30 +16,13 @@ // Copyright 2021-2022 Buf Technologies, Inc.

import { createEcmaScriptPlugin } from "@bufbuild/protoplugin";
import { typescript } from "./typescript.js";
import { javascript } from "./javascript.js";
import { declaration } from "./declaration";
import { generateTs } from "./typescript.js";
import { generateJs } from "./javascript.js";
import { generateDts } from "./declaration.js";
import { version } from "../package.json";
export const protocGenEs = createEcmaScriptPlugin(
{
name: "protoc-gen-es",
version: `v${String(version)}`,
},
(schema) => {
const targets = [typescript, javascript, declaration].filter((gen) =>
schema.targets.includes(gen.target)
);
for (const target of targets) {
for (const file of schema.files) {
const f = schema.generateFile(file.name + target.extension);
f.preamble(file);
for (const enumeration of file.enums) {
target.generateEnum(schema, f, enumeration);
}
for (const message of file.messages) {
target.generateMessage(schema, f, message);
}
// We do not generate anything for services, and we do not support extensions at this time
}
}
}
);
export const protocGenEs = createEcmaScriptPlugin({
name: "protoc-gen-es",
version: `v${String(version)}`,
generateTs,
generateJs,
generateDts,
});

@@ -22,3 +22,7 @@ // Copyright 2021-2022 Buf Technologies, Inc.

import { ScalarType } from "@bufbuild/protobuf";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import type {
GeneratedFile,
Printable,
Schema,
} from "@bufbuild/protoplugin/ecmascript";
import {

@@ -34,8 +38,15 @@ localName,

export const typescript = {
target: "ts",
extension: "_pb.ts",
generateEnum,
generateMessage,
} as const;
export function generateTs(schema: Schema) {
for (const file of schema.files) {
const f = schema.generateFile(file.name + "_pb.ts");
f.preamble(file);
for (const enumeration of file.enums) {
generateEnum(schema, f, enumeration);
}
for (const message of file.messages) {
generateMessage(schema, f, message);
}
// We do not generate anything for services, and we do not support extensions at this time
}
}

@@ -150,3 +161,3 @@ // prettier-ignore

f.print(makeJsDoc(field, " "));
const e: Parameters<typeof f.print> = [];
const e: Printable = [];
e.push(" ", localName(field));

@@ -153,0 +164,0 @@ const { defaultValue, typingInferrable } =

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