@rexeus/typeweaver-clients 0.5.0 → 0.6.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/README.md +1 -1
- package/dist/LICENSE +1 -1
- package/dist/NOTICE +1 -1
- package/dist/index.cjs +130 -152
- package/dist/index.d.cts +6 -5
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +109 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +12 -12
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -150
- package/dist/metafile-cjs.json +0 -1
- package/dist/metafile-esm.json +0 -1
package/README.md
CHANGED
package/dist/LICENSE
CHANGED
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
same "printed page" as the copyright notice for easier
|
|
188
188
|
identification within third-party archives.
|
|
189
189
|
|
|
190
|
-
Copyright
|
|
190
|
+
Copyright 2026 Dennis Wentzien
|
|
191
191
|
|
|
192
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
193
|
you may not use this file except in compliance with the License.
|
package/dist/NOTICE
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,159 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
10
26
|
|
|
11
|
-
|
|
12
|
-
|
|
27
|
+
//#endregion
|
|
28
|
+
let node_path = require("node:path");
|
|
29
|
+
node_path = __toESM(node_path);
|
|
30
|
+
let node_url = require("node:url");
|
|
31
|
+
let _rexeus_typeweaver_gen = require("@rexeus/typeweaver-gen");
|
|
32
|
+
let _rexeus_typeweaver_zod_to_ts = require("@rexeus/typeweaver-zod-to-ts");
|
|
33
|
+
let case$1 = require("case");
|
|
34
|
+
case$1 = __toESM(case$1);
|
|
13
35
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
17
|
-
var moduleDir = path__default.default.dirname(node_url.fileURLToPath(importMetaUrl));
|
|
36
|
+
//#region src/ClientGenerator.ts
|
|
37
|
+
const moduleDir$1 = node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
18
38
|
var ClientGenerator = class {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
(r) => (r.statusCode < 200 || r.statusCode >= 300) && r.isReference
|
|
103
|
-
);
|
|
104
|
-
const headerTsType = request.header ? typeweaverZodToTs.TsTypePrinter.print(typeweaverZodToTs.TsTypeNode.fromZod(request.header)) : void 0;
|
|
105
|
-
const paramTsType = request.param ? typeweaverZodToTs.TsTypePrinter.print(typeweaverZodToTs.TsTypeNode.fromZod(request.param)) : void 0;
|
|
106
|
-
const queryTsType = request.query ? typeweaverZodToTs.TsTypePrinter.print(typeweaverZodToTs.TsTypeNode.fromZod(request.query)) : void 0;
|
|
107
|
-
const bodyTsType = request.body ? typeweaverZodToTs.TsTypePrinter.print(typeweaverZodToTs.TsTypeNode.fromZod(request.body)) : void 0;
|
|
108
|
-
const successResponseImportPath = (response) => {
|
|
109
|
-
if (response.isReference && response.path) {
|
|
110
|
-
return response.path;
|
|
111
|
-
}
|
|
112
|
-
return `./${path__default.default.basename(outputResponseFileName, ".ts")}`;
|
|
113
|
-
};
|
|
114
|
-
const requestFile = `./${path__default.default.basename(outputRequestFileName, ".ts")}`;
|
|
115
|
-
const responseValidatorFile = `./${path__default.default.basename(outputResponseValidationFileName, ".ts")}`;
|
|
116
|
-
const relativeSourceFile = path__default.default.relative(sourceDir, sourceFile);
|
|
117
|
-
const sourcePath = path__default.default.join(
|
|
118
|
-
sourceDir,
|
|
119
|
-
relativeSourceFile.replace(/\.ts$/, "")
|
|
120
|
-
);
|
|
121
|
-
const relativeSourcePath = path__default.default.relative(outputDir, sourcePath);
|
|
122
|
-
const content = context.renderTemplate(templateFilePath, {
|
|
123
|
-
sourcePath: relativeSourcePath,
|
|
124
|
-
operationId,
|
|
125
|
-
pascalCaseOperationId,
|
|
126
|
-
method,
|
|
127
|
-
headerTsType,
|
|
128
|
-
paramTsType,
|
|
129
|
-
queryTsType,
|
|
130
|
-
bodyTsType,
|
|
131
|
-
ownSuccessResponses,
|
|
132
|
-
ownErrorResponses,
|
|
133
|
-
sharedSuccessResponses,
|
|
134
|
-
sharedErrorResponses,
|
|
135
|
-
requestFile,
|
|
136
|
-
responseValidatorFile,
|
|
137
|
-
successResponseImportPath
|
|
138
|
-
});
|
|
139
|
-
const outputCommandFile = path__default.default.join(
|
|
140
|
-
outputDir,
|
|
141
|
-
`${pascalCaseOperationId}RequestCommand.ts`
|
|
142
|
-
);
|
|
143
|
-
const relativePath = path__default.default.relative(context.outputDir, outputCommandFile);
|
|
144
|
-
context.writeFile(relativePath, content);
|
|
145
|
-
}
|
|
39
|
+
static generate(context) {
|
|
40
|
+
const clientTemplatePath = node_path.default.join(moduleDir$1, "templates", "Client.ejs");
|
|
41
|
+
const commandTemplatePath = node_path.default.join(moduleDir$1, "templates", "RequestCommand.ejs");
|
|
42
|
+
for (const [, entityResource] of Object.entries(context.resources.entityResources)) {
|
|
43
|
+
this.writeClient(clientTemplatePath, entityResource.operations, context);
|
|
44
|
+
this.writeRequestCommands(commandTemplatePath, entityResource.operations, context);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
static writeClient(templateFilePath, operationResources, context) {
|
|
48
|
+
const entityName = operationResources[0].entityName;
|
|
49
|
+
const pascalCaseEntityName = case$1.default.pascal(entityName);
|
|
50
|
+
const outputDir = operationResources[0].outputDir;
|
|
51
|
+
const operations = [];
|
|
52
|
+
for (const operationResource of operationResources) {
|
|
53
|
+
const { definition, outputResponseFileName, outputResponseValidationFileName, outputRequestFileName } = operationResource;
|
|
54
|
+
const { operationId } = definition;
|
|
55
|
+
const pascalCaseOperationId = case$1.default.pascal(operationId);
|
|
56
|
+
const requestFile = `./${node_path.default.basename(outputRequestFileName, ".ts")}`;
|
|
57
|
+
const responseValidatorFile = `./${node_path.default.basename(outputResponseValidationFileName, ".ts")}`;
|
|
58
|
+
const responseFile = `./${node_path.default.basename(outputResponseFileName, ".ts")}`;
|
|
59
|
+
operations.push({
|
|
60
|
+
operationId,
|
|
61
|
+
pascalCaseOperationId,
|
|
62
|
+
requestFile,
|
|
63
|
+
responseValidatorFile,
|
|
64
|
+
responseFile
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const content = context.renderTemplate(templateFilePath, {
|
|
68
|
+
coreDir: context.coreDir,
|
|
69
|
+
pascalCaseEntityName,
|
|
70
|
+
operations
|
|
71
|
+
});
|
|
72
|
+
const outputClientFile = node_path.default.join(outputDir, `${pascalCaseEntityName}Client.ts`);
|
|
73
|
+
const relativePath = node_path.default.relative(context.outputDir, outputClientFile);
|
|
74
|
+
context.writeFile(relativePath, content);
|
|
75
|
+
}
|
|
76
|
+
static writeRequestCommands(templateFilePath, operationResources, context) {
|
|
77
|
+
for (const operationResource of operationResources) this.writeRequestCommand(templateFilePath, operationResource, context);
|
|
78
|
+
}
|
|
79
|
+
static writeRequestCommand(templateFilePath, operationResource, context) {
|
|
80
|
+
const { definition, sourceDir, sourceFile, outputDir, outputResponseFileName, outputResponseValidationFileName, outputRequestFileName } = operationResource;
|
|
81
|
+
const { operationId, method, request, responses } = definition;
|
|
82
|
+
const pascalCaseOperationId = case$1.default.pascal(operationId);
|
|
83
|
+
const allResponses = responses;
|
|
84
|
+
const ownSuccessResponses = allResponses.filter((r) => r.statusCode >= 200 && r.statusCode < 300 && !r.isReference);
|
|
85
|
+
const ownErrorResponses = allResponses.filter((r) => (r.statusCode < 200 || r.statusCode >= 300) && !r.isReference);
|
|
86
|
+
const sharedSuccessResponses = allResponses.filter((r) => r.statusCode >= 200 && r.statusCode < 300 && r.isReference);
|
|
87
|
+
const sharedErrorResponses = allResponses.filter((r) => (r.statusCode < 200 || r.statusCode >= 300) && r.isReference);
|
|
88
|
+
const headerTsType = request.header ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(request.header)) : void 0;
|
|
89
|
+
const paramTsType = request.param ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(request.param)) : void 0;
|
|
90
|
+
const queryTsType = request.query ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(request.query)) : void 0;
|
|
91
|
+
const bodyTsType = request.body ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(request.body)) : void 0;
|
|
92
|
+
const successResponseImportPath = (response) => {
|
|
93
|
+
if (response.isReference && response.path) return response.path;
|
|
94
|
+
return `./${node_path.default.basename(outputResponseFileName, ".ts")}`;
|
|
95
|
+
};
|
|
96
|
+
const requestFile = `./${node_path.default.basename(outputRequestFileName, ".ts")}`;
|
|
97
|
+
const responseValidatorFile = `./${node_path.default.basename(outputResponseValidationFileName, ".ts")}`;
|
|
98
|
+
const relativeSourceFile = node_path.default.relative(sourceDir, sourceFile);
|
|
99
|
+
const sourcePath = node_path.default.join(sourceDir, relativeSourceFile.replace(/\.ts$/, ""));
|
|
100
|
+
const relativeSourcePath = node_path.default.relative(outputDir, sourcePath);
|
|
101
|
+
const content = context.renderTemplate(templateFilePath, {
|
|
102
|
+
sourcePath: relativeSourcePath,
|
|
103
|
+
operationId,
|
|
104
|
+
pascalCaseOperationId,
|
|
105
|
+
method,
|
|
106
|
+
headerTsType,
|
|
107
|
+
paramTsType,
|
|
108
|
+
queryTsType,
|
|
109
|
+
bodyTsType,
|
|
110
|
+
ownSuccessResponses,
|
|
111
|
+
ownErrorResponses,
|
|
112
|
+
sharedSuccessResponses,
|
|
113
|
+
sharedErrorResponses,
|
|
114
|
+
requestFile,
|
|
115
|
+
responseValidatorFile,
|
|
116
|
+
successResponseImportPath
|
|
117
|
+
});
|
|
118
|
+
const outputCommandFile = node_path.default.join(outputDir, `${pascalCaseOperationId}RequestCommand.ts`);
|
|
119
|
+
const relativePath = node_path.default.relative(context.outputDir, outputCommandFile);
|
|
120
|
+
context.writeFile(relativePath, content);
|
|
121
|
+
}
|
|
146
122
|
};
|
|
147
123
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/index.ts
|
|
126
|
+
const moduleDir = node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
127
|
+
var ClientsPlugin = class extends _rexeus_typeweaver_gen.BasePlugin {
|
|
128
|
+
name = "clients";
|
|
129
|
+
generate(context) {
|
|
130
|
+
const libDir = node_path.default.join(moduleDir, "lib");
|
|
131
|
+
this.copyLibFiles(context, libDir, "clients");
|
|
132
|
+
ClientGenerator.generate(context);
|
|
133
|
+
}
|
|
157
134
|
};
|
|
158
135
|
|
|
159
|
-
|
|
136
|
+
//#endregion
|
|
137
|
+
module.exports = ClientsPlugin;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BasePlugin, GeneratorContext } from
|
|
1
|
+
import { BasePlugin, GeneratorContext } from "@rexeus/typeweaver-gen";
|
|
2
2
|
|
|
3
|
+
//#region src/index.d.ts
|
|
3
4
|
declare class ClientsPlugin extends BasePlugin {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
name: string;
|
|
6
|
+
generate(context: GeneratorContext): Promise<void> | void;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
export = ClientsPlugin;
|
|
9
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAQqB,aAAA,SAAsB,UAAA;EAClC,IAAA;EACS,QAAA,CAAS,OAAA,EAAS,gBAAA,GAAmB,OAAA;AAAA;AAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BasePlugin, GeneratorContext } from "@rexeus/typeweaver-gen";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare class ClientsPlugin extends BasePlugin {
|
|
5
|
+
name: string;
|
|
6
|
+
generate(context: GeneratorContext): Promise<void> | void;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ClientsPlugin as default };
|
|
10
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAQqB,aAAA,SAAsB,UAAA;EAClC,IAAA;EACS,QAAA,CAAS,OAAA,EAAS,gBAAA,GAAmB,OAAA;AAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { BasePlugin } from "@rexeus/typeweaver-gen";
|
|
4
|
+
import { TsTypeNode, TsTypePrinter } from "@rexeus/typeweaver-zod-to-ts";
|
|
5
|
+
import Case from "case";
|
|
6
|
+
|
|
7
|
+
//#region src/ClientGenerator.ts
|
|
8
|
+
const moduleDir$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
var ClientGenerator = class {
|
|
10
|
+
static generate(context) {
|
|
11
|
+
const clientTemplatePath = path.join(moduleDir$1, "templates", "Client.ejs");
|
|
12
|
+
const commandTemplatePath = path.join(moduleDir$1, "templates", "RequestCommand.ejs");
|
|
13
|
+
for (const [, entityResource] of Object.entries(context.resources.entityResources)) {
|
|
14
|
+
this.writeClient(clientTemplatePath, entityResource.operations, context);
|
|
15
|
+
this.writeRequestCommands(commandTemplatePath, entityResource.operations, context);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
static writeClient(templateFilePath, operationResources, context) {
|
|
19
|
+
const entityName = operationResources[0].entityName;
|
|
20
|
+
const pascalCaseEntityName = Case.pascal(entityName);
|
|
21
|
+
const outputDir = operationResources[0].outputDir;
|
|
22
|
+
const operations = [];
|
|
23
|
+
for (const operationResource of operationResources) {
|
|
24
|
+
const { definition, outputResponseFileName, outputResponseValidationFileName, outputRequestFileName } = operationResource;
|
|
25
|
+
const { operationId } = definition;
|
|
26
|
+
const pascalCaseOperationId = Case.pascal(operationId);
|
|
27
|
+
const requestFile = `./${path.basename(outputRequestFileName, ".ts")}`;
|
|
28
|
+
const responseValidatorFile = `./${path.basename(outputResponseValidationFileName, ".ts")}`;
|
|
29
|
+
const responseFile = `./${path.basename(outputResponseFileName, ".ts")}`;
|
|
30
|
+
operations.push({
|
|
31
|
+
operationId,
|
|
32
|
+
pascalCaseOperationId,
|
|
33
|
+
requestFile,
|
|
34
|
+
responseValidatorFile,
|
|
35
|
+
responseFile
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const content = context.renderTemplate(templateFilePath, {
|
|
39
|
+
coreDir: context.coreDir,
|
|
40
|
+
pascalCaseEntityName,
|
|
41
|
+
operations
|
|
42
|
+
});
|
|
43
|
+
const outputClientFile = path.join(outputDir, `${pascalCaseEntityName}Client.ts`);
|
|
44
|
+
const relativePath = path.relative(context.outputDir, outputClientFile);
|
|
45
|
+
context.writeFile(relativePath, content);
|
|
46
|
+
}
|
|
47
|
+
static writeRequestCommands(templateFilePath, operationResources, context) {
|
|
48
|
+
for (const operationResource of operationResources) this.writeRequestCommand(templateFilePath, operationResource, context);
|
|
49
|
+
}
|
|
50
|
+
static writeRequestCommand(templateFilePath, operationResource, context) {
|
|
51
|
+
const { definition, sourceDir, sourceFile, outputDir, outputResponseFileName, outputResponseValidationFileName, outputRequestFileName } = operationResource;
|
|
52
|
+
const { operationId, method, request, responses } = definition;
|
|
53
|
+
const pascalCaseOperationId = Case.pascal(operationId);
|
|
54
|
+
const allResponses = responses;
|
|
55
|
+
const ownSuccessResponses = allResponses.filter((r) => r.statusCode >= 200 && r.statusCode < 300 && !r.isReference);
|
|
56
|
+
const ownErrorResponses = allResponses.filter((r) => (r.statusCode < 200 || r.statusCode >= 300) && !r.isReference);
|
|
57
|
+
const sharedSuccessResponses = allResponses.filter((r) => r.statusCode >= 200 && r.statusCode < 300 && r.isReference);
|
|
58
|
+
const sharedErrorResponses = allResponses.filter((r) => (r.statusCode < 200 || r.statusCode >= 300) && r.isReference);
|
|
59
|
+
const headerTsType = request.header ? TsTypePrinter.print(TsTypeNode.fromZod(request.header)) : void 0;
|
|
60
|
+
const paramTsType = request.param ? TsTypePrinter.print(TsTypeNode.fromZod(request.param)) : void 0;
|
|
61
|
+
const queryTsType = request.query ? TsTypePrinter.print(TsTypeNode.fromZod(request.query)) : void 0;
|
|
62
|
+
const bodyTsType = request.body ? TsTypePrinter.print(TsTypeNode.fromZod(request.body)) : void 0;
|
|
63
|
+
const successResponseImportPath = (response) => {
|
|
64
|
+
if (response.isReference && response.path) return response.path;
|
|
65
|
+
return `./${path.basename(outputResponseFileName, ".ts")}`;
|
|
66
|
+
};
|
|
67
|
+
const requestFile = `./${path.basename(outputRequestFileName, ".ts")}`;
|
|
68
|
+
const responseValidatorFile = `./${path.basename(outputResponseValidationFileName, ".ts")}`;
|
|
69
|
+
const relativeSourceFile = path.relative(sourceDir, sourceFile);
|
|
70
|
+
const sourcePath = path.join(sourceDir, relativeSourceFile.replace(/\.ts$/, ""));
|
|
71
|
+
const relativeSourcePath = path.relative(outputDir, sourcePath);
|
|
72
|
+
const content = context.renderTemplate(templateFilePath, {
|
|
73
|
+
sourcePath: relativeSourcePath,
|
|
74
|
+
operationId,
|
|
75
|
+
pascalCaseOperationId,
|
|
76
|
+
method,
|
|
77
|
+
headerTsType,
|
|
78
|
+
paramTsType,
|
|
79
|
+
queryTsType,
|
|
80
|
+
bodyTsType,
|
|
81
|
+
ownSuccessResponses,
|
|
82
|
+
ownErrorResponses,
|
|
83
|
+
sharedSuccessResponses,
|
|
84
|
+
sharedErrorResponses,
|
|
85
|
+
requestFile,
|
|
86
|
+
responseValidatorFile,
|
|
87
|
+
successResponseImportPath
|
|
88
|
+
});
|
|
89
|
+
const outputCommandFile = path.join(outputDir, `${pascalCaseOperationId}RequestCommand.ts`);
|
|
90
|
+
const relativePath = path.relative(context.outputDir, outputCommandFile);
|
|
91
|
+
context.writeFile(relativePath, content);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/index.ts
|
|
97
|
+
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
98
|
+
var ClientsPlugin = class extends BasePlugin {
|
|
99
|
+
name = "clients";
|
|
100
|
+
generate(context) {
|
|
101
|
+
const libDir = path.join(moduleDir, "lib");
|
|
102
|
+
this.copyLibFiles(context, libDir, "clients");
|
|
103
|
+
ClientGenerator.generate(context);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
export { ClientsPlugin as default };
|
|
109
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["moduleDir"],"sources":["../src/ClientGenerator.ts","../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type {\n GeneratorContext,\n OperationResource,\n} from \"@rexeus/typeweaver-gen\";\nimport { TsTypeNode, TsTypePrinter } from \"@rexeus/typeweaver-zod-to-ts\";\nimport Case from \"case\";\n\nconst moduleDir = path.dirname(fileURLToPath(import.meta.url));\n\nexport class ClientGenerator {\n public static generate(context: GeneratorContext): void {\n const clientTemplatePath = path.join(moduleDir, \"templates\", \"Client.ejs\");\n const commandTemplatePath = path.join(\n moduleDir,\n \"templates\",\n \"RequestCommand.ejs\"\n );\n\n for (const [, entityResource] of Object.entries(\n context.resources.entityResources\n )) {\n this.writeClient(clientTemplatePath, entityResource.operations, context);\n this.writeRequestCommands(\n commandTemplatePath,\n entityResource.operations,\n context\n );\n }\n }\n\n private static writeClient(\n templateFilePath: string,\n operationResources: OperationResource[],\n context: GeneratorContext\n ): void {\n const entityName = operationResources[0]!.entityName;\n const pascalCaseEntityName = Case.pascal(entityName);\n const outputDir = operationResources[0]!.outputDir;\n\n const operations: {\n operationId: string;\n pascalCaseOperationId: string;\n requestFile: string;\n responseValidatorFile: string;\n responseFile: string;\n }[] = [];\n for (const operationResource of operationResources) {\n const {\n definition,\n outputResponseFileName,\n outputResponseValidationFileName,\n outputRequestFileName,\n } = operationResource;\n const { operationId } = definition;\n\n const pascalCaseOperationId = Case.pascal(operationId);\n const requestFile = `./${path.basename(outputRequestFileName, \".ts\")}`;\n const responseValidatorFile = `./${path.basename(outputResponseValidationFileName, \".ts\")}`;\n const responseFile = `./${path.basename(outputResponseFileName, \".ts\")}`;\n\n operations.push({\n operationId,\n pascalCaseOperationId,\n requestFile,\n responseValidatorFile,\n responseFile,\n });\n }\n\n const content = context.renderTemplate(templateFilePath, {\n coreDir: context.coreDir,\n pascalCaseEntityName,\n operations,\n });\n\n const outputClientFile = path.join(\n outputDir,\n `${pascalCaseEntityName}Client.ts`\n );\n const relativePath = path.relative(context.outputDir, outputClientFile);\n context.writeFile(relativePath, content);\n }\n\n private static writeRequestCommands(\n templateFilePath: string,\n operationResources: OperationResource[],\n context: GeneratorContext\n ): void {\n for (const operationResource of operationResources) {\n this.writeRequestCommand(templateFilePath, operationResource, context);\n }\n }\n\n private static writeRequestCommand(\n templateFilePath: string,\n operationResource: OperationResource,\n context: GeneratorContext\n ): void {\n const {\n definition,\n sourceDir,\n sourceFile,\n outputDir,\n outputResponseFileName,\n outputResponseValidationFileName,\n outputRequestFileName,\n } = operationResource;\n\n const { operationId, method, request, responses } = definition;\n const pascalCaseOperationId = Case.pascal(operationId);\n\n // Get response information\n const allResponses = responses;\n const ownSuccessResponses = allResponses.filter(\n r => r.statusCode >= 200 && r.statusCode < 300 && !r.isReference\n );\n const ownErrorResponses = allResponses.filter(\n r => (r.statusCode < 200 || r.statusCode >= 300) && !r.isReference\n );\n const sharedSuccessResponses = allResponses.filter(\n r => r.statusCode >= 200 && r.statusCode < 300 && r.isReference\n );\n const sharedErrorResponses = allResponses.filter(\n r => (r.statusCode < 200 || r.statusCode >= 300) && r.isReference\n );\n\n // Build request type information\n const headerTsType = request.header\n ? TsTypePrinter.print(TsTypeNode.fromZod(request.header))\n : undefined;\n const paramTsType = request.param\n ? TsTypePrinter.print(TsTypeNode.fromZod(request.param))\n : undefined;\n const queryTsType = request.query\n ? TsTypePrinter.print(TsTypeNode.fromZod(request.query))\n : undefined;\n const bodyTsType = request.body\n ? TsTypePrinter.print(TsTypeNode.fromZod(request.body))\n : undefined;\n\n // Helper function to determine response import path\n const successResponseImportPath = (response: {\n name: string;\n isReference?: boolean;\n path?: string;\n }) => {\n if (response.isReference && response.path) {\n return response.path;\n }\n return `./${path.basename(outputResponseFileName, \".ts\")}`;\n };\n\n // Build relative paths\n const requestFile = `./${path.basename(outputRequestFileName, \".ts\")}`;\n const responseValidatorFile = `./${path.basename(outputResponseValidationFileName, \".ts\")}`;\n const relativeSourceFile = path.relative(sourceDir, sourceFile);\n const sourcePath = path.join(\n sourceDir,\n relativeSourceFile.replace(/\\.ts$/, \"\")\n );\n const relativeSourcePath = path.relative(outputDir, sourcePath);\n\n const content = context.renderTemplate(templateFilePath, {\n sourcePath: relativeSourcePath,\n operationId,\n pascalCaseOperationId,\n method,\n headerTsType,\n paramTsType,\n queryTsType,\n bodyTsType,\n ownSuccessResponses,\n ownErrorResponses,\n sharedSuccessResponses,\n sharedErrorResponses,\n requestFile,\n responseValidatorFile,\n successResponseImportPath,\n });\n\n const outputCommandFile = path.join(\n outputDir,\n `${pascalCaseOperationId}RequestCommand.ts`\n );\n const relativePath = path.relative(context.outputDir, outputCommandFile);\n context.writeFile(relativePath, content);\n }\n}\n","import path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { BasePlugin } from \"@rexeus/typeweaver-gen\";\nimport type { GeneratorContext } from \"@rexeus/typeweaver-gen\";\nimport { ClientGenerator } from \"./ClientGenerator\";\n\nconst moduleDir = path.dirname(fileURLToPath(import.meta.url));\n\nexport default class ClientsPlugin extends BasePlugin {\n public name = \"clients\";\n public override generate(context: GeneratorContext): Promise<void> | void {\n // Copy lib files to lib/clients/ from dist folder\n const libDir = path.join(moduleDir, \"lib\");\n this.copyLibFiles(context, libDir, \"clients\");\n\n ClientGenerator.generate(context);\n }\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexeus/typeweaver-clients",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Generates HTTP clients directly from your API definitions. Powered by Typeweaver 🧵✨",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "dist/index.cjs",
|
|
8
|
-
"module": "dist/index.
|
|
9
|
-
"types": "dist/index.d.
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"types": "dist/index.d.mts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"import": {
|
|
13
|
-
"types": "./dist/index.d.
|
|
14
|
-
"default": "./dist/index.
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"default": "./dist/index.mjs"
|
|
15
15
|
},
|
|
16
16
|
"require": {
|
|
17
17
|
"types": "./dist/index.d.cts",
|
|
@@ -48,24 +48,24 @@
|
|
|
48
48
|
"homepage": "https://github.com/rexeus/typeweaver#readme",
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"zod": "^4.3.0",
|
|
51
|
-
"@rexeus/typeweaver-
|
|
52
|
-
"@rexeus/typeweaver-
|
|
51
|
+
"@rexeus/typeweaver-core": "^0.6.0",
|
|
52
|
+
"@rexeus/typeweaver-gen": "^0.6.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@hono/node-server": "^1.19.7",
|
|
56
56
|
"test-utils": "file:../test-utils",
|
|
57
57
|
"zod": "^4.3.6",
|
|
58
|
-
"@rexeus/typeweaver-
|
|
59
|
-
"@rexeus/typeweaver-
|
|
58
|
+
"@rexeus/typeweaver-gen": "^0.6.0",
|
|
59
|
+
"@rexeus/typeweaver-core": "^0.6.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"case": "^1.6.3",
|
|
63
|
-
"@rexeus/typeweaver-zod-to-ts": "^0.
|
|
63
|
+
"@rexeus/typeweaver-zod-to-ts": "^0.6.0"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"typecheck": "tsc --noEmit",
|
|
67
|
-
"format": "
|
|
68
|
-
"build": "
|
|
67
|
+
"format": "oxfmt",
|
|
68
|
+
"build": "tsdown && mkdir -p ./dist/templates ./dist/lib && cp -r ./src/templates/* ./dist/templates/ && cp -r ./src/lib/* ./dist/lib/ && cp ../../LICENSE ../../NOTICE ./dist/",
|
|
69
69
|
"test": "vitest --run",
|
|
70
70
|
"preversion": "npm run build"
|
|
71
71
|
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import { BasePlugin } from '@rexeus/typeweaver-gen';
|
|
4
|
-
import { TsTypePrinter, TsTypeNode } from '@rexeus/typeweaver-zod-to-ts';
|
|
5
|
-
import Case from 'case';
|
|
6
|
-
|
|
7
|
-
// src/index.ts
|
|
8
|
-
var moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
var ClientGenerator = class {
|
|
10
|
-
static generate(context) {
|
|
11
|
-
const clientTemplatePath = path.join(moduleDir, "templates", "Client.ejs");
|
|
12
|
-
const commandTemplatePath = path.join(
|
|
13
|
-
moduleDir,
|
|
14
|
-
"templates",
|
|
15
|
-
"RequestCommand.ejs"
|
|
16
|
-
);
|
|
17
|
-
for (const [, entityResource] of Object.entries(
|
|
18
|
-
context.resources.entityResources
|
|
19
|
-
)) {
|
|
20
|
-
this.writeClient(clientTemplatePath, entityResource.operations, context);
|
|
21
|
-
this.writeRequestCommands(
|
|
22
|
-
commandTemplatePath,
|
|
23
|
-
entityResource.operations,
|
|
24
|
-
context
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
static writeClient(templateFilePath, operationResources, context) {
|
|
29
|
-
const entityName = operationResources[0].entityName;
|
|
30
|
-
const pascalCaseEntityName = Case.pascal(entityName);
|
|
31
|
-
const outputDir = operationResources[0].outputDir;
|
|
32
|
-
const operations = [];
|
|
33
|
-
for (const operationResource of operationResources) {
|
|
34
|
-
const {
|
|
35
|
-
definition,
|
|
36
|
-
outputResponseFileName,
|
|
37
|
-
outputResponseValidationFileName,
|
|
38
|
-
outputRequestFileName
|
|
39
|
-
} = operationResource;
|
|
40
|
-
const { operationId } = definition;
|
|
41
|
-
const pascalCaseOperationId = Case.pascal(operationId);
|
|
42
|
-
const requestFile = `./${path.basename(outputRequestFileName, ".ts")}`;
|
|
43
|
-
const responseValidatorFile = `./${path.basename(outputResponseValidationFileName, ".ts")}`;
|
|
44
|
-
const responseFile = `./${path.basename(outputResponseFileName, ".ts")}`;
|
|
45
|
-
operations.push({
|
|
46
|
-
operationId,
|
|
47
|
-
pascalCaseOperationId,
|
|
48
|
-
requestFile,
|
|
49
|
-
responseValidatorFile,
|
|
50
|
-
responseFile
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
const content = context.renderTemplate(templateFilePath, {
|
|
54
|
-
coreDir: context.coreDir,
|
|
55
|
-
pascalCaseEntityName,
|
|
56
|
-
operations
|
|
57
|
-
});
|
|
58
|
-
const outputClientFile = path.join(
|
|
59
|
-
outputDir,
|
|
60
|
-
`${pascalCaseEntityName}Client.ts`
|
|
61
|
-
);
|
|
62
|
-
const relativePath = path.relative(context.outputDir, outputClientFile);
|
|
63
|
-
context.writeFile(relativePath, content);
|
|
64
|
-
}
|
|
65
|
-
static writeRequestCommands(templateFilePath, operationResources, context) {
|
|
66
|
-
for (const operationResource of operationResources) {
|
|
67
|
-
this.writeRequestCommand(templateFilePath, operationResource, context);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
static writeRequestCommand(templateFilePath, operationResource, context) {
|
|
71
|
-
const {
|
|
72
|
-
definition,
|
|
73
|
-
sourceDir,
|
|
74
|
-
sourceFile,
|
|
75
|
-
outputDir,
|
|
76
|
-
outputResponseFileName,
|
|
77
|
-
outputResponseValidationFileName,
|
|
78
|
-
outputRequestFileName
|
|
79
|
-
} = operationResource;
|
|
80
|
-
const { operationId, method, request, responses } = definition;
|
|
81
|
-
const pascalCaseOperationId = Case.pascal(operationId);
|
|
82
|
-
const allResponses = responses;
|
|
83
|
-
const ownSuccessResponses = allResponses.filter(
|
|
84
|
-
(r) => r.statusCode >= 200 && r.statusCode < 300 && !r.isReference
|
|
85
|
-
);
|
|
86
|
-
const ownErrorResponses = allResponses.filter(
|
|
87
|
-
(r) => (r.statusCode < 200 || r.statusCode >= 300) && !r.isReference
|
|
88
|
-
);
|
|
89
|
-
const sharedSuccessResponses = allResponses.filter(
|
|
90
|
-
(r) => r.statusCode >= 200 && r.statusCode < 300 && r.isReference
|
|
91
|
-
);
|
|
92
|
-
const sharedErrorResponses = allResponses.filter(
|
|
93
|
-
(r) => (r.statusCode < 200 || r.statusCode >= 300) && r.isReference
|
|
94
|
-
);
|
|
95
|
-
const headerTsType = request.header ? TsTypePrinter.print(TsTypeNode.fromZod(request.header)) : void 0;
|
|
96
|
-
const paramTsType = request.param ? TsTypePrinter.print(TsTypeNode.fromZod(request.param)) : void 0;
|
|
97
|
-
const queryTsType = request.query ? TsTypePrinter.print(TsTypeNode.fromZod(request.query)) : void 0;
|
|
98
|
-
const bodyTsType = request.body ? TsTypePrinter.print(TsTypeNode.fromZod(request.body)) : void 0;
|
|
99
|
-
const successResponseImportPath = (response) => {
|
|
100
|
-
if (response.isReference && response.path) {
|
|
101
|
-
return response.path;
|
|
102
|
-
}
|
|
103
|
-
return `./${path.basename(outputResponseFileName, ".ts")}`;
|
|
104
|
-
};
|
|
105
|
-
const requestFile = `./${path.basename(outputRequestFileName, ".ts")}`;
|
|
106
|
-
const responseValidatorFile = `./${path.basename(outputResponseValidationFileName, ".ts")}`;
|
|
107
|
-
const relativeSourceFile = path.relative(sourceDir, sourceFile);
|
|
108
|
-
const sourcePath = path.join(
|
|
109
|
-
sourceDir,
|
|
110
|
-
relativeSourceFile.replace(/\.ts$/, "")
|
|
111
|
-
);
|
|
112
|
-
const relativeSourcePath = path.relative(outputDir, sourcePath);
|
|
113
|
-
const content = context.renderTemplate(templateFilePath, {
|
|
114
|
-
sourcePath: relativeSourcePath,
|
|
115
|
-
operationId,
|
|
116
|
-
pascalCaseOperationId,
|
|
117
|
-
method,
|
|
118
|
-
headerTsType,
|
|
119
|
-
paramTsType,
|
|
120
|
-
queryTsType,
|
|
121
|
-
bodyTsType,
|
|
122
|
-
ownSuccessResponses,
|
|
123
|
-
ownErrorResponses,
|
|
124
|
-
sharedSuccessResponses,
|
|
125
|
-
sharedErrorResponses,
|
|
126
|
-
requestFile,
|
|
127
|
-
responseValidatorFile,
|
|
128
|
-
successResponseImportPath
|
|
129
|
-
});
|
|
130
|
-
const outputCommandFile = path.join(
|
|
131
|
-
outputDir,
|
|
132
|
-
`${pascalCaseOperationId}RequestCommand.ts`
|
|
133
|
-
);
|
|
134
|
-
const relativePath = path.relative(context.outputDir, outputCommandFile);
|
|
135
|
-
context.writeFile(relativePath, content);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// src/index.ts
|
|
140
|
-
var moduleDir2 = path.dirname(fileURLToPath(import.meta.url));
|
|
141
|
-
var ClientsPlugin = class extends BasePlugin {
|
|
142
|
-
name = "clients";
|
|
143
|
-
generate(context) {
|
|
144
|
-
const libDir = path.join(moduleDir2, "lib");
|
|
145
|
-
this.copyLibFiles(context, libDir, "clients");
|
|
146
|
-
ClientGenerator.generate(context);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export { ClientsPlugin as default };
|
package/dist/metafile-cjs.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/ClientGenerator.ts":{"bytes":5968,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@rexeus/typeweaver-zod-to-ts","kind":"import-statement","external":true},{"path":"case","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":669,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@rexeus/typeweaver-gen","kind":"import-statement","external":true},{"path":"src/ClientGenerator.ts","kind":"import-statement","original":"./ClientGenerator"},{"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":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@rexeus/typeweaver-gen","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@rexeus/typeweaver-zod-to-ts","kind":"import-statement","external":true},{"path":"case","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"src/index.ts","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":{"bytesInOutput":314},"src/index.ts":{"bytesInOutput":443},"src/ClientGenerator.ts":{"bytesInOutput":5138}},"bytes":6125}}}
|
package/dist/metafile-esm.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/ClientGenerator.ts":{"bytes":5968,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@rexeus/typeweaver-zod-to-ts","kind":"import-statement","external":true},{"path":"case","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":669,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@rexeus/typeweaver-gen","kind":"import-statement","external":true},{"path":"src/ClientGenerator.ts","kind":"import-statement","original":"./ClientGenerator"},{"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":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@rexeus/typeweaver-gen","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@rexeus/typeweaver-zod-to-ts","kind":"import-statement","external":true},{"path":"case","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":445},"src/ClientGenerator.ts":{"bytesInOutput":5140}},"bytes":5684}}}
|