decompose structure

This commit is contained in:
Первов Артем
2026-06-20 00:51:18 +03:00
parent dbda8ee613
commit 31add10e56
77 changed files with 4112 additions and 3974 deletions

View File

@@ -0,0 +1,16 @@
import { getJson } from '../../shared/api/http';
import { cloudApiUrl } from '../../shared/config/env';
import type { CurrentResponse } from './types';
/** Загружает текущие значения показателей для выбранной буровой. */
export function getCurrent(edge: string, tags?: string[]): Promise<CurrentResponse> {
return getJson<CurrentResponse>(cloudApiUrl, '/current', { edge, tags });
}
/** Формирует URL SSE-потока текущих значений. */
export function getCurrentEventsUrl(edge: string, tags?: string[]): string {
const url = new URL('/current/events', cloudApiUrl);
url.searchParams.set('edge', edge);
tags?.forEach((tag) => url.searchParams.append('tags', tag));
return url.toString();
}

View File

@@ -0,0 +1,22 @@
export type CurrentItem = {
edge: string;
tag: string;
value: number;
createdAt: string;
updatedAt: string;
time: string;
name: string | null;
tagGroup: string | null;
min: number | null;
max: number | null;
comment: string | null;
unitOfMeasurement: string | null;
precision: number | null;
};
export type CurrentResponse = {
edge: string;
items: CurrentItem[];
};
export type CurrentEvent = CurrentResponse;

View File

@@ -0,0 +1,22 @@
import { getAccessToken } from '../../auth/keycloak';
import { getJson } from '../../shared/api/http';
import { diagramApiUrl } from '../../shared/config/env';
import type { DiagramPageResponse, DiagramPageSummary } from './types';
/** Выполняет запрос к diagram-service и пробрасывает Bearer-токен, если UI работает с SSO. */
async function request<T>(path: string, params?: Record<string, string | undefined>): Promise<T> {
const token = await getAccessToken();
return getJson<T>(diagramApiUrl, path, params, {
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
});
}
/** Возвращает список страниц схем; опубликованность определяется по publishedRevision. */
export function listDiagramPages(ownerEdgeId?: string): Promise<DiagramPageSummary[]> {
return request<DiagramPageSummary[]>('/diagram/pages', { ownerEdgeId });
}
/** Загружает опубликованную версию страницы схемы. */
export function getPublishedDiagramPage(pageKey: string): Promise<DiagramPageResponse> {
return request<DiagramPageResponse>(`/diagram/pages/${encodeURIComponent(pageKey)}/published`);
}

View File

@@ -0,0 +1,88 @@
export type DiagramPoint = {
x: number;
y: number;
};
export type DiagramSize = {
width: number;
height: number;
};
export type DiagramBindingConfig = {
stateTagId?: string;
alarmTagId?: string;
edgeId?: string;
sseEdgeId?: string;
sseUrl?: string;
};
export type DiagramNode =
| {
id: string;
kind: 'tagWidget';
tagId: string;
edgeId: string;
widgetType: string;
position: DiagramPoint;
size?: DiagramSize;
zIndex?: number;
label?: string;
displayType?: 'widget' | 'compact' | 'card';
style?: Record<string, unknown>;
}
| {
id: string;
kind: 'decoration';
decorationType: string;
position: DiagramPoint;
size: DiagramSize;
rotation?: number;
zIndex?: number;
data?: Record<string, unknown>;
style?: Record<string, unknown>;
bindings?: DiagramBindingConfig;
};
export type DiagramEdge = {
id: string;
sourceNodeId: string;
targetNodeId: string;
sourceSide?: 'left' | 'right' | 'top' | 'bottom';
targetSide?: 'left' | 'right' | 'top' | 'bottom';
kind: 'wire' | 'power' | 'signal' | 'alert';
label?: string;
animated?: boolean;
waypoints?: DiagramPoint[];
};
export type DiagramDocument = {
schemaVersion: number;
pageKey: string;
ownerEdgeId: string;
title?: string;
viewport?: { x: number; y: number; zoom: number } | null;
background?: {
url?: string;
opacity?: number;
fit?: 'contain' | 'cover' | 'stretch';
};
nodes: DiagramNode[];
edges: DiagramEdge[];
};
export type DiagramPageSummary = {
pageKey: string;
ownerEdgeId: string;
title?: string | null;
schemaVersion: number;
revision: number;
status: 'draft' | 'published' | 'archived';
publishedRevision?: number;
publishedAt?: string;
createdAt: string;
updatedAt: string;
};
export type DiagramPageResponse = DiagramPageSummary & {
document: DiagramDocument;
};

8
src/entities/edge/api.ts Normal file
View File

@@ -0,0 +1,8 @@
import { getJson } from '../../shared/api/http';
import { cloudApiUrl } from '../../shared/config/env';
import type { EdgeResponse } from './types';
/** Возвращает список буровых, доступных в cloud-v3. */
export function getEdges(): Promise<EdgeResponse> {
return getJson<EdgeResponse>(cloudApiUrl, '/edge');
}

View File

@@ -0,0 +1,11 @@
export type EdgeItem = {
id: string;
name: string;
parentId: string | null;
tagIds: string[];
tagCount: number;
};
export type EdgeResponse = {
items: EdgeItem[];
};

View File

@@ -0,0 +1,8 @@
import { getJson } from '../../shared/api/http';
import { cloudApiUrl } from '../../shared/config/env';
import type { HealthResponse } from './types';
/** Запрашивает состояние cloud-v3 и подключенной базы данных. */
export function getHealth(): Promise<HealthResponse> {
return getJson<HealthResponse>(cloudApiUrl, '/health');
}

View File

@@ -0,0 +1,8 @@
export type HealthResponse = {
status: 'ok';
database: {
now: string;
timescaledb_installed: boolean;
timescaledb_version: string | null;
};
};

View File

@@ -0,0 +1,8 @@
import { getJson } from '../../shared/api/http';
import { cloudApiUrl } from '../../shared/config/env';
import type { HistoryRequest, HistoryResponse } from './types';
/** Запрашивает исторический ряд с avg-линией и min/max-диапазоном для графика. */
export function getHistory(params: HistoryRequest): Promise<HistoryResponse> {
return getJson<HistoryResponse>(cloudApiUrl, '/history', params);
}

View File

@@ -0,0 +1,30 @@
export type HistoryPoint = {
t: number;
min: number;
avg: number;
max: number;
count: number;
};
export type HistorySeries = {
edge: string;
tag: string;
points: HistoryPoint[];
};
export type HistoryResponse = {
edge: string;
tag: string;
granulate: string;
series: HistorySeries[];
from: string;
to: string;
};
export type HistoryRequest = {
edge: string;
tag: string;
from: string;
to: string;
granulate: string;
};

8
src/entities/tag/api.ts Normal file
View File

@@ -0,0 +1,8 @@
import { getJson } from '../../shared/api/http';
import { cloudApiUrl } from '../../shared/config/env';
import type { TagResponse } from './types';
/** Загружает справочник тегов; tag.name используется как отображаемое имя. */
export function getTags(params: { edge?: string; search?: string } = {}): Promise<TagResponse> {
return getJson<TagResponse>(cloudApiUrl, '/tag', params);
}

15
src/entities/tag/types.ts Normal file
View File

@@ -0,0 +1,15 @@
export type TagItem = {
id: string;
name: string;
tagGroup: string | null;
min: number;
max: number;
comment: string;
unitOfMeasurement: string;
edgeIds: string[];
precision: number | null;
};
export type TagResponse = {
items: TagItem[];
};