@rexeus/typeweaver-server 0.9.2 → 0.10.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/README.md CHANGED
@@ -126,7 +126,7 @@ import { userHandlers } from "./user-handlers";
126
126
  const app = new TypeweaverApp();
127
127
  app.route(new UserRouter({ requestHandlers: userHandlers }));
128
128
 
129
- export default app;
129
+ export { app };
130
130
  ```
131
131
 
132
132
  ### Start the server
@@ -134,7 +134,7 @@ export default app;
134
134
  **Bun**
135
135
 
136
136
  ```ts
137
- import app from "./server";
137
+ import { app } from "./server";
138
138
 
139
139
  Bun.serve({ fetch: app.fetch, port: 3000 });
140
140
  ```
@@ -142,7 +142,7 @@ Bun.serve({ fetch: app.fetch, port: 3000 });
142
142
  **Deno**
143
143
 
144
144
  ```ts
145
- import app from "./server.ts";
145
+ import { app } from "./server.ts";
146
146
 
147
147
  Deno.serve({ port: 3000 }, app.fetch);
148
148
  ```
@@ -152,7 +152,7 @@ Deno.serve({ port: 3000 }, app.fetch);
152
152
  ```ts
153
153
  import { createServer } from "node:http";
154
154
  import { nodeAdapter } from "./generated/lib/server";
155
- import app from "./server";
155
+ import { app } from "./server";
156
156
 
157
157
  createServer(nodeAdapter(app)).listen(3000);
158
158
  ```
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
2
  //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -25,8 +26,6 @@ node_path = __toESM(node_path);
25
26
  let node_url = require("node:url");
26
27
  let _rexeus_typeweaver_gen = require("@rexeus/typeweaver-gen");
27
28
  let _rexeus_typeweaver_core = require("@rexeus/typeweaver-core");
28
- let case$1 = require("case");
29
- case$1 = __toESM(case$1);
30
29
  //#region src/routerGenerator.ts
31
30
  /**
32
31
  * Generates TypeweaverRouter subclasses from API definitions.
@@ -45,7 +44,7 @@ function generate(context) {
45
44
  for (const resource of context.normalizedSpec.resources) writeRouter(resource, templateFile, context);
46
45
  }
47
46
  function writeRouter(resource, templateFile, context) {
48
- const pascalCaseEntityName = case$1.default.pascal(resource.name);
47
+ const pascalCaseEntityName = (0, _rexeus_typeweaver_gen.toPascalCase)(resource.name);
49
48
  const outputDir = context.getResourceOutputDir(resource.name);
50
49
  const outputPath = node_path.default.join(outputDir, `${pascalCaseEntityName}Router.ts`);
51
50
  const operations = resource.operations.filter((operation) => operation.method !== _rexeus_typeweaver_core.HttpMethod.HEAD).map((operation) => createOperationData(operation)).sort((a, b) => (0, _rexeus_typeweaver_gen.compareRoutes)(a, b));
@@ -60,7 +59,7 @@ function writeRouter(resource, templateFile, context) {
60
59
  }
61
60
  function createOperationData(operation) {
62
61
  const operationId = operation.operationId;
63
- const className = case$1.default.pascal(operationId);
62
+ const className = (0, _rexeus_typeweaver_gen.toPascalCase)(operationId);
64
63
  return {
65
64
  operationId,
66
65
  className,
@@ -81,6 +80,7 @@ const moduleDir = node_path.default.dirname((0, node_url.fileURLToPath)(require(
81
80
  */
82
81
  var ServerPlugin = class extends _rexeus_typeweaver_gen.BasePlugin {
83
82
  name = "server";
83
+ depends = ["types"];
84
84
  /**
85
85
  * Generates the server runtime and typed routers for all resources.
86
86
  *
@@ -93,4 +93,4 @@ var ServerPlugin = class extends _rexeus_typeweaver_gen.BasePlugin {
93
93
  }
94
94
  };
95
95
  //#endregion
96
- module.exports = ServerPlugin;
96
+ exports.ServerPlugin = ServerPlugin;
package/dist/index.d.cts CHANGED
@@ -10,6 +10,7 @@ import { BasePlugin, GeneratorContext } from "@rexeus/typeweaver-gen";
10
10
  */
11
11
  declare class ServerPlugin extends BasePlugin {
12
12
  name: string;
13
+ depends: string[];
13
14
  /**
14
15
  * Generates the server runtime and typed routers for all resources.
15
16
  *
@@ -17,5 +18,6 @@ declare class ServerPlugin extends BasePlugin {
17
18
  */
18
19
  generate(context: GeneratorContext): void;
19
20
  }
20
- export = ServerPlugin;
21
+ //#endregion
22
+ export { ServerPlugin };
21
23
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;AAG+D;;;;;;cAY1C,YAAA,SAAqB,UAAA;EACjC,IAAA;EAOkB;;;;;EAAT,QAAA,CAAS,OAAA,EAAS,gBAAA;AAAA;AAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;AAeA;;;;;;cAAa,YAAA,SAAqB,UAAA;EACzB,IAAA;EACS,OAAA;EAOS;;;;;EAAT,QAAA,CAAS,OAAA,EAAS,gBAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -10,6 +10,7 @@ import { BasePlugin, GeneratorContext } from "@rexeus/typeweaver-gen";
10
10
  */
11
11
  declare class ServerPlugin extends BasePlugin {
12
12
  name: string;
13
+ depends: string[];
13
14
  /**
14
15
  * Generates the server runtime and typed routers for all resources.
15
16
  *
@@ -18,5 +19,5 @@ declare class ServerPlugin extends BasePlugin {
18
19
  generate(context: GeneratorContext): void;
19
20
  }
20
21
  //#endregion
21
- export { ServerPlugin as default };
22
+ export { ServerPlugin };
22
23
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;AAG+D;;;;;;cAY1C,YAAA,SAAqB,UAAA;EACjC,IAAA;EAOkB;;;;;EAAT,QAAA,CAAS,OAAA,EAAS,gBAAA;AAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;AAeA;;;;;;cAAa,YAAA,SAAqB,UAAA;EACzB,IAAA;EACS,OAAA;EAOS;;;;;EAAT,QAAA,CAAS,OAAA,EAAS,gBAAA;AAAA"}
package/dist/index.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  import path from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- import { BasePlugin, compareRoutes, relative } from "@rexeus/typeweaver-gen";
3
+ import { BasePlugin, compareRoutes, relative, toPascalCase } from "@rexeus/typeweaver-gen";
4
4
  import { HttpMethod } from "@rexeus/typeweaver-core";
5
- import Case from "case";
6
5
  //#region src/routerGenerator.ts
7
6
  /**
8
7
  * Generates TypeweaverRouter subclasses from API definitions.
@@ -21,7 +20,7 @@ function generate(context) {
21
20
  for (const resource of context.normalizedSpec.resources) writeRouter(resource, templateFile, context);
22
21
  }
23
22
  function writeRouter(resource, templateFile, context) {
24
- const pascalCaseEntityName = Case.pascal(resource.name);
23
+ const pascalCaseEntityName = toPascalCase(resource.name);
25
24
  const outputDir = context.getResourceOutputDir(resource.name);
26
25
  const outputPath = path.join(outputDir, `${pascalCaseEntityName}Router.ts`);
27
26
  const operations = resource.operations.filter((operation) => operation.method !== HttpMethod.HEAD).map((operation) => createOperationData(operation)).sort((a, b) => compareRoutes(a, b));
@@ -36,7 +35,7 @@ function writeRouter(resource, templateFile, context) {
36
35
  }
37
36
  function createOperationData(operation) {
38
37
  const operationId = operation.operationId;
39
- const className = Case.pascal(operationId);
38
+ const className = toPascalCase(operationId);
40
39
  return {
41
40
  operationId,
42
41
  className,
@@ -57,6 +56,7 @@ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
57
56
  */
58
57
  var ServerPlugin = class extends BasePlugin {
59
58
  name = "server";
59
+ depends = ["types"];
60
60
  /**
61
61
  * Generates the server runtime and typed routers for all resources.
62
62
  *
@@ -69,6 +69,6 @@ var ServerPlugin = class extends BasePlugin {
69
69
  }
70
70
  };
71
71
  //#endregion
72
- export { ServerPlugin as default };
72
+ export { ServerPlugin };
73
73
 
74
74
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/routerGenerator.ts","../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { HttpMethod } from \"@rexeus/typeweaver-core\";\nimport { compareRoutes, relative } from \"@rexeus/typeweaver-gen\";\nimport type {\n GeneratorContext,\n NormalizedOperation,\n NormalizedResource,\n} from \"@rexeus/typeweaver-gen\";\nimport Case from \"case\";\n\ntype OperationData = {\n readonly operationId: string;\n readonly className: string;\n readonly handlerName: string;\n readonly method: string;\n readonly path: string;\n};\n\n/**\n * Generates TypeweaverRouter subclasses from API definitions.\n *\n * For each resource (e.g., `Todo`, `Account`), produces a `<ResourceName>Router.ts`\n * file that extends `TypeweaverRouter` and registers all operations as routes.\n */\n\n/**\n * Generates router files for all resources in the given context.\n *\n * @param context - The generator context containing resources, templates, and output configuration\n */\nexport function generate(context: GeneratorContext): void {\n const moduleDir = path.dirname(fileURLToPath(import.meta.url));\n const templateFile = path.join(moduleDir, \"templates\", \"Router.ejs\");\n\n for (const resource of context.normalizedSpec.resources) {\n writeRouter(resource, templateFile, context);\n }\n}\n\nfunction writeRouter(\n resource: NormalizedResource,\n templateFile: string,\n context: GeneratorContext\n): void {\n const pascalCaseEntityName = Case.pascal(resource.name);\n const outputDir = context.getResourceOutputDir(resource.name);\n const outputPath = path.join(outputDir, `${pascalCaseEntityName}Router.ts`);\n\n const operations = resource.operations\n .filter(operation => operation.method !== HttpMethod.HEAD)\n .map(operation => createOperationData(operation))\n .sort((a, b) => compareRoutes(a, b));\n\n const content = context.renderTemplate(templateFile, {\n coreDir: relative(outputDir, context.outputDir),\n entityName: resource.name,\n pascalCaseEntityName,\n operations,\n });\n\n const relativePath = path.relative(context.outputDir, outputPath);\n context.writeFile(relativePath, content);\n}\n\nfunction createOperationData(operation: NormalizedOperation): OperationData {\n const operationId = operation.operationId;\n const className = Case.pascal(operationId);\n\n return {\n operationId,\n className,\n handlerName: `handle${className}Request`,\n method: operation.method,\n path: operation.path,\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 { generate as generateRouters } from \"./routerGenerator\";\n\nconst moduleDir = path.dirname(fileURLToPath(import.meta.url));\n\n/**\n * Typeweaver plugin that generates a lightweight, dependency-free server\n * with built-in routing and middleware support.\n *\n * Copies the runtime library files (`TypeweaverApp`, `TypeweaverRouter`, `Router`,\n * `Middleware`, etc.) and generates typed router classes for each resource.\n */\nexport default class ServerPlugin extends BasePlugin {\n public name = \"server\";\n\n /**\n * Generates the server runtime and typed routers for all resources.\n *\n * @param context - The generator context\n */\n public override generate(context: GeneratorContext): void {\n const libSourceDir = path.join(moduleDir, \"lib\");\n this.copyLibFiles(context, libSourceDir, this.name);\n\n generateRouters(context);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,SAAgB,SAAS,SAAiC;CACxD,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;CAC9D,MAAM,eAAe,KAAK,KAAK,WAAW,aAAa,aAAa;AAEpE,MAAK,MAAM,YAAY,QAAQ,eAAe,UAC5C,aAAY,UAAU,cAAc,QAAQ;;AAIhD,SAAS,YACP,UACA,cACA,SACM;CACN,MAAM,uBAAuB,KAAK,OAAO,SAAS,KAAK;CACvD,MAAM,YAAY,QAAQ,qBAAqB,SAAS,KAAK;CAC7D,MAAM,aAAa,KAAK,KAAK,WAAW,GAAG,qBAAqB,WAAW;CAE3E,MAAM,aAAa,SAAS,WACzB,QAAO,cAAa,UAAU,WAAW,WAAW,KAAK,CACzD,KAAI,cAAa,oBAAoB,UAAU,CAAC,CAChD,MAAM,GAAG,MAAM,cAAc,GAAG,EAAE,CAAC;CAEtC,MAAM,UAAU,QAAQ,eAAe,cAAc;EACnD,SAAS,SAAS,WAAW,QAAQ,UAAU;EAC/C,YAAY,SAAS;EACrB;EACA;EACD,CAAC;CAEF,MAAM,eAAe,KAAK,SAAS,QAAQ,WAAW,WAAW;AACjE,SAAQ,UAAU,cAAc,QAAQ;;AAG1C,SAAS,oBAAoB,WAA+C;CAC1E,MAAM,cAAc,UAAU;CAC9B,MAAM,YAAY,KAAK,OAAO,YAAY;AAE1C,QAAO;EACL;EACA;EACA,aAAa,SAAS,UAAU;EAChC,QAAQ,UAAU;EAClB,MAAM,UAAU;EACjB;;;;ACrEH,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;;;;;;;;AAS9D,IAAqB,eAArB,cAA0C,WAAW;CACnD,OAAc;;;;;;CAOd,SAAyB,SAAiC;EACxD,MAAM,eAAe,KAAK,KAAK,WAAW,MAAM;AAChD,OAAK,aAAa,SAAS,cAAc,KAAK,KAAK;AAEnD,WAAgB,QAAQ"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/routerGenerator.ts","../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { HttpMethod } from \"@rexeus/typeweaver-core\";\nimport { compareRoutes, relative, toPascalCase } from \"@rexeus/typeweaver-gen\";\nimport type {\n GeneratorContext,\n NormalizedOperation,\n NormalizedResource,\n} from \"@rexeus/typeweaver-gen\";\n\ntype OperationData = {\n readonly operationId: string;\n readonly className: string;\n readonly handlerName: string;\n readonly method: string;\n readonly path: string;\n};\n\n/**\n * Generates TypeweaverRouter subclasses from API definitions.\n *\n * For each resource (e.g., `Todo`, `Account`), produces a `<ResourceName>Router.ts`\n * file that extends `TypeweaverRouter` and registers all operations as routes.\n */\n\n/**\n * Generates router files for all resources in the given context.\n *\n * @param context - The generator context containing resources, templates, and output configuration\n */\nexport function generate(context: GeneratorContext): void {\n const moduleDir = path.dirname(fileURLToPath(import.meta.url));\n const templateFile = path.join(moduleDir, \"templates\", \"Router.ejs\");\n\n for (const resource of context.normalizedSpec.resources) {\n writeRouter(resource, templateFile, context);\n }\n}\n\nfunction writeRouter(\n resource: NormalizedResource,\n templateFile: string,\n context: GeneratorContext\n): void {\n const pascalCaseEntityName = toPascalCase(resource.name);\n const outputDir = context.getResourceOutputDir(resource.name);\n const outputPath = path.join(outputDir, `${pascalCaseEntityName}Router.ts`);\n\n const operations = resource.operations\n .filter(operation => operation.method !== HttpMethod.HEAD)\n .map(operation => createOperationData(operation))\n .sort((a, b) => compareRoutes(a, b));\n\n const content = context.renderTemplate(templateFile, {\n coreDir: relative(outputDir, context.outputDir),\n entityName: resource.name,\n pascalCaseEntityName,\n operations,\n });\n\n const relativePath = path.relative(context.outputDir, outputPath);\n context.writeFile(relativePath, content);\n}\n\nfunction createOperationData(operation: NormalizedOperation): OperationData {\n const operationId = operation.operationId;\n const className = toPascalCase(operationId);\n\n return {\n operationId,\n className,\n handlerName: `handle${className}Request`,\n method: operation.method,\n path: operation.path,\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 { generate as generateRouters } from \"./routerGenerator\";\n\nconst moduleDir = path.dirname(fileURLToPath(import.meta.url));\n\n/**\n * Typeweaver plugin that generates a lightweight, dependency-free server\n * with built-in routing and middleware support.\n *\n * Copies the runtime library files (`TypeweaverApp`, `TypeweaverRouter`, `Router`,\n * `Middleware`, etc.) and generates typed router classes for each resource.\n */\nexport class ServerPlugin extends BasePlugin {\n public name = \"server\";\n public override depends = [\"types\"];\n\n /**\n * Generates the server runtime and typed routers for all resources.\n *\n * @param context - The generator context\n */\n public override generate(context: GeneratorContext): void {\n const libSourceDir = path.join(moduleDir, \"lib\");\n this.copyLibFiles(context, libSourceDir, this.name);\n\n generateRouters(context);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8BA,SAAgB,SAAS,SAAiC;CACxD,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;CAC9D,MAAM,eAAe,KAAK,KAAK,WAAW,aAAa,aAAa;AAEpE,MAAK,MAAM,YAAY,QAAQ,eAAe,UAC5C,aAAY,UAAU,cAAc,QAAQ;;AAIhD,SAAS,YACP,UACA,cACA,SACM;CACN,MAAM,uBAAuB,aAAa,SAAS,KAAK;CACxD,MAAM,YAAY,QAAQ,qBAAqB,SAAS,KAAK;CAC7D,MAAM,aAAa,KAAK,KAAK,WAAW,GAAG,qBAAqB,WAAW;CAE3E,MAAM,aAAa,SAAS,WACzB,QAAO,cAAa,UAAU,WAAW,WAAW,KAAK,CACzD,KAAI,cAAa,oBAAoB,UAAU,CAAC,CAChD,MAAM,GAAG,MAAM,cAAc,GAAG,EAAE,CAAC;CAEtC,MAAM,UAAU,QAAQ,eAAe,cAAc;EACnD,SAAS,SAAS,WAAW,QAAQ,UAAU;EAC/C,YAAY,SAAS;EACrB;EACA;EACD,CAAC;CAEF,MAAM,eAAe,KAAK,SAAS,QAAQ,WAAW,WAAW;AACjE,SAAQ,UAAU,cAAc,QAAQ;;AAG1C,SAAS,oBAAoB,WAA+C;CAC1E,MAAM,cAAc,UAAU;CAC9B,MAAM,YAAY,aAAa,YAAY;AAE3C,QAAO;EACL;EACA;EACA,aAAa,SAAS,UAAU;EAChC,QAAQ,UAAU;EAClB,MAAM,UAAU;EACjB;;;;ACpEH,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;;;;;;;;AAS9D,IAAa,eAAb,cAAkC,WAAW;CAC3C,OAAc;CACd,UAA0B,CAAC,QAAQ;;;;;;CAOnC,SAAyB,SAAiC;EACxD,MAAM,eAAe,KAAK,KAAK,WAAW,MAAM;AAChD,OAAK,aAAa,SAAS,cAAc,KAAK,KAAK;AAEnD,WAAgB,QAAQ"}
@@ -111,7 +111,7 @@ export class TypeweaverApp<TState extends Record<string, unknown> = {}> {
111
111
  ([TState] extends [TReq] ? unknown : StateRequirementError<TReq, TState>)
112
112
  ): TypeweaverApp<TState & TProv> {
113
113
  this.middlewares.push(middleware.handler);
114
- return this as unknown as TypeweaverApp<TState & TProv>;
114
+ return this as TypeweaverApp<TState & TProv>;
115
115
  }
116
116
 
117
117
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexeus/typeweaver-server",
3
- "version": "0.9.2",
3
+ "version": "0.10.1",
4
4
  "description": "Generates a lightweight, dependency-free server with built-in routing and middleware from your API definitions. Powered by Typeweaver.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -47,23 +47,20 @@
47
47
  },
48
48
  "homepage": "https://github.com/rexeus/typeweaver#readme",
49
49
  "peerDependencies": {
50
- "@rexeus/typeweaver-core": "^0.9.2",
51
- "@rexeus/typeweaver-gen": "^0.9.2"
50
+ "@rexeus/typeweaver-core": "^0.10.1",
51
+ "@rexeus/typeweaver-gen": "^0.10.1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "get-port": "^7.2.0",
55
55
  "test-utils": "file:../test-utils",
56
56
  "tsx": "^4.21.0",
57
- "@rexeus/typeweaver-core": "^0.9.2",
58
- "@rexeus/typeweaver-gen": "^0.9.2"
59
- },
60
- "dependencies": {
61
- "case": "^1.6.3"
57
+ "@rexeus/typeweaver-core": "^0.10.1",
58
+ "@rexeus/typeweaver-gen": "^0.10.1"
62
59
  },
63
60
  "scripts": {
64
61
  "typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
65
62
  "format": "oxfmt",
66
- "build": "tsdown && mkdir -p ./dist/templates ./dist/lib && cp -r ./src/templates/* ./dist/templates/ && cp -r ./src/lib/* ./dist/lib/ && cp ../../LICENSE ../../NOTICE ./dist/",
63
+ "build": "tsdown",
67
64
  "test": "vitest --run",
68
65
  "preversion": "npm run build"
69
66
  }