Skip to content

Commit

Permalink
Merge pull request #1334 from samchon/feat/protobuf
Browse files Browse the repository at this point in the history
Close #1234: completed `Sequence<N>` implementation for Protocol Buffer.
  • Loading branch information
samchon authored Oct 19, 2024
2 parents 88f8b87 + aa66555 commit 24c4ad9
Show file tree
Hide file tree
Showing 87 changed files with 2,494 additions and 602 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "../typia-7.0.0-dev.20241019.tgz"
"typia": "../typia-7.0.0-dev.20241020.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": "../typia-7.0.0-dev.20241019.tgz"
"typia": "../typia-7.0.0-dev.20241020.tgz"
}
}
27 changes: 27 additions & 0 deletions errors/src/protobuf/error_protobuf_sequence_property_duplicated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import typia, { tags } from "typia";

interface IPointer<T> {
value: T;
}
interface Something {
id: string & tags.Sequence<1>;
age: number & tags.Sequence<1>;
}

// MESSAGE
typia.protobuf.message<Something>();
typia.protobuf.message<IPointer<Something>>();
typia.protobuf.message<IPointer<Something[]>>();
typia.protobuf.message<IPointer<Map<string, Something>>>();

// DECODE
typia.protobuf.createDecode<Something>();
typia.protobuf.createDecode<IPointer<Something>>();
typia.protobuf.createDecode<IPointer<Something[]>>();
typia.protobuf.createDecode<IPointer<Map<string, Something>>>();

// ENCODE
typia.protobuf.createEncode<Something>();
typia.protobuf.createEncode<IPointer<Something>>();
typia.protobuf.createEncode<IPointer<Something[]>>();
typia.protobuf.createEncode<IPointer<Map<string, Something>>>();
32 changes: 32 additions & 0 deletions errors/src/protobuf/error_protobuf_sequence_union_duplicated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import typia, { tags } from "typia";

interface IPointer<T> {
value: T;
}
interface Something {
id:
| (number & tags.Type<"uint32"> & tags.Sequence<1>)
| (number & tags.Type<"double"> & tags.Sequence<2>)
| (string & tags.Sequence<3>);
sex:
| (number & tags.Type<"uint32"> & tags.Sequence<4>)
| (string & tags.Sequence<3>);
}

// MESSAGE
typia.protobuf.message<Something>();
typia.protobuf.message<IPointer<Something>>();
typia.protobuf.message<IPointer<Something[]>>();
typia.protobuf.message<IPointer<Map<string, Something>>>();

// DECODE
typia.protobuf.createDecode<Something>();
typia.protobuf.createDecode<IPointer<Something>>();
typia.protobuf.createDecode<IPointer<Something[]>>();
typia.protobuf.createDecode<IPointer<Map<string, Something>>>();

// ENCODE
typia.protobuf.createEncode<Something>();
typia.protobuf.createEncode<IPointer<Something>>();
typia.protobuf.createEncode<IPointer<Something[]>>();
typia.protobuf.createEncode<IPointer<Map<string, Something>>>();
29 changes: 29 additions & 0 deletions errors/src/protobuf/error_protobuf_sequence_union_omitted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import typia, { tags } from "typia";

interface IPointer<T> {
value: T;
}
interface Something {
id:
| (number & tags.Type<"uint32"> & tags.Sequence<1>)
| (number & tags.Type<"double"> & tags.Sequence<2>)
| string;
}

// MESSAGE
typia.protobuf.message<Something>();
typia.protobuf.message<IPointer<Something>>();
typia.protobuf.message<IPointer<Something[]>>();
typia.protobuf.message<IPointer<Map<string, Something>>>();

// DECODE
typia.protobuf.createDecode<Something>();
typia.protobuf.createDecode<IPointer<Something>>();
typia.protobuf.createDecode<IPointer<Something[]>>();
typia.protobuf.createDecode<IPointer<Map<string, Something>>>();

// ENCODE
typia.protobuf.createEncode<Something>();
typia.protobuf.createEncode<IPointer<Something>>();
typia.protobuf.createEncode<IPointer<Something[]>>();
typia.protobuf.createEncode<IPointer<Map<string, Something>>>();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "7.0.0-dev.20241019",
"version": "7.0.0-dev.20241020",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand All @@ -20,6 +20,7 @@
"-------------------------------------------------": "",
"build": "rimraf lib && tsc && rollup -c",
"dev": "tsc --project tsconfig.test.json --watch",
"dev:errors": "tsc --project tsconfig.errors.json --watch",
"eslint": "eslint ./**/*.ts",
"eslint:fix": "eslint ./**/*.ts --fix",
"prettier": "prettier src --write",
Expand Down
5 changes: 3 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": "7.0.0-dev.20241019",
"version": "7.0.0-dev.20241020",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand All @@ -16,6 +16,7 @@
"-------------------------------------------------": "",
"build": "rimraf lib && tsc && rollup -c",
"dev": "tsc --project tsconfig.test.json --watch",
"dev:errors": "tsc --project tsconfig.errors.json --watch",
"eslint": "eslint ./**/*.ts",
"eslint:fix": "eslint ./**/*.ts --fix",
"prettier": "prettier src --write",
Expand Down Expand Up @@ -63,7 +64,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "7.0.0-dev.20241019"
"typia": "7.0.0-dev.20241020"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.7.0"
Expand Down
10 changes: 4 additions & 6 deletions src/factories/ProtobufFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,10 @@ export namespace ProtobufFactory {
index: getSequence(atomic.tags[0] ?? [])!,
});

// SORTING IF REQUIRED
if (map.size && map.values().next().value!.index === null)
return new Map(
Array.from(map).sort((x, y) => ProtobufUtil.compare(x[0], y[0])),
);
return map;
// SORTING FOR VALIDATION REASON
return new Map(
Array.from(map).sort((x, y) => ProtobufUtil.compare(x[0], y[0])),
);
};

const emplaceBigint = (next: {
Expand Down
2 changes: 1 addition & 1 deletion src/programmers/helpers/RandomJoiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export namespace RandomJoiner {
.filter(([key]) => key !== "items")
.map(([key, value]) =>
ts.factory.createPropertyAssignment(
key,
IdentifierFactory.identifier(key),
LiteralFactory.write(value),
),
)
Expand Down
Loading

0 comments on commit 24c4ad9

Please sign in to comment.