@augment-vir/common 31.68.0 → 31.68.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.
@@ -1,11 +1,9 @@
1
- import { type JsonCompatibleValue, type PartialWithUndefined } from '@augment-vir/core';
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, { enableUnsafeCopyAll, }?: Readonly<PartialWithUndefined<{
38
- enableUnsafeCopyAll: boolean;
39
- }>> | undefined): IsUnknown<T> extends true ? JsonCompatibleValue : Writable<Jsonify<T>>;
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, { enableUnsafeCopyAll, } = {}) {
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
- const stringified = enableUnsafeCopyAll ? JSON.stringify(input) : safeJsonStringify(input);
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`, input);
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.0",
3
+ "version": "31.68.1",
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.0",
44
- "@augment-vir/core": "^31.68.0",
43
+ "@augment-vir/assert": "^31.68.1",
44
+ "@augment-vir/core": "^31.68.1",
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.2.0"
50
+ "typed-event-target": "^4.3.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@web/dev-server-esbuild": "^1.0.5",