@rexeus/typeweaver-clients 0.2.1 → 0.3.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 ADDED
@@ -0,0 +1,191 @@
1
+ "use strict";
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 __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => ClientsPlugin
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
38
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
39
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
+
41
+ // src/index.ts
42
+ var import_node_path2 = __toESM(require("node:path"), 1);
43
+ var import_node_url2 = require("node:url");
44
+ var import_typeweaver_gen = require("@rexeus/typeweaver-gen");
45
+
46
+ // src/ClientGenerator.ts
47
+ var import_node_path = __toESM(require("node:path"), 1);
48
+ var import_node_url = require("node:url");
49
+ var import_typeweaver_zod_to_ts = require("@rexeus/typeweaver-zod-to-ts");
50
+ var import_case = __toESM(require("case"), 1);
51
+ var moduleDir = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
52
+ var ClientGenerator = class {
53
+ static generate(context) {
54
+ const clientTemplatePath = import_node_path.default.join(moduleDir, "templates", "Client.ejs");
55
+ const commandTemplatePath = import_node_path.default.join(
56
+ moduleDir,
57
+ "templates",
58
+ "RequestCommand.ejs"
59
+ );
60
+ for (const [, entityResource] of Object.entries(
61
+ context.resources.entityResources
62
+ )) {
63
+ this.writeClient(clientTemplatePath, entityResource.operations, context);
64
+ this.writeRequestCommands(
65
+ commandTemplatePath,
66
+ entityResource.operations,
67
+ context
68
+ );
69
+ }
70
+ }
71
+ static writeClient(templateFilePath, operationResources, context) {
72
+ const entityName = operationResources[0].entityName;
73
+ const pascalCaseEntityName = import_case.default.pascal(entityName);
74
+ const outputDir = operationResources[0].outputDir;
75
+ const operations = [];
76
+ for (const operationResource of operationResources) {
77
+ const {
78
+ definition,
79
+ outputResponseFileName,
80
+ outputResponseValidationFileName,
81
+ outputRequestFileName
82
+ } = operationResource;
83
+ const { operationId } = definition;
84
+ const pascalCaseOperationId = import_case.default.pascal(operationId);
85
+ const requestFile = `./${import_node_path.default.basename(outputRequestFileName, ".ts")}`;
86
+ const responseValidatorFile = `./${import_node_path.default.basename(outputResponseValidationFileName, ".ts")}`;
87
+ const responseFile = `./${import_node_path.default.basename(outputResponseFileName, ".ts")}`;
88
+ operations.push({
89
+ operationId,
90
+ pascalCaseOperationId,
91
+ requestFile,
92
+ responseValidatorFile,
93
+ responseFile
94
+ });
95
+ }
96
+ const content = context.renderTemplate(templateFilePath, {
97
+ coreDir: context.coreDir,
98
+ pascalCaseEntityName,
99
+ operations
100
+ });
101
+ const outputClientFile = import_node_path.default.join(
102
+ outputDir,
103
+ `${pascalCaseEntityName}Client.ts`
104
+ );
105
+ const relativePath = import_node_path.default.relative(context.outputDir, outputClientFile);
106
+ context.writeFile(relativePath, content);
107
+ }
108
+ static writeRequestCommands(templateFilePath, operationResources, context) {
109
+ for (const operationResource of operationResources) {
110
+ this.writeRequestCommand(templateFilePath, operationResource, context);
111
+ }
112
+ }
113
+ static writeRequestCommand(templateFilePath, operationResource, context) {
114
+ const {
115
+ definition,
116
+ sourceDir,
117
+ sourceFile,
118
+ outputDir,
119
+ outputResponseFileName,
120
+ outputResponseValidationFileName,
121
+ outputRequestFileName
122
+ } = operationResource;
123
+ const { operationId, method, request, responses } = definition;
124
+ const pascalCaseOperationId = import_case.default.pascal(operationId);
125
+ const allResponses = responses;
126
+ const ownSuccessResponses = allResponses.filter(
127
+ (r) => r.statusCode >= 200 && r.statusCode < 300 && !r.isReference
128
+ );
129
+ const ownErrorResponses = allResponses.filter(
130
+ (r) => (r.statusCode < 200 || r.statusCode >= 300) && !r.isReference
131
+ );
132
+ const sharedSuccessResponses = allResponses.filter(
133
+ (r) => r.statusCode >= 200 && r.statusCode < 300 && r.isReference
134
+ );
135
+ const sharedErrorResponses = allResponses.filter(
136
+ (r) => (r.statusCode < 200 || r.statusCode >= 300) && r.isReference
137
+ );
138
+ const headerTsType = request.header ? import_typeweaver_zod_to_ts.TsTypePrinter.print(import_typeweaver_zod_to_ts.TsTypeNode.fromZod(request.header)) : void 0;
139
+ const paramTsType = request.param ? import_typeweaver_zod_to_ts.TsTypePrinter.print(import_typeweaver_zod_to_ts.TsTypeNode.fromZod(request.param)) : void 0;
140
+ const queryTsType = request.query ? import_typeweaver_zod_to_ts.TsTypePrinter.print(import_typeweaver_zod_to_ts.TsTypeNode.fromZod(request.query)) : void 0;
141
+ const bodyTsType = request.body ? import_typeweaver_zod_to_ts.TsTypePrinter.print(import_typeweaver_zod_to_ts.TsTypeNode.fromZod(request.body)) : void 0;
142
+ const successResponseImportPath = (response) => {
143
+ if (response.isReference && response.path) {
144
+ return response.path;
145
+ }
146
+ return `./${import_node_path.default.basename(outputResponseFileName, ".ts")}`;
147
+ };
148
+ const requestFile = `./${import_node_path.default.basename(outputRequestFileName, ".ts")}`;
149
+ const responseValidatorFile = `./${import_node_path.default.basename(outputResponseValidationFileName, ".ts")}`;
150
+ const relativeSourceFile = import_node_path.default.relative(sourceDir, sourceFile);
151
+ const sourcePath = import_node_path.default.join(
152
+ sourceDir,
153
+ relativeSourceFile.replace(/\.ts$/, "")
154
+ );
155
+ const relativeSourcePath = import_node_path.default.relative(outputDir, sourcePath);
156
+ const content = context.renderTemplate(templateFilePath, {
157
+ sourcePath: relativeSourcePath,
158
+ operationId,
159
+ pascalCaseOperationId,
160
+ method,
161
+ headerTsType,
162
+ paramTsType,
163
+ queryTsType,
164
+ bodyTsType,
165
+ ownSuccessResponses,
166
+ ownErrorResponses,
167
+ sharedSuccessResponses,
168
+ sharedErrorResponses,
169
+ requestFile,
170
+ responseValidatorFile,
171
+ successResponseImportPath
172
+ });
173
+ const outputCommandFile = import_node_path.default.join(
174
+ outputDir,
175
+ `${pascalCaseOperationId}RequestCommand.ts`
176
+ );
177
+ const relativePath = import_node_path.default.relative(context.outputDir, outputCommandFile);
178
+ context.writeFile(relativePath, content);
179
+ }
180
+ };
181
+
182
+ // src/index.ts
183
+ var moduleDir2 = import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(importMetaUrl));
184
+ var ClientsPlugin = class extends import_typeweaver_gen.BasePlugin {
185
+ name = "clients";
186
+ generate(context) {
187
+ const libDir = import_node_path2.default.join(moduleDir2, "lib");
188
+ this.copyLibFiles(context, libDir, "clients");
189
+ ClientGenerator.generate(context);
190
+ }
191
+ };
@@ -0,0 +1,8 @@
1
+ import { BasePlugin, GeneratorContext } from '@rexeus/typeweaver-gen';
2
+
3
+ declare class ClientsPlugin extends BasePlugin {
4
+ name: string;
5
+ generate(context: GeneratorContext): Promise<void> | void;
6
+ }
7
+
8
+ export { ClientsPlugin as default };
package/dist/index.js CHANGED
@@ -1,15 +1,19 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
- import { BasePlugin } from '@rexeus/typeweaver-gen';
4
- import { TsTypePrinter, TsTypeNode } from '@rexeus/typeweaver-zod-to-ts';
5
- import Case from 'case';
1
+ // src/index.ts
2
+ import path2 from "node:path";
3
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
4
+ import { BasePlugin } from "@rexeus/typeweaver-gen";
6
5
 
7
- const __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
8
- class ClientGenerator {
6
+ // src/ClientGenerator.ts
7
+ import path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import { TsTypeNode, TsTypePrinter } from "@rexeus/typeweaver-zod-to-ts";
10
+ import Case from "case";
11
+ var moduleDir = path.dirname(fileURLToPath(import.meta.url));
12
+ var ClientGenerator = class {
9
13
  static generate(context) {
10
- const clientTemplatePath = path.join(__dirname$1, "templates", "Client.ejs");
14
+ const clientTemplatePath = path.join(moduleDir, "templates", "Client.ejs");
11
15
  const commandTemplatePath = path.join(
12
- __dirname$1,
16
+ moduleDir,
13
17
  "templates",
14
18
  "RequestCommand.ejs"
15
19
  );
@@ -133,16 +137,18 @@ class ClientGenerator {
133
137
  const relativePath = path.relative(context.outputDir, outputCommandFile);
134
138
  context.writeFile(relativePath, content);
135
139
  }
136
- }
140
+ };
137
141
 
138
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
139
- class ClientsPlugin extends BasePlugin {
142
+ // src/index.ts
143
+ var moduleDir2 = path2.dirname(fileURLToPath2(import.meta.url));
144
+ var ClientsPlugin = class extends BasePlugin {
140
145
  name = "clients";
141
146
  generate(context) {
142
- const libDir = path.join(__dirname, "lib");
147
+ const libDir = path2.join(moduleDir2, "lib");
143
148
  this.copyLibFiles(context, libDir, "clients");
144
149
  ClientGenerator.generate(context);
145
150
  }
146
- }
147
-
148
- export { ClientsPlugin as default };
151
+ };
152
+ export {
153
+ ClientsPlugin as default
154
+ };
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "@rexeus/typeweaver-clients",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Generates HTTP clients directly from your API definitions. Powered by Typeweaver 🧵✨",
5
5
  "type": "module",
6
- "main": "dist/index.js",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
12
19
  }
13
20
  },
14
21
  "files": [
@@ -39,25 +46,25 @@
39
46
  },
40
47
  "homepage": "https://github.com/rexeus/typeweaver#readme",
41
48
  "peerDependencies": {
42
- "axios": "^1.7.0",
43
- "@rexeus/typeweaver-core": "^0.2.1",
44
- "@rexeus/typeweaver-gen": "^0.2.1"
49
+ "axios": "^1.13.2",
50
+ "@rexeus/typeweaver-core": "^0.3.0",
51
+ "@rexeus/typeweaver-gen": "^0.3.0"
45
52
  },
46
53
  "devDependencies": {
47
- "@hono/node-server": "^1.19.5",
48
- "axios": "^1.12.2",
54
+ "@hono/node-server": "^1.19.7",
55
+ "axios": "^1.13.2",
49
56
  "test-utils": "file:../test-utils",
50
- "@rexeus/typeweaver-core": "^0.2.1",
51
- "@rexeus/typeweaver-gen": "^0.2.1"
57
+ "@rexeus/typeweaver-core": "^0.3.0",
58
+ "@rexeus/typeweaver-gen": "^0.3.0"
52
59
  },
53
60
  "dependencies": {
54
61
  "case": "^1.6.3",
55
- "@rexeus/typeweaver-zod-to-ts": "^0.2.1"
62
+ "@rexeus/typeweaver-zod-to-ts": "^0.3.0"
56
63
  },
57
64
  "scripts": {
58
65
  "typecheck": "tsc --noEmit",
59
66
  "format": "prettier --write .",
60
- "build": "pkgroll --clean-dist && cp -r ./src/templates ./dist/templates && cp -r ./src/lib ./dist/lib && cp ../../LICENSE ../../NOTICE ./dist/",
67
+ "build": "tsup && mkdir -p ./dist/templates ./dist/lib && cp -r ./src/templates/* ./dist/templates/ && cp -r ./src/lib/* ./dist/lib/ && cp ../../LICENSE ../../NOTICE ./dist/",
61
68
  "test": "vitest --run",
62
69
  "preversion": "npm run build"
63
70
  }