Skip to content

Commit

Permalink
Merge pull request #903 from samchon/features/encode
Browse files Browse the repository at this point in the history
Fix #901 - `protobuf.encode<T>()` be returned when union type comes.
  • Loading branch information
samchon committed Dec 11, 2023
2 parents 784aafb + d225492 commit 9e53cfc
Show file tree
Hide file tree
Showing 76 changed files with 893 additions and 404 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^2.5.13",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.3.4.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.5.tgz"
}
}
2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "D:\\github\\samchon\\typia\\typia-5.3.4.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.5.tgz"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "5.3.4",
"version": "5.3.5",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "5.3.4",
"version": "5.3.5",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -61,7 +61,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.3.4"
"typia": "5.3.5"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.4.0"
Expand Down
4 changes: 2 additions & 2 deletions src/programmers/protobuf/ProtobufEncodeProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export namespace ProtobufEncodeProgrammer {
: ExpressionFactory.isRequired(accessor);
return ts.factory.createIfStatement(
pred,
ts.factory.createReturnStatement(
ts.factory.createExpressionStatement(
ExpressionFactory.selfCall(
decode_object(project)(importer)(indexes!.get(spec.object)!)(
input,
Expand All @@ -758,7 +758,7 @@ export namespace ProtobufEncodeProgrammer {
),
i === array.length - 1
? remained.length
? ts.factory.createReturnStatement(
? ts.factory.createExpressionStatement(
ExpressionFactory.selfCall(
explore_objects(project)(importer)(level + 1)(index)(
input,
Expand Down
2 changes: 1 addition & 1 deletion test/build/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"lib": [
Expand Down
4 changes: 2 additions & 2 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"rimraf": "^5.0.5",
"ts-node": "^10.9.1",
"ts-patch": "^3.1.0",
"typescript": "^5.3.2"
"typescript": "^5.3.3"
},
"dependencies": {
"cli": "^1.0.1",
Expand All @@ -51,6 +51,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^2.5.13",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.3.4.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.5.tgz"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import typia, { tags } from "typia";

import { protobuf_equal_to } from "../../helpers/protobuf_equal_to";

export const test_issue_901_protobuf_encode_union_problem = () => {
const customer: Customer = typia.random<Customer>();
const encoded: Uint8Array = typia.protobuf.encode<Customer>(customer);
const decoded: Customer = typia.protobuf.decode<Customer>(encoded);

if (false === protobuf_equal_to("equal")(customer, decoded))
throw new Error(
"Bug on typia.protobuf.encode(): failed to encode the union type.",
);
};

interface Customer {
id: number & tags.Type<"int32">;
email: string & tags.Format<"email">;
name: string;
pet: Cat | Dog;
memo: Map<string, string>;
logins: Array<CustomerLogin> & tags.MinItems<1>;
}
interface Cat {
type: "cat";
name: string;
ribbon: boolean;
}
interface Dog {
type: "dog";
name: string;
hunt: boolean;
}
interface CustomerLogin {
success: boolean;
href: string & tags.Format<"url">;
referrer: string & tags.Format<"url">;
ip: string & (tags.Format<"ipv4"> | tags.Format<"ipv6">);
time: string & tags.Format<"date-time">;
}
Loading

0 comments on commit 9e53cfc

Please sign in to comment.