Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
MellKam committed Aug 28, 2023
1 parent b9b9091 commit 7651c88
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"deno.unstable": true,
"editor.defaultFormatter": "denoland.vscode-deno",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
2 changes: 1 addition & 1 deletion benchmarks/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,6 @@ Deno.bench("yumi-fetch (v1)", async () => {
userId: 2,
},
method: "POST",
parseAs: "json"
parseAs: "json",
});
});
22 changes: 21 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions examples/deno-basic/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createClient, FetchError, ExtractParams } from "../../src/mod.ts";
import { createClient, FetchError, ExtractParams, FetcherOptions } from "../../src/mod.ts";
import { z, ZodError } from "npm:zod";

const client = createClient({
Expand All @@ -12,6 +12,17 @@ const todoSchema = z.object({
userId: z.number(),
});

const getTodo = async (options: FetcherOptions<{
path: "/todos/{id}",
}>) => {
const data = await client.fetch("/todos/{id}", {
...options,
parseAs: "json",
});

return todoSchema.parse(data);
};

const todosSchema = z.object({
todos: z.array(todoSchema),
total: z.number(),
Expand All @@ -37,17 +48,8 @@ try {
}
}

const getTodo = async (options: ExtractParams<"/todos/{id}">) => {
const data = await client.fetch("/todos/{id}", {
params: options,
parseAs: "json",
});

return todoSchema.parse(data);
}

try {
const todo = await getTodo({ id: 2 });
const todo = await getTodo({ params: { id: 8 } });
console.log(todo);
} catch (error) {
if (error instanceof FetchError) {
Expand All @@ -57,4 +59,4 @@ try {
} else {
console.error("Some tricky error:", error);
}
}
}
119 changes: 54 additions & 65 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,55 @@
{
"name": "yumi-fetch",
"version": "0.3.0",
"description": "🍭 An extensible fetch wrapper for simplified and powerful HTTP requests using native web APIs",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/mod.d.ts",
"type": "module",
"files": [
"dist/",
"src/",
"package.json",
"README.md",
"LICENSE"
],
"author": {
"name": "Artem Melnyk",
"url": "https://github.com/MellKam"
},
"sideEffects": false,
"exports": {
".": {
"default": "./dist/mod.js",
"import": "./dist/mod.js",
"require": "./dist/mod.cjs",
"types": "./dist/mod.d.ts"
},
"./plugins": {
"default": "./dist/plugins.js",
"import": "./dist/plugins.js",
"require": "./dist/plugins.cjs",
"types": "./dist/plugins/mod.d.ts"
}
},
"typesVersions": {
"*": {
"index": [
"./dist/mod.d.ts"
],
"plugins": [
"./dist/plugins/mod.d.ts"
]
}
},
"license": "MIT",
"repository": "github:MellKam/yumi-fetch",
"readme": "https://github.com/MellKam/yumi-fetch#readme",
"homepage": "https://github.com/MellKam/yumi-fetch#readme",
"bugs": {
"url": "https://github.com/MellKam/yumi-fetch/issues"
},
"keywords": [
"fetch",
"client",
"request",
"response",
"yumi",
"api",
"rest",
"http",
"network",
"middleware",
"extensible",
"plugin"
]
}
"name": "yumi-fetch",
"version": "0.3.0",
"description": "🍭 An extensible fetch wrapper for simplified and powerful HTTP requests using native web APIs",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/mod.d.ts",
"type": "module",
"files": [
"dist/",
"package.json",
"README.md",
"LICENSE"
],
"author": {
"name": "Artem Melnyk",
"url": "https://github.com/MellKam"
},
"sideEffects": false,
"exports": {
".": {
"default": "./dist/mod.js",
"import": "./dist/mod.js",
"require": "./dist/mod.cjs",
"types": "./dist/mod.d.ts"
}
},
"typesVersions": {
"*": {
"index": [
"./dist/mod.d.ts"
]
}
},
"license": "MIT",
"repository": "github:MellKam/yumi-fetch",
"readme": "https://github.com/MellKam/yumi-fetch#readme",
"homepage": "https://github.com/MellKam/yumi-fetch#readme",
"bugs": {
"url": "https://github.com/MellKam/yumi-fetch/issues"
},
"keywords": [
"fetch",
"client",
"request",
"response",
"yumi",
"api",
"rest",
"http",
"network",
"middleware",
"plugin"
]
}
Loading

0 comments on commit 7651c88

Please sign in to comment.