@powerlines/deepkit 0.4.91 → 0.4.92
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/vendor/core.d.cts +827 -1
- package/dist/vendor/core.d.ts +827 -1
- package/dist/vendor/type-spec.d.cts +192 -1
- package/dist/vendor/type-spec.d.ts +192 -1
- package/dist/vendor/type.d.cts +3425 -1
- package/dist/vendor/type.d.ts +3425 -1
- package/package.json +5 -4
package/dist/vendor/core.d.ts
CHANGED
|
@@ -1 +1,827 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Makes sure the error once printed using console.log contains the actual class name.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```
|
|
6
|
+
* class MyApiError extends CustomerError {}
|
|
7
|
+
*
|
|
8
|
+
* throw MyApiError() // prints MyApiError instead of simply "Error".
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare class CustomError extends Error {
|
|
14
|
+
name: string;
|
|
15
|
+
constructor(...args: any[]);
|
|
16
|
+
}
|
|
17
|
+
export interface CustomError {
|
|
18
|
+
cause?: unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface ClassType<T = any> {
|
|
24
|
+
new (...args: any[]): T;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export type AbstractClassType<T = any> = abstract new (...args: any[]) => T;
|
|
30
|
+
export type ExtractClassType<T> = T extends AbstractClassType<infer K> ? K : never;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the class name either of the class definition or of the class of an instance.
|
|
33
|
+
*
|
|
34
|
+
* Note when code is minimized/uglified this output will change. You should disable in your compile the
|
|
35
|
+
* className modification.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* class User {}
|
|
40
|
+
*
|
|
41
|
+
* expect(getClassName(User)).toBe('User');
|
|
42
|
+
* expect(getClassName(new User())).toBe('User');
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export declare function getClassName<T>(classTypeOrInstance: ClassType<T> | Object): string;
|
|
48
|
+
/**
|
|
49
|
+
* Same as getClassName but appends the propertyName.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export declare function getClassPropertyName<T>(classType: ClassType<T> | Object, propertyName: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export declare function applyDefaults<T>(classType: ClassType<T>, target: {
|
|
57
|
+
[k: string]: any;
|
|
58
|
+
}): T;
|
|
59
|
+
/**
|
|
60
|
+
* Tries to identify the object by normalised result of Object.toString(obj).
|
|
61
|
+
*/
|
|
62
|
+
export declare function identifyType(obj: any): string;
|
|
63
|
+
/**
|
|
64
|
+
* Returns true if the given obj is a plain object, and no class instance.
|
|
65
|
+
*
|
|
66
|
+
* isPlainObject(\{\}) === true
|
|
67
|
+
* isPlainObject(new ClassXY) === false
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export declare function isPlainObject(obj: any): obj is object;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the ClassType for a given instance.
|
|
74
|
+
*/
|
|
75
|
+
export declare function getClassTypeFromInstance<T>(target: T): ClassType<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Returns true when target is a class instance.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isClassInstance(target: any): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Returns a human-readable string representation from the given value.
|
|
82
|
+
*/
|
|
83
|
+
export declare function stringifyValueWithType(value: any, depth?: number): string;
|
|
84
|
+
/**
|
|
85
|
+
* Changes the class of a given instance and returns the new object.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
*
|
|
90
|
+
* class Model1 {
|
|
91
|
+
* id: number = 0;
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* class Model2 {
|
|
95
|
+
* id: number = 0;
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* const model1 = new Model1();
|
|
99
|
+
* const model2 = changeClass(model1, Model2);
|
|
100
|
+
* model2 instanceof Model2; //true
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function changeClass<T>(value: object, newClass: ClassType<T>): T;
|
|
104
|
+
export declare function prettyPrintObject(object: object, depth?: number): string;
|
|
105
|
+
/**
|
|
106
|
+
* Returns true if given obj is a function.
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
export declare function isFunction(obj: any): obj is Function;
|
|
111
|
+
export declare const AsyncFunction: {
|
|
112
|
+
new (...args: string[]): Function;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Returns true if given obj is a async function.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export declare function isAsyncFunction(obj: any): obj is (...args: any[]) => Promise<any>;
|
|
120
|
+
/**
|
|
121
|
+
* Returns true if given obj is a promise like object.
|
|
122
|
+
*
|
|
123
|
+
* Note: There's not way to check if it's actually a Promise using instanceof since
|
|
124
|
+
* there are a lot of different implementations around.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export declare function isPromise<T>(obj: any | Promise<T>): obj is Promise<T>;
|
|
129
|
+
/**
|
|
130
|
+
* Returns true if given obj is a ES6 class (ES5 fake classes are not supported).
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
export declare function isClass(obj: any): obj is AbstractClassType;
|
|
135
|
+
export declare function isGlobalClass(obj: any): obj is AbstractClassType;
|
|
136
|
+
/**
|
|
137
|
+
* Returns true for real objects: object literals ({}) or class instances (new MyClass).
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export declare function isObject(obj: any): obj is {
|
|
142
|
+
[key: string]: any;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Returns true if given obj is a plain object, and no Date, Array, Map, Set, etc.
|
|
146
|
+
*
|
|
147
|
+
* This is different to isObject and used in the type system to differentiate
|
|
148
|
+
* between JS objects in general and what we define as ReflectionKind.objectLiteral.
|
|
149
|
+
* Since we have Date, Set, Map, etc. in the type system, we need to differentiate
|
|
150
|
+
* between them and all other object literals.
|
|
151
|
+
*/
|
|
152
|
+
export declare function isObjectLiteral(obj: any): obj is {
|
|
153
|
+
[key: string]: any;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* @public
|
|
157
|
+
*/
|
|
158
|
+
export declare const isArray: (obj: any) => obj is any[];
|
|
159
|
+
/**
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
export declare function isNull(obj: any): obj is null;
|
|
163
|
+
/**
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
export declare function isUndefined(obj: any): obj is undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Checks if obj is not null and not undefined.
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
export declare function isSet(obj: any): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
export declare function isNumber(obj: any): obj is number;
|
|
177
|
+
/**
|
|
178
|
+
* Returns true if given value is strictly a numeric string value (or a number).
|
|
179
|
+
*
|
|
180
|
+
* ```typescript
|
|
181
|
+
* isNumeric(12); //true
|
|
182
|
+
* isNumeric('12'); //true
|
|
183
|
+
* isNumeric('12.3'); //true
|
|
184
|
+
* isNumeric('12.3 '); //false
|
|
185
|
+
* isNumeric('12px'); //false
|
|
186
|
+
* ```
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
export declare function isNumeric(s: string | number): boolean;
|
|
190
|
+
export declare const isInteger: (obj: any) => obj is number;
|
|
191
|
+
/**
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
export declare function isString(obj: any): obj is string;
|
|
195
|
+
/**
|
|
196
|
+
* @public
|
|
197
|
+
*/
|
|
198
|
+
export declare function indexOf<T>(array: T[], item: T): number;
|
|
199
|
+
/**
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
export declare function sleep(seconds: number): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Creates a shallow copy of given array.
|
|
205
|
+
*
|
|
206
|
+
* @public
|
|
207
|
+
*/
|
|
208
|
+
export declare function copy<T>(v: T[]): T[];
|
|
209
|
+
/**
|
|
210
|
+
* Checks whether given array or object is empty (no keys). If given object is falsy, returns false.
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
export declare function empty<T>(value?: T[] | object | {}): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Returns the size of given array or object.
|
|
217
|
+
*
|
|
218
|
+
* @public
|
|
219
|
+
*/
|
|
220
|
+
export declare function size<T>(array: T[] | {
|
|
221
|
+
[key: string]: T;
|
|
222
|
+
}): number;
|
|
223
|
+
/**
|
|
224
|
+
* Returns the first key of a given object.
|
|
225
|
+
*
|
|
226
|
+
* @public
|
|
227
|
+
*/
|
|
228
|
+
export declare function firstKey(v: {
|
|
229
|
+
[key: string]: any;
|
|
230
|
+
} | object): string | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* Returns the last key of a given object.
|
|
233
|
+
*
|
|
234
|
+
* @public
|
|
235
|
+
*/
|
|
236
|
+
export declare function lastKey(v: {
|
|
237
|
+
[key: string]: any;
|
|
238
|
+
} | object): string | undefined;
|
|
239
|
+
/**
|
|
240
|
+
* Returns the first value of given array or object.
|
|
241
|
+
*
|
|
242
|
+
* @public
|
|
243
|
+
*/
|
|
244
|
+
export declare function first<T>(v: {
|
|
245
|
+
[key: string]: T;
|
|
246
|
+
} | T[]): T | undefined;
|
|
247
|
+
/**
|
|
248
|
+
* Returns the last value of given array or object.
|
|
249
|
+
*
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
export declare function last<T>(v: {
|
|
253
|
+
[key: string]: T;
|
|
254
|
+
} | T[]): T | undefined;
|
|
255
|
+
/**
|
|
256
|
+
* Returns the average of a number array.
|
|
257
|
+
*
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
export declare function average(array: number[]): number;
|
|
261
|
+
/**
|
|
262
|
+
* @public
|
|
263
|
+
*/
|
|
264
|
+
export declare function prependObjectKeys(o: {
|
|
265
|
+
[k: string]: any;
|
|
266
|
+
}, prependText: string): {
|
|
267
|
+
[k: string]: any;
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* @public
|
|
271
|
+
*/
|
|
272
|
+
export declare function appendObject(origin: {
|
|
273
|
+
[k: string]: any;
|
|
274
|
+
}, extend: {
|
|
275
|
+
[k: string]: any;
|
|
276
|
+
}, prependKeyName?: string): void;
|
|
277
|
+
/**
|
|
278
|
+
* A better alternative to "new Promise()" that supports error handling and maintains the stack trace for Error.stack.
|
|
279
|
+
*
|
|
280
|
+
* When you use `new Promise()` you need to wrap your code inside a try-catch to call `reject` on error.
|
|
281
|
+
* asyncOperation() does this automatically.
|
|
282
|
+
*
|
|
283
|
+
* When you use `new Promise()` you will lose the stack trace when `reject(new Error())` is called.
|
|
284
|
+
* asyncOperation() makes sure the error stack trace is the correct one.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* await asyncOperation(async (resolve, reject) => {
|
|
289
|
+
* await doSomething(); //if this fails, reject() will automatically be called
|
|
290
|
+
* stream.on('data', (data) => {
|
|
291
|
+
* resolve(data); //at some point you MUST call resolve(data)
|
|
292
|
+
* });
|
|
293
|
+
* });
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @public
|
|
297
|
+
* @reflection never
|
|
298
|
+
*/
|
|
299
|
+
export declare function asyncOperation<T>(executor: (resolve: (value: T) => void, reject: (error: any) => void) => void | Promise<void>): Promise<T>;
|
|
300
|
+
/**
|
|
301
|
+
* When an API is called that returns a promise that loses the stack trace on error, you can use fixAsyncOperation().
|
|
302
|
+
*
|
|
303
|
+
* ```typescript
|
|
304
|
+
* cons storage = new BrokenPromiseStorage();
|
|
305
|
+
* const files = await fixAsyncOperation(storage.files('/'));
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
export declare function fixAsyncOperation<T>(promise: Promise<T>): Promise<T>;
|
|
309
|
+
/**
|
|
310
|
+
* @public
|
|
311
|
+
*/
|
|
312
|
+
export declare function mergePromiseStack<T>(promise: Promise<T>, stack?: string): Promise<T>;
|
|
313
|
+
/**
|
|
314
|
+
* @beta
|
|
315
|
+
*/
|
|
316
|
+
export declare function createStack(removeCallee?: boolean): string;
|
|
317
|
+
/**
|
|
318
|
+
* @beta
|
|
319
|
+
*/
|
|
320
|
+
export declare function mergeStack(error: Error, stack: string): void;
|
|
321
|
+
/**
|
|
322
|
+
* Makes sure the given value is an error. If it's not an error, it creates a new error with the given value as message.
|
|
323
|
+
*/
|
|
324
|
+
export declare function ensureError(error?: any, classType?: ClassType): Error;
|
|
325
|
+
export declare function collectForMicrotask<T>(callback: (args: T[]) => void): (arg: T) => void;
|
|
326
|
+
/**
|
|
327
|
+
* Returns the current time as seconds.
|
|
328
|
+
*
|
|
329
|
+
* @public
|
|
330
|
+
*/
|
|
331
|
+
export declare function time(): number;
|
|
332
|
+
/**
|
|
333
|
+
* @public
|
|
334
|
+
*/
|
|
335
|
+
export declare function getPathValue(bag: {
|
|
336
|
+
[field: string]: any;
|
|
337
|
+
}, parameterPath: string, defaultValue?: any): any;
|
|
338
|
+
/**
|
|
339
|
+
* @public
|
|
340
|
+
*/
|
|
341
|
+
export declare function setPathValue(bag: object, parameterPath: string, value: any): void;
|
|
342
|
+
/**
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
export declare function deletePathValue(bag: object, parameterPath: string): void;
|
|
346
|
+
/**
|
|
347
|
+
* Returns the human-readable byte representation.
|
|
348
|
+
*
|
|
349
|
+
* @public
|
|
350
|
+
*/
|
|
351
|
+
export declare function humanBytes(bytes: number, si?: boolean): string;
|
|
352
|
+
/**
|
|
353
|
+
* Returns the number of properties on `obj`. This is 20x faster than Object.keys(obj).length.
|
|
354
|
+
*/
|
|
355
|
+
export declare function getObjectKeysSize(obj: object): number;
|
|
356
|
+
export declare function isConstructable(fn: any): boolean;
|
|
357
|
+
export declare function isPrototypeOfBase(prototype: AbstractClassType | undefined, base: ClassType): boolean;
|
|
358
|
+
export declare function getParentClass(classType: ClassType): ClassType | undefined;
|
|
359
|
+
export declare function getInheritanceChain(classType: ClassType): ClassType[];
|
|
360
|
+
export declare function inDebugMode(): boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Create a new class with the given name.
|
|
363
|
+
* This is currently the only know way to make it workable in browsers too.
|
|
364
|
+
*/
|
|
365
|
+
export declare function createDynamicClass(name: string, base?: ClassType): ClassType;
|
|
366
|
+
export declare function isIterable(value: any): boolean;
|
|
367
|
+
export declare function iterableSize(value: Array<unknown> | Set<unknown> | Map<unknown, unknown>): number;
|
|
368
|
+
/**
|
|
369
|
+
* Returns __filename, works in both cjs and esm.
|
|
370
|
+
*/
|
|
371
|
+
export declare function getCurrentFileName(): string;
|
|
372
|
+
/**
|
|
373
|
+
* Escape special characters in a regex string, so it can be used as a literal string.
|
|
374
|
+
*/
|
|
375
|
+
export declare function escapeRegExp(string: string): string;
|
|
376
|
+
export declare function hasProperty(object: any, property: any): boolean;
|
|
377
|
+
/**
|
|
378
|
+
* Returns an iterator of numbers from start (inclusive) to stop (exclusive) by step.
|
|
379
|
+
*/
|
|
380
|
+
export declare function range(startOrLength: number, stop?: number, step?: number): IterableIterator<number>;
|
|
381
|
+
/**
|
|
382
|
+
* Returns an array of numbers from start (inclusive) to stop (exclusive) by step.
|
|
383
|
+
*
|
|
384
|
+
* Works the same as python's range function.
|
|
385
|
+
*/
|
|
386
|
+
export declare function rangeArray(startOrLength: number, stop?: number, step?: number): number[];
|
|
387
|
+
/**
|
|
388
|
+
* Returns a combined array of the given arrays.
|
|
389
|
+
*
|
|
390
|
+
* Works the same as python's zip function.
|
|
391
|
+
*/
|
|
392
|
+
export declare function zip<T extends (readonly unknown[])[]>(...args: T): {
|
|
393
|
+
[K in keyof T]: T[K] extends (infer V)[] ? V : never;
|
|
394
|
+
}[];
|
|
395
|
+
/**
|
|
396
|
+
* Forwards the runtime type arguments from function x to function y.
|
|
397
|
+
* This is necessary when a generic function is overridden and forwarded to something else.
|
|
398
|
+
*
|
|
399
|
+
* ```typescript
|
|
400
|
+
* let generic = <T>(type?: ReceiveType<T>) => undefined;
|
|
401
|
+
*
|
|
402
|
+
* let forwarded<T> = () => {
|
|
403
|
+
* forwardTypeArguments(forwarded, generic); //all type arguments are forwarded to generic()
|
|
404
|
+
* generic(); //call as usual
|
|
405
|
+
* }
|
|
406
|
+
*
|
|
407
|
+
* forwarded<any>(); //generic receives any in runtime.
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* Note that generic.bind(this) will not work, as bind() creates a new function and forwarded type arguments can not
|
|
411
|
+
* reach the original function anymore.
|
|
412
|
+
*
|
|
413
|
+
* ```typescript
|
|
414
|
+
* let forwarded<T> = () => {
|
|
415
|
+
* const bound = generic.bind(this);
|
|
416
|
+
* forwardTypeArguments(forwarded, bound); //can not be forwarded anymore
|
|
417
|
+
* bound(); //fails
|
|
418
|
+
* }
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* This is a limitation of JavaScript. In this case you have to manually forward type arguments.
|
|
422
|
+
*
|
|
423
|
+
* ```typescript
|
|
424
|
+
* let forwarded<T> = (type?: ReceiveType<T>) => {
|
|
425
|
+
* const bound = generic.bind(this);
|
|
426
|
+
* bound(type);
|
|
427
|
+
* }
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
export declare function forwardTypeArguments(x: any, y: any): void;
|
|
431
|
+
export declare function formatError(error: any, withStack?: boolean): string;
|
|
432
|
+
/**
|
|
433
|
+
* Asserts that the given object is an instance of the given class.
|
|
434
|
+
*/
|
|
435
|
+
export declare function assertInstanceOf<T>(object: any, constructor: {
|
|
436
|
+
new (...args: any[]): T;
|
|
437
|
+
}): asserts object is T;
|
|
438
|
+
/**
|
|
439
|
+
* Asserts that the given value is defined (not null and not undefined).
|
|
440
|
+
*/
|
|
441
|
+
export declare function assertDefined<T>(value: T): asserts value is NonNullable<T>;
|
|
442
|
+
export declare type __ΩCustomError = any[];
|
|
443
|
+
export declare type __ΩClassType = any[];
|
|
444
|
+
export declare type __ΩAbstractClassType = any[];
|
|
445
|
+
export declare type __ΩExtractClassType = any[];
|
|
446
|
+
/**
|
|
447
|
+
* Logs every call to this method on stdout.
|
|
448
|
+
*
|
|
449
|
+
* @public
|
|
450
|
+
*/
|
|
451
|
+
export declare function log(): (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
452
|
+
/**
|
|
453
|
+
* Makes sure that calls to this async method are stacked up and are called one after another and not parallel.
|
|
454
|
+
*
|
|
455
|
+
* @public
|
|
456
|
+
*/
|
|
457
|
+
export declare function stack(): (target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) => void;
|
|
458
|
+
/**
|
|
459
|
+
* Makes sure that this async method is only running once at a time. When this method is running and it is tried
|
|
460
|
+
* to call it another times, that call is "dropped" and it returns simply the result of the previous running call (waiting for it to complete first).
|
|
461
|
+
*
|
|
462
|
+
* @public
|
|
463
|
+
*/
|
|
464
|
+
export declare function singleStack(): (target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) => void;
|
|
465
|
+
/**
|
|
466
|
+
* Returns the enum label for a given enum value.
|
|
467
|
+
*
|
|
468
|
+
* @public
|
|
469
|
+
*/
|
|
470
|
+
export declare function getEnumLabel(enumType: {
|
|
471
|
+
[field: string]: any;
|
|
472
|
+
}, id: any): any;
|
|
473
|
+
/**
|
|
474
|
+
* Returns all possible enum labels.
|
|
475
|
+
*
|
|
476
|
+
* @public
|
|
477
|
+
*/
|
|
478
|
+
export declare function getEnumLabels(enumDefinition: any): string[];
|
|
479
|
+
/**
|
|
480
|
+
* Returns all possible enum keys.
|
|
481
|
+
*
|
|
482
|
+
* @public
|
|
483
|
+
*/
|
|
484
|
+
export declare function getEnumValues(enumDefinition: any): any[];
|
|
485
|
+
export declare function getEnumKeyLabelMap(enumDefinition: any): Map<any, string>;
|
|
486
|
+
/**
|
|
487
|
+
* Checks whether given enum value is valid.
|
|
488
|
+
*
|
|
489
|
+
* @public
|
|
490
|
+
*/
|
|
491
|
+
export declare function isValidEnumValue(enumDefinition: any, value: any, allowLabelsAsValue?: boolean): boolean;
|
|
492
|
+
/**
|
|
493
|
+
* @public
|
|
494
|
+
*/
|
|
495
|
+
export declare function getValidEnumValue(enumDefinition: any, value: any, allowLabelsAsValue?: boolean): any;
|
|
496
|
+
/**
|
|
497
|
+
* Iterator for each key of an array or object.
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```
|
|
501
|
+
* for (const i of eachKey(['a', 'b']) {
|
|
502
|
+
* console.log(i); //0, 1
|
|
503
|
+
* }
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* @public
|
|
507
|
+
* @category iterator
|
|
508
|
+
*/
|
|
509
|
+
export declare function eachKey<T>(object: ArrayLike<T>): IterableIterator<number>;
|
|
510
|
+
/** @public */
|
|
511
|
+
export declare function eachKey<T extends {
|
|
512
|
+
[key: string]: any;
|
|
513
|
+
}, K extends keyof T>(object: T): IterableIterator<string>;
|
|
514
|
+
/**
|
|
515
|
+
* Iterator for each value of an array or object.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```
|
|
519
|
+
* for (const v of each(['a', 'b']) {
|
|
520
|
+
* console.log(v); //a, b
|
|
521
|
+
* }
|
|
522
|
+
* ```
|
|
523
|
+
*
|
|
524
|
+
* @public
|
|
525
|
+
* @category iterator
|
|
526
|
+
*/
|
|
527
|
+
export declare function each<T>(object: {
|
|
528
|
+
[s: string]: T;
|
|
529
|
+
} | ArrayLike<T>): IterableIterator<T>;
|
|
530
|
+
/**
|
|
531
|
+
* Iterator for key value pair of an array or object.
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```
|
|
535
|
+
* for (const [i, v] of eachPair(['a', 'b']) {
|
|
536
|
+
* console.log(i, v); //0 a, 1 b
|
|
537
|
+
* }
|
|
538
|
+
*
|
|
539
|
+
* for (const [i, v] of eachPair({'foo': 'bar}) {
|
|
540
|
+
* console.log(i, v); //foo bar
|
|
541
|
+
* }
|
|
542
|
+
* ```
|
|
543
|
+
*
|
|
544
|
+
* @public
|
|
545
|
+
* @category iterator
|
|
546
|
+
*/
|
|
547
|
+
export declare function eachPair<T>(object: ArrayLike<T>): IterableIterator<[
|
|
548
|
+
number,
|
|
549
|
+
T
|
|
550
|
+
]>;
|
|
551
|
+
/** @public */
|
|
552
|
+
export declare function eachPair<T>(object: {
|
|
553
|
+
[s: string]: T;
|
|
554
|
+
}): IterableIterator<[
|
|
555
|
+
string,
|
|
556
|
+
T
|
|
557
|
+
]>;
|
|
558
|
+
export declare class Timer {
|
|
559
|
+
protected timeoutTimers: any[];
|
|
560
|
+
setTimeout(cb: () => void, timeout: number): any;
|
|
561
|
+
/**
|
|
562
|
+
* Clears all timers at once.
|
|
563
|
+
*/
|
|
564
|
+
clear(): void;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* This lock mechanism works only for one process (worker).
|
|
568
|
+
*
|
|
569
|
+
* live-mutex: has horrible API and doesn't allow to check if an key is currently locked.
|
|
570
|
+
* proper-filelock: No way to do a correct mutex locking with event-driven blocking acquire() method.
|
|
571
|
+
* redislock: Very bad performance on high-load (when multiple locks on the same key `wait`, since it loops)
|
|
572
|
+
* mongodb lock: even worse performance than redis. Jesus.
|
|
573
|
+
*/
|
|
574
|
+
export declare class ProcessLock {
|
|
575
|
+
readonly id: string;
|
|
576
|
+
private holding;
|
|
577
|
+
protected ttlTimeout: any;
|
|
578
|
+
constructor(id: string);
|
|
579
|
+
acquire(ttl?: number, timeout?: number): Promise<void>;
|
|
580
|
+
isLocked(): boolean;
|
|
581
|
+
tryLock(ttl?: number): boolean;
|
|
582
|
+
unlock(): void;
|
|
583
|
+
}
|
|
584
|
+
export declare class ProcessLocker {
|
|
585
|
+
/**
|
|
586
|
+
*
|
|
587
|
+
* @param id
|
|
588
|
+
* @param ttl optional defines when the times automatically unlocks.
|
|
589
|
+
* @param timeout if after `timeout` seconds the lock isn't acquired, it throws an error.
|
|
590
|
+
*/
|
|
591
|
+
acquireLock(id: string, ttl?: number, timeout?: number): Promise<ProcessLock>;
|
|
592
|
+
tryLock(id: string, ttl?: number): Promise<ProcessLock | undefined>;
|
|
593
|
+
isLocked(id: string): boolean;
|
|
594
|
+
}
|
|
595
|
+
export declare class Mutex {
|
|
596
|
+
protected promise?: Promise<void>;
|
|
597
|
+
protected resolver?: Function;
|
|
598
|
+
unlock(): void;
|
|
599
|
+
lock(): Promise<void>;
|
|
600
|
+
}
|
|
601
|
+
export declare class ParsedHost {
|
|
602
|
+
host: string;
|
|
603
|
+
port: number;
|
|
604
|
+
unixSocket: string;
|
|
605
|
+
get isUnixSocket(): boolean;
|
|
606
|
+
get isHostname(): boolean;
|
|
607
|
+
get hostWithIp(): string;
|
|
608
|
+
toString(): string;
|
|
609
|
+
getWebSocketUrl(secure?: boolean): string;
|
|
610
|
+
getHttpUrl(secure?: boolean): string;
|
|
611
|
+
}
|
|
612
|
+
export declare function parseHost(hostWithIpOrUnixPath: string): ParsedHost;
|
|
613
|
+
export declare function toFastProperties(obj: any): void;
|
|
614
|
+
export declare class CompilerContext {
|
|
615
|
+
readonly context: Map<string, any>;
|
|
616
|
+
protected constVariables: Map<any, string>;
|
|
617
|
+
maxReservedVariable: number;
|
|
618
|
+
protected reservedNames: Set<string>;
|
|
619
|
+
protected variableContext: {
|
|
620
|
+
[name: string]: any;
|
|
621
|
+
};
|
|
622
|
+
/**
|
|
623
|
+
* Code that is executed in the context, but before the actual function is generated.
|
|
624
|
+
* This helps for example to initialize dynamically some context variables.
|
|
625
|
+
*/
|
|
626
|
+
preCode: string;
|
|
627
|
+
initialiseVariables: string[];
|
|
628
|
+
config: {
|
|
629
|
+
indent: boolean;
|
|
630
|
+
};
|
|
631
|
+
constructor(config?: Partial<CompilerContext["config"]>);
|
|
632
|
+
reserveName(name: string): string;
|
|
633
|
+
set(values: {
|
|
634
|
+
[name: string]: any;
|
|
635
|
+
}): void;
|
|
636
|
+
/**
|
|
637
|
+
* Returns always the same variable name for the same value.
|
|
638
|
+
* The variable name should not be set afterwards.
|
|
639
|
+
*/
|
|
640
|
+
reserveConst(value: any, name?: string): string;
|
|
641
|
+
reserveVariable(name?: string, value?: any): string;
|
|
642
|
+
raw(functionCode: string): Function;
|
|
643
|
+
protected format(code: string): string;
|
|
644
|
+
build(functionCode: string, ...args: string[]): any;
|
|
645
|
+
buildAsync(functionCode: string, ...args: string[]): Function;
|
|
646
|
+
}
|
|
647
|
+
export declare function indent(indentation: number, prefix?: string): (str?: string) => string;
|
|
648
|
+
export declare function capitalize(string: string): string;
|
|
649
|
+
export type AsyncSubscriber<T> = (event: T) => Promise<void> | void;
|
|
650
|
+
export type Subscriber<T> = (event: T) => Promise<void> | void;
|
|
651
|
+
export type AsyncEventSubscription = {
|
|
652
|
+
unsubscribe: () => void;
|
|
653
|
+
};
|
|
654
|
+
export type EventSubscription = {
|
|
655
|
+
unsubscribe: () => void;
|
|
656
|
+
};
|
|
657
|
+
export declare class EmitterEvent {
|
|
658
|
+
readonly id: number;
|
|
659
|
+
stopped: boolean;
|
|
660
|
+
propagationStopped: boolean;
|
|
661
|
+
/**
|
|
662
|
+
* Stop propagating the event to subsequent event listeners.
|
|
663
|
+
*/
|
|
664
|
+
stopPropagation(): void;
|
|
665
|
+
/**
|
|
666
|
+
* Signal the emitter that you want to abort.
|
|
667
|
+
* Subsequent event listeners will still be called.
|
|
668
|
+
*/
|
|
669
|
+
stop(): void;
|
|
670
|
+
}
|
|
671
|
+
export declare class EventEmitter<T extends EmitterEvent> {
|
|
672
|
+
protected parent?: EventEmitter<any> | undefined;
|
|
673
|
+
protected subscribers: Subscriber<T>[];
|
|
674
|
+
constructor(parent?: EventEmitter<any> | undefined);
|
|
675
|
+
subscribe(callback: Subscriber<T>): EventSubscription;
|
|
676
|
+
emit(event: T): void;
|
|
677
|
+
hasSubscriptions(): boolean;
|
|
678
|
+
}
|
|
679
|
+
export declare class AsyncEventEmitter<T extends EmitterEvent> {
|
|
680
|
+
protected parent?: AsyncEventEmitter<any> | undefined;
|
|
681
|
+
protected subscribers: AsyncSubscriber<T>[];
|
|
682
|
+
constructor(parent?: AsyncEventEmitter<any> | undefined);
|
|
683
|
+
subscribe(callback: AsyncSubscriber<T>): AsyncEventSubscription;
|
|
684
|
+
emit(event: T): Promise<void>;
|
|
685
|
+
hasSubscriptions(): boolean;
|
|
686
|
+
}
|
|
687
|
+
export declare type __ΩAsyncEventSubscription = any[];
|
|
688
|
+
export declare type __ΩEventSubscription = any[];
|
|
689
|
+
export declare const nextTick: (cb: () => void) => any;
|
|
690
|
+
export declare const clearTick: (id: any) => any;
|
|
691
|
+
/**
|
|
692
|
+
* Wraps a function and calls it only `cps` times per frame.
|
|
693
|
+
*
|
|
694
|
+
* This is handy to throttle all kind of rapid calls, like mouse move events or other kind of events.
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
* ```typescript
|
|
698
|
+
* function expensiveFunction() {
|
|
699
|
+
* //...
|
|
700
|
+
* }
|
|
701
|
+
*
|
|
702
|
+
* const throttled = throttleTime(expensiveFunction, 5); //5 calls per second max
|
|
703
|
+
*
|
|
704
|
+
* throttled();
|
|
705
|
+
* throttled();
|
|
706
|
+
* throttled();
|
|
707
|
+
* //throttled will here only be called once
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
710
|
+
export declare function throttleTime(call: Function, cps?: number): (...args: any[]) => void;
|
|
711
|
+
/**
|
|
712
|
+
* This functions returns a stack that is filled as long as the gate is not activated.
|
|
713
|
+
* Once activated all recorded calls go to given callback and subsequent calls go directly to given callback.
|
|
714
|
+
*/
|
|
715
|
+
export declare function bufferedGate<T>(callback: (arg: T) => any): {
|
|
716
|
+
activate: () => void;
|
|
717
|
+
call: (i: T) => void;
|
|
718
|
+
};
|
|
719
|
+
export declare function extractParameters(fn: string | Function | ClassType): string[];
|
|
720
|
+
export declare function extractMethodBody(classCode: string, name: string): string;
|
|
721
|
+
export declare function removeStrings(code: string): string;
|
|
722
|
+
export declare function urlJoin(...path: string[]): string;
|
|
723
|
+
/**
|
|
724
|
+
* @public
|
|
725
|
+
*/
|
|
726
|
+
export declare function arrayHasItem<T>(array: T[], item: T): boolean;
|
|
727
|
+
/**
|
|
728
|
+
* Clears the array so its empty. Returns the amount of removed items.
|
|
729
|
+
*
|
|
730
|
+
* @public
|
|
731
|
+
*/
|
|
732
|
+
export declare function arrayClear<T>(array: T[]): number;
|
|
733
|
+
/**
|
|
734
|
+
* Removes on particular item by reference of an array.
|
|
735
|
+
*
|
|
736
|
+
* @public
|
|
737
|
+
*/
|
|
738
|
+
export declare function arrayRemoveItem<T>(array: T[], item: T): boolean;
|
|
739
|
+
/**
|
|
740
|
+
* Moves a particular item in an array up or down (move>0=down, move<0=up).
|
|
741
|
+
* Changes the array itself.
|
|
742
|
+
*
|
|
743
|
+
* ```typescript
|
|
744
|
+
* const array = ['a', 'b', 'c'];
|
|
745
|
+
*
|
|
746
|
+
* arrayMoveItem(array, 'a', +1); //['b', 'a', 'c']
|
|
747
|
+
* arrayMoveItem(array, 'a', -1); //['a', 'b', 'c']
|
|
748
|
+
*
|
|
749
|
+
* arrayMoveItem(array, 'b', -1); //['b', 'a', 'c']
|
|
750
|
+
* arrayMoveItem(array, 'b', +1); //['a', 'c', 'b']
|
|
751
|
+
*
|
|
752
|
+
* arrayMoveItem(array, 'c', -1); //['b', 'c', 'b']
|
|
753
|
+
* arrayMoveItem(array, 'c', +1); //['a', 'b', 'c']
|
|
754
|
+
*
|
|
755
|
+
* ```
|
|
756
|
+
*
|
|
757
|
+
* @public
|
|
758
|
+
*/
|
|
759
|
+
export declare function arrayMoveItem<A extends T[], T>(array: A, item: T, move: number): A;
|
|
760
|
+
/**
|
|
761
|
+
* Type to use for custom type annotations.
|
|
762
|
+
*
|
|
763
|
+
* Adds runtime meta information to a type without influencing the type itself.
|
|
764
|
+
* This is like an intrinsic type, but only for runtime.
|
|
765
|
+
*
|
|
766
|
+
* ```typescript
|
|
767
|
+
* import { TypeAnnotation } from '@deepkit/core';
|
|
768
|
+
* import { typeAnnotation } from '@deepkit/type';
|
|
769
|
+
*
|
|
770
|
+
* type PrimaryKey = TypeAnnotation<'primaryKey'>;
|
|
771
|
+
* type UserId = string & PrimaryKey;
|
|
772
|
+
*
|
|
773
|
+
* const type = typeOf<UserId>();
|
|
774
|
+
* const metaData = typeAnnotation.getType(type, 'primaryKey');
|
|
775
|
+
* ```
|
|
776
|
+
*
|
|
777
|
+
* Runtime type is `{ __meta?: never & [T, Options] };`
|
|
778
|
+
*
|
|
779
|
+
* @intrinsic
|
|
780
|
+
*/
|
|
781
|
+
export type TypeAnnotation<T extends string, Options = never> = unknown;
|
|
782
|
+
export type InjectMeta<T = never> = TypeAnnotation<"inject", T>;
|
|
783
|
+
export type Inject<Type, Token = never> = Type & InjectMeta<Token>;
|
|
784
|
+
export declare type __ΩTypeAnnotation = any[];
|
|
785
|
+
export declare type __ΩInjectMeta = any[];
|
|
786
|
+
export declare type __ΩInject = any[];
|
|
787
|
+
/**
|
|
788
|
+
* Create a buffer of the given size (uninitialized, so it may contain random data).
|
|
789
|
+
*
|
|
790
|
+
* Note that the result is either Uin8Array or Buffer, depending on the environment.
|
|
791
|
+
* Buffer from NodeJS works slightly different than Uint8Array.
|
|
792
|
+
*/
|
|
793
|
+
export declare const createBuffer: (size: number) => Uint8Array;
|
|
794
|
+
/**
|
|
795
|
+
* Concat multiple buffers into one.
|
|
796
|
+
*/
|
|
797
|
+
export declare function bufferConcat(chunks: Uint8Array[], length?: number): Uint8Array;
|
|
798
|
+
export declare const uint8ArrayToUtf8: (buffer: Uint8Array) => any;
|
|
799
|
+
/**
|
|
800
|
+
* Convert a buffer to a string.
|
|
801
|
+
*/
|
|
802
|
+
export declare function bufferToString(buffer: string | Uint8Array): string;
|
|
803
|
+
export declare function nativeBase64ToUint8Array(base64: string): Uint8Array;
|
|
804
|
+
/**
|
|
805
|
+
* Converts a base64 string to a Uint8Array.
|
|
806
|
+
*/
|
|
807
|
+
export declare const base64ToUint8Array: (v: string) => Uint8Array;
|
|
808
|
+
/**
|
|
809
|
+
* Normalizes the given path.
|
|
810
|
+
* Removes duplicate slashes, removes trailing slashes, adds a leading slash.
|
|
811
|
+
*/
|
|
812
|
+
export declare function pathNormalize(path: string): string;
|
|
813
|
+
/**
|
|
814
|
+
* Returns the directory (dirname) of the given path.
|
|
815
|
+
*/
|
|
816
|
+
export declare function pathDirectory(path: string): string;
|
|
817
|
+
/**
|
|
818
|
+
* Returns the basename of the given path.
|
|
819
|
+
*/
|
|
820
|
+
export declare function pathBasename(path: string): string;
|
|
821
|
+
/**
|
|
822
|
+
* Returns the extension of the given path.
|
|
823
|
+
*/
|
|
824
|
+
export declare function pathExtension(path: string): string;
|
|
825
|
+
export declare function pathJoin(...paths: string[]): string;
|
|
826
|
+
|
|
827
|
+
export {};
|