Skip to content

Commit 089b700

Browse files
authored
Merge pull request #6 from johantor/bugfix/underlying-filesystem
fix: underlying filesystem, linting and package updates
2 parents 6d6ead9 + b1023f9 commit 089b700

21 files changed

Lines changed: 2808 additions & 837 deletions

.github/workflows/publish.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
- uses: actions/checkout@v1
1313
- uses: actions/setup-node@v1
1414
with:
15-
node-version: 16
15+
node-version: 22
1616
- run: npm install
17-
17+
1818
- name: Setup GIT
1919
run: |
2020
git reset --hard
@@ -23,8 +23,8 @@ jobs:
2323
git config user.email "wezz@wezz.se"
2424
git config user.name "Wezz Balk"
2525
env:
26-
GH_EMAIL: ${{secrets.GH_EMAIL}}
27-
26+
GH_EMAIL: ${{secrets.GH_EMAIL}}
27+
2828
- name: Bump version
2929
run: |
3030
git reset --hard
@@ -35,10 +35,10 @@ jobs:
3535
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY"
3636
env:
3737
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
38-
38+
3939
- name: npm publish
4040
run: |
4141
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
4242
npm publish --access public
4343
env:
44-
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
44+
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": false,
7+
"printWidth": 80,
8+
"bracketSpacing": true,
9+
"objectWrap": "preserve"
10+
}

README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# Fetch Manager
22

3-
This is a script to ease the use of making fetch requests.
3+
This is a script to ease the use of making fetch requests.
44
It features the ability to stop consequetive requests, delay a request and parse querystrings from JSON.
55

66
## Installation
7+
78
```
89
npm install @wezz/fetchmanager
910
```
1011

1112
## Usage
13+
1214
### Initialize Fetch Manager
15+
1316
```
1417
import { FetchManager } from '@wezz/fetchmanager';
1518
// On document ready
@@ -20,7 +23,9 @@ const data = response.json();
2023
```
2124

2225
## Options
26+
2327
When doing a fetch request you should define a options object that looks like this:
28+
2429
```
2530
{
2631
"key": "unique request key",
@@ -32,52 +37,61 @@ When doing a fetch request you should define a options object that looks like th
3237
"json": true
3338
}
3439
```
35-
*Note that the option fetchoptions is passed down directly to fetch.*<br/>
40+
41+
_Note that the option fetchoptions is passed down directly to fetch._<br/>
3642
[Click here for the fetch options documentation](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options)
3743

3844
### Key
45+
3946
If a key is set then the "signal" will be stored and if another request is being sent with an identical key, the current request will be aborted.
4047
So if you're doing requests related to a users input (typing in an input field) and sending a request per input, this would stop all the old requests and only deliver the last request made as to stop race conditions.
4148

4249
### Url
50+
4351
This is the URL you wish to fetch, without parameters
4452

4553
### Querystring
54+
4655
This can be empty, an object that will be parsed to a querystring, or just a string.
4756

4857
### Request delay
49-
This delays a request with the specified amount of miliseconds.
58+
59+
This delays a request with the specified amount of miliseconds.
5060

5161
### Cache
62+
5263
If this is enabled then any request will be cached in either local or session storage. Session storage is default.
53-
You can either send in a boolean,
64+
You can either send in a boolean,
5465
or you can send in an object like this
66+
5567
```
5668
{ permanent: true, cachekey: 'myCacheKey' }
5769
```
5870

5971
If permanent is set to true it will be stored in local storage.
6072

6173
### JSON
74+
6275
The JSON options will add the header "Content-Type": application/json and it is enabled by default.
63-
If another content type header has been specified it will not override it.
76+
If another content type header has been specified it will not override it.
6477

6578
Set this to false if you need to fetch any mimetype that is not json.
6679

6780
### Fetch options
81+
6882
Fetch options is standard fetch opions.
6983
[Read more about fetch options on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options).
7084

71-
7285
## Development & Demo
86+
7387
Clone this repo
7488
Run
75-
``` npm install ```
76-
77-
To run the interactive demo, run
78-
``` npm run demo ```
89+
`npm install`
7990

91+
To run the interactive demo, run
92+
`npm run demo`
8093

8194
## Breaking changes
82-
In the Version 1 release the response is no longer automatically parsed to JSON.
95+
96+
In the Version 1 release the response is no longer automatically parsed to JSON.
8397
Consumers of the package will get the regular response object back just as if they had used the native fetch function.

dist/FetchManager.d.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

dist/fetchmanager.umd.cjs

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/index.d.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1-
export { default as FetchManager } from './FetchManager';
1+
declare class FetchManager {
2+
moduleName: string;
3+
private requestStore;
4+
private defaultOptions;
5+
private defaultFetchOptions;
6+
constructor();
7+
ObjToQueryString(params: any): string;
8+
Fetch(initOptions: IFetchManagerOption): Promise<any>;
9+
GetScript(url: string): Promise<unknown>;
10+
CompileUrl(options: IFetchManagerOption): string;
11+
private getRequestObj;
12+
private getResponseFromCache;
13+
private validResponse;
14+
private saveResponseToCache;
15+
private parseFetchOptions;
16+
private getRequestCacheOptions;
17+
private getCacheKey;
18+
private getKey;
19+
private debug;
20+
}
21+
export default FetchManager;
22+
23+
declare interface IFetchManagerCacheOption {
24+
usecache: boolean;
25+
permanent: boolean;
26+
pemanent: boolean;
27+
cachekey: string;
28+
iscached?: boolean;
29+
}
30+
31+
declare interface IFetchManagerOption {
32+
key?: string;
33+
url: string;
34+
querystring?: object | string;
35+
requestdelay?: number;
36+
cache?: boolean | IFetchManagerCacheOption;
37+
fetchoptions?: RequestInit;
38+
signal?: AbortController["signal"];
39+
json?: boolean;
40+
debug?: boolean;
41+
}
42+
43+
export { }
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var p = Object.defineProperty;
22
var y = (a, e, t) => e in a ? p(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3-
var i = (a, e, t) => (y(a, typeof e != "symbol" ? e + "" : e, t), t);
4-
var g = Object.defineProperty, b = (a, e, t) => e in a ? g(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t, w = (a, e, t) => (b(a, typeof e != "symbol" ? e + "" : e, t), t);
3+
var i = (a, e, t) => y(a, typeof e != "symbol" ? e + "" : e, t);
4+
var g = Object.defineProperty, b = (a, e, t) => e in a ? g(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t, w = (a, e, t) => (b(a, e + "", t), t);
55
class S {
66
constructor(e = "cache") {
77
w(this, "prefix"), this.prefix = e;
@@ -97,7 +97,10 @@ class v {
9797
return this.has(e) ? delete this.root[this.storeNamespace][this.storeName][e] : !1;
9898
}
9999
}
100-
const f = new S("fetchmanager"), O = new v("requests", "fetchmanagerstore");
100+
const f = new S("fetchmanager"), O = new v(
101+
"requests",
102+
"fetchmanagerstore"
103+
);
101104
class $ {
102105
constructor() {
103106
i(this, "moduleName", "FetchManager");
@@ -120,8 +123,7 @@ class $ {
120123
const t = { ...this.defaultOptions, ...e };
121124
if (!t.url)
122125
return console.error("Need a url to do a request"), null;
123-
const o = this.getKey(t), r = this.getRequestObj(o, t);
124-
let s = this.parseFetchOptions(t);
126+
const o = this.getKey(t), r = this.getRequestObj(o, t), s = this.parseFetchOptions(t);
125127
if (t.json && !s.headers) {
126128
const n = new Headers(s.headers);
127129
n.has("Content-Type") || (n.append("Content-Type", "application/json"), s.headers = n);
@@ -181,6 +183,7 @@ class $ {
181183
return this.validResponse(t) ? {
182184
body: function() {
183185
},
186+
// eslint-disable-line @typescript-eslint/no-empty-function
184187
bodyUsed: !1,
185188
headers: {},
186189
redirected: !1,
@@ -205,7 +208,7 @@ class $ {
205208
async saveResponseToCache(e) {
206209
if (e.cache.usecache !== !0 || !e.result)
207210
return !1;
208-
let t = this.validResponse(e.result);
211+
const t = this.validResponse(e.result);
209212
if (this.debug(e.debug, "Storing response in cache ", e.result), !t)
210213
return console.info(
211214
"Result was not accepted so it is not saved to cache",
@@ -245,5 +248,5 @@ class $ {
245248
}
246249
}
247250
export {
248-
$ as FetchManager
251+
$ as default
249252
};

0 commit comments

Comments
 (0)