Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add range limit for numeric types. #767

Merged
merged 2 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
6 changes: 4 additions & 2 deletions build/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ function script(
struct.RANDOM ? `${struct.name}.RANDOM` : ""
})`
: `(input) => ${symbol}<${struct.name}>(input)`;
const body: string = feat.opposite
const body: string = feat.opposite?.length
? [
"{",
` ${feat.method}: ${call},`,
` ${feat.opposite.name}: ${feat.opposite.method}<${struct.name}>(),`,
...feat.opposite.map(
(o) => ` ${o.name}: ${o.method}<${struct.name}>(),`,
),
"}",
].join("\n")
: call;
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-2",
"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-2",
"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-2"
},
"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
6 changes: 4 additions & 2 deletions src/factories/MetadataTagFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ export namespace MetadataTagFactory {
text === "uint32" ||
text === "int64" ||
text === "uint64" ||
text === "float" ||
text === "double")
text === "float")
? { kind: "type", value: text }
: null;
},
Expand Down Expand Up @@ -315,6 +314,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 +337,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 +356,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
Loading