Skip to content

Commit d17f184

Browse files
Update to release on NPM.
1 parent 40180bb commit d17f184

File tree

8 files changed

+734
-258
lines changed

8 files changed

+734
-258
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.log
22
.DS_Store
33
node_modules
4+
dist

README.md

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,3 @@
1-
# TSDX User Guide
1+
# React Query API
22

3-
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
4-
5-
> This TSDX setup is meant for developing libraries (not apps!) that can be published to NPM. If you’re looking to build a Node app, you could use `ts-node-dev`, plain `ts-node`, or simple `tsc`.
6-
7-
> If you’re new to TypeScript, checkout [this handy cheatsheet](https://devhints.io/typescript)
8-
9-
## Commands
10-
11-
TSDX scaffolds your new library inside `/src`.
12-
13-
To run TSDX, use:
14-
15-
```bash
16-
npm start # or yarn start
17-
```
18-
19-
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
20-
21-
To do a one-off build, use `npm run build` or `yarn build`.
22-
23-
To run tests, use `npm test` or `yarn test`.
24-
25-
## Configuration
26-
27-
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
28-
29-
### Jest
30-
31-
Jest tests are set up to run with `npm test` or `yarn test`.
32-
33-
### Bundle Analysis
34-
35-
[`size-limit`](https://github.com/ai/size-limit) is set up to calculate the real cost of your library with `npm run size` and visualize the bundle with `npm run analyze`.
36-
37-
#### Setup Files
38-
39-
This is the folder structure we set up for you:
40-
41-
```txt
42-
/src
43-
index.tsx # EDIT THIS
44-
/test
45-
blah.test.tsx # EDIT THIS
46-
.gitignore
47-
package.json
48-
README.md # EDIT THIS
49-
tsconfig.json
50-
```
51-
52-
### Rollup
53-
54-
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
55-
56-
### TypeScript
57-
58-
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
59-
60-
## Continuous Integration
61-
62-
### GitHub Actions
63-
64-
Two actions are added by default:
65-
66-
- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
67-
- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
68-
69-
## Optimizations
70-
71-
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
72-
73-
```js
74-
// ./types/index.d.ts
75-
declare var __DEV__: boolean;
76-
77-
// inside your code...
78-
if (__DEV__) {
79-
console.log('foo');
80-
}
81-
```
82-
83-
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
84-
85-
## Module Formats
86-
87-
CJS, ESModules, and UMD module formats are supported.
88-
89-
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
90-
91-
## Named Exports
92-
93-
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
94-
95-
## Including Styles
96-
97-
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
98-
99-
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
100-
101-
## Publishing to NPM
102-
103-
We recommend using [np](https://github.com/sindresorhus/np).
3+
This is the React Query API which is used for the React Query course on ui.dev. Built with [MSW](https://mswjs.io).

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"node": ">=10"
1212
},
1313
"scripts": {
14+
"dev": "nodemon --exec node -r ts-eager/register server.ts",
1415
"start": "tsdx watch",
1516
"build": "tsdx build",
1617
"lint": "tsdx lint",
@@ -30,7 +31,7 @@
3031
"singleQuote": true,
3132
"trailingComma": "es5"
3233
},
33-
"name": "react-query-api",
34+
"name": "@uidotdev/react-query-api",
3435
"author": "Alex Anderson",
3536
"module": "dist/react-query-api.esm.js",
3637
"size-limit": [
@@ -46,12 +47,15 @@
4647
"devDependencies": {
4748
"@size-limit/preset-small-lib": "^5.0.5",
4849
"husky": "^7.0.2",
50+
"nodemon": "^2.0.13",
4951
"size-limit": "^5.0.5",
5052
"tsdx": "^0.14.1",
5153
"tslib": "^2.3.1",
5254
"typescript": "^4.4.3"
5355
},
5456
"dependencies": {
55-
"msw": "^0.35.0"
57+
"msw": "^0.35.0",
58+
"node-fetch": "^3.0.0",
59+
"ts-eager": "^2.0.2"
5660
}
5761
}

server.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { setupServer } from 'msw/node';
2+
import { handlers } from './src/handlers';
3+
import http from 'http';
4+
5+
const port = Number(process.env.PORT) || 3000;
6+
7+
(async function runServer() {
8+
const { default: fetch, Headers, Response } = await import('node-fetch');
9+
const mockServer = setupServer(...handlers);
10+
11+
mockServer.listen();
12+
13+
const server = http.createServer(async (req, res) => {
14+
const body: string = await new Promise(res => {
15+
let data = '';
16+
req.on('data', chunk => {
17+
data += chunk;
18+
});
19+
20+
req.on('end', () => {
21+
res(data);
22+
});
23+
});
24+
const headers = new Headers();
25+
for (let header in req.headers) {
26+
headers.append(header, req.headers[header].toString());
27+
}
28+
try {
29+
const response = await Promise.race([
30+
fetch(`http://localhost:3000${req.url}`, {
31+
method: req.method,
32+
body: req.method !== 'GET' ? body : undefined,
33+
headers,
34+
}),
35+
new Promise((_, reject) => setTimeout(reject, 1500)),
36+
]);
37+
if (!(response instanceof Response)) {
38+
throw new Error('Response is not instance of Response');
39+
}
40+
const result = await response.text();
41+
response.headers.forEach((v, k) => res.setHeader(k, v));
42+
res.statusCode = response.status;
43+
res.end(result);
44+
} catch (err) {
45+
console.log(err);
46+
res.statusCode = 500;
47+
res.end('Error making request');
48+
}
49+
});
50+
51+
server.listen(port, () => {
52+
console.log(`Server running at port ${port}`);
53+
});
54+
})();

src/db.ts

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
import { Issue, Label, User } from "./types";
1+
import { Issue, Label, User, IssueComment } from './types';
22

33
export let users: User[] = [
44
{
5-
id: "u_1",
6-
name: "Tyler",
5+
id: 'u_1',
6+
name: 'Tyler',
77
profilePictureUrl:
8-
"https://pbs.twimg.com/profile_images/1428205319616798721/xmr7q976_400x400.jpg",
8+
'https://pbs.twimg.com/profile_images/1428205319616798721/xmr7q976_400x400.jpg',
99
},
1010
{
11-
id: "u_2",
12-
name: "Bono",
11+
id: 'u_2',
12+
name: 'Bono',
1313
profilePictureUrl:
14-
"https://pbs.twimg.com/profile_images/1384860221110095873/f8s_E6a6_400x400.jpg",
14+
'https://pbs.twimg.com/profile_images/1384860221110095873/f8s_E6a6_400x400.jpg',
1515
},
1616
{
17-
id: "u_3",
18-
name: "Tanner",
17+
id: 'u_3',
18+
name: 'Tanner',
1919
profilePictureUrl:
20-
"https://pbs.twimg.com/profile_images/1164219021283094530/ACRln2kL_400x400.jpg",
20+
'https://pbs.twimg.com/profile_images/1164219021283094530/ACRln2kL_400x400.jpg',
2121
},
2222
{
23-
id: "u_4",
24-
name: "Alex",
23+
id: 'u_4',
24+
name: 'Alex',
2525
profilePictureUrl:
26-
"https://pbs.twimg.com/profile_images/1403026826075779075/cHtraFgQ_400x400.jpg",
26+
'https://pbs.twimg.com/profile_images/1403026826075779075/cHtraFgQ_400x400.jpg',
2727
},
2828
];
2929

3030
export let labels: Label[] = [
31-
{ id: "l_1", color: "red", name: "bug" },
32-
{ id: "l_2", color: "blue", name: "feature" },
33-
{ id: "l_3", color: "cyan", name: "enhancement" },
34-
{ id: "l_4", color: "orange", name: "question" },
35-
{ id: "l_5", color: "lime", name: "help wanted" },
36-
{ id: "l_6", color: "white", name: "wontfix" },
37-
{ id: "l_7", color: "rebeccapurple", name: "duplicate" },
38-
{ id: "l_8", color: "yellow", name: "help-wanted" },
31+
{ id: 'l_1', color: 'red', name: 'bug' },
32+
{ id: 'l_2', color: 'blue', name: 'feature' },
33+
{ id: 'l_3', color: 'cyan', name: 'enhancement' },
34+
{ id: 'l_4', color: 'orange', name: 'question' },
35+
{ id: 'l_5', color: 'lime', name: 'help wanted' },
36+
{ id: 'l_6', color: 'white', name: 'wontfix' },
37+
{ id: 'l_7', color: 'rebeccapurple', name: 'duplicate' },
38+
{ id: 'l_8', color: 'yellow', name: 'help-wanted' },
3939
];
4040

4141
const templateIssues = [
42-
"Dependencies need to be updated",
43-
"Poor performance on Windows devices",
44-
"Poor performance on macOS devices",
45-
"Poor performance on Android devices",
46-
"Holding down the space bar causes the processor to heat up",
42+
'Dependencies need to be updated',
43+
'Poor performance on Windows devices',
44+
'Poor performance on macOS devices',
45+
'Poor performance on Android devices',
46+
'Holding down the space bar causes the processor to heat up',
4747
`Error: "Cannot read property 'length' of undefined"`,
48-
"The app is crashing on iOS devices",
49-
"How am I supposed to create new tasks?",
50-
"Styling on the profile page looks weird.",
51-
"Feature: Build out multiplayer connectivity",
52-
"Feature: Build out a leaderboard",
48+
'The app is crashing on iOS devices',
49+
'How am I supposed to create new tasks?',
50+
'Styling on the profile page looks weird.',
51+
'Feature: Build out multiplayer connectivity',
52+
'Feature: Build out a leaderboard',
5353
];
5454

5555
const templateIssueComments = [
@@ -58,51 +58,59 @@ const templateIssueComments = [
5858
"I'm working on it.",
5959
"I'm not sure how to fix it.",
6060
"I'm not sure if I can reproduce the problem.",
61-
"This is a really big deal for me.",
62-
"Has there been any progress on this?",
63-
"What is the status of this issue?",
64-
"Never mind, I figured out how to fix this",
65-
"Can you send me a little bit more information about the problem.",
61+
'This is a really big deal for me.',
62+
'Has there been any progress on this?',
63+
'What is the status of this issue?',
64+
'Never mind, I figured out how to fix this',
65+
'Can you send me a little bit more information about the problem.',
6666
"I've reproduced this issue. Working on a fix now.",
6767
"I'm on it. I'll get back to you when I'm done.",
68-
"It would seem this is caused by user error.",
69-
"Whoops, I just dropped the production database. Hang on...",
68+
'It would seem this is caused by user error.',
69+
'Whoops, I just dropped the production database. Hang on...',
7070
];
7171

72-
const allStatus: ("backlog" | "todo" | "inProgress" | "done" | "cancelled")[] =
73-
["backlog", "todo", "inProgress", "done", "cancelled"];
72+
const allStatus: (
73+
| 'backlog'
74+
| 'todo'
75+
| 'inProgress'
76+
| 'done'
77+
| 'cancelled'
78+
)[] = ['backlog', 'todo', 'inProgress', 'done', 'cancelled'];
79+
80+
export let issueComments: IssueComment[] = [];
7481

7582
export const issues: Issue[] = Array.from({ length: 100 }, (_, i) => {
7683
const isCompleted = Math.random() > 0.9;
84+
const comments: IssueComment[] = Array.from(
85+
{ length: Math.floor(Math.random() * 10) + 1 },
86+
(_, j) => ({
87+
id: `c_${issueComments.length + j}`,
88+
createdDate: new Date(Date.now() - Math.floor(Math.random() * 100000)),
89+
createdBy: users[Math.floor(Math.random() * users.length)].id,
90+
issueId: `i_${i}`,
91+
comment:
92+
templateIssueComments[
93+
Math.floor(Math.random() * templateIssueComments.length)
94+
],
95+
})
96+
);
97+
issueComments = issueComments.concat(comments);
7798
return {
7899
id: `i_${i}`,
79100
title: templateIssues[Math.floor(Math.random() * templateIssues.length)],
80-
labels: [labels[Math.floor(Math.random() * labels.length)]],
81-
comments: Array.from(
82-
{ length: Math.floor(Math.random() * 10) + 1 },
83-
(_, j) => ({
84-
id: `c_${i}_${j}`,
85-
createdDate: new Date(Date.now() - Math.floor(Math.random() * 100000)),
86-
createdBy: users[Math.floor(Math.random() * users.length)],
87-
issueId: `i_${i}`,
88-
user: users[Math.floor(Math.random() * users.length)],
89-
comment:
90-
templateIssueComments[
91-
Math.floor(Math.random() * templateIssueComments.length)
92-
],
93-
})
94-
),
101+
labels: [labels[Math.floor(Math.random() * labels.length)].id],
102+
comments: comments.map(c => c.id),
95103
number: i + 1,
96104
status: isCompleted
97-
? "done"
98-
: allStatus.filter((f) => f !== "done")[
105+
? 'done'
106+
: allStatus.filter(f => f !== 'done')[
99107
Math.floor(Math.random() * allStatus.length)
100108
],
101109
createdDate: new Date(Date.now() - Math.floor(Math.random() * 10000000000)),
102-
createdBy: users[Math.floor(Math.random() * users.length)],
110+
createdBy: users[Math.floor(Math.random() * users.length)].id,
103111
assignee:
104112
Math.random() > 0.5
105-
? users[Math.floor(Math.random() * users.length)]
113+
? users[Math.floor(Math.random() * users.length)].id
106114
: null,
107115
dueDate:
108116
Math.random() > 0.5

0 commit comments

Comments
 (0)