@monterosa/sdk-util 0.17.1-rc.6

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.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * delay.ts
4
+ * util
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ /**
12
+ * @internal
13
+ */
14
+ export declare const delay: (timeout: number) => Promise<void>;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license
3
+ * subscribe.ts
4
+ * util
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ declare type Handler = (...args: any[]) => void;
12
+ export declare class Emitter {
13
+ private readonly emitter;
14
+ private readonly handlers;
15
+ constructor();
16
+ on(event: string, handler: Handler): Unsubscribe;
17
+ off(event: string, handler?: Handler): void;
18
+ emit(event: string, ...args: any[]): void;
19
+ once(event: string, handler: Handler): Unsubscribe;
20
+ }
21
+ /**
22
+ * The unsubscribe function. When it is called, the previously set event
23
+ * listener is removed. It is returned by every observer functions
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const unsubscribe: Unsubscribe = onElementPublished((element) => {
28
+ * console.log('Element published', element);
29
+ * });
30
+ *
31
+ * unsubscribe();
32
+ * ```
33
+ */
34
+ export interface Unsubscribe {
35
+ (): void;
36
+ }
37
+ /**
38
+ * @internal
39
+ */
40
+ export interface Subscribe {
41
+ (emitter: Emitter, event: string, callback: (...args: any[]) => void): Unsubscribe;
42
+ }
43
+ /**
44
+ * @internal
45
+ */
46
+ export declare const subscribe: Subscribe;
47
+ export {};
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * error.ts
4
+ * util
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-31
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ /**
12
+ * MonterosaError extends the standard JavaScript `Error` object. It has
13
+ * an error code so that user can identify the error. Also it has it's own
14
+ * specific `name` "MonterosaError"
15
+ */
16
+ export declare class MonterosaError extends Error {
17
+ /**
18
+ * The name property represents a name for the type of error.
19
+ */
20
+ readonly name = "MonterosaError";
21
+ /**
22
+ * Error code string
23
+ */
24
+ readonly code: string;
25
+ /**
26
+ * @param code - Error code string
27
+ * @param message - A descriptive message for the error
28
+ */
29
+ constructor(code: string, message: string);
30
+ }
31
+ declare type ErrorMap<ErrorCode extends string> = {
32
+ readonly [K in ErrorCode]: (...rest: any[]) => string;
33
+ };
34
+ /**
35
+ * @internal
36
+ */
37
+ export declare function createError<ErrorCode extends string>(code: ErrorCode, messages: ErrorMap<ErrorCode>, ...params: any[]): MonterosaError;
38
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * global.ts
4
+ * util
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ /**
12
+ * Global object polyfill.
13
+ * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
14
+ *
15
+ * @internal
16
+ *
17
+ * @returns typeof globalThis
18
+ */
19
+ export declare function getGlobal(): typeof globalThis;