@rexeus/typeweaver-server 0.9.1 → 0.10.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 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,
@@ -93,4 +92,4 @@ var ServerPlugin = class extends _rexeus_typeweaver_gen.BasePlugin {
93
92
  }
94
93
  };
95
94
  //#endregion
96
- module.exports = ServerPlugin;
95
+ exports.ServerPlugin = ServerPlugin;
package/dist/index.d.cts CHANGED
@@ -17,5 +17,6 @@ declare class ServerPlugin extends BasePlugin {
17
17
  */
18
18
  generate(context: GeneratorContext): void;
19
19
  }
20
- export = ServerPlugin;
20
+ //#endregion
21
+ export { ServerPlugin };
21
22
  //# 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;EAOkB;;;;;EAAT,QAAA,CAAS,OAAA,EAAS,gBAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -18,5 +18,5 @@ declare class ServerPlugin extends BasePlugin {
18
18
  generate(context: GeneratorContext): void;
19
19
  }
20
20
  //#endregion
21
- export { ServerPlugin as default };
21
+ export { ServerPlugin };
22
22
  //# 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;EAOkB;;;;;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,
@@ -69,6 +68,6 @@ var ServerPlugin = class extends BasePlugin {
69
68
  }
70
69
  };
71
70
  //#endregion
72
- export { ServerPlugin as default };
71
+ export { ServerPlugin };
73
72
 
74
73
  //# 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\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;;;;;;CAOd,SAAyB,SAAiC;EACxD,MAAM,eAAe,KAAK,KAAK,WAAW,MAAM;AAChD,OAAK,aAAa,SAAS,cAAc,KAAK,KAAK;AAEnD,WAAgB,QAAQ"}
@@ -284,14 +284,14 @@ export class FetchApiAdapter {
284
284
  private static concatChunks(
285
285
  chunks: Uint8Array[],
286
286
  totalBytes: number
287
- ): Uint8Array {
287
+ ): ArrayBuffer {
288
288
  const buffer = new Uint8Array(totalBytes);
289
289
  let offset = 0;
290
290
  for (const chunk of chunks) {
291
291
  buffer.set(chunk, offset);
292
292
  offset += chunk.byteLength;
293
293
  }
294
- return buffer;
294
+ return buffer.buffer as ArrayBuffer;
295
295
  }
296
296
 
297
297
  private static serializeResponseBody(
@@ -103,8 +103,8 @@ async function handleRequest(
103
103
  function collectBody(
104
104
  req: IncomingMessage,
105
105
  maxBodySize: number
106
- ): Promise<Buffer> {
107
- return new Promise<Buffer>((resolve, reject) => {
106
+ ): Promise<ArrayBuffer> {
107
+ return new Promise<ArrayBuffer>((resolve, reject) => {
108
108
  const chunks: Buffer[] = [];
109
109
  let totalBytes = 0;
110
110
 
@@ -118,7 +118,15 @@ function collectBody(
118
118
  chunks.push(chunk);
119
119
  });
120
120
 
121
- req.on("end", () => resolve(Buffer.concat(chunks, totalBytes)));
121
+ req.on("end", () => {
122
+ const combined = Buffer.concat(chunks, totalBytes);
123
+ resolve(
124
+ combined.buffer.slice(
125
+ combined.byteOffset,
126
+ combined.byteOffset + combined.byteLength
127
+ ) as ArrayBuffer
128
+ );
129
+ });
122
130
  req.on("error", reject);
123
131
  });
124
132
  }
@@ -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.1",
3
+ "version": "0.10.0",
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,18 +47,15 @@
47
47
  },
48
48
  "homepage": "https://github.com/rexeus/typeweaver#readme",
49
49
  "peerDependencies": {
50
- "@rexeus/typeweaver-gen": "^0.9.1",
51
- "@rexeus/typeweaver-core": "^0.9.1"
50
+ "@rexeus/typeweaver-core": "^0.10.0",
51
+ "@rexeus/typeweaver-gen": "^0.10.0"
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.1",
58
- "@rexeus/typeweaver-gen": "^0.9.1"
59
- },
60
- "dependencies": {
61
- "case": "^1.6.3"
57
+ "@rexeus/typeweaver-core": "^0.10.0",
58
+ "@rexeus/typeweaver-gen": "^0.10.0"
62
59
  },
63
60
  "scripts": {
64
61
  "typecheck": "tsc --noEmit -p tsconfig.typecheck.json",