@rexeus/typeweaver 0.5.1 → 0.6.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
@@ -56,6 +56,7 @@ Now you are ready to start building! Check out [Quickstart](#-get-started)
56
56
  | ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
57
57
  | [@rexeus/typeweaver-types](https://github.com/rexeus/typeweaver/tree/main/packages/types/README.md) | Plugin for request/response types and validation - the foundation for all other plugins and always included | ![npm](https://img.shields.io/npm/v/@rexeus/typeweaver-types) |
58
58
  | [@rexeus/typeweaver-clients](https://github.com/rexeus/typeweaver/tree/main/packages/clients/README.md) | Plugin for HTTP clients using fetch | ![npm](https://img.shields.io/npm/v/@rexeus/typeweaver-clients) |
59
+ | [@rexeus/typeweaver-server](https://github.com/rexeus/typeweaver/tree/main/packages/server/README.md) | Plugin for a zero-dependency, Fetch API-native server with built-in routing and middleware | ![npm](https://img.shields.io/npm/v/@rexeus/typeweaver-server) |
59
60
  | [@rexeus/typeweaver-hono](https://github.com/rexeus/typeweaver/tree/main/packages/hono/README.md) | Plugin for Hono routers | ![npm](https://img.shields.io/npm/v/@rexeus/typeweaver-hono) |
60
61
  | [@rexeus/typeweaver-aws-cdk](https://github.com/rexeus/typeweaver/tree/main/packages/aws-cdk/README.md) | Plugin for AWS CDK constructs for API Gateway V2 | ![npm](https://img.shields.io/npm/v/@rexeus/typeweaver-aws-cdk) |
61
62
 
@@ -95,7 +96,7 @@ bunx typeweaver generate --input ./api/definition --output ./api/generated --plu
95
96
  - `--config, -c <path>`: Configuration file path (optional)
96
97
  - `--plugins, -p <plugins>`: Comma-separated list of plugins to use (e.g., "clients,hono" or "all"
97
98
  for all plugins)
98
- - `--prettier / --no-prettier`: Enable/disable code formatting with Prettier (default: true)
99
+ - `--format / --no-format`: Enable/disable code formatting with oxfmt (default: true)
99
100
  - `--clean / --no-clean`: Enable/disable output directory cleaning (default: true)
100
101
 
101
102
  ### 📝 Configuration File
@@ -107,7 +108,7 @@ export default {
107
108
  input: "./api/definition",
108
109
  output: "./api/generated",
109
110
  plugins: ["clients", "hono", "aws-cdk"],
110
- prettier: true,
111
+ format: true,
111
112
  clean: true,
112
113
  };
113
114
  ```
@@ -212,7 +213,11 @@ export const userSchema = z.object({
212
213
 
213
214
  ```typescript
214
215
  // api/definition/user/GetUserDefinition.ts
215
- import { HttpOperationDefinition, HttpMethod, HttpStatusCode } from "@rexeus/typeweaver-core";
216
+ import {
217
+ HttpOperationDefinition,
218
+ HttpMethod,
219
+ HttpStatusCode,
220
+ } from "@rexeus/typeweaver-core";
216
221
  import { z } from "zod";
217
222
  import { sharedResponses } from "../shared/sharedResponses";
218
223
  import { userSchema } from "./userSchema";
@@ -248,7 +253,11 @@ export default new HttpOperationDefinition({
248
253
 
249
254
  ```typescript
250
255
  // api/definition/user/UpdateUserDefinition.ts
251
- import { HttpOperationDefinition, HttpMethod, HttpStatusCode } from "@rexeus/typeweaver-core";
256
+ import {
257
+ HttpOperationDefinition,
258
+ HttpMethod,
259
+ HttpStatusCode,
260
+ } from "@rexeus/typeweaver-core";
252
261
  import { z } from "zod";
253
262
  import { sharedResponses } from "../shared/sharedResponses";
254
263
  import { userSchema } from "./userSchema";
@@ -311,7 +320,10 @@ export default NotFoundErrorDefinition.extend({
311
320
 
312
321
  ```typescript
313
322
  // api/definition/user/errors/UserStatusTransitionInvalidErrorDefinition.ts
314
- import { HttpResponseDefinition, HttpStatusCode } from "@rexeus/typeweaver-core";
323
+ import {
324
+ HttpResponseDefinition,
325
+ HttpStatusCode,
326
+ } from "@rexeus/typeweaver-core";
315
327
  import { z } from "zod";
316
328
  import { userStatusSchema } from "../userSchema";
317
329
 
@@ -323,7 +335,9 @@ export default new HttpResponseDefinition({
323
335
  name: "UserStatusTransitionInvalidError",
324
336
  description: "User status transition is conflicting with current status",
325
337
  body: z.object({
326
- message: z.literal("User status transition is conflicting with current status"),
338
+ message: z.literal(
339
+ "User status transition is conflicting with current status",
340
+ ),
327
341
  code: z.literal("USER_STATUS_TRANSITION_INVALID_ERROR"),
328
342
  context: z.object({
329
343
  userId: z.uuid(),
@@ -375,7 +389,7 @@ npx typeweaver generate --input ./api/definition --output ./api/generated --plug
375
389
  // api/user-handlers.ts
376
390
  import { HttpResponse, HttpStatusCode } from "@rexeus/typeweaver-core";
377
391
  import {
378
- type UserApiHandler,
392
+ type HonoUserApiHandler,
379
393
  type IGetUserRequest,
380
394
  GetUserResponse,
381
395
  GetUserSuccessResponse,
@@ -387,10 +401,12 @@ import {
387
401
  ListUserResponse,
388
402
  } from "./generated";
389
403
 
390
- export class UserHandlers implements UserApiHandler {
404
+ export class UserHandlers implements HonoUserApiHandler {
391
405
  public constructor() {}
392
406
 
393
- public async handleGetUserRequest(request: IGetUserRequest): Promise<GetUserResponse> {
407
+ public async handleGetUserRequest(
408
+ request: IGetUserRequest,
409
+ ): Promise<GetUserResponse> {
394
410
  // Simulate fetching user data
395
411
  const fetchedUser = {
396
412
  id: request.param.userId,
@@ -410,15 +426,21 @@ export class UserHandlers implements UserApiHandler {
410
426
  });
411
427
  }
412
428
 
413
- public handleCreateUserRequest(request: ICreateUserRequest): Promise<CreateUserResponse> {
429
+ public handleCreateUserRequest(
430
+ request: ICreateUserRequest,
431
+ ): Promise<CreateUserResponse> {
414
432
  throw new Error("Not implemented");
415
433
  }
416
434
 
417
- public handleUpdateUserRequest(request: IUpdateUserRequest): Promise<UpdateUserResponse> {
435
+ public handleUpdateUserRequest(
436
+ request: IUpdateUserRequest,
437
+ ): Promise<UpdateUserResponse> {
418
438
  throw new Error("Not implemented");
419
439
  }
420
440
 
421
- public handleListUserRequest(request: IListUserRequest): Promise<ListUserResponse> {
441
+ public handleListUserRequest(
442
+ request: IListUserRequest,
443
+ ): Promise<ListUserResponse> {
422
444
  throw new Error("Not implemented");
423
445
  }
424
446
  }
@@ -458,7 +480,7 @@ serve(
458
480
  },
459
481
  () => {
460
482
  console.log("Server is running on http://localhost:3000");
461
- }
483
+ },
462
484
  );
463
485
  ```
464
486
 
@@ -471,12 +493,18 @@ tsx api/server.ts
471
493
 
472
494
  ```typescript
473
495
  // api/client-test.ts
474
- import { UserClient, GetUserRequestCommand, UserNotFoundErrorResponse } from "./generated";
496
+ import {
497
+ UserClient,
498
+ GetUserRequestCommand,
499
+ UserNotFoundErrorResponse,
500
+ } from "./generated";
475
501
 
476
502
  const client = new UserClient({ baseUrl: "http://localhost:3000" });
477
503
 
478
504
  try {
479
- const getUserRequestCommand = new GetUserRequestCommand({ param: { userId: "123" } });
505
+ const getUserRequestCommand = new GetUserRequestCommand({
506
+ param: { userId: "123" },
507
+ });
480
508
  const result = await client.send(getUserRequestCommand);
481
509
 
482
510
  console.log("Successfully fetched user:", result.body);