Skip to content

Commit

Permalink
Add range limit for numeric types.
Browse files Browse the repository at this point in the history
From v5 updates, supports those atomic types, and their ranges are limited by their own specs. For reference, `int` and `uint` types, they are not being limited.

  - int32 / uint32
  - int64
  - float
  • Loading branch information
samchon committed Aug 20, 2023
1 parent db2e236 commit acfaab7
Show file tree
Hide file tree
Showing 391 changed files with 19,910 additions and 12,108 deletions.
54 changes: 32 additions & 22 deletions build/internal/TestFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export interface TestFeature {
explicit?: true;
primitive?: true;
random?: true;
opposite?: {
opposite?: Array<{
name: string;
method: string;
};
}>;
}
export namespace TestFeature {
export const DATA: TestFeature[] = [
Expand Down Expand Up @@ -69,10 +69,12 @@ export namespace TestFeature {
spoilable: false,
primitive: true,
random: true,
opposite: {
name: "assert",
method: "typia.createAssert",
},
opposite: [
{
name: "assert",
method: "typia.createAssert",
},
],
},

//----
Expand All @@ -84,40 +86,48 @@ export namespace TestFeature {
method: "encode",
creatable: true,
spoilable: false,
opposite: {
name: "message",
method: "typia.protobuf.message",
},
opposite: [
{
name: "message",
method: "typia.protobuf.message",
},
],
},
{
module: "protobuf",
method: "isEncode",
creatable: true,
spoilable: true,
opposite: {
name: "message",
method: "typia.protobuf.message",
},
opposite: [
{
name: "message",
method: "typia.protobuf.message",
},
],
},
{
module: "protobuf",
method: "assertEncode",
creatable: true,
spoilable: true,
opposite: {
name: "message",
method: "typia.protobuf.message",
},
opposite: [
{
name: "message",
method: "typia.protobuf.message",
},
],
},
{
module: "protobuf",
method: "validateEncode",
creatable: true,
spoilable: true,
opposite: {
name: "message",
method: "typia.protobuf.message",
},
opposite: [
{
name: "message",
method: "typia.protobuf.message",
},
],
},

//----
Expand Down
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.0.0-dev.20230819",
"version": "5.0.0-dev.20230820",
"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.0.0-dev.20230819",
"version": "5.0.0-dev.20230820",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -68,7 +68,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.0.0-dev.20230819"
"typia": "5.0.0-dev.20230820"
},
"peerDependencies": {
"typescript": ">= 4.7.4"
Expand Down
7 changes: 7 additions & 0 deletions src/factories/ExpressionFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import ts from "typescript";

export namespace ExpressionFactory {
export const bigint = (value: number) =>
ts.factory.createCallExpression(
ts.factory.createIdentifier("BigInt"),
undefined,
[ts.factory.createNumericLiteral(value)],
);

export const isRequired = (input: ts.Expression): ts.Expression =>
ts.factory.createStrictInequality(
ts.factory.createIdentifier("undefined"),
Expand Down
3 changes: 3 additions & 0 deletions src/factories/MetadataTagFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ const has_atomic =
metadata.tuples.some((tuple) =>
tuple.elements.some(has_atomic(type)(visited)),
) ||
metadata.maps.some((map) => has_atomic(type)(visited)(map.value)) ||
metadata.aliases.some((alias) =>
has_atomic(type)(visited)(alias.value),
) ||
Expand All @@ -337,6 +338,7 @@ const has_native =
metadata.tuples.some((tuple) =>
tuple.elements.some(has_native(type)(visited)),
) ||
metadata.maps.some((map) => has_native(type)(visited)(map.value)) ||
metadata.aliases.some((alias) =>
has_native(type)(visited)(alias.value),
) ||
Expand All @@ -355,6 +357,7 @@ const has_array =
metadata.tuples.some((tuple) =>
tuple.elements.some(has_array(visited)),
) ||
metadata.maps.some((map) => has_array(visited)(map.value)) ||
metadata.aliases.some((alias) => has_array(visited)(alias.value)) ||
(metadata.resolved !== null &&
has_array(visited)(metadata.resolved.returns))
Expand Down
3 changes: 1 addition & 2 deletions src/functional/$ProtobufReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ export class $ProtobufReader {
if (loaded < N80) return value;

value |= (this.u8n() & N01) << BigInt(63);

return value;
return BigInt.asIntN(64, value);
}

private u8(): number {
Expand Down
25 changes: 0 additions & 25 deletions src/functional/$proto_bytes.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/functional/$proto_field.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/functional/$proto_float.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/functional/$proto_i32.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/functional/$proto_i64.ts

This file was deleted.

Loading

0 comments on commit acfaab7

Please sign in to comment.