Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2: Add mutable registry #898

Merged
merged 2 commits into from
Jun 21, 2024
Merged

V2: Add mutable registry #898

merged 2 commits into from
Jun 21, 2024

Conversation

timostamm
Copy link
Member

This PR adds a mutable registry:

import { createMutableRegistry } from "@bufbuild/protobuf";
import { MyMessageSchema } from "./gen/example_pb";

const registry = createMutableRegistry();

// Adds a message, enum, extension, or service descriptor to the registry
registry.add(MyMessageSchema);

// Removes a descriptor
registry.remove(MyMessageSchema);

registry.getMessage("MyMessage"); // undefined

Note that registries - mutable and immutable ones - also support composition:

import { createRegistry } from "@bufbuild/protobuf";
import { MyMessageSchema, file_example } from "./gen/example_pb";

// The variadic function accepts any number of arguments
const registry = createRegistry(
  MyMessageSchema, // Initialize with a message, enum, extension, or service descriptor
  file_example, // Passing a file descriptor adds all types defined in the Protobuf file
  otherRegistry, // Adds all types from the other registry
);

Closes #679.

@timostamm timostamm merged commit 5e19fc4 into v2 Jun 21, 2024
7 checks passed
@timostamm timostamm deleted the tstamm/mutable-registry branch June 21, 2024 14:06
@timostamm timostamm mentioned this pull request Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants