@esposter/shared 2.17.0 → 2.19.2
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/LICENSE +201 -201
- package/README.md +23 -23
- package/dist/index.d.ts +470 -137
- package/dist/index.js +1172 -1087
- package/package.json +17 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { HTMLElement } from "node-html-parser";
|
|
3
2
|
|
|
3
|
+
//#region src/test/constants.d.ts
|
|
4
|
+
declare const AllSpecialValues: {
|
|
5
|
+
isPlainObject: boolean;
|
|
6
|
+
value: unknown;
|
|
7
|
+
}[];
|
|
8
|
+
//#endregion
|
|
4
9
|
//#region src/models/shared/Operation.d.ts
|
|
5
10
|
declare enum Operation {
|
|
6
11
|
Create = "Create",
|
|
@@ -8,7 +13,7 @@ declare enum Operation {
|
|
|
8
13
|
Push = "Push",
|
|
9
14
|
Read = "Read",
|
|
10
15
|
Unshift = "Unshift",
|
|
11
|
-
Update = "Update"
|
|
16
|
+
Update = "Update"
|
|
12
17
|
}
|
|
13
18
|
//#endregion
|
|
14
19
|
//#region src/models/error/InvalidOperationError.d.ts
|
|
@@ -17,18 +22,19 @@ declare class InvalidOperationError extends Error {
|
|
|
17
22
|
}
|
|
18
23
|
//#endregion
|
|
19
24
|
//#region src/models/error/NotFoundError.d.ts
|
|
20
|
-
declare class NotFoundError<T
|
|
21
|
-
constructor(name: T
|
|
25
|
+
declare class NotFoundError<T extends string = string> extends Error {
|
|
26
|
+
constructor(name: T, id: string);
|
|
22
27
|
}
|
|
23
28
|
//#endregion
|
|
24
29
|
//#region src/models/error/NotInitializedError.d.ts
|
|
25
|
-
declare class NotInitializedError<T
|
|
26
|
-
constructor(name: T
|
|
30
|
+
declare class NotInitializedError<T extends string = string> extends Error {
|
|
31
|
+
constructor(name: T);
|
|
27
32
|
}
|
|
28
33
|
//#endregion
|
|
29
34
|
//#region src/models/router/RoutePath.d.ts
|
|
30
35
|
declare const RoutePath: {
|
|
31
36
|
readonly About: "/about";
|
|
37
|
+
readonly Achievements: "/achievements";
|
|
32
38
|
readonly Anime: "/anime";
|
|
33
39
|
readonly Calendar: "/calendar";
|
|
34
40
|
readonly Clicker: "/clicker";
|
|
@@ -38,6 +44,7 @@ declare const RoutePath: {
|
|
|
38
44
|
readonly Dungeons: "/dungeons";
|
|
39
45
|
readonly EmailEditor: "/email-editor";
|
|
40
46
|
readonly FlowchartEditor: "/flowchart-editor";
|
|
47
|
+
readonly FluidSimulator: "/fluid-simulator";
|
|
41
48
|
readonly Github: "https://github.com/Esposter/Esposter";
|
|
42
49
|
readonly Index: "/";
|
|
43
50
|
readonly Login: "/login";
|
|
@@ -57,7 +64,7 @@ declare const RoutePath: {
|
|
|
57
64
|
};
|
|
58
65
|
type RoutePath = typeof RoutePath;
|
|
59
66
|
//#endregion
|
|
60
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
67
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/primitive.d.ts
|
|
61
68
|
/**
|
|
62
69
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
63
70
|
|
|
@@ -65,18 +72,18 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
|
|
|
65
72
|
*/
|
|
66
73
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
67
74
|
//#endregion
|
|
68
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
75
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/basic.d.ts
|
|
69
76
|
/**
|
|
70
77
|
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
71
78
|
|
|
72
79
|
@category Class
|
|
73
80
|
*/
|
|
74
|
-
type Class<T
|
|
75
|
-
prototype: Pick<T
|
|
76
|
-
new (...arguments_: Arguments): T
|
|
81
|
+
type Class<T, Arguments extends unknown[] = any[]> = {
|
|
82
|
+
prototype: Pick<T, keyof T>;
|
|
83
|
+
new (...arguments_: Arguments): T;
|
|
77
84
|
};
|
|
78
85
|
//#endregion
|
|
79
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
86
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/is-any.d.ts
|
|
80
87
|
/**
|
|
81
88
|
Returns a boolean for whether the given type is `any`.
|
|
82
89
|
|
|
@@ -91,8 +98,8 @@ import type {IsAny} from 'type-fest';
|
|
|
91
98
|
const typedObject = {a: 1, b: 2} as const;
|
|
92
99
|
const anyObject: any = {a: 1, b: 2};
|
|
93
100
|
|
|
94
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(
|
|
95
|
-
return
|
|
101
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
102
|
+
return object[key];
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
const typedA = get(typedObject, 'a');
|
|
@@ -105,9 +112,9 @@ const anyA = get(anyObject, 'a');
|
|
|
105
112
|
@category Type Guard
|
|
106
113
|
@category Utilities
|
|
107
114
|
*/
|
|
108
|
-
type IsAny<T
|
|
115
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
109
116
|
//#endregion
|
|
110
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
117
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
111
118
|
/**
|
|
112
119
|
Returns a boolean for whether the given key is an optional key of type.
|
|
113
120
|
|
|
@@ -117,17 +124,17 @@ This is useful when writing utility types or schema validators that need to diff
|
|
|
117
124
|
```
|
|
118
125
|
import type {IsOptionalKeyOf} from 'type-fest';
|
|
119
126
|
|
|
120
|
-
|
|
127
|
+
type User = {
|
|
121
128
|
name: string;
|
|
122
129
|
surname: string;
|
|
123
130
|
|
|
124
131
|
luckyNumber?: number;
|
|
125
|
-
}
|
|
132
|
+
};
|
|
126
133
|
|
|
127
|
-
|
|
134
|
+
type Admin = {
|
|
128
135
|
name: string;
|
|
129
136
|
surname?: string;
|
|
130
|
-
}
|
|
137
|
+
};
|
|
131
138
|
|
|
132
139
|
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
133
140
|
//=> true
|
|
@@ -148,9 +155,9 @@ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
|
148
155
|
@category Type Guard
|
|
149
156
|
@category Utilities
|
|
150
157
|
*/
|
|
151
|
-
type IsOptionalKeyOf<Type extends object, Key
|
|
158
|
+
type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
|
|
152
159
|
//#endregion
|
|
153
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
160
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
154
161
|
/**
|
|
155
162
|
Extract all optional keys from the given type.
|
|
156
163
|
|
|
@@ -160,12 +167,12 @@ This is useful when you want to create a new type that contains different type v
|
|
|
160
167
|
```
|
|
161
168
|
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
162
169
|
|
|
163
|
-
|
|
170
|
+
type User = {
|
|
164
171
|
name: string;
|
|
165
172
|
surname: string;
|
|
166
173
|
|
|
167
174
|
luckyNumber?: number;
|
|
168
|
-
}
|
|
175
|
+
};
|
|
169
176
|
|
|
170
177
|
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
171
178
|
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
@@ -173,12 +180,12 @@ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKe
|
|
|
173
180
|
};
|
|
174
181
|
|
|
175
182
|
const update1: UpdateOperation<User> = {
|
|
176
|
-
name: 'Alice'
|
|
183
|
+
name: 'Alice',
|
|
177
184
|
};
|
|
178
185
|
|
|
179
186
|
const update2: UpdateOperation<User> = {
|
|
180
187
|
name: 'Bob',
|
|
181
|
-
luckyNumber: REMOVE_FIELD
|
|
188
|
+
luckyNumber: REMOVE_FIELD,
|
|
182
189
|
};
|
|
183
190
|
```
|
|
184
191
|
|
|
@@ -188,7 +195,7 @@ type OptionalKeysOf<Type extends object> = Type extends unknown // For distribut
|
|
|
188
195
|
? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
189
196
|
: never;
|
|
190
197
|
//#endregion
|
|
191
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
198
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/required-keys-of.d.ts
|
|
192
199
|
/**
|
|
193
200
|
Extract all required keys from the given type.
|
|
194
201
|
|
|
@@ -198,17 +205,23 @@ This is useful when you want to create a new type that contains different type v
|
|
|
198
205
|
```
|
|
199
206
|
import type {RequiredKeysOf} from 'type-fest';
|
|
200
207
|
|
|
201
|
-
declare function createValidation<
|
|
208
|
+
declare function createValidation<
|
|
209
|
+
Entity extends object,
|
|
210
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
211
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
202
212
|
|
|
203
|
-
|
|
213
|
+
type User = {
|
|
204
214
|
name: string;
|
|
205
215
|
surname: string;
|
|
206
|
-
|
|
207
216
|
luckyNumber?: number;
|
|
208
|
-
}
|
|
217
|
+
};
|
|
209
218
|
|
|
210
219
|
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
211
220
|
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
221
|
+
|
|
222
|
+
// @ts-expect-error
|
|
223
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
224
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
212
225
|
```
|
|
213
226
|
|
|
214
227
|
@category Utilities
|
|
@@ -216,7 +229,7 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
|
|
|
216
229
|
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
217
230
|
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
218
231
|
//#endregion
|
|
219
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
232
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/is-never.d.ts
|
|
220
233
|
/**
|
|
221
234
|
Returns a boolean for whether the given type is `never`.
|
|
222
235
|
|
|
@@ -230,37 +243,49 @@ Useful in type utilities, such as checking if something does not occur.
|
|
|
230
243
|
```
|
|
231
244
|
import type {IsNever, And} from 'type-fest';
|
|
232
245
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
type A = IsNever<never>;
|
|
247
|
+
//=> true
|
|
248
|
+
|
|
249
|
+
type B = IsNever<any>;
|
|
250
|
+
//=> false
|
|
251
|
+
|
|
252
|
+
type C = IsNever<unknown>;
|
|
253
|
+
//=> false
|
|
254
|
+
|
|
255
|
+
type D = IsNever<never[]>;
|
|
256
|
+
//=> false
|
|
257
|
+
|
|
258
|
+
type E = IsNever<object>;
|
|
259
|
+
//=> false
|
|
260
|
+
|
|
261
|
+
type F = IsNever<string>;
|
|
262
|
+
//=> false
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
@example
|
|
266
|
+
```
|
|
267
|
+
import type {IsNever} from 'type-fest';
|
|
250
268
|
|
|
251
|
-
|
|
269
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
270
|
+
|
|
271
|
+
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
272
|
+
type A = IsTrue<never>;
|
|
252
273
|
//=> never
|
|
253
274
|
|
|
254
|
-
|
|
255
|
-
|
|
275
|
+
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
276
|
+
type IsTrueFixed<T> =
|
|
277
|
+
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
278
|
+
|
|
279
|
+
type B = IsTrueFixed<never>;
|
|
280
|
+
//=> false
|
|
256
281
|
```
|
|
257
282
|
|
|
258
283
|
@category Type Guard
|
|
259
284
|
@category Utilities
|
|
260
285
|
*/
|
|
261
|
-
type IsNever<T
|
|
286
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
262
287
|
//#endregion
|
|
263
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
288
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/if.d.ts
|
|
264
289
|
/**
|
|
265
290
|
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
266
291
|
|
|
@@ -273,7 +298,7 @@ Note:
|
|
|
273
298
|
|
|
274
299
|
@example
|
|
275
300
|
```
|
|
276
|
-
import {If} from 'type-fest';
|
|
301
|
+
import type {If} from 'type-fest';
|
|
277
302
|
|
|
278
303
|
type A = If<true, 'yes', 'no'>;
|
|
279
304
|
//=> 'yes'
|
|
@@ -293,7 +318,7 @@ type E = If<never, 'yes', 'no'>;
|
|
|
293
318
|
|
|
294
319
|
@example
|
|
295
320
|
```
|
|
296
|
-
import {If, IsAny, IsNever} from 'type-fest';
|
|
321
|
+
import type {If, IsAny, IsNever} from 'type-fest';
|
|
297
322
|
|
|
298
323
|
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
299
324
|
//=> 'not any'
|
|
@@ -304,7 +329,7 @@ type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
|
304
329
|
|
|
305
330
|
@example
|
|
306
331
|
```
|
|
307
|
-
import {If, IsEqual} from 'type-fest';
|
|
332
|
+
import type {If, IsEqual} from 'type-fest';
|
|
308
333
|
|
|
309
334
|
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
310
335
|
|
|
@@ -355,7 +380,7 @@ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
|
355
380
|
*/
|
|
356
381
|
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
357
382
|
//#endregion
|
|
358
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
383
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/internal/type.d.ts
|
|
359
384
|
/**
|
|
360
385
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
361
386
|
*/
|
|
@@ -368,12 +393,12 @@ Needed to handle the case of a single call signature with properties.
|
|
|
368
393
|
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
369
394
|
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
370
395
|
*/
|
|
371
|
-
type HasMultipleCallSignatures<T
|
|
396
|
+
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
372
397
|
(...arguments_: infer A): unknown;
|
|
373
398
|
(...arguments_: infer B): unknown;
|
|
374
399
|
} ? B extends A ? A extends B ? false : true : true : false;
|
|
375
400
|
//#endregion
|
|
376
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
401
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/simplify.d.ts
|
|
377
402
|
/**
|
|
378
403
|
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.
|
|
379
404
|
|
|
@@ -419,10 +444,11 @@ const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
|
419
444
|
const someType: SomeType = literal;
|
|
420
445
|
const someInterface: SomeInterface = literal;
|
|
421
446
|
|
|
422
|
-
function fn(object: Record<string, unknown>): void
|
|
447
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
423
448
|
|
|
424
449
|
fn(literal); // Good: literal object type is sealed
|
|
425
450
|
fn(someType); // Good: type is sealed
|
|
451
|
+
// @ts-expect-error
|
|
426
452
|
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
427
453
|
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
428
454
|
```
|
|
@@ -431,9 +457,9 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
|
|
|
431
457
|
@see {@link SimplifyDeep}
|
|
432
458
|
@category Object
|
|
433
459
|
*/
|
|
434
|
-
type Simplify<T
|
|
460
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
435
461
|
//#endregion
|
|
436
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
462
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/is-equal.d.ts
|
|
437
463
|
/**
|
|
438
464
|
Returns a boolean for whether the two given types are equal.
|
|
439
465
|
|
|
@@ -460,11 +486,11 @@ type Includes<Value extends readonly any[], Item> =
|
|
|
460
486
|
@category Type Guard
|
|
461
487
|
@category Utilities
|
|
462
488
|
*/
|
|
463
|
-
type IsEqual<A
|
|
489
|
+
type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
|
|
464
490
|
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
465
|
-
type _IsEqual<A
|
|
491
|
+
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
466
492
|
//#endregion
|
|
467
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
493
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
468
494
|
/**
|
|
469
495
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
470
496
|
|
|
@@ -482,8 +508,9 @@ It relies on the fact that an empty object (`{}`) is assignable to an object wit
|
|
|
482
508
|
```
|
|
483
509
|
const indexed: Record<string, unknown> = {}; // Allowed
|
|
484
510
|
|
|
511
|
+
// @ts-expect-error
|
|
485
512
|
const keyed: Record<'foo', unknown> = {}; // Error
|
|
486
|
-
//
|
|
513
|
+
// TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
487
514
|
```
|
|
488
515
|
|
|
489
516
|
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:
|
|
@@ -492,19 +519,21 @@ Instead of causing a type error like the above, you can also use a [conditional
|
|
|
492
519
|
type Indexed = {} extends Record<string, unknown>
|
|
493
520
|
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
494
521
|
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
495
|
-
|
|
522
|
+
|
|
523
|
+
type IndexedResult = Indexed;
|
|
524
|
+
//=> '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
496
525
|
|
|
497
526
|
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
498
|
-
?
|
|
499
|
-
:
|
|
500
|
-
|
|
527
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
528
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
529
|
+
|
|
530
|
+
type KeyedResult = Keyed;
|
|
531
|
+
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
501
532
|
```
|
|
502
533
|
|
|
503
534
|
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`...
|
|
504
535
|
|
|
505
536
|
```
|
|
506
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
507
|
-
|
|
508
537
|
type OmitIndexSignature<ObjectType> = {
|
|
509
538
|
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
510
539
|
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
@@ -514,14 +543,12 @@ type OmitIndexSignature<ObjectType> = {
|
|
|
514
543
|
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
515
544
|
|
|
516
545
|
```
|
|
517
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
518
|
-
|
|
519
546
|
type OmitIndexSignature<ObjectType> = {
|
|
520
547
|
[KeyType in keyof ObjectType
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
548
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
549
|
+
as {} extends Record<KeyType, unknown>
|
|
550
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
551
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
525
552
|
]: ObjectType[KeyType];
|
|
526
553
|
};
|
|
527
554
|
```
|
|
@@ -532,24 +559,24 @@ If `{}` is assignable, it means that `KeyType` is an index signature and we want
|
|
|
532
559
|
```
|
|
533
560
|
import type {OmitIndexSignature} from 'type-fest';
|
|
534
561
|
|
|
535
|
-
|
|
562
|
+
type Example = {
|
|
536
563
|
// These index signatures will be removed.
|
|
537
|
-
[x: string]: any
|
|
538
|
-
[x: number]: any
|
|
539
|
-
[x: symbol]: any
|
|
540
|
-
[x: `head-${string}`]: string
|
|
541
|
-
[x: `${string}-tail`]: string
|
|
542
|
-
[x: `head-${string}-tail`]: string
|
|
543
|
-
[x: `${bigint}`]: string
|
|
544
|
-
[x: `embedded-${number}`]: string
|
|
564
|
+
[x: string]: any;
|
|
565
|
+
[x: number]: any;
|
|
566
|
+
[x: symbol]: any;
|
|
567
|
+
[x: `head-${string}`]: string;
|
|
568
|
+
[x: `${string}-tail`]: string;
|
|
569
|
+
[x: `head-${string}-tail`]: string;
|
|
570
|
+
[x: `${bigint}`]: string;
|
|
571
|
+
[x: `embedded-${number}`]: string;
|
|
545
572
|
|
|
546
573
|
// These explicitly defined keys will remain.
|
|
547
574
|
foo: 'bar';
|
|
548
575
|
qux?: 'baz';
|
|
549
|
-
}
|
|
576
|
+
};
|
|
550
577
|
|
|
551
578
|
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
552
|
-
|
|
579
|
+
//=> {foo: 'bar'; qux?: 'baz'}
|
|
553
580
|
```
|
|
554
581
|
|
|
555
582
|
@see {@link PickIndexSignature}
|
|
@@ -557,7 +584,7 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
557
584
|
*/
|
|
558
585
|
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
559
586
|
//#endregion
|
|
560
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
587
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
561
588
|
/**
|
|
562
589
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
563
590
|
|
|
@@ -605,10 +632,9 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
605
632
|
*/
|
|
606
633
|
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
607
634
|
//#endregion
|
|
608
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
635
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/merge.d.ts
|
|
609
636
|
// Merges two objects without worrying about index signatures.
|
|
610
|
-
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source
|
|
611
|
-
|
|
637
|
+
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
|
|
612
638
|
/**
|
|
613
639
|
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
614
640
|
|
|
@@ -616,12 +642,12 @@ Merge two types into a new type. Keys of the second type overrides keys of the f
|
|
|
616
642
|
```
|
|
617
643
|
import type {Merge} from 'type-fest';
|
|
618
644
|
|
|
619
|
-
|
|
645
|
+
type Foo = {
|
|
620
646
|
[x: string]: unknown;
|
|
621
647
|
[x: number]: unknown;
|
|
622
648
|
foo: string;
|
|
623
649
|
bar: symbol;
|
|
624
|
-
}
|
|
650
|
+
};
|
|
625
651
|
|
|
626
652
|
type Bar = {
|
|
627
653
|
[x: number]: number;
|
|
@@ -631,7 +657,7 @@ type Bar = {
|
|
|
631
657
|
};
|
|
632
658
|
|
|
633
659
|
export type FooBar = Merge<Foo, Bar>;
|
|
634
|
-
|
|
660
|
+
//=> {
|
|
635
661
|
// [x: string]: unknown;
|
|
636
662
|
// [x: number]: number;
|
|
637
663
|
// [x: symbol]: unknown;
|
|
@@ -641,11 +667,19 @@ export type FooBar = Merge<Foo, Bar>;
|
|
|
641
667
|
// }
|
|
642
668
|
```
|
|
643
669
|
|
|
670
|
+
Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
|
|
671
|
+
|
|
672
|
+
@see {@link ObjectMerge}
|
|
644
673
|
@category Object
|
|
645
674
|
*/
|
|
646
|
-
type Merge<Destination, Source> =
|
|
675
|
+
type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
|
|
676
|
+
? Source extends unknown // For distributing `Source`
|
|
677
|
+
? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
|
|
678
|
+
: never;
|
|
679
|
+
// Should never happen
|
|
680
|
+
type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
647
681
|
//#endregion
|
|
648
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
682
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/internal/object.d.ts
|
|
649
683
|
/**
|
|
650
684
|
Merges user specified options with default options.
|
|
651
685
|
|
|
@@ -700,7 +734,7 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
|
|
|
700
734
|
*/
|
|
701
735
|
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
702
736
|
//#endregion
|
|
703
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
737
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/except.d.ts
|
|
704
738
|
/**
|
|
705
739
|
Filter out keys from an object.
|
|
706
740
|
|
|
@@ -728,7 +762,7 @@ type Filtered = Filter<'bar', 'foo'>;
|
|
|
728
762
|
|
|
729
763
|
@see {Except}
|
|
730
764
|
*/
|
|
731
|
-
type Filter<KeyType
|
|
765
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
732
766
|
type ExceptOptions = {
|
|
733
767
|
/**
|
|
734
768
|
Disallow assigning non-specified properties.
|
|
@@ -740,7 +774,6 @@ type ExceptOptions = {
|
|
|
740
774
|
type DefaultExceptOptions = {
|
|
741
775
|
requireExactProps: false;
|
|
742
776
|
};
|
|
743
|
-
|
|
744
777
|
/**
|
|
745
778
|
Create a type from an object type without certain keys.
|
|
746
779
|
|
|
@@ -762,14 +795,16 @@ type Foo = {
|
|
|
762
795
|
type FooWithoutA = Except<Foo, 'a'>;
|
|
763
796
|
//=> {b: string}
|
|
764
797
|
|
|
798
|
+
// @ts-expect-error
|
|
765
799
|
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
766
|
-
|
|
800
|
+
// errors: 'a' does not exist in type '{ b: string; }'
|
|
767
801
|
|
|
768
802
|
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
769
|
-
//=> {a: number} & Partial<Record<
|
|
803
|
+
//=> {a: number} & Partial<Record<'b', never>>
|
|
770
804
|
|
|
805
|
+
// @ts-expect-error
|
|
771
806
|
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
772
|
-
|
|
807
|
+
// errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
773
808
|
|
|
774
809
|
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
775
810
|
|
|
@@ -784,12 +819,12 @@ type UserData = {
|
|
|
784
819
|
|
|
785
820
|
// `Omit` clearly doesn't behave as expected in this case:
|
|
786
821
|
type PostPayload = Omit<UserData, 'email'>;
|
|
787
|
-
//=>
|
|
822
|
+
//=> {[x: string]: string; [x: number]: string}
|
|
788
823
|
|
|
789
824
|
// In situations like this, `Except` works better.
|
|
790
825
|
// It simply removes the `email` key while preserving all the other keys.
|
|
791
|
-
type
|
|
792
|
-
//=>
|
|
826
|
+
type PostPayloadFixed = Except<UserData, 'email'>;
|
|
827
|
+
//=> {[x: string]: string; name: string; role: 'admin' | 'user'}
|
|
793
828
|
```
|
|
794
829
|
|
|
795
830
|
@category Object
|
|
@@ -797,7 +832,7 @@ type PostPayload = Except<UserData, 'email'>;
|
|
|
797
832
|
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
798
833
|
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
|
|
799
834
|
//#endregion
|
|
800
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
835
|
+
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/required-deep.d.ts
|
|
801
836
|
/**
|
|
802
837
|
Create a type from another type with all keys and nested keys set to required.
|
|
803
838
|
|
|
@@ -839,19 +874,20 @@ Note that types containing overloaded functions are not made deeply required due
|
|
|
839
874
|
@category Set
|
|
840
875
|
@category Map
|
|
841
876
|
*/
|
|
842
|
-
type RequiredDeep<T
|
|
877
|
+
type RequiredDeep<T> = T extends BuiltIns ? T : T extends Map<infer KeyType, infer ValueType> ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends Set<infer ItemType> ? Set<RequiredDeep<ItemType>> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends ReadonlySet<infer ItemType> ? ReadonlySet<RequiredDeep<ItemType>> : T extends WeakMap<infer KeyType, infer ValueType> ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends WeakSet<infer ItemType> ? WeakSet<RequiredDeep<ItemType>> : T extends Promise<infer ValueType> ? Promise<RequiredDeep<ValueType>> : T extends ((...arguments_: any[]) => unknown) ? IsNever<keyof T> extends true ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & RequiredObjectDeep<T> : T extends object ? Simplify<RequiredObjectDeep<T>> // `Simplify` to prevent `RequiredObjectDeep` from appearing in the resulting type
|
|
878
|
+
: unknown;
|
|
843
879
|
type RequiredObjectDeep<ObjectType extends object> = { [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]> };
|
|
844
880
|
//#endregion
|
|
845
881
|
//#region src/util/types/PropertyNames.d.ts
|
|
846
|
-
type PropertyNames<T
|
|
882
|
+
type PropertyNames<T> = RequiredDeep<{ [P in keyof T]: P }>;
|
|
847
883
|
//#endregion
|
|
848
884
|
//#region src/models/shared/ItemEntityType.d.ts
|
|
849
|
-
interface ItemEntityType<T
|
|
850
|
-
type: T
|
|
885
|
+
interface ItemEntityType<T extends string> {
|
|
886
|
+
type: T;
|
|
851
887
|
}
|
|
852
888
|
declare const ItemEntityTypePropertyNames: PropertyNames<ItemEntityType<string>>;
|
|
853
|
-
declare const createItemEntityTypeSchema: <T
|
|
854
|
-
type: T
|
|
889
|
+
declare const createItemEntityTypeSchema: <T extends z.ZodType<string>>(schema: T) => z.ZodObject<{
|
|
890
|
+
type: T;
|
|
855
891
|
}>;
|
|
856
892
|
//#endregion
|
|
857
893
|
//#region src/models/shared/ItemMetadata.d.ts
|
|
@@ -872,23 +908,29 @@ declare abstract class Serializable {
|
|
|
872
908
|
toJSON(): string;
|
|
873
909
|
}
|
|
874
910
|
//#endregion
|
|
911
|
+
//#region src/models/shared/TakeOne.d.ts
|
|
912
|
+
interface TakeOne {
|
|
913
|
+
<T extends readonly unknown[]>(values: T, index?: number): T[number];
|
|
914
|
+
<T extends Record<PropertyKey, unknown>>(values: T, index: keyof T): T[keyof T];
|
|
915
|
+
}
|
|
916
|
+
//#endregion
|
|
875
917
|
//#region src/util/types/DeepOmitArray.d.ts
|
|
876
918
|
type DeepOmitArray<TArray extends unknown[], TKey> = { [P in keyof TArray]: DeepOmit<TArray[P], TKey> };
|
|
877
919
|
//#endregion
|
|
878
920
|
//#region src/util/types/DeepOmit.d.ts
|
|
879
|
-
type DeepOmit<T
|
|
921
|
+
type DeepOmit<T, TKey> = T extends Primitive ? T : { [P in Exclude<keyof T, TKey>]: T[P] extends infer TP ? TP extends Date | Function | Primitive ? TP : TP extends unknown[] ? DeepOmitArray<TP, TKey> : Record<string, unknown> extends TP ? TP : DeepOmit<TP, TKey> : never };
|
|
880
922
|
//#endregion
|
|
881
923
|
//#region src/util/types/DeepOptionalProperties.d.ts
|
|
882
|
-
type DeepOptionalProperties<T
|
|
924
|
+
type DeepOptionalProperties<T> = { [K in keyof T as undefined extends T[K] ? K : never]?: DeepOptionalProperties<T[K]> };
|
|
883
925
|
//#endregion
|
|
884
926
|
//#region src/util/types/DeepRequiredProperties.d.ts
|
|
885
|
-
type DeepRequiredProperties<T
|
|
927
|
+
type DeepRequiredProperties<T> = { [K in keyof T as undefined extends T[K] ? never : K]: DeepRequiredProperties<T[K]> };
|
|
886
928
|
//#endregion
|
|
887
929
|
//#region src/util/types/DeepOptionalUndefined.d.ts
|
|
888
|
-
type DeepOptionalUndefined<T
|
|
930
|
+
type DeepOptionalUndefined<T> = T extends ((...args: unknown[]) => unknown) ? T : T extends (infer U)[] ? DeepOptionalUndefined<U>[] : T extends readonly (infer U)[] ? readonly DeepOptionalUndefined<U>[] : T extends Date ? T : T extends object ? keyof T extends never ? never : DeepOptionalProperties<T> extends Record<never, unknown> ? DeepRequiredProperties<T> : DeepRequiredProperties<T> extends Record<never, unknown> ? DeepOptionalProperties<T> : DeepOptionalProperties<T> & DeepRequiredProperties<T> : T;
|
|
889
931
|
//#endregion
|
|
890
932
|
//#region src/models/shared/ToData.d.ts
|
|
891
|
-
type ToData<T
|
|
933
|
+
type ToData<T extends Serializable> = DeepOptionalUndefined<DeepOmit<T, "toJSON">>;
|
|
892
934
|
//#endregion
|
|
893
935
|
//#region src/models/shared/WithMetadata.d.ts
|
|
894
936
|
interface WithMetadata<TBase extends Class<NonNullable<unknown>>> {
|
|
@@ -905,6 +947,294 @@ declare const MENTION_LABEL_ATTRIBUTE = "data-label";
|
|
|
905
947
|
declare const MENTION_TYPE_ATTRIBUTE = "data-type";
|
|
906
948
|
declare const MENTION_TYPE = "mention";
|
|
907
949
|
//#endregion
|
|
950
|
+
//#region ../../node_modules/.pnpm/node-html-parser@7.0.2/node_modules/node-html-parser/dist/void-tag.d.ts
|
|
951
|
+
declare class VoidTag {
|
|
952
|
+
addClosingSlash: boolean;
|
|
953
|
+
private voidTags;
|
|
954
|
+
constructor(addClosingSlash?: boolean, tags?: string[]);
|
|
955
|
+
formatNode(tag: string, attrs: string, innerHTML: string): string;
|
|
956
|
+
isVoidElement(tag: string): boolean;
|
|
957
|
+
}
|
|
958
|
+
//#endregion
|
|
959
|
+
//#region ../../node_modules/.pnpm/node-html-parser@7.0.2/node_modules/node-html-parser/dist/nodes/type.d.ts
|
|
960
|
+
declare enum NodeType {
|
|
961
|
+
ELEMENT_NODE = 1,
|
|
962
|
+
TEXT_NODE = 3,
|
|
963
|
+
COMMENT_NODE = 8
|
|
964
|
+
}
|
|
965
|
+
//#endregion
|
|
966
|
+
//#region ../../node_modules/.pnpm/node-html-parser@7.0.2/node_modules/node-html-parser/dist/nodes/node.d.ts
|
|
967
|
+
/**
|
|
968
|
+
* Node Class as base class for TextNode and HTMLElement.
|
|
969
|
+
*/
|
|
970
|
+
declare abstract class Node {
|
|
971
|
+
parentNode: HTMLElement;
|
|
972
|
+
abstract rawTagName: string;
|
|
973
|
+
abstract nodeType: NodeType;
|
|
974
|
+
childNodes: Node[];
|
|
975
|
+
range: readonly [number, number];
|
|
976
|
+
abstract text: string;
|
|
977
|
+
abstract rawText: string;
|
|
978
|
+
abstract toString(): string;
|
|
979
|
+
abstract clone(): Node;
|
|
980
|
+
constructor(parentNode?: HTMLElement, range?: [number, number]);
|
|
981
|
+
/**
|
|
982
|
+
* Remove current node
|
|
983
|
+
*/
|
|
984
|
+
remove(): this;
|
|
985
|
+
get innerText(): string;
|
|
986
|
+
get textContent(): string;
|
|
987
|
+
set textContent(val: string);
|
|
988
|
+
}
|
|
989
|
+
//#endregion
|
|
990
|
+
//#region ../../node_modules/.pnpm/node-html-parser@7.0.2/node_modules/node-html-parser/dist/nodes/html.d.ts
|
|
991
|
+
interface KeyAttributes {
|
|
992
|
+
id?: string;
|
|
993
|
+
class?: string;
|
|
994
|
+
}
|
|
995
|
+
interface Attributes {
|
|
996
|
+
[key: string]: string;
|
|
997
|
+
}
|
|
998
|
+
interface RawAttributes {
|
|
999
|
+
[key: string]: string;
|
|
1000
|
+
}
|
|
1001
|
+
type InsertPosition = 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
|
|
1002
|
+
type NodeInsertable = Node | string;
|
|
1003
|
+
declare class DOMTokenList {
|
|
1004
|
+
private _set;
|
|
1005
|
+
private _afterUpdate;
|
|
1006
|
+
private _validate;
|
|
1007
|
+
constructor(valuesInit?: string[], afterUpdate?: (t: DOMTokenList) => void);
|
|
1008
|
+
add(c: string): void;
|
|
1009
|
+
replace(c1: string, c2: string): void;
|
|
1010
|
+
remove(c: string): void;
|
|
1011
|
+
toggle(c: string): void;
|
|
1012
|
+
contains(c: string): boolean;
|
|
1013
|
+
get length(): number;
|
|
1014
|
+
values(): IterableIterator<string>;
|
|
1015
|
+
get value(): string[];
|
|
1016
|
+
toString(): string;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* HTMLElement, which contains a set of children.
|
|
1020
|
+
*
|
|
1021
|
+
* Note: this is a minimalist implementation, no complete tree
|
|
1022
|
+
* structure provided (no parentNode, nextSibling,
|
|
1023
|
+
* previousSibling etc).
|
|
1024
|
+
* @class HTMLElement
|
|
1025
|
+
* @extends {Node}
|
|
1026
|
+
*/
|
|
1027
|
+
declare class HTMLElement extends Node {
|
|
1028
|
+
rawAttrs: string;
|
|
1029
|
+
private voidTag;
|
|
1030
|
+
private _attrs;
|
|
1031
|
+
private _rawAttrs;
|
|
1032
|
+
private _parseOptions;
|
|
1033
|
+
private _id;
|
|
1034
|
+
rawTagName: string;
|
|
1035
|
+
classList: DOMTokenList;
|
|
1036
|
+
/**
|
|
1037
|
+
* Node Type declaration.
|
|
1038
|
+
*/
|
|
1039
|
+
nodeType: NodeType;
|
|
1040
|
+
/**
|
|
1041
|
+
* Quote attribute values
|
|
1042
|
+
* @param attr attribute value
|
|
1043
|
+
* @returns {string} quoted value
|
|
1044
|
+
*/
|
|
1045
|
+
private quoteAttribute;
|
|
1046
|
+
/**
|
|
1047
|
+
* Creates an instance of HTMLElement.
|
|
1048
|
+
* @param keyAttrs id and class attribute
|
|
1049
|
+
* @param [rawAttrs] attributes in string
|
|
1050
|
+
*
|
|
1051
|
+
* @memberof HTMLElement
|
|
1052
|
+
*/
|
|
1053
|
+
constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs?: string, parentNode?: HTMLElement, range?: [number, number], voidTag?: VoidTag, _parseOptions?: Partial<Options>);
|
|
1054
|
+
/**
|
|
1055
|
+
* Remove Child element from childNodes array
|
|
1056
|
+
* @param {HTMLElement} node node to remove
|
|
1057
|
+
*/
|
|
1058
|
+
removeChild(node: Node): this;
|
|
1059
|
+
/**
|
|
1060
|
+
* Exchanges given child with new child
|
|
1061
|
+
* @param {HTMLElement} oldNode node to exchange
|
|
1062
|
+
* @param {HTMLElement} newNode new node
|
|
1063
|
+
*/
|
|
1064
|
+
exchangeChild(oldNode: Node, newNode: Node): this;
|
|
1065
|
+
get tagName(): string;
|
|
1066
|
+
set tagName(newname: string);
|
|
1067
|
+
get localName(): string;
|
|
1068
|
+
get isVoidElement(): boolean;
|
|
1069
|
+
get id(): string;
|
|
1070
|
+
set id(newid: string);
|
|
1071
|
+
/**
|
|
1072
|
+
* Get escpaed (as-it) text value of current node and its children.
|
|
1073
|
+
* @return {string} text content
|
|
1074
|
+
*/
|
|
1075
|
+
get rawText(): string;
|
|
1076
|
+
get textContent(): string;
|
|
1077
|
+
set textContent(val: string);
|
|
1078
|
+
/**
|
|
1079
|
+
* Get unescaped text value of current node and its children.
|
|
1080
|
+
* @return {string} text content
|
|
1081
|
+
*/
|
|
1082
|
+
get text(): string;
|
|
1083
|
+
/**
|
|
1084
|
+
* Get structured Text (with '\n' etc.)
|
|
1085
|
+
* @return {string} structured text
|
|
1086
|
+
*/
|
|
1087
|
+
get structuredText(): string;
|
|
1088
|
+
toString(): string;
|
|
1089
|
+
get innerHTML(): string;
|
|
1090
|
+
set innerHTML(content: string);
|
|
1091
|
+
set_content(content: string | Node | Node[], options?: Partial<Options>): this;
|
|
1092
|
+
replaceWith(...nodes: (string | Node)[]): this;
|
|
1093
|
+
get outerHTML(): string;
|
|
1094
|
+
/**
|
|
1095
|
+
* Trim element from right (in block) after seeing pattern in a TextNode.
|
|
1096
|
+
* @param {RegExp} pattern pattern to find
|
|
1097
|
+
* @return {HTMLElement} reference to current node
|
|
1098
|
+
*/
|
|
1099
|
+
trimRight(pattern: RegExp): this;
|
|
1100
|
+
/**
|
|
1101
|
+
* Get DOM structure
|
|
1102
|
+
* @return {string} structure
|
|
1103
|
+
*/
|
|
1104
|
+
get structure(): string;
|
|
1105
|
+
/**
|
|
1106
|
+
* Remove whitespaces in this sub tree.
|
|
1107
|
+
* @return {HTMLElement} pointer to this
|
|
1108
|
+
*/
|
|
1109
|
+
removeWhitespace(): this;
|
|
1110
|
+
/**
|
|
1111
|
+
* Query CSS selector to find matching nodes.
|
|
1112
|
+
* @param {string} selector Simplified CSS selector
|
|
1113
|
+
* @return {HTMLElement[]} matching elements
|
|
1114
|
+
*/
|
|
1115
|
+
querySelectorAll(selector: string): HTMLElement[];
|
|
1116
|
+
/**
|
|
1117
|
+
* Query CSS Selector to find matching node.
|
|
1118
|
+
* @param {string} selector Simplified CSS selector
|
|
1119
|
+
* @return {(HTMLElement|null)} matching node
|
|
1120
|
+
*/
|
|
1121
|
+
querySelector(selector: string): HTMLElement | null;
|
|
1122
|
+
/**
|
|
1123
|
+
* find elements by their tagName
|
|
1124
|
+
* @param {string} tagName the tagName of the elements to select
|
|
1125
|
+
*/
|
|
1126
|
+
getElementsByTagName(tagName: string): Array<HTMLElement>;
|
|
1127
|
+
/**
|
|
1128
|
+
* find element by it's id
|
|
1129
|
+
* @param {string} id the id of the element to select
|
|
1130
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
1131
|
+
*/
|
|
1132
|
+
getElementById(id: string): HTMLElement | null;
|
|
1133
|
+
/**
|
|
1134
|
+
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
|
|
1135
|
+
* @param selector a DOMString containing a selector list
|
|
1136
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
1137
|
+
*/
|
|
1138
|
+
closest(selector: string): HTMLElement | null;
|
|
1139
|
+
/**
|
|
1140
|
+
* Append a child node to childNodes
|
|
1141
|
+
* @param {Node} node node to append
|
|
1142
|
+
* @return {Node} node appended
|
|
1143
|
+
*/
|
|
1144
|
+
appendChild<T extends Node = Node>(node: T): T;
|
|
1145
|
+
/**
|
|
1146
|
+
* Get attributes
|
|
1147
|
+
* @access private
|
|
1148
|
+
* @return {Object} parsed and unescaped attributes
|
|
1149
|
+
*/
|
|
1150
|
+
get attrs(): Attributes;
|
|
1151
|
+
get attributes(): Record<string, string>;
|
|
1152
|
+
/**
|
|
1153
|
+
* Get escaped (as-is) attributes
|
|
1154
|
+
* @return {Object} parsed attributes
|
|
1155
|
+
*/
|
|
1156
|
+
get rawAttributes(): RawAttributes;
|
|
1157
|
+
removeAttribute(key: string): this;
|
|
1158
|
+
hasAttribute(key: string): boolean;
|
|
1159
|
+
/**
|
|
1160
|
+
* Get an attribute
|
|
1161
|
+
* @return {string | undefined} value of the attribute; or undefined if not exist
|
|
1162
|
+
*/
|
|
1163
|
+
getAttribute(key: string): string | undefined;
|
|
1164
|
+
/**
|
|
1165
|
+
* Set an attribute value to the HTMLElement
|
|
1166
|
+
* @param {string} key The attribute name
|
|
1167
|
+
* @param {string} value The value to set, or null / undefined to remove an attribute
|
|
1168
|
+
*/
|
|
1169
|
+
setAttribute(key: string, value: string): this;
|
|
1170
|
+
/**
|
|
1171
|
+
* Replace all the attributes of the HTMLElement by the provided attributes
|
|
1172
|
+
* @param {Attributes} attributes the new attribute set
|
|
1173
|
+
*/
|
|
1174
|
+
setAttributes(attributes: Attributes): this;
|
|
1175
|
+
insertAdjacentHTML(where: InsertPosition, html: string): this;
|
|
1176
|
+
/** Prepend nodes or strings to this node's children. */
|
|
1177
|
+
prepend(...insertable: NodeInsertable[]): void;
|
|
1178
|
+
/** Append nodes or strings to this node's children. */
|
|
1179
|
+
append(...insertable: NodeInsertable[]): void;
|
|
1180
|
+
/** Insert nodes or strings before this node. */
|
|
1181
|
+
before(...insertable: NodeInsertable[]): void;
|
|
1182
|
+
/** Insert nodes or strings after this node. */
|
|
1183
|
+
after(...insertable: NodeInsertable[]): void;
|
|
1184
|
+
get nextSibling(): Node | null;
|
|
1185
|
+
get nextElementSibling(): HTMLElement | null;
|
|
1186
|
+
get previousSibling(): Node | null;
|
|
1187
|
+
get previousElementSibling(): HTMLElement | null;
|
|
1188
|
+
/** Get all childNodes of type {@link HTMLElement}. */
|
|
1189
|
+
get children(): HTMLElement[];
|
|
1190
|
+
/**
|
|
1191
|
+
* Get the first child node.
|
|
1192
|
+
* @return The first child or undefined if none exists.
|
|
1193
|
+
*/
|
|
1194
|
+
get firstChild(): Node | undefined;
|
|
1195
|
+
/**
|
|
1196
|
+
* Get the first child node of type {@link HTMLElement}.
|
|
1197
|
+
* @return The first child element or undefined if none exists.
|
|
1198
|
+
*/
|
|
1199
|
+
get firstElementChild(): HTMLElement | undefined;
|
|
1200
|
+
/**
|
|
1201
|
+
* Get the last child node.
|
|
1202
|
+
* @return The last child or undefined if none exists.
|
|
1203
|
+
*/
|
|
1204
|
+
get lastChild(): Node | undefined;
|
|
1205
|
+
/**
|
|
1206
|
+
* Get the last child node of type {@link HTMLElement}.
|
|
1207
|
+
* @return The last child element or undefined if none exists.
|
|
1208
|
+
*/
|
|
1209
|
+
get lastElementChild(): HTMLElement | undefined;
|
|
1210
|
+
get childElementCount(): number;
|
|
1211
|
+
get classNames(): string;
|
|
1212
|
+
/** Clone this Node */
|
|
1213
|
+
clone(): Node;
|
|
1214
|
+
}
|
|
1215
|
+
interface Options {
|
|
1216
|
+
lowerCaseTagName?: boolean;
|
|
1217
|
+
comment?: boolean;
|
|
1218
|
+
/**
|
|
1219
|
+
* @see PR #215 for explanation
|
|
1220
|
+
*/
|
|
1221
|
+
fixNestedATags?: boolean;
|
|
1222
|
+
parseNoneClosedTags?: boolean;
|
|
1223
|
+
blockTextElements: {
|
|
1224
|
+
[tag: string]: boolean;
|
|
1225
|
+
};
|
|
1226
|
+
voidTag?: {
|
|
1227
|
+
/**
|
|
1228
|
+
* options, default value is ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']
|
|
1229
|
+
*/
|
|
1230
|
+
tags?: string[];
|
|
1231
|
+
/**
|
|
1232
|
+
* void tag serialisation, add a final slash <br/>
|
|
1233
|
+
*/
|
|
1234
|
+
closingSlash?: boolean;
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
//#endregion
|
|
908
1238
|
//#region src/services/message/getMentions.d.ts
|
|
909
1239
|
declare const getMentions: (message: string) => HTMLElement[];
|
|
910
1240
|
//#endregion
|
|
@@ -920,6 +1250,9 @@ declare const applyItemMetadataMixin: <TBase extends Class<NonNullable<unknown>>
|
|
|
920
1250
|
//#region src/services/survey/constants.d.ts
|
|
921
1251
|
declare const SURVEY_DISPLAY_NAME = "Surveyer";
|
|
922
1252
|
//#endregion
|
|
1253
|
+
//#region src/util/array/takeOne.d.ts
|
|
1254
|
+
declare const takeOne: TakeOne;
|
|
1255
|
+
//#endregion
|
|
923
1256
|
//#region src/util/environment/getIsServer.d.ts
|
|
924
1257
|
declare const getIsServer: () => boolean;
|
|
925
1258
|
//#endregion
|
|
@@ -927,7 +1260,7 @@ declare const getIsServer: () => boolean;
|
|
|
927
1260
|
declare const ID_SEPARATOR = "|";
|
|
928
1261
|
//#endregion
|
|
929
1262
|
//#region src/util/object/getPropertyNames.d.ts
|
|
930
|
-
declare const getPropertyNames: <T
|
|
1263
|
+
declare const getPropertyNames: <T>() => PropertyNames<T>;
|
|
931
1264
|
//#endregion
|
|
932
1265
|
//#region src/util/object/isPlainObject.d.ts
|
|
933
1266
|
declare const isPlainObject: (data: unknown) => data is object;
|
|
@@ -936,16 +1269,16 @@ declare const isPlainObject: (data: unknown) => data is object;
|
|
|
936
1269
|
declare const jsonDateParse: (text: string) => any;
|
|
937
1270
|
//#endregion
|
|
938
1271
|
//#region src/util/types/MergeObjectsStrict.d.ts
|
|
939
|
-
type MergeObjectsStrict<T
|
|
1272
|
+
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;
|
|
940
1273
|
//#endregion
|
|
941
1274
|
//#region src/util/object/mergeObjectsStrict.d.ts
|
|
942
|
-
declare const mergeObjectsStrict: <T
|
|
1275
|
+
declare const mergeObjectsStrict: <T extends object[]>(...objects: T) => MergeObjectsStrict<T>;
|
|
943
1276
|
//#endregion
|
|
944
1277
|
//#region src/util/reactivity/getRawData.d.ts
|
|
945
|
-
declare const getRawData: <T
|
|
1278
|
+
declare const getRawData: <T>(data: T) => T;
|
|
946
1279
|
//#endregion
|
|
947
1280
|
//#region src/util/reactivity/toRawDeep.d.ts
|
|
948
|
-
declare const toRawDeep: <T
|
|
1281
|
+
declare const toRawDeep: <T extends object>(data: T) => T;
|
|
949
1282
|
//#endregion
|
|
950
1283
|
//#region src/util/regex/escapeRegExp.d.ts
|
|
951
1284
|
declare const escapeRegExp: (string: string) => string;
|
|
@@ -960,13 +1293,13 @@ declare const streamToText: (readable: NodeJS.ReadableStream) => Promise<string>
|
|
|
960
1293
|
type CamelToKebab<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Uncapitalize<T>}${CamelToKebab<U>}` : `${Uncapitalize<T>}-${CamelToKebab<U>}` : S;
|
|
961
1294
|
//#endregion
|
|
962
1295
|
//#region src/util/text/toKebabCase.d.ts
|
|
963
|
-
declare const toKebabCase: <T
|
|
1296
|
+
declare const toKebabCase: <T extends string>(string: T) => CamelToKebab<T>;
|
|
964
1297
|
//#endregion
|
|
965
1298
|
//#region src/util/text/truncate.d.ts
|
|
966
1299
|
declare const truncate: (string: string, length: number) => string;
|
|
967
1300
|
//#endregion
|
|
968
1301
|
//#region src/util/text/uncapitalize.d.ts
|
|
969
|
-
declare const uncapitalize: <T
|
|
1302
|
+
declare const uncapitalize: <T extends string>(string: T) => Uncapitalize<T>;
|
|
970
1303
|
//#endregion
|
|
971
1304
|
//#region src/util/time/hrtime.d.ts
|
|
972
1305
|
declare const hrtime: (previousHrTime?: [number, number]) => [number, number];
|
|
@@ -975,10 +1308,10 @@ declare const hrtime: (previousHrTime?: [number, number]) => [number, number];
|
|
|
975
1308
|
declare const now: () => string;
|
|
976
1309
|
//#endregion
|
|
977
1310
|
//#region src/util/types/FunctionProperties.d.ts
|
|
978
|
-
type FunctionProperties<T
|
|
1311
|
+
type FunctionProperties<T> = { [K in keyof T]: T[K] extends Function ? K : never };
|
|
979
1312
|
//#endregion
|
|
980
1313
|
//#region src/util/types/ExcludeFunctionProperties.d.ts
|
|
981
|
-
type ExcludeFunctionProperties<T
|
|
1314
|
+
type ExcludeFunctionProperties<T> = Except<T, FunctionProperties<T>[keyof T]>;
|
|
982
1315
|
//#endregion
|
|
983
1316
|
//#region src/util/types/KebabToCamel.d.ts
|
|
984
1317
|
type KebabToCamel<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamel<U>>}` : S;
|
|
@@ -987,25 +1320,25 @@ type KebabToCamel<S extends string> = S extends `${infer T}-${infer U}` ? `${T}$
|
|
|
987
1320
|
type MapValue<BaseType> = BaseType extends Map<unknown, infer ValueType> ? ValueType : never;
|
|
988
1321
|
//#endregion
|
|
989
1322
|
//#region src/util/types/PartialByKeys.d.ts
|
|
990
|
-
type PartialByKeys<T
|
|
1323
|
+
type PartialByKeys<T, K extends keyof T = keyof T> = Except<T, K> & Partial<Pick<T, Extract<keyof T, K>>>;
|
|
991
1324
|
//#endregion
|
|
992
1325
|
//#region src/util/types/TupleSplitHead.d.ts
|
|
993
|
-
type TupleSplitHead<T
|
|
1326
|
+
type TupleSplitHead<T extends unknown[], N extends number> = T["length"] extends N ? T : T extends [...infer R, unknown] ? TupleSplitHead<R, N> : never;
|
|
994
1327
|
//#endregion
|
|
995
1328
|
//#region src/util/types/TupleSplitTail.d.ts
|
|
996
|
-
type TupleSplitTail<T
|
|
1329
|
+
type TupleSplitTail<T, N extends number, O extends unknown[] = []> = O["length"] extends N ? T : T extends [infer F, ...infer R] ? TupleSplitTail<[...R], N, [...O, F]> : never;
|
|
997
1330
|
//#endregion
|
|
998
1331
|
//#region src/util/types/TupleSplit.d.ts
|
|
999
|
-
type TupleSplit<T
|
|
1332
|
+
type TupleSplit<T extends unknown[], N extends number> = [TupleSplitHead<T, N>, TupleSplitTail<T, N>];
|
|
1000
1333
|
//#endregion
|
|
1001
1334
|
//#region src/util/types/SkipFirst.d.ts
|
|
1002
|
-
type SkipFirst<T
|
|
1335
|
+
type SkipFirst<T extends unknown[], N extends number> = TupleSplit<T, N>[1];
|
|
1003
1336
|
//#endregion
|
|
1004
1337
|
//#region src/util/types/TakeFirst.d.ts
|
|
1005
|
-
type TakeFirst<T
|
|
1338
|
+
type TakeFirst<T extends unknown[], N extends number> = TupleSplit<T, N>[0];
|
|
1006
1339
|
//#endregion
|
|
1007
1340
|
//#region src/util/types/TupleSlice.d.ts
|
|
1008
|
-
type TupleSlice<T
|
|
1341
|
+
type TupleSlice<T extends unknown[], S extends number, E extends number = T["length"]> = SkipFirst<TakeFirst<T, E>, S>;
|
|
1009
1342
|
//#endregion
|
|
1010
1343
|
//#region src/util/validation/exhaustiveGuard.d.ts
|
|
1011
1344
|
declare const exhaustiveGuard: (value: never) => never;
|
|
@@ -1017,4 +1350,4 @@ declare const UUIDV4_REGEX: RegExp;
|
|
|
1017
1350
|
//#region src/util/id/uuid/uuidValidateV4.d.ts
|
|
1018
1351
|
declare const uuidValidateV4: (uuid: string) => boolean;
|
|
1019
1352
|
//#endregion
|
|
1020
|
-
export { CamelToKebab, DeepOmit, DeepOmitArray, DeepOptionalProperties, DeepOptionalUndefined, DeepRequiredProperties, ExcludeFunctionProperties, FunctionProperties, ID_SEPARATOR, InvalidOperationError, ItemEntityType, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, KebabToCamel, MENTION_ID_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MapValue, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, PartialByKeys, PropertyNames, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, SkipFirst, TakeFirst, ToData, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, WithMetadata, applyItemMetadataMixin, capitalize, createItemEntityTypeSchema, css, escapeRegExp, exhaustiveGuard, getIsServer, getMentions, getPropertyNames, getRawData, hrtime, html, isPlainObject, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, now, streamToText, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4 };
|
|
1353
|
+
export { AllSpecialValues, CamelToKebab, DeepOmit, DeepOmitArray, DeepOptionalProperties, DeepOptionalUndefined, DeepRequiredProperties, ExcludeFunctionProperties, FunctionProperties, ID_SEPARATOR, InvalidOperationError, ItemEntityType, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, KebabToCamel, MENTION_ID_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MapValue, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, PartialByKeys, PropertyNames, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, SkipFirst, TakeFirst, TakeOne, ToData, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, WithMetadata, applyItemMetadataMixin, capitalize, createItemEntityTypeSchema, css, escapeRegExp, exhaustiveGuard, getIsServer, getMentions, getPropertyNames, getRawData, hrtime, html, isPlainObject, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, now, streamToText, takeOne, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4 };
|