Skip to content

Commit

Permalink
Exact validation of MetadataFactory.
Browse files Browse the repository at this point in the history
Until `4.2.2` version, validator of  `MetadataFactory` had not worked exactly when lazy constructed type like Object or Repeated Array (Tuple) type come.

Therefore, enhanced validator of `MetadataFactory`, so there would not be any problem on the validator more.
  • Loading branch information
samchon committed Aug 14, 2023
1 parent 5489d2e commit d931343
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 40 deletions.
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": "4.2.2",
"version": "4.2.3",
"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": "4.2.2",
"version": "4.2.3",
"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": "4.2.2"
"typia": "4.2.3"
},
"peerDependencies": {
"typescript": ">= 4.7.4"
Expand Down
5 changes: 5 additions & 0 deletions src/factories/MetadataCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class MetadataCollection {
private recursive_array_index_: number;
private recursive_tuple_index_: number;

/**
* @internal
*/
public readonly entire_: Set<Metadata> = new Set();

public constructor(
private readonly options?: Partial<MetadataCollection.IOptions>,
) {
Expand Down
4 changes: 4 additions & 0 deletions src/factories/MetadataFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export namespace MetadataFactory {
)(type, false);
iterate_metadata_collection(collection);
iterate_metadata_sort(collection)(meta);

if (options.validate)
for (const elem of collection.entire_) options.validate(elem);
collection.entire_.clear();
return meta;
};
}
10 changes: 4 additions & 6 deletions src/factories/internal/metadata/explore_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ export const explore_metadata =
): Metadata => {
// CONSTRUCT METADATA
const meta: Metadata = Metadata.initialize(parentResolved);
const out = (meta: Metadata) => {
if (options.validate) options.validate(meta);
return meta;
};
if (type === null) return out(meta);
collection.entire_.add(meta);

if (type === null) return meta;

// ITERATE TYPESCRIPT TYPES
iterate_metadata(checker)(options)(collection)(
Expand All @@ -36,5 +34,5 @@ export const explore_metadata =
emend_metadata_atomics(meta.resolved.original);
emend_metadata_atomics(meta.resolved.returns);
}
return out(meta);
return meta;
};
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const iterate_metadata_intersection =
throw new Error(message(children));
});
Object.assign(meta, Metadata.merge(meta, least));
collection.entire_.add(least);
return true;
};

Expand Down
9 changes: 0 additions & 9 deletions src/programmers/CheckerProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,6 @@ export namespace CheckerProgrammer {
resolve: false,
constant: true,
absorb: true,
validate: (meta) => {
if (
meta.arrays.length > 1 &&
meta.arrays.some((a) => a.recursive)
)
throw new Error(
`Repeated union array types are not supported yet.`,
);
},
})(collection)(type);
return [collection, meta];
},
Expand Down
8 changes: 8 additions & 0 deletions src/programmers/StringifyProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,12 @@ export namespace StringifyProgrammer {
validate: (meta) => {
if (meta.atomics.find((str) => str === "bigint"))
throw new Error(NO_BIGINT);
else if (
meta.arrays.some(
(array) => array.value.isRequired() === false,
)
)
throw new Error(NO_UNDEFINED_IN_ARRAY);
},
})(collection)(type);
return [collection, meta];
Expand Down Expand Up @@ -976,3 +982,5 @@ interface IUnion {
}

const NO_BIGINT = "Error on typia.stringify(): does not allow bigint type.";
const NO_UNDEFINED_IN_ARRAY =
"Error on typia.stringify(): does not allow undefined type in array.";
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export namespace ApplicationTransformer {
validate: (meta) => {
if (meta.atomics.find((str) => str === "bigint"))
throw new Error(NO_BIGIT);
else if (
meta.arrays.some(
(array) => array.value.isRequired() === false,
)
)
throw new Error(NO_UNDEFINED_IN_ARRAY);
},
})(collection)(type),
);
Expand Down Expand Up @@ -102,3 +108,5 @@ const NO_GENERIC_ARGUMENT =
const GENERIC_ARGUMENT =
"Error on typia.application(): non-specified generic argument(s).";
const NO_BIGIT = "Error on typia.application(): does not allow bigint type.";
const NO_UNDEFINED_IN_ARRAY =
"Error on typia.application(): does not allow undefined type in array.";
8 changes: 4 additions & 4 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "5.1.6",
"typia": "^4.2.2"
"typia": "^4.2.3"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
Expand Down
34 changes: 17 additions & 17 deletions website/public/sitemap-0.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://typia.io/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/parse/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/schema/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/stringify/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/miscellaneous/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/pure/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/random/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/setup/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/nestjs/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/prisma/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/trpc/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/assert/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/comment-tags/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/is/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/validate/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/playground/</loc><lastmod>2023-08-13T13:56:54.868Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/parse/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/schema/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/json/stringify/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/miscellaneous/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/pure/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/random/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/setup/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/nestjs/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/prisma/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/utilization/trpc/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/assert/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/comment-tags/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/is/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/docs/validators/validate/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://typia.io/playground/</loc><lastmod>2023-08-14T18:33:23.863Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
</urlset>

0 comments on commit d931343

Please sign in to comment.