@rexeus/typeweaver-hono 0.2.1 → 0.3.1

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,134 @@
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: () => HonoPlugin
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/HonoRouterGenerator.ts
47
+ var import_node_path = __toESM(require("node:path"), 1);
48
+ var import_node_url = require("node:url");
49
+ var import_typeweaver_core = require("@rexeus/typeweaver-core");
50
+ var import_case = __toESM(require("case"), 1);
51
+ var HonoRouterGenerator = class {
52
+ static generate(context) {
53
+ const moduleDir2 = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
54
+ const templateFile = import_node_path.default.join(moduleDir2, "templates", "HonoRouter.ejs");
55
+ for (const [entityName, entityResource] of Object.entries(
56
+ context.resources.entityResources
57
+ )) {
58
+ this.writeHonoRouter(
59
+ entityName,
60
+ templateFile,
61
+ entityResource.operations,
62
+ context
63
+ );
64
+ }
65
+ }
66
+ static writeHonoRouter(entityName, templateFile, operationResources, context) {
67
+ const pascalCaseEntityName = import_case.default.pascal(entityName);
68
+ const outputDir = import_node_path.default.join(context.outputDir, entityName);
69
+ const outputPath = import_node_path.default.join(outputDir, `${pascalCaseEntityName}Hono.ts`);
70
+ const operations = operationResources.filter((resource) => resource.definition.method !== import_typeweaver_core.HttpMethod.HEAD).map((resource) => this.createOperationData(resource)).sort((a, b) => this.compareRoutes(a, b));
71
+ const content = context.renderTemplate(templateFile, {
72
+ coreDir: import_node_path.default.relative(outputDir, context.outputDir),
73
+ entityName,
74
+ pascalCaseEntityName,
75
+ operations
76
+ });
77
+ const relativePath = import_node_path.default.relative(context.outputDir, outputPath);
78
+ context.writeFile(relativePath, content);
79
+ }
80
+ static createOperationData(resource) {
81
+ const operationId = resource.definition.operationId;
82
+ const className = import_case.default.pascal(operationId);
83
+ const handlerName = `handle${className}Request`;
84
+ return {
85
+ className,
86
+ handlerName,
87
+ method: resource.definition.method,
88
+ path: resource.definition.path
89
+ };
90
+ }
91
+ static compareRoutes(a, b) {
92
+ const aSegments = a.path.split("/").filter((s) => s);
93
+ const bSegments = b.path.split("/").filter((s) => s);
94
+ if (aSegments.length !== bSegments.length) {
95
+ return aSegments.length - bSegments.length;
96
+ }
97
+ for (let i = 0; i < aSegments.length; i++) {
98
+ const aSegment = aSegments[i];
99
+ const bSegment = bSegments[i];
100
+ const aIsParam = aSegment.startsWith(":");
101
+ const bIsParam = bSegment.startsWith(":");
102
+ if (aIsParam !== bIsParam) {
103
+ return aIsParam ? 1 : -1;
104
+ }
105
+ if (aSegment !== bSegment) {
106
+ return aSegment.localeCompare(bSegment);
107
+ }
108
+ }
109
+ return this.getMethodPriority(a.method) - this.getMethodPriority(b.method);
110
+ }
111
+ static getMethodPriority(method) {
112
+ const priorities = {
113
+ GET: 1,
114
+ POST: 2,
115
+ PUT: 3,
116
+ PATCH: 4,
117
+ DELETE: 5,
118
+ OPTIONS: 6,
119
+ HEAD: 7
120
+ };
121
+ return priorities[method] ?? 999;
122
+ }
123
+ };
124
+
125
+ // src/index.ts
126
+ var moduleDir = import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(importMetaUrl));
127
+ var HonoPlugin = class extends import_typeweaver_gen.BasePlugin {
128
+ name = "hono";
129
+ generate(context) {
130
+ const libSourceDir = import_node_path2.default.join(moduleDir, "lib");
131
+ this.copyLibFiles(context, libSourceDir, this.name);
132
+ HonoRouterGenerator.generate(context);
133
+ }
134
+ };
@@ -0,0 +1,8 @@
1
+ import { BasePlugin, GeneratorContext } from '@rexeus/typeweaver-gen';
2
+
3
+ declare class HonoPlugin extends BasePlugin {
4
+ name: string;
5
+ generate(context: GeneratorContext): void;
6
+ }
7
+
8
+ export { HonoPlugin as default };
package/dist/index.js CHANGED
@@ -1,15 +1,17 @@
1
- import path$1 from 'path';
2
- import { fileURLToPath as fileURLToPath$1 } from 'url';
3
- import { BasePlugin } from '@rexeus/typeweaver-gen';
4
- import path from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
- import { HttpMethod } from '@rexeus/typeweaver-core';
7
- 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";
8
5
 
9
- class HonoRouterGenerator {
6
+ // src/HonoRouterGenerator.ts
7
+ import path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import { HttpMethod } from "@rexeus/typeweaver-core";
10
+ import Case from "case";
11
+ var HonoRouterGenerator = class {
10
12
  static generate(context) {
11
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
12
- const templateFile = path.join(__dirname, "templates", "HonoRouter.ejs");
13
+ const moduleDir2 = path.dirname(fileURLToPath(import.meta.url));
14
+ const templateFile = path.join(moduleDir2, "templates", "HonoRouter.ejs");
13
15
  for (const [entityName, entityResource] of Object.entries(
14
16
  context.resources.entityResources
15
17
  )) {
@@ -78,16 +80,18 @@ class HonoRouterGenerator {
78
80
  };
79
81
  return priorities[method] ?? 999;
80
82
  }
81
- }
83
+ };
82
84
 
83
- const __dirname = path$1.dirname(fileURLToPath$1(import.meta.url));
84
- class HonoPlugin extends BasePlugin {
85
+ // src/index.ts
86
+ var moduleDir = path2.dirname(fileURLToPath2(import.meta.url));
87
+ var HonoPlugin = class extends BasePlugin {
85
88
  name = "hono";
86
89
  generate(context) {
87
- const libSourceDir = path$1.join(__dirname, "lib");
90
+ const libSourceDir = path2.join(moduleDir, "lib");
88
91
  this.copyLibFiles(context, libSourceDir, this.name);
89
92
  HonoRouterGenerator.generate(context);
90
93
  }
91
- }
92
-
93
- export { HonoPlugin as default };
94
+ };
95
+ export {
96
+ HonoPlugin as default
97
+ };
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "@rexeus/typeweaver-hono",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "Generates Hono routers and handlers straight 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": [
@@ -38,15 +45,15 @@
38
45
  },
39
46
  "homepage": "https://github.com/rexeus/typeweaver#readme",
40
47
  "peerDependencies": {
41
- "hono": "^4.9.7",
42
- "@rexeus/typeweaver-core": "^0.2.1",
43
- "@rexeus/typeweaver-gen": "^0.2.1"
48
+ "hono": "^4.11.3",
49
+ "@rexeus/typeweaver-core": "^0.3.1",
50
+ "@rexeus/typeweaver-gen": "^0.3.1"
44
51
  },
45
52
  "devDependencies": {
46
- "hono": "^4.9.9",
53
+ "hono": "^4.11.3",
47
54
  "test-utils": "file:../test-utils",
48
- "@rexeus/typeweaver-core": "^0.2.1",
49
- "@rexeus/typeweaver-gen": "^0.2.1"
55
+ "@rexeus/typeweaver-core": "^0.3.1",
56
+ "@rexeus/typeweaver-gen": "^0.3.1"
50
57
  },
51
58
  "dependencies": {
52
59
  "case": "^1.6.3"
@@ -54,7 +61,7 @@
54
61
  "scripts": {
55
62
  "typecheck": "tsc --noEmit",
56
63
  "format": "prettier --write .",
57
- "build": "pkgroll --clean-dist && cp -r ./src/templates ./dist/templates && cp -r ./src/lib ./dist/lib && cp ../../LICENSE ../../NOTICE ./dist/",
64
+ "build": "tsup && mkdir -p ./dist/templates ./dist/lib && cp -r ./src/templates/* ./dist/templates/ && cp -r ./src/lib/* ./dist/lib/ && cp ../../LICENSE ../../NOTICE ./dist/",
58
65
  "test": "vitest --run",
59
66
  "preversion": "npm run build"
60
67
  }