serverless-spy 0.0.60 → 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 +4 -3
- package/README.md +1 -1
- package/_config.yml +14 -3
- package/assets/images/site-logo.png +0 -0
- package/dist/releasetag.txt +1 -1
- package/doc/Lambda.md +2 -0
- 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
- package/doc/sample_app.md +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {PromiseValue} from './promise-value';
|
|
2
|
+
|
|
3
|
+
type AsyncFunction = (...args: any[]) => Promise<unknown>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
Unwrap the return type of a function that returns a `Promise`.
|
|
7
|
+
|
|
8
|
+
There has been [discussion](https://github.com/microsoft/TypeScript/pull/35998) about implementing this type in TypeScript.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```ts
|
|
12
|
+
import type {AsyncReturnType} from 'type-fest';
|
|
13
|
+
import {asyncFunction} from 'api';
|
|
14
|
+
|
|
15
|
+
// This type resolves to the unwrapped return type of `asyncFunction`.
|
|
16
|
+
type Value = AsyncReturnType<typeof asyncFunction>;
|
|
17
|
+
|
|
18
|
+
async function doSomething(value: Value) {}
|
|
19
|
+
|
|
20
|
+
asyncFunction().then(value => doSomething(value));
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
@category Async
|
|
24
|
+
*/
|
|
25
|
+
export type AsyncReturnType<Target extends AsyncFunction> = PromiseValue<ReturnType<Target>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type {PromiseValue} from './promise-value';
|
|
2
|
+
import type {SetReturnType} from './set-return-type';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types.
|
|
6
|
+
|
|
7
|
+
Use-case: You have two functions, one synchronous and one asynchronous that do the same thing. Instead of having to duplicate the type definition, you can use `Asyncify` to reuse the synchronous type.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import type {Asyncify} from 'type-fest';
|
|
12
|
+
|
|
13
|
+
// Synchronous function.
|
|
14
|
+
function getFooSync(someArg: SomeType): Foo {
|
|
15
|
+
// …
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type AsyncifiedFooGetter = Asyncify<typeof getFooSync>;
|
|
19
|
+
//=> type AsyncifiedFooGetter = (someArg: SomeType) => Promise<Foo>;
|
|
20
|
+
|
|
21
|
+
// Same as `getFooSync` but asynchronous.
|
|
22
|
+
const getFooAsync: AsyncifiedFooGetter = (someArg) => {
|
|
23
|
+
// TypeScript now knows that `someArg` is `SomeType` automatically.
|
|
24
|
+
// It also knows that this function must return `Promise<Foo>`.
|
|
25
|
+
// If you have `@typescript-eslint/promise-function-async` linter rule enabled, it will even report that "Functions that return promises must be async.".
|
|
26
|
+
|
|
27
|
+
// …
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
@category Async
|
|
32
|
+
*/
|
|
33
|
+
export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<PromiseValue<ReturnType<Fn>>>>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
3
|
+
|
|
4
|
+
@category Class
|
|
5
|
+
*/
|
|
6
|
+
export type Class<T, Arguments extends unknown[] = any[]> = Constructor<T, Arguments> & {prototype: T};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
10
|
+
|
|
11
|
+
@category Class
|
|
12
|
+
*/
|
|
13
|
+
export type Constructor<T, Arguments extends unknown[] = any[]> = new(...arguments_: Arguments) => T;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
Matches a JSON object.
|
|
17
|
+
|
|
18
|
+
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
|
|
19
|
+
|
|
20
|
+
@category JSON
|
|
21
|
+
*/
|
|
22
|
+
export type JsonObject = {[Key in string]?: JsonValue};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
Matches a JSON array.
|
|
26
|
+
|
|
27
|
+
@category JSON
|
|
28
|
+
*/
|
|
29
|
+
export type JsonArray = JsonValue[];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
Matches any valid JSON primitive value.
|
|
33
|
+
|
|
34
|
+
@category JSON
|
|
35
|
+
*/
|
|
36
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
Matches any valid JSON value.
|
|
40
|
+
|
|
41
|
+
@see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
|
|
42
|
+
|
|
43
|
+
@category JSON
|
|
44
|
+
*/
|
|
45
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type {WordSeparators} from '../source/internal';
|
|
2
|
+
import type {Split} from './split';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Step by step takes the first item in an array literal, formats it and adds it to a string literal, and then recursively appends the remainder.
|
|
6
|
+
|
|
7
|
+
Only to be used by `CamelCaseStringArray<>`.
|
|
8
|
+
|
|
9
|
+
@see CamelCaseStringArray
|
|
10
|
+
*/
|
|
11
|
+
type InnerCamelCaseStringArray<Parts extends readonly any[], PreviousPart> =
|
|
12
|
+
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
|
13
|
+
? FirstPart extends undefined
|
|
14
|
+
? ''
|
|
15
|
+
: FirstPart extends ''
|
|
16
|
+
? InnerCamelCaseStringArray<RemainingParts, PreviousPart>
|
|
17
|
+
: `${PreviousPart extends '' ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`
|
|
18
|
+
: '';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
Starts fusing the output of `Split<>`, an array literal of strings, into a camel-cased string literal.
|
|
22
|
+
|
|
23
|
+
It's separate from `InnerCamelCaseStringArray<>` to keep a clean API outwards to the rest of the code.
|
|
24
|
+
|
|
25
|
+
@see Split
|
|
26
|
+
*/
|
|
27
|
+
type CamelCaseStringArray<Parts extends readonly string[]> =
|
|
28
|
+
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
|
29
|
+
? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`>
|
|
30
|
+
: never;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
Convert a string literal to camel-case.
|
|
34
|
+
|
|
35
|
+
This can be useful when, for example, converting some kebab-cased command-line flags or a snake-cased database result.
|
|
36
|
+
|
|
37
|
+
@example
|
|
38
|
+
```
|
|
39
|
+
import type {CamelCase} from 'type-fest';
|
|
40
|
+
|
|
41
|
+
// Simple
|
|
42
|
+
|
|
43
|
+
const someVariable: CamelCase<'foo-bar'> = 'fooBar';
|
|
44
|
+
|
|
45
|
+
// Advanced
|
|
46
|
+
|
|
47
|
+
type CamelCasedProperties<T> = {
|
|
48
|
+
[K in keyof T as CamelCase<K>]: T[K]
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface RawOptions {
|
|
52
|
+
'dry-run': boolean;
|
|
53
|
+
'full_family_name': string;
|
|
54
|
+
foo: number;
|
|
55
|
+
BAR: string;
|
|
56
|
+
QUZ_QUX: number;
|
|
57
|
+
'OTHER-FIELD': boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const dbResult: CamelCasedProperties<RawOptions> = {
|
|
61
|
+
dryRun: true,
|
|
62
|
+
fullFamilyName: 'bar.js',
|
|
63
|
+
foo: 123,
|
|
64
|
+
bar: 'foo',
|
|
65
|
+
quzQux: 6,
|
|
66
|
+
otherField: false
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
@category Change case
|
|
71
|
+
@category Template literal
|
|
72
|
+
*/
|
|
73
|
+
export type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K extends Uppercase<K> ? Lowercase<K> : K, WordSeparators>> : K;
|
package/node_modules/serialize-error/node_modules/type-fest/source/camel-cased-properties-deep.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {CamelCase} from './camel-case';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Convert object properties to camel case recursively.
|
|
5
|
+
|
|
6
|
+
This can be useful when, for example, converting some API types from a different style.
|
|
7
|
+
|
|
8
|
+
@see CamelCasedProperties
|
|
9
|
+
@see CamelCase
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import type {CamelCasedPropertiesDeep} 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: CamelCasedPropertiesDeep<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 CamelCasedPropertiesDeep<Value> = Value extends Function
|
|
48
|
+
? Value
|
|
49
|
+
: Value extends Array<infer U>
|
|
50
|
+
? Array<CamelCasedPropertiesDeep<U>>
|
|
51
|
+
: Value extends Set<infer U>
|
|
52
|
+
? Set<CamelCasedPropertiesDeep<U>> : {
|
|
53
|
+
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>;
|
|
54
|
+
};
|
package/node_modules/serialize-error/node_modules/type-fest/source/camel-cased-properties.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {CamelCase} from './camel-case';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Convert object properties to camel case but not recursively.
|
|
5
|
+
|
|
6
|
+
This can be useful when, for example, converting some API types from a different style.
|
|
7
|
+
|
|
8
|
+
@see CamelCasedPropertiesDeep
|
|
9
|
+
@see CamelCase
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import type {CamelCasedProperties} from 'type-fest';
|
|
14
|
+
|
|
15
|
+
interface User {
|
|
16
|
+
UserId: number;
|
|
17
|
+
UserName: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const result: CamelCasedProperties<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 CamelCasedProperties<Value> = Value extends Function
|
|
31
|
+
? Value
|
|
32
|
+
: Value extends Array<infer U>
|
|
33
|
+
? Value
|
|
34
|
+
: {
|
|
35
|
+
[K in keyof Value as CamelCase<K>]: Value[K];
|
|
36
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {Except} from './except';
|
|
2
|
+
import type {ConditionalKeys} from './conditional-keys';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Exclude keys from a shape that matches the given `Condition`.
|
|
6
|
+
|
|
7
|
+
This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import type {Primitive, ConditionalExcept} from 'type-fest';
|
|
12
|
+
|
|
13
|
+
class Awesome {
|
|
14
|
+
name: string;
|
|
15
|
+
successes: number;
|
|
16
|
+
failures: bigint;
|
|
17
|
+
|
|
18
|
+
run() {}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
|
|
22
|
+
//=> {run: () => void}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
@example
|
|
26
|
+
```
|
|
27
|
+
import type {ConditionalExcept} from 'type-fest';
|
|
28
|
+
|
|
29
|
+
interface Example {
|
|
30
|
+
a: string;
|
|
31
|
+
b: string | number;
|
|
32
|
+
c: () => void;
|
|
33
|
+
d: {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
|
37
|
+
//=> {b: string | number; c: () => void; d: {}}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
@category Object
|
|
41
|
+
*/
|
|
42
|
+
export type ConditionalExcept<Base, Condition> = Except<
|
|
43
|
+
Base,
|
|
44
|
+
ConditionalKeys<Base, Condition>
|
|
45
|
+
>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Extract the keys from a type where the value type of the key extends the given `Condition`.
|
|
3
|
+
|
|
4
|
+
Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
interface Example {
|
|
11
|
+
a: string;
|
|
12
|
+
b: string | number;
|
|
13
|
+
c?: string;
|
|
14
|
+
d: {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type StringKeysOnly = ConditionalKeys<Example, string>;
|
|
18
|
+
//=> 'a'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
|
|
22
|
+
|
|
23
|
+
@example
|
|
24
|
+
```
|
|
25
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
26
|
+
|
|
27
|
+
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
28
|
+
//=> 'a' | 'c'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
@category Object
|
|
32
|
+
*/
|
|
33
|
+
export type ConditionalKeys<Base, Condition> = NonNullable<
|
|
34
|
+
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
|
35
|
+
{
|
|
36
|
+
// Map through all the keys of the given base type.
|
|
37
|
+
[Key in keyof Base]:
|
|
38
|
+
// Pick only keys with types extending the given `Condition` type.
|
|
39
|
+
Base[Key] extends Condition
|
|
40
|
+
// Retain this key since the condition passes.
|
|
41
|
+
? Key
|
|
42
|
+
// Discard this key since the condition fails.
|
|
43
|
+
: never;
|
|
44
|
+
|
|
45
|
+
// Convert the produced object into a union type of the keys which passed the conditional test.
|
|
46
|
+
}[keyof Base]
|
|
47
|
+
>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type {ConditionalKeys} from './conditional-keys';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Pick keys from the shape that matches the given `Condition`.
|
|
5
|
+
|
|
6
|
+
This is useful when you want to create a new type from a specific subset of an existing type. For example, you might want to pick all the primitive properties from a class and form a new automatically derived type.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {Primitive, ConditionalPick} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
class Awesome {
|
|
13
|
+
name: string;
|
|
14
|
+
successes: number;
|
|
15
|
+
failures: bigint;
|
|
16
|
+
|
|
17
|
+
run() {}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type PickPrimitivesFromAwesome = ConditionalPick<Awesome, Primitive>;
|
|
21
|
+
//=> {name: string; successes: number; failures: bigint}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
@example
|
|
25
|
+
```
|
|
26
|
+
import type {ConditionalPick} from 'type-fest';
|
|
27
|
+
|
|
28
|
+
interface Example {
|
|
29
|
+
a: string;
|
|
30
|
+
b: string | number;
|
|
31
|
+
c: () => void;
|
|
32
|
+
d: {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type StringKeysOnly = ConditionalPick<Example, string>;
|
|
36
|
+
//=> {a: string}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
@category Object
|
|
40
|
+
*/
|
|
41
|
+
export type ConditionalPick<Base, Condition> = Pick<
|
|
42
|
+
Base,
|
|
43
|
+
ConditionalKeys<Base, Condition>
|
|
44
|
+
>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type {UpperCaseCharacters, WordSeparators} from '../source/internal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Unlike a simpler split, this one includes the delimiter splitted on in the resulting array literal. This is to enable splitting on, for example, upper-case characters.
|
|
5
|
+
|
|
6
|
+
@category Template literal
|
|
7
|
+
*/
|
|
8
|
+
export type SplitIncludingDelimiters<Source extends string, Delimiter extends string> =
|
|
9
|
+
Source extends '' ? [] :
|
|
10
|
+
Source extends `${infer FirstPart}${Delimiter}${infer SecondPart}` ?
|
|
11
|
+
(
|
|
12
|
+
Source extends `${FirstPart}${infer UsedDelimiter}${SecondPart}`
|
|
13
|
+
? UsedDelimiter extends Delimiter
|
|
14
|
+
? Source extends `${infer FirstPart}${UsedDelimiter}${infer SecondPart}`
|
|
15
|
+
? [...SplitIncludingDelimiters<FirstPart, Delimiter>, UsedDelimiter, ...SplitIncludingDelimiters<SecondPart, Delimiter>]
|
|
16
|
+
: never
|
|
17
|
+
: never
|
|
18
|
+
: never
|
|
19
|
+
) :
|
|
20
|
+
[Source];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
Format a specific part of the splitted string literal that `StringArrayToDelimiterCase<>` fuses together, ensuring desired casing.
|
|
24
|
+
|
|
25
|
+
@see StringArrayToDelimiterCase
|
|
26
|
+
*/
|
|
27
|
+
type StringPartToDelimiterCase<StringPart extends string, Start extends boolean, UsedWordSeparators extends string, UsedUpperCaseCharacters extends string, Delimiter extends string> =
|
|
28
|
+
StringPart extends UsedWordSeparators ? Delimiter :
|
|
29
|
+
Start extends true ? Lowercase<StringPart> :
|
|
30
|
+
StringPart extends UsedUpperCaseCharacters ? `${Delimiter}${Lowercase<StringPart>}` :
|
|
31
|
+
StringPart;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
Takes the result of a splitted string literal and recursively concatenates it together into the desired casing.
|
|
35
|
+
|
|
36
|
+
It receives `UsedWordSeparators` and `UsedUpperCaseCharacters` as input to ensure it's fully encapsulated.
|
|
37
|
+
|
|
38
|
+
@see SplitIncludingDelimiters
|
|
39
|
+
*/
|
|
40
|
+
type StringArrayToDelimiterCase<Parts extends readonly any[], Start extends boolean, UsedWordSeparators extends string, UsedUpperCaseCharacters extends string, Delimiter extends string> =
|
|
41
|
+
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
|
42
|
+
? `${StringPartToDelimiterCase<FirstPart, Start, UsedWordSeparators, UsedUpperCaseCharacters, Delimiter>}${StringArrayToDelimiterCase<RemainingParts, false, UsedWordSeparators, UsedUpperCaseCharacters, Delimiter>}`
|
|
43
|
+
: Parts extends [string]
|
|
44
|
+
? string
|
|
45
|
+
: '';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
Convert a string literal to a custom string delimiter casing.
|
|
49
|
+
|
|
50
|
+
This can be useful when, for example, converting a camel-cased object property to an oddly cased one.
|
|
51
|
+
|
|
52
|
+
@see KebabCase
|
|
53
|
+
@see SnakeCase
|
|
54
|
+
|
|
55
|
+
@example
|
|
56
|
+
```
|
|
57
|
+
import type {DelimiterCase} from 'type-fest';
|
|
58
|
+
|
|
59
|
+
// Simple
|
|
60
|
+
|
|
61
|
+
const someVariable: DelimiterCase<'fooBar', '#'> = 'foo#bar';
|
|
62
|
+
|
|
63
|
+
// Advanced
|
|
64
|
+
|
|
65
|
+
type OddlyCasedProperties<T> = {
|
|
66
|
+
[K in keyof T as DelimiterCase<K, '#'>]: T[K]
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
interface SomeOptions {
|
|
70
|
+
dryRun: boolean;
|
|
71
|
+
includeFile: string;
|
|
72
|
+
foo: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
|
|
76
|
+
'dry#run': true,
|
|
77
|
+
'include#file': 'bar.js',
|
|
78
|
+
foo: 123
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
@category Change case
|
|
83
|
+
@category Template literal
|
|
84
|
+
*/
|
|
85
|
+
export type DelimiterCase<Value, Delimiter extends string> = Value extends string
|
|
86
|
+
? StringArrayToDelimiterCase<
|
|
87
|
+
SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>,
|
|
88
|
+
true,
|
|
89
|
+
WordSeparators,
|
|
90
|
+
UpperCaseCharacters,
|
|
91
|
+
Delimiter
|
|
92
|
+
>
|
|
93
|
+
: Value;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {DelimiterCase} from './delimiter-case';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Convert object properties to delimiter case recursively.
|
|
5
|
+
|
|
6
|
+
This can be useful when, for example, converting some API types from a different style.
|
|
7
|
+
|
|
8
|
+
@see DelimiterCase
|
|
9
|
+
@see DelimiterCasedProperties
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import type {DelimiterCasedPropertiesDeep} 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: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
|
|
26
|
+
'user-info': {
|
|
27
|
+
'user-id': 1,
|
|
28
|
+
'user-name': 'Tom',
|
|
29
|
+
},
|
|
30
|
+
'user-friends': [
|
|
31
|
+
{
|
|
32
|
+
'user-id': 2,
|
|
33
|
+
'user-name': 'Jerry',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
'user-id': 3,
|
|
37
|
+
'user-name': 'Spike',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
@category Change case
|
|
44
|
+
@category Template literal
|
|
45
|
+
@category Object
|
|
46
|
+
*/
|
|
47
|
+
export type DelimiterCasedPropertiesDeep<
|
|
48
|
+
Value,
|
|
49
|
+
Delimiter extends string,
|
|
50
|
+
> = Value extends Function | Date | RegExp
|
|
51
|
+
? Value
|
|
52
|
+
: Value extends Array<infer U>
|
|
53
|
+
? Array<DelimiterCasedPropertiesDeep<U, Delimiter>>
|
|
54
|
+
: Value extends Set<infer U>
|
|
55
|
+
? Set<DelimiterCasedPropertiesDeep<U, Delimiter>> : {
|
|
56
|
+
[K in keyof Value as DelimiterCase<
|
|
57
|
+
K,
|
|
58
|
+
Delimiter
|
|
59
|
+
>]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>;
|
|
60
|
+
};
|
package/node_modules/serialize-error/node_modules/type-fest/source/delimiter-cased-properties.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type {DelimiterCase} from './delimiter-case';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Convert object properties to delimiter case but not recursively.
|
|
5
|
+
|
|
6
|
+
This can be useful when, for example, converting some API types from a different style.
|
|
7
|
+
|
|
8
|
+
@see DelimiterCase
|
|
9
|
+
@see DelimiterCasedPropertiesDeep
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import type {DelimiterCasedProperties} from 'type-fest';
|
|
14
|
+
|
|
15
|
+
interface User {
|
|
16
|
+
userId: number;
|
|
17
|
+
userName: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const result: DelimiterCasedProperties<User, '-'> = {
|
|
21
|
+
'user-id': 1,
|
|
22
|
+
'user-name': 'Tom',
|
|
23
|
+
};
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
@category Change case
|
|
27
|
+
@category Template literal
|
|
28
|
+
@category Object
|
|
29
|
+
*/
|
|
30
|
+
export type DelimiterCasedProperties<
|
|
31
|
+
Value,
|
|
32
|
+
Delimiter extends string,
|
|
33
|
+
> = Value extends Function
|
|
34
|
+
? Value
|
|
35
|
+
: Value extends Array<infer U>
|
|
36
|
+
? Value
|
|
37
|
+
: {[K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K]};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type {ArrayEntry, MapEntry, ObjectEntry, SetEntry} from './entry';
|
|
2
|
+
|
|
3
|
+
type ArrayEntries<BaseType extends readonly unknown[]> = Array<ArrayEntry<BaseType>>;
|
|
4
|
+
type MapEntries<BaseType> = Array<MapEntry<BaseType>>;
|
|
5
|
+
type ObjectEntries<BaseType> = Array<ObjectEntry<BaseType>>;
|
|
6
|
+
type SetEntries<BaseType extends Set<unknown>> = Array<SetEntry<BaseType>>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entries` type will return the type of that collection's entries.
|
|
10
|
+
|
|
11
|
+
For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
|
|
12
|
+
|
|
13
|
+
@see `Entry` if you want to just access the type of a single entry.
|
|
14
|
+
|
|
15
|
+
@example
|
|
16
|
+
```
|
|
17
|
+
import type {Entries} from 'type-fest';
|
|
18
|
+
|
|
19
|
+
interface Example {
|
|
20
|
+
someKey: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const manipulatesEntries = (examples: Entries<Example>) => examples.map(example => [
|
|
24
|
+
// Does some arbitrary processing on the key (with type information available)
|
|
25
|
+
example[0].toUpperCase(),
|
|
26
|
+
|
|
27
|
+
// Does some arbitrary processing on the value (with type information available)
|
|
28
|
+
example[1].toFixed()
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const example: Example = {someKey: 1};
|
|
32
|
+
const entries = Object.entries(example) as Entries<Example>;
|
|
33
|
+
const output = manipulatesEntries(entries);
|
|
34
|
+
|
|
35
|
+
// Objects
|
|
36
|
+
const objectExample = {a: 1};
|
|
37
|
+
const objectEntries: Entries<typeof objectExample> = [['a', 1]];
|
|
38
|
+
|
|
39
|
+
// Arrays
|
|
40
|
+
const arrayExample = ['a', 1];
|
|
41
|
+
const arrayEntries: Entries<typeof arrayExample> = [[0, 'a'], [1, 1]];
|
|
42
|
+
|
|
43
|
+
// Maps
|
|
44
|
+
const mapExample = new Map([['a', 1]]);
|
|
45
|
+
const mapEntries: Entries<typeof map> = [['a', 1]];
|
|
46
|
+
|
|
47
|
+
// Sets
|
|
48
|
+
const setExample = new Set(['a', 1]);
|
|
49
|
+
const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
@category Object
|
|
53
|
+
@category Map
|
|
54
|
+
@category Set
|
|
55
|
+
@category Array
|
|
56
|
+
*/
|
|
57
|
+
export type Entries<BaseType> =
|
|
58
|
+
BaseType extends Map<unknown, unknown> ? MapEntries<BaseType>
|
|
59
|
+
: BaseType extends Set<unknown> ? SetEntries<BaseType>
|
|
60
|
+
: BaseType extends readonly unknown[] ? ArrayEntries<BaseType>
|
|
61
|
+
: BaseType extends object ? ObjectEntries<BaseType>
|
|
62
|
+
: never;
|