@sevtech/kit 20.1.4 → 20.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,63 +0,0 @@
1
- import * as _angular_core from '@angular/core';
2
- import { Provider } from '@angular/core';
3
- import { Observable } from 'rxjs';
4
- import { PostVariants, ReceiveVariants, ChannelMessage, PostParameters } from '@sevtech/kit/service-worker/shared';
5
- export { PostMessage, PostVariants, ReceiveMessage, ReceiveVariants, isPostMessage, isReceiveMessage, isSameAction, isSameChannel } from '@sevtech/kit/service-worker/shared';
6
- import { MaybeAsync } from '@sevtech/kit/ng-misc';
7
- import { MaybeFunction } from '@sevtech/kit/misc';
8
-
9
- declare abstract class CommonChannel<Send extends PostVariants, Receive extends ReceiveVariants, Channel extends string> {
10
- protected abstract channel: Channel;
11
- private readonly serviceWorker;
12
- protected readonly isActive$$: _angular_core.Signal<boolean>;
13
- protected listen<const Action extends Receive['action']>(action: Action): Observable<ChannelMessage<Receive & {
14
- action: Action;
15
- }, Channel>>;
16
- protected postMessage<const Action extends Send['action']>(...[action, payload]: PostParameters<Send, Action>): Promise<void>;
17
- protected requestMessage<const Action extends Send['action']>(...[action, payload]: PostParameters<Send, Action>): Promise<Receive & {
18
- action: Action;
19
- }>;
20
- }
21
-
22
- declare const ErrorCodes: {
23
- readonly Unavailable: "UNAVAILABLE";
24
- readonly Uncontrolled: "UNCONTROLLED";
25
- readonly Blocked: "BLOCKED";
26
- readonly RequestTimeout: "REQUEST_TIMEOUT";
27
- readonly DeserializationError: "DESERIALIZATION_ERROR";
28
- };
29
- type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
30
- declare class ServiceWorkerError extends Error {
31
- readonly name: string;
32
- readonly code: ErrorCode;
33
- constructor(code: ErrorCode, cause?: unknown);
34
- }
35
-
36
- type MessageFilterFunction = (message: unknown) => MaybeAsync<boolean>;
37
- interface Config {
38
- /**
39
- * Включить или отключить логи в ServiceWorker
40
- * @default false
41
- */
42
- debug: boolean;
43
- /**
44
- * Таймаут ожидания ответа
45
- * @description Если сервис-воркер не ответил за указанное время — промис реджектится с ошибкой RequestTimeout
46
- * @default 8000
47
- */
48
- requestTimeout: number;
49
- /**
50
- * Таймаут ожидания ответа на ping
51
- * @description Если сервис-воркер не ответил на ping за указанное время — считается недоступным
52
- * @default 5000
53
- */
54
- pingTimeout: number;
55
- }
56
- type ServiceWorkerConfig = Partial<Config>;
57
-
58
- declare function provideServiceWorkerPing(data: MaybeFunction<Observable<unknown>>): Provider;
59
- declare function provideServiceWorkerMessageFilter(data: MaybeFunction<MessageFilterFunction>, inject?: boolean): Provider;
60
- declare function provideServiceWorkerConfig(config: MaybeFunction<ServiceWorkerConfig>): Provider;
61
-
62
- export { ErrorCodes, CommonChannel as ServiceWorkerChannel, ServiceWorkerError, provideServiceWorkerConfig, provideServiceWorkerMessageFilter, provideServiceWorkerPing };
63
- export type { ServiceWorkerConfig };
@@ -1,54 +0,0 @@
1
- import { PostVariants, ReceiveMessage } from '@sevtech/kit/service-worker/shared';
2
- export { PostMessage, PostParameters, isPostMessage, isReceiveMessage } from '@sevtech/kit/service-worker/shared';
3
-
4
- /**
5
- * Обрабатывает служебные сообщения библиотеки
6
- */
7
- declare function defineSystemChannel(): void;
8
- declare function listenLoggerStateChange(listener: (enabled: boolean) => void): void;
9
- declare function logger(message: string, ...args: unknown[]): void;
10
-
11
- type ActionHandler<Payload = unknown> = (payload: Payload, event: ExtendableMessageEvent) => void | Promise<void>;
12
- type ChannelHandlerMap<Send extends PostVariants> = {
13
- [K in Send['action']]: ActionHandler<Extract<Send, {
14
- action: K;
15
- }> extends {
16
- payload: infer P;
17
- } ? P : undefined>;
18
- };
19
- /**
20
- * Создаёт обработчик канала для использования в handleChannels
21
- * @param channel - имя канала (должно совпадать с channel на Angular стороне)
22
- * @param handlers - карта обработчиков по action
23
- */
24
- declare function defineChannel<Send extends PostVariants>(channel: string, handlers: ChannelHandlerMap<Send>): void;
25
-
26
- /**
27
- * Обрабатывает сообщения которые приходят из Angular service.
28
- * Системный канал (PING) подключается автоматически.
29
-
30
- * @example
31
- * self.addEventListener('message', handleByChannels);
32
- */
33
- declare function handleChannels(event: ExtendableMessageEvent): boolean;
34
-
35
- interface NotifyOptions {
36
- /** Отправить только этим клиентам (ID или массив ID) */
37
- clients?: string | string[];
38
- /** Исключить этих клиентов (ID или массив ID) */
39
- exclude?: string | string[];
40
- /** Тип клиентов. По умолчанию 'window' */
41
- type?: ClientQueryOptions['type'];
42
- }
43
- /**
44
- * Отправляет сообщение клиентам (вкладкам), контролируемым данным сервис-воркером.
45
- *
46
- * По умолчанию — всем window-клиентам.
47
- * Через options.clients — только указанным.
48
- * Через options.exclude — всем кроме указанных.
49
- */
50
- declare function notifyClients<Action extends string, Message = never>(message: {
51
- channel: string;
52
- } & ReceiveMessage<Action, Message>, options?: NotifyOptions): Promise<void>;
53
-
54
- export { defineChannel, defineSystemChannel, handleChannels, listenLoggerStateChange, logger, notifyClients };
@@ -1,42 +0,0 @@
1
- type PostVariants = PostMessage<string> | PostMessage<string, never>;
2
- type ReceiveVariants = ReceiveMessage<string> | ReceiveMessage<string, never>;
3
- type ChannelMessage<Message, Channel extends string> = Message & {
4
- channel: Channel;
5
- };
6
- type PostParameters<Config, Action> = Extract<Config, {
7
- action: Action;
8
- }> extends {
9
- payload: infer P;
10
- } ? [Action, P] : [Action];
11
- type PostMessage<Action, Payload = unknown> = [Payload] extends [never] ? {
12
- action: Action;
13
- } : {
14
- action: Action;
15
- payload: Payload;
16
- };
17
- type ReceiveMessage<Action, Message = unknown> = [Message] extends [never] ? {
18
- action: Action;
19
- } : {
20
- action: Action;
21
- message: Message;
22
- };
23
-
24
- declare const SYSTEM_CHANNEL: "SYSTEM_CHANNEL";
25
- declare const SYSTEM_ACTIONS: {
26
- /** Пинг сервис воркера */
27
- readonly Ping: "PING";
28
- /** Ответ на пинг от сервиса воркера */
29
- readonly Pong: "PONG";
30
- /** Включение или выключения логирования в сервис-воркере*/
31
- readonly Logger: "LOGGER";
32
- };
33
-
34
- declare function isPostMessage<T extends PostVariants, Channel extends string>(message: unknown): message is ChannelMessage<T, Channel>;
35
- declare function isReceiveMessage<Receive extends ReceiveVariants>(message: unknown): message is ChannelMessage<Receive, string>;
36
- declare function isSameChannel<Channel extends string, Receive extends ReceiveVariants>(message: ChannelMessage<Receive, string>, channel: Channel): message is ChannelMessage<Receive, Channel>;
37
- declare function isSameAction<Receive extends ReceiveVariants, Action>(message: Receive, action: Action): message is ChannelMessage<Receive & {
38
- action: Action;
39
- }, string>;
40
-
41
- export { SYSTEM_ACTIONS, SYSTEM_CHANNEL, isPostMessage, isReceiveMessage, isSameAction, isSameChannel };
42
- export type { ChannelMessage, PostMessage, PostParameters, PostVariants, ReceiveMessage, ReceiveVariants };