@bufbuild/protoplugin
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -23,4 +23,4 @@ "use strict"; | ||
*/ | ||
function findCustomScalarOption(desc, id, scalarType) { | ||
const reader = createBinaryReader(desc, id); | ||
function findCustomScalarOption(desc, extensionNumber, scalarType) { | ||
const reader = createBinaryReader(desc, extensionNumber); | ||
if (reader) { | ||
@@ -67,11 +67,14 @@ switch (scalarType) { | ||
/** | ||
* Returns the value of a custom message option for the given descriptor and ID. | ||
* The msgType param is then used to deserialize the message for returning to the caller. | ||
* Returns the value of a custom message option for the given descriptor and | ||
* extension number. | ||
* The msgType param is then used to deserialize the message for returning to | ||
* the caller. | ||
* | ||
* If no options are found, returns undefined. | ||
* | ||
* If the message option is unable to be read or deserialized, an error will be thrown. | ||
* If the message option is unable to be read or deserialized, an error will | ||
* be thrown. | ||
*/ | ||
function findCustomMessageOption(desc, id, msgType) { | ||
const reader = createBinaryReader(desc, id); | ||
function findCustomMessageOption(desc, extensionNumber, msgType) { | ||
const reader = createBinaryReader(desc, extensionNumber); | ||
if (reader) { | ||
@@ -91,14 +94,15 @@ try { | ||
/** | ||
* Returns the value of a custom enum option for the given descriptor and ID. | ||
* Returns the value of a custom enum option for the given descriptor and | ||
* extension number. | ||
* | ||
* If no options are found, returns undefined. | ||
*/ | ||
function findCustomEnumOption(desc, id) { | ||
return findCustomScalarOption(desc, id, protobuf_1.ScalarType.INT32); | ||
function findCustomEnumOption(desc, extensionNumber) { | ||
return findCustomScalarOption(desc, extensionNumber, protobuf_1.ScalarType.INT32); | ||
} | ||
exports.findCustomEnumOption = findCustomEnumOption; | ||
/** | ||
* Returns a binary reader for the given descriptor and field ID. | ||
* Returns a binary reader for the given descriptor and extension number. | ||
*/ | ||
function createBinaryReader(desc, id) { | ||
function createBinaryReader(desc, extensionNumber) { | ||
const opt = desc.proto.options; | ||
@@ -108,3 +112,3 @@ let reader = undefined; | ||
const unknownFields = protobuf_1.proto3.bin.listUnknownFields(opt); | ||
const field = unknownFields.find((f) => f.no === id); | ||
const field = unknownFields.find((f) => f.no === extensionNumber); | ||
if (field) { | ||
@@ -111,0 +115,0 @@ reader = new protobuf_1.BinaryReader(field.data); |
@@ -16,3 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findCustomEnumOption = exports.findCustomMessageOption = exports.findCustomScalarOption = exports.literalString = exports.makeJsDoc = exports.getFieldTyping = exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.createJsDocBlock = exports.localName = void 0; | ||
exports.findCustomEnumOption = exports.findCustomMessageOption = exports.findCustomScalarOption = exports.literalString = exports.makeJsDoc = exports.getFieldTyping = exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.createJsDocBlock = exports.reifyWkt = exports.localName = void 0; | ||
const protobuf_1 = require("@bufbuild/protobuf"); | ||
@@ -24,3 +24,3 @@ var target_js_1 = require("./target.js"); | ||
var import_symbol_js_1 = require("./import-symbol.js"); | ||
exports.localName = protobuf_1.codegenInfo.localName; | ||
exports.localName = protobuf_1.codegenInfo.localName, exports.reifyWkt = protobuf_1.codegenInfo.reifyWkt; | ||
var gencommon_js_1 = require("./gencommon.js"); | ||
@@ -27,0 +27,0 @@ Object.defineProperty(exports, "createJsDocBlock", { enumerable: true, get: function () { return gencommon_js_1.createJsDocBlock; } }); |
@@ -20,4 +20,4 @@ // Copyright 2021-2022 Buf Technologies, Inc. | ||
*/ | ||
export function findCustomScalarOption(desc, id, scalarType) { | ||
const reader = createBinaryReader(desc, id); | ||
export function findCustomScalarOption(desc, extensionNumber, scalarType) { | ||
const reader = createBinaryReader(desc, extensionNumber); | ||
if (reader) { | ||
@@ -63,11 +63,14 @@ switch (scalarType) { | ||
/** | ||
* Returns the value of a custom message option for the given descriptor and ID. | ||
* The msgType param is then used to deserialize the message for returning to the caller. | ||
* Returns the value of a custom message option for the given descriptor and | ||
* extension number. | ||
* The msgType param is then used to deserialize the message for returning to | ||
* the caller. | ||
* | ||
* If no options are found, returns undefined. | ||
* | ||
* If the message option is unable to be read or deserialized, an error will be thrown. | ||
* If the message option is unable to be read or deserialized, an error will | ||
* be thrown. | ||
*/ | ||
export function findCustomMessageOption(desc, id, msgType) { | ||
const reader = createBinaryReader(desc, id); | ||
export function findCustomMessageOption(desc, extensionNumber, msgType) { | ||
const reader = createBinaryReader(desc, extensionNumber); | ||
if (reader) { | ||
@@ -86,13 +89,14 @@ try { | ||
/** | ||
* Returns the value of a custom enum option for the given descriptor and ID. | ||
* Returns the value of a custom enum option for the given descriptor and | ||
* extension number. | ||
* | ||
* If no options are found, returns undefined. | ||
*/ | ||
export function findCustomEnumOption(desc, id) { | ||
return findCustomScalarOption(desc, id, ScalarType.INT32); | ||
export function findCustomEnumOption(desc, extensionNumber) { | ||
return findCustomScalarOption(desc, extensionNumber, ScalarType.INT32); | ||
} | ||
/** | ||
* Returns a binary reader for the given descriptor and field ID. | ||
* Returns a binary reader for the given descriptor and extension number. | ||
*/ | ||
function createBinaryReader(desc, id) { | ||
function createBinaryReader(desc, extensionNumber) { | ||
const opt = desc.proto.options; | ||
@@ -102,3 +106,3 @@ let reader = undefined; | ||
const unknownFields = proto3.bin.listUnknownFields(opt); | ||
const field = unknownFields.find((f) => f.no === id); | ||
const field = unknownFields.find((f) => f.no === extensionNumber); | ||
if (field) { | ||
@@ -105,0 +109,0 @@ reader = new BinaryReader(field.data); |
@@ -20,4 +20,4 @@ // Copyright 2021-2022 Buf Technologies, Inc. | ||
export {} from "./import-symbol.js"; | ||
export const { localName } = codegenInfo; | ||
export const { localName, reifyWkt } = codegenInfo; | ||
export { createJsDocBlock, getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, makeJsDoc, literalString, } from "./gencommon.js"; | ||
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js"; |
@@ -8,18 +8,22 @@ import type { AnyDesc } from "@bufbuild/protobuf"; | ||
*/ | ||
export declare function findCustomScalarOption<T extends ScalarType>(desc: AnyDesc, id: number, scalarType: T): ScalarValue<T> | undefined; | ||
export declare function findCustomScalarOption<T extends ScalarType>(desc: AnyDesc, extensionNumber: number, scalarType: T): ScalarValue<T> | undefined; | ||
/** | ||
* Returns the value of a custom message option for the given descriptor and ID. | ||
* The msgType param is then used to deserialize the message for returning to the caller. | ||
* Returns the value of a custom message option for the given descriptor and | ||
* extension number. | ||
* The msgType param is then used to deserialize the message for returning to | ||
* the caller. | ||
* | ||
* If no options are found, returns undefined. | ||
* | ||
* If the message option is unable to be read or deserialized, an error will be thrown. | ||
* If the message option is unable to be read or deserialized, an error will | ||
* be thrown. | ||
*/ | ||
export declare function findCustomMessageOption<T extends Message<T>>(desc: AnyDesc, id: number, msgType: MessageType<T>): T | undefined; | ||
export declare function findCustomMessageOption<T extends Message<T>>(desc: AnyDesc, extensionNumber: number, msgType: MessageType<T>): T | undefined; | ||
/** | ||
* Returns the value of a custom enum option for the given descriptor and ID. | ||
* Returns the value of a custom enum option for the given descriptor and | ||
* extension number. | ||
* | ||
* If no options are found, returns undefined. | ||
*/ | ||
export declare function findCustomEnumOption(desc: AnyDesc, id: number): number | undefined; | ||
export declare function findCustomEnumOption(desc: AnyDesc, extensionNumber: number): number | undefined; | ||
/** | ||
@@ -26,0 +30,0 @@ * ScalarValue is a conditional type that pairs a ScalarType value with its concrete type. |
@@ -6,4 +6,4 @@ export { Target } from "./target.js"; | ||
export { ImportSymbol } from "./import-symbol.js"; | ||
export declare const localName: typeof import("@bufbuild/protobuf/dist/types/private/names.js").localName; | ||
export declare const localName: typeof import("@bufbuild/protobuf/dist/types/private/names.js").localName, reifyWkt: typeof import("@bufbuild/protobuf/dist/types/private/reify-wkt.js").reifyWkt; | ||
export { createJsDocBlock, getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, makeJsDoc, literalString, } from "./gencommon.js"; | ||
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js"; |
{ | ||
"name": "@bufbuild/protoplugin", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"license": "(Apache-2.0 AND BSD-3-Clause)", | ||
@@ -38,3 +38,3 @@ "description": "Helps to create your own Protocol Buffers code generators.", | ||
"dependencies": { | ||
"@bufbuild/protobuf": "0.2.0", | ||
"@bufbuild/protobuf": "0.2.1", | ||
"@typescript/vfs": "^1.4.0", | ||
@@ -41,0 +41,0 @@ "typescript": "4.5.2" |
# @bufbuild/protoplugin | ||
This package helps to create your own code generator plugin. | ||
This package helps to create your own code generator plugin using the | ||
Protobuf-ES plugin framework. | ||
## Protocol Buffers for ECMAScript | ||
Protobuf-ES is a complete implementation of [Protocol Buffers](https://developers.google.com/protocol-buffers) in TypeScript, suitable for web browsers and Node.js. | ||
A complete implementation of [Protocol Buffers](https://developers.google.com/protocol-buffers) | ||
in TypeScript, suitable for web browsers and Node.js. | ||
Learn more at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es). | ||
In addition to a full Protobuf runtime library, it also provides a code generator | ||
`protoc-gen-es`, which utilizes a plugin framework to generate base types from | ||
your Protobuf schema. It is fully compatible with both Buf and protoc compilers. | ||
And now, you can write your own Protobuf-ES compatible plugins using this same | ||
plugin framework with the `@bufbuild/protoplugin` package. | ||
It is a complete implementation of [Protocol Buffers](https://developers.google.com/protocol-buffers) | ||
in TypeScript, suitable for web browsers and Node.js. | ||
With `@bufbuild/protoplugin`, you can generate your own TypeScript code tailored | ||
to your project or needs. You also have various options for producing | ||
JavaScript and TypeScript declaration files: | ||
For example, the following definition: | ||
- Exercise full control by writing your own JavaScript and declaration file | ||
generators in addition to TypeScript. | ||
```protobuf | ||
message Person { | ||
string name = 1; | ||
int32 id = 2; // Unique ID number for this person. | ||
string email = 3; | ||
} | ||
``` | ||
- Generate TypeScript files only and let the framework generate JavaScript and | ||
declaration files automatically using our internal TypeScript compiler. | ||
Is compiled to an ECMAScript class that can be used like this: | ||
- Generate TypeScript files only and bring your own TypeScript compiler, using | ||
it to generate JavaScript and declaration files with your own version of | ||
TypeScript and your own compiler options. | ||
```typescript | ||
let pete = new Person({ | ||
name: "pete", | ||
id: 123 | ||
}); | ||
With `protoplugin`, you have all the tools at your disposal to produce ECMAScript-compliant | ||
code. | ||
let bytes = pete.toBinary(); | ||
pete = Person.fromBinary(bytes); | ||
pete = Person.fromJsonString('{"name": "pete", "id": 123}'); | ||
``` | ||
Learn more at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es). | ||
Get started now with our [plugin documentation](https://github.com/bufbuild/protobuf-es/blob/main/docs/writing_plugins.md). |
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
134523
3415
33
+ Added@bufbuild/protobuf@0.2.1(transitive)
- Removed@bufbuild/protobuf@0.2.0(transitive)
Updated@bufbuild/protobuf@0.2.1