@donkeylabs/server 0.4.6 → 0.4.7

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.
@@ -88,27 +88,19 @@ import { createHandle } from "@donkeylabs/adapter-sveltekit/hooks";
88
88
  export const handle = createHandle();
89
89
  ```
90
90
 
91
- ### 4. Create the API Client
91
+ ### 4. Generate the API Client
92
92
 
93
- ```ts
94
- // src/lib/api.ts
95
- import { UnifiedApiClientBase } from "@donkeylabs/adapter-sveltekit/client";
96
-
97
- interface DataResponse {
98
- message: string;
99
- }
100
-
101
- export class ApiClient extends UnifiedApiClientBase {
102
- data = {
103
- get: () => this.request<{}, DataResponse>("api.data.get", {}),
104
- };
105
- }
93
+ Run the generator to create a fully-typed client:
106
94
 
107
- export function createApi(options?: { locals?: any }) {
108
- return new ApiClient(options);
109
- }
95
+ ```bash
96
+ bun run donkeylabs generate
110
97
  ```
111
98
 
99
+ This creates `src/lib/api.ts` with:
100
+ - Typed methods for all your routes
101
+ - `Routes` namespace with `Input` and `Output` types
102
+ - `createApi()` factory function
103
+
112
104
  ---
113
105
 
114
106
  ## Usage
@@ -322,36 +314,73 @@ Add path aliases in `tsconfig.json`:
322
314
 
323
315
  ---
324
316
 
325
- ## Common Patterns
317
+ ## Auto-Generated Client
326
318
 
327
- ### Typed API Client
319
+ When you run `donkeylabs generate`, it creates a fully-typed client at `src/lib/api.ts`.
328
320
 
329
- Create a fully typed client that mirrors your routes:
321
+ ### Generated Structure
330
322
 
331
323
  ```ts
332
- // src/lib/api.ts
333
- import { UnifiedApiClientBase } from "@donkeylabs/adapter-sveltekit/client";
334
-
335
- // Define response types
336
- interface User { id: string; name: string; }
337
- interface UsersResponse { users: User[]; }
324
+ // src/lib/api.ts (auto-generated)
325
+
326
+ // Route types - use these for forms, props, etc.
327
+ export namespace Routes {
328
+ export namespace Api {
329
+ export namespace Users {
330
+ export namespace List {
331
+ export type Input = {};
332
+ export type Output = { users: User[] };
333
+ }
334
+ export namespace Create {
335
+ export type Input = { name: string; email: string };
336
+ export type Output = { id: string; name: string; email: string };
337
+ }
338
+ }
339
+ }
340
+ }
338
341
 
342
+ // API Client with typed methods
339
343
  export class ApiClient extends UnifiedApiClientBase {
340
- users = {
341
- list: () =>
342
- this.request<{}, UsersResponse>("api.users.list", {}),
343
- get: (input: { id: string }) =>
344
- this.request<typeof input, User>("api.users.get", input),
345
- create: (input: { name: string }) =>
346
- this.request<typeof input, User>("api.users.create", input),
344
+ api = {
345
+ users: {
346
+ list: (input: Routes.Api.Users.List.Input): Promise<Routes.Api.Users.List.Output> => ...,
347
+ create: (input: Routes.Api.Users.Create.Input): Promise<Routes.Api.Users.Create.Output> => ...,
348
+ }
347
349
  };
348
350
  }
349
351
 
350
- export function createApi(options?: { locals?: any }) {
351
- return new ApiClient(options);
352
+ export function createApi(options?: ClientOptions) { ... }
353
+ ```
354
+
355
+ ### Using Route Types
356
+
357
+ Import types for forms, validation, or props:
358
+
359
+ ```ts
360
+ // In a Svelte component or server file
361
+ import { type Routes } from '$lib/api';
362
+
363
+ // Use route types
364
+ type CreateUserInput = Routes.Api.Users.Create.Input;
365
+ type CreateUserOutput = Routes.Api.Users.Create.Output;
366
+
367
+ // Example: typed form handler
368
+ function handleSubmit(data: CreateUserInput) {
369
+ api.api.users.create(data);
352
370
  }
353
371
  ```
354
372
 
373
+ ### When to Regenerate
374
+
375
+ Run `donkeylabs generate` after:
376
+ - Adding new routes
377
+ - Changing route input/output schemas
378
+ - Adding new plugins with routes
379
+
380
+ ---
381
+
382
+ ## Common Patterns
383
+
355
384
  ### Error Handling
356
385
 
357
386
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donkeylabs/server",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "type": "module",
5
5
  "description": "Type-safe plugin system for building RPC-style APIs with Bun",
6
6
  "main": "./src/index.ts",