@augment-vir/common 31.68.0 → 31.68.2
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type NoInputsFunction
|
|
1
|
+
import { type NoInputsFunction } from '@augment-vir/core';
|
|
2
|
+
import { type RequireOneOrNone } from 'type-fest';
|
|
2
3
|
/**
|
|
3
4
|
* Options for {@link wrapInTry}.
|
|
4
5
|
*
|
|
@@ -6,7 +7,7 @@ import { type NoInputsFunction, type PartialWithUndefined } from '@augment-vir/c
|
|
|
6
7
|
* @category Package : @augment-vir/common
|
|
7
8
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
9
|
*/
|
|
9
|
-
export type WrapInTryOptions<FallbackValue> =
|
|
10
|
+
export type WrapInTryOptions<FallbackValue> = RequireOneOrNone<{
|
|
10
11
|
/**
|
|
11
12
|
* Call this function if the callback passed to {@link wrapInTry} throws an error. The thrown
|
|
12
13
|
* error is passed to this function. If a `fallbackValue` option is also provided, it will be
|
|
@@ -29,18 +30,18 @@ export declare function wrapInTry<Value>(callback: NoInputsFunction<Value>, opti
|
|
|
29
30
|
}): Error | Value;
|
|
30
31
|
export declare function wrapInTry<Value extends Promise<any>, FallbackValue = undefined>(callback: NoInputsFunction<Value>, options: {
|
|
31
32
|
handleError: (error: unknown) => FallbackValue;
|
|
32
|
-
fallbackValue?:
|
|
33
|
+
fallbackValue?: never;
|
|
33
34
|
}): Promise<Awaited<FallbackValue> | Awaited<Value>>;
|
|
34
35
|
export declare function wrapInTry<Value, FallbackValue = undefined>(callback: NoInputsFunction<Value>, options: {
|
|
35
36
|
handleError: (error: unknown) => FallbackValue;
|
|
36
|
-
fallbackValue?:
|
|
37
|
+
fallbackValue?: never;
|
|
37
38
|
}): FallbackValue | Value;
|
|
38
39
|
export declare function wrapInTry<Value extends Promise<any>, FallbackValue = undefined>(callback: NoInputsFunction<Value>, options: {
|
|
39
|
-
handleError?:
|
|
40
|
+
handleError?: never;
|
|
40
41
|
fallbackValue: FallbackValue;
|
|
41
42
|
}): Promise<Awaited<FallbackValue> | Awaited<Value>>;
|
|
42
43
|
export declare function wrapInTry<Value, FallbackValue = undefined>(callback: NoInputsFunction<Value>, options: {
|
|
43
|
-
handleError?:
|
|
44
|
+
handleError?: never;
|
|
44
45
|
fallbackValue: FallbackValue;
|
|
45
46
|
}): FallbackValue | Value;
|
|
46
47
|
export declare function wrapInTry<Value extends Promise<any>, FallbackValue = undefined>(callback: NoInputsFunction<Value>, options?: WrapInTryOptions<FallbackValue> | undefined): Promise<FallbackValue | Value | Error>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
|
-
import { ensureError
|
|
2
|
+
import { ensureError } from '@augment-vir/core';
|
|
3
3
|
/**
|
|
4
4
|
* Calls the callback and returns its output. If the callback throws an error, it is handled in the
|
|
5
5
|
* following ways:
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { type JsonCompatibleValue
|
|
1
|
+
import { type JsonCompatibleValue } from '@augment-vir/core';
|
|
2
2
|
import { type IsUnknown, type Jsonify, type Writable } from 'type-fest';
|
|
3
3
|
/**
|
|
4
4
|
* Deeply copy an object through JSON. This is the fastest deep copy, but the input must already be
|
|
5
5
|
* JSON serializable otherwise the copy will not match the original.
|
|
6
6
|
*
|
|
7
|
-
* Note that this will truncate inputs if they are not safe to serialize.
|
|
8
|
-
*
|
|
9
7
|
* @category JSON : Common
|
|
10
8
|
* @category Copy
|
|
11
9
|
* @category Package : @augment-vir/common
|
|
@@ -34,6 +32,13 @@ import { type IsUnknown, type Jsonify, type Writable } from 'type-fest';
|
|
|
34
32
|
*
|
|
35
33
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
36
34
|
*/
|
|
37
|
-
export declare function copyThroughJson<const T>(input: T
|
|
38
|
-
|
|
39
|
-
}
|
|
35
|
+
export declare function copyThroughJson<const T>(input: T): IsUnknown<T> extends true ? JsonCompatibleValue : Writable<Jsonify<T>>;
|
|
36
|
+
/**
|
|
37
|
+
* Same as {@link copyThroughJson} but this uses safe serialization from {@link safeJsonStringify}.
|
|
38
|
+
*
|
|
39
|
+
* @category JSON : Common
|
|
40
|
+
* @category Copy
|
|
41
|
+
* @category Package : @augment-vir/common
|
|
42
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
43
|
+
*/
|
|
44
|
+
export declare function safeCopyThroughJson<const T>(input: T): IsUnknown<T> extends true ? JsonCompatibleValue : Writable<Jsonify<T>>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { ensureErrorAndPrependMessage } from '@augment-vir/core';
|
|
1
2
|
import { safeJsonStringify } from './safe-json-stringify.js';
|
|
2
3
|
/**
|
|
3
4
|
* Deeply copy an object through JSON. This is the fastest deep copy, but the input must already be
|
|
4
5
|
* JSON serializable otherwise the copy will not match the original.
|
|
5
6
|
*
|
|
6
|
-
* Note that this will truncate inputs if they are not safe to serialize.
|
|
7
|
-
*
|
|
8
7
|
* @category JSON : Common
|
|
9
8
|
* @category Copy
|
|
10
9
|
* @category Package : @augment-vir/common
|
|
@@ -33,14 +32,31 @@ import { safeJsonStringify } from './safe-json-stringify.js';
|
|
|
33
32
|
*
|
|
34
33
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
35
34
|
*/
|
|
36
|
-
export function copyThroughJson(input
|
|
35
|
+
export function copyThroughJson(input) {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(JSON.stringify(input));
|
|
38
|
+
/* node:coverage ignore next 4 */
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(`Failed to JSON copy for:`, input);
|
|
42
|
+
throw ensureErrorAndPrependMessage(error, 'Failed JSON copy');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Same as {@link copyThroughJson} but this uses safe serialization from {@link safeJsonStringify}.
|
|
47
|
+
*
|
|
48
|
+
* @category JSON : Common
|
|
49
|
+
* @category Copy
|
|
50
|
+
* @category Package : @augment-vir/common
|
|
51
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
52
|
+
*/
|
|
53
|
+
export function safeCopyThroughJson(input) {
|
|
37
54
|
try {
|
|
38
|
-
|
|
39
|
-
return JSON.parse(stringified);
|
|
55
|
+
return JSON.parse(safeJsonStringify(input));
|
|
40
56
|
/* node:coverage ignore next 4 */
|
|
41
57
|
}
|
|
42
58
|
catch (error) {
|
|
43
|
-
console.error(`Failed to JSON copy for
|
|
44
|
-
throw error;
|
|
59
|
+
console.error(`Failed to JSON copy for:`, input);
|
|
60
|
+
throw ensureErrorAndPrependMessage(error, 'Failed JSON copy');
|
|
45
61
|
}
|
|
46
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.68.
|
|
3
|
+
"version": "31.68.2",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.68.
|
|
44
|
-
"@augment-vir/core": "^31.68.
|
|
43
|
+
"@augment-vir/assert": "^31.68.2",
|
|
44
|
+
"@augment-vir/core": "^31.68.2",
|
|
45
45
|
"@date-vir/duration": "^8.2.0",
|
|
46
46
|
"ansi-styles": "^6.2.3",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|
|
48
48
|
"json5": "^2.2.3",
|
|
49
49
|
"type-fest": "^5.4.4",
|
|
50
|
-
"typed-event-target": "^4.
|
|
50
|
+
"typed-event-target": "^4.3.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@web/dev-server-esbuild": "^1.0.5",
|