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,113 @@
|
|
|
1
|
+
import type {BuiltIns} from './internal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
@see PartialDeep
|
|
5
|
+
*/
|
|
6
|
+
export interface PartialDeepOptions {
|
|
7
|
+
/**
|
|
8
|
+
Whether to affect the individual elements of arrays and tuples.
|
|
9
|
+
|
|
10
|
+
@default true
|
|
11
|
+
*/
|
|
12
|
+
readonly recurseIntoArrays?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
Create a type from another type with all keys and nested keys set to optional.
|
|
17
|
+
|
|
18
|
+
Use-cases:
|
|
19
|
+
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
20
|
+
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
21
|
+
|
|
22
|
+
@example
|
|
23
|
+
```
|
|
24
|
+
import type {PartialDeep} from 'type-fest';
|
|
25
|
+
|
|
26
|
+
const settings: Settings = {
|
|
27
|
+
textEditor: {
|
|
28
|
+
fontSize: 14;
|
|
29
|
+
fontColor: '#000000';
|
|
30
|
+
fontWeight: 400;
|
|
31
|
+
}
|
|
32
|
+
autocomplete: false;
|
|
33
|
+
autosave: true;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
|
|
37
|
+
return {...settings, ...savedSettings};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
By default, this also affects array and tuple types:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
import type {PartialDeep} from 'type-fest';
|
|
47
|
+
|
|
48
|
+
interface Settings {
|
|
49
|
+
languages: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const partialSettings: PartialDeep<Settings> = {
|
|
53
|
+
languages: [undefined]
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
If this is undesirable, you can pass `{recurseIntoArrays: false}` as the second type argument.
|
|
58
|
+
|
|
59
|
+
@category Object
|
|
60
|
+
@category Array
|
|
61
|
+
@category Set
|
|
62
|
+
@category Map
|
|
63
|
+
*/
|
|
64
|
+
export type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns
|
|
65
|
+
? T
|
|
66
|
+
: T extends Map<infer KeyType, infer ValueType>
|
|
67
|
+
? PartialMapDeep<KeyType, ValueType, Options>
|
|
68
|
+
: T extends Set<infer ItemType>
|
|
69
|
+
? PartialSetDeep<ItemType, Options>
|
|
70
|
+
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
71
|
+
? PartialReadonlyMapDeep<KeyType, ValueType, Options>
|
|
72
|
+
: T extends ReadonlySet<infer ItemType>
|
|
73
|
+
? PartialReadonlySetDeep<ItemType, Options>
|
|
74
|
+
: T extends ((...arguments: any[]) => unknown)
|
|
75
|
+
? T | undefined
|
|
76
|
+
: T extends object
|
|
77
|
+
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
78
|
+
? Options['recurseIntoArrays'] extends false // If they opt out of array testing, just use the original type
|
|
79
|
+
? T
|
|
80
|
+
: ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
81
|
+
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
82
|
+
? ReadonlyArray<PartialDeep<ItemType | undefined, Options>>
|
|
83
|
+
: Array<PartialDeep<ItemType | undefined, Options>>
|
|
84
|
+
: PartialObjectDeep<T, Options> // Tuples behave properly
|
|
85
|
+
: PartialObjectDeep<T, Options>
|
|
86
|
+
: unknown;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
90
|
+
*/
|
|
91
|
+
interface PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> extends Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>> {}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
95
|
+
*/
|
|
96
|
+
interface PartialSetDeep<T, Options extends PartialDeepOptions> extends Set<PartialDeep<T, Options>> {}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
100
|
+
*/
|
|
101
|
+
interface PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> extends ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>> {}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
105
|
+
*/
|
|
106
|
+
interface PartialReadonlySetDeep<T, Options extends PartialDeepOptions> extends ReadonlySet<PartialDeep<T, Options>> {}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
110
|
+
*/
|
|
111
|
+
type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions> = {
|
|
112
|
+
[KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
|
|
113
|
+
};
|
package/node_modules/serialize-error/node_modules/type-fest/source/partial-on-undefined-deep.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type {BuiltIns} from './internal';
|
|
2
|
+
import type {Merge} from './merge';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
@see PartialOnUndefinedDeep
|
|
6
|
+
*/
|
|
7
|
+
export interface PartialOnUndefinedDeepOptions {
|
|
8
|
+
/**
|
|
9
|
+
Whether to affect the individual elements of arrays and tuples.
|
|
10
|
+
|
|
11
|
+
@default false
|
|
12
|
+
*/
|
|
13
|
+
readonly recurseIntoArrays?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
Create a deep version of another type where all keys accepting `undefined` type are set to optional.
|
|
18
|
+
|
|
19
|
+
This utility type is recursive, transforming at any level deep. By default, it does not affect arrays and tuples items unless you explicitly pass `{recurseIntoArrays: true}` as the second type argument.
|
|
20
|
+
|
|
21
|
+
Use-cases:
|
|
22
|
+
- Make all properties of a type that can be undefined optional to not have to specify keys with undefined value.
|
|
23
|
+
|
|
24
|
+
@example
|
|
25
|
+
```
|
|
26
|
+
import type {PartialOnUndefinedDeep} from 'type-fest';
|
|
27
|
+
|
|
28
|
+
interface Settings {
|
|
29
|
+
optionA: string;
|
|
30
|
+
optionB: number | undefined;
|
|
31
|
+
subOption: {
|
|
32
|
+
subOptionA: boolean;
|
|
33
|
+
subOptionB: boolean | undefined;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const testSettings: PartialOnUndefinedDeep<Settings> = {
|
|
38
|
+
optionA: 'foo',
|
|
39
|
+
// 👉 optionB is now optional and can be omitted
|
|
40
|
+
subOption: {
|
|
41
|
+
subOptionA: true,
|
|
42
|
+
// 👉 subOptionB is now optional as well and can be omitted
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
@category Object
|
|
48
|
+
*/
|
|
49
|
+
export type PartialOnUndefinedDeep<T, Options extends PartialOnUndefinedDeepOptions = {}> = T extends Record<any, any> | undefined
|
|
50
|
+
? {[KeyType in keyof T as undefined extends T[KeyType] ? KeyType : never]?: PartialOnUndefinedDeepValue<T[KeyType], Options>} extends infer U // Make a partial type with all value types accepting undefined (and set them optional)
|
|
51
|
+
? Merge<{[KeyType in keyof T as KeyType extends keyof U ? never : KeyType]: PartialOnUndefinedDeepValue<T[KeyType], Options>}, U> // Join all remaining keys not treated in U
|
|
52
|
+
: never // Should not happen
|
|
53
|
+
: T;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
Utility type to get the value type by key and recursively call `PartialOnUndefinedDeep` to transform sub-objects.
|
|
57
|
+
*/
|
|
58
|
+
type PartialOnUndefinedDeepValue<T, Options extends PartialOnUndefinedDeepOptions> = T extends BuiltIns | ((...arguments: any[]) => unknown)
|
|
59
|
+
? T
|
|
60
|
+
: T extends ReadonlyArray<infer U> // Test if type is array or tuple
|
|
61
|
+
? Options['recurseIntoArrays'] extends true // Check if option is activated
|
|
62
|
+
? U[] extends T // Check if array not tuple
|
|
63
|
+
? readonly U[] extends T
|
|
64
|
+
? ReadonlyArray<PartialOnUndefinedDeep<U, Options>> // Readonly array treatment
|
|
65
|
+
: Array<PartialOnUndefinedDeep<U, Options>> // Mutable array treatment
|
|
66
|
+
: PartialOnUndefinedDeep<{[Key in keyof T]: PartialOnUndefinedDeep<T[Key], Options>}, Options> // Tuple treatment
|
|
67
|
+
: T
|
|
68
|
+
: T extends Record<any, any> | undefined
|
|
69
|
+
? PartialOnUndefinedDeep<T, Options>
|
|
70
|
+
: unknown;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {CamelCase} from './camel-case';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Converts a string literal to pascal-case.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {PascalCase} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
// Simple
|
|
11
|
+
|
|
12
|
+
const someVariable: PascalCase<'foo-bar'> = 'FooBar';
|
|
13
|
+
|
|
14
|
+
// Advanced
|
|
15
|
+
|
|
16
|
+
type PascalCaseProps<T> = {
|
|
17
|
+
[K in keyof T as PascalCase<K>]: T[K]
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
interface RawOptions {
|
|
21
|
+
'dry-run': boolean;
|
|
22
|
+
'full_family_name': string;
|
|
23
|
+
foo: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const dbResult: CamelCasedProperties<ModelProps> = {
|
|
27
|
+
DryRun: true,
|
|
28
|
+
FullFamilyName: 'bar.js',
|
|
29
|
+
Foo: 123
|
|
30
|
+
};
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
@category Change case
|
|
34
|
+
@category Template literal
|
|
35
|
+
*/
|
|
36
|
+
export type PascalCase<Value> = CamelCase<Value> extends string
|
|
37
|
+
? Capitalize<CamelCase<Value>>
|
|
38
|
+
: CamelCase<Value>;
|
package/node_modules/serialize-error/node_modules/type-fest/source/pascal-cased-properties-deep.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {PascalCase} from './pascal-case';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Convert object properties to pascal case recursively.
|
|
5
|
+
|
|
6
|
+
This can be useful when, for example, converting some API types from a different style.
|
|
7
|
+
|
|
8
|
+
@see PascalCase
|
|
9
|
+
@see PascalCasedProperties
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import type {PascalCasedPropertiesDeep} from 'type-fest';
|
|
14
|
+
|
|
15
|
+
interface User {
|
|
16
|
+
userId: number;
|
|
17
|
+
userName: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface UserWithFriends {
|
|
21
|
+
userInfo: User;
|
|
22
|
+
userFriends: User[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const result: PascalCasedPropertiesDeep<UserWithFriends> = {
|
|
26
|
+
UserInfo: {
|
|
27
|
+
UserId: 1,
|
|
28
|
+
UserName: 'Tom',
|
|
29
|
+
},
|
|
30
|
+
UserFriends: [
|
|
31
|
+
{
|
|
32
|
+
UserId: 2,
|
|
33
|
+
UserName: 'Jerry',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
UserId: 3,
|
|
37
|
+
UserName: 'Spike',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
@category Change case
|
|
44
|
+
@category Template literal
|
|
45
|
+
@category Object
|
|
46
|
+
*/
|
|
47
|
+
export type PascalCasedPropertiesDeep<Value> = Value extends Function | Date | RegExp
|
|
48
|
+
? Value
|
|
49
|
+
: Value extends Array<infer U>
|
|
50
|
+
? Array<PascalCasedPropertiesDeep<U>>
|
|
51
|
+
: Value extends Set<infer U>
|
|
52
|
+
? Set<PascalCasedPropertiesDeep<U>> : {
|
|
53
|
+
[K in keyof Value as PascalCase<K>]: PascalCasedPropertiesDeep<Value[K]>;
|
|
54
|
+
};
|
package/node_modules/serialize-error/node_modules/type-fest/source/pascal-cased-properties.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {PascalCase} from './pascal-case';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Convert object properties to pascal case but not recursively.
|
|
5
|
+
|
|
6
|
+
This can be useful when, for example, converting some API types from a different style.
|
|
7
|
+
|
|
8
|
+
@see PascalCase
|
|
9
|
+
@see PascalCasedPropertiesDeep
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import type {PascalCasedProperties} from 'type-fest';
|
|
14
|
+
|
|
15
|
+
interface User {
|
|
16
|
+
userId: number;
|
|
17
|
+
userName: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const result: PascalCasedProperties<User> = {
|
|
21
|
+
UserId: 1,
|
|
22
|
+
UserName: 'Tom',
|
|
23
|
+
};
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
@category Change case
|
|
27
|
+
@category Template literal
|
|
28
|
+
@category Object
|
|
29
|
+
*/
|
|
30
|
+
export type PascalCasedProperties<Value> = Value extends Function
|
|
31
|
+
? Value
|
|
32
|
+
: Value extends Array<infer U>
|
|
33
|
+
? Value
|
|
34
|
+
: {[K in keyof Value as PascalCase<K>]: Value[K]};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
3
|
+
|
|
4
|
+
Use-cases:
|
|
5
|
+
- A function accepts a callback that may either return a value synchronously or may return a promised value.
|
|
6
|
+
- This type could be the return type of `Promise#then()`, `Promise#catch()`, and `Promise#finally()` callbacks.
|
|
7
|
+
|
|
8
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31394) if you want to have this type as a built-in in TypeScript.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import type {Promisable} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
|
|
15
|
+
const entry = await getLogEntry();
|
|
16
|
+
console.log(entry);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
logger(() => 'foo');
|
|
20
|
+
logger(() => Promise.resolve('bar'));
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
@category Async
|
|
24
|
+
*/
|
|
25
|
+
export type Promisable<T> = T | PromiseLike<T>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@deprecated Use the built-in [`Awaited` type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#the-awaited-type-and-promise-improvements) instead.
|
|
3
|
+
|
|
4
|
+
Returns the type that is wrapped inside a `Promise` type.
|
|
5
|
+
If the type is a nested Promise, it is unwrapped recursively until a non-Promise type is obtained.
|
|
6
|
+
If the type is not a `Promise`, the type itself is returned.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {PromiseValue} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type AsyncData = Promise<string>;
|
|
13
|
+
let asyncData: AsyncData = Promise.resolve('ABC');
|
|
14
|
+
|
|
15
|
+
type Data = PromiseValue<AsyncData>;
|
|
16
|
+
let data: Data = await asyncData;
|
|
17
|
+
|
|
18
|
+
// Here's an example that shows how this type reacts to non-Promise types.
|
|
19
|
+
type SyncData = PromiseValue<string>;
|
|
20
|
+
let syncData: SyncData = getSyncData();
|
|
21
|
+
|
|
22
|
+
// Here's an example that shows how this type reacts to recursive Promise types.
|
|
23
|
+
type RecursiveAsyncData = Promise<Promise<string>>;
|
|
24
|
+
let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = await Promise.resolve(Promise.resolve('ABC'));
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
@category Async
|
|
28
|
+
*/
|
|
29
|
+
export type PromiseValue<PromiseType> = PromiseType extends PromiseLike<infer Value> ? PromiseValue<Value> : PromiseType;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type {BuiltIns} from './internal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
|
5
|
+
|
|
6
|
+
This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
|
|
7
|
+
|
|
8
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
// data.json
|
|
13
|
+
{
|
|
14
|
+
"foo": ["bar"]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// main.ts
|
|
18
|
+
import type {ReadonlyDeep} from 'type-fest';
|
|
19
|
+
import dataJson = require('./data.json');
|
|
20
|
+
|
|
21
|
+
const data: ReadonlyDeep<typeof dataJson> = dataJson;
|
|
22
|
+
|
|
23
|
+
export default data;
|
|
24
|
+
|
|
25
|
+
// test.ts
|
|
26
|
+
import data from './main';
|
|
27
|
+
|
|
28
|
+
data.foo.push('bar');
|
|
29
|
+
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
@category Object
|
|
33
|
+
@category Array
|
|
34
|
+
@category Set
|
|
35
|
+
@category Map
|
|
36
|
+
*/
|
|
37
|
+
export type ReadonlyDeep<T> = T extends BuiltIns
|
|
38
|
+
? T
|
|
39
|
+
: T extends (...arguments: any[]) => unknown
|
|
40
|
+
? {} extends ReadonlyObjectDeep<T>
|
|
41
|
+
? T
|
|
42
|
+
: HasMultipleCallSignatures<T> extends true
|
|
43
|
+
? T
|
|
44
|
+
: ((...arguments: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T>
|
|
45
|
+
: T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
|
|
46
|
+
? ReadonlyMapDeep<KeyType, ValueType>
|
|
47
|
+
: T extends Readonly<ReadonlySet<infer ItemType>>
|
|
48
|
+
? ReadonlySetDeep<ItemType>
|
|
49
|
+
: T extends object
|
|
50
|
+
? ReadonlyObjectDeep<T>
|
|
51
|
+
: unknown;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
55
|
+
*/
|
|
56
|
+
interface ReadonlyMapDeep<KeyType, ValueType>
|
|
57
|
+
extends Readonly<ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>>> {}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
61
|
+
*/
|
|
62
|
+
interface ReadonlySetDeep<ItemType>
|
|
63
|
+
extends Readonly<ReadonlySet<ReadonlyDeep<ItemType>>> {}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
67
|
+
*/
|
|
68
|
+
type ReadonlyObjectDeep<ObjectType extends object> = {
|
|
69
|
+
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
Test if the given function has multiple call signatures.
|
|
74
|
+
|
|
75
|
+
Needed to handle the case of a single call signature with properties.
|
|
76
|
+
|
|
77
|
+
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
78
|
+
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
79
|
+
*/
|
|
80
|
+
type HasMultipleCallSignatures<T extends (...arguments: any[]) => unknown> =
|
|
81
|
+
T extends {(...arguments: infer A): unknown; (...arguments: any[]): unknown}
|
|
82
|
+
? unknown[] extends A
|
|
83
|
+
? false
|
|
84
|
+
: true
|
|
85
|
+
: false;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Creates a read-only tuple of type `Element` and with the length of `Length`.
|
|
3
|
+
|
|
4
|
+
@private
|
|
5
|
+
@see `ReadonlyTuple` which is safer because it tests if `Length` is a specific finite number.
|
|
6
|
+
*/
|
|
7
|
+
type BuildTupleHelper<Element, Length extends number, Rest extends Element[]> =
|
|
8
|
+
Rest['length'] extends Length ?
|
|
9
|
+
readonly [...Rest] : // Terminate with readonly array (aka tuple)
|
|
10
|
+
BuildTupleHelper<Element, Length, [Element, ...Rest]>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
Create a type that represents a read-only tuple of the given type and length.
|
|
14
|
+
|
|
15
|
+
Use-cases:
|
|
16
|
+
- Declaring fixed-length tuples with a large number of items.
|
|
17
|
+
- Creating a range union (for example, `0 | 1 | 2 | 3 | 4` from the keys of such a type) without having to resort to recursive types.
|
|
18
|
+
- Creating a tuple of coordinates with a static length, for example, length of 3 for a 3D vector.
|
|
19
|
+
|
|
20
|
+
@example
|
|
21
|
+
```
|
|
22
|
+
import {ReadonlyTuple} from 'type-fest';
|
|
23
|
+
|
|
24
|
+
type FencingTeam = ReadonlyTuple<string, 3>;
|
|
25
|
+
|
|
26
|
+
const guestFencingTeam: FencingTeam = ['Josh', 'Michael', 'Robert'];
|
|
27
|
+
|
|
28
|
+
const homeFencingTeam: FencingTeam = ['George', 'John'];
|
|
29
|
+
//=> error TS2322: Type string[] is not assignable to type 'FencingTeam'
|
|
30
|
+
|
|
31
|
+
guestFencingTeam.push('Sam');
|
|
32
|
+
//=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
@category Utilities
|
|
36
|
+
*/
|
|
37
|
+
export type ReadonlyTuple<Element, Length extends number> =
|
|
38
|
+
number extends Length
|
|
39
|
+
// Because `Length extends number` and `number extends Length`, then `Length` is not a specific finite number.
|
|
40
|
+
? readonly Element[] // It's not fixed length.
|
|
41
|
+
: BuildTupleHelper<Element, Length, []>; // Otherwise it is a fixed length tuple.
|
package/node_modules/serialize-error/node_modules/type-fest/source/remove-index-signature.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Remove any index signatures from the given object type, so that only explicitly defined properties remain.
|
|
3
|
+
|
|
4
|
+
Use-cases:
|
|
5
|
+
- Remove overly permissive signatures from third-party types.
|
|
6
|
+
|
|
7
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
8
|
+
|
|
9
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
10
|
+
|
|
11
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
15
|
+
|
|
16
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
17
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
type Indexed = {} extends Record<string, unknown>
|
|
24
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
25
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
26
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
27
|
+
|
|
28
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
29
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
30
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
31
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
import type {RemoveIndexSignature} from 'type-fest';
|
|
38
|
+
|
|
39
|
+
type RemoveIndexSignature<ObjectType> = {
|
|
40
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
41
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `RemoveIndexSignature<Foo> == Foo`.
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
import type {RemoveIndexSignature} from 'type-fest';
|
|
49
|
+
|
|
50
|
+
type RemoveIndexSignature<ObjectType> = {
|
|
51
|
+
[KeyType in keyof ObjectType
|
|
52
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
53
|
+
as {} extends Record<KeyType, unknown>
|
|
54
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
55
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
56
|
+
]: ObjectType[KeyType];
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
import type {RemoveIndexSignature} from 'type-fest';
|
|
64
|
+
|
|
65
|
+
type RemoveIndexSignature<ObjectType> = {
|
|
66
|
+
[KeyType in keyof ObjectType
|
|
67
|
+
as {} extends Record<KeyType, unknown>
|
|
68
|
+
? never // => Remove this `KeyType`.
|
|
69
|
+
: KeyType // => Keep this `KeyType` as it is.
|
|
70
|
+
]: ObjectType[KeyType];
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
@example
|
|
75
|
+
```
|
|
76
|
+
import type {RemoveIndexSignature} from 'type-fest';
|
|
77
|
+
|
|
78
|
+
interface Example {
|
|
79
|
+
// These index signatures will be removed.
|
|
80
|
+
[x: string]: any
|
|
81
|
+
[x: number]: any
|
|
82
|
+
[x: symbol]: any
|
|
83
|
+
[x: `head-${string}`]: string
|
|
84
|
+
[x: `${string}-tail`]: string
|
|
85
|
+
[x: `head-${string}-tail`]: string
|
|
86
|
+
[x: `${bigint}`]: string
|
|
87
|
+
[x: `embedded-${number}`]: string
|
|
88
|
+
|
|
89
|
+
// These explicitly defined keys will remain.
|
|
90
|
+
foo: 'bar';
|
|
91
|
+
qux?: 'baz';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
type ExampleWithoutIndexSignatures = RemoveIndexSignature<Example>;
|
|
95
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
@category Object
|
|
99
|
+
*/
|
|
100
|
+
export type RemoveIndexSignature<ObjectType> = {
|
|
101
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
102
|
+
? never
|
|
103
|
+
: KeyType]: ObjectType[KeyType];
|
|
104
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
type ReplaceOptions = {
|
|
2
|
+
all?: boolean;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
Represents a string with some or all matches replaced by a replacement.
|
|
7
|
+
|
|
8
|
+
Use-case:
|
|
9
|
+
- `snake-case-path` to `dotted.path.notation`
|
|
10
|
+
- Changing date/time format: `01-08-2042` → `01/08/2042`
|
|
11
|
+
- Manipulation of type properties, for example, removal of prefixes
|
|
12
|
+
|
|
13
|
+
@example
|
|
14
|
+
```
|
|
15
|
+
import {Replace} from 'type-fest';
|
|
16
|
+
|
|
17
|
+
declare function replace<
|
|
18
|
+
Input extends string,
|
|
19
|
+
Search extends string,
|
|
20
|
+
Replacement extends string
|
|
21
|
+
>(
|
|
22
|
+
input: Input,
|
|
23
|
+
search: Search,
|
|
24
|
+
replacement: Replacement
|
|
25
|
+
): Replace<Input, Search, Replacement>;
|
|
26
|
+
|
|
27
|
+
declare function replaceAll<
|
|
28
|
+
Input extends string,
|
|
29
|
+
Search extends string,
|
|
30
|
+
Replacement extends string
|
|
31
|
+
>(
|
|
32
|
+
input: Input,
|
|
33
|
+
search: Search,
|
|
34
|
+
replacement: Replacement
|
|
35
|
+
): Replace<Input, Search, Replacement, {all: true}>;
|
|
36
|
+
|
|
37
|
+
// The return type is the exact string literal, not just `string`.
|
|
38
|
+
|
|
39
|
+
replace('hello ?', '?', '🦄');
|
|
40
|
+
//=> 'hello 🦄'
|
|
41
|
+
|
|
42
|
+
replace('hello ??', '?', '❓');
|
|
43
|
+
//=> 'hello ❓?'
|
|
44
|
+
|
|
45
|
+
replaceAll('10:42:00', ':', '-');
|
|
46
|
+
//=> '10-42-00'
|
|
47
|
+
|
|
48
|
+
replaceAll('__userName__', '__', '');
|
|
49
|
+
//=> 'userName'
|
|
50
|
+
|
|
51
|
+
replaceAll('My Cool Title', ' ', '');
|
|
52
|
+
//=> 'MyCoolTitle'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
@category String
|
|
56
|
+
@category Template literal
|
|
57
|
+
*/
|
|
58
|
+
export type Replace<
|
|
59
|
+
Input extends string,
|
|
60
|
+
Search extends string,
|
|
61
|
+
Replacement extends string,
|
|
62
|
+
Options extends ReplaceOptions = {},
|
|
63
|
+
> = Input extends `${infer Head}${Search}${infer Tail}`
|
|
64
|
+
? Options['all'] extends true
|
|
65
|
+
? `${Head}${Replacement}${Replace<Tail, Search, Replacement, Options>}`
|
|
66
|
+
: `${Head}${Replacement}${Tail}`
|
|
67
|
+
: Input;
|