typia 15.4.0 → 15.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,125 @@
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "os"
6
+ "path/filepath"
7
+ "strings"
8
+ "testing"
9
+
10
+ "github.com/samchon/ttsc/packages/ttsc/driver"
11
+ )
12
+
13
+ // The driver pairs manifest entries with registrations by position, and Go
14
+ // runs package init functions in file-name order. This registration follows
15
+ // the ones in build_emit_hook_observations_test.go (entry 0) and
16
+ // transform_prints_files_rewritten_outside_typia_test.go (entry 1), so it
17
+ // answers manifest entry 2.
18
+ func init() { driver.RegisterPlugin(typiaCheckLoadProbe{}) }
19
+
20
+ // typiaCheckLoads counts driver.LoadProgram calls that selected the probe.
21
+ var typiaCheckLoads int
22
+
23
+ // typiaCheckValidSource is a source whose only typia call transforms cleanly.
24
+ const typiaCheckValidSource = `import typia from "typia";
25
+ export const isValue = (input: unknown): input is { value: number } =>
26
+ typia.is<{ value: number }>(input);
27
+ `
28
+
29
+ func typiaCheckWrite(t *testing.T, file, text string) {
30
+ t.Helper()
31
+ if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
32
+ t.Fatal(err)
33
+ }
34
+ if err := os.WriteFile(file, []byte(text), 0o644); err != nil {
35
+ t.Fatal(err)
36
+ }
37
+ }
38
+
39
+ // typiaCheckLoadProbe is a linked SourcePreamblePlugin contributing no text.
40
+ // LoadProgram asks every linked plugin for its preamble once per load, so the
41
+ // calls count Program loads.
42
+ type typiaCheckLoadProbe struct{}
43
+
44
+ func (typiaCheckLoadProbe) SourcePreamble(driver.PluginContext) (string, error) {
45
+ typiaCheckLoads++
46
+ return "", nil
47
+ }
48
+
49
+ // TestTypiaCheckLoadsOneProgram verifies an analysis-only `check` answers from
50
+ // the one Program it loads, with the diagnostics and linked-hook outcome the
51
+ // emit lane would report.
52
+ //
53
+ // `check` used to load the project, diagnose it, then load it again with emit
54
+ // forced so typia's transformer could run inside the emit pipeline. The
55
+ // analysis now runs typia's transformer over the first Program, so it must
56
+ // still reach every file the emit lane transforms, including under
57
+ // emitDeclarationOnly, which the forced reload cleared, and still run the
58
+ // linked program hooks.
59
+ //
60
+ // 1. Select two linked ProgramPlugins and the load-counting probe.
61
+ // 2. Check a project with an invalid typia call, the same project under
62
+ // emitDeclarationOnly, a valid project and a failing linked hook.
63
+ // 3. Require one load each, the typia diagnostic, a clean pass and the hook's
64
+ // failure respectively.
65
+ //
66
+ // @evidence contracts/testing.md#behavioral-verification run("check") must report the typia diagnostic with its location, pass a valid project silently and surface a linked hook's error, each after exactly one LoadProgram; a forced-emit reload, a missed file or a skipped hook fails an assertion.
67
+ // @evidence contracts/testing.md#independent-expectations The authored generic typia.is call must fail at src/main.ts:3:9, the authored hook returns "authored hook failure", and one LoadProgram per invocation is the issue's acceptance criterion.
68
+ // @evidence contracts/testing.md#distinguishing-cases Invalid, emitDeclarationOnly-invalid, valid and hook-failure cases; the emitDeclarationOnly twin distinguishes a selection computed from the noEmit Program's own options, which would analyze nothing. Existing noEmit tests own manifest, verbose and allowImportingTsExtensions behavior.
69
+ // @evidence contracts/testing.md#execution-ownership The native Go runner discovers this unit test; linked plugins are selected with t.Setenv and the command runs in process through run.
70
+ func TestTypiaCheckLoadsOneProgram(t *testing.T) {
71
+ for _, tc := range []struct {
72
+ name string
73
+ declarationOnly bool
74
+ valid bool
75
+ hook string
76
+ status int
77
+ stderr string
78
+ }{
79
+ {name: "transform-failure", hook: "complete", status: 3, stderr: "src/main.ts:3:9 - error TS(typia.is):"},
80
+ {name: "declaration-only", declarationOnly: true, hook: "complete", status: 3, stderr: "src/main.ts:3:9 - error TS(typia.is):"},
81
+ {name: "valid", valid: true, hook: "complete", status: 0},
82
+ {name: "hook-failure", hook: "fail", status: 3, stderr: "ttsc-typia build: emit failed: authored hook failure"},
83
+ } {
84
+ t.Run(tc.name, func(t *testing.T) {
85
+ project := buildNoEmitDiagnosticProject(t, false)
86
+ if tc.declarationOnly {
87
+ config := filepath.Join(project, "tsconfig.json")
88
+ text, err := os.ReadFile(config)
89
+ if err != nil {
90
+ t.Fatal(err)
91
+ }
92
+ typiaCheckWrite(t, config, strings.Replace(string(text), `"declaration": true,`, `"declaration": true,
93
+ "emitDeclarationOnly": true,`, 1))
94
+ }
95
+ if tc.valid {
96
+ typiaCheckWrite(t, filepath.Join(project, "src", "main.ts"), typiaCheckValidSource)
97
+ }
98
+ typiaCheckWrite(t, filepath.Join(project, "external.txt"), "consumed\n")
99
+ payload, _ := json.Marshal([]driver.PluginEntry{
100
+ {Name: "observation-test", Stage: "transform", Config: map[string]any{"mode": tc.hook}},
101
+ {Name: "linked-edit", Stage: "transform", Config: map[string]any{}},
102
+ {Name: "load-probe", Stage: "transform", Config: map[string]any{}},
103
+ })
104
+ t.Setenv(driver.LinkedPluginsEnv, string(payload))
105
+ typiaCheckLoads = 0
106
+ out, errText, code := ttscTypiaTestCapture(func() int {
107
+ return run([]string{"check", "--cwd", project, "--tsconfig", "tsconfig.json"})
108
+ })
109
+ if code != tc.status || typiaCheckLoads != 1 {
110
+ t.Fatalf("check = %d after %d loads, want %d after one\nstdout=%s\nstderr=%s", code, typiaCheckLoads, tc.status, out, errText)
111
+ }
112
+ normalized := filepath.ToSlash(errText)
113
+ if tc.stderr == "" {
114
+ if strings.TrimSpace(out+errText) != "" {
115
+ t.Fatalf("a passing check printed output:\nstdout=%s\nstderr=%s", out, errText)
116
+ }
117
+ } else if !strings.Contains(normalized, tc.stderr) {
118
+ t.Fatalf("check lost %q:\n%s", tc.stderr, errText)
119
+ }
120
+ if tc.hook == "fail" && strings.Contains(normalized, "TS(typia") {
121
+ t.Fatalf("a failed linked hook must stop the analysis before typia runs:\n%s", errText)
122
+ }
123
+ })
124
+ }
125
+ }
package/native/go.mod CHANGED
@@ -2,7 +2,8 @@ module github.com/samchon/typia/packages/typia/native
2
2
 
3
3
  go 1.26
4
4
 
5
- // The supported ttsc floor (>= 0.37.0, including recorded environment inputs)
5
+ // The supported ttsc floor (>= 0.38.0, including driver.NewSessionFromProgram
6
+ // and Session.Contains for the resident check-serve command)
6
7
  // is enforced through typia's package.json peerDependency, not here: ttsc builds
7
8
  // this plugin from source on the user's machine and its buildSourcePlugin
8
9
  // generates `replace github.com/samchon/ttsc/packages/ttsc v0.0.0 =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typia",
3
- "version": "15.4.0",
3
+ "version": "15.5.0",
4
4
  "description": "Superfast runtime validators with only one line",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -43,11 +43,11 @@
43
43
  "homepage": "https://typia.io",
44
44
  "dependencies": {
45
45
  "randexp": "^0.5.3",
46
- "@typia/interface": "^15.4.0",
47
- "@typia/utils": "^15.4.0"
46
+ "@typia/interface": "^15.5.0",
47
+ "@typia/utils": "^15.5.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "ttsc": ">=0.37.0"
50
+ "ttsc": ">=0.38.0"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "ttsc": {
@@ -58,7 +58,7 @@
58
58
  "@types/node": "^25.3.0",
59
59
  "rimraf": "^6.1.2",
60
60
  "rolldown": "^1.1.5",
61
- "ttsc": "^0.37.0",
61
+ "ttsc": "^0.38.0",
62
62
  "typescript": "7.1.0-dev.20261020.3"
63
63
  },
64
64
  "sideEffects": false,
package/src/transform.ts CHANGED
@@ -15,7 +15,9 @@ import type { ITtscPlugin, ITtscPluginFactoryContext } from "ttsc";
15
15
  * and compiler-owned output provenance for ttsc's checked runtime reuse
16
16
  * protocol. Its only variable reads outside ttsc's own namespace go through the
17
17
  * program's recorded `Env`, so it declares `environmentInputs` and ttsc keys
18
- * its outputs by the variables it read instead of the whole environment.
18
+ * its outputs by the variables it read instead of the whole environment. The
19
+ * host also answers `check-serve`, so it declares `residentCheck` and a `ttsc
20
+ * --noEmit --watch` keeps one typia process and its program across saves.
19
21
  *
20
22
  * @param context Plugin factory context of ttsc
21
23
  *
@@ -44,6 +46,7 @@ export function createTtscPlugin(
44
46
  emitObservations: true,
45
47
  emitProvenance: true,
46
48
  environmentInputs: true,
49
+ residentCheck: true,
47
50
  },
48
51
  };
49
52
  }