vite-plugin-server-actions 1.0.1 → 1.2.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 +162 -52
- package/index.d.ts +76 -32
- package/package.json +23 -14
- package/src/ast-parser.js +535 -0
- package/src/build-utils.js +10 -12
- package/src/dev-validator.js +272 -0
- package/src/error-enhancer.js +283 -0
- package/src/index.js +428 -80
- package/src/openapi.js +67 -29
- package/src/security.js +118 -0
- package/src/type-generator.js +378 -0
- package/src/types.ts +1 -1
- package/src/validation-runtime.js +100 -0
- package/src/validation.js +126 -21
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vite Server Actions
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/vite-plugin-server-actions)
|
|
4
4
|
[](https://www.npmjs.com/package/vite-plugin-server-actions)
|
|
@@ -20,26 +20,33 @@ import { getUsers } from "./server/db.server.js";
|
|
|
20
20
|
const users = await getUsers(); // Just call it!
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Why Vite Server Actions?
|
|
24
24
|
|
|
25
25
|
- **Zero API Boilerplate** - No need to define routes, handle HTTP methods, or parse request bodies
|
|
26
|
-
- **
|
|
26
|
+
- **TypeScript Support** - Full TypeScript support with automatic type generation
|
|
27
27
|
- **Built-in Validation** - Automatic request validation using Zod schemas
|
|
28
|
-
- **Auto Documentation** - OpenAPI
|
|
29
|
-
- **Production Ready** - Builds to
|
|
30
|
-
- **Developer Experience** -
|
|
28
|
+
- **Auto Documentation** - OpenAPI 3.0 specs and Swagger UI generated automatically
|
|
29
|
+
- **Production Ready** - Builds to optimized Node.js Express server
|
|
30
|
+
- **Developer Experience** - Clear error messages, hot reload, and development-time validation
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## Core Features
|
|
33
33
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
34
|
+
- **Seamless Imports** - Import server functions like any other module
|
|
35
|
+
- **Secure by Default** - Server code never exposed to client, path traversal protection
|
|
36
|
+
- **TypeScript** - Full support with cross-file imports, automatic compilation via Vite's SSR module system
|
|
37
|
+
- **Validation** - Zod schemas with type inference and OpenAPI generation
|
|
38
|
+
- **Documentation** - OpenAPI 3.0 specs with Swagger UI
|
|
39
|
+
- **Middleware Support** - Authentication, logging, CORS, and custom middleware
|
|
40
|
+
- **Flexible Routing** - Multiple routing strategies with hierarchical paths
|
|
41
|
+
- **Developer Experience** - Helpful error messages and development warnings
|
|
42
|
+
- **Production Optimized** - Efficient Express server builds
|
|
41
43
|
|
|
42
|
-
##
|
|
44
|
+
## Requirements
|
|
45
|
+
|
|
46
|
+
- Node.js 18+ (Node 16 reached EOL)
|
|
47
|
+
- Vite 4, 5, 6, or 7
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
43
50
|
|
|
44
51
|
### 1. Install
|
|
45
52
|
|
|
@@ -63,7 +70,7 @@ export default defineConfig({
|
|
|
63
70
|
|
|
64
71
|
### 3. Create a Server Function
|
|
65
72
|
|
|
66
|
-
Any file ending with `.server.js` becomes a server module:
|
|
73
|
+
Any file ending with `.server.js` or `.server.ts` becomes a server module:
|
|
67
74
|
|
|
68
75
|
```javascript
|
|
69
76
|
// actions/todos.server.js
|
|
@@ -108,12 +115,12 @@ function TodoApp({ userId }) {
|
|
|
108
115
|
|
|
109
116
|
That's it! The plugin automatically:
|
|
110
117
|
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
118
|
+
- Creates API endpoints for each function
|
|
119
|
+
- Handles serialization/deserialization
|
|
120
|
+
- Provides TypeScript support
|
|
121
|
+
- Works in development and production
|
|
115
122
|
|
|
116
|
-
##
|
|
123
|
+
## Real-World Examples
|
|
117
124
|
|
|
118
125
|
### Database Operations
|
|
119
126
|
|
|
@@ -199,7 +206,7 @@ login.schema = LoginSchema;
|
|
|
199
206
|
- [Todo App with React](examples/react-todo-app) - Same todo app built with React
|
|
200
207
|
- More examples coming soon for other frameworks
|
|
201
208
|
|
|
202
|
-
##
|
|
209
|
+
## How It Works
|
|
203
210
|
|
|
204
211
|
When you import a `.server.js` file in your client code, Vite Server Actions:
|
|
205
212
|
|
|
@@ -225,7 +232,7 @@ const user = await fetch("/api/user/getUser", {
|
|
|
225
232
|
- **Development**: Server functions run as Express middleware in Vite's dev server
|
|
226
233
|
- **Production**: Builds to a standalone Express server with all your functions
|
|
227
234
|
|
|
228
|
-
##
|
|
235
|
+
## Configuration
|
|
229
236
|
|
|
230
237
|
### Common Use Cases
|
|
231
238
|
|
|
@@ -280,29 +287,33 @@ serverActions({
|
|
|
280
287
|
|
|
281
288
|
### All Configuration Options
|
|
282
289
|
|
|
283
|
-
| Option | Type | Default
|
|
284
|
-
| ---------------- | ------------ |
|
|
285
|
-
| `apiPrefix` | `string` | `"/api"`
|
|
286
|
-
| `include` | `string[]` | `["**/*.server.js"]` | Files to process |
|
|
287
|
-
| `exclude` | `string[]` | `[]`
|
|
288
|
-
| `middleware` | `Function[]` | `[]`
|
|
289
|
-
| `routeTransform` | `Function` | See below
|
|
290
|
-
| `validation` | `Object` | `{ enabled: false }`
|
|
291
|
-
| `openAPI` | `Object` | `{ enabled: false }`
|
|
290
|
+
| Option | Type | Default | Description |
|
|
291
|
+
| ---------------- | ------------ | -------------------------------------- | ------------------------------ |
|
|
292
|
+
| `apiPrefix` | `string` | `"/api"` | URL prefix for all endpoints |
|
|
293
|
+
| `include` | `string[]` | `["**/*.server.js", "**/*.server.ts"]` | Files to process |
|
|
294
|
+
| `exclude` | `string[]` | `[]` | Files to ignore |
|
|
295
|
+
| `middleware` | `Function[]` | `[]` | Express middleware stack |
|
|
296
|
+
| `routeTransform` | `Function` | See below | Customize URL generation |
|
|
297
|
+
| `validation` | `Object` | `{ enabled: false }` | Validation settings |
|
|
298
|
+
| `openAPI` | `Object` | `{ enabled: false }` | OpenAPI documentation settings |
|
|
292
299
|
|
|
293
300
|
#### Route Transform Options
|
|
294
301
|
|
|
302
|
+
The plugin uses clean hierarchical paths by default (e.g., `actions/todo/create` instead of `src_actions_todo/create`).
|
|
303
|
+
|
|
295
304
|
```javascript
|
|
296
305
|
import { pathUtils } from "vite-plugin-server-actions";
|
|
297
306
|
|
|
298
307
|
// Available presets:
|
|
299
|
-
pathUtils.createCleanRoute; // (default) auth.server.js → /api/auth/login
|
|
300
|
-
pathUtils.createLegacyRoute; // auth.server.js → /api/
|
|
301
|
-
pathUtils.createMinimalRoute; // auth.server.js → /api/auth.server/login
|
|
308
|
+
pathUtils.createCleanRoute; // (default) src/actions/auth.server.js → /api/actions/auth/login
|
|
309
|
+
pathUtils.createLegacyRoute; // src/actions/auth.server.js → /api/src_actions_auth/login
|
|
310
|
+
pathUtils.createMinimalRoute; // actions/auth.server.js → /api/actions/auth.server/login
|
|
302
311
|
```
|
|
303
312
|
|
|
304
313
|
#### Validation Options
|
|
305
314
|
|
|
315
|
+
Validation is disabled by default. Enable it explicitly in your configuration.
|
|
316
|
+
|
|
306
317
|
| Option | Type | Default | Description |
|
|
307
318
|
| --------- | --------- | ------- | ------------------------------------- |
|
|
308
319
|
| `enabled` | `boolean` | `false` | Enable request validation |
|
|
@@ -532,7 +543,7 @@ export async function sendEmail(to, subject, body) {
|
|
|
532
543
|
|
|
533
544
|
### Server Code Isolation
|
|
534
545
|
|
|
535
|
-
- Server files (`.server.js`) are never bundled into client code
|
|
546
|
+
- Server files (`.server.js` and `.server.ts`) are never bundled into client code
|
|
536
547
|
- Development builds include safety checks to prevent accidental imports
|
|
537
548
|
- Production builds completely separate server and client code
|
|
538
549
|
|
|
@@ -564,39 +575,138 @@ export async function readAllowedFile(filename) {
|
|
|
564
575
|
readAllowedFile.schema = FileSchema;
|
|
565
576
|
```
|
|
566
577
|
|
|
567
|
-
##
|
|
578
|
+
## TypeScript Support
|
|
579
|
+
|
|
580
|
+
Vite Server Actions provides TypeScript support with automatic type generation:
|
|
568
581
|
|
|
569
|
-
|
|
582
|
+
### TypeScript Features
|
|
583
|
+
|
|
584
|
+
- **Automatic Type Generation** - `.d.ts` files generated for all server actions
|
|
585
|
+
- **Real-time Compilation** - TypeScript files compiled on-the-fly in development
|
|
586
|
+
- **Helpful Error Messages** - Development-time suggestions for TypeScript usage
|
|
587
|
+
- **Production Build Support** - Full TypeScript compilation in build process
|
|
570
588
|
|
|
571
589
|
```typescript
|
|
572
590
|
// server/users.server.ts
|
|
573
|
-
export
|
|
591
|
+
export interface User {
|
|
592
|
+
id: number;
|
|
593
|
+
name: string;
|
|
594
|
+
email: string;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Get user by ID with full type safety
|
|
599
|
+
* @param id - The user ID to fetch
|
|
600
|
+
* @returns Promise containing user data or null
|
|
601
|
+
*/
|
|
602
|
+
export async function getUser(id: number): Promise<User | null> {
|
|
574
603
|
return await db.users.findUnique({ where: { id } });
|
|
575
604
|
}
|
|
576
605
|
|
|
577
|
-
//
|
|
578
|
-
import { getUser } from "./server/users.server";
|
|
606
|
+
// Client.tsx - Automatic type inference and IntelliSense!
|
|
607
|
+
import { getUser, type User } from "./server/users.server";
|
|
579
608
|
|
|
580
609
|
const user = await getUser(123); // Type: User | null
|
|
581
610
|
```
|
|
582
611
|
|
|
583
|
-
###
|
|
612
|
+
### Validation with Type Safety
|
|
584
613
|
|
|
585
614
|
```typescript
|
|
586
615
|
import { z } from "zod";
|
|
587
616
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
617
|
+
// Define your schemas with TypeScript interfaces
|
|
618
|
+
export interface CreateUserInput {
|
|
619
|
+
name: string;
|
|
620
|
+
email: string;
|
|
621
|
+
age?: number;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const CreateUserSchema = z.object({
|
|
625
|
+
name: z.string().min(1, "Name is required"),
|
|
626
|
+
email: z.string().email("Invalid email format"),
|
|
627
|
+
age: z.number().optional(),
|
|
591
628
|
});
|
|
592
629
|
|
|
593
|
-
export async function createUser(data:
|
|
594
|
-
|
|
630
|
+
export async function createUser(data: CreateUserInput): Promise<User> {
|
|
631
|
+
const validated = CreateUserSchema.parse(data);
|
|
632
|
+
return await db.users.create({ data: validated });
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// Attach schema for automatic validation and OpenAPI generation
|
|
636
|
+
createUser.schema = z.tuple([CreateUserSchema]);
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
### Documentation Generation
|
|
640
|
+
|
|
641
|
+
TypeScript types and JSDoc comments automatically generate API documentation:
|
|
642
|
+
|
|
643
|
+
```typescript
|
|
644
|
+
/**
|
|
645
|
+
* Upload a file with validation and type safety
|
|
646
|
+
* @param fileData - File upload data with filename, content, and metadata
|
|
647
|
+
* @returns Promise containing upload result with file path and metadata
|
|
648
|
+
*/
|
|
649
|
+
export async function uploadFile(fileData: {
|
|
650
|
+
filename: string;
|
|
651
|
+
content: string;
|
|
652
|
+
mimetype: string;
|
|
653
|
+
}): Promise<FileUploadResult> {
|
|
654
|
+
// Implementation...
|
|
595
655
|
}
|
|
596
|
-
createUser.schema = schema;
|
|
597
656
|
```
|
|
598
657
|
|
|
599
|
-
|
|
658
|
+
This automatically generates:
|
|
659
|
+
|
|
660
|
+
- **OpenAPI 3.0 specs** with TypeScript types
|
|
661
|
+
- **Swagger UI documentation** with interactive examples
|
|
662
|
+
- **Type definitions** (`.d.ts`) for client-side imports
|
|
663
|
+
|
|
664
|
+
## Developer Experience
|
|
665
|
+
|
|
666
|
+
Vite Server Actions provides development feedback and suggestions to improve code quality:
|
|
667
|
+
|
|
668
|
+
### Code Analysis
|
|
669
|
+
|
|
670
|
+
The plugin uses AST-based parsing to analyze your server functions and provide helpful feedback:
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
// The plugin analyzes your code and provides suggestions:
|
|
674
|
+
|
|
675
|
+
// ⚠️ Warning: Function should be async
|
|
676
|
+
export function syncFunction() {
|
|
677
|
+
return "data";
|
|
678
|
+
}
|
|
679
|
+
// 💡 Suggestion: Change to: export async function syncFunction()
|
|
680
|
+
|
|
681
|
+
// ⚠️ Warning: Missing return type annotation
|
|
682
|
+
export async function getUser(id) {
|
|
683
|
+
return await db.user.findUnique({ where: { id } });
|
|
684
|
+
}
|
|
685
|
+
// 💡 Suggestion: Add return type like: Promise<User | null>
|
|
686
|
+
|
|
687
|
+
// ⚠️ Warning: Missing validation schema
|
|
688
|
+
export async function updateUser(id, data) {
|
|
689
|
+
return await db.user.update({ where: { id }, data });
|
|
690
|
+
}
|
|
691
|
+
// Suggestion: Add schema: updateUser.schema = z.tuple([...])
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
### Development Warnings & Suggestions
|
|
695
|
+
|
|
696
|
+
- **Type Safety Hints** - Suggestions for adding TypeScript types and return annotations
|
|
697
|
+
- **Schema Validation** - Recommendations for adding Zod schemas to improve API reliability
|
|
698
|
+
- **Function Structure** - Best practices for async functions and proper exports
|
|
699
|
+
- **Security Warnings** - Path traversal detection and secure coding suggestions
|
|
700
|
+
- **Performance Tips** - Optimization suggestions for production builds
|
|
701
|
+
|
|
702
|
+
### Test Coverage
|
|
703
|
+
|
|
704
|
+
- **Test Coverage** - Unit and e2e test suites
|
|
705
|
+
- **Framework Support** - Tested with Svelte, Vue, React, and TypeScript React
|
|
706
|
+
- **Production Testing** - Feature parity between development and production modes
|
|
707
|
+
- **Cross-platform** - Works across different operating systems
|
|
708
|
+
|
|
709
|
+
## Error Handling
|
|
600
710
|
|
|
601
711
|
Server errors are automatically caught and returned with proper HTTP status codes:
|
|
602
712
|
|
|
@@ -624,7 +734,7 @@ export async function authenticate(token) {
|
|
|
624
734
|
}
|
|
625
735
|
```
|
|
626
736
|
|
|
627
|
-
##
|
|
737
|
+
## Common Patterns
|
|
628
738
|
|
|
629
739
|
### Authenticated Actions
|
|
630
740
|
|
|
@@ -668,13 +778,13 @@ export async function getExpensiveData(key) {
|
|
|
668
778
|
}
|
|
669
779
|
```
|
|
670
780
|
|
|
671
|
-
##
|
|
781
|
+
## Contributing
|
|
672
782
|
|
|
673
783
|
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
674
784
|
|
|
675
785
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
|
|
676
786
|
|
|
677
|
-
##
|
|
787
|
+
## License
|
|
678
788
|
|
|
679
789
|
This project is [MIT](LICENSE) licensed.
|
|
680
790
|
|
package/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface ValidationOptions {
|
|
|
8
8
|
* @default false
|
|
9
9
|
*/
|
|
10
10
|
enabled?: boolean;
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
/**
|
|
13
13
|
* Validation adapter to use
|
|
14
14
|
* @default "zod"
|
|
@@ -22,7 +22,7 @@ export interface OpenAPIOptions {
|
|
|
22
22
|
* @default false
|
|
23
23
|
*/
|
|
24
24
|
enabled?: boolean;
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
/**
|
|
27
27
|
* OpenAPI specification info
|
|
28
28
|
*/
|
|
@@ -31,19 +31,19 @@ export interface OpenAPIOptions {
|
|
|
31
31
|
version?: string;
|
|
32
32
|
description?: string;
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
/**
|
|
36
36
|
* Path to serve the Swagger UI documentation
|
|
37
37
|
* @default "/api/docs"
|
|
38
38
|
*/
|
|
39
39
|
docsPath?: string;
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
/**
|
|
42
42
|
* Path to serve the OpenAPI JSON specification
|
|
43
43
|
* @default "/api/openapi.json"
|
|
44
44
|
*/
|
|
45
45
|
specPath?: string;
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
/**
|
|
48
48
|
* Enable Swagger UI
|
|
49
49
|
* @default true when OpenAPI is enabled
|
|
@@ -57,46 +57,46 @@ export interface ServerActionOptions {
|
|
|
57
57
|
* @default "/api"
|
|
58
58
|
*/
|
|
59
59
|
apiPrefix?: string;
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
/**
|
|
62
62
|
* Include patterns for server action files
|
|
63
|
-
* @default ["**\/*.server.js"]
|
|
63
|
+
* @default ["**\/*.server.js", "**\/*.server.ts"]
|
|
64
64
|
*/
|
|
65
65
|
include?: string | string[];
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
/**
|
|
68
68
|
* Exclude patterns for server action files
|
|
69
69
|
* @default []
|
|
70
70
|
*/
|
|
71
71
|
exclude?: string | string[];
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
/**
|
|
74
74
|
* Middleware to run before server action handlers
|
|
75
75
|
* Can be a single middleware or array of middleware
|
|
76
76
|
*/
|
|
77
77
|
middleware?: RequestHandler | RequestHandler[];
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
/**
|
|
80
80
|
* Transform function for module names (internal use)
|
|
81
81
|
* @param filePath - The file path relative to project root
|
|
82
82
|
* @returns The module name to use internally
|
|
83
83
|
*/
|
|
84
84
|
moduleNameTransform?: (filePath: string) => string;
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
/**
|
|
87
87
|
* Transform function for API routes
|
|
88
88
|
* @param filePath - The file path relative to project root
|
|
89
89
|
* @param functionName - The exported function name
|
|
90
90
|
* @returns The API route path (without prefix)
|
|
91
|
-
* @default Clean hierarchical paths (removes src/ and .server.js)
|
|
91
|
+
* @default Clean hierarchical paths (removes src/ and .server.js or .server.ts)
|
|
92
92
|
*/
|
|
93
93
|
routeTransform?: (filePath: string, functionName: string) => string;
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
/**
|
|
96
96
|
* Validation configuration
|
|
97
97
|
*/
|
|
98
98
|
validation?: ValidationOptions;
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
/**
|
|
101
101
|
* OpenAPI documentation configuration
|
|
102
102
|
*/
|
|
@@ -135,7 +135,7 @@ export declare const pathUtils: {
|
|
|
135
135
|
* @returns Clean route path
|
|
136
136
|
*/
|
|
137
137
|
createCleanRoute: (filePath: string, functionName: string) => string;
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
/**
|
|
140
140
|
* Creates legacy underscore-separated routes: "src_actions_todo/create"
|
|
141
141
|
* @param filePath - The file path relative to project root
|
|
@@ -143,7 +143,7 @@ export declare const pathUtils: {
|
|
|
143
143
|
* @returns Legacy route path
|
|
144
144
|
*/
|
|
145
145
|
createLegacyRoute: (filePath: string, functionName: string) => string;
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
/**
|
|
148
148
|
* Creates minimal routes: "actions/todo.server/create"
|
|
149
149
|
* @param filePath - The file path relative to project root
|
|
@@ -151,7 +151,7 @@ export declare const pathUtils: {
|
|
|
151
151
|
* @returns Minimal route path
|
|
152
152
|
*/
|
|
153
153
|
createMinimalRoute: (filePath: string, functionName: string) => string;
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
/**
|
|
156
156
|
* Creates module names for internal use
|
|
157
157
|
* @param filePath - The file path relative to project root
|
|
@@ -162,39 +162,83 @@ export declare const pathUtils: {
|
|
|
162
162
|
|
|
163
163
|
// Validation exports
|
|
164
164
|
export interface ValidationAdapter {
|
|
165
|
-
validate(
|
|
166
|
-
|
|
165
|
+
validate(
|
|
166
|
+
schema: any,
|
|
167
|
+
data: any,
|
|
168
|
+
): Promise<{
|
|
169
|
+
success: boolean;
|
|
170
|
+
data?: any;
|
|
171
|
+
errors?: Array<{ path: string; message: string; code: string; value?: any }>;
|
|
172
|
+
}>;
|
|
173
|
+
toOpenAPISchema(schema: any): any;
|
|
174
|
+
getParameters(schema: any): any[];
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
export declare class ZodAdapter implements ValidationAdapter {
|
|
170
|
-
validate(
|
|
171
|
-
|
|
178
|
+
validate(
|
|
179
|
+
schema: z.ZodSchema<any>,
|
|
180
|
+
data: any,
|
|
181
|
+
): Promise<{
|
|
182
|
+
success: boolean;
|
|
183
|
+
data?: any;
|
|
184
|
+
errors?: Array<{ path: string; message: string; code: string; value?: any }>;
|
|
185
|
+
}>;
|
|
186
|
+
toOpenAPISchema(schema: z.ZodSchema<any>): any;
|
|
187
|
+
getParameters(schema: z.ZodSchema<any>): any[];
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
export declare class SchemaDiscovery {
|
|
175
|
-
constructor();
|
|
191
|
+
constructor(adapter?: ValidationAdapter);
|
|
176
192
|
registerSchema(moduleName: string, functionName: string, schema: any): void;
|
|
177
193
|
getSchema(moduleName: string, functionName: string): any;
|
|
194
|
+
hasSchema(moduleName: string, functionName: string): boolean;
|
|
178
195
|
getAllSchemas(): Map<string, any>;
|
|
179
196
|
discoverFromModule(module: any, moduleName: string): void;
|
|
197
|
+
clear(): void;
|
|
180
198
|
}
|
|
181
199
|
|
|
182
200
|
export declare const adapters: {
|
|
183
|
-
zod: ZodAdapter;
|
|
201
|
+
zod: typeof ZodAdapter;
|
|
184
202
|
};
|
|
185
203
|
|
|
186
|
-
export declare
|
|
187
|
-
|
|
204
|
+
export declare const defaultAdapter: ZodAdapter;
|
|
205
|
+
export declare const defaultSchemaDiscovery: SchemaDiscovery;
|
|
206
|
+
|
|
207
|
+
export declare function createValidationMiddleware(options?: {
|
|
208
|
+
adapter?: ValidationAdapter | "zod";
|
|
209
|
+
schemaDiscovery?: SchemaDiscovery;
|
|
188
210
|
}): RequestHandler;
|
|
189
211
|
|
|
190
212
|
// OpenAPI exports
|
|
191
213
|
export declare class OpenAPIGenerator {
|
|
192
|
-
constructor(options?: {
|
|
193
|
-
|
|
214
|
+
constructor(options?: {
|
|
215
|
+
info?: { title?: string; version?: string; description?: string };
|
|
216
|
+
adapter?: ValidationAdapter;
|
|
217
|
+
servers?: Array<{ url: string; description?: string }>;
|
|
218
|
+
});
|
|
219
|
+
generateSpec(
|
|
220
|
+
serverFunctions: Map<string, any>,
|
|
221
|
+
schemaDiscovery: SchemaDiscovery,
|
|
222
|
+
options?: {
|
|
223
|
+
apiPrefix?: string;
|
|
224
|
+
routeTransform?: (filePath: string, functionName: string) => string;
|
|
225
|
+
port?: number | string;
|
|
226
|
+
},
|
|
227
|
+
): any;
|
|
194
228
|
}
|
|
195
229
|
|
|
196
|
-
export declare function setupOpenAPIEndpoints(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
230
|
+
export declare function setupOpenAPIEndpoints(
|
|
231
|
+
app: any,
|
|
232
|
+
openAPISpec: any,
|
|
233
|
+
options?: {
|
|
234
|
+
docsPath?: string;
|
|
235
|
+
specPath?: string;
|
|
236
|
+
enableSwaggerUI?: boolean;
|
|
237
|
+
port?: number;
|
|
238
|
+
swaggerOptions?: any;
|
|
239
|
+
},
|
|
240
|
+
): void;
|
|
241
|
+
|
|
242
|
+
export declare function createSwaggerMiddleware(spec: any, options?: { swaggerOptions?: any }): RequestHandler[];
|
|
243
|
+
|
|
244
|
+
export default serverActions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-server-actions",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Server actions for Vite - call backend functions directly from your frontend with automatic API generation, TypeScript support, and zero configuration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"middleware",
|
|
22
22
|
"express"
|
|
23
23
|
],
|
|
24
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://serveractions.dev",
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/HelgeSverre/vite-plugin-server-actions/issues"
|
|
27
27
|
},
|
|
@@ -36,43 +36,48 @@
|
|
|
36
36
|
"url": "https://helgesver.re"
|
|
37
37
|
},
|
|
38
38
|
"type": "module",
|
|
39
|
-
"main": "src/index.js",
|
|
40
|
-
"types": "index.d.ts",
|
|
41
39
|
"exports": {
|
|
42
40
|
".": {
|
|
43
41
|
"import": "./src/index.js",
|
|
44
42
|
"types": "./index.d.ts"
|
|
45
43
|
}
|
|
46
44
|
},
|
|
45
|
+
"main": "src/index.js",
|
|
46
|
+
"types": "index.d.ts",
|
|
47
47
|
"files": [
|
|
48
48
|
"src",
|
|
49
49
|
"index.d.ts",
|
|
50
50
|
"README.md",
|
|
51
51
|
"LICENSE"
|
|
52
52
|
],
|
|
53
|
-
"engines": {
|
|
54
|
-
"node": ">=16.0.0"
|
|
55
|
-
},
|
|
56
53
|
"scripts": {
|
|
54
|
+
"check": "npm run test:run && npm run typecheck",
|
|
55
|
+
"deploy:docs": "cd docs && vc --prod",
|
|
56
|
+
"example:react-ts:build": "npm run build --prefix examples/react-todo-app-typescript",
|
|
57
|
+
"example:react-ts:dev": "npm run dev --prefix examples/react-todo-app-typescript",
|
|
58
|
+
"example:react:build": "npm run build --prefix examples/react-todo-app",
|
|
59
|
+
"example:react:dev": "npm run dev --prefix examples/react-todo-app",
|
|
57
60
|
"example:svelte:build": "npm run build --prefix examples/svelte-todo-app",
|
|
58
61
|
"example:svelte:dev": "npm run dev --prefix examples/svelte-todo-app",
|
|
59
62
|
"example:vue:build": "npm run build --prefix examples/vue-todo-app",
|
|
60
63
|
"example:vue:dev": "npm run dev --prefix examples/vue-todo-app",
|
|
61
|
-
"example:react:build": "npm run build --prefix examples/react-todo-app",
|
|
62
|
-
"example:react:dev": "npm run dev --prefix examples/react-todo-app",
|
|
63
64
|
"format": "npx prettier --write .",
|
|
65
|
+
"prepublishOnly": "npm run check",
|
|
66
|
+
"reset:todos": "node scripts/reset-todos.js",
|
|
64
67
|
"sort": "npx sort-package-json",
|
|
65
68
|
"test": "vitest",
|
|
66
|
-
"test:run": "vitest run",
|
|
67
69
|
"test:e2e": "playwright test",
|
|
70
|
+
"test:e2e:clean": "npm run reset:todos && npm run test:e2e",
|
|
71
|
+
"test:e2e:headed": "playwright test --headed",
|
|
68
72
|
"test:e2e:ui": "playwright test --ui",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"prepublishOnly": "npm run check",
|
|
72
|
-
"deploy:docs": "cd docs && vc --prod"
|
|
73
|
+
"test:run": "vitest run",
|
|
74
|
+
"typecheck": "tsc --noEmit"
|
|
73
75
|
},
|
|
74
76
|
"dependencies": {
|
|
75
77
|
"@asteasolutions/zod-to-openapi": "^7.3.4",
|
|
78
|
+
"@babel/parser": "^7.27.7",
|
|
79
|
+
"@babel/traverse": "^7.27.7",
|
|
80
|
+
"esbuild": "^0.19.0",
|
|
76
81
|
"express": "^4.21.0",
|
|
77
82
|
"minimatch": "^10.0.3",
|
|
78
83
|
"rollup": "^4.0.0",
|
|
@@ -88,6 +93,7 @@
|
|
|
88
93
|
"@types/node": "^24.0.3",
|
|
89
94
|
"@types/swagger-ui-express": "^4.1.6",
|
|
90
95
|
"@vitest/runner": "^3.2.4",
|
|
96
|
+
"openapi-types": "^12.1.3",
|
|
91
97
|
"playwright": "^1.53.1",
|
|
92
98
|
"prettier": "^3.6.0",
|
|
93
99
|
"typescript": "^5.8.3",
|
|
@@ -97,5 +103,8 @@
|
|
|
97
103
|
"peerDependencies": {
|
|
98
104
|
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
99
105
|
},
|
|
106
|
+
"engines": {
|
|
107
|
+
"node": ">=18.0.0"
|
|
108
|
+
},
|
|
100
109
|
"readme": "README.md"
|
|
101
110
|
}
|