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

Fix #853 - Record<string & tags.Format<"uuid">, T> case. #861

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "5.2.4",
"version": "5.2.5",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -134,7 +134,7 @@
"zod": "^3.19.1"
},
"stackblitzs": {
"startCommand": "npm run prepare && npm run build && npm run build:test && npm run test"
"startCommand": "npm run prepare && npm run build:test:actions && npm run build:test && npm run test"
},
"files": [
"LICENSE",
Expand Down
6 changes: 3 additions & 3 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.2.4",
"version": "5.2.5",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -72,13 +72,13 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.2.4"
"typia": "5.2.5"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.3.0"
},
"stackblitzs": {
"startCommand": "npm run prepare && npm run build && npm run build:test && npm run test"
"startCommand": "npm run prepare && npm run build:test:actions && npm run build:test && npm run test"
},
"files": [
"LICENSE",
Expand Down
28 changes: 28 additions & 0 deletions src/factories/internal/metadata/emplace_metadata_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,34 @@ export const emplace_metadata_object =
const key: Metadata = analyzer(index.keyType)(null);
const value: Metadata = analyzer(index.type)({});

if (
key.atomics.length +
key.constants
.map((c) => c.values.length)
.reduce((a, b) => a + b, 0) +
key.templates.length +
key.natives.filter(
(type) =>
type === "Boolean" ||
type === "BigInt" ||
type === "Number" ||
type === "String",
).length !==
key.size()
)
errors.push({
name: key.getName(),
explore: {
top: false,
object: obj,
property: "[key]",
nested: null,
escaped: false,
aliased: false,
},
messages: [],
});

// INSERT WITH REQUIRED CONFIGURATION
insert(key)(value)(
index.declaration?.parent
Expand Down
8 changes: 8 additions & 0 deletions src/functional/$stoll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const $is_bigint_string = (str: string): boolean => {
try {
BigInt(str);
return true;
} catch {
return false;
}
};
4 changes: 4 additions & 0 deletions src/functional/Namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { $join } from "./$join";
import { $number } from "./$number";
import { $report } from "./$report";
import { $rest } from "./$rest";
import { $is_bigint_string } from "./$stoll";
import { $string } from "./$string";
import { $strlen } from "./$strlen";
import { $tail } from "./$tail";
Expand All @@ -28,6 +29,7 @@ import { $tail } from "./$tail";
export namespace Namespace {
export const is = () => ({
is_between: $is_between,
is_bigint_string: $is_bigint_string,
});

export const assert = (method: string) => ({
Expand Down Expand Up @@ -97,11 +99,13 @@ export namespace Namespace {

export namespace protobuf {
export const decode = (method: string) => ({
...is(),
Reader: $ProtobufReader,
throws: $throws(`protobuf.${method}`),
});

export const encode = (method: string) => ({
...is(),
Sizer: $ProtobufSizer,
Writer: $ProtobufWriter,
strlen: $strlen,
Expand Down
67 changes: 36 additions & 31 deletions src/programmers/AssertProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export namespace AssertProgrammer {
),
]),
].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
combiner: combiner(equals)(importer),
joiner: joiner(equals)(importer),
combiner: combiner(equals)(project)(importer),
joiner: joiner(equals)(project)(importer),
success: ts.factory.createTrue(),
addition: () => importer.declare(modulo),
})(importer)(type, name);
Expand Down Expand Up @@ -148,13 +148,14 @@ export namespace AssertProgrammer {

const combiner =
(equals: boolean) =>
(project: IProject) =>
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
(explore: CheckerProgrammer.IExplore) => {
if (explore.tracable === false)
return IsProgrammer.configure({
object: assert_object(equals)(importer),
object: assert_object(equals)(project)(importer),
numeric: true,
})(importer).combiner(explore);
})(project)(importer).combiner(explore);

const path: string = explore.postfix
? `_path + ${explore.postfix}`
Expand Down Expand Up @@ -219,40 +220,44 @@ export namespace AssertProgrammer {
// })();
};

const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
check_object({
equals,
assert: true,
undefined: true,
reduce: ts.factory.createLogicalAnd,
positive: ts.factory.createTrue(),
superfluous: (value) =>
create_guard_call(importer)()(
ts.factory.createAdd(
ts.factory.createIdentifier("_path"),
ts.factory.createCallExpression(
importer.use("join"),
undefined,
[ts.factory.createIdentifier("key")],
const assert_object =
(equals: boolean) =>
(project: IProject) =>
(importer: FunctionImporter) =>
check_object({
equals,
assert: true,
undefined: true,
reduce: ts.factory.createLogicalAnd,
positive: ts.factory.createTrue(),
superfluous: (value) =>
create_guard_call(importer)()(
ts.factory.createAdd(
ts.factory.createIdentifier("_path"),
ts.factory.createCallExpression(
importer.use("join"),
undefined,
[ts.factory.createIdentifier("key")],
),
),
"undefined",
value,
),
"undefined",
value,
),
halt: (expr) =>
ts.factory.createLogicalOr(
ts.factory.createStrictEquality(
ts.factory.createFalse(),
ts.factory.createIdentifier("_exceptionable"),
halt: (expr) =>
ts.factory.createLogicalOr(
ts.factory.createStrictEquality(
ts.factory.createFalse(),
ts.factory.createIdentifier("_exceptionable"),
),
expr,
),
expr,
),
})(importer);
})(project)(importer);

const joiner =
(equals: boolean) =>
(project: IProject) =>
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
object: assert_object(equals)(importer),
object: assert_object(equals)(project)(importer),
array: (input, arrow) =>
ts.factory.createCallExpression(
IdentifierFactory.access(input)("every"),
Expand Down
20 changes: 13 additions & 7 deletions src/programmers/IsProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { feature_object_entries } from "./internal/feature_object_entries";
export namespace IsProgrammer {
export const configure =
(options?: Partial<CONFIG.IOptions>) =>
(project: IProject) =>
(importer: FunctionImporter): CheckerProgrammer.IConfig => ({
prefix: "$i",
equals: !!options?.object,
Expand Down Expand Up @@ -79,7 +80,7 @@ export namespace IsProgrammer {
reduce: ts.factory.createLogicalAnd,
positive: ts.factory.createTrue(),
superfluous: () => ts.factory.createFalse(),
})(importer),
})(project)(importer),
array: (input, arrow) =>
ts.factory.createCallExpression(
IdentifierFactory.access(input)("every"),
Expand Down Expand Up @@ -126,9 +127,9 @@ export namespace IsProgrammer {
reduce: ts.factory.createLogicalAnd,
positive: ts.factory.createTrue(),
superfluous: () => ts.factory.createFalse(),
})(importer),
})(project)(importer),
numeric: OptionPredicator.numeric(project.options),
})(importer),
})(project)(importer),
trace: equals,
addition: () => importer.declare(modulo),
};
Expand Down Expand Up @@ -185,7 +186,7 @@ export namespace IsProgrammer {
(project: IProject) =>
(importer: FunctionImporter) =>
(collection: MetadataCollection) => {
const config = configure()(importer);
const config = configure()(project)(importer);
const objects =
CheckerProgrammer.write_object_functions(project)(config)(
importer,
Expand Down Expand Up @@ -223,10 +224,15 @@ export namespace IsProgrammer {
DECODERS
----------------------------------------------------------- */
export const decode = (project: IProject) => (importer: FunctionImporter) =>
CheckerProgrammer.decode(project)(configure()(importer))(importer);
CheckerProgrammer.decode(project)(configure()(project)(importer))(
importer,
);

export const decode_object = (importer: FunctionImporter) =>
CheckerProgrammer.decode_object(configure()(importer))(importer);
export const decode_object =
(project: IProject) => (importer: FunctionImporter) =>
CheckerProgrammer.decode_object(configure()(project)(importer))(
importer,
);

export const decode_to_json =
(checkNull: boolean) =>
Expand Down
65 changes: 34 additions & 31 deletions src/programmers/ValidateProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export namespace ValidateProgrammer {
),
]),
].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
combiner: combine(equals)(importer),
joiner: joiner(equals)(importer),
combiner: combine(equals)(project)(importer),
joiner: joiner(equals)(project)(importer),
success: ts.factory.createTrue(),
addition: () => importer.declare(modulo),
},
Expand Down Expand Up @@ -195,13 +195,14 @@ export namespace ValidateProgrammer {

const combine =
(equals: boolean) =>
(project: IProject) =>
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
(explore: CheckerProgrammer.IExplore) => {
if (explore.tracable === false)
return IsProgrammer.configure({
object: validate_object(equals)(importer),
object: validate_object(equals)(project)(importer),
numeric: true,
})(importer).combiner(explore);
})(project)(importer).combiner(explore);

const path: string = explore.postfix
? `_path + ${explore.postfix}`
Expand Down Expand Up @@ -240,40 +241,42 @@ const combine =
);
};

const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
check_object({
equals,
undefined: true,
assert: false,
reduce: ts.factory.createLogicalAnd,
positive: ts.factory.createTrue(),
superfluous: (value) =>
create_report_call()(
ts.factory.createAdd(
ts.factory.createIdentifier("_path"),
ts.factory.createCallExpression(
importer.use("join"),
undefined,
[ts.factory.createIdentifier("key")],
const validate_object =
(equals: boolean) => (project: IProject) => (importer: FunctionImporter) =>
check_object({
equals,
undefined: true,
assert: false,
reduce: ts.factory.createLogicalAnd,
positive: ts.factory.createTrue(),
superfluous: (value) =>
create_report_call()(
ts.factory.createAdd(
ts.factory.createIdentifier("_path"),
ts.factory.createCallExpression(
importer.use("join"),
undefined,
[ts.factory.createIdentifier("key")],
),
),
"undefined",
value,
),
"undefined",
value,
),
halt: (expr) =>
ts.factory.createLogicalOr(
ts.factory.createStrictEquality(
ts.factory.createFalse(),
ts.factory.createIdentifier("_exceptionable"),
halt: (expr) =>
ts.factory.createLogicalOr(
ts.factory.createStrictEquality(
ts.factory.createFalse(),
ts.factory.createIdentifier("_exceptionable"),
),
expr,
),
expr,
),
})(importer);
})(project)(importer);

const joiner =
(equals: boolean) =>
(project: IProject) =>
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
object: validate_object(equals)(importer),
object: validate_object(equals)(project)(importer),
array: (input, arrow) =>
check_everything(
ts.factory.createCallExpression(
Expand Down
Loading