Skip to content

Commit

Permalink
$importInternal script in the type tag validator.
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Nov 14, 2024
1 parent 4210e6e commit dd942d8
Show file tree
Hide file tree
Showing 80 changed files with 479 additions and 7,156 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.20241112.tgz"
"typia": "../typia-7.0.0-dev.20241114.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": "7.0.0-dev.20241112",
"version": "7.0.0-dev.20241114",
"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": "7.0.0-dev.20241112",
"version": "7.0.0-dev.20241114",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -64,7 +64,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "7.0.0-dev.20241112"
"typia": "7.0.0-dev.20241114"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.7.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-json/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"DOM",
"ES2020"
Expand Down
70 changes: 62 additions & 8 deletions src/factories/ExpressionFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ts from "typescript";

import { ImportProgrammer } from "../programmers/ImportProgrammer";

import { _randomFormatUuid } from "../internal/_randomFormatUuid";

export namespace ExpressionFactory {
Expand Down Expand Up @@ -129,13 +131,14 @@ export namespace ExpressionFactory {
props.input.getSourceFile(),
);

export const transpile = (
transformer: ts.TransformationContext,
script: string,
) => {
export const transpile = (props: {
transformer?: ts.TransformationContext;
importer?: ImportProgrammer;
script: string;
}) => {
const file: ts.SourceFile = ts.createSourceFile(
`${_randomFormatUuid()}.ts`,
script,
props.script,
ts.ScriptTarget.ESNext,
true,
ts.ScriptKind.TS,
Expand All @@ -152,13 +155,64 @@ export namespace ExpressionFactory {
return (input: ts.Expression): ts.Expression => {
const visitor = (node: ts.Node): ts.Node => {
if (ts.isIdentifier(node) && node.text === "$input") return input;
else if (props.importer !== undefined && ts.isCallExpression(node))
if (
node.expression.getText() === "$importInternal" &&
node.arguments.length === 1 &&
ts.isStringLiteralLike(node.arguments[0]!)
) {
const name: string = node.arguments[0]!.text;
return props.importer.internal(name);
} else if (
node.expression.getText() === "$importInstance" &&
node.arguments.length === 2 &&
ts.isStringLiteralLike(node.arguments[0]!) &&
ts.isStringLiteralLike(node.arguments[1]!)
) {
const name: string = node.arguments[0]!.text;
const file: string = node.arguments[1]!.text;
return props.importer.instance({
file,
name,
alias: null,
type: false,
});
} else if (
node.expression.getText() === "$importNamespace" &&
node.arguments.length === 2 &&
ts.isStringLiteralLike(node.arguments[0]!) &&
ts.isStringLiteralLike(node.arguments[1]!)
) {
const name: string = node.arguments[0]!.text;
const file: string = node.arguments[1]!.text;
return props.importer.namespace({
file,
name,
type: false,
});
} else if (
node.expression.getText() === "$importDefault" &&
node.arguments.length === 3 &&
ts.isStringLiteralLike(node.arguments[0]!) &&
ts.isStringLiteralLike(node.arguments[1]!)
) {
const name: string = node.arguments[0]!.text;
const file: string = node.arguments[1]!.text;
return props.importer.default({
file,
name,
type: false,
});
}
return ts.visitEachChild(
(ts.factory as any).cloneNode(node),
ts.factory.cloneNode(node),
visitor,
transformer,
props.transformer,
);
};
return visitor(statement.expression) as ts.Expression;
return visitor(
ts.factory.cloneNode(statement.expression),
) as ts.Expression;
};
};
}
37 changes: 17 additions & 20 deletions src/factories/MetadataFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,29 @@ export namespace MetadataFactory {
};

const validateMeta = (props: {
transformer?: ts.TransformationContext;
options: IOptions;
visitor: IValidationVisitor;
metadata: Metadata;
explore: IExplore;
}) => {
const result: string[] = [];
if (props.transformer !== undefined)
for (const atomic of props.metadata.atomics)
for (const row of atomic.tags)
for (const tag of row.filter(
(t) => t.validate !== undefined && t.predicate === undefined,
))
try {
tag.predicate = ExpressionFactory.transpile(
props.transformer,
tag.validate!,
);
} catch {
result.push(
`Unable to transpile type tag script: ${JSON.stringify(
tag.validate,
)}`,
);
tag.predicate = () => ts.factory.createTrue();
}
for (const atomic of props.metadata.atomics)
for (const row of atomic.tags)
for (const tag of row.filter(
(t) => t.validate !== undefined && t.predicate === undefined,
))
try {
tag.predicate = ExpressionFactory.transpile({
script: tag.validate!,
});
} catch {
result.push(
`Unable to transpile type tag script: ${JSON.stringify(
tag.validate,
)}`,
);
tag.predicate = () => ts.factory.createTrue();
}
result.push(...props.visitor.functor(props.metadata, props.explore));
if (result.length)
props.visitor.errors.push({
Expand Down
7 changes: 7 additions & 0 deletions src/internal/_isFormatByte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const _isFormatByte = (str: string): boolean => {
PATTERN.lastIndex = 0;
return PATTERN.test(str);
};

const PATTERN =
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
3 changes: 3 additions & 0 deletions src/internal/_isFormatDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const _isFormatDate = (str: string): boolean => FORMAT.test(str);

const FORMAT = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
4 changes: 4 additions & 0 deletions src/internal/_isFormatDateTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatDateTime = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i;
4 changes: 4 additions & 0 deletions src/internal/_isFormatDuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatDuration = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/;
4 changes: 4 additions & 0 deletions src/internal/_isFormatEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatEmail = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
4 changes: 4 additions & 0 deletions src/internal/_isFormatHostname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatHostname = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
4 changes: 4 additions & 0 deletions src/internal/_isFormatIdnEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatIdnEmail = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
4 changes: 4 additions & 0 deletions src/internal/_isFormatIdnHostname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatIdnHostname = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^([a-z0-9\u00a1-\uffff0-9]+(-[a-z0-9\u00a1-\uffff0-9]+)*\.)+[a-z\u00a1-\uffff]{2,}$/i;
4 changes: 4 additions & 0 deletions src/internal/_isFormatIpv4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatIpv4 = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
4 changes: 4 additions & 0 deletions src/internal/_isFormatIpv6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatIpv6 = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;
3 changes: 3 additions & 0 deletions src/internal/_isFormatIri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const _isFormatIri = (str: string): boolean => PATTERN.test(str);

const PATTERN = /^[A-Za-z][\d+-.A-Za-z]*:[^\u0000-\u0020"<>\\^`{|}]*$/u;
4 changes: 4 additions & 0 deletions src/internal/_isFormatIriReference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatIriReference = (str: string): boolean =>
PATTERN.test(str);

const PATTERN = /^[A-Za-z][\d+-.A-Za-z]*:[^\u0000-\u0020"<>\\^`{|}]*$/u;
3 changes: 3 additions & 0 deletions src/internal/_isFormatJsonPointer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const _isFormatJsonPointer = (str: string): boolean => PATTERN.test(str);

const PATTERN = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
1 change: 1 addition & 0 deletions src/internal/_isFormatPassword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const _isFormatPassword = (): boolean => true;
8 changes: 8 additions & 0 deletions src/internal/_isFormatRegex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const _isFormatRegex = (str: string): boolean => {
try {
new RegExp(str);
return true;
} catch {
return false;
}
};
4 changes: 4 additions & 0 deletions src/internal/_isFormatRelativeJsonPointer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatRelativeJsonPointer = (str: string): boolean =>
PATTERN.test(str);

const PATTERN = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
4 changes: 4 additions & 0 deletions src/internal/_isFormatTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatTime = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i;
6 changes: 6 additions & 0 deletions src/internal/_isFormatUri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const _isFormatUri = (str: string): boolean =>
NOT_URI_FRAGMENT.test(str) && URI.test(str);

const NOT_URI_FRAGMENT = /\/|:/;
const URI =
/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
5 changes: 5 additions & 0 deletions src/internal/_isFormatUriReference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const _isFormatUriReference = (str: string): boolean =>
PATTERN.test(str);

const PATTERN =
/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
4 changes: 4 additions & 0 deletions src/internal/_isFormatUriTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatUriTemplate = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
4 changes: 4 additions & 0 deletions src/internal/_isFormatUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const _isFormatUrl = (str: string): boolean => PATTERN.test(str);

const PATTERN =
/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
3 changes: 3 additions & 0 deletions src/internal/_isFormatUuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const _isFormatUuid = (str: string): boolean => PATTERN.test(str);

const PATTERN = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
5 changes: 5 additions & 0 deletions src/internal/_isTypeFloat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const _isTypeFloat = (value: number): boolean =>
MINIMUM <= value && value <= MAXIMUM;

const MINIMUM = -1.175494351e38;
const MAXIMUM = 3.4028235e38;
5 changes: 5 additions & 0 deletions src/internal/_isTypeInt32.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const _isTypeInt32 = (value: number): boolean =>
Math.floor(value) === value && MINIMUM <= value && value <= MAXIMUM;

const MINIMUM = -(2 ** 31);
const MAXIMUM = 2 ** 31 - 1;
5 changes: 5 additions & 0 deletions src/internal/_isTypeInt64.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const _isTypeInt64 = (value: number): boolean =>
Math.floor(value) === value && MINIMUM <= value && value <= MAXIMUM;

const MINIMUM = -(2 ** 63);
const MAXIMUM = 2 ** 63 - 1;
5 changes: 5 additions & 0 deletions src/internal/_isTypeUint32.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const _isTypeUint32 = (value: number): boolean =>
Math.floor(value) === value && MINIMUM <= value && value <= MAXIMUM;

const MINIMUM = 0;
const MAXIMUM = 2 ** 32 - 1;
5 changes: 5 additions & 0 deletions src/internal/_isTypeUint64.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const _isTypeUint64 = (value: number): boolean =>
Math.floor(value) === value && MINIMUM <= value && value <= MAXIMUM;

const MINIMUM = 0;
const MAXIMUM = 2 ** 64 - 1;
9 changes: 5 additions & 4 deletions src/programmers/internal/check_array_length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const check_array_type_tags = (props: {
.map((row) =>
row.map((tag) => ({
expected: `Array<> & ${tag.name}`,
expression: (
tag.predicate ??
ExpressionFactory.transpile(props.context.transformer, tag.validate!)
)(props.input),
expression: ExpressionFactory.transpile({
transformer: props.context.transformer,
importer: props.context.importer,
script: tag.validate!,
})(props.input),
})),
);
9 changes: 5 additions & 4 deletions src/programmers/internal/check_bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ const check_bigint_type_tags = (props: {
.map((row) =>
row.map((tag) => ({
expected: `bigint & ${tag.name}`,
expression: (
tag.predicate ??
ExpressionFactory.transpile(props.context.transformer, tag.validate!)
)(props.input),
expression: ExpressionFactory.transpile({
transformer: props.context.transformer,
importer: props.context.importer,
script: tag.validate!,
})(props.input),
})),
);
9 changes: 5 additions & 4 deletions src/programmers/internal/check_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ const check_numeric_type_tags = (props: {
]),
...row.map((tag) => ({
expected: `number & ${tag.name}`,
expression: (
tag.predicate ??
ExpressionFactory.transpile(props.context.transformer, tag.validate!)
)(props.input),
expression: ExpressionFactory.transpile({
transformer: props.context.transformer,
importer: props.context.importer,
script: tag.validate!,
})(props.input),
})),
]);
9 changes: 5 additions & 4 deletions src/programmers/internal/check_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ const check_string_type_tags = (props: {
.map((row) =>
row.map((tag) => ({
expected: `string & ${tag.name}`,
expression: (
tag.predicate ??
ExpressionFactory.transpile(props.context.transformer, tag.validate!)
)(props.input),
expression: ExpressionFactory.transpile({
transformer: props.context.transformer,
importer: props.context.importer,
script: tag.validate!,
})(props.input),
})),
);
Loading

0 comments on commit dd942d8

Please sign in to comment.