@naturalcycles/js-lib 15.73.1 → 15.74.0
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/dist/datetime/localTime.js +1 -0
- package/dist/decorators/memoFnAsync.js +2 -2
- package/dist/error/error.util.js +1 -0
- package/dist/http/fetcher.js +3 -1
- package/dist/http/fetcher.model.d.ts +7 -0
- package/dist/string/stringify.js +1 -0
- package/package.json +1 -1
- package/src/datetime/localTime.ts +1 -0
- package/src/datetime/wallTime.ts +1 -0
- package/src/decorators/memoFnAsync.ts +2 -6
- package/src/error/error.util.ts +1 -0
- package/src/http/fetcher.model.ts +8 -0
- package/src/http/fetcher.ts +3 -1
- package/src/string/stringify.ts +1 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _assert } from '../error/assert.js';
|
|
2
2
|
import { localDate } from './localDate.js';
|
|
3
3
|
import { _ms } from './time.util.js';
|
|
4
|
+
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
4
5
|
import { WallTime } from './wallTime.js';
|
|
5
6
|
export var ISODayOfWeek;
|
|
6
7
|
(function (ISODayOfWeek) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MISS } from '../types.js';
|
|
2
|
-
import { jsonMemoSerializer
|
|
2
|
+
import { jsonMemoSerializer } from './memo.util.js';
|
|
3
3
|
/**
|
|
4
4
|
* @experimental
|
|
5
5
|
*/
|
|
6
6
|
export function _memoFnAsync(fn, opt) {
|
|
7
|
-
const { logger = console, cacheFactory
|
|
7
|
+
const { logger = console, cacheFactory, cacheKeyFn = jsonMemoSerializer } = opt;
|
|
8
8
|
const cache = cacheFactory();
|
|
9
9
|
const memoizedFn = async function (...args) {
|
|
10
10
|
const ctx = this;
|
package/dist/error/error.util.js
CHANGED
|
@@ -2,6 +2,7 @@ import { isServerSide } from '../env.js';
|
|
|
2
2
|
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
3
3
|
import { _jsonParseIfPossible } from '../string/json.util.js';
|
|
4
4
|
import { _truncate, _truncateMiddle } from '../string/string.util.js';
|
|
5
|
+
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
5
6
|
import { _stringify } from '../string/stringify.js';
|
|
6
7
|
/**
|
|
7
8
|
* Useful to ensure that error in `catch (err) { ... }`
|
package/dist/http/fetcher.js
CHANGED
|
@@ -610,11 +610,12 @@ export class Fetcher {
|
|
|
610
610
|
credentials: cfg.credentials,
|
|
611
611
|
redirect: cfg.redirect,
|
|
612
612
|
dispatcher: cfg.dispatcher,
|
|
613
|
+
keepalive: cfg.keepalive,
|
|
613
614
|
},
|
|
614
615
|
hooks: {},
|
|
615
616
|
throwHttpErrors: true,
|
|
616
617
|
errorData: {},
|
|
617
|
-
}, _omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger', 'name']));
|
|
618
|
+
}, _omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger', 'name', 'keepalive']));
|
|
618
619
|
norm.init.headers = _mapKeys(norm.init.headers, k => k.toLowerCase());
|
|
619
620
|
return norm;
|
|
620
621
|
}
|
|
@@ -663,6 +664,7 @@ export class Fetcher {
|
|
|
663
664
|
method: opt.method || this.cfg.init.method,
|
|
664
665
|
credentials: opt.credentials || this.cfg.init.credentials,
|
|
665
666
|
redirect: opt.redirect || this.cfg.init.redirect || 'follow',
|
|
667
|
+
keepalive: opt.keepalive ?? this.cfg.init.keepalive,
|
|
666
668
|
}, {
|
|
667
669
|
headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
|
|
668
670
|
}),
|
|
@@ -205,6 +205,12 @@ export interface FetcherOptions {
|
|
|
205
205
|
* 'manual' will not throw, but return !ok response with 3xx status.
|
|
206
206
|
*/
|
|
207
207
|
redirect?: RequestRedirect;
|
|
208
|
+
/**
|
|
209
|
+
* Default to false.
|
|
210
|
+
* When set to true, the request will not be aborted when the page is unloaded.
|
|
211
|
+
* Useful for sending analytics or tracking events that need to complete even if the user navigates away.
|
|
212
|
+
*/
|
|
213
|
+
keepalive?: boolean;
|
|
208
214
|
headers?: Record<string, any>;
|
|
209
215
|
responseType?: FetcherResponseType;
|
|
210
216
|
searchParams?: Record<string, any>;
|
|
@@ -287,6 +293,7 @@ export type RequestInitNormalized = Omit<RequestInit, 'method' | 'headers'> & {
|
|
|
287
293
|
method: HttpMethod;
|
|
288
294
|
headers: Record<string, any>;
|
|
289
295
|
dispatcher?: Dispatcher;
|
|
296
|
+
keepalive?: boolean;
|
|
290
297
|
};
|
|
291
298
|
export interface FetcherSuccessResponse<BODY = unknown> {
|
|
292
299
|
ok: true;
|
package/dist/string/stringify.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
2
2
|
import { _isBackendErrorResponseObject, _isErrorLike, _isErrorObject } from '../error/error.util.js';
|
|
3
|
+
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
3
4
|
import { _jsonParseIfPossible } from './json.util.js';
|
|
4
5
|
import { _safeJsonStringify } from './safeJsonStringify.js';
|
|
5
6
|
import { _truncateMiddle } from './string.util.js';
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
import type { LocalDate } from './localDate.js'
|
|
17
17
|
import { localDate } from './localDate.js'
|
|
18
18
|
import { _ms } from './time.util.js'
|
|
19
|
+
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
19
20
|
import { WallTime } from './wallTime.js'
|
|
20
21
|
|
|
21
22
|
export type LocalTimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second'
|
package/src/datetime/wallTime.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IsoDate, IsoDateTime } from '../types.js'
|
|
2
2
|
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
3
3
|
import { LocalDate } from './localDate.js'
|
|
4
|
+
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
4
5
|
import type { DateTimeObject, LocalTime } from './localTime.js'
|
|
5
6
|
import { localTime } from './localTime.js'
|
|
6
7
|
|
|
@@ -2,7 +2,7 @@ import type { AnyAsyncFunction, MaybeParameters } from '../types.js'
|
|
|
2
2
|
import { MISS } from '../types.js'
|
|
3
3
|
import type { AsyncMemoOptions } from './asyncMemo.decorator.js'
|
|
4
4
|
import type { AsyncMemoCache } from './memo.util.js'
|
|
5
|
-
import { jsonMemoSerializer
|
|
5
|
+
import { jsonMemoSerializer } from './memo.util.js'
|
|
6
6
|
|
|
7
7
|
export interface MemoizedAsyncFunction {
|
|
8
8
|
cache: AsyncMemoCache
|
|
@@ -15,11 +15,7 @@ export function _memoFnAsync<FN extends AnyAsyncFunction>(
|
|
|
15
15
|
fn: FN,
|
|
16
16
|
opt: AsyncMemoOptions<FN>,
|
|
17
17
|
): FN & MemoizedAsyncFunction {
|
|
18
|
-
const {
|
|
19
|
-
logger = console,
|
|
20
|
-
cacheFactory = () => new MapMemoCache(),
|
|
21
|
-
cacheKeyFn = jsonMemoSerializer,
|
|
22
|
-
} = opt
|
|
18
|
+
const { logger = console, cacheFactory, cacheKeyFn = jsonMemoSerializer } = opt
|
|
23
19
|
|
|
24
20
|
const cache = cacheFactory()
|
|
25
21
|
|
package/src/error/error.util.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { isServerSide } from '../env.js'
|
|
|
2
2
|
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
3
3
|
import { _jsonParseIfPossible } from '../string/json.util.js'
|
|
4
4
|
import { _truncate, _truncateMiddle } from '../string/string.util.js'
|
|
5
|
+
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
5
6
|
import { _stringify } from '../string/stringify.js'
|
|
6
7
|
import type { Class } from '../types.js'
|
|
7
8
|
import type {
|
|
@@ -263,6 +263,13 @@ export interface FetcherOptions {
|
|
|
263
263
|
*/
|
|
264
264
|
redirect?: RequestRedirect
|
|
265
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Default to false.
|
|
268
|
+
* When set to true, the request will not be aborted when the page is unloaded.
|
|
269
|
+
* Useful for sending analytics or tracking events that need to complete even if the user navigates away.
|
|
270
|
+
*/
|
|
271
|
+
keepalive?: boolean
|
|
272
|
+
|
|
266
273
|
// Removing RequestInit from options to simplify FetcherOptions interface.
|
|
267
274
|
// Will instead only add hand-picked useful options, such as `credentials`.
|
|
268
275
|
// init?: Partial<RequestInitNormalized>
|
|
@@ -361,6 +368,7 @@ export type RequestInitNormalized = Omit<RequestInit, 'method' | 'headers'> & {
|
|
|
361
368
|
method: HttpMethod
|
|
362
369
|
headers: Record<string, any>
|
|
363
370
|
dispatcher?: Dispatcher
|
|
371
|
+
keepalive?: boolean
|
|
364
372
|
}
|
|
365
373
|
|
|
366
374
|
export interface FetcherSuccessResponse<BODY = unknown> {
|
package/src/http/fetcher.ts
CHANGED
|
@@ -744,12 +744,13 @@ export class Fetcher {
|
|
|
744
744
|
credentials: cfg.credentials,
|
|
745
745
|
redirect: cfg.redirect,
|
|
746
746
|
dispatcher: cfg.dispatcher,
|
|
747
|
+
keepalive: cfg.keepalive,
|
|
747
748
|
},
|
|
748
749
|
hooks: {},
|
|
749
750
|
throwHttpErrors: true,
|
|
750
751
|
errorData: {},
|
|
751
752
|
},
|
|
752
|
-
_omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger', 'name']),
|
|
753
|
+
_omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger', 'name', 'keepalive']),
|
|
753
754
|
)
|
|
754
755
|
|
|
755
756
|
norm.init.headers = _mapKeys(norm.init.headers, k => k.toLowerCase())
|
|
@@ -804,6 +805,7 @@ export class Fetcher {
|
|
|
804
805
|
method: opt.method || this.cfg.init.method,
|
|
805
806
|
credentials: opt.credentials || this.cfg.init.credentials,
|
|
806
807
|
redirect: opt.redirect || this.cfg.init.redirect || 'follow',
|
|
808
|
+
keepalive: opt.keepalive ?? this.cfg.init.keepalive,
|
|
807
809
|
},
|
|
808
810
|
{
|
|
809
811
|
headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
|
package/src/string/stringify.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { _isBackendErrorResponseObject, _isErrorLike, _isErrorObject } from '../error/error.util.js'
|
|
3
3
|
import type { ErrorLike } from '../error/index.js'
|
|
4
4
|
import type { Reviver } from '../types.js'
|
|
5
|
+
// oxlint-disable-next-line import/no-cycle -- intentional cycle
|
|
5
6
|
import { _jsonParseIfPossible } from './json.util.js'
|
|
6
7
|
import { _safeJsonStringify } from './safeJsonStringify.js'
|
|
7
8
|
import { _truncateMiddle } from './string.util.js'
|