@rexeus/typeweaver-server 0.9.2 → 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 +4 -4
- package/dist/index.cjs +4 -5
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -5
- package/dist/index.mjs.map +1 -1
- package/dist/lib/TypeweaverApp.ts +1 -1
- package/package.json +5 -8
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
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
95
|
+
exports.ServerPlugin = ServerPlugin;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;
|
|
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
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;
|
|
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 =
|
|
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 =
|
|
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
|
|
71
|
+
export { ServerPlugin };
|
|
73
72
|
|
|
74
73
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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\";\
|
|
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"}
|
|
@@ -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
|
|
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.
|
|
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-core": "^0.
|
|
51
|
-
"@rexeus/typeweaver-gen": "^0.
|
|
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.
|
|
58
|
-
"@rexeus/typeweaver-gen": "^0.
|
|
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",
|