@reykjavik/webtools 0.2.10 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -5
- package/CookieHubConsent.d.ts +2 -2
- package/CookieHubConsent.js +2 -2
- package/README.md +21 -5
- package/SiteImprove.d.ts +3 -3
- package/SiteImprove.js +3 -3
- package/async.d.ts +4 -4
- package/async.js +3 -3
- package/errorhandling.d.ts +11 -10
- package/errorhandling.js +8 -7
- package/esm/CookieHubConsent.d.ts +2 -2
- package/esm/CookieHubConsent.js +2 -2
- package/esm/SiteImprove.d.ts +3 -3
- package/esm/SiteImprove.js +3 -3
- package/esm/async.d.ts +4 -4
- package/esm/async.js +3 -3
- package/esm/errorhandling.d.ts +11 -10
- package/esm/errorhandling.js +8 -7
- package/esm/hooks.d.ts +2 -2
- package/esm/hooks.js +2 -2
- package/esm/http.d.ts +11 -11
- package/esm/http.js +26 -18
- package/esm/next/http.d.ts +2 -2
- package/esm/next/http.js +3 -3
- package/esm/react-router/Wait.d.ts +2 -2
- package/esm/react-router/Wait.js +1 -1
- package/esm/react-router/http.d.ts +1 -1
- package/esm/react-router/http.js +1 -1
- package/esm/vanillaExtract.d.ts +4 -4
- package/esm/vanillaExtract.js +3 -3
- package/hooks.d.ts +2 -2
- package/hooks.js +2 -2
- package/http.d.ts +11 -11
- package/http.js +29 -21
- package/next/http.d.ts +2 -2
- package/next/http.js +3 -3
- package/package.json +1 -1
- package/react-router/Wait.d.ts +2 -2
- package/react-router/Wait.js +1 -1
- package/react-router/http.d.ts +1 -1
- package/react-router/http.js +1 -1
- package/vanillaExtract.d.ts +4 -4
- package/vanillaExtract.js +3 -3
package/esm/errorhandling.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Error subclass for thrown NON-Error values that got turned into an actual
|
|
3
3
|
* Error, with the original thrown value as the `payload` property.
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#aserror
|
|
6
6
|
*/
|
|
7
7
|
/*#__NO_SIDE_EFFECTS__*/
|
|
8
8
|
export class ErrorFromPayload extends Error {
|
|
@@ -24,7 +24,7 @@ export class ErrorFromPayload extends Error {
|
|
|
24
24
|
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
25
25
|
* original value is stored in a `payload`
|
|
26
26
|
*
|
|
27
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
27
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#aserror
|
|
28
28
|
*/
|
|
29
29
|
/*#__NO_SIDE_EFFECTS__*/
|
|
30
30
|
export const asError = (maybeError) => {
|
|
@@ -74,29 +74,30 @@ mapFn) => {
|
|
|
74
74
|
* Singleton object with small methods for creating, mapping or handling
|
|
75
75
|
* `ResultTupleObj` instances.
|
|
76
76
|
*
|
|
77
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
77
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#result-singleton
|
|
78
78
|
*/
|
|
79
79
|
export const Result = {
|
|
80
80
|
/**
|
|
81
81
|
* Factory for creating a successful `Result.TupleObj`.
|
|
82
82
|
*
|
|
83
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
83
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsuccess
|
|
84
84
|
*/
|
|
85
85
|
Success,
|
|
86
86
|
/**
|
|
87
87
|
* Factory for creating a failed `Result.TupleObj`.
|
|
88
88
|
*
|
|
89
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
89
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsfail
|
|
90
90
|
*/
|
|
91
91
|
Fail,
|
|
92
92
|
// NOTE: The JSDoc must be placed above the `catch_` function above.
|
|
93
93
|
catch: catch_,
|
|
94
|
+
ify: catch_,
|
|
94
95
|
/**
|
|
95
96
|
* Helper to map a `ResultTuple`-like object to a new `ResultTupleObj`
|
|
96
97
|
* object, applying a transformation function to the result, but retaining
|
|
97
98
|
* the error as-is.
|
|
98
99
|
*
|
|
99
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
100
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resulmap
|
|
100
101
|
*/
|
|
101
102
|
/*#__NO_SIDE_EFFECTS__*/
|
|
102
103
|
map: (result, mapFn) => {
|
|
@@ -110,7 +111,7 @@ export const Result = {
|
|
|
110
111
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
111
112
|
* and throws if there's an error, but returns the result otherwise.
|
|
112
113
|
*
|
|
113
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
114
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resulthrow
|
|
114
115
|
*/
|
|
115
116
|
/*#__NO_SIDE_EFFECTS__*/
|
|
116
117
|
throw: (result) => {
|
package/esm/hooks.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* **NOTE:** The supplied callback does not need to be memoized. The debouncer
|
|
7
7
|
* will always invoke the last supplied version.
|
|
8
8
|
*
|
|
9
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
9
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usedebounced
|
|
10
10
|
*/
|
|
11
11
|
export declare const useDebounced: <A extends Array<unknown>>(
|
|
12
12
|
/** The function to debounce */
|
|
@@ -23,7 +23,7 @@ immediate?: boolean) => ((...args: A) => void) & {
|
|
|
23
23
|
* **NOTE:** The supplied callback does not need to be memoized. The throttler
|
|
24
24
|
* will always invoke the last supplied version.
|
|
25
25
|
*
|
|
26
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
26
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usethrottled
|
|
27
27
|
*/
|
|
28
28
|
export declare const useThrottled: <A extends Array<unknown>>(
|
|
29
29
|
/** The function to throttle */
|
package/esm/hooks.js
CHANGED
|
@@ -8,7 +8,7 @@ import { debounce, throttle } from './async.js';
|
|
|
8
8
|
* **NOTE:** The supplied callback does not need to be memoized. The debouncer
|
|
9
9
|
* will always invoke the last supplied version.
|
|
10
10
|
*
|
|
11
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
11
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usedebounced
|
|
12
12
|
*/
|
|
13
13
|
export const useDebounced = (
|
|
14
14
|
/** The function to debounce */
|
|
@@ -29,7 +29,7 @@ immediate) => {
|
|
|
29
29
|
* **NOTE:** The supplied callback does not need to be memoized. The throttler
|
|
30
30
|
* will always invoke the last supplied version.
|
|
31
31
|
*
|
|
32
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
32
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usethrottled
|
|
33
33
|
*/
|
|
34
34
|
export const useThrottled = (
|
|
35
35
|
/** The function to throttle */
|
package/esm/http.d.ts
CHANGED
|
@@ -154,23 +154,23 @@ type TTLObj = {
|
|
|
154
154
|
/**
|
|
155
155
|
* Configures quick TTL-related settings for a HTTP request object
|
|
156
156
|
*
|
|
157
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
157
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-ttlconfig
|
|
158
158
|
*/
|
|
159
159
|
export type TTLConfig = TTL | TTLKeywords | TTLObj;
|
|
160
|
-
/**
|
|
161
|
-
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
162
|
-
* negative input values.
|
|
163
|
-
*
|
|
164
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#tosec-ttl-helper
|
|
165
|
-
*/
|
|
166
|
-
export declare const toSec: (ttl: TTL) => number;
|
|
167
160
|
/**
|
|
168
161
|
* Converts a `TTL` (duration) value into milliseconds. Returns `0` for bad
|
|
169
162
|
* and/or negative input values.
|
|
170
163
|
*
|
|
171
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
164
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#toms-duration-helper
|
|
172
165
|
*/
|
|
173
166
|
export declare const toMs: (ttl: TTL) => number;
|
|
167
|
+
/**
|
|
168
|
+
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
169
|
+
* negative input values.
|
|
170
|
+
*
|
|
171
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#tosec-ttl-helper
|
|
172
|
+
*/
|
|
173
|
+
export declare const toSec: (ttl: TTL) => number;
|
|
174
174
|
type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'removeHeader'> & {
|
|
175
175
|
headers?: Record<string, string | Array<string>>;
|
|
176
176
|
};
|
|
@@ -181,7 +181,7 @@ type ResponseStub = {
|
|
|
181
181
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
182
182
|
* on a HTTP response
|
|
183
183
|
*
|
|
184
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
184
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cachecontrol-helper
|
|
185
185
|
*/
|
|
186
186
|
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
|
|
187
187
|
res: ServerResponseStub | ResponseStub;
|
|
@@ -191,7 +191,7 @@ export declare const cacheControl: (response: ServerResponseStub | ResponseStub
|
|
|
191
191
|
* situations requiring a `HeadersInit` compatible object.
|
|
192
192
|
*
|
|
193
193
|
* Accepts the same arguments as `cacheControl()`.
|
|
194
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
194
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cachecontrolheaders-helper
|
|
195
195
|
*/
|
|
196
196
|
export declare const cacheControlHeaders: (ttlCfg: TTLConfig, eTag?: string | number) => Record<string, string>;
|
|
197
197
|
export {};
|
package/esm/http.js
CHANGED
|
@@ -125,36 +125,44 @@ export const HTTP_508_LoopDetected = 508;
|
|
|
125
125
|
export const HTTP_510_NotExtended = 510;
|
|
126
126
|
/** The client needs to authenticate to gain network access. */
|
|
127
127
|
export const HTTP_511_NetworkAuthenticationRequired = 511;
|
|
128
|
-
const
|
|
129
|
-
s:
|
|
130
|
-
m:
|
|
131
|
-
h:
|
|
132
|
-
d: 24 *
|
|
133
|
-
w: 7 * 24 *
|
|
128
|
+
const unitToMilliseconds = {
|
|
129
|
+
s: 1000,
|
|
130
|
+
m: 60000,
|
|
131
|
+
h: 60 * 60000,
|
|
132
|
+
d: 24 * 60 * 60000,
|
|
133
|
+
w: 7 * 24 * 60 * 60000,
|
|
134
134
|
};
|
|
135
135
|
/**
|
|
136
|
-
* Converts a `TTL` (
|
|
137
|
-
* negative input values.
|
|
136
|
+
* Converts a `TTL` (duration) value into milliseconds. Returns `0` for bad
|
|
137
|
+
* and/or negative input values.
|
|
138
138
|
*
|
|
139
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
139
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#toms-duration-helper
|
|
140
140
|
*/
|
|
141
141
|
/*#__NO_SIDE_EFFECTS__*/
|
|
142
|
-
export const
|
|
142
|
+
export const toMs = (ttl) => {
|
|
143
|
+
if (!ttl) {
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
143
146
|
if (typeof ttl === 'string') {
|
|
144
147
|
const value = parseFloat(ttl);
|
|
145
|
-
const factor =
|
|
148
|
+
const factor = unitToMilliseconds[ttl.slice(-1)] || 1;
|
|
146
149
|
ttl = value * factor;
|
|
147
150
|
}
|
|
148
151
|
return Math.max(0, Math.round(ttl)) || 0;
|
|
149
152
|
};
|
|
150
153
|
/**
|
|
151
|
-
* Converts a `TTL` (
|
|
152
|
-
*
|
|
154
|
+
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
155
|
+
* negative input values.
|
|
153
156
|
*
|
|
154
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
157
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#tosec-ttl-helper
|
|
155
158
|
*/
|
|
156
159
|
/*#__NO_SIDE_EFFECTS__*/
|
|
157
|
-
export const
|
|
160
|
+
export const toSec = (ttl) => {
|
|
161
|
+
if (typeof ttl === 'number') {
|
|
162
|
+
ttl = ttl * 1000;
|
|
163
|
+
}
|
|
164
|
+
return Math.round(toMs(ttl) / 1000);
|
|
165
|
+
};
|
|
158
166
|
/*#__NO_SIDE_EFFECTS__*/
|
|
159
167
|
const toRespnseStubHeaders = (response) => {
|
|
160
168
|
if (response instanceof Map) {
|
|
@@ -199,7 +207,7 @@ const setCC = (response, cc) => {
|
|
|
199
207
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
200
208
|
* on a HTTP response
|
|
201
209
|
*
|
|
202
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
210
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cachecontrol-helper
|
|
203
211
|
*/
|
|
204
212
|
/*#__NO_SIDE_EFFECTS__*/ // eslint-disable-next-line complexity
|
|
205
213
|
export const cacheControl = (response, ttlCfg, eTag) => {
|
|
@@ -210,7 +218,7 @@ export const cacheControl = (response, ttlCfg, eTag) => {
|
|
|
210
218
|
let maxAge = opts.maxAge;
|
|
211
219
|
if (typeof maxAge === 'string') {
|
|
212
220
|
if (maxAge === 'permanent') {
|
|
213
|
-
maxAge = 365 *
|
|
221
|
+
maxAge = 365 * unitToMilliseconds.d;
|
|
214
222
|
}
|
|
215
223
|
else if (maxAge === 'no-cache') {
|
|
216
224
|
maxAge = 0;
|
|
@@ -242,7 +250,7 @@ export const cacheControl = (response, ttlCfg, eTag) => {
|
|
|
242
250
|
* situations requiring a `HeadersInit` compatible object.
|
|
243
251
|
*
|
|
244
252
|
* Accepts the same arguments as `cacheControl()`.
|
|
245
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
253
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cachecontrolheaders-helper
|
|
246
254
|
*/
|
|
247
255
|
/*#__NO_SIDE_EFFECTS__*/
|
|
248
256
|
export const cacheControlHeaders = (ttlCfg, eTag) => {
|
package/esm/next/http.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type InferErrorPageProps<SEP extends ShowErrorPageFn<any>> = Cleanup<Retu
|
|
|
25
25
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
26
26
|
* and optional friendly `message`.
|
|
27
27
|
*
|
|
28
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
28
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#makeerrorizeapphoc
|
|
29
29
|
*/
|
|
30
30
|
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage: FunctionComponent<EP>) => {
|
|
31
31
|
<P extends {
|
|
@@ -47,7 +47,7 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
|
|
|
47
47
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
48
48
|
* in a way that doesn't make TypeScript shout at you.
|
|
49
49
|
*
|
|
50
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
50
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#notmodified304-helper
|
|
51
51
|
*/
|
|
52
52
|
export declare const notModified304: (response: ServerResponse | NextContextLike) => {
|
|
53
53
|
readonly props: any;
|
package/esm/next/http.js
CHANGED
|
@@ -9,7 +9,7 @@ export * from '../http.js';
|
|
|
9
9
|
* Use this method inside a `getServerSideProps` method (or API route)
|
|
10
10
|
* to return an error page with proper HTTP status code and all the shit.
|
|
11
11
|
*
|
|
12
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
12
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#showerrorpage-helper
|
|
13
13
|
*/
|
|
14
14
|
/*#__NO_SIDE_EFFECTS__*/
|
|
15
15
|
const showErrorPage = (response, error, ttl = '2s') => {
|
|
@@ -34,7 +34,7 @@ const showErrorPage = (response, error, ttl = '2s') => {
|
|
|
34
34
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
35
35
|
* and optional friendly `message`.
|
|
36
36
|
*
|
|
37
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
37
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#makeerrorizeapphoc
|
|
38
38
|
*/
|
|
39
39
|
/*#__NO_SIDE_EFFECTS__*/
|
|
40
40
|
export const makeErrorizeAppHOC = (ErrorPage) => {
|
|
@@ -64,7 +64,7 @@ export const makeErrorizeAppHOC = (ErrorPage) => {
|
|
|
64
64
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
65
65
|
* in a way that doesn't make TypeScript shout at you.
|
|
66
66
|
*
|
|
67
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
67
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#notmodified304-helper
|
|
68
68
|
*/
|
|
69
69
|
/*#__NO_SIDE_EFFECTS__*/
|
|
70
70
|
export const notModified304 = (response) => {
|
|
@@ -31,7 +31,7 @@ export type WaitProps<T> = WaitPropsBase<T> & WaitFallbacks;
|
|
|
31
31
|
* custom properties for `meanwhile` and `error` fallbacks, and/or other
|
|
32
32
|
* behaviors.
|
|
33
33
|
*
|
|
34
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
34
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-rr.md#type-waitcomponent
|
|
35
35
|
*/
|
|
36
36
|
export type WaitComponent<CustomProps extends Record<string, unknown> = Record<never, never>> = (<T>(props: WaitPropsBase<T> & CustomProps) => ReactElement) & {
|
|
37
37
|
displayName?: string;
|
|
@@ -43,7 +43,7 @@ export type WaitComponent<CustomProps extends Record<string, unknown> = Record<n
|
|
|
43
43
|
* If the awaited promise (`props.for`) resolves to an object with a truthy
|
|
44
44
|
* `$error` property, the `$error` will be thrown.
|
|
45
45
|
*
|
|
46
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
46
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-rr.md#wait-component
|
|
47
47
|
*/
|
|
48
48
|
export declare const Wait: WaitComponent<WaitFallbacks>;
|
|
49
49
|
export {};
|
package/esm/react-router/Wait.js
CHANGED
|
@@ -7,7 +7,7 @@ import { Await } from 'react-router';
|
|
|
7
7
|
* If the awaited promise (`props.for`) resolves to an object with a truthy
|
|
8
8
|
* `$error` property, the `$error` will be thrown.
|
|
9
9
|
*
|
|
10
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
10
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-rr.md#wait-component
|
|
11
11
|
*/
|
|
12
12
|
export const Wait = (props) => (React.createElement(Suspense, { fallback: props.meanwhile || 'Loading...' },
|
|
13
13
|
React.createElement(Await, { resolve: props.for, errorElement: props.error || 'An error occurred.' }, (value) => {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Detects if the request is a client fetch, or an initial/full-page load.
|
|
3
3
|
* Useful for deciding whether to defer data fetching or not.
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-rr.md#isclientfetch
|
|
6
6
|
*/
|
|
7
7
|
export declare const isClientFetch: (request: Request) => boolean;
|
package/esm/react-router/http.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Detects if the request is a client fetch, or an initial/full-page load.
|
|
3
3
|
* Useful for deciding whether to defer data fetching or not.
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-rr.md#isclientfetch
|
|
6
6
|
*/
|
|
7
7
|
/*#__NO_SIDE_EFFECTS__*/
|
|
8
8
|
export const isClientFetch = (request) =>
|
package/esm/vanillaExtract.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { GlobalStyleRule } from '@vanilla-extract/css';
|
|
|
2
2
|
/**
|
|
3
3
|
* Adds free-form CSS as a globalStyle
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillaglobal
|
|
6
6
|
*/
|
|
7
7
|
export declare const vanillaGlobal: (css: string) => void;
|
|
8
8
|
/**
|
|
9
9
|
* Spreads the return value into a style object, to inject free-form CSS
|
|
10
10
|
* properties (or nested blocks)
|
|
11
11
|
*
|
|
12
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
12
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillaprops
|
|
13
13
|
*/
|
|
14
14
|
export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
15
15
|
type ClassNameCallback = (
|
|
@@ -27,7 +27,7 @@ classNameSelector: string) => string;
|
|
|
27
27
|
*
|
|
28
28
|
* To opt out of the `&&` replacement, use the callback function signature.
|
|
29
29
|
*
|
|
30
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
30
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillaclass
|
|
31
31
|
*/
|
|
32
32
|
export declare function vanillaClass(css: string | ClassNameCallback): string;
|
|
33
33
|
export declare function vanillaClass(debugId: string, css: string | ClassNameCallback): string;
|
|
@@ -35,7 +35,7 @@ export declare function vanillaClass(debugId: string, css: string | ClassNameCal
|
|
|
35
35
|
* Returns an object with privately scoped CSS variables props.
|
|
36
36
|
* Pass them around and use them in your CSS.
|
|
37
37
|
*
|
|
38
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
38
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillacvars
|
|
39
39
|
*/
|
|
40
40
|
export declare const vanillaVars: <T extends string>(...varNames: Array<T>) => Record<`var${Capitalize<T>}`, string> & {
|
|
41
41
|
/** Allows initializing all or some of the variables in CSS, without offending VSCode's CSS syntax parser too much. */
|
package/esm/vanillaExtract.js
CHANGED
|
@@ -3,7 +3,7 @@ import { globalStyle, style } from '@vanilla-extract/css';
|
|
|
3
3
|
/**
|
|
4
4
|
* Adds free-form CSS as a globalStyle
|
|
5
5
|
*
|
|
6
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
6
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillaglobal
|
|
7
7
|
*/
|
|
8
8
|
export const vanillaGlobal = (css) => globalStyle('x', { x: `} ${css} x{x:` });
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
@@ -11,7 +11,7 @@ export const vanillaGlobal = (css) => globalStyle('x', { x: `} ${css} x{x:` });
|
|
|
11
11
|
* Spreads the return value into a style object, to inject free-form CSS
|
|
12
12
|
* properties (or nested blocks)
|
|
13
13
|
*
|
|
14
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
14
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillaprops
|
|
15
15
|
*/
|
|
16
16
|
export const vanillaProps = (css) => ({ x: `; ${css}` });
|
|
17
17
|
export function vanillaClass(cssOrDebugId, css) {
|
|
@@ -31,7 +31,7 @@ export function vanillaClass(cssOrDebugId, css) {
|
|
|
31
31
|
* Returns an object with privately scoped CSS variables props.
|
|
32
32
|
* Pass them around and use them in your CSS.
|
|
33
33
|
*
|
|
34
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
34
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillacvars
|
|
35
35
|
*/
|
|
36
36
|
export const vanillaVars = (...varNames) => {
|
|
37
37
|
const id = vanillaClass(``);
|
package/hooks.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* **NOTE:** The supplied callback does not need to be memoized. The debouncer
|
|
7
7
|
* will always invoke the last supplied version.
|
|
8
8
|
*
|
|
9
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
9
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usedebounced
|
|
10
10
|
*/
|
|
11
11
|
export declare const useDebounced: <A extends Array<unknown>>(
|
|
12
12
|
/** The function to debounce */
|
|
@@ -23,7 +23,7 @@ immediate?: boolean) => ((...args: A) => void) & {
|
|
|
23
23
|
* **NOTE:** The supplied callback does not need to be memoized. The throttler
|
|
24
24
|
* will always invoke the last supplied version.
|
|
25
25
|
*
|
|
26
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
26
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usethrottled
|
|
27
27
|
*/
|
|
28
28
|
export declare const useThrottled: <A extends Array<unknown>>(
|
|
29
29
|
/** The function to throttle */
|
package/hooks.js
CHANGED
|
@@ -11,7 +11,7 @@ const async_js_1 = require("./async.js");
|
|
|
11
11
|
* **NOTE:** The supplied callback does not need to be memoized. The debouncer
|
|
12
12
|
* will always invoke the last supplied version.
|
|
13
13
|
*
|
|
14
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
14
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usedebounced
|
|
15
15
|
*/
|
|
16
16
|
const useDebounced = (
|
|
17
17
|
/** The function to debounce */
|
|
@@ -33,7 +33,7 @@ exports.useDebounced = useDebounced;
|
|
|
33
33
|
* **NOTE:** The supplied callback does not need to be memoized. The throttler
|
|
34
34
|
* will always invoke the last supplied version.
|
|
35
35
|
*
|
|
36
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
36
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usethrottled
|
|
37
37
|
*/
|
|
38
38
|
const useThrottled = (
|
|
39
39
|
/** The function to throttle */
|
package/http.d.ts
CHANGED
|
@@ -154,23 +154,23 @@ type TTLObj = {
|
|
|
154
154
|
/**
|
|
155
155
|
* Configures quick TTL-related settings for a HTTP request object
|
|
156
156
|
*
|
|
157
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
157
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-ttlconfig
|
|
158
158
|
*/
|
|
159
159
|
export type TTLConfig = TTL | TTLKeywords | TTLObj;
|
|
160
|
-
/**
|
|
161
|
-
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
162
|
-
* negative input values.
|
|
163
|
-
*
|
|
164
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#tosec-ttl-helper
|
|
165
|
-
*/
|
|
166
|
-
export declare const toSec: (ttl: TTL) => number;
|
|
167
160
|
/**
|
|
168
161
|
* Converts a `TTL` (duration) value into milliseconds. Returns `0` for bad
|
|
169
162
|
* and/or negative input values.
|
|
170
163
|
*
|
|
171
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
164
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#toms-duration-helper
|
|
172
165
|
*/
|
|
173
166
|
export declare const toMs: (ttl: TTL) => number;
|
|
167
|
+
/**
|
|
168
|
+
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
169
|
+
* negative input values.
|
|
170
|
+
*
|
|
171
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#tosec-ttl-helper
|
|
172
|
+
*/
|
|
173
|
+
export declare const toSec: (ttl: TTL) => number;
|
|
174
174
|
type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'removeHeader'> & {
|
|
175
175
|
headers?: Record<string, string | Array<string>>;
|
|
176
176
|
};
|
|
@@ -181,7 +181,7 @@ type ResponseStub = {
|
|
|
181
181
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
182
182
|
* on a HTTP response
|
|
183
183
|
*
|
|
184
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
184
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cachecontrol-helper
|
|
185
185
|
*/
|
|
186
186
|
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
|
|
187
187
|
res: ServerResponseStub | ResponseStub;
|
|
@@ -191,7 +191,7 @@ export declare const cacheControl: (response: ServerResponseStub | ResponseStub
|
|
|
191
191
|
* situations requiring a `HeadersInit` compatible object.
|
|
192
192
|
*
|
|
193
193
|
* Accepts the same arguments as `cacheControl()`.
|
|
194
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
194
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cachecontrolheaders-helper
|
|
195
195
|
*/
|
|
196
196
|
export declare const cacheControlHeaders: (ttlCfg: TTLConfig, eTag?: string | number) => Record<string, string>;
|
|
197
197
|
export {};
|
package/http.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HTTP_502_BadGateway = exports.HTTP_501_NotImplemented = exports.HTTP_500_InternalServerError = exports.HTTP_451_UnavailableForLegalReasons = exports.HTTP_431_RequestHeaderFieldsTooLarge = exports.HTTP_429_TooManyRequests = exports.HTTP_428_PreconditionRequired = exports.HTTP_426_UpgradeRequired = exports.HTTP_424_FailedDependency = exports.HTTP_423_Locked = exports.HTTP_422_UnprocessableContent = exports.HTTP_421_MisdirectedRequest = exports.HTTP_418_ImATeapot = exports.HTTP_417_ExpectationFailed = exports.HTTP_416_RangeNotSatisfiable = exports.HTTP_415_UnsupportedMediaType = exports.HTTP_414_URITooLong = exports.HTTP_413_PayloadTooLarge = exports.HTTP_412_PreconditionFailed = exports.HTTP_411_LengthRequired = exports.HTTP_410_Gone = exports.HTTP_409_Conflict = exports.HTTP_408_RequestTimeout = exports.HTTP_407_ProxyAuthenticationRequired = exports.HTTP_406_NotAcceptable = exports.HTTP_405_MethodNotAllowed = exports.HTTP_404_NotFound = exports.HTTP_403_Forbidden = exports.HTTP_401_Unauthorized = exports.HTTP_400_BadRequest = exports.HTTP_308_PermanentRedirect = exports.HTTP_307_TemporaryRedirect = exports.HTTP_304_NotModified = exports.HTTP_303_SeeOther = exports.HTTP_302_Found = exports.HTTP_301_MovedPermanently = exports.HTTP_226_IMUsed = exports.HTTP_208_AlreadyReported = exports.HTTP_207_MultiStatus = exports.HTTP_206_PartialContent = exports.HTTP_205_ResetContent = exports.HTTP_204_NoContent = exports.HTTP_203_NonAuthoritativeInformation = exports.HTTP_202_Accepted = exports.HTTP_201_Created = exports.HTTP_200_OK = exports.HTTP_103_EarlyHints = exports.HTTP_102_Processing = exports.HTTP_101_SwitchingProtocols = exports.HTTP_100_Continue = void 0;
|
|
4
|
-
exports.cacheControlHeaders = exports.cacheControl = exports.
|
|
4
|
+
exports.cacheControlHeaders = exports.cacheControl = exports.toSec = exports.toMs = exports.HTTP_511_NetworkAuthenticationRequired = exports.HTTP_510_NotExtended = exports.HTTP_508_LoopDetected = exports.HTTP_507_InsufficientStorage = exports.HTTP_506_VariantAlsoNegotiates = exports.HTTP_505_HTTPVersionNotSupported = exports.HTTP_504_GatewayTimeout = exports.HTTP_503_ServiceUnavailable = void 0;
|
|
5
5
|
// INFORMATION
|
|
6
6
|
/** The client should continue the request or ignore the response if the request is already finished. */
|
|
7
7
|
exports.HTTP_100_Continue = 100;
|
|
@@ -129,38 +129,46 @@ exports.HTTP_508_LoopDetected = 508;
|
|
|
129
129
|
exports.HTTP_510_NotExtended = 510;
|
|
130
130
|
/** The client needs to authenticate to gain network access. */
|
|
131
131
|
exports.HTTP_511_NetworkAuthenticationRequired = 511;
|
|
132
|
-
const
|
|
133
|
-
s:
|
|
134
|
-
m:
|
|
135
|
-
h:
|
|
136
|
-
d: 24 *
|
|
137
|
-
w: 7 * 24 *
|
|
132
|
+
const unitToMilliseconds = {
|
|
133
|
+
s: 1000,
|
|
134
|
+
m: 60000,
|
|
135
|
+
h: 60 * 60000,
|
|
136
|
+
d: 24 * 60 * 60000,
|
|
137
|
+
w: 7 * 24 * 60 * 60000,
|
|
138
138
|
};
|
|
139
139
|
/**
|
|
140
|
-
* Converts a `TTL` (
|
|
141
|
-
* negative input values.
|
|
140
|
+
* Converts a `TTL` (duration) value into milliseconds. Returns `0` for bad
|
|
141
|
+
* and/or negative input values.
|
|
142
142
|
*
|
|
143
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
143
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#toms-duration-helper
|
|
144
144
|
*/
|
|
145
145
|
/*#__NO_SIDE_EFFECTS__*/
|
|
146
|
-
const
|
|
146
|
+
const toMs = (ttl) => {
|
|
147
|
+
if (!ttl) {
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
147
150
|
if (typeof ttl === 'string') {
|
|
148
151
|
const value = parseFloat(ttl);
|
|
149
|
-
const factor =
|
|
152
|
+
const factor = unitToMilliseconds[ttl.slice(-1)] || 1;
|
|
150
153
|
ttl = value * factor;
|
|
151
154
|
}
|
|
152
155
|
return Math.max(0, Math.round(ttl)) || 0;
|
|
153
156
|
};
|
|
154
|
-
exports.
|
|
157
|
+
exports.toMs = toMs;
|
|
155
158
|
/**
|
|
156
|
-
* Converts a `TTL` (
|
|
157
|
-
*
|
|
159
|
+
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
160
|
+
* negative input values.
|
|
158
161
|
*
|
|
159
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
162
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#tosec-ttl-helper
|
|
160
163
|
*/
|
|
161
164
|
/*#__NO_SIDE_EFFECTS__*/
|
|
162
|
-
const
|
|
163
|
-
|
|
165
|
+
const toSec = (ttl) => {
|
|
166
|
+
if (typeof ttl === 'number') {
|
|
167
|
+
ttl = ttl * 1000;
|
|
168
|
+
}
|
|
169
|
+
return Math.round((0, exports.toMs)(ttl) / 1000);
|
|
170
|
+
};
|
|
171
|
+
exports.toSec = toSec;
|
|
164
172
|
/*#__NO_SIDE_EFFECTS__*/
|
|
165
173
|
const toRespnseStubHeaders = (response) => {
|
|
166
174
|
if (response instanceof Map) {
|
|
@@ -205,7 +213,7 @@ const setCC = (response, cc) => {
|
|
|
205
213
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
206
214
|
* on a HTTP response
|
|
207
215
|
*
|
|
208
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
216
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cachecontrol-helper
|
|
209
217
|
*/
|
|
210
218
|
/*#__NO_SIDE_EFFECTS__*/ // eslint-disable-next-line complexity
|
|
211
219
|
const cacheControl = (response, ttlCfg, eTag) => {
|
|
@@ -216,7 +224,7 @@ const cacheControl = (response, ttlCfg, eTag) => {
|
|
|
216
224
|
let maxAge = opts.maxAge;
|
|
217
225
|
if (typeof maxAge === 'string') {
|
|
218
226
|
if (maxAge === 'permanent') {
|
|
219
|
-
maxAge = 365 *
|
|
227
|
+
maxAge = 365 * unitToMilliseconds.d;
|
|
220
228
|
}
|
|
221
229
|
else if (maxAge === 'no-cache') {
|
|
222
230
|
maxAge = 0;
|
|
@@ -249,7 +257,7 @@ exports.cacheControl = cacheControl;
|
|
|
249
257
|
* situations requiring a `HeadersInit` compatible object.
|
|
250
258
|
*
|
|
251
259
|
* Accepts the same arguments as `cacheControl()`.
|
|
252
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
260
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cachecontrolheaders-helper
|
|
253
261
|
*/
|
|
254
262
|
/*#__NO_SIDE_EFFECTS__*/
|
|
255
263
|
const cacheControlHeaders = (ttlCfg, eTag) => {
|
package/next/http.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type InferErrorPageProps<SEP extends ShowErrorPageFn<any>> = Cleanup<Retu
|
|
|
25
25
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
26
26
|
* and optional friendly `message`.
|
|
27
27
|
*
|
|
28
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
28
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#makeerrorizeapphoc
|
|
29
29
|
*/
|
|
30
30
|
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage: FunctionComponent<EP>) => {
|
|
31
31
|
<P extends {
|
|
@@ -47,7 +47,7 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
|
|
|
47
47
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
48
48
|
* in a way that doesn't make TypeScript shout at you.
|
|
49
49
|
*
|
|
50
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
50
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#notmodified304-helper
|
|
51
51
|
*/
|
|
52
52
|
export declare const notModified304: (response: ServerResponse | NextContextLike) => {
|
|
53
53
|
readonly props: any;
|
package/next/http.js
CHANGED
|
@@ -29,7 +29,7 @@ __exportStar(require("../http.js"), exports);
|
|
|
29
29
|
* Use this method inside a `getServerSideProps` method (or API route)
|
|
30
30
|
* to return an error page with proper HTTP status code and all the shit.
|
|
31
31
|
*
|
|
32
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
32
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#showerrorpage-helper
|
|
33
33
|
*/
|
|
34
34
|
/*#__NO_SIDE_EFFECTS__*/
|
|
35
35
|
const showErrorPage = (response, error, ttl = '2s') => {
|
|
@@ -54,7 +54,7 @@ const showErrorPage = (response, error, ttl = '2s') => {
|
|
|
54
54
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
55
55
|
* and optional friendly `message`.
|
|
56
56
|
*
|
|
57
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
57
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#makeerrorizeapphoc
|
|
58
58
|
*/
|
|
59
59
|
/*#__NO_SIDE_EFFECTS__*/
|
|
60
60
|
const makeErrorizeAppHOC = (ErrorPage) => {
|
|
@@ -85,7 +85,7 @@ exports.makeErrorizeAppHOC = makeErrorizeAppHOC;
|
|
|
85
85
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
86
86
|
* in a way that doesn't make TypeScript shout at you.
|
|
87
87
|
*
|
|
88
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
88
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README-nextjs.md#notmodified304-helper
|
|
89
89
|
*/
|
|
90
90
|
/*#__NO_SIDE_EFFECTS__*/
|
|
91
91
|
const notModified304 = (response) => {
|
package/package.json
CHANGED