@naturalcycles/js-lib 15.83.0 → 15.84.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/dist/datetime/localTime.js +44 -14
- package/dist/decorators/asyncMemo.decorator.d.ts +2 -1
- package/dist/decorators/debounce.d.ts +73 -3
- package/dist/decorators/debounce.decorator.d.ts +23 -3
- package/dist/decorators/debounce.decorator.js +31 -1
- package/dist/decorators/debounce.js +197 -41
- package/dist/decorators/decorator.util.d.ts +6 -0
- package/dist/decorators/memo.decorator.d.ts +2 -1
- package/dist/decorators/memo.util.d.ts +1 -7
- package/dist/promise/pGradualQueue.js +1 -0
- package/dist/promise/pQueue.js +1 -0
- package/dist/promise/pTimeout.js +1 -0
- package/package.json +1 -3
- package/src/datetime/localTime.ts +49 -14
- package/src/decorators/asyncMemo.decorator.ts +2 -1
- package/src/decorators/debounce.decorator.ts +59 -8
- package/src/decorators/debounce.ts +354 -95
- package/src/decorators/decorator.util.ts +11 -0
- package/src/decorators/memo.decorator.ts +2 -1
- package/src/decorators/memo.util.ts +1 -12
- package/src/promise/pGradualQueue.ts +2 -1
- package/src/promise/pQueue.ts +2 -1
- package/src/promise/pTimeout.ts +2 -1
- package/src/typeFest.ts +6 -6
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { AnyObject, InstanceId } from '../types.js'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Generic override of TypeScript's built-in legacy MethodDecorator, that
|
|
5
|
+
* allows us to infer the parameters of the decorated method from the parameters
|
|
6
|
+
* of a decorator.
|
|
7
|
+
*/
|
|
8
|
+
export type MethodDecorator<T> = (
|
|
9
|
+
target: AnyObject,
|
|
10
|
+
propertyKey: string | symbol,
|
|
11
|
+
descriptor: TypedPropertyDescriptor<T>,
|
|
12
|
+
) => TypedPropertyDescriptor<T> | undefined
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* @returns
|
|
5
16
|
* e.g `NameOfYourClass.methodName`
|
|
@@ -2,8 +2,9 @@ import { _assert, _assertTypeOf } from '../error/assert.js'
|
|
|
2
2
|
import type { CommonLogger } from '../log/commonLogger.js'
|
|
3
3
|
import type { AnyFunction, AnyObject, MaybeParameters } from '../types.js'
|
|
4
4
|
import { _objectAssign } from '../types.js'
|
|
5
|
+
import type { MethodDecorator } from './decorator.util.js'
|
|
5
6
|
import { _getTargetMethodSignature } from './decorator.util.js'
|
|
6
|
-
import type { MemoCache
|
|
7
|
+
import type { MemoCache } from './memo.util.js'
|
|
7
8
|
import { jsonMemoSerializer, MapMemoCache } from './memo.util.js'
|
|
8
9
|
|
|
9
10
|
export interface MemoOptions<FN> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _isPrimitive } from '../is.util.js'
|
|
2
2
|
import { pDelay } from '../promise/pDelay.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type { UnixTimestamp } from '../types.js'
|
|
4
4
|
import { MISS } from '../types.js'
|
|
5
5
|
|
|
6
6
|
export type MemoSerializer = (args: any[]) => any
|
|
@@ -147,14 +147,3 @@ export class MapAsyncMemoCache<KEY = any, VALUE = any> implements AsyncMemoCache
|
|
|
147
147
|
this.m.clear()
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Generic override of Typescript's built in legacy MethodDecorator, that
|
|
153
|
-
* allows us to infer the parameters of the decorated method from the parameters
|
|
154
|
-
* of a decorator.
|
|
155
|
-
*/
|
|
156
|
-
export type MethodDecorator<T> = (
|
|
157
|
-
target: AnyObject,
|
|
158
|
-
propertyKey: string | symbol,
|
|
159
|
-
descriptor: TypedPropertyDescriptor<T>,
|
|
160
|
-
) => TypedPropertyDescriptor<T> | undefined
|
|
@@ -159,7 +159,8 @@ function runSafe<R>(fn: AsyncFunction<R>): Promise<R> {
|
|
|
159
159
|
return fn()
|
|
160
160
|
} catch (err) {
|
|
161
161
|
// Handle synchronous throws
|
|
162
|
-
|
|
162
|
+
// oxlint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
163
|
+
return Promise.reject(err)
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
|
package/src/promise/pQueue.ts
CHANGED
|
@@ -150,7 +150,8 @@ function runSafe<R>(fn: AsyncFunction<R>): Promise<R> {
|
|
|
150
150
|
return fn()
|
|
151
151
|
} catch (err) {
|
|
152
152
|
// Handle synchronous throws - ensure inFlight is decremented
|
|
153
|
-
|
|
153
|
+
// oxlint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
154
|
+
return Promise.reject(err)
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
|
package/src/promise/pTimeout.ts
CHANGED
|
@@ -108,7 +108,8 @@ export async function pTimeout<T>(
|
|
|
108
108
|
try {
|
|
109
109
|
resolve(await fn(signal))
|
|
110
110
|
} catch (err) {
|
|
111
|
-
|
|
111
|
+
// oxlint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
112
|
+
reject(err)
|
|
112
113
|
} finally {
|
|
113
114
|
clearTimeout(timer)
|
|
114
115
|
}
|
package/src/typeFest.ts
CHANGED
|
@@ -57,9 +57,9 @@ export type Except<ObjectType, KeysType extends keyof ObjectType> = {
|
|
|
57
57
|
* When you use a type that will iterate through an object that has indexed keys and explicitly defined keys you end up with a type where only the indexed keys are kept. This is because `keyof` of an indexed type always returns `string | number | symbol`, because every key is possible in that object. With this type, you can save the indexed keys and reinject them later, like in the second example below.
|
|
58
58
|
*/
|
|
59
59
|
export type PickIndexSignature<ObjectType> = {
|
|
60
|
-
[
|
|
61
|
-
? KeyType
|
|
62
|
-
|
|
60
|
+
[
|
|
61
|
+
KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never
|
|
62
|
+
]: ObjectType[KeyType]
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
@@ -73,9 +73,9 @@ export type PickIndexSignature<ObjectType> = {
|
|
|
73
73
|
* (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
74
74
|
*/
|
|
75
75
|
export type OmitIndexSignature<ObjectType> = {
|
|
76
|
-
[
|
|
77
|
-
? never
|
|
78
|
-
|
|
76
|
+
[
|
|
77
|
+
KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType
|
|
78
|
+
]: ObjectType[KeyType]
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|