typia 15.3.1 → 15.4.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.
- package/lib/transform.d.ts +3 -1
- package/lib/transform.js +4 -1
- package/lib/transform.js.map +1 -1
- package/lib/transform.mjs +5 -2
- package/lib/transform.mjs.map +1 -1
- package/native/cmd/ttsc-typia/transform.go +14 -5
- package/native/cmd/ttsc-typia/transform_output_default_test.go +67 -0
- package/native/go.mod +1 -1
- package/package.json +5 -5
- package/src/transform.ts +4 -1
package/lib/transform.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ import type { ITtscPlugin, ITtscPluginFactoryContext } from "ttsc";
|
|
|
10
10
|
* resolution, so an empty hostInputHashes declaration permits safe descriptor
|
|
11
11
|
* replay. The native build host supplies generation-owned input observations
|
|
12
12
|
* and compiler-owned output provenance for ttsc's checked runtime reuse
|
|
13
|
-
* protocol.
|
|
13
|
+
* protocol. Its only variable reads outside ttsc's own namespace go through the
|
|
14
|
+
* program's recorded `Env`, so it declares `environmentInputs` and ttsc keys
|
|
15
|
+
* its outputs by the variables it read instead of the whole environment.
|
|
14
16
|
*
|
|
15
17
|
* @param context Plugin factory context of ttsc
|
|
16
18
|
*
|
package/lib/transform.js
CHANGED
|
@@ -17,7 +17,9 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
17
17
|
* resolution, so an empty hostInputHashes declaration permits safe descriptor
|
|
18
18
|
* replay. The native build host supplies generation-owned input observations
|
|
19
19
|
* and compiler-owned output provenance for ttsc's checked runtime reuse
|
|
20
|
-
* protocol.
|
|
20
|
+
* protocol. Its only variable reads outside ttsc's own namespace go through the
|
|
21
|
+
* program's recorded `Env`, so it declares `environmentInputs` and ttsc keys
|
|
22
|
+
* its outputs by the variables it read instead of the whole environment.
|
|
21
23
|
*
|
|
22
24
|
* @param context Plugin factory context of ttsc
|
|
23
25
|
*
|
|
@@ -41,6 +43,7 @@ function createTtscPlugin(context) {
|
|
|
41
43
|
capabilities: {
|
|
42
44
|
emitObservations: true,
|
|
43
45
|
emitProvenance: true,
|
|
46
|
+
environmentInputs: true,
|
|
44
47
|
},
|
|
45
48
|
};
|
|
46
49
|
}
|
package/lib/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA4C;AAC5C,0DAA6B;AAG7B
|
|
1
|
+
{"version":3,"file":"transform.js","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA4C;AAC5C,0DAA6B;AAG7B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,0BACE,OAAkC;IAElC,oEAAoE;IACpE,wEAAwE;IACxE,2EAA2E;IAC3E,MAAM,WAAW,GAAG,IAAA,2BAAa,EAC/B,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAC/C,CAAC;IACF,MAAM,IAAI,GAAW,mBAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAC7E,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,mBAAI,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC;QACzD,eAAe,EAAE,EAAE;QACnB,YAAY,EAAE;YACZ,gBAAgB,EAAE,IAAI;YACtB,cAAc,EAAE,IAAI;YACpB,iBAAiB,EAAE,IAAI;SACxB;KACF,CAAC;AACJ,CAAC;kBAEc,gBAAgB"}
|
package/lib/transform.mjs
CHANGED
|
@@ -12,7 +12,9 @@ import path from "node:path";
|
|
|
12
12
|
* resolution, so an empty hostInputHashes declaration permits safe descriptor
|
|
13
13
|
* replay. The native build host supplies generation-owned input observations
|
|
14
14
|
* and compiler-owned output provenance for ttsc's checked runtime reuse
|
|
15
|
-
* protocol.
|
|
15
|
+
* protocol. Its only variable reads outside ttsc's own namespace go through the
|
|
16
|
+
* program's recorded `Env`, so it declares `environmentInputs` and ttsc keys
|
|
17
|
+
* its outputs by the variables it read instead of the whole environment.
|
|
16
18
|
*
|
|
17
19
|
* @param context Plugin factory context of ttsc
|
|
18
20
|
*
|
|
@@ -32,7 +34,8 @@ function createTtscPlugin(context) {
|
|
|
32
34
|
hostInputHashes: {},
|
|
33
35
|
capabilities: {
|
|
34
36
|
emitObservations: true,
|
|
35
|
-
emitProvenance: true
|
|
37
|
+
emitProvenance: true,
|
|
38
|
+
environmentInputs: true
|
|
36
39
|
}
|
|
37
40
|
};
|
|
38
41
|
}
|
package/lib/transform.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.mjs","names":[],"sources":["../src/transform.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport type { ITtscPlugin, ITtscPluginFactoryContext } from \"ttsc\";\n\n/**\n * Describe typia's native transform to ttsc.\n *\n * Ttsc loads this file as an ES module, where `require` is unavailable, so a\n * resolver is anchored on the consuming project to find typia's own package\n * root. The returned descriptor names the plugin and the Go command under\n * `native/cmd/ttsc-typia`; the transform itself is not written in TypeScript.\n * No file is read outside the module graph. Ttsc records the package\n * resolution, so an empty hostInputHashes declaration permits safe descriptor\n * replay. The native build host supplies generation-owned input observations\n * and compiler-owned output provenance for ttsc's checked runtime reuse\n * protocol.\n *\n * @param context Plugin factory context of ttsc\n *\n * @returns Plugin descriptor\n *\n * @evidence contracts/common.md#principled-implementation The ttsc loader runs this file as an ES module where `require` is absent, so the function builds a CommonJS resolver anchored at the consuming project and resolves typia's own `package.json`, whose directory holds the native sources. No external file is read; ttsc records that module lookup and invalidates descriptor replay when its module graph or factory inputs change. The descriptor names the plugin and Go command under `native/cmd/ttsc-typia`.\n * @evidence contracts/common.md#clear-and-simple-design One function returns the plugin name, Go source, supported native protocols and external-input declaration; the default export repeats the same function for loaders that read it.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The package root comes from the installed typia through the supported resolver and not from path substrings, so it works for npm consumers and workspaces alike; the transform itself stays in Go.\n * @evidence contracts/common.md#meaningful-documentation A comment explains the purpose, the ESM resolution reason and the descriptor.\n */\nexport function createTtscPlugin(\n context: ITtscPluginFactoryContext,\n): ITtscPlugin {\n // ttsc loads this descriptor as ESM, where the ambient `require` is\n // unavailable; anchor a CJS resolver on the consuming project to locate\n // typia's own package root (not the project root, which has no `native/`).\n const requireFrom = createRequire(\n path.join(context.projectRoot, \"package.json\"),\n );\n const root: string = path.dirname(requireFrom.resolve(\"typia/package.json\"));\n return {\n name: \"typia\",\n source: path.resolve(root, \"native\", \"cmd\", \"ttsc-typia\"),\n hostInputHashes: {},\n capabilities: {\n emitObservations: true,\n emitProvenance: true,\n },\n };\n}\n\nexport default createTtscPlugin;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform.mjs","names":[],"sources":["../src/transform.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport type { ITtscPlugin, ITtscPluginFactoryContext } from \"ttsc\";\n\n/**\n * Describe typia's native transform to ttsc.\n *\n * Ttsc loads this file as an ES module, where `require` is unavailable, so a\n * resolver is anchored on the consuming project to find typia's own package\n * root. The returned descriptor names the plugin and the Go command under\n * `native/cmd/ttsc-typia`; the transform itself is not written in TypeScript.\n * No file is read outside the module graph. Ttsc records the package\n * resolution, so an empty hostInputHashes declaration permits safe descriptor\n * replay. The native build host supplies generation-owned input observations\n * and compiler-owned output provenance for ttsc's checked runtime reuse\n * protocol. Its only variable reads outside ttsc's own namespace go through the\n * program's recorded `Env`, so it declares `environmentInputs` and ttsc keys\n * its outputs by the variables it read instead of the whole environment.\n *\n * @param context Plugin factory context of ttsc\n *\n * @returns Plugin descriptor\n *\n * @evidence contracts/common.md#principled-implementation The ttsc loader runs this file as an ES module where `require` is absent, so the function builds a CommonJS resolver anchored at the consuming project and resolves typia's own `package.json`, whose directory holds the native sources. No external file is read; ttsc records that module lookup and invalidates descriptor replay when its module graph or factory inputs change. The descriptor names the plugin and Go command under `native/cmd/ttsc-typia`.\n * @evidence contracts/common.md#clear-and-simple-design One function returns the plugin name, Go source, supported native protocols and external-input declaration; the default export repeats the same function for loaders that read it.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The package root comes from the installed typia through the supported resolver and not from path substrings, so it works for npm consumers and workspaces alike; the transform itself stays in Go.\n * @evidence contracts/common.md#meaningful-documentation A comment explains the purpose, the ESM resolution reason and the descriptor.\n */\nexport function createTtscPlugin(\n context: ITtscPluginFactoryContext,\n): ITtscPlugin {\n // ttsc loads this descriptor as ESM, where the ambient `require` is\n // unavailable; anchor a CJS resolver on the consuming project to locate\n // typia's own package root (not the project root, which has no `native/`).\n const requireFrom = createRequire(\n path.join(context.projectRoot, \"package.json\"),\n );\n const root: string = path.dirname(requireFrom.resolve(\"typia/package.json\"));\n return {\n name: \"typia\",\n source: path.resolve(root, \"native\", \"cmd\", \"ttsc-typia\"),\n hostInputHashes: {},\n capabilities: {\n emitObservations: true,\n emitProvenance: true,\n environmentInputs: true,\n },\n };\n}\n\nexport default createTtscPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,iBACd,SACa;CAIb,MAAM,cAAc,cAClB,KAAK,KAAK,QAAQ,aAAa,cAAc,CAC/C;CACA,MAAM,OAAe,KAAK,QAAQ,YAAY,QAAQ,oBAAoB,CAAC;CAC3E,OAAO;EACL,MAAM;EACN,QAAQ,KAAK,QAAQ,MAAM,UAAU,OAAO,YAAY;EACxD,iBAAiB,CAAC;EAClB,cAAc;GACZ,kBAAkB;GAClB,gBAAgB;GAChB,mBAAmB;EACrB;CACF;AACF"}
|
|
@@ -41,7 +41,7 @@ func runTransform(args []string) int {
|
|
|
41
41
|
cwdOverride := fs.String("cwd", "", "override the working directory")
|
|
42
42
|
out := fs.String("out", "", "write single-file output to PATH instead of stdout")
|
|
43
43
|
rewriteMode := fs.String("rewrite-mode", "typia", "native rewrite backend id")
|
|
44
|
-
output := fs.String("output",
|
|
44
|
+
output := fs.String("output", "", "single-file output kind: js or ts (default: TYPIA_TTSC_TRANSFORM_OUTPUT, else ts)")
|
|
45
45
|
pluginsJSON := fs.String("plugins-json", "", "ordered ttsc plugin payload")
|
|
46
46
|
if err := fs.Parse(args); err != nil {
|
|
47
47
|
return 2
|
|
@@ -50,7 +50,7 @@ func runTransform(args []string) int {
|
|
|
50
50
|
fmt.Fprintf(stderr, "ttsc-typia transform: unknown --rewrite-mode value %q\n", *rewriteMode)
|
|
51
51
|
return 2
|
|
52
52
|
}
|
|
53
|
-
if *output != "js" && *output != "ts" {
|
|
53
|
+
if *output != "" && *output != "js" && *output != "ts" {
|
|
54
54
|
fmt.Fprintf(stderr, "ttsc-typia transform: unknown --output value %q\n", *output)
|
|
55
55
|
return 2
|
|
56
56
|
}
|
|
@@ -119,8 +119,12 @@ func runTransform(args []string) int {
|
|
|
119
119
|
fmt.Fprintf(stderr, "ttsc-typia transform: source file is not in program: %s\n", absFile)
|
|
120
120
|
return 2
|
|
121
121
|
}
|
|
122
|
+
kind := *output
|
|
123
|
+
if kind == "" {
|
|
124
|
+
kind = defaultTransformOutput(prog)
|
|
125
|
+
}
|
|
122
126
|
return runTransformSingle(cwd, *out, &transformDiags, func() (string, int) {
|
|
123
|
-
if
|
|
127
|
+
if kind == "js" {
|
|
124
128
|
return transformSingleToJavaScript(prog, typiaTransform, target)
|
|
125
129
|
}
|
|
126
130
|
return transformFileToTypeScript(prog, typiaTransform, target), 0
|
|
@@ -377,8 +381,13 @@ func writeSingleOutput(text, outPath string) int {
|
|
|
377
381
|
return 0
|
|
378
382
|
}
|
|
379
383
|
|
|
380
|
-
|
|
381
|
-
|
|
384
|
+
// defaultTransformOutput is the single-file output kind when --output is not
|
|
385
|
+
// given: `TYPIA_TTSC_TRANSFORM_OUTPUT=js` selects JavaScript, anything else
|
|
386
|
+
// TypeScript. It is read through the program, which records the read as an
|
|
387
|
+
// input of this generation, so a host that reuses this output under another
|
|
388
|
+
// value sees the change; os.Getenv was recorded by nothing (samchon/ttsc#1852).
|
|
389
|
+
func defaultTransformOutput(prog *driver.Program) string {
|
|
390
|
+
if value, _ := prog.Env("TYPIA_TTSC_TRANSFORM_OUTPUT"); value == "js" {
|
|
382
391
|
return "js"
|
|
383
392
|
}
|
|
384
393
|
return "ts"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"os"
|
|
5
|
+
"path/filepath"
|
|
6
|
+
"strings"
|
|
7
|
+
"testing"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// TestTransformOutputDefaultFollowsTheRecordedVariable verifies the single-file
|
|
11
|
+
// output kind defaults to TYPIA_TTSC_TRANSFORM_OUTPUT read through the loaded
|
|
12
|
+
// program, and that an explicit --output still wins.
|
|
13
|
+
//
|
|
14
|
+
// The default was read with os.Getenv while flags were parsed, before any
|
|
15
|
+
// program existed, so nothing recorded it and a host reusing output across
|
|
16
|
+
// launches could not tell a changed value (samchon/ttsc#1852). The program's
|
|
17
|
+
// Env records the read as an input of the generation.
|
|
18
|
+
//
|
|
19
|
+
// 1. Transform one annotated declaration with the variable set to js and no
|
|
20
|
+
// --output: the annotation is gone.
|
|
21
|
+
// 2. Keep the variable at js and pass --output ts: the annotation stays.
|
|
22
|
+
// 3. Unset the variable: the annotation stays.
|
|
23
|
+
//
|
|
24
|
+
// @evidence contracts/testing.md#behavioral-verification The real transform command runs over a real program; the printed declaration shows which output kind ran.
|
|
25
|
+
// @evidence contracts/testing.md#independent-expectations TypeScript output keeps the authored `: number` annotation and JavaScript output drops it, independently of typia's rewriting.
|
|
26
|
+
// @evidence contracts/testing.md#distinguishing-cases The variable set, unset, and overridden by an explicit flag separate the default from the flag.
|
|
27
|
+
// @evidence contracts/testing.md#execution-ownership The native Go runner owns the temporary fixture and the in-process transform; t.Setenv restores the variable.
|
|
28
|
+
func TestTransformOutputDefaultFollowsTheRecordedVariable(t *testing.T) {
|
|
29
|
+
dir := ttscTypiaTestFixtureDirectory(t, "transform-output-default-")
|
|
30
|
+
src := filepath.Join(dir, "src")
|
|
31
|
+
if err := os.MkdirAll(src, 0o755); err != nil {
|
|
32
|
+
t.Fatalf("mkdir fixture src: %v", err)
|
|
33
|
+
}
|
|
34
|
+
if err := os.WriteFile(filepath.Join(dir, "tsconfig.json"), []byte(atomicIntersectionSchemaTSConfig), 0o644); err != nil {
|
|
35
|
+
t.Fatalf("write tsconfig: %v", err)
|
|
36
|
+
}
|
|
37
|
+
if err := os.WriteFile(filepath.Join(src, "main.ts"), []byte("export const answer: number = 42;\n"), 0o644); err != nil {
|
|
38
|
+
t.Fatalf("write source: %v", err)
|
|
39
|
+
}
|
|
40
|
+
transform := func(extra ...string) string {
|
|
41
|
+
t.Helper()
|
|
42
|
+
out, errText, code := ttscTypiaTestCapture(func() int {
|
|
43
|
+
return runTransform(append([]string{
|
|
44
|
+
"--cwd", dir,
|
|
45
|
+
"--tsconfig", "tsconfig.json",
|
|
46
|
+
"--file", "src/main.ts",
|
|
47
|
+
}, extra...))
|
|
48
|
+
})
|
|
49
|
+
if code != 0 {
|
|
50
|
+
t.Fatalf("transform failed: code=%d stderr=\n%s", code, errText)
|
|
51
|
+
}
|
|
52
|
+
return out
|
|
53
|
+
}
|
|
54
|
+
annotated := func(out string) bool { return strings.Contains(out, "answer: number") }
|
|
55
|
+
|
|
56
|
+
t.Setenv("TYPIA_TTSC_TRANSFORM_OUTPUT", "js")
|
|
57
|
+
if out := transform(); annotated(out) {
|
|
58
|
+
t.Fatalf("the variable selects JavaScript output:\n%s", out)
|
|
59
|
+
}
|
|
60
|
+
if out := transform("--output", "ts"); !annotated(out) {
|
|
61
|
+
t.Fatalf("an explicit --output ts wins over the variable:\n%s", out)
|
|
62
|
+
}
|
|
63
|
+
os.Unsetenv("TYPIA_TTSC_TRANSFORM_OUTPUT")
|
|
64
|
+
if out := transform(); !annotated(out) {
|
|
65
|
+
t.Fatalf("without the variable the output is TypeScript:\n%s", out)
|
|
66
|
+
}
|
|
67
|
+
}
|
package/native/go.mod
CHANGED
|
@@ -2,7 +2,7 @@ module github.com/samchon/typia/packages/typia/native
|
|
|
2
2
|
|
|
3
3
|
go 1.26
|
|
4
4
|
|
|
5
|
-
// The supported ttsc floor (>= 0.
|
|
5
|
+
// The supported ttsc floor (>= 0.37.0, including recorded environment inputs)
|
|
6
6
|
// is enforced through typia's package.json peerDependency, not here: ttsc builds
|
|
7
7
|
// this plugin from source on the user's machine and its buildSourcePlugin
|
|
8
8
|
// 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.
|
|
3
|
+
"version": "15.4.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.
|
|
47
|
-
"@typia/utils": "^15.
|
|
46
|
+
"@typia/interface": "^15.4.0",
|
|
47
|
+
"@typia/utils": "^15.4.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"ttsc": ">=0.
|
|
50
|
+
"ttsc": ">=0.37.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.
|
|
61
|
+
"ttsc": "^0.37.0",
|
|
62
62
|
"typescript": "7.1.0-dev.20261020.3"
|
|
63
63
|
},
|
|
64
64
|
"sideEffects": false,
|
package/src/transform.ts
CHANGED
|
@@ -13,7 +13,9 @@ import type { ITtscPlugin, ITtscPluginFactoryContext } from "ttsc";
|
|
|
13
13
|
* resolution, so an empty hostInputHashes declaration permits safe descriptor
|
|
14
14
|
* replay. The native build host supplies generation-owned input observations
|
|
15
15
|
* and compiler-owned output provenance for ttsc's checked runtime reuse
|
|
16
|
-
* protocol.
|
|
16
|
+
* protocol. Its only variable reads outside ttsc's own namespace go through the
|
|
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.
|
|
17
19
|
*
|
|
18
20
|
* @param context Plugin factory context of ttsc
|
|
19
21
|
*
|
|
@@ -41,6 +43,7 @@ export function createTtscPlugin(
|
|
|
41
43
|
capabilities: {
|
|
42
44
|
emitObservations: true,
|
|
43
45
|
emitProvenance: true,
|
|
46
|
+
environmentInputs: true,
|
|
44
47
|
},
|
|
45
48
|
};
|
|
46
49
|
}
|