zod-to-x 2.2.1-dev.0 → 2.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.
@@ -37,28 +37,29 @@ class Zod2Ts extends core_1.Zod2X {
37
37
  return `${namespace}.${typeName}`;
38
38
  }
39
39
  addExtendedType(name, parentNamespace, aliasOf, opt) {
40
- var _a;
40
+ var _a, _b;
41
41
  const extendedType = (opt === null || opt === void 0 ? void 0 : opt.isInternal)
42
42
  ? aliasOf
43
43
  : this.getTypeFromExternalNamespace(parentNamespace, aliasOf);
44
44
  const templates = (_a = opt === null || opt === void 0 ? void 0 : opt.templates) !== null && _a !== void 0 ? _a : "";
45
+ const declaredName = `${name}${(_b = opt === null || opt === void 0 ? void 0 : opt.declaredTemplates) !== null && _b !== void 0 ? _b : ""}`;
45
46
  if ((opt === null || opt === void 0 ? void 0 : opt.type) === "alias") {
46
- this.push0(`export type ${name} = ${extendedType}${templates};\n`);
47
+ this.push0(`export type ${declaredName} = ${extendedType}${templates};\n`);
47
48
  }
48
49
  else if (this.opt.outType === "class") {
49
50
  if ((opt === null || opt === void 0 ? void 0 : opt.type) === "d-union") {
50
- this.push0(`export type ${name} = ${extendedType}${templates};\n`);
51
+ this.push0(`export type ${declaredName} = ${extendedType}${templates};\n`);
51
52
  }
52
53
  else {
53
- this.push0(`export class ${name} extends ${extendedType}${templates} {}\n`);
54
+ this.push0(`export class ${declaredName} extends ${extendedType}${templates} {}\n`);
54
55
  }
55
56
  }
56
57
  else {
57
58
  if ((opt === null || opt === void 0 ? void 0 : opt.type) === "union" || (opt === null || opt === void 0 ? void 0 : opt.type) === "d-union") {
58
- this.push0(`export type ${name} = ${extendedType}${templates};\n`);
59
+ this.push0(`export type ${declaredName} = ${extendedType}${templates};\n`);
59
60
  }
60
61
  else {
61
- this.push0(`export interface ${name} extends ${extendedType}${templates} {}\n`);
62
+ this.push0(`export interface ${declaredName} extends ${extendedType}${templates} {}\n`);
62
63
  }
63
64
  }
64
65
  }
@@ -80,12 +81,24 @@ class Zod2Ts extends core_1.Zod2X {
80
81
  ">");
81
82
  }
82
83
  }
84
+ /**
85
+ * Emits an alias/extension declaration early when a node references another layered type.
86
+ * It preserves concrete template translations and falls back to declared templates (e.g. <T>)
87
+ * for aliases of generic templates.
88
+ */
83
89
  checkExtendedTypeInclusion(data, type) {
90
+ const declaredTemplatesFallback = data instanceof core_1.ASTObject && data.templates.size > 0
91
+ ? `<${[...data.templates].join(", ")}>`
92
+ : undefined;
93
+ const translatedTemplates = this.getGenericTemplatesTranslation(data);
94
+ const templates = translatedTemplates || declaredTemplatesFallback;
95
+ const declaredTemplates = translatedTemplates ? undefined : declaredTemplatesFallback;
84
96
  if (this.isExternalTypeImport(data)) {
85
97
  if (data.aliasOf) {
86
98
  this.addExtendedType(data.name, data.parentNamespace, data.aliasOf, {
87
99
  type,
88
- templates: this.getGenericTemplatesTranslation(data),
100
+ templates,
101
+ declaredTemplates,
89
102
  });
90
103
  this.addExternalTypeImport(data);
91
104
  }
@@ -95,7 +108,8 @@ class Zod2Ts extends core_1.Zod2X {
95
108
  this.addExtendedType(data.name, data.parentNamespace, data.aliasOf, {
96
109
  type,
97
110
  isInternal: true,
98
- templates: this.getGenericTemplatesTranslation(data),
111
+ templates,
112
+ declaredTemplates,
99
113
  });
100
114
  return true;
101
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-to-x",
3
- "version": "2.2.1-dev.0",
3
+ "version": "2.4.0",
4
4
  "description": "Multi language types generation from Zod schemas.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -11,10 +11,13 @@
11
11
  "build": "npm run clear_dist && tsc && tsc-alias",
12
12
  "build:debug": "npm run clear_dist && tsc --project tsconfig.dev.json && tsc-alias",
13
13
  "format:check": "prettier --check .",
14
+ "swap": "npm install && npm run build",
14
15
  "test": "find ./test -name \"err-*\" -delete && vitest --run",
15
16
  "test:cpp": "bash ./test/test_zod2cpp/test_cpp.sh",
16
17
  "test:py": "bash ./test/test_zod2py/test_py.sh",
17
- "test:all": "npm run test:cpp && npm run test:py",
18
+ "test:go": "bash ./test/test_zod2go/test_go.sh",
19
+ "test:dart": "bash ./test/test_zod2dart/test_dart.sh",
20
+ "test:all": "npm run test:cpp && npm run test:py && npm run test:go && npm run test:dart",
18
21
  "ts-run": "ts-node -r tsconfig-paths/register",
19
22
  "prepare": "husky"
20
23
  },
@@ -29,7 +32,7 @@
29
32
  "type",
30
33
  "generator",
31
34
  "zod-to-cpp",
32
- "zpd-to-c++",
35
+ "zod-to-c++",
33
36
  "zod-to-ts",
34
37
  "zod-to-typescript",
35
38
  "typescript",
@@ -59,7 +62,7 @@
59
62
  "husky": "^9.1.7",
60
63
  "lint-staged": "^15.2.11",
61
64
  "prettier": "^3.4.2",
62
- "protobufjs": "7.4.0",
65
+ "protobufjs": "7.6.5",
63
66
  "ts-node": "^10.9.2",
64
67
  "tsc-alias": "^1.8.10",
65
68
  "tsconfig-paths": "4.2.0",