@esposter/shared 1.41.0 → 1.42.0
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/dist/index.d.ts +793 -26
- package/dist/index.js +43608 -61740
- package/package.json +3 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,72 +1,839 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/util/parseXmlString.d.ts
|
|
2
|
+
declare const parseXmlString: <T extends object>(xmlString: string) => Promise<T>;
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const parseXmlValue: (value: string) =>
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/util/parseXmlValue.d.ts
|
|
6
|
+
declare const parseXmlValue: (value: string) => boolean | number | string;
|
|
6
7
|
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/models/shared/Operation.d.ts
|
|
7
10
|
declare enum Operation {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Create = "Create",
|
|
12
|
+
Delete = "Delete",
|
|
13
|
+
Push = "Push",
|
|
14
|
+
Read = "Read",
|
|
15
|
+
Update = "Update"
|
|
13
16
|
}
|
|
14
17
|
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/models/error/InvalidOperationError.d.ts
|
|
15
20
|
declare class InvalidOperationError extends Error {
|
|
16
|
-
|
|
21
|
+
constructor(operation: Operation, name: string, message: string);
|
|
17
22
|
}
|
|
18
23
|
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/models/error/NotFoundError.d.ts
|
|
19
26
|
declare class NotFoundError<T extends string = string> extends Error {
|
|
20
|
-
|
|
27
|
+
constructor(name: T, id: string);
|
|
21
28
|
}
|
|
22
29
|
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/models/error/NotInitializedError.d.ts
|
|
23
32
|
declare class NotInitializedError<T extends string = string> extends Error {
|
|
24
|
-
|
|
33
|
+
constructor(name: T);
|
|
25
34
|
}
|
|
26
35
|
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/util/id/constants.d.ts
|
|
27
38
|
declare const ID_SEPARATOR = "|";
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/util/object/isPlainObject.d.ts
|
|
42
|
+
declare const isPlainObject: (data: unknown) => data is object;
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} ? TRemaining extends object[] ? MergeObjectsStrict<[TSecond, ...TRemaining]> & TFirst : TFirst & TSecond : never : T extends [infer TFirst] ? TFirst : never;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/util/types/MergeObjectsStrict.d.ts
|
|
46
|
+
type MergeObjectsStrict<T extends object[]> = T extends [infer TFirst, infer TSecond, ...infer TRemaining] ? TSecond extends { [K in keyof TSecond] : K extends keyof TFirst ? never : TSecond[K] } ? TRemaining extends object[] ? MergeObjectsStrict<[TSecond, ...TRemaining]> & TFirst : TFirst & TSecond : never : T extends [infer TFirst] ? TFirst : never;
|
|
34
47
|
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/util/object/mergeObjectsStrict.d.ts
|
|
35
50
|
declare const mergeObjectsStrict: <T extends object[]>(...objects: T) => MergeObjectsStrict<T>;
|
|
36
51
|
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/util/text/capitalize.d.ts
|
|
37
54
|
declare const capitalize: (string: string) => string;
|
|
38
55
|
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/util/types/CamelToKebab.d.ts
|
|
39
58
|
type CamelToKebab<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Uncapitalize<T>}${CamelToKebab<U>}` : `${Uncapitalize<T>}-${CamelToKebab<U>}` : S;
|
|
40
59
|
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/util/text/toKebabCase.d.ts
|
|
41
62
|
declare const toKebabCase: <T extends string>(string: T) => CamelToKebab<T>;
|
|
42
63
|
|
|
43
|
-
|
|
44
|
-
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/util/types/FunctionProperties.d.ts
|
|
66
|
+
type FunctionProperties<T> = { [K in keyof T] : T[K] extends Function ? K : never };
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/observable-like.d.ts
|
|
70
|
+
declare global {
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
72
|
+
interface SymbolConstructor {
|
|
73
|
+
readonly observable: symbol;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
79
|
+
/**
|
|
80
|
+
Extract all optional keys from the given type.
|
|
81
|
+
|
|
82
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
83
|
+
|
|
84
|
+
@example
|
|
85
|
+
```
|
|
86
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
87
|
+
|
|
88
|
+
interface User {
|
|
89
|
+
name: string;
|
|
90
|
+
surname: string;
|
|
91
|
+
|
|
92
|
+
luckyNumber?: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
96
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
97
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const update1: UpdateOperation<User> = {
|
|
101
|
+
name: 'Alice'
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const update2: UpdateOperation<User> = {
|
|
105
|
+
name: 'Bob',
|
|
106
|
+
luckyNumber: REMOVE_FIELD
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
@category Utilities
|
|
111
|
+
*/
|
|
112
|
+
type OptionalKeysOf<BaseType extends object> =
|
|
113
|
+
BaseType extends unknown // For distributing `BaseType`
|
|
114
|
+
? (keyof {
|
|
115
|
+
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
|
116
|
+
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
117
|
+
: never;
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
121
|
+
/**
|
|
122
|
+
Extract all required keys from the given type.
|
|
123
|
+
|
|
124
|
+
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
125
|
+
|
|
126
|
+
@example
|
|
127
|
+
```
|
|
128
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
129
|
+
|
|
130
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
131
|
+
|
|
132
|
+
interface User {
|
|
133
|
+
name: string;
|
|
134
|
+
surname: string;
|
|
135
|
+
|
|
136
|
+
luckyNumber?: number;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
140
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
@category Utilities
|
|
144
|
+
*/
|
|
145
|
+
type RequiredKeysOf<BaseType extends object> =
|
|
146
|
+
BaseType extends unknown // For distributing `BaseType`
|
|
147
|
+
? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
|
|
148
|
+
: never;
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/is-never.d.ts
|
|
152
|
+
/**
|
|
153
|
+
Returns a boolean for whether the given type is `never`.
|
|
154
|
+
|
|
155
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
156
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
157
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
158
|
+
|
|
159
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
160
|
+
|
|
161
|
+
@example
|
|
162
|
+
```
|
|
163
|
+
import type {IsNever, And} from 'type-fest';
|
|
164
|
+
|
|
165
|
+
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
166
|
+
type AreStringsEqual<A extends string, B extends string> =
|
|
167
|
+
And<
|
|
168
|
+
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
169
|
+
IsNever<Exclude<B, A>> extends true ? true : false
|
|
170
|
+
>;
|
|
171
|
+
|
|
172
|
+
type EndIfEqual<I extends string, O extends string> =
|
|
173
|
+
AreStringsEqual<I, O> extends true
|
|
174
|
+
? never
|
|
175
|
+
: void;
|
|
176
|
+
|
|
177
|
+
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
178
|
+
if (input === output) {
|
|
179
|
+
process.exit(0);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
endIfEqual('abc', 'abc');
|
|
184
|
+
//=> never
|
|
185
|
+
|
|
186
|
+
endIfEqual('abc', '123');
|
|
187
|
+
//=> void
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
@category Type Guard
|
|
191
|
+
@category Utilities
|
|
192
|
+
*/
|
|
193
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
194
|
+
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/if-never.d.ts
|
|
197
|
+
/**
|
|
198
|
+
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
199
|
+
|
|
200
|
+
@see {@link IsNever}
|
|
201
|
+
|
|
202
|
+
@example
|
|
203
|
+
```
|
|
204
|
+
import type {IfNever} from 'type-fest';
|
|
205
|
+
|
|
206
|
+
type ShouldBeTrue = IfNever<never>;
|
|
207
|
+
//=> true
|
|
208
|
+
|
|
209
|
+
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
210
|
+
//=> 'bar'
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
@category Type Guard
|
|
214
|
+
@category Utilities
|
|
215
|
+
*/
|
|
216
|
+
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
|
217
|
+
IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/is-any.d.ts
|
|
222
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
223
|
+
/**
|
|
224
|
+
Returns a boolean for whether the given type is `any`.
|
|
225
|
+
|
|
226
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
227
|
+
|
|
228
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
229
|
+
|
|
230
|
+
@example
|
|
231
|
+
```
|
|
232
|
+
import type {IsAny} from 'type-fest';
|
|
233
|
+
|
|
234
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
235
|
+
const anyObject: any = {a: 1, b: 2};
|
|
236
|
+
|
|
237
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
238
|
+
return obj[key];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const typedA = get(typedObject, 'a');
|
|
242
|
+
//=> 1
|
|
243
|
+
|
|
244
|
+
const anyA = get(anyObject, 'a');
|
|
245
|
+
//=> any
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
@category Type Guard
|
|
249
|
+
@category Utilities
|
|
250
|
+
*/
|
|
251
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
252
|
+
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/is-equal.d.ts
|
|
255
|
+
/**
|
|
256
|
+
Returns a boolean for whether the two given types are equal.
|
|
257
|
+
|
|
258
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
259
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
260
|
+
|
|
261
|
+
Use-cases:
|
|
262
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
263
|
+
|
|
264
|
+
@example
|
|
265
|
+
```
|
|
266
|
+
import type {IsEqual} from 'type-fest';
|
|
267
|
+
|
|
268
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
269
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
270
|
+
type Includes<Value extends readonly any[], Item> =
|
|
271
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
272
|
+
? IsEqual<Value[0], Item> extends true
|
|
273
|
+
? true
|
|
274
|
+
: Includes<rest, Item>
|
|
275
|
+
: false;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
@category Type Guard
|
|
279
|
+
@category Utilities
|
|
280
|
+
*/
|
|
281
|
+
type IsEqual<A, B> =
|
|
282
|
+
(<G>() => G extends A & G | G ? 1 : 2) extends
|
|
283
|
+
(<G>() => G extends B & G | G ? 1 : 2)
|
|
284
|
+
? true
|
|
285
|
+
: false;
|
|
286
|
+
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/simplify.d.ts
|
|
289
|
+
/**
|
|
290
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
291
|
+
|
|
292
|
+
@example
|
|
293
|
+
```
|
|
294
|
+
import type {Simplify} from 'type-fest';
|
|
295
|
+
|
|
296
|
+
type PositionProps = {
|
|
297
|
+
top: number;
|
|
298
|
+
left: number;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
type SizeProps = {
|
|
302
|
+
width: number;
|
|
303
|
+
height: number;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
307
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
311
|
+
|
|
312
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
313
|
+
|
|
314
|
+
@example
|
|
315
|
+
```
|
|
316
|
+
import type {Simplify} from 'type-fest';
|
|
317
|
+
|
|
318
|
+
interface SomeInterface {
|
|
319
|
+
foo: number;
|
|
320
|
+
bar?: string;
|
|
321
|
+
baz: number | undefined;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
type SomeType = {
|
|
325
|
+
foo: number;
|
|
326
|
+
bar?: string;
|
|
327
|
+
baz: number | undefined;
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
331
|
+
const someType: SomeType = literal;
|
|
332
|
+
const someInterface: SomeInterface = literal;
|
|
333
|
+
|
|
334
|
+
function fn(object: Record<string, unknown>): void {}
|
|
335
|
+
|
|
336
|
+
fn(literal); // Good: literal object type is sealed
|
|
337
|
+
fn(someType); // Good: type is sealed
|
|
338
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
339
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
343
|
+
@see SimplifyDeep
|
|
344
|
+
@category Object
|
|
345
|
+
*/
|
|
346
|
+
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
|
|
347
|
+
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
350
|
+
/**
|
|
351
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
352
|
+
|
|
353
|
+
This is the counterpart of `PickIndexSignature`.
|
|
354
|
+
|
|
355
|
+
Use-cases:
|
|
356
|
+
- Remove overly permissive signatures from third-party types.
|
|
357
|
+
|
|
358
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
359
|
+
|
|
360
|
+
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>`.
|
|
361
|
+
|
|
362
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
366
|
+
|
|
367
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
368
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
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:
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
type Indexed = {} extends Record<string, unknown>
|
|
375
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
376
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
377
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
378
|
+
|
|
379
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
380
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
381
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
382
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
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`...
|
|
386
|
+
|
|
387
|
+
```
|
|
388
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
389
|
+
|
|
390
|
+
type OmitIndexSignature<ObjectType> = {
|
|
391
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
392
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
393
|
+
};
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
397
|
+
|
|
398
|
+
```
|
|
399
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
400
|
+
|
|
401
|
+
type OmitIndexSignature<ObjectType> = {
|
|
402
|
+
[KeyType in keyof ObjectType
|
|
403
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
404
|
+
as {} extends Record<KeyType, unknown>
|
|
405
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
406
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
407
|
+
]: ObjectType[KeyType];
|
|
408
|
+
};
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
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.
|
|
412
|
+
|
|
413
|
+
@example
|
|
414
|
+
```
|
|
415
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
416
|
+
|
|
417
|
+
interface Example {
|
|
418
|
+
// These index signatures will be removed.
|
|
419
|
+
[x: string]: any
|
|
420
|
+
[x: number]: any
|
|
421
|
+
[x: symbol]: any
|
|
422
|
+
[x: `head-${string}`]: string
|
|
423
|
+
[x: `${string}-tail`]: string
|
|
424
|
+
[x: `head-${string}-tail`]: string
|
|
425
|
+
[x: `${bigint}`]: string
|
|
426
|
+
[x: `embedded-${number}`]: string
|
|
427
|
+
|
|
428
|
+
// These explicitly defined keys will remain.
|
|
429
|
+
foo: 'bar';
|
|
430
|
+
qux?: 'baz';
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
434
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
@see PickIndexSignature
|
|
438
|
+
@category Object
|
|
439
|
+
*/
|
|
440
|
+
type OmitIndexSignature<ObjectType> = {
|
|
441
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
442
|
+
? never
|
|
443
|
+
: KeyType]: ObjectType[KeyType];
|
|
45
444
|
};
|
|
46
445
|
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
448
|
+
/**
|
|
449
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
450
|
+
|
|
451
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
452
|
+
|
|
453
|
+
@example
|
|
454
|
+
```
|
|
455
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
456
|
+
|
|
457
|
+
declare const symbolKey: unique symbol;
|
|
458
|
+
|
|
459
|
+
type Example = {
|
|
460
|
+
// These index signatures will remain.
|
|
461
|
+
[x: string]: unknown;
|
|
462
|
+
[x: number]: unknown;
|
|
463
|
+
[x: symbol]: unknown;
|
|
464
|
+
[x: `head-${string}`]: string;
|
|
465
|
+
[x: `${string}-tail`]: string;
|
|
466
|
+
[x: `head-${string}-tail`]: string;
|
|
467
|
+
[x: `${bigint}`]: string;
|
|
468
|
+
[x: `embedded-${number}`]: string;
|
|
469
|
+
|
|
470
|
+
// These explicitly defined keys will be removed.
|
|
471
|
+
['kebab-case-key']: string;
|
|
472
|
+
[symbolKey]: string;
|
|
473
|
+
foo: 'bar';
|
|
474
|
+
qux?: 'baz';
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
478
|
+
// {
|
|
479
|
+
// [x: string]: unknown;
|
|
480
|
+
// [x: number]: unknown;
|
|
481
|
+
// [x: symbol]: unknown;
|
|
482
|
+
// [x: `head-${string}`]: string;
|
|
483
|
+
// [x: `${string}-tail`]: string;
|
|
484
|
+
// [x: `head-${string}-tail`]: string;
|
|
485
|
+
// [x: `${bigint}`]: string;
|
|
486
|
+
// [x: `embedded-${number}`]: string;
|
|
487
|
+
// }
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
@see OmitIndexSignature
|
|
491
|
+
@category Object
|
|
492
|
+
*/
|
|
493
|
+
type PickIndexSignature<ObjectType> = {
|
|
494
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
495
|
+
? KeyType
|
|
496
|
+
: never]: ObjectType[KeyType];
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/merge.d.ts
|
|
501
|
+
type SimpleMerge<Destination, Source> = {
|
|
502
|
+
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
|
503
|
+
} & Source;
|
|
504
|
+
/**
|
|
505
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
506
|
+
|
|
507
|
+
@example
|
|
508
|
+
```
|
|
509
|
+
import type {Merge} from 'type-fest';
|
|
510
|
+
|
|
511
|
+
interface Foo {
|
|
512
|
+
[x: string]: unknown;
|
|
513
|
+
[x: number]: unknown;
|
|
514
|
+
foo: string;
|
|
515
|
+
bar: symbol;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
type Bar = {
|
|
519
|
+
[x: number]: number;
|
|
520
|
+
[x: symbol]: unknown;
|
|
521
|
+
bar: Date;
|
|
522
|
+
baz: boolean;
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
526
|
+
// => {
|
|
527
|
+
// [x: string]: unknown;
|
|
528
|
+
// [x: number]: number;
|
|
529
|
+
// [x: symbol]: unknown;
|
|
530
|
+
// foo: string;
|
|
531
|
+
// bar: Date;
|
|
532
|
+
// baz: boolean;
|
|
533
|
+
// }
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
@category Object
|
|
537
|
+
*/
|
|
538
|
+
type Merge<Destination, Source> =
|
|
539
|
+
Simplify<
|
|
540
|
+
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
541
|
+
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
542
|
+
>;
|
|
543
|
+
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/if-any.d.ts
|
|
546
|
+
/**
|
|
547
|
+
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
548
|
+
|
|
549
|
+
@see {@link IsAny}
|
|
550
|
+
|
|
551
|
+
@example
|
|
552
|
+
```
|
|
553
|
+
import type {IfAny} from 'type-fest';
|
|
554
|
+
|
|
555
|
+
type ShouldBeTrue = IfAny<any>;
|
|
556
|
+
//=> true
|
|
557
|
+
|
|
558
|
+
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
559
|
+
//=> 'bar'
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
@category Type Guard
|
|
563
|
+
@category Utilities
|
|
564
|
+
*/
|
|
565
|
+
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
566
|
+
IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
567
|
+
);
|
|
568
|
+
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/internal/object.d.ts
|
|
571
|
+
/**
|
|
572
|
+
Merges user specified options with default options.
|
|
573
|
+
|
|
574
|
+
@example
|
|
575
|
+
```
|
|
576
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
577
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
578
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
579
|
+
|
|
580
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
581
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
@example
|
|
585
|
+
```
|
|
586
|
+
// Complains if default values are not provided for optional options
|
|
587
|
+
|
|
588
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
589
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
590
|
+
type SpecifiedOptions = {};
|
|
591
|
+
|
|
592
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
593
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
594
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
@example
|
|
598
|
+
```
|
|
599
|
+
// Complains if an option's default type does not conform to the expected type
|
|
600
|
+
|
|
601
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
602
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
603
|
+
type SpecifiedOptions = {};
|
|
604
|
+
|
|
605
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
606
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
607
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
@example
|
|
611
|
+
```
|
|
612
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
613
|
+
|
|
614
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
615
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
616
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
617
|
+
|
|
618
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
619
|
+
// ~~~~~~~~~~~~~~~~
|
|
620
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
621
|
+
```
|
|
622
|
+
*/
|
|
623
|
+
type ApplyDefaultOptions<
|
|
624
|
+
Options extends object,
|
|
625
|
+
Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
|
|
626
|
+
SpecifiedOptions extends Options,
|
|
627
|
+
> =
|
|
628
|
+
IfAny<SpecifiedOptions, Defaults,
|
|
629
|
+
IfNever<SpecifiedOptions, Defaults,
|
|
630
|
+
Simplify<Merge<Defaults, {
|
|
631
|
+
[Key in keyof SpecifiedOptions
|
|
632
|
+
as Key extends OptionalKeysOf<Options>
|
|
633
|
+
? Extract<SpecifiedOptions[Key], undefined> extends never
|
|
634
|
+
? Key
|
|
635
|
+
: never
|
|
636
|
+
: Key
|
|
637
|
+
]: SpecifiedOptions[Key]
|
|
638
|
+
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
639
|
+
>>;
|
|
640
|
+
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.0/node_modules/type-fest/source/except.d.ts
|
|
643
|
+
/**
|
|
644
|
+
Filter out keys from an object.
|
|
645
|
+
|
|
646
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
647
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
648
|
+
Returns `Key` otherwise.
|
|
649
|
+
|
|
650
|
+
@example
|
|
651
|
+
```
|
|
652
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
653
|
+
//=> never
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
@example
|
|
657
|
+
```
|
|
658
|
+
type Filtered = Filter<'bar', string>;
|
|
659
|
+
//=> never
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
@example
|
|
663
|
+
```
|
|
664
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
665
|
+
//=> 'bar'
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
@see {Except}
|
|
669
|
+
*/
|
|
670
|
+
/**
|
|
671
|
+
Filter out keys from an object.
|
|
672
|
+
|
|
673
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
674
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
675
|
+
Returns `Key` otherwise.
|
|
676
|
+
|
|
677
|
+
@example
|
|
678
|
+
```
|
|
679
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
680
|
+
//=> never
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
@example
|
|
684
|
+
```
|
|
685
|
+
type Filtered = Filter<'bar', string>;
|
|
686
|
+
//=> never
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
@example
|
|
690
|
+
```
|
|
691
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
692
|
+
//=> 'bar'
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
@see {Except}
|
|
696
|
+
*/
|
|
697
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
698
|
+
type ExceptOptions = {
|
|
699
|
+
/**
|
|
700
|
+
Disallow assigning non-specified properties.
|
|
701
|
+
|
|
702
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
703
|
+
|
|
704
|
+
@default false
|
|
705
|
+
*/
|
|
706
|
+
requireExactProps?: boolean;
|
|
707
|
+
};
|
|
708
|
+
type DefaultExceptOptions = {
|
|
709
|
+
requireExactProps: false;
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
Create a type from an object type without certain keys.
|
|
713
|
+
|
|
714
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
715
|
+
|
|
716
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
717
|
+
|
|
718
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
719
|
+
|
|
720
|
+
@example
|
|
721
|
+
```
|
|
722
|
+
import type {Except} from 'type-fest';
|
|
723
|
+
|
|
724
|
+
type Foo = {
|
|
725
|
+
a: number;
|
|
726
|
+
b: string;
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
730
|
+
//=> {b: string}
|
|
731
|
+
|
|
732
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
733
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
734
|
+
|
|
735
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
736
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
737
|
+
|
|
738
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
739
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
740
|
+
|
|
741
|
+
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
742
|
+
|
|
743
|
+
// Consider the following example:
|
|
744
|
+
|
|
745
|
+
type UserData = {
|
|
746
|
+
[metadata: string]: string;
|
|
747
|
+
email: string;
|
|
748
|
+
name: string;
|
|
749
|
+
role: 'admin' | 'user';
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
// `Omit` clearly doesn't behave as expected in this case:
|
|
753
|
+
type PostPayload = Omit<UserData, 'email'>;
|
|
754
|
+
//=> type PostPayload = { [x: string]: string; [x: number]: string; }
|
|
755
|
+
|
|
756
|
+
// In situations like this, `Except` works better.
|
|
757
|
+
// It simply removes the `email` key while preserving all the other keys.
|
|
758
|
+
type PostPayload = Except<UserData, 'email'>;
|
|
759
|
+
//=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
@category Object
|
|
763
|
+
*/
|
|
764
|
+
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =
|
|
765
|
+
_Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
766
|
+
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {
|
|
767
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
768
|
+
} & (Options['requireExactProps'] extends true
|
|
769
|
+
? Partial<Record<KeysType, never>>
|
|
770
|
+
: {});
|
|
771
|
+
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region src/util/types/ExcludeFunctionProperties.d.ts
|
|
47
774
|
type ExcludeFunctionProperties<T> = Except<T, FunctionProperties<T>[keyof T]>;
|
|
48
775
|
|
|
776
|
+
//#endregion
|
|
777
|
+
//#region src/util/types/KebabToCamel.d.ts
|
|
49
778
|
type KebabToCamel<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamel<U>>}` : S;
|
|
50
779
|
|
|
51
|
-
|
|
780
|
+
//#endregion
|
|
781
|
+
//#region src/util/types/TupleSplitHead.d.ts
|
|
782
|
+
type TupleSplitHead<
|
|
783
|
+
T extends unknown[],
|
|
784
|
+
N extends number
|
|
785
|
+
> = T["length"] extends N ? T : T extends [...infer R, unknown] ? TupleSplitHead<R, N> : never;
|
|
52
786
|
|
|
53
|
-
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region src/util/types/TupleSplitTail.d.ts
|
|
789
|
+
type TupleSplitTail<
|
|
790
|
+
T,
|
|
791
|
+
N extends number,
|
|
792
|
+
O extends unknown[] = []
|
|
793
|
+
> = O["length"] extends N ? T : T extends [infer F, ...infer R] ? TupleSplitTail<[...R], N, [...O, F]> : never;
|
|
54
794
|
|
|
55
|
-
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region src/util/types/TupleSplit.d.ts
|
|
797
|
+
type TupleSplit<
|
|
798
|
+
T extends unknown[],
|
|
799
|
+
N extends number
|
|
800
|
+
> = [TupleSplitHead<T, N>, TupleSplitTail<T, N>];
|
|
56
801
|
|
|
57
|
-
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region src/util/types/SkipFirst.d.ts
|
|
804
|
+
type SkipFirst<
|
|
805
|
+
T extends unknown[],
|
|
806
|
+
N extends number
|
|
807
|
+
> = TupleSplit<T, N>[1];
|
|
58
808
|
|
|
59
|
-
|
|
809
|
+
//#endregion
|
|
810
|
+
//#region src/util/types/TakeFirst.d.ts
|
|
811
|
+
type TakeFirst<
|
|
812
|
+
T extends unknown[],
|
|
813
|
+
N extends number
|
|
814
|
+
> = TupleSplit<T, N>[0];
|
|
60
815
|
|
|
61
|
-
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/util/types/TupleSlice.d.ts
|
|
818
|
+
type TupleSlice<
|
|
819
|
+
T extends unknown[],
|
|
820
|
+
S extends number,
|
|
821
|
+
E extends number = T["length"]
|
|
822
|
+
> = SkipFirst<TakeFirst<T, E>, S>;
|
|
62
823
|
|
|
824
|
+
//#endregion
|
|
825
|
+
//#region src/util/validation/exhaustiveGuard.d.ts
|
|
63
826
|
declare const exhaustiveGuard: (value: never) => never;
|
|
64
827
|
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/util/id/uuid/constants.d.ts
|
|
65
830
|
declare const NIL = "00000000-0000-0000-0000-000000000000";
|
|
66
831
|
declare const UUIDV4_REGEX: RegExp;
|
|
67
832
|
declare const UUIDV4_SEARCH_REGEX: RegExp;
|
|
68
833
|
|
|
834
|
+
//#endregion
|
|
835
|
+
//#region src/util/id/uuid/uuidValidateV4.d.ts
|
|
69
836
|
declare const uuidValidateV4: (uuid: string) => boolean;
|
|
70
837
|
|
|
71
|
-
|
|
72
|
-
export
|
|
838
|
+
//#endregion
|
|
839
|
+
export { CamelToKebab, ExcludeFunctionProperties, FunctionProperties, ID_SEPARATOR, InvalidOperationError, KebabToCamel, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, SkipFirst, TakeFirst, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, UUIDV4_SEARCH_REGEX, capitalize, exhaustiveGuard, isPlainObject, mergeObjectsStrict, parseXmlString, parseXmlValue, toKebabCase, uuidValidateV4 };
|