-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #657 from samchon/features/intersection
Fix #654 - support intersection type with `atomic & object`
- Loading branch information
Showing
198 changed files
with
6,984 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/factories/internal/metadata/iterate_metadata_intersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import ts from "typescript"; | ||
|
||
import { Metadata } from "../../../metadata/Metadata"; | ||
|
||
import { MetadataCollection } from "../../MetadataCollection"; | ||
import { MetadataFactory } from "../../MetadataFactory"; | ||
import { explore_metadata } from "./explore_metadata"; | ||
import { iterate_metadata } from "./iterate_metadata"; | ||
import { iterate_metadata_object } from "./iterate_metadata_object"; | ||
|
||
export const iterate_metadata_intersection = | ||
(checker: ts.TypeChecker) => | ||
(options: MetadataFactory.IOptions) => | ||
(collection: MetadataCollection) => | ||
( | ||
meta: Metadata, | ||
type: ts.Type, | ||
resolved: boolean, | ||
aliased: boolean, | ||
): boolean => { | ||
if (!type.isIntersection()) return false; | ||
|
||
// COSTRUCT FAKE METADATA LIST | ||
const fakeCollection: MetadataCollection = new MetadataCollection(); | ||
const children: Metadata[] = [ | ||
...new Map( | ||
type.types.map((t) => { | ||
const m: Metadata = explore_metadata(checker)(options)( | ||
fakeCollection, | ||
)(t, resolved); | ||
return [m.getName(), m] as const; | ||
}), | ||
).values(), | ||
]; | ||
|
||
// ONLY ONE CHILD AFTER REMOVING DUPLICATES | ||
if (children.length === 1) { | ||
iterate_metadata(checker)(options)(collection)( | ||
meta, | ||
type.types[0]!, | ||
resolved, | ||
aliased, | ||
); | ||
return true; | ||
} | ||
|
||
// ONLY OBJECT TYPES -> MERGE | ||
const object: boolean = children.every( | ||
(c) => c.objects.length && c.objects.length === c.size(), | ||
); | ||
if (object) | ||
return iterate_metadata_object(checker)(options)(collection)( | ||
meta, | ||
type, | ||
resolved, | ||
true, | ||
); | ||
|
||
// ABSORB TO ATOMIC (OR CONSTANT) TYPE | ||
const atomics: Metadata[] = children.filter( | ||
(c) => | ||
(c.atomics.length ? 1 : 0 + c.constants.length ? 1 : 0) === | ||
c.bucket(), | ||
); | ||
const objects: Metadata[] = children.filter( | ||
(c) => c.objects.length && c.objects.length === c.size(), | ||
); | ||
if ( | ||
atomics.length === 0 || | ||
atomics.length + objects.length !== children.length | ||
) | ||
throw new Error(message(children)); | ||
|
||
const least: Metadata = atomics.reduce((x, y) => { | ||
if (Metadata.covers(x, y)) return y; | ||
else if (Metadata.covers(y, x)) return x; | ||
throw new Error(message(children)); | ||
}); | ||
Object.assign(meta, Metadata.merge(meta, least)); | ||
return true; | ||
}; | ||
|
||
const message = (children: Metadata[]) => | ||
`Error on typia.MetadataFactory.analyze(): nonsensibl intersection type detected - ${children | ||
.map((c) => c.getName()) | ||
.join(" & ")}.`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/features/application/ajv/test_application_ajv_AtomicIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import typia from "typia"; | ||
|
||
import { _test_application } from "../../../internal/_test_application"; | ||
import { AtomicIntersection } from "../../../structures/AtomicIntersection"; | ||
|
||
export const test_application_ajv_AtomicIntersection = _test_application("ajv")( | ||
"AtomicIntersection", | ||
typia.application<[AtomicIntersection], "ajv">(), | ||
); |
8 changes: 8 additions & 0 deletions
8
test/features/application/ajv/test_application_ajv_ConstantIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import typia from "typia"; | ||
|
||
import { _test_application } from "../../../internal/_test_application"; | ||
import { ConstantIntersection } from "../../../structures/ConstantIntersection"; | ||
|
||
export const test_application_ajv_ConstantIntersection = _test_application( | ||
"ajv", | ||
)("ConstantIntersection", typia.application<[ConstantIntersection], "ajv">()); |
8 changes: 8 additions & 0 deletions
8
test/features/application/swagger/test_application_swagger_AtomicIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import typia from "typia"; | ||
|
||
import { _test_application } from "../../../internal/_test_application"; | ||
import { AtomicIntersection } from "../../../structures/AtomicIntersection"; | ||
|
||
export const test_application_swagger_AtomicIntersection = _test_application( | ||
"swagger", | ||
)("AtomicIntersection", typia.application<[AtomicIntersection], "swagger">()); |
11 changes: 11 additions & 0 deletions
11
test/features/application/swagger/test_application_swagger_ConstantIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import typia from "typia"; | ||
|
||
import { _test_application } from "../../../internal/_test_application"; | ||
import { ConstantIntersection } from "../../../structures/ConstantIntersection"; | ||
|
||
export const test_application_swagger_ConstantIntersection = _test_application( | ||
"swagger", | ||
)( | ||
"ConstantIntersection", | ||
typia.application<[ConstantIntersection], "swagger">(), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assert } from "../../internal/_test_assert"; | ||
import { AtomicIntersection } from "../../structures/AtomicIntersection"; | ||
|
||
export const test_assert_AtomicIntersection = _test_assert( | ||
"AtomicIntersection", | ||
AtomicIntersection.generate, | ||
(input) => typia.assert(input), | ||
AtomicIntersection.SPOILERS, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assert } from "../../internal/_test_assert"; | ||
import { ConstantIntersection } from "../../structures/ConstantIntersection"; | ||
|
||
export const test_assert_ConstantIntersection = _test_assert( | ||
"ConstantIntersection", | ||
ConstantIntersection.generate, | ||
(input) => typia.assert(input), | ||
ConstantIntersection.SPOILERS, | ||
); |
10 changes: 10 additions & 0 deletions
10
test/features/assertClone/test_assertClone_AtomicIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertClone } from "../../internal/_test_assertClone"; | ||
import { AtomicIntersection } from "../../structures/AtomicIntersection"; | ||
|
||
export const test_assertClone_AtomicIntersection = _test_assertClone( | ||
"AtomicIntersection", | ||
AtomicIntersection.generate, | ||
(input) => typia.assertClone(input), | ||
AtomicIntersection.SPOILERS, | ||
); |
10 changes: 10 additions & 0 deletions
10
test/features/assertClone/test_assertClone_ConstantIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertClone } from "../../internal/_test_assertClone"; | ||
import { ConstantIntersection } from "../../structures/ConstantIntersection"; | ||
|
||
export const test_assertClone_ConstantIntersection = _test_assertClone( | ||
"ConstantIntersection", | ||
ConstantIntersection.generate, | ||
(input) => typia.assertClone(input), | ||
ConstantIntersection.SPOILERS, | ||
); |
9 changes: 9 additions & 0 deletions
9
test/features/assertEquals/test_assertEquals_AtomicIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertEquals } from "../../internal/_test_assertEquals"; | ||
import { AtomicIntersection } from "../../structures/AtomicIntersection"; | ||
|
||
export const test_assertEquals_AtomicIntersection = _test_assertEquals( | ||
"AtomicIntersection", | ||
AtomicIntersection.generate, | ||
(input) => typia.assertEquals(input), | ||
); |
9 changes: 9 additions & 0 deletions
9
test/features/assertEquals/test_assertEquals_ConstantIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertEquals } from "../../internal/_test_assertEquals"; | ||
import { ConstantIntersection } from "../../structures/ConstantIntersection"; | ||
|
||
export const test_assertEquals_ConstantIntersection = _test_assertEquals( | ||
"ConstantIntersection", | ||
ConstantIntersection.generate, | ||
(input) => typia.assertEquals(input), | ||
); |
10 changes: 10 additions & 0 deletions
10
test/features/assertParse/test_assertParse_AtomicIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertParse } from "../../internal/_test_assertParse"; | ||
import { AtomicIntersection } from "../../structures/AtomicIntersection"; | ||
|
||
export const test_assertParse_AtomicIntersection = _test_assertParse( | ||
"AtomicIntersection", | ||
AtomicIntersection.generate, | ||
(input) => typia.assertParse<AtomicIntersection>(input), | ||
AtomicIntersection.SPOILERS, | ||
); |
10 changes: 10 additions & 0 deletions
10
test/features/assertParse/test_assertParse_ConstantIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertParse } from "../../internal/_test_assertParse"; | ||
import { ConstantIntersection } from "../../structures/ConstantIntersection"; | ||
|
||
export const test_assertParse_ConstantIntersection = _test_assertParse( | ||
"ConstantIntersection", | ||
ConstantIntersection.generate, | ||
(input) => typia.assertParse<ConstantIntersection>(input), | ||
ConstantIntersection.SPOILERS, | ||
); |
10 changes: 10 additions & 0 deletions
10
test/features/assertPrune/test_assertPrune_AtomicIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertPrune } from "../../internal/_test_assertPrune"; | ||
import { AtomicIntersection } from "../../structures/AtomicIntersection"; | ||
|
||
export const test_assertPrune_AtomicIntersection = _test_assertPrune( | ||
"AtomicIntersection", | ||
AtomicIntersection.generate, | ||
(input) => typia.assertPrune(input), | ||
AtomicIntersection.SPOILERS, | ||
); |
10 changes: 10 additions & 0 deletions
10
test/features/assertPrune/test_assertPrune_ConstantIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertPrune } from "../../internal/_test_assertPrune"; | ||
import { ConstantIntersection } from "../../structures/ConstantIntersection"; | ||
|
||
export const test_assertPrune_ConstantIntersection = _test_assertPrune( | ||
"ConstantIntersection", | ||
ConstantIntersection.generate, | ||
(input) => typia.assertPrune(input), | ||
ConstantIntersection.SPOILERS, | ||
); |
10 changes: 10 additions & 0 deletions
10
test/features/assertStringify/test_assertStringify_AtomicIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertStringify } from "../../internal/_test_assertStringify"; | ||
import { AtomicIntersection } from "../../structures/AtomicIntersection"; | ||
|
||
export const test_assertStringify_AtomicIntersection = _test_assertStringify( | ||
"AtomicIntersection", | ||
AtomicIntersection.generate, | ||
(input) => typia.assertStringify(input), | ||
AtomicIntersection.SPOILERS, | ||
); |
10 changes: 10 additions & 0 deletions
10
test/features/assertStringify/test_assertStringify_ConstantIntersection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typia from "../../../src"; | ||
import { _test_assertStringify } from "../../internal/_test_assertStringify"; | ||
import { ConstantIntersection } from "../../structures/ConstantIntersection"; | ||
|
||
export const test_assertStringify_ConstantIntersection = _test_assertStringify( | ||
"ConstantIntersection", | ||
ConstantIntersection.generate, | ||
(input) => typia.assertStringify(input), | ||
ConstantIntersection.SPOILERS, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import typia from "../../../src"; | ||
import { _test_clone } from "../../internal/_test_clone"; | ||
import { AtomicIntersection } from "../../structures/AtomicIntersection"; | ||
|
||
export const test_clone_AtomicIntersection = _test_clone( | ||
"AtomicIntersection", | ||
AtomicIntersection.generate, | ||
(input) => typia.clone(input), | ||
); |
Oops, something went wrong.