Skip to content

Commit 60f400c

Browse files
authored
refactor(typia): dismantle the misc namespace into plain / compare / reflect
Relocates clone/prune to plain, equal/cover to compare, literals to reflect; removes the misc namespace. Tests, examples, and the guide migrated. Fixes #1952.
1 parent f6a7505 commit 60f400c

104 files changed

Lines changed: 1889 additions & 1846 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/src/misc/literals.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typia from "typia";
22

33
const department: IDepartment = typia.random<IDepartment>();
4-
const cloned: IDepartment = typia.misc.assertClone<IDepartment>(department);
4+
const cloned: IDepartment = typia.plain.assertClone<IDepartment>(department);
55

66
console.log(cloned);
77

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typia from "typia";
22

33
const department: IDepartment = typia.random<IDepartment>();
4-
const pruned: IDepartment = typia.misc.assertPrune<IDepartment>(department);
4+
const pruned: IDepartment = typia.plain.assertPrune<IDepartment>(department);
55

66
console.log(pruned);
77

examples/src/reflect/literals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import typia from "typia";
2+
3+
typia.reflect.literals<"A" | "B" | "C" | 1 | 2n>();

packages/typia/native/cmd/ttsc-typia/misc_equal_cover_transform_test.go renamed to packages/typia/native/cmd/ttsc-typia/compare_equal_cover_transform_test.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ import (
88
"testing"
99
)
1010

11-
// TestMiscEqualCoverTransform verifies type-directed structural comparison.
11+
// TestCompareEqualCoverTransform verifies type-directed structural comparison.
1212
//
13-
// Issue #1497 adds `typia.misc.equal` and `typia.misc.cover`:
13+
// Issue #1497 adds `typia.compare.equal` and `typia.compare.cover`:
1414
//
1515
// 1. Transform direct and factory calls for equal/cover.
1616
// 2. Execute object, partial-object, array-length, native, dynamic-key,
1717
// union, and recursive pair-tracking cases.
1818
// 3. Reject unsupported any, function, Set, Map, WeakSet, and WeakMap types
1919
// at transform time.
20-
func TestMiscEqualCoverTransform(t *testing.T) {
21-
project := miscEqualCoverProject(t, "misc-equal-cover-", miscEqualCoverSource)
22-
js := miscEqualCoverTransform(t, project)
20+
func TestCompareEqualCoverTransform(t *testing.T) {
21+
project := compareEqualCoverProject(t, "compare-equal-cover-", compareEqualCoverSource)
22+
js := compareEqualCoverTransform(t, project)
2323
for _, needle := range []string{"getTime", "source", "flags", "Uint8Array", "WeakMap", "_vctx"} {
2424
if !strings.Contains(js, needle) {
25-
t.Fatalf("misc equal/cover output is missing %q:\n%s", needle, js)
25+
t.Fatalf("compare equal/cover output is missing %q:\n%s", needle, js)
2626
}
2727
}
28-
miscEqualCoverRunRuntimeCases(t, project, js)
29-
miscEqualCoverRejectsUnsupported(t)
28+
compareEqualCoverRunRuntimeCases(t, project, js)
29+
compareEqualCoverRejectsUnsupported(t)
3030
}
3131

32-
func miscEqualCoverProject(t *testing.T, prefix string, source string) string {
32+
func compareEqualCoverProject(t *testing.T, prefix string, source string) string {
3333
t.Helper()
3434
root := ttscTypiaTestRepoRoot(t)
3535
base := filepath.Join(root, "packages", "typia", "native", ".tmp-ttsc-typia-tests")
@@ -47,7 +47,7 @@ func miscEqualCoverProject(t *testing.T, prefix string, source string) string {
4747
if err := os.MkdirAll(src, 0o755); err != nil {
4848
t.Fatalf("mkdir fixture src: %v", err)
4949
}
50-
if err := os.WriteFile(filepath.Join(dir, "tsconfig.json"), []byte(miscEqualCoverTSConfig), 0o644); err != nil {
50+
if err := os.WriteFile(filepath.Join(dir, "tsconfig.json"), []byte(compareEqualCoverTSConfig), 0o644); err != nil {
5151
t.Fatalf("write tsconfig: %v", err)
5252
}
5353
if err := os.WriteFile(filepath.Join(src, "main.ts"), []byte(source), 0o644); err != nil {
@@ -56,7 +56,7 @@ func miscEqualCoverProject(t *testing.T, prefix string, source string) string {
5656
return dir
5757
}
5858

59-
func miscEqualCoverTransform(t *testing.T, project string) string {
59+
func compareEqualCoverTransform(t *testing.T, project string) string {
6060
t.Helper()
6161
out, errText, code := ttscTypiaTestCapture(func() int {
6262
return runTransform([]string{
@@ -67,12 +67,12 @@ func miscEqualCoverTransform(t *testing.T, project string) string {
6767
})
6868
})
6969
if code != 0 {
70-
t.Fatalf("misc equal/cover transform failed: code=%d stderr=\n%s", code, errText)
70+
t.Fatalf("compare equal/cover transform failed: code=%d stderr=\n%s", code, errText)
7171
}
7272
return out
7373
}
7474

75-
func miscEqualCoverRunRuntimeCases(t *testing.T, project string, js string) {
75+
func compareEqualCoverRunRuntimeCases(t *testing.T, project string, js string) {
7676
t.Helper()
7777
node, err := exec.LookPath("node")
7878
if err != nil {
@@ -88,33 +88,33 @@ func miscEqualCoverRunRuntimeCases(t *testing.T, project string, js string) {
8888
t.Fatalf("write runtime module: %v", err)
8989
}
9090
runner := filepath.Join(runtimeDir, "run.cjs")
91-
if err := os.WriteFile(runner, []byte(miscEqualCoverRuntimeRunner), 0o644); err != nil {
91+
if err := os.WriteFile(runner, []byte(compareEqualCoverRuntimeRunner), 0o644); err != nil {
9292
t.Fatalf("write runtime runner: %v", err)
9393
}
9494
cmd := exec.Command(node, runner)
9595
cmd.Dir = runtimeDir
9696
output, err := cmd.CombinedOutput()
9797
if err != nil {
98-
t.Fatalf("misc equal/cover runtime cases failed: %v\n%s", err, output)
98+
t.Fatalf("compare equal/cover runtime cases failed: %v\n%s", err, output)
9999
}
100100
}
101101

102-
func miscEqualCoverRejectsUnsupported(t *testing.T) {
102+
func compareEqualCoverRejectsUnsupported(t *testing.T) {
103103
t.Helper()
104104
cases := []struct {
105105
Name string
106106
Source string
107107
}{
108-
{"any", "export const bad = typia.misc.createEqual<any>();"},
109-
{"function", "export const bad = typia.misc.createEqual<() => void>();"},
110-
{"set", "export const bad = typia.misc.createCover<Set<string>>();"},
111-
{"map", "export const bad = typia.misc.createEqual<Map<string, number>>();"},
112-
{"weak-set", "export const bad = typia.misc.createCover<WeakSet<object>>();"},
113-
{"weak-map", "export const bad = typia.misc.createEqual<WeakMap<object, object>>();"},
108+
{"any", "export const bad = typia.compare.createEqual<any>();"},
109+
{"function", "export const bad = typia.compare.createEqual<() => void>();"},
110+
{"set", "export const bad = typia.compare.createCover<Set<string>>();"},
111+
{"map", "export const bad = typia.compare.createEqual<Map<string, number>>();"},
112+
{"weak-set", "export const bad = typia.compare.createCover<WeakSet<object>>();"},
113+
{"weak-map", "export const bad = typia.compare.createEqual<WeakMap<object, object>>();"},
114114
}
115115
for _, tc := range cases {
116116
t.Run(tc.Name, func(t *testing.T) {
117-
project := miscEqualCoverProject(t, "misc-equal-cover-reject-", `import typia from "typia";
117+
project := compareEqualCoverProject(t, "compare-equal-cover-reject-", `import typia from "typia";
118118
`+tc.Source+`
119119
`)
120120
out, errText, code := ttscTypiaTestCapture(func() int {
@@ -133,7 +133,7 @@ func miscEqualCoverRejectsUnsupported(t *testing.T) {
133133
}
134134
}
135135

136-
const miscEqualCoverTSConfig = `{
136+
const compareEqualCoverTSConfig = `{
137137
"compilerOptions": {
138138
"target": "ES2022",
139139
"module": "commonjs",
@@ -148,7 +148,7 @@ const miscEqualCoverTSConfig = `{
148148
}
149149
`
150150

151-
const miscEqualCoverSource = `import typia, { misc } from "typia";
151+
const compareEqualCoverSource = `import typia, { compare } from "typia";
152152
153153
interface IUser {
154154
name: string;
@@ -164,34 +164,34 @@ interface IUser {
164164
bytes: Uint8Array;
165165
}
166166
167-
export const equalUser = typia.misc.createEqual<IUser>();
168-
export const coverUser = typia.misc.createCover<IUser>();
169-
export const equalUserDirect = (x: IUser, y: IUser) => typia.misc.equal<IUser>(x, y);
170-
export const coverUserDirect = (x: IUser, y: misc.Cover<IUser>) => typia.misc.cover<IUser>(x, y);
167+
export const equalUser = typia.compare.createEqual<IUser>();
168+
export const coverUser = typia.compare.createCover<IUser>();
169+
export const equalUserDirect = (x: IUser, y: IUser) => typia.compare.equal<IUser>(x, y);
170+
export const coverUserDirect = (x: IUser, y: compare.Cover<IUser>) => typia.compare.cover<IUser>(x, y);
171171
172172
interface IDictionary {
173173
fixed: string;
174174
[key: string]: string;
175175
}
176-
export const equalDictionary = typia.misc.createEqual<IDictionary>();
177-
export const coverDictionary = typia.misc.createCover<IDictionary>();
176+
export const equalDictionary = typia.compare.createEqual<IDictionary>();
177+
export const coverDictionary = typia.compare.createCover<IDictionary>();
178178
179179
type Shape =
180180
| { kind: "circle"; radius: number; nested: { label: string } }
181181
| { kind: "square"; size: number; nested: { label: string } };
182-
export const equalShape = typia.misc.createEqual<Shape>();
183-
export const coverShape = typia.misc.createCover<Shape>();
182+
export const equalShape = typia.compare.createEqual<Shape>();
183+
export const coverShape = typia.compare.createCover<Shape>();
184184
185185
interface INode {
186186
id: number;
187187
next: INode | null;
188188
children: INode[];
189189
}
190-
export const equalNode = typia.misc.createEqual<INode>();
191-
export const coverNode = typia.misc.createCover<INode>();
190+
export const equalNode = typia.compare.createEqual<INode>();
191+
export const coverNode = typia.compare.createCover<INode>();
192192
`
193193

194-
const miscEqualCoverRuntimeRunner = `const mod = require("./main.cjs");
194+
const compareEqualCoverRuntimeRunner = `const mod = require("./main.cjs");
195195
196196
const expect = (label, actual, expected) => {
197197
if (actual !== expected) {

packages/typia/native/cmd/ttsc-typia/misc_clone_bigint_wrapper_transform_test.go renamed to packages/typia/native/cmd/ttsc-typia/plain_clone_bigint_wrapper_transform_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"testing"
99
)
1010

11-
// TestMiscCloneBigIntWrapperTransform verifies BigInt wrapper unboxing.
11+
// TestPlainCloneBigIntWrapperTransform verifies BigInt wrapper unboxing.
1212
//
13-
// Collecting TypeScript `BigInt` as native metadata routes `misc.clone` and
13+
// Collecting TypeScript `BigInt` as native metadata routes `plain.clone` and
1414
// notation programmers into their native arms. Those arms must unbox the four
1515
// primitive wrappers through `valueOf()`; before the fix the default branch
1616
// emitted a bare zero-argument `BigInt()`, which throws for every input, so
@@ -21,8 +21,8 @@ import (
2121
// 2. Require the emitted code to call `valueOf` and never bare `BigInt()`.
2222
// 3. Execute clone, assertClone, and camel notation over primitive and boxed
2323
// inputs and require primitive bigint identities back.
24-
func TestMiscCloneBigIntWrapperTransform(t *testing.T) {
25-
project := miscCloneBigIntWrapperProject(t)
24+
func TestPlainCloneBigIntWrapperTransform(t *testing.T) {
25+
project := plainCloneBigIntWrapperProject(t)
2626
out, errText, code := ttscTypiaTestCapture(func() int {
2727
return runTransform([]string{
2828
"--cwd", project,
@@ -40,17 +40,17 @@ func TestMiscCloneBigIntWrapperTransform(t *testing.T) {
4040
if strings.Contains(out, "BigInt()") {
4141
t.Fatalf("bigint wrapper clone must not emit a bare BigInt() call:\n%s", out)
4242
}
43-
miscCloneBigIntWrapperRunRuntimeCases(t, project, out)
43+
plainCloneBigIntWrapperRunRuntimeCases(t, project, out)
4444
}
4545

46-
func miscCloneBigIntWrapperProject(t *testing.T) string {
46+
func plainCloneBigIntWrapperProject(t *testing.T) string {
4747
t.Helper()
4848
root := ttscTypiaTestRepoRoot(t)
4949
base := filepath.Join(root, "packages", "typia", "native", ".tmp-ttsc-typia-tests")
5050
if err := os.MkdirAll(base, 0o755); err != nil {
5151
t.Fatalf("mkdir temp base: %v", err)
5252
}
53-
dir, err := os.MkdirTemp(base, "misc-clone-bigint-")
53+
dir, err := os.MkdirTemp(base, "plain-clone-bigint-")
5454
if err != nil {
5555
t.Fatalf("create temp fixture: %v", err)
5656
}
@@ -61,16 +61,16 @@ func miscCloneBigIntWrapperProject(t *testing.T) string {
6161
if err := os.MkdirAll(src, 0o755); err != nil {
6262
t.Fatalf("mkdir fixture src: %v", err)
6363
}
64-
if err := os.WriteFile(filepath.Join(dir, "tsconfig.json"), []byte(miscCloneBigIntWrapperTSConfig), 0o644); err != nil {
64+
if err := os.WriteFile(filepath.Join(dir, "tsconfig.json"), []byte(plainCloneBigIntWrapperTSConfig), 0o644); err != nil {
6565
t.Fatalf("write tsconfig: %v", err)
6666
}
67-
if err := os.WriteFile(filepath.Join(src, "main.ts"), []byte(miscCloneBigIntWrapperSource), 0o644); err != nil {
67+
if err := os.WriteFile(filepath.Join(src, "main.ts"), []byte(plainCloneBigIntWrapperSource), 0o644); err != nil {
6868
t.Fatalf("write source: %v", err)
6969
}
7070
return dir
7171
}
7272

73-
func miscCloneBigIntWrapperRunRuntimeCases(t *testing.T, project string, js string) {
73+
func plainCloneBigIntWrapperRunRuntimeCases(t *testing.T, project string, js string) {
7474
t.Helper()
7575
node, err := exec.LookPath("node")
7676
if err != nil {
@@ -86,7 +86,7 @@ func miscCloneBigIntWrapperRunRuntimeCases(t *testing.T, project string, js stri
8686
t.Fatalf("write runtime module: %v", err)
8787
}
8888
runner := filepath.Join(runtimeDir, "run.cjs")
89-
if err := os.WriteFile(runner, []byte(miscCloneBigIntWrapperRuntimeRunner), 0o644); err != nil {
89+
if err := os.WriteFile(runner, []byte(plainCloneBigIntWrapperRuntimeRunner), 0o644); err != nil {
9090
t.Fatalf("write runtime runner: %v", err)
9191
}
9292
cmd := exec.Command(node, runner)
@@ -97,7 +97,7 @@ func miscCloneBigIntWrapperRunRuntimeCases(t *testing.T, project string, js stri
9797
}
9898
}
9999

100-
const miscCloneBigIntWrapperTSConfig = `{
100+
const plainCloneBigIntWrapperTSConfig = `{
101101
"compilerOptions": {
102102
"target": "ES2022",
103103
"module": "commonjs",
@@ -112,19 +112,19 @@ const miscCloneBigIntWrapperTSConfig = `{
112112
}
113113
`
114114

115-
const miscCloneBigIntWrapperSource = `import typia from "typia";
115+
const plainCloneBigIntWrapperSource = `import typia from "typia";
116116
117117
interface BoxedRecord {
118118
big_value: BigInt;
119119
}
120120
121-
export const cloneInterface = typia.misc.createClone<BigInt>();
122-
export const cloneUnion = typia.misc.createClone<bigint | BigInt>();
123-
export const assertCloneInterface = typia.misc.createAssertClone<BigInt>();
121+
export const cloneInterface = typia.plain.createClone<BigInt>();
122+
export const cloneUnion = typia.plain.createClone<bigint | BigInt>();
123+
export const assertCloneInterface = typia.plain.createAssertClone<BigInt>();
124124
export const camelRecord = typia.notations.createCamel<BoxedRecord>();
125125
`
126126

127-
const miscCloneBigIntWrapperRuntimeRunner = `const mod = require("./main.cjs");
127+
const plainCloneBigIntWrapperRuntimeRunner = `const mod = require("./main.cjs");
128128
129129
const boxed = Object(1n);
130130
const expectPrimitive = (name, value, expected) => {

packages/typia/native/cmd/ttsc-typia/recursive_visit_tracking_transform_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ func recursiveVisitTrackingRunRuntimeCases(t *testing.T, project string, js stri
108108
}
109109
ttscTypiaTestWriteCommonRuntimeStubs(t, runtimeDir)
110110
extras := map[string]string{
111-
"throw-type-guard-error-stub.cjs": recursiveVisitTrackingThrowStub,
112-
"protobuf-sizer-stub.cjs": recursiveVisitTrackingProtobufSizerStub,
113-
"protobuf-writer-stub.cjs": recursiveVisitTrackingProtobufWriterStub,
114-
"json-stringify-number-stub.cjs": recursiveVisitTrackingNumberStub,
111+
"throw-type-guard-error-stub.cjs": recursiveVisitTrackingThrowStub,
112+
"protobuf-sizer-stub.cjs": recursiveVisitTrackingProtobufSizerStub,
113+
"protobuf-writer-stub.cjs": recursiveVisitTrackingProtobufWriterStub,
114+
"json-stringify-number-stub.cjs": recursiveVisitTrackingNumberStub,
115115
}
116116
for name, content := range extras {
117117
if err := os.WriteFile(filepath.Join(runtimeDir, name), []byte(content), 0o644); err != nil {
@@ -216,13 +216,13 @@ export const validateForest = typia.createValidate<ITree[] | number>();
216216
217217
// Rebuilders: clone must reproduce cycles (structured-clone style), and the
218218
// assert composition shares one functor with the clone emission.
219-
export const cloneNode = typia.misc.createClone<INode>();
220-
export const assertCloneNode = typia.misc.createAssertClone<INode>();
221-
export const cloneTree = typia.misc.createClone<ITree>();
219+
export const cloneNode = typia.plain.createClone<INode>();
220+
export const assertCloneNode = typia.plain.createAssertClone<INode>();
221+
export const cloneTree = typia.plain.createClone<ITree>();
222222
223223
// In-place walker: prune must terminate on cycles while still erasing the
224224
// superfluous properties it reaches.
225-
export const pruneNode = typia.misc.createPrune<INode>();
225+
export const pruneNode = typia.plain.createPrune<INode>();
226226
227227
// Renaming rebuilder: notations must reproduce cycles under the new keys.
228228
interface IRenamed {

0 commit comments

Comments
 (0)