Skip to content

feat: add custom protons options for limiting list/map sizes #120

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

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: update option name
  • Loading branch information
achingbrain committed Oct 23, 2023
commit d0e3513872d658b4a0bc4530e14b2b4cb5df1dcc
4 changes: 2 additions & 2 deletions packages/protons-runtime/options.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
syntax = "proto3";
syntax = "proto2";

import "google/protobuf/descriptor.proto";

@@ -11,5 +11,5 @@ message ProtonsOptions {

// custom options available for use by protons
extend google.protobuf.FieldOptions {
optional ProtonsOptions protons_options = 1186;
optional ProtonsOptions options = 1186;
}
2 changes: 1 addition & 1 deletion packages/protons/src/index.ts
Original file line number Diff line number Diff line change
@@ -826,7 +826,7 @@ function defineModule (def: ClassDef, flags: Flags): ModuleDef {
fieldDef.repeated = fieldDef.rule === 'repeated'
fieldDef.optional = !fieldDef.repeated && fieldDef.options?.proto3_optional === true
fieldDef.map = fieldDef.keyType != null
fieldDef.lengthLimit = fieldDef.options?.['(protons.limit)']
fieldDef.lengthLimit = fieldDef.options?.['(protons.options).limit']
fieldDef.proto2Required = false

if (fieldDef.rule === 'required') {
4 changes: 2 additions & 2 deletions packages/protons/test/fixtures/protons-options.proto
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ syntax = "proto3";
import "protons-rutime/options.proto";

message MessageWithSizeLimitedRepeatedField {
repeated string repeatedField = 1 [(protons.limit) = 1];
repeated string repeatedField = 1 [(protons.options).limit = 1];
}

message MessageWithSizeLimitedMap {
map<string, string> mapField = 1 [(protons.limit) = 1];
map<string, string> mapField = 1 [(protons.options).limit = 1];
}