Skip to content

Commit

Permalink
Tweak which proto fields are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn committed Sep 11, 2024
1 parent 2649d78 commit 7b73c79
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 30 deletions.
6 changes: 3 additions & 3 deletions proto/common/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import "versionId/v1.proto";

message Common_1 {
// 32-byte random generated number
optional bytes docId = 1 [(required) = true];
bytes docId = 1 [(required) = true];
repeated VersionId_1 links = 2;
optional google.protobuf.Timestamp createdAt = 3 [(required) = true];
optional google.protobuf.Timestamp updatedAt = 4 [(required) = true];
google.protobuf.Timestamp createdAt = 3 [(required) = true];
google.protobuf.Timestamp updatedAt = 4 [(required) = true];
VersionId_1 originalVersionId = 5;
bool deleted = 6 [(required) = true];
}
Expand Down
10 changes: 5 additions & 5 deletions proto/coreOwnership/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ message CoreOwnership_1 {

Common_1 common = 1;

optional bytes authCoreId = 5 [(required) = true];
optional bytes configCoreId = 6 [(required) = true];
optional bytes dataCoreId = 7 [(required) = true];
optional bytes blobCoreId = 8 [(required) = true];
optional bytes blobIndexCoreId = 9 [(required) = true];
bytes authCoreId = 5 [(required) = true];
bytes configCoreId = 6 [(required) = true];
bytes dataCoreId = 7 [(required) = true];
bytes blobCoreId = 8 [(required) = true];
bytes blobIndexCoreId = 9 [(required) = true];
CoreSignatures coreSignatures = 10 [(required) = true];
bytes identitySignature = 11;

Expand Down
2 changes: 1 addition & 1 deletion proto/deviceInfo/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ message DeviceInfo_1 {
selfHostedServer = 4;
}

optional string name = 5 [(required) = true];
string name = 5 [(required) = true];
optional DeviceType deviceType = 6;
}
4 changes: 2 additions & 2 deletions proto/field/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ message Field_1 {

Common_1 common = 1;

optional string tagKey = 5 [(required) = true];
string tagKey = 5 [(required) = true];
enum Type {
type_unspecified = 0;
text = 1;
number = 2;
selectOne = 3;
selectMultiple = 4;
}
optional Type type = 6 [(required) = true];
Type type = 6 [(required) = true];
optional string label = 7 [(required) = true];
enum Appearance {
appearance_unspecified = 0;
Expand Down
6 changes: 3 additions & 3 deletions proto/icon/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ message Icon_1 {
x3 = 3;
}

optional PixelDensity pixelDensity = 1 [(required) = true];
PixelDensity pixelDensity = 1 [(required) = true];
}

message IconVariant {
Expand All @@ -43,8 +43,8 @@ message Icon_1 {
int32 index = 2;
}

optional Size size = 3 [(required) = true];
optional BlobVersionId blobVersionId = 4 [(required) = true];
Size size = 3 [(required) = true];
BlobVersionId blobVersionId = 4 [(required) = true];
}
repeated IconVariant variants = 3;
}
4 changes: 2 additions & 2 deletions proto/preset/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ message Preset_1 {

Common_1 common = 1;

optional string name = 5 [(required) = true];
string name = 5 [(required) = true];
repeated Geometry geometry = 6;
map<string, TagValue_1> tags = 7;
map<string, TagValue_1> addTags = 8;
map<string, TagValue_1> removeTags = 9;
repeated FieldRef fieldRefs = 10;
optional IconRef iconRef = 11;
repeated string terms = 12;
optional string color = 13 [(required) = true];
string color = 13 [(required) = true];

enum Geometry {
geometry_unspecified = 0;
Expand Down
2 changes: 1 addition & 1 deletion proto/role/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ message Role_1 {

Common_1 common = 1;

optional bytes roleId = 5 [(required) = true];
bytes roleId = 5 [(required) = true];
optional uint32 fromIndex = 6 [(required) = true];
}
8 changes: 4 additions & 4 deletions proto/translation/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ message Translation_1 {
Common_1 common = 1;
DocRef docRef = 2;

optional string propertyRef = 3 [(required) = true];
optional string languageCode = 4 [(required) = true];
optional string regionCode = 5 [(required) = true];
optional string message = 6 [(required) = true];
string propertyRef = 3 [(required) = true];
string languageCode = 4 [(required) = true];
string regionCode = 5 [(required) = true];
string message = 6 [(required) = true];

message DocRef {
bytes docId = 1;
Expand Down
27 changes: 18 additions & 9 deletions src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const convertField: ConvertFunction<'field'> = (message, versionObj) => {
const { common, schemaVersion, tagKey, type, label, ...rest } = message
const jsonSchemaCommon = convertCommon(common, versionObj)
ensure(tagKey, 'field', 'tagKey')
ensure(type, 'field', 'type')
ensure(type !== 'type_unspecified', 'field', 'type')
return {
...jsonSchemaCommon,
...rest,
Expand Down Expand Up @@ -196,7 +196,7 @@ export const convertPreset: ConvertFunction<'preset'> = (

export const convertRole: ConvertFunction<'role'> = (message, versionObj) => {
const { common, schemaVersion, fromIndex, roleId, ...rest } = message
ensure(roleId?.length, 'role', 'roleId')
ensure(roleId.length, 'role', 'roleId')
ensure(typeof fromIndex === 'number', 'role', 'fromIndex')
const jsonSchemaCommon = convertCommon(common, versionObj)
return {
Expand Down Expand Up @@ -237,11 +237,11 @@ export const convertCoreOwnership: ConvertFunction<'coreOwnership'> = (
...rest
} = message
ensure(coreSignatures, 'coreOwnership', 'coreSignatures')
ensure(authCoreId?.byteLength, 'coreOwnership', 'authCoreId')
ensure(configCoreId?.byteLength, 'coreOwnership', 'configCoreId')
ensure(dataCoreId?.byteLength, 'coreOwnership', 'dataCoreId')
ensure(blobCoreId?.byteLength, 'coreOwnership', 'blobCoreId')
ensure(blobIndexCoreId?.byteLength, 'coreOwnership', 'blobIndexCoreId')
ensure(authCoreId.byteLength, 'coreOwnership', 'authCoreId')
ensure(configCoreId.byteLength, 'coreOwnership', 'configCoreId')
ensure(dataCoreId.byteLength, 'coreOwnership', 'dataCoreId')
ensure(blobCoreId.byteLength, 'coreOwnership', 'blobCoreId')
ensure(blobIndexCoreId.byteLength, 'coreOwnership', 'blobIndexCoreId')
const jsonSchemaCommon = convertCommon(common, versionObj)
return {
...jsonSchemaCommon,
Expand Down Expand Up @@ -328,7 +328,11 @@ function convertIconVariant(
): Icon['variants'][number] {
if (variant.variant?.$case === 'pngIcon') {
const { pixelDensity } = variant.variant.pngIcon
ensure(pixelDensity, 'icon.variants[].pngIcon', 'pixelDensity')
ensure(
pixelDensity !== 'pixel_density_unspecified',
'icon.variants[].pngIcon',
'pixelDensity'
)
return convertIconVariantPng({ ...variant, pixelDensity })
} else if (variant.variant?.$case === 'svgIcon') {
return convertIconVariantSvg(variant)
Expand Down Expand Up @@ -439,7 +443,12 @@ function convertCommon(
common: ProtoTypesWithSchemaInfo['common'],
versionObj: VersionIdObject
): Omit<MapeoCommon, 'schemaName'> {
if (!common || !common.docId || !common.createdAt || !common.updatedAt) {
if (
!common ||
!common.docId.byteLength ||
!common.createdAt ||
!common.updatedAt
) {
throw new Error('Missing required common properties')
}

Expand Down

0 comments on commit 7b73c79

Please sign in to comment.