@rexeus/typeweaver-zod-to-ts 0.3.1 → 0.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/dist/index.cjs +101 -130
- package/dist/index.js +5 -53
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1,197 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
TsTypeNode: () => TsTypeNode,
|
|
24
|
-
TsTypePrinter: () => TsTypePrinter
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var typescript = require('typescript');
|
|
4
|
+
var core = require('zod/v4/core');
|
|
27
5
|
|
|
28
6
|
// src/TsTypeGenerator.ts
|
|
29
|
-
var import_typescript = require("typescript");
|
|
30
|
-
var import_core = require("zod/v4/core");
|
|
31
7
|
var TsTypeNode = class _TsTypeNode {
|
|
32
8
|
static fromZod(zodType) {
|
|
33
|
-
if (zodType instanceof
|
|
9
|
+
if (zodType instanceof core.$ZodString) {
|
|
34
10
|
return _TsTypeNode.fromZodString(zodType);
|
|
35
11
|
}
|
|
36
|
-
if (zodType instanceof
|
|
12
|
+
if (zodType instanceof core.$ZodNumber) {
|
|
37
13
|
return _TsTypeNode.fromZodNumber(zodType);
|
|
38
14
|
}
|
|
39
|
-
if (zodType instanceof
|
|
15
|
+
if (zodType instanceof core.$ZodBigInt) {
|
|
40
16
|
return _TsTypeNode.fromZodBigInt(zodType);
|
|
41
17
|
}
|
|
42
|
-
if (zodType instanceof
|
|
18
|
+
if (zodType instanceof core.$ZodBoolean) {
|
|
43
19
|
return _TsTypeNode.fromZodBoolean(zodType);
|
|
44
20
|
}
|
|
45
|
-
if (zodType instanceof
|
|
21
|
+
if (zodType instanceof core.$ZodDate) {
|
|
46
22
|
return _TsTypeNode.fromZodDate(zodType);
|
|
47
23
|
}
|
|
48
|
-
if (zodType instanceof
|
|
24
|
+
if (zodType instanceof core.$ZodSymbol) {
|
|
49
25
|
return _TsTypeNode.fromZodSymbol(zodType);
|
|
50
26
|
}
|
|
51
|
-
if (zodType instanceof
|
|
27
|
+
if (zodType instanceof core.$ZodUndefined) {
|
|
52
28
|
return _TsTypeNode.fromZodUndefined(zodType);
|
|
53
29
|
}
|
|
54
|
-
if (zodType instanceof
|
|
30
|
+
if (zodType instanceof core.$ZodNullable) {
|
|
55
31
|
return _TsTypeNode.fromZodNullable(zodType);
|
|
56
32
|
}
|
|
57
|
-
if (zodType instanceof
|
|
33
|
+
if (zodType instanceof core.$ZodNull) {
|
|
58
34
|
return _TsTypeNode.fromZodNull(zodType);
|
|
59
35
|
}
|
|
60
|
-
if (zodType instanceof
|
|
36
|
+
if (zodType instanceof core.$ZodAny) {
|
|
61
37
|
return _TsTypeNode.fromZodAny(zodType);
|
|
62
38
|
}
|
|
63
|
-
if (zodType instanceof
|
|
39
|
+
if (zodType instanceof core.$ZodUnknown) {
|
|
64
40
|
return _TsTypeNode.fromZodUnknown(zodType);
|
|
65
41
|
}
|
|
66
|
-
if (zodType instanceof
|
|
42
|
+
if (zodType instanceof core.$ZodNever) {
|
|
67
43
|
return _TsTypeNode.fromZodNever(zodType);
|
|
68
44
|
}
|
|
69
|
-
if (zodType instanceof
|
|
45
|
+
if (zodType instanceof core.$ZodVoid) {
|
|
70
46
|
return _TsTypeNode.fromZodVoid(zodType);
|
|
71
47
|
}
|
|
72
|
-
if (zodType instanceof
|
|
48
|
+
if (zodType instanceof core.$ZodArray) {
|
|
73
49
|
return _TsTypeNode.fromZodArray(zodType);
|
|
74
50
|
}
|
|
75
|
-
if (zodType instanceof
|
|
51
|
+
if (zodType instanceof core.$ZodObject) {
|
|
76
52
|
return _TsTypeNode.fromZodObject(zodType);
|
|
77
53
|
}
|
|
78
|
-
if (zodType instanceof
|
|
54
|
+
if (zodType instanceof core.$ZodUnion) {
|
|
79
55
|
return _TsTypeNode.fromZodUnion(zodType);
|
|
80
56
|
}
|
|
81
|
-
if (zodType instanceof
|
|
57
|
+
if (zodType instanceof core.$ZodIntersection) {
|
|
82
58
|
return _TsTypeNode.fromZodIntersection(zodType);
|
|
83
59
|
}
|
|
84
|
-
if (zodType instanceof
|
|
60
|
+
if (zodType instanceof core.$ZodTuple) {
|
|
85
61
|
return _TsTypeNode.fromZodTuple(zodType);
|
|
86
62
|
}
|
|
87
|
-
if (zodType instanceof
|
|
63
|
+
if (zodType instanceof core.$ZodRecord) {
|
|
88
64
|
return _TsTypeNode.fromZodRecord(zodType);
|
|
89
65
|
}
|
|
90
|
-
if (zodType instanceof
|
|
66
|
+
if (zodType instanceof core.$ZodMap) {
|
|
91
67
|
return _TsTypeNode.fromZodMap(zodType);
|
|
92
68
|
}
|
|
93
|
-
if (zodType instanceof
|
|
69
|
+
if (zodType instanceof core.$ZodSet) {
|
|
94
70
|
return _TsTypeNode.fromZodSet(zodType);
|
|
95
71
|
}
|
|
96
|
-
if (zodType instanceof
|
|
72
|
+
if (zodType instanceof core.$ZodLiteral) {
|
|
97
73
|
if (!_TsTypeNode) {
|
|
98
74
|
throw new Error("ZodLiteral has no values");
|
|
99
75
|
}
|
|
100
76
|
return _TsTypeNode.fromZodLiteral(zodType);
|
|
101
77
|
}
|
|
102
|
-
if (zodType instanceof
|
|
78
|
+
if (zodType instanceof core.$ZodEnum) {
|
|
103
79
|
return _TsTypeNode.fromZodEnum(zodType);
|
|
104
80
|
}
|
|
105
|
-
if (zodType instanceof
|
|
81
|
+
if (zodType instanceof core.$ZodPromise) {
|
|
106
82
|
return _TsTypeNode.fromZodPromise(zodType);
|
|
107
83
|
}
|
|
108
|
-
if (zodType instanceof
|
|
84
|
+
if (zodType instanceof core.$ZodLazy) {
|
|
109
85
|
return _TsTypeNode.fromZodLazy(zodType);
|
|
110
86
|
}
|
|
111
|
-
if (zodType instanceof
|
|
87
|
+
if (zodType instanceof core.$ZodOptional) {
|
|
112
88
|
return _TsTypeNode.fromZodOptional(zodType);
|
|
113
89
|
}
|
|
114
|
-
if (zodType instanceof
|
|
90
|
+
if (zodType instanceof core.$ZodDefault) {
|
|
115
91
|
return _TsTypeNode.fromZodDefault(zodType);
|
|
116
92
|
}
|
|
117
|
-
if (zodType instanceof
|
|
93
|
+
if (zodType instanceof core.$ZodTemplateLiteral) {
|
|
118
94
|
return _TsTypeNode.fromZodTemplateLiteral(zodType);
|
|
119
95
|
}
|
|
120
|
-
if (zodType instanceof
|
|
96
|
+
if (zodType instanceof core.$ZodCustom) {
|
|
121
97
|
return _TsTypeNode.fromZodCustom(zodType);
|
|
122
98
|
}
|
|
123
|
-
if (zodType instanceof
|
|
99
|
+
if (zodType instanceof core.$ZodTransform) {
|
|
124
100
|
return _TsTypeNode.fromZodTransform(zodType);
|
|
125
101
|
}
|
|
126
|
-
if (zodType instanceof
|
|
102
|
+
if (zodType instanceof core.$ZodNonOptional) {
|
|
127
103
|
return _TsTypeNode.fromZodNonOptional(zodType);
|
|
128
104
|
}
|
|
129
|
-
if (zodType instanceof
|
|
105
|
+
if (zodType instanceof core.$ZodReadonly) {
|
|
130
106
|
return _TsTypeNode.fromZodReadonly(zodType);
|
|
131
107
|
}
|
|
132
|
-
if (zodType instanceof
|
|
108
|
+
if (zodType instanceof core.$ZodNaN) {
|
|
133
109
|
return _TsTypeNode.fromZodNaN(zodType);
|
|
134
110
|
}
|
|
135
|
-
if (zodType instanceof
|
|
111
|
+
if (zodType instanceof core.$ZodPipe) {
|
|
136
112
|
return _TsTypeNode.fromZodPipe(zodType);
|
|
137
113
|
}
|
|
138
|
-
if (zodType instanceof
|
|
114
|
+
if (zodType instanceof core.$ZodSuccess) {
|
|
139
115
|
return _TsTypeNode.fromZodSuccess(zodType);
|
|
140
116
|
}
|
|
141
|
-
if (zodType instanceof
|
|
117
|
+
if (zodType instanceof core.$ZodCatch) {
|
|
142
118
|
return _TsTypeNode.fromZodCatch(zodType);
|
|
143
119
|
}
|
|
144
|
-
if (zodType instanceof
|
|
120
|
+
if (zodType instanceof core.$ZodFile) {
|
|
145
121
|
return _TsTypeNode.fromZodFile(zodType);
|
|
146
122
|
}
|
|
147
|
-
return
|
|
123
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
148
124
|
}
|
|
149
125
|
static fromZodString(_zodString) {
|
|
150
|
-
return
|
|
126
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.StringKeyword);
|
|
151
127
|
}
|
|
152
128
|
static fromZodNumber(_zodNumber) {
|
|
153
|
-
return
|
|
129
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.NumberKeyword);
|
|
154
130
|
}
|
|
155
131
|
static fromZodBigInt(_zodBigInt) {
|
|
156
|
-
return
|
|
132
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.BigIntKeyword);
|
|
157
133
|
}
|
|
158
134
|
static fromZodBoolean(_zodBoolean) {
|
|
159
|
-
return
|
|
135
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.BooleanKeyword);
|
|
160
136
|
}
|
|
161
137
|
static fromZodDate(_zodDate) {
|
|
162
|
-
return
|
|
138
|
+
return typescript.factory.createTypeReferenceNode(typescript.factory.createIdentifier("Date"));
|
|
163
139
|
}
|
|
164
140
|
static fromZodSymbol(_zodSymbol) {
|
|
165
|
-
return
|
|
141
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.SymbolKeyword);
|
|
166
142
|
}
|
|
167
143
|
static fromZodUndefined(_zodUndefined) {
|
|
168
|
-
return
|
|
144
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UndefinedKeyword);
|
|
169
145
|
}
|
|
170
146
|
static fromZodNullable(zodNullable) {
|
|
171
147
|
const innerType = _TsTypeNode.fromZod(zodNullable._zod.def.innerType);
|
|
172
|
-
return
|
|
148
|
+
return typescript.factory.createUnionTypeNode([
|
|
173
149
|
innerType,
|
|
174
|
-
|
|
150
|
+
typescript.factory.createLiteralTypeNode(typescript.factory.createNull())
|
|
175
151
|
]);
|
|
176
152
|
}
|
|
177
153
|
static fromZodNull(_zodNull) {
|
|
178
|
-
return
|
|
154
|
+
return typescript.factory.createLiteralTypeNode(typescript.factory.createNull());
|
|
179
155
|
}
|
|
180
156
|
static fromZodAny(_zodAny) {
|
|
181
|
-
return
|
|
157
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.AnyKeyword);
|
|
182
158
|
}
|
|
183
159
|
static fromZodUnknown(_zodUnknown) {
|
|
184
|
-
return
|
|
160
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
185
161
|
}
|
|
186
162
|
static fromZodNever(_zodNever) {
|
|
187
|
-
return
|
|
163
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.NeverKeyword);
|
|
188
164
|
}
|
|
189
165
|
static fromZodVoid(_zodVoid) {
|
|
190
|
-
return
|
|
166
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.VoidKeyword);
|
|
191
167
|
}
|
|
192
168
|
static fromZodArray(zodArray) {
|
|
193
169
|
const innerType = _TsTypeNode.fromZod(zodArray._zod.def.element);
|
|
194
|
-
return
|
|
170
|
+
return typescript.factory.createArrayTypeNode(innerType);
|
|
195
171
|
}
|
|
196
172
|
static fromZodObject(zodObject) {
|
|
197
173
|
const entries = Object.entries(zodObject._zod.def.shape);
|
|
@@ -207,33 +183,33 @@ var TsTypeNode = class _TsTypeNode {
|
|
|
207
183
|
}
|
|
208
184
|
const { type: nextZodNodeTypeName } = nextZodNode._zod?.def ?? {};
|
|
209
185
|
const isOptional = nextZodNodeTypeName === "optional";
|
|
210
|
-
const propertySignature =
|
|
186
|
+
const propertySignature = typescript.factory.createPropertySignature(
|
|
211
187
|
void 0,
|
|
212
188
|
_TsTypeNode.createTsAstPropertyKey(key),
|
|
213
|
-
isOptional ?
|
|
189
|
+
isOptional ? typescript.factory.createToken(typescript.SyntaxKind.QuestionToken) : void 0,
|
|
214
190
|
type
|
|
215
191
|
);
|
|
216
192
|
return propertySignature;
|
|
217
193
|
});
|
|
218
|
-
return
|
|
194
|
+
return typescript.factory.createTypeLiteralNode(members);
|
|
219
195
|
}
|
|
220
196
|
static fromZodUnion(zodUnion) {
|
|
221
197
|
const options = zodUnion._zod.def.options.map(_TsTypeNode.fromZod);
|
|
222
|
-
return
|
|
198
|
+
return typescript.factory.createUnionTypeNode(options);
|
|
223
199
|
}
|
|
224
200
|
static fromZodIntersection(zodIntersection) {
|
|
225
201
|
const left = _TsTypeNode.fromZod(zodIntersection._zod.def.left);
|
|
226
202
|
const right = _TsTypeNode.fromZod(zodIntersection._zod.def.right);
|
|
227
|
-
return
|
|
203
|
+
return typescript.factory.createIntersectionTypeNode([left, right]);
|
|
228
204
|
}
|
|
229
205
|
static fromZodTuple(zodTuple) {
|
|
230
206
|
const elements = zodTuple._zod.def.items.map(_TsTypeNode.fromZod);
|
|
231
|
-
return
|
|
207
|
+
return typescript.factory.createTupleTypeNode(elements);
|
|
232
208
|
}
|
|
233
209
|
static fromZodRecord(zodRecord) {
|
|
234
210
|
const keyType = _TsTypeNode.fromZod(zodRecord._zod.def.keyType);
|
|
235
211
|
const valueType = _TsTypeNode.fromZod(zodRecord._zod.def.valueType);
|
|
236
|
-
return
|
|
212
|
+
return typescript.factory.createTypeReferenceNode(typescript.factory.createIdentifier("Record"), [
|
|
237
213
|
keyType,
|
|
238
214
|
valueType
|
|
239
215
|
]);
|
|
@@ -241,14 +217,14 @@ var TsTypeNode = class _TsTypeNode {
|
|
|
241
217
|
static fromZodMap(zodMap) {
|
|
242
218
|
const keyType = _TsTypeNode.fromZod(zodMap._zod.def.keyType);
|
|
243
219
|
const valueType = _TsTypeNode.fromZod(zodMap._zod.def.valueType);
|
|
244
|
-
return
|
|
220
|
+
return typescript.factory.createTypeReferenceNode(typescript.factory.createIdentifier("Map"), [
|
|
245
221
|
keyType,
|
|
246
222
|
valueType
|
|
247
223
|
]);
|
|
248
224
|
}
|
|
249
225
|
static fromZodSet(zodSet) {
|
|
250
226
|
const innerType = _TsTypeNode.fromZod(zodSet._zod.def.valueType);
|
|
251
|
-
return
|
|
227
|
+
return typescript.factory.createTypeReferenceNode(typescript.factory.createIdentifier("Set"), [
|
|
252
228
|
innerType
|
|
253
229
|
]);
|
|
254
230
|
}
|
|
@@ -258,58 +234,58 @@ var TsTypeNode = class _TsTypeNode {
|
|
|
258
234
|
}
|
|
259
235
|
const value = zodLiteral._zod.def.values[0];
|
|
260
236
|
if (typeof value === "string") {
|
|
261
|
-
return
|
|
237
|
+
return typescript.factory.createLiteralTypeNode(typescript.factory.createStringLiteral(value));
|
|
262
238
|
}
|
|
263
239
|
if (typeof value === "number") {
|
|
264
|
-
return
|
|
240
|
+
return typescript.factory.createLiteralTypeNode(typescript.factory.createNumericLiteral(value));
|
|
265
241
|
}
|
|
266
242
|
if (typeof value === "boolean") {
|
|
267
|
-
return
|
|
268
|
-
value ?
|
|
243
|
+
return typescript.factory.createLiteralTypeNode(
|
|
244
|
+
value ? typescript.factory.createTrue() : typescript.factory.createFalse()
|
|
269
245
|
);
|
|
270
246
|
}
|
|
271
247
|
if (typeof value === "bigint") {
|
|
272
|
-
return
|
|
273
|
-
|
|
248
|
+
return typescript.factory.createLiteralTypeNode(
|
|
249
|
+
typescript.factory.createBigIntLiteral(value.toString())
|
|
274
250
|
);
|
|
275
251
|
}
|
|
276
252
|
if (value === null) {
|
|
277
|
-
return
|
|
253
|
+
return typescript.factory.createLiteralTypeNode(typescript.factory.createNull());
|
|
278
254
|
}
|
|
279
255
|
if (value === void 0) {
|
|
280
|
-
return
|
|
256
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UndefinedKeyword);
|
|
281
257
|
}
|
|
282
258
|
throw new Error(`Unsupported literal type: ${typeof value}`);
|
|
283
259
|
}
|
|
284
260
|
static fromZodEnum(zodEnum) {
|
|
285
261
|
const entries = Object.entries(zodEnum._zod.def.entries);
|
|
286
262
|
const types = entries.map(([key, value]) => {
|
|
287
|
-
return
|
|
263
|
+
return typescript.factory.createLiteralTypeNode(typescript.factory.createStringLiteral(key));
|
|
288
264
|
});
|
|
289
|
-
return
|
|
265
|
+
return typescript.factory.createUnionTypeNode(types);
|
|
290
266
|
}
|
|
291
267
|
static fromZodPromise(zodPromise) {
|
|
292
268
|
const innerType = _TsTypeNode.fromZod(zodPromise._zod.def.innerType);
|
|
293
|
-
return
|
|
294
|
-
|
|
269
|
+
return typescript.factory.createTypeReferenceNode(
|
|
270
|
+
typescript.factory.createIdentifier("Promise"),
|
|
295
271
|
[innerType]
|
|
296
272
|
);
|
|
297
273
|
}
|
|
298
274
|
static fromZodLazy(_zodLazy) {
|
|
299
|
-
return
|
|
275
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
300
276
|
}
|
|
301
277
|
static fromZodOptional(zodOptional) {
|
|
302
278
|
const innerType = _TsTypeNode.fromZod(zodOptional._zod.def.innerType);
|
|
303
|
-
return
|
|
279
|
+
return typescript.factory.createUnionTypeNode([
|
|
304
280
|
innerType,
|
|
305
|
-
|
|
281
|
+
typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UndefinedKeyword)
|
|
306
282
|
]);
|
|
307
283
|
}
|
|
308
284
|
static fromZodDefault(zodDefault) {
|
|
309
285
|
const innerType = _TsTypeNode.fromZod(zodDefault._zod.def.innerType);
|
|
310
286
|
const filteredNodes = [];
|
|
311
287
|
innerType.forEachChild((node) => {
|
|
312
|
-
if (node.kind !==
|
|
288
|
+
if (node.kind !== typescript.SyntaxKind.UndefinedKeyword) {
|
|
313
289
|
filteredNodes.push(node);
|
|
314
290
|
}
|
|
315
291
|
});
|
|
@@ -317,34 +293,34 @@ var TsTypeNode = class _TsTypeNode {
|
|
|
317
293
|
return innerType;
|
|
318
294
|
}
|
|
319
295
|
static fromZodTemplateLiteral(_zodTemplateLiteral) {
|
|
320
|
-
return
|
|
296
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
321
297
|
}
|
|
322
298
|
static fromZodCustom(_zodCustom) {
|
|
323
|
-
return
|
|
299
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
324
300
|
}
|
|
325
301
|
static fromZodTransform(_zodTransform) {
|
|
326
|
-
return
|
|
302
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
327
303
|
}
|
|
328
304
|
static fromZodNonOptional(_zodNonOptional) {
|
|
329
|
-
return
|
|
305
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
330
306
|
}
|
|
331
307
|
static fromZodReadonly(_zodReadonly) {
|
|
332
|
-
return
|
|
308
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
333
309
|
}
|
|
334
310
|
static fromZodNaN(_zodNaN) {
|
|
335
|
-
return
|
|
311
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
336
312
|
}
|
|
337
313
|
static fromZodPipe(_zodPipe) {
|
|
338
|
-
return
|
|
314
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
339
315
|
}
|
|
340
316
|
static fromZodSuccess(_zodSuccess) {
|
|
341
|
-
return
|
|
317
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
342
318
|
}
|
|
343
319
|
static fromZodCatch(_zodCatch) {
|
|
344
|
-
return
|
|
320
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
345
321
|
}
|
|
346
322
|
static fromZodFile(_zodFile) {
|
|
347
|
-
return
|
|
323
|
+
return typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword);
|
|
348
324
|
}
|
|
349
325
|
/**
|
|
350
326
|
* Returns a TypeScript AST node representing the property key.
|
|
@@ -356,29 +332,24 @@ var TsTypeNode = class _TsTypeNode {
|
|
|
356
332
|
*/
|
|
357
333
|
static createTsAstPropertyKey(key) {
|
|
358
334
|
if (/^[$A-Z_a-z][\w$]*$/.test(key)) {
|
|
359
|
-
return
|
|
335
|
+
return typescript.factory.createIdentifier(key);
|
|
360
336
|
}
|
|
361
|
-
return
|
|
337
|
+
return typescript.factory.createStringLiteral(key);
|
|
362
338
|
}
|
|
363
339
|
};
|
|
364
|
-
|
|
365
|
-
// src/TsTypePrinter.ts
|
|
366
|
-
var import_typescript2 = require("typescript");
|
|
367
340
|
var TsTypePrinter = class {
|
|
368
341
|
static print(tsType) {
|
|
369
|
-
const sourceFile =
|
|
342
|
+
const sourceFile = typescript.createSourceFile(
|
|
370
343
|
"print.ts",
|
|
371
344
|
"",
|
|
372
|
-
|
|
345
|
+
typescript.ScriptTarget.Latest,
|
|
373
346
|
false,
|
|
374
|
-
|
|
347
|
+
typescript.ScriptKind.TS
|
|
375
348
|
);
|
|
376
|
-
const printer =
|
|
377
|
-
return printer.printNode(
|
|
349
|
+
const printer = typescript.createPrinter();
|
|
350
|
+
return printer.printNode(typescript.EmitHint.Unspecified, tsType, sourceFile);
|
|
378
351
|
}
|
|
379
352
|
};
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
TsTypePrinter
|
|
384
|
-
});
|
|
353
|
+
|
|
354
|
+
exports.TsTypeNode = TsTypeNode;
|
|
355
|
+
exports.TsTypePrinter = TsTypePrinter;
|
package/dist/index.js
CHANGED
|
@@ -1,44 +1,7 @@
|
|
|
1
|
+
import { factory, SyntaxKind, createSourceFile, ScriptTarget, ScriptKind, createPrinter, EmitHint } from 'typescript';
|
|
2
|
+
import { $ZodString, $ZodNumber, $ZodBigInt, $ZodBoolean, $ZodDate, $ZodSymbol, $ZodUndefined, $ZodNullable, $ZodNull, $ZodAny, $ZodUnknown, $ZodNever, $ZodVoid, $ZodArray, $ZodObject, $ZodUnion, $ZodIntersection, $ZodTuple, $ZodRecord, $ZodMap, $ZodSet, $ZodLiteral, $ZodEnum, $ZodPromise, $ZodLazy, $ZodOptional, $ZodDefault, $ZodTemplateLiteral, $ZodCustom, $ZodTransform, $ZodNonOptional, $ZodReadonly, $ZodNaN, $ZodPipe, $ZodSuccess, $ZodCatch, $ZodFile } from 'zod/v4/core';
|
|
3
|
+
|
|
1
4
|
// src/TsTypeGenerator.ts
|
|
2
|
-
import { factory, SyntaxKind } from "typescript";
|
|
3
|
-
import {
|
|
4
|
-
$ZodAny,
|
|
5
|
-
$ZodArray,
|
|
6
|
-
$ZodBigInt,
|
|
7
|
-
$ZodBoolean,
|
|
8
|
-
$ZodCatch,
|
|
9
|
-
$ZodCustom,
|
|
10
|
-
$ZodDate,
|
|
11
|
-
$ZodDefault,
|
|
12
|
-
$ZodEnum,
|
|
13
|
-
$ZodFile,
|
|
14
|
-
$ZodIntersection,
|
|
15
|
-
$ZodLazy,
|
|
16
|
-
$ZodLiteral,
|
|
17
|
-
$ZodMap,
|
|
18
|
-
$ZodNaN,
|
|
19
|
-
$ZodNever,
|
|
20
|
-
$ZodNonOptional,
|
|
21
|
-
$ZodNull,
|
|
22
|
-
$ZodNullable,
|
|
23
|
-
$ZodNumber,
|
|
24
|
-
$ZodObject,
|
|
25
|
-
$ZodOptional,
|
|
26
|
-
$ZodPipe,
|
|
27
|
-
$ZodPromise,
|
|
28
|
-
$ZodReadonly,
|
|
29
|
-
$ZodRecord,
|
|
30
|
-
$ZodSet,
|
|
31
|
-
$ZodString,
|
|
32
|
-
$ZodSuccess,
|
|
33
|
-
$ZodSymbol,
|
|
34
|
-
$ZodTemplateLiteral,
|
|
35
|
-
$ZodTransform,
|
|
36
|
-
$ZodTuple,
|
|
37
|
-
$ZodUndefined,
|
|
38
|
-
$ZodUnion,
|
|
39
|
-
$ZodUnknown,
|
|
40
|
-
$ZodVoid
|
|
41
|
-
} from "zod/v4/core";
|
|
42
5
|
var TsTypeNode = class _TsTypeNode {
|
|
43
6
|
static fromZod(zodType) {
|
|
44
7
|
if (zodType instanceof $ZodString) {
|
|
@@ -372,15 +335,6 @@ var TsTypeNode = class _TsTypeNode {
|
|
|
372
335
|
return factory.createStringLiteral(key);
|
|
373
336
|
}
|
|
374
337
|
};
|
|
375
|
-
|
|
376
|
-
// src/TsTypePrinter.ts
|
|
377
|
-
import {
|
|
378
|
-
createPrinter,
|
|
379
|
-
createSourceFile,
|
|
380
|
-
EmitHint,
|
|
381
|
-
ScriptKind,
|
|
382
|
-
ScriptTarget
|
|
383
|
-
} from "typescript";
|
|
384
338
|
var TsTypePrinter = class {
|
|
385
339
|
static print(tsType) {
|
|
386
340
|
const sourceFile = createSourceFile(
|
|
@@ -394,7 +348,5 @@ var TsTypePrinter = class {
|
|
|
394
348
|
return printer.printNode(EmitHint.Unspecified, tsType, sourceFile);
|
|
395
349
|
}
|
|
396
350
|
};
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
TsTypePrinter
|
|
400
|
-
};
|
|
351
|
+
|
|
352
|
+
export { TsTypeNode, TsTypePrinter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js":{"bytes":569,"imports":[],"format":"esm"},"src/TsTypeGenerator.ts":{"bytes":14164,"imports":[{"path":"typescript","kind":"import-statement","external":true},{"path":"zod/v4/core","kind":"import-statement","external":true},{"path":"/home/runner/work/typeweaver/typeweaver/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","kind":"import-statement","external":true}],"format":"esm"},"src/TsTypePrinter.ts":{"bytes":477,"imports":[{"path":"typescript","kind":"import-statement","external":true},{"path":"/home/runner/work/typeweaver/typeweaver/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":68,"imports":[{"path":"src/TsTypeGenerator.ts","kind":"import-statement","original":"./TsTypeGenerator"},{"path":"src/TsTypePrinter.ts","kind":"import-statement","original":"./TsTypePrinter"},{"path":"/home/runner/work/typeweaver/typeweaver/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.cjs":{"imports":[{"path":"typescript","kind":"import-statement","external":true},{"path":"zod/v4/core","kind":"import-statement","external":true},{"path":"typescript","kind":"import-statement","external":true}],"exports":["TsTypeNode","TsTypePrinter"],"entryPoint":"src/index.ts","inputs":{"src/TsTypeGenerator.ts":{"bytesInOutput":12275},"src/index.ts":{"bytesInOutput":0},"src/TsTypePrinter.ts":{"bytesInOutput":413}},"bytes":12781}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js":{"bytes":322,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true}],"format":"esm"},"src/TsTypeGenerator.ts":{"bytes":14164,"imports":[{"path":"typescript","kind":"import-statement","external":true},{"path":"zod/v4/core","kind":"import-statement","external":true},{"path":"/home/runner/work/typeweaver/typeweaver/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js","kind":"import-statement","external":true}],"format":"esm"},"src/TsTypePrinter.ts":{"bytes":477,"imports":[{"path":"typescript","kind":"import-statement","external":true},{"path":"/home/runner/work/typeweaver/typeweaver/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":68,"imports":[{"path":"src/TsTypeGenerator.ts","kind":"import-statement","original":"./TsTypeGenerator"},{"path":"src/TsTypePrinter.ts","kind":"import-statement","original":"./TsTypePrinter"},{"path":"/home/runner/work/typeweaver/typeweaver/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.js":{"imports":[{"path":"typescript","kind":"import-statement","external":true},{"path":"zod/v4/core","kind":"import-statement","external":true},{"path":"typescript","kind":"import-statement","external":true}],"exports":["TsTypeNode","TsTypePrinter"],"entryPoint":"src/index.ts","inputs":{"src/TsTypeGenerator.ts":{"bytesInOutput":12275},"src/index.ts":{"bytesInOutput":0},"src/TsTypePrinter.ts":{"bytesInOutput":413}},"bytes":12781}}}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexeus/typeweaver-zod-to-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Transforms Zod v4 schemas into precise TypeScript shapes. Powered by Typeweaver 🧵✨",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"main": "dist/index.cjs",
|
|
7
8
|
"module": "dist/index.js",
|
|
8
9
|
"types": "dist/index.d.ts",
|
|
@@ -48,10 +49,10 @@
|
|
|
48
49
|
"typescript": "^5.9.3"
|
|
49
50
|
},
|
|
50
51
|
"peerDependencies": {
|
|
51
|
-
"zod": "^4.3.
|
|
52
|
+
"zod": "^4.3.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"zod": "^4.3.
|
|
55
|
+
"zod": "^4.3.6"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
57
58
|
"typecheck": "tsc --noEmit",
|