Skip to content

Commit

Permalink
Fix number protobuf serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
steida committed Dec 10, 2023
1 parent 69c7d85 commit 33974aa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
5 changes: 1 addition & 4 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
}
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/curvy-turtles-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@evolu/common": patch
---

Fix number protobuf serialization
2 changes: 1 addition & 1 deletion packages/evolu-common/protobuf/Protobuf.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ message MessageContent {
string column = 3;
oneof value {
string stringValue = 4;
int32 numberValue = 5;
string numberValue = 5;
bytes bytesValue = 6;
string jsonValue = 7;
};
Expand Down
6 changes: 3 additions & 3 deletions packages/evolu-common/src/Protobuf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export interface MessageContent {
}
| {
oneofKind: "numberValue";
/** @generated from protobuf field: int32 numberValue = 5; */
numberValue: number;
/** @generated from protobuf field: string numberValue = 5; */
numberValue: string;
}
| {
oneofKind: "bytesValue";
Expand Down Expand Up @@ -132,7 +132,7 @@ class MessageContent$Type extends MessageType<MessageContent> {
name: "numberValue",
kind: "scalar",
oneof: "value",
T: 5 /*ScalarType.INT32*/,
T: 9 /*ScalarType.STRING*/,
},
{
no: 6,
Expand Down
8 changes: 6 additions & 2 deletions packages/evolu-common/src/SyncWorker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as S from "@effect/schema/Schema";
import { concatBytes } from "@noble/ciphers/utils";
import { BinaryReader, BinaryWriter } from "@protobuf-ts/runtime";
import {
Expand Down Expand Up @@ -153,7 +154,10 @@ const valueToProtobuf = (value: Value): MessageContent["value"] => {
case "string":
return { oneofKind: "stringValue", stringValue: value };
case "number":
return { oneofKind: "numberValue", numberValue: value };
return {
oneofKind: "numberValue",
numberValue: S.encodeSync(S.NumberFromString)(value),
};
}
if (value == null) return { oneofKind: undefined };
if (Predicate.isUint8Array(value))
Expand All @@ -164,7 +168,7 @@ const valueToProtobuf = (value: Value): MessageContent["value"] => {
const valueFromProtobuf = (value: MessageContent["value"]): Value => {
switch (value.oneofKind) {
case "numberValue":
return value.numberValue;
return S.decodeSync(S.NumberFromString)(value.numberValue);
case "stringValue":
return value.stringValue;
case "bytesValue":
Expand Down

1 comment on commit 33974aa

@vercel
Copy link

@vercel vercel bot commented on 33974aa Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

evolu – ./

evolu.vercel.app
www.evolu.dev
evolu-git-main-evolu.vercel.app
evolu.dev
evolu-evolu.vercel.app

Please sign in to comment.