vite-plugin-server-actions 0.1.1 → 1.0.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/LICENSE +21 -0
- package/README.md +606 -105
- package/index.d.ts +200 -0
- package/package.json +74 -11
- package/src/build-utils.js +101 -0
- package/src/index.js +531 -58
- package/src/middleware.js +89 -0
- package/src/openapi.js +369 -0
- package/src/types.ts +35 -0
- package/src/validation.js +307 -0
- package/.editorconfig +0 -20
- package/.nvmrc +0 -1
- package/.prettierrc +0 -7
- package/examples/todo-app/.prettierrc +0 -17
- package/examples/todo-app/README.md +0 -58
- package/examples/todo-app/index.html +0 -12
- package/examples/todo-app/jsconfig.json +0 -32
- package/examples/todo-app/package.json +0 -22
- package/examples/todo-app/src/App.svelte +0 -155
- package/examples/todo-app/src/actions/auth.server.js +0 -14
- package/examples/todo-app/src/actions/todo.server.js +0 -57
- package/examples/todo-app/src/app.css +0 -0
- package/examples/todo-app/src/main.js +0 -8
- package/examples/todo-app/svelte.config.js +0 -7
- package/examples/todo-app/todos.json +0 -27
- package/examples/todo-app/vite.config.js +0 -12
- package/examples/todo-app/yarn.lock +0 -658
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import fs from "fs/promises";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
const TODO_FILE = path.join(process.cwd(), "todos.json");
|
|
5
|
-
|
|
6
|
-
async function readTodos() {
|
|
7
|
-
try {
|
|
8
|
-
const data = await fs.readFile(TODO_FILE, "utf8");
|
|
9
|
-
return JSON.parse(data);
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.log(error);
|
|
12
|
-
if (error.code === "ENOENT") {
|
|
13
|
-
// File doesn't exist, return an empty array
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
console.error("Error reading todos:", error);
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function writeTodos(todos) {
|
|
22
|
-
try {
|
|
23
|
-
await fs.writeFile(TODO_FILE, JSON.stringify(todos, null, 2), "utf8");
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.error("Error writing todos:", error);
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function getTodos() {
|
|
31
|
-
return await readTodos();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function addTodo(todo) {
|
|
35
|
-
const todos = await readTodos();
|
|
36
|
-
const newTodo = { id: Date.now(), text: todo.text, completed: false };
|
|
37
|
-
todos.push(newTodo);
|
|
38
|
-
await writeTodos(todos);
|
|
39
|
-
return newTodo;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function updateTodo(id, updates) {
|
|
43
|
-
const todos = await readTodos();
|
|
44
|
-
const index = todos.findIndex((todo) => todo.id === id);
|
|
45
|
-
if (index !== -1) {
|
|
46
|
-
todos[index] = { ...todos[index], ...updates };
|
|
47
|
-
await writeTodos(todos);
|
|
48
|
-
return todos[index];
|
|
49
|
-
}
|
|
50
|
-
throw new Error("Todo not found");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function deleteTodo(id) {
|
|
54
|
-
const todos = await readTodos();
|
|
55
|
-
const newTodos = todos.filter((todo) => todo.id != id);
|
|
56
|
-
await writeTodos(newTodos);
|
|
57
|
-
}
|
|
File without changes
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"id": 1,
|
|
4
|
-
"text": "Finish writing documentation",
|
|
5
|
-
"completed": false
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
"id": 2,
|
|
9
|
-
"text": "Implement authentication logic",
|
|
10
|
-
"completed": true
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"id": 3,
|
|
14
|
-
"text": "Design user interface",
|
|
15
|
-
"completed": false
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"id": 4,
|
|
19
|
-
"text": "Test server actions",
|
|
20
|
-
"completed": true
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"id": 5,
|
|
24
|
-
"text": "Deploy application",
|
|
25
|
-
"completed": false
|
|
26
|
-
}
|
|
27
|
-
]
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vite";
|
|
2
|
-
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
3
|
-
import serverActions from "../../src/index.js";
|
|
4
|
-
|
|
5
|
-
// https://vitejs.dev/config/
|
|
6
|
-
export default defineConfig({
|
|
7
|
-
plugins: [
|
|
8
|
-
svelte(),
|
|
9
|
-
serverActions(),
|
|
10
|
-
// ...
|
|
11
|
-
],
|
|
12
|
-
});
|