Option Descriptors from the Packages
Applies to 1.3.0. Optional: projects that keep generating their own copies keep working.
Does this apply to you?
Only if your project generates code for Connectum's own option protos — its gen/ directory holds connectum/auth/v1/options_pb.ts or connectum/events/v1/options_pb.ts. That is the case for projects created with connectum init --auth or --events before 1.3.0, and for projects that copied connectum/events/v1/options.proto into their proto tree.
Nothing breaks if you do nothing: Protobuf-ES matches an extension by the extended message's type name and the field number, so a local copy of the descriptors reads the same options as the package's. Adopting the change removes the duplicate generated code and makes your generated files use the very descriptor objects that @connectum/auth and @connectum/events use.
What changed
@connectum/authexports@connectum/auth/gen/connectum/auth/v1/options_pb.js, and@connectum/eventsexports@connectum/events/gen/connectum/events/v1/options_pb.js. Each is the module the package itself uses at runtime.connectum init --auth/--eventsgenerates abuf.gen.yamlthat imports from those subpaths and no longer generates the option protos, and sets every@connectum/*dependency to one range of^1.3.0or higher.
Required changes
Move every
@connectum/*dependency to one 1.3.0-or-later range, and make sure@bufbuild/protoc-gen-esis 2.15.0 or later (map_importsfirst ships there; the scaffold declares^2.16.0). Keep a single@bufbuild/protobufversion.In
buf.gen.yaml, generate from your own protos only, and map the option-proto imports to the packages. Passmap_importstoprotoc-gen-esonly — Connectum's catalog plugin rejects options it does not know:yamlversion: v2 clean: true inputs: - directory: proto # only if your proto tree holds a copy of the events option proto exclude_paths: - proto/connectum/events/v1 plugins: - local: protoc-gen-es out: gen opt: - target=ts - import_extension=.ts - erasable_syntax=true - map_imports=connectum/auth/v1/:@connectum/auth/gen # with auth - map_imports=connectum/events/v1/:@connectum/events/gen # with eventsKeep a single input. With auth,
buf.yamlstill listsnode_modules/@connectum/auth/protoas a module, so buf can compile the imports; pinning the input toprotostops it from generating that module. One input per module would run each plugin once per module.If you also generate the service catalog, keep
strategy: allonprotoc-gen-connectum-catalog, asconnectum initwrites it. A single input does not change buf's defaultdirectorystrategy, which would run the plugin once per directory, and every run writes the samecatalog.gen.ts:yaml- local: protoc-gen-connectum-catalog strategy: all out: gen opt: - target=ts - import_extension=.tsRun
buf generate, thentypecheck. Withclean: true, buf empties the wholegen/output directory before generating — that is what removes the oldgen/connectum/files — so move anything you keep ingen/that these plugins do not regenerate.If your own code imported from
#gen/connectum/auth/v1/options_pb.tsor#gen/connectum/events/v1/options_pb.ts, import the same names from the package subpaths above:@connectum/auth/gen/connectum/auth/v1/options_pb.jsand@connectum/events/gen/connectum/events/v1/options_pb.jsexport every generated name, including the file descriptorsfile_connectum_auth_v1_optionsandfile_connectum_events_v1_options.@connectum/auth/protore-exports only the auth extensions and schemas (method_auth,service_auth,*Schema) next to the authorization helpers.
Verify
gen/contains noconnectum/auth/v1/options_pb.tsorconnectum/events/v1/options_pb.ts.- The generated files that use the options import
@connectum/auth/gen/connectum/auth/v1/options_pb.js/@connectum/events/gen/connectum/events/v1/options_pb.js. typecheckand your tests pass.