serverless-spy 0.0.61 → 0.0.62
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/.jsii +3 -2
- package/_config.yml +14 -3
- package/assets/images/site-logo.png +0 -0
- package/dist/releasetag.txt +1 -1
- package/extension/interceptor.ts +5 -1
- package/lib/extension/dist/layer/nodejs/node_modules/interceptor.js +147 -2
- package/lib/extension/dist/layer/nodejs/node_modules/interceptor.js.map +4 -4
- package/lib/src/ServerlessSpy.js +1 -1
- package/logo/full_logo.png +0 -0
- package/node_modules/serialize-error/error-constructors.d.ts +8 -0
- package/node_modules/serialize-error/error-constructors.js +26 -0
- package/node_modules/serialize-error/index.d.ts +171 -0
- package/node_modules/serialize-error/index.js +205 -0
- package/node_modules/serialize-error/license +9 -0
- package/node_modules/serialize-error/node_modules/type-fest/index.d.ts +95 -0
- package/node_modules/serialize-error/node_modules/type-fest/package.json +52 -0
- package/node_modules/serialize-error/node_modules/type-fest/readme.md +905 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/async-return-type.d.ts +25 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/asyncify.d.ts +33 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/basic.d.ts +45 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/camel-case.d.ts +73 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/camel-cased-properties-deep.d.ts +54 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/camel-cased-properties.d.ts +36 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/conditional-except.d.ts +45 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/conditional-keys.d.ts +47 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/conditional-pick.d.ts +44 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/delimiter-case.d.ts +93 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/delimiter-cased-properties-deep.d.ts +60 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/delimiter-cased-properties.d.ts +37 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/entries.d.ts +62 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/entry.d.ts +65 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/exact.d.ts +73 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/except.d.ts +57 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/fixed-length-array.d.ts +43 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/get.d.ts +184 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/has-optional-keys.d.ts +21 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/has-required-keys.d.ts +59 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/includes.d.ts +22 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/internal.d.ts +59 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/invariant-of.d.ts +76 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/iterable-element.d.ts +54 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/join.d.ts +30 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/jsonify.d.ts +90 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/kebab-case.d.ts +38 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/kebab-cased-properties-deep.d.ts +47 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/kebab-cased-properties.d.ts +30 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/last-array-element.d.ts +28 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/literal-to-primitive.d.ts +36 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/literal-union.d.ts +35 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/merge-exclusive.d.ts +41 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/merge.d.ts +27 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/multidimensional-array.d.ts +43 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/multidimensional-readonly-array.d.ts +47 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/mutable.d.ts +5 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/numeric.d.ts +170 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/observable-like.d.ts +62 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/opaque.d.ts +107 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/optional-keys-of.d.ts +38 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/package-json.d.ts +663 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/partial-deep.d.ts +113 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/partial-on-undefined-deep.d.ts +70 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/pascal-case.d.ts +38 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/pascal-cased-properties-deep.d.ts +54 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/pascal-cased-properties.d.ts +34 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/primitive.d.ts +13 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/promisable.d.ts +25 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/promise-value.d.ts +29 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/readonly-deep.d.ts +85 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/readonly-tuple.d.ts +41 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/remove-index-signature.d.ts +104 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/replace.d.ts +67 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/require-all-or-none.d.ts +36 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/require-at-least-one.d.ts +35 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/require-exactly-one.d.ts +34 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/required-keys-of.d.ts +29 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/schema.d.ts +72 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/screaming-snake-case.d.ts +33 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/set-non-nullable.d.ts +35 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/set-optional.d.ts +35 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/set-required.d.ts +35 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/set-return-type.d.ts +31 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/simplify.d.ts +83 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/snake-case.d.ts +38 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/snake-cased-properties-deep.d.ts +47 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/snake-cased-properties.d.ts +30 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/split.d.ts +29 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/spread.d.ts +85 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/string-key-of.d.ts +25 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/stringified.d.ts +23 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/trim.d.ts +25 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/tsconfig-json.d.ts +1172 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/typed-array.d.ts +17 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/union-to-intersection.d.ts +60 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/value-of.d.ts +42 -0
- package/node_modules/serialize-error/node_modules/type-fest/source/writable.d.ts +40 -0
- package/node_modules/serialize-error/package.json +46 -0
- package/node_modules/serialize-error/readme.md +198 -0
- package/package.json +6 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
|
3
|
+
|
|
4
|
+
@category Array
|
|
5
|
+
*/
|
|
6
|
+
export type TypedArray =
|
|
7
|
+
| Int8Array
|
|
8
|
+
| Uint8Array
|
|
9
|
+
| Uint8ClampedArray
|
|
10
|
+
| Int16Array
|
|
11
|
+
| Uint16Array
|
|
12
|
+
| Int32Array
|
|
13
|
+
| Uint32Array
|
|
14
|
+
| Float32Array
|
|
15
|
+
| Float64Array
|
|
16
|
+
| BigInt64Array
|
|
17
|
+
| BigUint64Array;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
3
|
+
|
|
4
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
11
|
+
|
|
12
|
+
type Intersection = UnionToIntersection<Union>;
|
|
13
|
+
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
A more applicable example which could make its way into your library code follows.
|
|
17
|
+
|
|
18
|
+
@example
|
|
19
|
+
```
|
|
20
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
21
|
+
|
|
22
|
+
class CommandOne {
|
|
23
|
+
commands: {
|
|
24
|
+
a1: () => undefined,
|
|
25
|
+
b1: () => undefined,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class CommandTwo {
|
|
30
|
+
commands: {
|
|
31
|
+
a2: (argA: string) => undefined,
|
|
32
|
+
b2: (argB: string) => undefined,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
37
|
+
type Union = typeof union;
|
|
38
|
+
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
39
|
+
|
|
40
|
+
type Intersection = UnionToIntersection<Union>;
|
|
41
|
+
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
@category Type
|
|
45
|
+
*/
|
|
46
|
+
export type UnionToIntersection<Union> = (
|
|
47
|
+
// `extends unknown` is always going to be the case and is used to convert the
|
|
48
|
+
// `Union` into a [distributive conditional
|
|
49
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
50
|
+
Union extends unknown
|
|
51
|
+
// The union type is used as the only argument to a function since the union
|
|
52
|
+
// of function arguments is an intersection.
|
|
53
|
+
? (distributedUnion: Union) => void
|
|
54
|
+
// This won't happen.
|
|
55
|
+
: never
|
|
56
|
+
// Infer the `Intersection` type since TypeScript represents the positional
|
|
57
|
+
// arguments of unions of functions as an intersection of the union.
|
|
58
|
+
) extends ((mergedIntersection: infer Intersection) => void)
|
|
59
|
+
? Intersection
|
|
60
|
+
: never;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
3
|
+
|
|
4
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
// data.json
|
|
9
|
+
{
|
|
10
|
+
'foo': 1,
|
|
11
|
+
'bar': 2,
|
|
12
|
+
'biz': 3
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// main.ts
|
|
16
|
+
import type {ValueOf} from 'type-fest';
|
|
17
|
+
import data = require('./data.json');
|
|
18
|
+
|
|
19
|
+
export function getData(name: string): ValueOf<typeof data> {
|
|
20
|
+
return data[name];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
|
24
|
+
return data[name];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// file.ts
|
|
28
|
+
import {getData, onlyBar} from './main';
|
|
29
|
+
|
|
30
|
+
getData('foo');
|
|
31
|
+
//=> 1
|
|
32
|
+
|
|
33
|
+
onlyBar('foo');
|
|
34
|
+
//=> TypeError ...
|
|
35
|
+
|
|
36
|
+
onlyBar('bar');
|
|
37
|
+
//=> 2
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
@category Object
|
|
41
|
+
*/
|
|
42
|
+
export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type {Except} from './except';
|
|
2
|
+
import type {Simplify} from './simplify';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Create a type that strips `readonly` from all or some of an object's keys. Inverse of `Readonly<T>`.
|
|
6
|
+
|
|
7
|
+
This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import type {Writable} from 'type-fest';
|
|
12
|
+
|
|
13
|
+
type Foo = {
|
|
14
|
+
readonly a: number;
|
|
15
|
+
readonly b: readonly string[]; // To show that only the mutability status of the properties, not their values, are affected.
|
|
16
|
+
readonly c: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const writableFoo: Writable<Foo> = {a: 1, b: ['2'], c: true};
|
|
20
|
+
writableFoo.a = 3;
|
|
21
|
+
writableFoo.b[0] = 'new value'; // Will still fail as the value of property "b" is still a readonly type.
|
|
22
|
+
writableFoo.b = ['something']; // Will work as the "b" property itself is no longer readonly.
|
|
23
|
+
|
|
24
|
+
type SomeWritable = Writable<Foo, 'b' | 'c'>;
|
|
25
|
+
// type SomeWritable = {
|
|
26
|
+
// readonly a: number;
|
|
27
|
+
// b: readonly string[]; // It's now writable. The type of the property remains unaffected.
|
|
28
|
+
// c: boolean; // It's now writable.
|
|
29
|
+
// }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
@category Object
|
|
33
|
+
*/
|
|
34
|
+
export type Writable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
|
|
35
|
+
Simplify<
|
|
36
|
+
// Pick just the keys that are not writable from the base type.
|
|
37
|
+
Except<BaseType, Keys> &
|
|
38
|
+
// Pick the keys that should be writable from the base type and make them writable by removing the `readonly` modifier from the key.
|
|
39
|
+
{-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]}
|
|
40
|
+
>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "serialize-error",
|
|
3
|
+
"version": "11.0.0",
|
|
4
|
+
"description": "Serialize/deserialize an error into a plain object",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "sindresorhus/serialize-error",
|
|
7
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Sindre Sorhus",
|
|
10
|
+
"email": "sindresorhus@gmail.com",
|
|
11
|
+
"url": "https://sindresorhus.com"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": "./index.js",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=14.16"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "xo && ava && tsd"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"index.js",
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"error-constructors.js",
|
|
25
|
+
"error-constructors.d.ts"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"error",
|
|
29
|
+
"serialize",
|
|
30
|
+
"stringify",
|
|
31
|
+
"object",
|
|
32
|
+
"convert",
|
|
33
|
+
"process",
|
|
34
|
+
"send",
|
|
35
|
+
"cause",
|
|
36
|
+
"deserialize"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"type-fest": "^2.12.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"ava": "^4.2.0",
|
|
43
|
+
"tsd": "^0.20.0",
|
|
44
|
+
"xo": "^0.48.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# serialize-error
|
|
2
|
+
|
|
3
|
+
> Serialize/deserialize an error into a plain object
|
|
4
|
+
|
|
5
|
+
Useful if you for example need to `JSON.stringify()` or `process.send()` the error.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install serialize-error
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import {serializeError, deserializeError} from 'serialize-error';
|
|
17
|
+
|
|
18
|
+
const error = new Error('🦄');
|
|
19
|
+
|
|
20
|
+
console.log(error);
|
|
21
|
+
//=> [Error: 🦄]
|
|
22
|
+
|
|
23
|
+
const serialized = serializeError(error);
|
|
24
|
+
|
|
25
|
+
console.log(serialized);
|
|
26
|
+
//=> {name: 'Error', message: '🦄', stack: 'Error: 🦄\n at Object.<anonymous> …'}
|
|
27
|
+
|
|
28
|
+
const deserialized = deserializeError(serialized);
|
|
29
|
+
|
|
30
|
+
console.log(deserialized);
|
|
31
|
+
//=> [Error: 🦄]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Error constructors
|
|
35
|
+
|
|
36
|
+
When a serialized error with a known `name` is encountered, it will be deserialized using the corresponding error constructor, while unknown error names will be deserialized as regular errors:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import {deserializeError} from 'serialize-error';
|
|
40
|
+
|
|
41
|
+
const known = deserializeError({
|
|
42
|
+
name: 'TypeError',
|
|
43
|
+
message: '🦄'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
console.log(known);
|
|
47
|
+
//=> [TypeError: 🦄] <-- Still a TypeError
|
|
48
|
+
|
|
49
|
+
const unknown = deserializeError({
|
|
50
|
+
name: 'TooManyCooksError',
|
|
51
|
+
message: '🦄'
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
console.log(unknown);
|
|
55
|
+
//=> [Error: 🦄] <-- Just a regular Error
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The [list of known errors](./error-constructors.js) can be extended globally. This also works if `serialize-error` is a sub-dependency that's not used directly.
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import {errorConstructors} from 'serialize-error';
|
|
62
|
+
import {MyCustomError} from './errors.js'
|
|
63
|
+
|
|
64
|
+
errorConstructors.set('MyCustomError', MyCustomError)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Warning:** Only simple and standard error constructors are supported, like `new MyCustomError(message)`. If your error constructor **requires** a second parameter or does not accept a string as first parameter, adding it to this map **will** break the deserialization.
|
|
68
|
+
|
|
69
|
+
## API
|
|
70
|
+
|
|
71
|
+
### serializeError(value, options?)
|
|
72
|
+
|
|
73
|
+
Serialize an `Error` object into a plain object.
|
|
74
|
+
|
|
75
|
+
- Non-error values are passed through.
|
|
76
|
+
- Custom properties are preserved.
|
|
77
|
+
- Non-enumerable properties are kept non-enumerable (name, message, stack).
|
|
78
|
+
- Enumerable properties are kept enumerable (all properties besides the non-enumerable ones).
|
|
79
|
+
- Buffer properties are replaced with `[object Buffer]`.
|
|
80
|
+
- Circular references are handled.
|
|
81
|
+
- If the input object has a `.toJSON()` method, then it's called instead of serializing the object's properties.
|
|
82
|
+
- It's up to `.toJSON()` implementation to handle circular references and enumerability of the properties.
|
|
83
|
+
|
|
84
|
+
### value
|
|
85
|
+
|
|
86
|
+
Type: `Error | unknown`
|
|
87
|
+
|
|
88
|
+
### toJSON implementation examples
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
import {serializeError} from 'serialize-error';
|
|
92
|
+
|
|
93
|
+
class ErrorWithDate extends Error {
|
|
94
|
+
constructor() {
|
|
95
|
+
super();
|
|
96
|
+
this.date = new Date();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const error = new ErrorWithDate();
|
|
101
|
+
|
|
102
|
+
serializeError(error);
|
|
103
|
+
// => {date: '1970-01-01T00:00:00.000Z', name, message, stack}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
import {serializeError} from 'serialize-error';
|
|
108
|
+
|
|
109
|
+
const error = new Error('Unicorn');
|
|
110
|
+
|
|
111
|
+
error.horn = {
|
|
112
|
+
toJSON() {
|
|
113
|
+
return 'x';
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
serializeError(error);
|
|
118
|
+
// => {horn: 'x', name, message, stack}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### deserializeError(value, options?)
|
|
122
|
+
|
|
123
|
+
Deserialize a plain object or any value into an `Error` object.
|
|
124
|
+
|
|
125
|
+
- `Error` objects are passed through.
|
|
126
|
+
- Objects that have at least a `message` property are interpreted as errors.
|
|
127
|
+
- All other values are wrapped in a `NonError` error.
|
|
128
|
+
- Custom properties are preserved.
|
|
129
|
+
- Non-enumerable properties are kept non-enumerable (name, message, stack, cause).
|
|
130
|
+
- Enumerable properties are kept enumerable (all properties besides the non-enumerable ones).
|
|
131
|
+
- Circular references are handled.
|
|
132
|
+
- [Native error constructors](./error-constructors.js) are preserved (TypeError, DOMException, etc) and [more can be added.](#error-constructors)
|
|
133
|
+
|
|
134
|
+
### value
|
|
135
|
+
|
|
136
|
+
Type: `{message: string} | unknown`
|
|
137
|
+
|
|
138
|
+
### options
|
|
139
|
+
|
|
140
|
+
Type: `object`
|
|
141
|
+
|
|
142
|
+
#### maxDepth
|
|
143
|
+
|
|
144
|
+
Type: `number`\
|
|
145
|
+
Default: `Number.POSITIVE_INFINITY`
|
|
146
|
+
|
|
147
|
+
The maximum depth of properties to preserve when serializing/deserializing.
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
import {serializeError} from 'serialize-error';
|
|
151
|
+
|
|
152
|
+
const error = new Error('🦄');
|
|
153
|
+
error.one = {two: {three: {}}};
|
|
154
|
+
|
|
155
|
+
console.log(serializeError(error, {maxDepth: 1}));
|
|
156
|
+
//=> {name: 'Error', message: '🦄', one: {}}
|
|
157
|
+
|
|
158
|
+
console.log(serializeError(error, {maxDepth: 2}));
|
|
159
|
+
//=> {name: 'Error', message: '🦄', one: { two: {}}}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### useToJSON
|
|
163
|
+
|
|
164
|
+
Type: `boolean`\
|
|
165
|
+
Default: `true`
|
|
166
|
+
|
|
167
|
+
Indicate whether to use a `.toJSON()` method if encountered in the object. This is useful when a custom error implements [its own serialization logic via `.toJSON()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior) but you prefer to not use it.
|
|
168
|
+
|
|
169
|
+
### isErrorLike(value)
|
|
170
|
+
|
|
171
|
+
Predicate to determine whether a value looks like an error, even if it's not an instance of `Error`. It must have at least the `name`, `message`, and `stack` properties.
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
import {isErrorLike} from 'serialize-error';
|
|
175
|
+
|
|
176
|
+
const error = new Error('🦄');
|
|
177
|
+
error.one = {two: {three: {}}};
|
|
178
|
+
|
|
179
|
+
isErrorLike({
|
|
180
|
+
name: 'DOMException',
|
|
181
|
+
message: 'It happened',
|
|
182
|
+
stack: 'at foo (index.js:2:9)',
|
|
183
|
+
});
|
|
184
|
+
//=> true
|
|
185
|
+
|
|
186
|
+
isErrorLike(new Error('🦄'));
|
|
187
|
+
//=> true
|
|
188
|
+
|
|
189
|
+
isErrorLike(serializeError(new Error('🦄'));
|
|
190
|
+
//=> true
|
|
191
|
+
|
|
192
|
+
isErrorLike({
|
|
193
|
+
name: 'Bluberricious pancakes',
|
|
194
|
+
stack: 12,
|
|
195
|
+
ingredients: 'Blueberry',
|
|
196
|
+
});
|
|
197
|
+
//=> false
|
|
198
|
+
```
|
package/package.json
CHANGED
|
@@ -103,12 +103,13 @@
|
|
|
103
103
|
"@aws-sdk/util-dynamodb": "^3.180.0",
|
|
104
104
|
"aws-lambda": "^1.0.7",
|
|
105
105
|
"aws4": "^1.11.0",
|
|
106
|
-
"ws": "^8.9.0",
|
|
107
106
|
"bootstrap": "^5.2.1",
|
|
108
107
|
"bootstrap-icons": "^1.9.1",
|
|
109
108
|
"caporal": "^1.4.0",
|
|
110
109
|
"json-format-highlight": "^1.0.4",
|
|
111
|
-
"open": "^8.4.0"
|
|
110
|
+
"open": "^8.4.0",
|
|
111
|
+
"serialize-error": "^11.0.0",
|
|
112
|
+
"ws": "^8.9.0"
|
|
112
113
|
},
|
|
113
114
|
"keywords": [
|
|
114
115
|
"cdk",
|
|
@@ -133,7 +134,7 @@
|
|
|
133
134
|
"require": "./lib/index.js"
|
|
134
135
|
},
|
|
135
136
|
"license": "MPL-2.0",
|
|
136
|
-
"version": "0.0.
|
|
137
|
+
"version": "0.0.62",
|
|
137
138
|
"types": "lib/index.d.ts",
|
|
138
139
|
"stability": "stable",
|
|
139
140
|
"jsii": {
|
|
@@ -167,7 +168,8 @@
|
|
|
167
168
|
"bootstrap-icons",
|
|
168
169
|
"caporal",
|
|
169
170
|
"json-format-highlight",
|
|
170
|
-
"open"
|
|
171
|
+
"open",
|
|
172
|
+
"serialize-error"
|
|
171
173
|
],
|
|
172
174
|
"jest": {
|
|
173
175
|
"testMatch": [
|