@efanworks/tasks-api 1.0.1-alpha.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.
@@ -0,0 +1,2 @@
1
+ import type { Task } from "@efanworks/tasks-types";
2
+ export declare const addTask: (text: string) => Promise<Task>;
@@ -0,0 +1,15 @@
1
+ import { delayRequest, BASE_URL } from "./base";
2
+ // 添加任务
3
+ export const addTask = delayRequest(async (text) => {
4
+ const response = await fetch(`${BASE_URL}/addTask`, {
5
+ method: "POST",
6
+ headers: {
7
+ "Content-Type": "application/json",
8
+ },
9
+ body: JSON.stringify({ text }),
10
+ });
11
+ if (!response.ok) {
12
+ throw new Error("Failed to add task");
13
+ }
14
+ return response.json();
15
+ });
package/dist/base.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const BASE_URL = "http://localhost:3010";
2
+ export declare function delayRequest<Args extends unknown[], R>(request: (...args: Args) => Promise<R>): (...args: Args) => Promise<R>;
package/dist/base.js ADDED
@@ -0,0 +1,9 @@
1
+ export const BASE_URL = "http://localhost:3010";
2
+ export function delayRequest(request) {
3
+ return async function (...args) {
4
+ await new Promise((resolve) => {
5
+ setTimeout(resolve, 1500);
6
+ });
7
+ return request(...args);
8
+ };
9
+ }
@@ -0,0 +1,5 @@
1
+ import type { Task } from "@efanworks/tasks-types";
2
+ export declare const changeTask: (id: string, updates: {
3
+ text?: string;
4
+ done?: boolean;
5
+ }) => Promise<Task>;
@@ -0,0 +1,15 @@
1
+ import { delayRequest, BASE_URL } from "./base";
2
+ // 修改任务
3
+ export const changeTask = delayRequest(async (id, updates) => {
4
+ const response = await fetch(`${BASE_URL}/changeTask/${id}`, {
5
+ method: "PATCH",
6
+ headers: {
7
+ "Content-Type": "application/json",
8
+ },
9
+ body: JSON.stringify(updates),
10
+ });
11
+ if (!response.ok) {
12
+ throw new Error("Failed to change task");
13
+ }
14
+ return response.json();
15
+ });
@@ -0,0 +1 @@
1
+ export declare const deleteTask: (id: string) => Promise<void>;
@@ -0,0 +1,10 @@
1
+ import { delayRequest, BASE_URL } from "./base";
2
+ // 删除任务
3
+ export const deleteTask = delayRequest(async (id) => {
4
+ const response = await fetch(`${BASE_URL}/deleteTask/${id}`, {
5
+ method: "DELETE",
6
+ });
7
+ if (!response.ok) {
8
+ throw new Error("Failed to delete task");
9
+ }
10
+ });
@@ -0,0 +1,2 @@
1
+ import type { Task } from "@efanworks/tasks-types";
2
+ export declare const fetchTasks: () => Promise<Task[]>;
@@ -0,0 +1,9 @@
1
+ import { delayRequest, BASE_URL } from "./base";
2
+ // 获取所有任务
3
+ export const fetchTasks = delayRequest(async () => {
4
+ const response = await fetch(`${BASE_URL}/tasks`);
5
+ if (!response.ok) {
6
+ throw new Error("Failed to fetch tasks");
7
+ }
8
+ return response.json();
9
+ });
@@ -0,0 +1,4 @@
1
+ export { fetchTasks } from "./fetchTasks";
2
+ export { addTask } from "./addTask";
3
+ export { changeTask } from "./changeTask";
4
+ export { deleteTask } from "./deleteTask";
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { fetchTasks } from "./fetchTasks";
2
+ export { addTask } from "./addTask";
3
+ export { changeTask } from "./changeTask";
4
+ export { deleteTask } from "./deleteTask";
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@efanworks/tasks-api",
3
+ "version": "1.0.1-alpha.0",
4
+ "description": "Tasks API",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "npm run clean && tsc",
17
+ "clean": "rm -rf dist"
18
+ },
19
+ "devDependencies": {
20
+ "typescript": "^6.0.3"
21
+ },
22
+ "keywords": [],
23
+ "author": "",
24
+ "license": "ISC",
25
+ "publishConfig": {
26
+ "registry": "https://registry.npmjs.org/",
27
+ "access": "public"
28
+ }
29
+ }