Skip to content

Commit

Permalink
fix: dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian committed Nov 12, 2023
1 parent fe12893 commit 4386e82
Show file tree
Hide file tree
Showing 7 changed files with 3,903 additions and 5,632 deletions.
99 changes: 99 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<h1 align="center">http-wizard</h1>
<p align="center"><a href="https://git.io/typing-svg"><img src="https://readme-typing-svg.demolab.com?font=Fira+Code&size=18&duration=2000&pause=2000&center=true&width=540&height=80&lines=First+class+api+client+for+node+servers." alt="Typing SVG" /></a></p>

### Full documentation website:

[http-wizard.vercel.app](https://http-wizard.vercel.app)

## Introduction

Http-wizard weaves TypeScript magic, offering a type-safe API client and ensuring a delightful end-to-end developer experience. ✨

#### Here is an exemple of usage

https://github.com/flodlc/http-wizard/assets/3781663/71c749f0-3493-4865-8a9a-41421a371a05

### What it can do:

- 100% type-safe api client with typescript magic (no code generation)
- Fastify first-class support
- React-query first-class support
- Zod and Typebox Type providers
- Delightful end-to-end developer experience (tRPC-like)
- Http standards / REST compatibility: you are owner of your routes
- Type inference utils

---

Table of Contents:

- [Installation](#installation)
- [Usage](#usage)

---

## Installation

To get started, install http-wizard using npm or yarn:

```sh
npm install @http-wizard/core
# or
yarn add @http-wizard/core
```

## Usage

Currently http-wizard uses Zod or Typebox for validation.
Here is an exemple with Zod.

Let's first create a route on the server:

```typescript title="Route creation with Fastify and Zod"
// server.ts
import { createRoute } from "@http-wizard/core";
import { z } from "zod";

const User = z.object({
id: z.string(),
name: z.string(),
});

export const getUsers = (fastify: FastifyInstance) => {
return createRoute("/users", {
method: "GET",
schema: {
response: {
200: z.array(User),
},
},
}).handle((props) => {
fastify.route({
...props,
handler: (request) => {
const users = await db.getUsers();
return users;
},
});
});
};

const router = { ...getUsers() };
export type Router = typeof router;
```

Now, let's use the Router type on the client:

```typescript title="Client instanciation with axios"
// client.ts
import { createClient, ZodTypeProvider } from "@http-wizard/core";
import axios from "axios";

import type { Router } from "./server";

const apiClient = createClient<Router, ZodTypeProvider>(axios.instance());
const users = await apiClient.ref("[GET]/users").query({});
// users array is safe: { id:string, name:string }[]
```

Easy right ?
7 changes: 2 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"packageManager": "[email protected]",
"version": "1.3.12",
"version": "1.3.14",
"scripts": {
"dev": "tsup src/index.ts --watch",
"build": "tsup src/index.ts --dts",
Expand All @@ -29,10 +29,7 @@
"zod": "^3.22.4"
},
"peerDependencies": {
"@sinclair/typebox": "^0.29.0",
"@tanstack/react-query": "^5.8.1",
"axios": "^1.4.0",
"zod": "3.x"
"axios": "^1.4.0"
},
"files": [
"dist/*"
Expand Down
99 changes: 99 additions & 0 deletions packages/react-query/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<h1 align="center">http-wizard</h1>
<p align="center"><a href="https://git.io/typing-svg"><img src="https://readme-typing-svg.demolab.com?font=Fira+Code&size=18&duration=2000&pause=2000&center=true&width=540&height=80&lines=First+class+api+client+for+node+servers." alt="Typing SVG" /></a></p>

### Full documentation website:

[http-wizard.vercel.app](https://http-wizard.vercel.app)

## Introduction

Http-wizard weaves TypeScript magic, offering a type-safe API client and ensuring a delightful end-to-end developer experience. ✨

#### Here is an exemple of usage

https://github.com/flodlc/http-wizard/assets/3781663/71c749f0-3493-4865-8a9a-41421a371a05

### What it can do:

- 100% type-safe api client with typescript magic (no code generation)
- Fastify first-class support
- React-query first-class support
- Zod and Typebox Type providers
- Delightful end-to-end developer experience (tRPC-like)
- Http standards / REST compatibility: you are owner of your routes
- Type inference utils

---

Table of Contents:

- [Installation](#installation)
- [Usage](#usage)

---

## Installation

To get started, install http-wizard using npm or yarn:

```sh
npm install @http-wizard/core
# or
yarn add @http-wizard/core
```

## Usage

Currently http-wizard uses Zod or Typebox for validation.
Here is an exemple with Zod.

Let's first create a route on the server:

```typescript title="Route creation with Fastify and Zod"
// server.ts
import { createRoute } from "@http-wizard/core";
import { z } from "zod";

const User = z.object({
id: z.string(),
name: z.string(),
});

export const getUsers = (fastify: FastifyInstance) => {
return createRoute("/users", {
method: "GET",
schema: {
response: {
200: z.array(User),
},
},
}).handle((props) => {
fastify.route({
...props,
handler: (request) => {
const users = await db.getUsers();
return users;
},
});
});
};

const router = { ...getUsers() };
export type Router = typeof router;
```

Now, let's use the Router type on the client:

```typescript title="Client instanciation with axios"
// client.ts
import { createClient, ZodTypeProvider } from "@http-wizard/core";
import axios from "axios";

import type { Router } from "./server";

const apiClient = createClient<Router, ZodTypeProvider>(axios.instance());
const users = await apiClient.ref("[GET]/users").query({});
// users array is safe: { id:string, name:string }[]
```

Easy right ?
13 changes: 4 additions & 9 deletions packages/react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,29 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"packageManager": "[email protected]",
"version": "1.3.12",
"version": "1.3.14",
"scripts": {
"dev": "tsup src/index.ts --watch",
"build": "tsup src/index.ts --dts",
"test": "jest"
},
"dependencies": {
"axios": "^1.4.0"
},
"dependencies": {},
"devDependencies": {
"@sinclair/typebox": "^0.31.23",
"@tanstack/react-query": "^5.8.1",
"@types/jest": "^29.5.2",
"@types/node": "^18.7.16",
"axios": "^1.4.0",
"esbuild-jest": "^0.5.0",
"http-wizard": "1.3.11",
"@http-wizard/core": "1.3.13",
"jest": "^29.5.0",
"ts-jest": "^29.1.1",
"tsup": "^6.2.3",
"typescript": "^5.0.4",
"zod": "^3.22.4"
},
"peerDependencies": {
"@sinclair/typebox": "^0.29.0",
"@tanstack/react-query": "5.x",
"http-wizard": "1.3.11",
"zod": "3.x"
"@http-wizard/core": "1.3.13"
},
"files": [
"dist/*"
Expand Down
8 changes: 5 additions & 3 deletions packages/react-query/src/ReactQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
RouteDefinition,
TypeProvider,
createClient,
} from "http-wizard";
} from "@http-wizard/core";
import {
FetchQueryOptions,
QueryClient,
Expand All @@ -21,11 +21,11 @@ import {
useQuery,
useQueryClient,
} from "@tanstack/react-query";
import { AxiosRequestConfig } from "axios";
import axios, { AxiosRequestConfig } from "axios";

export const createQueryClient = <
Definitions extends Record<string, RouteDefinition>,
TP extends TypeProvider
TP extends TypeProvider,
>({
queryClient: optionQueryClient,
...options
Expand Down Expand Up @@ -149,3 +149,5 @@ export const createQueryClient = <
},
};
};

createQueryClient({ instance: axios.create() });
2 changes: 1 addition & 1 deletion packages/react-query/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type { Client, RouteDefinition, OkResponse } from "http-wizard";
export type { Client, RouteDefinition, OkResponse } from "@http-wizard/core";
export { createQueryClient } from "./ReactQuery";
Loading

0 comments on commit 4386e82

Please sign in to comment.