Skip to content

Commit eb067b6

Browse files
committed
feat: 🎸 New API
BREAKING CHANGE: 🧨 Changed almost all library APIs
1 parent 8ddd579 commit eb067b6

File tree

297 files changed

+5510
-5455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+5510
-5455
lines changed

.bin/jest.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ cwd=$(echo "$jest_config" | sed 's|\(.*\)/.*|\1|')
88

99
cd "$cwd"
1010

11-
command="yarn jest '$1' -c $jest_config -t '$5' $6"
11+
request="yarn jest '$1' -c $jest_config -t '$5' $6"
1212

13-
eval "$command"
13+
eval "$request"
1414

1515
cd ../..

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ particular `caching`, `queuing`, `persistence`, `offline first support`, `reques
7373

7474
🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Offline)
7575

76-
📡 **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Client)
76+
📡 **Built-in adapter** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Adapter)
7777

7878
🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Testing)
7979

@@ -182,17 +182,17 @@ yarn add @hyper-fetch/core @hyper-fetch/react
182182
#### Simple Setup
183183

184184
```tsx
185-
import { Builder } from "@hyper-fetch/core";
185+
import { Client } from "@hyper-fetch/core";
186186

187187
// Create global setup
188-
export const builder = new Builder({ url: "http://localhost:3000" });
188+
export const client = new Client({ url: "http://localhost:3000" });
189189

190-
// Create reusable commands to trigger requests
191-
export const postData = builder.createCommand<ResponseType, RequestType, LocalErrorType, QueryParamsType>()({
190+
// Create reusable requests to trigger requests
191+
export const postData = client.createRequest<ResponseType, RequestType, LocalErrorType, QueryParamsType>()({
192192
method: "POST",
193193
endpoint: "/data/:accountId",
194194
});
195-
export const getData = builder.createCommand<ResponseType, RequestType, LocalErrorType, QueryParamsType>()({
195+
export const getData = client.createRequest<ResponseType, RequestType, LocalErrorType, QueryParamsType>()({
196196
method: "GET",
197197
endpoint: "/user",
198198
});
@@ -201,17 +201,17 @@ export const getData = builder.createCommand<ResponseType, RequestType, LocalErr
201201
#### Triggering request
202202

203203
```tsx
204-
// Set the information to command (methods return command clone - NOT mutating the source)
205-
const command = postData
204+
// Set the information to request (methods return request clone - NOT mutating the source)
205+
const request = postData
206206
.setParams({ accountId: 104 }) // Set Params
207207
.setQueryParams({ paramOne: "test", paramTwo: "test2" })
208208
.setData({ name: "My new entity", description: "Some description" }); // Add payload data
209209

210-
// Use command directly
211-
const [data, error, status] = await command.send();
210+
// Use request directly
211+
const [data, error, status] = await request.send();
212212

213213
// OR pass dynamic data directly to '.send' method
214-
const [data, error, status] = await command.send({
214+
const [data, error, status] = await request.send({
215215
params: { accountId: 104 },
216216
data: { name: "My new entity", description: "Some description" },
217217
queryParams: { paramOne: "test", paramTwo: "test2" },
@@ -244,7 +244,7 @@ onError((error) => {
244244
```tsx
245245
import { useSubmit } from "@hyper-fetch/react";
246246

247-
const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(command);
247+
const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(request);
248248

249249
onSuccess((data) => {
250250
console.log(data);
@@ -262,7 +262,7 @@ return <button onClick={() => submit()}>Trigger request!</button>;
262262
```tsx
263263
import { useSubmit } from "@hyper-fetch/react";
264264

265-
const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(command);
265+
const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(request);
266266

267267
onSuccess((data) => {
268268
console.log(data);
@@ -293,7 +293,7 @@ return (
293293
import { useSubmit } from "@hyper-fetch/react";
294294

295295
// Manual triggering
296-
const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(command);
296+
const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(request);
297297

298298
onSuccess((data) => {
299299
console.log(data);

documentation/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Website
22

3-
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website
4-
generator.
3+
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
54

65
### Installation
76

@@ -15,23 +14,23 @@ $ yarn
1514
$ yarn start
1615
```
1716

18-
This command starts a local development server and opens up a browser window. Most changes are
19-
reflected live without having to restart the server.
17+
This request starts a local development server and opens up a browser window. Most changes are reflected live without
18+
having to restart the server.
2019

2120
### Build
2221

2322
```
2423
$ yarn build
2524
```
2625

27-
This command generates static content into the `build` directory and can be served using any static
28-
contents hosting service.
26+
This request generates static content into the `build` directory and can be served using any static contents hosting
27+
service.
2928

3029
### Deployment
3130

3231
```
3332
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
3433
```
3534

36-
If you are using GitHub pages for hosting, this command is a convenient way to build the website and
37-
push to the `gh-pages` branch.
35+
If you are using GitHub pages for hosting, this request is a convenient way to build the website and push to the
36+
`gh-pages` branch.

documentation/blog/2021-12-29-introducing-hyper-fetch.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ in systems that need offline or even persistent cache and request queues. It was
2626
classes for those purposes but it also suited my philosophy of writing interceptors in tests, where the functional
2727
approach requires copying part of the setup or extracting it significantly around files. As one of the lazy type of
2828
developers, the most pleasant thing was to write a class based shared setup, where the tester or developer could connect
29-
to such a builder or a specific command, thanks to which he based everything on the current setup running in the
29+
to such a client or a specific request, thanks to which he based everything on the current setup running in the
3030
application. Thanks to this approach, the tests were more maintainable, any changes in the structure were visible
3131
immediately thanks to typescript and the smaller config values were updated automatically, e.g. adding change to the
3232
name of the endpoint did not have to be corrected in the tests because it uses actual app setup. It is simply a
@@ -43,19 +43,19 @@ plugins and extensions - we are very open to help in testing and development, bu
4343
approved by the creators, especially at the beginning of the road, where testing and it may take us a while to cover
4444
everything with testing.
4545

46-
## Builder
46+
## Client
4747

48-
Builder is a class thanks to which we can control the entire process of interaction with the server. This is where all
49-
request sending queues, cache and other modules necessary for operation, such as the http client, are initialized. Its
48+
Client is a class thanks to which we can control the entire process of interaction with the server. This is where all
49+
request sending queues, cache and other modules necessary for operation, such as the http adapter, are initialized. Its
5050
main purpose is to set up one place where we prepare our connection, first of all establishing the base url of our
51-
server. With the setup builder behind us, we can create new instances of commands that will be able to use the prepared
51+
server. With the setup client behind us, we can create new instances of requests that will be able to use the prepared
5252
setup and derive information from it.
5353

54-
## Command
54+
## Request
5555

56-
Command is an interaction with a given endpoint. During initialization, we set the path, method and a whole range of
56+
Request is an interaction with a given endpoint. During initialization, we set the path, method and a whole range of
5757
interesting options such as cache time, retries count etc. It keeps the configuration needed to execute the request or
58-
to dump it and save in queue storage to wait for its turn. The biggest advantage of Command is simplicity and the
58+
to dump it and save in queue storage to wait for its turn. The biggest advantage of Request is simplicity and the
5959
ability to quickly set the entire configuration - only one option is required - the endpoint(method is defaulted to
6060
GET).
6161

documentation/docs/documentation/01-Getting Started/Comparison.mdx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Hyper Fetch is not just a wrapper; it offers full control over the flow and obse
1313
were to introduce:
1414

1515
- a data storage standard,
16-
- offer an embedded HTTP client,
16+
- offer an embedded HTTP adapter,
1717
- reduce setup times,
1818
- solve major architectural difficulties.
1919

@@ -30,8 +30,8 @@ data needs to be corrected, please let us know by opening an issue.
3030

3131
- Easy upload/download progress and ETA tracking
3232
- Supports request queueing and many [dispatching strategies](/documentation/02-Core/Dispatcher.mdx#dispatching-modes)!
33-
- [Command](/documentation/02-Core/Command.mdx) / [Builder](/documentation/02-Core/Builder.mdx) pattern gives you
34-
amazing control over requests at any time
33+
- [Command](/documentation/02-Core/Request.mdx) / [Builder](/documentation/02-Core/Client.mdx) pattern gives you amazing
34+
control over requests at any time
3535
- Code-sharing architecture lets [testers to hook into development setup and types](/documentation/01-Getting
3636
Started/Testing.mdx)
3737
- Features flat side-effects [helper hooks annotation](/documentation/04-React/01-Overview.mdx#helper-hooks) and
@@ -89,14 +89,14 @@ data needs to be corrected, please let us know by opening an issue.
8989
</tr>
9090
<tr>
9191
<td>Caching Approach</td>
92-
<td>Command Schema</td>
92+
<td>Request Schema</td>
9393
<td>Hierarchical Key > Value</td>
9494
<td>Unique Key > Value</td>
9595
<td>Normalized Schema</td>
9696
</tr>
9797
<tr>
9898
<td>Cache Key Strategy</td>
99-
<td>Command Key</td>
99+
<td>Request Key</td>
100100
<td>JSON</td>
101101
<td>JSON</td>
102102
<td>GraphQL Query</td>
@@ -117,7 +117,7 @@ data needs to be corrected, please let us know by opening an issue.
117117
</tr>
118118
<tr>
119119
<td>Queue Key Strategy</td>
120-
<td>Command Key</td>
120+
<td>Request Key</td>
121121
<td>N/A</td>
122122
<td>N/A</td>
123123
<td>N/A</td>
@@ -143,8 +143,8 @@ data needs to be corrected, please let us know by opening an issue.
143143
</tr>
144144
<tr>
145145
<td>
146-
Shared Command{" "}
147-
<Tippy content="Being able to prepare commands to be reused in the application">
146+
Shared Request{" "}
147+
<Tippy content="Being able to prepare requests to be reused in the application">
148148
<span>ℹ️</span>
149149
</Tippy>
150150
</td>
@@ -277,8 +277,8 @@ data needs to be corrected, please let us know by opening an issue.
277277
</tr>
278278
<tr>
279279
<td>
280-
Default Client{" "}
281-
<Tippy content="Library includes prepared client for requesting">
280+
Default Adapter{" "}
281+
<Tippy content="Library includes prepared adapter for requesting">
282282
<span>ℹ️</span>
283283
</Tippy>
284284
</td>
@@ -597,7 +597,7 @@ data needs to be corrected, please let us know by opening an issue.
597597
<tr>
598598
<td>
599599
File Uploading{" "}
600-
<Tippy content="File upload with built-in client">
600+
<Tippy content="File upload with built-in adapter">
601601
<span>ℹ️</span>
602602
</Tippy>
603603
</td>
@@ -632,8 +632,8 @@ data needs to be corrected, please let us know by opening an issue.
632632
</tr>
633633
<tr>
634634
<td>
635-
Simple Command Execution{" "}
636-
<Tippy content="Possibility to trigger requests commands">
635+
Simple Request Execution{" "}
636+
<Tippy content="Possibility to trigger requests requests">
637637
<span>ℹ️</span>
638638
</Tippy>
639639
</td>
@@ -804,8 +804,8 @@ data needs to be corrected, please let us know by opening an issue.
804804
</tr>
805805
<tr>
806806
<td>
807-
Command state tracking types{" "}
808-
<Tippy content="Types to check if you already set the data/params/query params on given command to prevent data corruption">
807+
Request state tracking types{" "}
808+
<Tippy content="Types to check if you already set the data/params/query params on given request to prevent data corruption">
809809
<span>ℹ️</span>
810810
</Tippy>
811811
</td>

documentation/docs/documentation/01-Getting Started/Development.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ sidebar_position: 5
55
## Structure
66

77
1. Structure is critically important, so we'll explain how we approach it in HyperFetch. First of all, we create a
8-
directory for our `builder` and its `commands`. We export the prepared elements from this directory.
8+
directory for our `client` and its `requests`. We export the prepared elements from this directory.
99

1010
2. Next, we create a directory for each entity in our system (i.e. users, todos, categories, products, groups ...) and
11-
store our commands.
11+
store our requests.
1212

1313
3. During this setup, we maintain maximum re-usability; thanks to the usage of classes and object-oriented approach, we
14-
can access these elements from anywhere. We can reuse our previously-prepared commands in any component. Also, tests
14+
can access these elements from anywhere. We can reuse our previously-prepared requests in any component. Also, tests
1515
have full access without any setup duplication – they use the current settings.
1616

1717
```
1818
src
1919
2020
├── api
21-
│ ├── builder.ts
21+
│ ├── client.ts
2222
│ ├── users
2323
│ │ ├── users.api.ts
2424
│ │ └── index.ts
@@ -39,12 +39,12 @@ You can debug apps in one of two ways:
3939

4040
** 1. Use the built-in logger **
4141

42-
Use the builder `setDebug(true)` method for this. It will start logging actions in the console. To adjust what type of
42+
Use the client `setDebug(true)` method for this. It will start logging actions in the console. To adjust what type of
4343
logs will be shown, use `setLoggerSeverity(3)` to get debug logs displayed in the console. Those will show you the exact
4444
data and information flow in the library while working on your application.
4545

4646
** 2. Create your own logger **
4747

4848
You can create your own dev tools based on events sent from the
49-
[commandManager](/documentation/02-Core/Managers.mdx#commandmanager). There is no limitation, and you can receive all
49+
[requestManager](/documentation/02-Core/Managers.mdx#requestmanager). There is no limitation, and you can receive all
5050
necessary data to create everything you may need.

documentation/docs/documentation/01-Getting Started/Quick Start.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ The basic version of Hyper Fetch is not associated with any framework or library
1111

1212
:::
1313

14-
### 1. Initialize the Builder
14+
### 1. Initialize the Client
1515

16-
The first step in implementing Hyper Fetch is to initialize the **[Builder](/documentation/02-Core/Builder.mdx)**. It
16+
The first step in implementing Hyper Fetch is to initialize the **[Client](/documentation/02-Core/Client.mdx)**. It
1717
manages the basic configuration for connection to the server and all Hyper Fetch’s essential elements (i.e. instances of
1818
**dispatchers**, **cache**, and **app managers**). Start by determining the `url` of your server.
1919

20-
```tsx title="/src/server/builder.ts"
21-
import { Builder } from "@hyper-fetch/core";
20+
```tsx title="/src/server/client.ts"
21+
import { Client } from "@hyper-fetch/core";
2222

23-
export const builder = new Builder({ url: "http://localhost:3000" });
23+
export const client = new Client({ url: "http://localhost:3000" });
2424
```
2525

26-
### 2. Create Commands
26+
### 2. Create Requests
2727

28-
Then, having already prepared a connection to the server, we use the builder method to create
29-
**[commands](/documentation/02-Core/Command.mdx)** and assign types to them.
28+
Then, having already prepared a connection to the server, we use the client method to create
29+
**[requests](/documentation/02-Core/Request.mdx)** and assign types to them.
3030

3131
:::caution
3232

@@ -37,15 +37,15 @@ resolved.
3737
:::
3838

3939
```tsx title="/src/server/auth/auth.ts"
40-
import { builder } from "../builder.ts";
40+
import { client } from "../client.ts";
4141

4242
type ResponseType = { token: string; refreshToken: string };
4343
type RequestType = { email: string; password: string };
4444

45-
const postLogin = builder.createCommand<ResponseType, RequestType>()({ method: "POST", endpoint: "/auth/login" });
45+
const postLogin = client.createRequest<ResponseType, RequestType>()({ method: "POST", endpoint: "/auth/login" });
4646
```
4747

48-
### 3. Use Commands
48+
### 3. Use Requests
4949

5050
<Tabs>
5151
<TabItem value="React" label="React" default>

0 commit comments

Comments
 (0)