@sarafapp/iron_core 1.0.64 → 1.0.67
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/package.json +5 -2
- package/index.ts +0 -37
- package/src/BaseModel.ts +0 -127
- package/src/Utils.ts +0 -16
- package/src/accessHandling/AccessControl.ts +0 -33
- package/src/accessHandling/AccessLevel.ts +0 -52
- package/src/accessHandling/Accessible.ts +0 -3
- package/src/accessHandling/EveryDirectiveAccess.ts +0 -7
- package/src/accessHandling/SSO/AuthorizationDirective.ts +0 -65
- package/src/accessHandling/SSO/AuthorizationService.ts +0 -74
- package/src/accessHandling/SSO/EveryLevelAuthorizationDirective.ts +0 -7
- package/src/accessHandling/SSO/SomeLevelsAuthorizationDirective.ts +0 -7
- package/src/accessHandling/SomeDirectiveAccess.ts +0 -7
- package/src/accessHandling/index.ts +0 -9
- package/src/baseDirective/BeforeMountDirective.ts +0 -3
- package/src/baseDirective/BeforeUnMountDirective.ts +0 -3
- package/src/baseDirective/BeforeUpdateDirective.ts +0 -3
- package/src/baseDirective/CreatedDirective.ts +0 -3
- package/src/baseDirective/MountedDirective.ts +0 -3
- package/src/baseDirective/UnMountedDirective.ts +0 -3
- package/src/baseDirective/UpdateDirective.ts +0 -3
- package/src/baseDirective/index.ts +0 -7
- package/src/baseForm/BaseRequestBodyFilter.ts +0 -7
- package/src/baseForm/FormManager.ts +0 -95
- package/src/baseForm/InputControl.ts +0 -182
- package/src/baseForm/InputControlBuilder.ts +0 -59
- package/src/baseForm/InputControlData.ts +0 -16
- package/src/baseForm/RequestBodyFilter.ts +0 -3
- package/src/baseForm/TouchSensitiveForm.ts +0 -47
- package/src/baseForm/UseForm.ts +0 -32
- package/src/baseForm/index.ts +0 -8
- package/src/baseSchedule/Schedule.ts +0 -3
- package/src/baseSchedule/Scheduler.ts +0 -29
- package/src/baseSchedule/index.ts +0 -2
- package/src/baseTable/BaseTable.ts +0 -162
- package/src/baseTable/Constants.ts +0 -26
- package/src/baseTable/OnDestory.ts +0 -3
- package/src/baseTable/RowActionSource.ts +0 -5
- package/src/baseTable/RowClick.ts +0 -3
- package/src/baseTable/RowDoubleClick.ts +0 -3
- package/src/baseTable/RowMetaClick.ts +0 -3
- package/src/baseTable/SelectableTable.ts +0 -86
- package/src/baseTable/TableAction.ts +0 -10
- package/src/baseTable/TableHeaderSchema.ts +0 -44
- package/src/baseTable/TableLoader.ts +0 -3
- package/src/baseTable/TablePaginate.ts +0 -3
- package/src/baseTable/TableService.ts +0 -10
- package/src/baseTable/TableSort.ts +0 -5
- package/src/baseTable/TableSummarySchema.ts +0 -11
- package/src/baseTable/generator/SelectableTableGenerator.ts +0 -65
- package/src/baseTable/generator/TableCellComponentRegistry.ts +0 -15
- package/src/baseTable/generator/TableConfig.ts +0 -18
- package/src/baseTable/generator/TableGenerator.ts +0 -147
- package/src/baseTable/generator/TableSource.ts +0 -34
- package/src/baseTable/index.ts +0 -43
- package/src/baseTable/moduleConnection/Action.ts +0 -12
- package/src/baseTable/moduleConnection/Column.ts +0 -11
- package/src/baseTable/moduleConnection/Table.ts +0 -49
- package/src/baseTable/moduleConnection/TableDestroy.ts +0 -7
- package/src/baseTable/moduleConnection/TableRowClick.ts +0 -7
- package/src/baseTable/moduleConnection/generator/GColumn.ts +0 -10
- package/src/baseTable/moduleConnection/generator/GTable.ts +0 -11
- package/src/composables/UseCrud.ts +0 -53
- package/src/composables/UseData.ts +0 -70
- package/src/composables/UseLoadingStatus.ts +0 -65
- package/src/composables/UseParams.ts +0 -93
- package/src/composables/UseRepository.ts +0 -207
- package/src/composables/UseState.ts +0 -30
- package/src/composables/UseStaticTableService.ts +0 -45
- package/src/composables/index.ts +0 -7
- package/src/constants/Constants.ts +0 -126
- package/src/constants/index.ts +0 -19
- package/src/crudService/CrudService.ts +0 -121
- package/src/crudService/index.ts +0 -1
- package/src/dateHandling/Constants.ts +0 -5
- package/src/dateHandling/Converter.ts +0 -15
- package/src/dateHandling/JalaliDateSetup.ts +0 -42
- package/src/dateHandling/Model.ts +0 -27
- package/src/dateHandling/Utils.ts +0 -49
- package/src/dateHandling/index.ts +0 -5
- package/src/debounce/DebounceAction.ts +0 -4
- package/src/debounce/DebounceService.ts +0 -27
- package/src/debounce/index.ts +0 -2
- package/src/deviceManagement/Constants.ts +0 -4
- package/src/deviceManagement/Visibility.ts +0 -4
- package/src/deviceManagement/VisibilityManager.ts +0 -18
- package/src/deviceManagement/index.ts +0 -3
- package/src/errorHandling/ErrorHandler.ts +0 -3
- package/src/errorHandling/HandleError.ts +0 -20
- package/src/errorHandling/index.ts +0 -2
- package/src/eventSystem/CustomEventDispatcher.ts +0 -13
- package/src/eventSystem/Model.ts +0 -29
- package/src/eventSystem/OnEvent.ts +0 -25
- package/src/eventSystem/index.ts +0 -3
- package/src/feedbackHandling/FailureFeedback.ts +0 -3
- package/src/feedbackHandling/Feedback.ts +0 -34
- package/src/feedbackHandling/HandleFeedback.ts +0 -28
- package/src/feedbackHandling/InfoFeedback.ts +0 -3
- package/src/feedbackHandling/SuccessFeedback.ts +0 -3
- package/src/feedbackHandling/WarningFeedback.ts +0 -3
- package/src/feedbackHandling/index.ts +0 -6
- package/src/httpClient/ApiBuilder.ts +0 -57
- package/src/httpClient/ErrorHandlerRegistry.ts +0 -29
- package/src/httpClient/HttpClient.ts +0 -77
- package/src/httpClient/Interceptor.ts +0 -5
- package/src/httpClient/index.ts +0 -4
- package/src/initializer/ApplicationInitializer.ts +0 -15
- package/src/initializer/Initializer.ts +0 -3
- package/src/initializer/index.ts +0 -2
- package/src/json/JsonMapper.ts +0 -48
- package/src/json/index.ts +0 -1
- package/src/layout/Constants.ts +0 -11
- package/src/layout/DialogService.ts +0 -75
- package/src/layout/DrawerService.ts +0 -25
- package/src/layout/Toast.ts +0 -14
- package/src/layout/index.ts +0 -4
- package/src/lib/Constants.ts +0 -433
- package/src/lib/Formatter.ts +0 -68
- package/src/lib/Util.ts +0 -113
- package/src/lib/index.ts +0 -3
- package/src/observables/AbstractSubject.ts +0 -21
- package/src/observables/BehaviorSubject.ts +0 -58
- package/src/observables/Observer.ts +0 -3
- package/src/observables/Subject.ts +0 -9
- package/src/observables/index.ts +0 -4
- package/src/process/Proccess.ts +0 -21
- package/src/process/ProcessManager.ts +0 -31
- package/src/process/index.ts +0 -2
- package/src/repository/Params.ts +0 -10
- package/src/repository/Repository.ts +0 -44
- package/src/repository/SyncDetail.ts +0 -8
- package/src/repository/index.ts +0 -4
- package/src/repository/model.ts +0 -9
- package/src/routeGuard/RouteGuard.ts +0 -38
- package/src/routeGuard/index.ts +0 -1
- package/src/search/client/ClientArraySearch.ts +0 -25
- package/src/search/client/ClientSearch.ts +0 -3
- package/src/search/index.ts +0 -2
- package/src/sort/SortDetail.ts +0 -11
- package/src/sort/client/Sorter.ts +0 -28
- package/src/sort/index.ts +0 -4
- package/src/sort/strategies/SimpleSort.ts +0 -35
- package/src/sort/strategies/SortStrategy.ts +0 -4
- package/src/types/Global.ts +0 -1
- package/src/types/index.ts +0 -1
- package/src/validators/Validator.ts +0 -5
- package/src/validators/index.ts +0 -1
- package/src/webSocket/Constants.ts +0 -6
- package/src/webSocket/Model.ts +0 -16
- package/src/webSocket/WebSocketService.ts +0 -153
- package/src/webSocket/index.ts +0 -3
- package/vite.config.ts +0 -55
package/src/process/Proccess.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Nullable } from '../types/Global'
|
|
2
|
-
import { ProcessManager } from './ProcessManager'
|
|
3
|
-
|
|
4
|
-
export abstract class Process {
|
|
5
|
-
public name: string;
|
|
6
|
-
public next: Nullable<Process> = null;
|
|
7
|
-
|
|
8
|
-
constructor(name: string, next: Nullable<Process>) {
|
|
9
|
-
this.name = name
|
|
10
|
-
this.next = next
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public addToManager(manager: ProcessManager) {
|
|
14
|
-
manager.setProcessToMap(this)
|
|
15
|
-
if (this.next) {
|
|
16
|
-
this.next.addToManager(manager)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public abstract execute(): Promise<void>
|
|
21
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Process } from './Proccess';
|
|
2
|
-
|
|
3
|
-
export class ProcessManager {
|
|
4
|
-
private mapProcesses = new Map<string, Process>()
|
|
5
|
-
private processes: Process
|
|
6
|
-
|
|
7
|
-
constructor(process: Process) {
|
|
8
|
-
this.processes = process
|
|
9
|
-
this.assignProcessManager()
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
private assignProcessManager() {
|
|
13
|
-
this.processes.addToManager(this)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public setProcessToMap(process: Process) {
|
|
17
|
-
this.mapProcesses.set(process.name, process)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public async start() {
|
|
21
|
-
await this.processes.execute()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public async startFrom(processName: string) {
|
|
25
|
-
const process = this.mapProcesses.get(processName)
|
|
26
|
-
if(!process) {
|
|
27
|
-
throw new Error(`Process ${processName} not found`)
|
|
28
|
-
}
|
|
29
|
-
await process.execute()
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/process/index.ts
DELETED
package/src/repository/Params.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SortDetail } from "../sort";
|
|
2
|
-
import { SortOrder } from "../constants";
|
|
3
|
-
import { BaseModel } from "../BaseModel";
|
|
4
|
-
|
|
5
|
-
export class Params {
|
|
6
|
-
pageNumber: number = 1;
|
|
7
|
-
itemCount: number = 20;
|
|
8
|
-
sortDetail: SortDetail<BaseModel> = new SortDetail("id", SortOrder.DESC);
|
|
9
|
-
filters: { key: string; value: unknown }[] = [];
|
|
10
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { BaseModel } from "../BaseModel";
|
|
2
|
-
import { FetchListResponse } from "./model";
|
|
3
|
-
import { type Nullable } from "../types";
|
|
4
|
-
import type { SyncDetail } from "./SyncDetail";
|
|
5
|
-
|
|
6
|
-
export interface Repository<Model extends BaseModel> {
|
|
7
|
-
/**
|
|
8
|
-
* Fetches a list of items based on optional query parameters.
|
|
9
|
-
* @param query - Optional query parameters.
|
|
10
|
-
* @returns A promise resolving to an array of items or undefined.
|
|
11
|
-
*/
|
|
12
|
-
fetchList(query?: Record<string, unknown>): Promise<FetchListResponse<Model>>;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Fetches a single item by its ID.
|
|
16
|
-
* @param id - ID of the item to retrieve.
|
|
17
|
-
* @returns A promise resolving to the fetched item or undefined.
|
|
18
|
-
*/
|
|
19
|
-
fetchItemById(id: number): Promise<Nullable<Model>>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new item.
|
|
23
|
-
* @param body - Data for creating the item.
|
|
24
|
-
* @returns A promise resolving to the created item or undefined.
|
|
25
|
-
*/
|
|
26
|
-
createItem<Body>(body: Body): Promise<Nullable<Model>>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Updates an existing item by its ID.
|
|
30
|
-
* @param id - ID of the item to update.
|
|
31
|
-
* @param body - Updated data for the item.
|
|
32
|
-
* @returns A promise resolving to the updated item or undefined.
|
|
33
|
-
*/
|
|
34
|
-
updateItem<Body>(id: number, body: Body): Promise<Nullable<Model>>;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Deletes an item by its ID.
|
|
38
|
-
* @param id - ID of the item to delete.
|
|
39
|
-
* @returns A promise resolving to a boolean indicating if the deletion was successful.
|
|
40
|
-
*/
|
|
41
|
-
deleteItem(id: number): Promise<boolean>;
|
|
42
|
-
|
|
43
|
-
getSyncDetail(): SyncDetail;
|
|
44
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export class SyncDetail {
|
|
2
|
-
public shouldKeepSync: boolean;
|
|
3
|
-
public intervalInMillisecond: number;
|
|
4
|
-
constructor(shouldKeepSync: boolean, intervalInMillisecond: number) {
|
|
5
|
-
this.shouldKeepSync = shouldKeepSync;
|
|
6
|
-
this.intervalInMillisecond = intervalInMillisecond;
|
|
7
|
-
}
|
|
8
|
-
}
|
package/src/repository/index.ts
DELETED
package/src/repository/model.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export abstract class RouteGuard {
|
|
2
|
-
|
|
3
|
-
protected constructor() {
|
|
4
|
-
this.checkAccessibility = this.checkAccessibility.bind(this);
|
|
5
|
-
this.isAccessible = this.isAccessible.bind(this);
|
|
6
|
-
this.getDestinationRouteName = this.getDestinationRouteName.bind(this);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public async checkAccessibility(to: unknown, from: unknown, next: CallableFunction) {
|
|
10
|
-
if (await this.isAccessible(to, from)) {
|
|
11
|
-
next();
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (await this.getDestinationRouteName()) {
|
|
16
|
-
next({name: await this.getDestinationRouteName()})
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (await this.getDestinationRouteLocation(to, from)) {
|
|
21
|
-
next(await this.getDestinationRouteLocation(to, from));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
next(false);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
protected abstract isAccessible(to: unknown, from: unknown): Promise<boolean>
|
|
29
|
-
|
|
30
|
-
protected async getDestinationRouteName(): Promise<string> {
|
|
31
|
-
return ''
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
protected async getDestinationRouteLocation(to: unknown, from: unknown): Promise<unknown> {
|
|
35
|
-
return null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
package/src/routeGuard/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { RouteGuard } from './RouteGuard'
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ClientSearch } from "./ClientSearch";
|
|
2
|
-
import { Util } from "../../lib/Util";
|
|
3
|
-
|
|
4
|
-
export class ClientArraySearch<T> extends ClientSearch {
|
|
5
|
-
public search(
|
|
6
|
-
items: T[],
|
|
7
|
-
phrase: string,
|
|
8
|
-
column: (item: T) => (string | number)[],
|
|
9
|
-
) {
|
|
10
|
-
const matchedItems: T[] = [];
|
|
11
|
-
item: for (const item of items) {
|
|
12
|
-
for (const value of column(item)) {
|
|
13
|
-
if (
|
|
14
|
-
Util.removeSpacesFromString(String(value).toLowerCase()).indexOf(
|
|
15
|
-
Util.removeSpacesFromString(String(phrase).toLowerCase()),
|
|
16
|
-
) > -1
|
|
17
|
-
) {
|
|
18
|
-
matchedItems.push(item);
|
|
19
|
-
continue item;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return matchedItems;
|
|
24
|
-
}
|
|
25
|
-
}
|
package/src/search/index.ts
DELETED
package/src/sort/SortDetail.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { SortOrder } from "../../constants/Constants";
|
|
2
|
-
import { SortStrategy } from "../strategies/SortStrategy";
|
|
3
|
-
import { SimpleSort } from "../strategies/SimpleSort";
|
|
4
|
-
|
|
5
|
-
export class Sorter {
|
|
6
|
-
public arrayOfObjectSort<T>(
|
|
7
|
-
items: T[],
|
|
8
|
-
by: keyof T,
|
|
9
|
-
order: SortOrder,
|
|
10
|
-
strategy: SortStrategy<T> = new SimpleSort(),
|
|
11
|
-
): T[] {
|
|
12
|
-
if (order === SortOrder.ASC) {
|
|
13
|
-
return strategy.aSort(items, by);
|
|
14
|
-
}
|
|
15
|
-
return strategy.bSort(items, by);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public arraySort(
|
|
19
|
-
items: number[] | string[],
|
|
20
|
-
order: SortOrder,
|
|
21
|
-
strategy: SortStrategy<string | number> = new SimpleSort(),
|
|
22
|
-
) {
|
|
23
|
-
if (order === SortOrder.ASC) {
|
|
24
|
-
return strategy.aSort(items);
|
|
25
|
-
}
|
|
26
|
-
return strategy.bSort(items);
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/sort/index.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { SortStrategy } from "./SortStrategy";
|
|
2
|
-
|
|
3
|
-
export class SimpleSort<T> implements SortStrategy<T> {
|
|
4
|
-
aSort(items: T[], by?: keyof T): T[] {
|
|
5
|
-
return items.sort((a: T, b: T) => {
|
|
6
|
-
const aItem = a[by as keyof T] ?? a;
|
|
7
|
-
const bItem = b[by as keyof T] ?? b;
|
|
8
|
-
if (typeof aItem === "string" && typeof bItem === "string") {
|
|
9
|
-
return aItem.localeCompare(bItem);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (typeof aItem === "number" && typeof bItem === "number") {
|
|
13
|
-
return aItem - bItem;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
throw new Error("Not supported data type");
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
bSort(items: T[], by?: keyof T): T[] {
|
|
21
|
-
return items.sort((a: T, b: T) => {
|
|
22
|
-
const aItem = a[by as keyof T] ?? a;
|
|
23
|
-
const bItem = b[by as keyof T] ?? b;
|
|
24
|
-
if (typeof aItem === "string" && typeof bItem === "string") {
|
|
25
|
-
return bItem.localeCompare(aItem);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (typeof aItem === "number" && typeof bItem === "number") {
|
|
29
|
-
return bItem - aItem;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
throw new Error("Not supported data type");
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/types/Global.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Nullable<T> = T | null;
|
package/src/types/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Global";
|
package/src/validators/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { type Validator } from "./Validator";
|
package/src/webSocket/Model.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export class WebSocketPostMessage<T> {
|
|
2
|
-
private type: string;
|
|
3
|
-
private data: T;
|
|
4
|
-
|
|
5
|
-
constructor(type: string, data: T) {
|
|
6
|
-
this.type = type;
|
|
7
|
-
this.data = data;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public getPayload() {
|
|
11
|
-
return JSON.stringify({
|
|
12
|
-
type: this.type,
|
|
13
|
-
data: this.data,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { Nullable } from "../types";
|
|
2
|
-
import { CustomEventDispatcher } from "../eventSystem/CustomEventDispatcher";
|
|
3
|
-
import { WebSocketEvents } from "./Constants";
|
|
4
|
-
import { WebSocketEvent } from "../eventSystem";
|
|
5
|
-
import { WebSocketPostMessage } from "./Model";
|
|
6
|
-
|
|
7
|
-
export class WebSocketService {
|
|
8
|
-
private webSocket: Nullable<WebSocket> = null;
|
|
9
|
-
private retry: number = 3;
|
|
10
|
-
private url: string = "";
|
|
11
|
-
private protocols: string[] = [];
|
|
12
|
-
private delayTimeInMillieSeconds: number = 500;
|
|
13
|
-
private baseUrl: string = "";
|
|
14
|
-
private intervalId: Nullable<ReturnType<typeof setInterval>> = null;
|
|
15
|
-
|
|
16
|
-
constructor(
|
|
17
|
-
private readonly customEventDispatcher: CustomEventDispatcher,
|
|
18
|
-
baseUrl: string,
|
|
19
|
-
) {
|
|
20
|
-
this.onOpen = this.onOpen.bind(this);
|
|
21
|
-
this.onMessage = this.onMessage.bind(this);
|
|
22
|
-
this.onError = this.onError.bind(this);
|
|
23
|
-
this.onClose = this.onClose.bind(this);
|
|
24
|
-
this.checkHealth = this.checkHealth.bind(this);
|
|
25
|
-
this.sendPing = this.sendPing.bind(this);
|
|
26
|
-
this.reconnect = this.reconnect.bind(this);
|
|
27
|
-
this.fakeWait = this.fakeWait.bind(this);
|
|
28
|
-
this.isClosing = this.isClosing.bind(this);
|
|
29
|
-
this.isClosed = this.isClosed.bind(this);
|
|
30
|
-
this.connect = this.connect.bind(this);
|
|
31
|
-
this.registerPingPontInterval = this.registerPingPontInterval.bind(this);
|
|
32
|
-
this.closeConnection = this.closeConnection.bind(this);
|
|
33
|
-
this.isConnectionOpen = this.isConnectionOpen.bind(this);
|
|
34
|
-
this.isConnecting = this.isConnecting.bind(this);
|
|
35
|
-
this.send = this.send.bind(this);
|
|
36
|
-
this.setBaseUrl = this.setBaseUrl.bind(this);
|
|
37
|
-
this.setBaseUrl(baseUrl);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public connect(url: string, protocols: string[] = [], retry: number = 3) {
|
|
41
|
-
if (this.webSocket) {
|
|
42
|
-
this.webSocket.removeEventListener("open", this.onOpen);
|
|
43
|
-
this.webSocket.removeEventListener("close", this.onClose);
|
|
44
|
-
this.webSocket.removeEventListener("error", this.onError);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
this.webSocket = new WebSocket(this.baseUrl + url, protocols);
|
|
48
|
-
this.retry = retry;
|
|
49
|
-
this.url = url;
|
|
50
|
-
this.protocols = protocols;
|
|
51
|
-
|
|
52
|
-
this.webSocket.addEventListener("error", this.onError);
|
|
53
|
-
this.webSocket.addEventListener("close", this.onClose);
|
|
54
|
-
this.webSocket.addEventListener("open", this.onOpen);
|
|
55
|
-
this.checkHealth();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private async checkHealth() {
|
|
59
|
-
try {
|
|
60
|
-
await this.fakeWait(this.delayTimeInMillieSeconds);
|
|
61
|
-
if (!this.isClosed() && !this.isClosing() && !this.isConnectionOpen()) {
|
|
62
|
-
this.sendPing();
|
|
63
|
-
}
|
|
64
|
-
} catch (_error) {
|
|
65
|
-
this.reconnect();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private sendPing() {
|
|
70
|
-
this.webSocket!.send("PING");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private reconnect() {
|
|
74
|
-
if (this.retry === 0) {
|
|
75
|
-
this.customEventDispatcher.dispatchOnWindow(WebSocketEvents.TIMEOUT);
|
|
76
|
-
}
|
|
77
|
-
if (this.retry > 0) {
|
|
78
|
-
this.delayTimeInMillieSeconds = this.delayTimeInMillieSeconds * 2;
|
|
79
|
-
this.connect(this.url, this.protocols, --this.retry);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private fakeWait(timeInMilleSeconds: number) {
|
|
84
|
-
return new Promise((resolve) => {
|
|
85
|
-
setTimeout(() => {
|
|
86
|
-
resolve(null);
|
|
87
|
-
}, timeInMilleSeconds);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private onError() {
|
|
92
|
-
this.customEventDispatcher.dispatchOnWindow(WebSocketEvents.ERROR);
|
|
93
|
-
this.closeConnection();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private onOpen() {
|
|
97
|
-
this.webSocket!.addEventListener("message", this.onMessage);
|
|
98
|
-
this.customEventDispatcher.dispatchOnWindow(WebSocketEvents.OPEN);
|
|
99
|
-
this.registerPingPontInterval();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private registerPingPontInterval() {
|
|
103
|
-
this.intervalId = setInterval(() => {
|
|
104
|
-
this.sendPing();
|
|
105
|
-
}, 10_000);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private onMessage(message: MessageEvent) {
|
|
109
|
-
const webSocketEvent = new WebSocketEvent<unknown>(message);
|
|
110
|
-
this.customEventDispatcher.dispatchWebSocketOnWindow(webSocketEvent);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private onClose() {
|
|
114
|
-
this.customEventDispatcher.dispatchOnWindow(WebSocketEvents.CLOSE);
|
|
115
|
-
if (this.intervalId) {
|
|
116
|
-
clearInterval(this.intervalId);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public closeConnection() {
|
|
121
|
-
if (!this.webSocket) {
|
|
122
|
-
console.warn("No connection to close");
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
this.webSocket.close();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public isConnectionOpen() {
|
|
130
|
-
return this.webSocket?.readyState === 1;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public isConnecting() {
|
|
134
|
-
return this.webSocket?.readyState === 0;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public isClosing() {
|
|
138
|
-
return this.webSocket?.readyState === 2;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public isClosed() {
|
|
142
|
-
return this.webSocket?.readyState === 3;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public send(data: WebSocketPostMessage<unknown>) {
|
|
146
|
-
if (!this.webSocket) throw new Error("NO webSocket to send data");
|
|
147
|
-
this.webSocket.send(data.getPayload());
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private setBaseUrl(baseUrl: string) {
|
|
151
|
-
this.baseUrl = baseUrl;
|
|
152
|
-
}
|
|
153
|
-
}
|
package/src/webSocket/index.ts
DELETED
package/vite.config.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { dirname, resolve } from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { defineConfig } from "vite";
|
|
4
|
-
import dts from "vite-plugin-dts";
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
|
|
7
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
|
|
9
|
-
export default defineConfig({
|
|
10
|
-
plugins: [dts({ insertTypesEntry: true })],
|
|
11
|
-
resolve: {
|
|
12
|
-
alias: {
|
|
13
|
-
"@": path.resolve(__dirname, "packages/core/src"),
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
build: {
|
|
17
|
-
lib: {
|
|
18
|
-
entry: resolve(__dirname, "index.ts"),
|
|
19
|
-
name: "IronCore",
|
|
20
|
-
// the proper extensions will be added
|
|
21
|
-
fileName: "IronCore",
|
|
22
|
-
},
|
|
23
|
-
rollupOptions: {
|
|
24
|
-
// make sure to externalize deps that shouldn't be bundled
|
|
25
|
-
// into your library
|
|
26
|
-
external: [
|
|
27
|
-
"vue",
|
|
28
|
-
"json2typescript",
|
|
29
|
-
"axios",
|
|
30
|
-
"dayjs",
|
|
31
|
-
"jalaliday",
|
|
32
|
-
"pinia",
|
|
33
|
-
],
|
|
34
|
-
output: {
|
|
35
|
-
// Provide global variables to use in the UMD build
|
|
36
|
-
// for externalized deps
|
|
37
|
-
globals: {
|
|
38
|
-
vue: "Vue",
|
|
39
|
-
json2typescript: "json2typescript",
|
|
40
|
-
axios: "axios",
|
|
41
|
-
dayjs: "dayjs",
|
|
42
|
-
jalaliday: "jalaliday",
|
|
43
|
-
pinia: "pinia",
|
|
44
|
-
"jalali-plugin-dayjs": "jalali-plugin-dayjs",
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
terserOptions: {
|
|
49
|
-
compress: {
|
|
50
|
-
dead_code: false,
|
|
51
|
-
conditionals: false,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
});
|