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

@bufbuild/protobuf

Package Overview
Dependencies
Maintainers
4
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bufbuild/protobuf - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

dist/cjs/package.json

71

dist/cjs/type-registry.js

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

/**
* TypeRegistry is a basic type registry
* TypeRegistry is a simple registry for all message, enum, or service types.
*/

@@ -27,17 +27,72 @@ class TypeRegistry {

}
/**
* Find a message type by its protobuf type name.
*/
findMessage(typeName) {
return this.messages[typeName];
}
/**
* Find an enum type by its protobuf type name.
*/
findEnum(typeName) {
return this.enums[typeName];
}
/**
* Find a service type by its protobuf type name.
*/
findService(typeName) {
return this.services[typeName];
}
/**
* Create a new TypeRegistry from the given types.
*/
static from(...types) {
const registry = new TypeRegistry();
for (const type of types) {
registry.add(type);
}
return registry;
}
/**
* @deprecated use TypeRegistry.from()
*/
static fromIterable(types) {
return TypeRegistry.from(...types);
}
/**
* @deprecated use TypeRegistry.from()
*/
static fromTypes(...types) {
return TypeRegistry.from(...types);
}
/**
* Add a type to the registry. For messages, the types used in message
* fields are added recursively. For services, the message types used
* for requests and responses are added recursively.
*/
add(type) {
if ("fields" in type) {
this.messages[type.typeName] = type;
if (!this.findMessage(type.typeName)) {
this.messages[type.typeName] = type;
for (const field of type.fields.list()) {
if (field.kind == "message") {
this.add(field.T);
}
else if (field.kind == "map" && field.V.kind == "message") {
this.add(field.V.T);
}
else if (field.kind == "enum") {
this.add(field.T);
}
}
}
}
else if ("methods" in type) {
this.services[type.typeName] = type;
if (!this.findService(type.typeName)) {
this.services[type.typeName] = type;
for (const method of Object.values(type.methods)) {
this.add(method.I);
this.add(method.O);
}
}
}

@@ -48,13 +103,3 @@ else {

}
static fromIterable(types) {
const r = new TypeRegistry();
for (const t of types) {
r.add(t);
}
return r;
}
static fromTypes(...types) {
return TypeRegistry.fromIterable(types);
}
}
exports.TypeRegistry = TypeRegistry;

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

/**
* TypeRegistry is a basic type registry
* TypeRegistry is a simple registry for all message, enum, or service types.
*/

@@ -24,17 +24,72 @@ export class TypeRegistry {

}
/**
* Find a message type by its protobuf type name.
*/
findMessage(typeName) {
return this.messages[typeName];
}
/**
* Find an enum type by its protobuf type name.
*/
findEnum(typeName) {
return this.enums[typeName];
}
/**
* Find a service type by its protobuf type name.
*/
findService(typeName) {
return this.services[typeName];
}
/**
* Create a new TypeRegistry from the given types.
*/
static from(...types) {
const registry = new TypeRegistry();
for (const type of types) {
registry.add(type);
}
return registry;
}
/**
* @deprecated use TypeRegistry.from()
*/
static fromIterable(types) {
return TypeRegistry.from(...types);
}
/**
* @deprecated use TypeRegistry.from()
*/
static fromTypes(...types) {
return TypeRegistry.from(...types);
}
/**
* Add a type to the registry. For messages, the types used in message
* fields are added recursively. For services, the message types used
* for requests and responses are added recursively.
*/
add(type) {
if ("fields" in type) {
this.messages[type.typeName] = type;
if (!this.findMessage(type.typeName)) {
this.messages[type.typeName] = type;
for (const field of type.fields.list()) {
if (field.kind == "message") {
this.add(field.T);
}
else if (field.kind == "map" && field.V.kind == "message") {
this.add(field.V.T);
}
else if (field.kind == "enum") {
this.add(field.T);
}
}
}
}
else if ("methods" in type) {
this.services[type.typeName] = type;
if (!this.findService(type.typeName)) {
this.services[type.typeName] = type;
for (const method of Object.values(type.methods)) {
this.add(method.I);
this.add(method.O);
}
}
}

@@ -45,12 +100,2 @@ else {

}
static fromIterable(types) {
const r = new TypeRegistry();
for (const t of types) {
r.add(t);
}
return r;
}
static fromTypes(...types) {
return TypeRegistry.fromIterable(types);
}
}

@@ -8,2 +8,5 @@ import type { MessageType } from "./message-type.js";

export interface IMessageTypeRegistry {
/**
* Find a message type by its protobuf type name.
*/
findMessage(typeName: string): MessageType | undefined;

@@ -15,2 +18,5 @@ }

export interface IEnumTypeRegistry {
/**
* Find an enum type by its protobuf type name.
*/
findEnum(typeName: string): EnumType | undefined;

@@ -22,6 +28,9 @@ }

export interface IServiceTypeRegistry {
/**
* Find a service type by its protobuf type name.
*/
findService(typeName: string): ServiceType | undefined;
}
/**
* TypeRegistry is a basic type registry
* TypeRegistry is a simple registry for all message, enum, or service types.
*/

@@ -32,8 +41,32 @@ export declare class TypeRegistry implements IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry {

private readonly services;
/**
* Find a message type by its protobuf type name.
*/
findMessage(typeName: string): MessageType | undefined;
/**
* Find an enum type by its protobuf type name.
*/
findEnum(typeName: string): EnumType | undefined;
/**
* Find a service type by its protobuf type name.
*/
findService(typeName: string): ServiceType | undefined;
private add;
/**
* Create a new TypeRegistry from the given types.
*/
static from(...types: Array<MessageType | EnumType | ServiceType>): TypeRegistry;
/**
* @deprecated use TypeRegistry.from()
*/
static fromIterable(types: Iterable<MessageType>): TypeRegistry;
/**
* @deprecated use TypeRegistry.from()
*/
static fromTypes(...types: MessageType[]): TypeRegistry;
/**
* Add a type to the registry. For messages, the types used in message
* fields are added recursively. For services, the message types used
* for requests and responses are added recursively.
*/
add(type: MessageType | EnumType | ServiceType): void;
}

6

package.json
{
"name": "@bufbuild/protobuf",
"version": "0.0.4",
"version": "0.0.5",
"license": "(Apache-2.0 AND BSD-3-Clause)",

@@ -15,3 +15,3 @@ "description": "A complete implementation of protocol buffers in TypeScript, suitable for web browsers and Node.js.",

"build": "npm run build:cjs && npm run build:esm+types",
"build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs",
"build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm+types": "npx tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"

@@ -27,3 +27,3 @@ },

"devDependencies": {
"typescript": "^4.6.4"
"typescript": "^4.7.3"
},

@@ -30,0 +30,0 @@ "files": [

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