From 4cbaf8f0b4afd95729592c8c5ab51953000855ce Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Wed, 11 Sep 2024 19:33:39 +0000 Subject: [PATCH] Tweak which proto fields are optional --- proto/common/v1.proto | 6 +++--- proto/coreOwnership/v1.proto | 10 +++++----- proto/deviceInfo/v1.proto | 2 +- proto/field/v1.proto | 6 +++--- proto/icon/v1.proto | 8 ++++---- proto/preset/v1.proto | 4 ++-- proto/role/v1.proto | 2 +- proto/translation/v1.proto | 8 ++++---- src/lib/decode-conversions.ts | 27 ++++++++++++++++++--------- 9 files changed, 41 insertions(+), 32 deletions(-) diff --git a/proto/common/v1.proto b/proto/common/v1.proto index 0418b53..640a8d2 100644 --- a/proto/common/v1.proto +++ b/proto/common/v1.proto @@ -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]; } diff --git a/proto/coreOwnership/v1.proto b/proto/coreOwnership/v1.proto index 814fc68..4a78354 100644 --- a/proto/coreOwnership/v1.proto +++ b/proto/coreOwnership/v1.proto @@ -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; diff --git a/proto/deviceInfo/v1.proto b/proto/deviceInfo/v1.proto index 0d813f8..196764d 100644 --- a/proto/deviceInfo/v1.proto +++ b/proto/deviceInfo/v1.proto @@ -21,6 +21,6 @@ message DeviceInfo_1 { selfHostedServer = 4; } - optional string name = 5 [(required) = true]; + string name = 5 [(required) = true]; optional DeviceType deviceType = 6; } diff --git a/proto/field/v1.proto b/proto/field/v1.proto index 3d0d333..9792ac8 100644 --- a/proto/field/v1.proto +++ b/proto/field/v1.proto @@ -14,7 +14,7 @@ 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; @@ -22,8 +22,8 @@ message Field_1 { selectOne = 3; selectMultiple = 4; } - optional Type type = 6 [(required) = true]; - optional string label = 7 [(required) = true]; + Type type = 6 [(required) = true]; + string label = 7 [(required) = true]; enum Appearance { appearance_unspecified = 0; multiline = 1; diff --git a/proto/icon/v1.proto b/proto/icon/v1.proto index 6c6f82a..c6acfae 100644 --- a/proto/icon/v1.proto +++ b/proto/icon/v1.proto @@ -10,7 +10,7 @@ message Icon_1 { option (schemaName) = "icon"; Common_1 common = 1; - optional string name = 2 [(required) = true]; + string name = 2 [(required) = true]; message IconVariantSvg {} @@ -22,7 +22,7 @@ message Icon_1 { x3 = 3; } - optional PixelDensity pixelDensity = 1 [(required) = true]; + PixelDensity pixelDensity = 1 [(required) = true]; } message IconVariant { @@ -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; } diff --git a/proto/preset/v1.proto b/proto/preset/v1.proto index 949dbb5..85f3d50 100644 --- a/proto/preset/v1.proto +++ b/proto/preset/v1.proto @@ -15,7 +15,7 @@ message Preset_1 { Common_1 common = 1; - optional string name = 5 [(required) = true]; + string name = 5 [(required) = true]; repeated Geometry geometry = 6; map tags = 7; map addTags = 8; @@ -23,7 +23,7 @@ message Preset_1 { 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; diff --git a/proto/role/v1.proto b/proto/role/v1.proto index 68e89d9..440013b 100644 --- a/proto/role/v1.proto +++ b/proto/role/v1.proto @@ -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]; } diff --git a/proto/translation/v1.proto b/proto/translation/v1.proto index 7813b29..3bbe5c4 100644 --- a/proto/translation/v1.proto +++ b/proto/translation/v1.proto @@ -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; diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 3bb02f5..af0376e 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -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, @@ -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 { @@ -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, @@ -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) @@ -439,7 +443,12 @@ function convertCommon( common: ProtoTypesWithSchemaInfo['common'], versionObj: VersionIdObject ): Omit { - if (!common || !common.docId || !common.createdAt || !common.updatedAt) { + if ( + !common || + !common.docId.byteLength || + !common.createdAt || + !common.updatedAt + ) { throw new Error('Missing required common properties') }