@soonspacejs/plugin-cps-soonmanager 2.9.7 → 2.9.9

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,17 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import PoiRendererPlugin from '@soonspacejs/plugin-poi-renderer';
3
+ import CpsManagerPlugin from '../';
4
+ import { ITreeData } from '../types';
5
+ import { SourceApiListInterface } from '../data-source/request-types';
6
+ import { PoiList } from './types';
7
+ declare class BatchUpdatePoi {
8
+ #private;
9
+ treeList: ITreeData[] | null;
10
+ poiList: PoiList[] | null;
11
+ ssp: SoonSpace;
12
+ plugin: PoiRendererPlugin;
13
+ cpsPlugin: CpsManagerPlugin;
14
+ constructor(treeList: ITreeData[] | null, poiList: PoiList[] | null, ssp: SoonSpace, plugin: PoiRendererPlugin, cpsPlugin: CpsManagerPlugin);
15
+ batchPoi(api: SourceApiListInterface, data: any): void;
16
+ }
17
+ export default BatchUpdatePoi;
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import { IPublishPacket } from 'mqtt';
3
+ import { IPoiData, ITreeData, PoiContent } from '../types';
4
+ export type TFlatTreeNode = Record<ITreeData['id'], ITreeData>;
5
+ export type PoiList = IPoiData & {
6
+ contentData?: PoiContent;
7
+ };
8
+ export type ResponseMqttType = {
9
+ topic: string;
10
+ payload: Buffer;
11
+ packet: IPublishPacket;
12
+ };
13
+ export type ResponseSocketType = {
14
+ event: string;
15
+ message: any;
16
+ };
@@ -0,0 +1,18 @@
1
+ import { ITreeData } from '../types';
2
+ import { PoiList, TFlatTreeNode } from './types';
3
+ /**
4
+ * 重新生成树节点
5
+ * @param modelTree
6
+ */
7
+ export declare const regenerateNodes: (modelTree: ITreeData[]) => {
8
+ treeNodes: ITreeData[];
9
+ flatNodes: TFlatTreeNode;
10
+ };
11
+ export declare const getPoiByNodeId: (id: string, poiList: PoiList[]) => PoiList[];
12
+ /**
13
+ * 捕获 JSON.parse 错误
14
+ * @param str
15
+ * @returns
16
+ */
17
+ export declare const safeParseJSON: <T = any>(str: string) => T | null;
18
+ export declare const subjectTopicMqtt: (subject: string, topic: string) => boolean;
@@ -14,6 +14,10 @@ export declare const TREE_DATA_FILE_PATH = "/db/tree_models.json";
14
14
  * poi
15
15
  */
16
16
  export declare const POI_DATA_FILE_PATH = "/db/pois.json";
17
+ /**
18
+ * poi
19
+ */
20
+ export declare const DATA_SOURCE_FILE_PATH = "/db/data_source.json";
17
21
  /**
18
22
  * 拓扑路径
19
23
  */
@@ -0,0 +1,15 @@
1
+ import { ClientType, SourceOnEventType } from './types';
2
+ import { SourceApiListInterface, SourceEnvListInterface } from './request-types';
3
+ declare class DataSource {
4
+ #private;
5
+ sourceEnv: SourceEnvListInterface[];
6
+ sourceApi: SourceApiListInterface[];
7
+ constructor(sourceEnv: SourceEnvListInterface[], sourceApi: SourceApiListInterface[]);
8
+ on<T extends keyof SourceOnEventType>(eventName: T, callback: SourceOnEventType[T]): void;
9
+ getClientById(id: string): ClientType;
10
+ requestAll(): void;
11
+ requestById(ids: string[]): void;
12
+ closeAll(): void;
13
+ closeById(ids: string[]): void;
14
+ }
15
+ export default DataSource;
@@ -0,0 +1,193 @@
1
+ /**
2
+ * @description: 请求参数类型
3
+ */
4
+ export declare enum RequestParamsTypeEnum {
5
+ PARAMS = "params",
6
+ BODY = "body",
7
+ HEADERS = "headers"
8
+ }
9
+ /**
10
+ * @description: 协议
11
+ */
12
+ export declare enum ProtocolEnum {
13
+ HTTP = "HTTP",
14
+ MQTT = "MQTT",
15
+ WEBSOCKET = "WebSocket"
16
+ }
17
+ /**
18
+ * @description: 协议值
19
+ */
20
+ export declare enum ProtocolValueEnum {
21
+ HTTPS = "https://",
22
+ HTTP = "http://",
23
+ MQTTS = "wss://",
24
+ MQTT = "ws://",
25
+ WSS = "wss://",
26
+ WS = "ws://"
27
+ }
28
+ /**
29
+ * @description: 请求参数主体
30
+ */
31
+ export type RequestParamsObjType = {
32
+ [T: string]: string;
33
+ };
34
+ /**
35
+ * @description: 请求头部类型
36
+ */
37
+ export declare enum RequestBodyEnum {
38
+ NONE = "none",
39
+ FORM_DATA = "form-data",
40
+ X_WWW_FORM_URLENCODED = "x-www-form-urlencoded",
41
+ JSON = "json",
42
+ XML = "xml"
43
+ }
44
+ /**
45
+ * @description: 请求方法
46
+ */
47
+ export declare enum RequestHttpEnum {
48
+ GET = "GET",
49
+ POST = "POST",
50
+ PATCH = "PATCH",
51
+ PUT = "PUT",
52
+ OPTIONS = "OPTIONS",
53
+ DELETE = "DELETE"
54
+ }
55
+ /**
56
+ * @description: 请求间隔
57
+ */
58
+ export declare enum RequestHttpIntervalEnum {
59
+ SECOND = "second",
60
+ MINUTE = "minute",
61
+ HOUR = "hour",
62
+ DAY = "day"
63
+ }
64
+ /**
65
+ * @description: 导出包json文件类型
66
+ */
67
+ export type DataSourceType = {
68
+ dataSources: SourceEnvListInterface[];
69
+ dataSourceApis: SourceApiListInterface[];
70
+ };
71
+ /**
72
+ * @description: 数据源基础字段
73
+ */
74
+ export interface SourceBaseConfigInterface {
75
+ id: string;
76
+ url: string;
77
+ name: string;
78
+ [RequestParamsTypeEnum.HEADERS]: RequestParamsObjType;
79
+ protocol: ProtocolEnum;
80
+ protocolValue: ProtocolValueEnum;
81
+ modules: 'SOON_MANAGER';
82
+ }
83
+ /**
84
+ * @description: 环境
85
+ */
86
+ export interface SourceEnvListInterface extends SourceBaseConfigInterface {
87
+ apiNumber: number;
88
+ port?: number;
89
+ }
90
+ /**
91
+ * @description: 接口
92
+ */
93
+ export interface SourceApiListInterface extends SourceBaseConfigInterface {
94
+ sid: string;
95
+ componentsId?: string[];
96
+ configureJson: RequestConfigType;
97
+ method?: RequestHttpEnum;
98
+ nodeArray?: SourceApiRelation[];
99
+ fullUrl?: string;
100
+ }
101
+ export type RequestConfigType = HttpConfigInterface | WssConfigInterface | MqttConfigInterface;
102
+ /**
103
+ * @description: Http连接配置
104
+ */
105
+ export interface HttpConfigInterface {
106
+ [RequestParamsTypeEnum.PARAMS]: RequestParamsObjType;
107
+ [RequestParamsTypeEnum.BODY]: {
108
+ [RequestBodyEnum.FORM_DATA]: RequestParamsObjType;
109
+ [RequestBodyEnum.X_WWW_FORM_URLENCODED]: RequestParamsObjType;
110
+ [RequestBodyEnum.JSON]: string;
111
+ [RequestBodyEnum.XML]: string;
112
+ };
113
+ filter: string;
114
+ interval: number;
115
+ unit: RequestHttpIntervalEnum;
116
+ bodyType: RequestBodyEnum;
117
+ method: RequestHttpEnum;
118
+ }
119
+ /**
120
+ * @description: 长连接事件处理
121
+ */
122
+ export interface ConnectionEventInterface {
123
+ successCallback?: string;
124
+ errorCallback?: string;
125
+ }
126
+ /**
127
+ * @description: websocket连接配置
128
+ */
129
+ export interface WssConfigInterface extends ConnectionEventInterface {
130
+ nameSpace?: string;
131
+ subProtocols?: string;
132
+ eventList: WssEventList[];
133
+ query: RequestParamsObjType;
134
+ }
135
+ /**
136
+ * @description: websocket-事件
137
+ */
138
+ export interface WssEventList {
139
+ event: string;
140
+ remark?: string;
141
+ filter?: string;
142
+ }
143
+ /**
144
+ * @description: mqtt连接配置
145
+ */
146
+ export interface MqttConfigInterface extends ConnectionEventInterface {
147
+ baseConfig: MqttBaseConfig;
148
+ willMessage: MqttLastWillMessage;
149
+ subscription: MqttSubscription[];
150
+ }
151
+ export interface MqttBaseConfig {
152
+ version: 3 | 4 | 5;
153
+ clientId?: string;
154
+ username?: string;
155
+ password?: string;
156
+ keepAlive?: number;
157
+ }
158
+ export type QoS = 0 | 1 | 2;
159
+ export interface MqttLastWillMessage {
160
+ topic: string;
161
+ qos: QoS;
162
+ retain: boolean;
163
+ message: string;
164
+ }
165
+ export interface MqttSubscription {
166
+ topic: string;
167
+ qos: QoS;
168
+ remark?: string;
169
+ filter?: string;
170
+ }
171
+ export type OptionType = {
172
+ label: string;
173
+ value: string;
174
+ };
175
+ /**
176
+ * @description: 节点和接口的关联关系
177
+ */
178
+ export type SourceApiRelation = {
179
+ id: string;
180
+ apiId: string;
181
+ eventList?: string[];
182
+ nodeId: string;
183
+ projectId: string;
184
+ matchParams?: string;
185
+ };
186
+ export declare const ProtocolOption: OptionType[];
187
+ export declare enum ContentTypeEnum {
188
+ JSON = "application/json;charset=UTF-8",
189
+ TEXT = "text/plain;charset=UTF-8",
190
+ XML = "application/xml;charset=UTF-8",
191
+ FORM_URLENCODED = "application/x-www-form-urlencoded;charset=UTF-8",
192
+ FORM_DATA = "multipart/form-data"
193
+ }
@@ -0,0 +1,37 @@
1
+ import { MqttClient } from 'mqtt';
2
+ import { Socket } from 'socket.io-client';
3
+ import { HttpRequest } from './utils/http-request';
4
+ import { SourceApiListInterface } from './request-types';
5
+ export type ClientType = HttpRequest | MqttClient | Socket | undefined;
6
+ export type SourceClientListType = {
7
+ [T: string]: ClientType;
8
+ };
9
+ /**
10
+ * @description: 连接状态
11
+ */
12
+ export declare enum RequestStatusEnum {
13
+ SUCCESS = "success",
14
+ ERROR = "error",
15
+ CONNECT = "connect",
16
+ CLOSE = "close"
17
+ }
18
+ export type SourceOnEventType = {
19
+ onStatus: SourceStatusCallbackType;
20
+ onMessage: SourceMessageCallbackType;
21
+ };
22
+ export type SourceOnEventNameType = 'onMessage' | 'onStatus';
23
+ export type SourceStatusCallbackType = (info: SourceStatusType) => void;
24
+ export type SourceMessageCallbackType = (info: SourceMessageType) => void;
25
+ export type SourceCallBackBaseType = {
26
+ api: SourceApiListInterface;
27
+ client: ClientType;
28
+ };
29
+ export type SourceStatusType = SourceCallBackBaseType & InfoStatusType;
30
+ export type SourceMessageType = SourceCallBackBaseType & InfoMessageType;
31
+ export type InfoStatusType = {
32
+ status: RequestStatusEnum;
33
+ message?: Error;
34
+ };
35
+ export type InfoMessageType = {
36
+ data: any;
37
+ };
@@ -0,0 +1,72 @@
1
+ export interface HttpRequesttOptionInterface {
2
+ method?: string;
3
+ protocol?: string;
4
+ headers?: RequestParamsObjType;
5
+ params?: RequestParamsObjType;
6
+ body?: string | FormData | RequestParamsObjType | null;
7
+ interval?: number;
8
+ timeout?: number;
9
+ responseType?: XMLHttpRequestResponseType;
10
+ filter?: ((response: any) => any) | string;
11
+ }
12
+ /**
13
+ * @description: 请求参数主体
14
+ */
15
+ type RequestParamsObjType = {
16
+ [T: string]: string;
17
+ };
18
+ export type RequestEventNameType = 'onSuccess' | 'onError' | 'onStatus';
19
+ export declare class HttpRequest {
20
+ url: string;
21
+ method: string;
22
+ protocol: string;
23
+ params?: RequestParamsObjType;
24
+ headers?: RequestParamsObjType;
25
+ body: any | string | FormData | RequestParamsObjType | null;
26
+ filter?: any;
27
+ interval: number;
28
+ timeout: number;
29
+ responseType: XMLHttpRequestResponseType;
30
+ responseData: any;
31
+ filteredData: any | null;
32
+ option?: HttpRequesttOptionInterface;
33
+ XHR: XMLHttpRequest | undefined;
34
+ private isInterval;
35
+ private successCallback;
36
+ private errorCallback;
37
+ private statusCallback;
38
+ constructor(url: string, option?: HttpRequesttOptionInterface);
39
+ get getUrl(): string;
40
+ get getOption(): {
41
+ url: string;
42
+ method?: string | undefined;
43
+ protocol?: string | undefined;
44
+ headers?: RequestParamsObjType | undefined;
45
+ params?: RequestParamsObjType | undefined;
46
+ body?: string | RequestParamsObjType | FormData | null | undefined;
47
+ interval?: number | undefined;
48
+ timeout?: number | undefined;
49
+ responseType?: XMLHttpRequestResponseType | undefined;
50
+ filter?: string | ((response: any) => any) | undefined;
51
+ };
52
+ get getStatus(): number | undefined;
53
+ get getRequesting(): boolean;
54
+ get getResponseData(): any;
55
+ get getFilterData(): any;
56
+ send(): void;
57
+ abort(): void;
58
+ onceSend(): void;
59
+ listen(successCallback: (response: any, filteredData: any) => void, errorCallback?: (error: Error) => void): void;
60
+ on(eventName: RequestEventNameType, callback: any): void;
61
+ private onStatusCallback;
62
+ private onErrorCallback;
63
+ private onSuccessCallback;
64
+ private request;
65
+ private circulateRequest;
66
+ private onTimeout;
67
+ private onLoad;
68
+ private onError;
69
+ private paramsUrl;
70
+ private toObject;
71
+ }
72
+ export {};
@@ -0,0 +1,4 @@
1
+ import { HttpRequest } from './http-request';
2
+ import { SourceApiListInterface, SourceEnvListInterface } from '../request-types';
3
+ import { SourceMessageCallbackType, SourceStatusCallbackType } from '../types';
4
+ export declare function requestHttp(api: SourceApiListInterface, env: SourceEnvListInterface, onStatus: SourceStatusCallbackType, onMessage: SourceMessageCallbackType): HttpRequest;
@@ -0,0 +1,4 @@
1
+ export * from './http';
2
+ export * from './mqtt';
3
+ export * from './socket';
4
+ export * from './utils';
@@ -0,0 +1,4 @@
1
+ import mqtt from 'mqtt';
2
+ import { SourceApiListInterface, SourceEnvListInterface } from '../request-types';
3
+ import { SourceMessageCallbackType, SourceStatusCallbackType } from '../types';
4
+ export declare function requestMqtt(api: SourceApiListInterface, env: SourceEnvListInterface, onStatus: SourceStatusCallbackType, onMessage: SourceMessageCallbackType): mqtt.MqttClient;
@@ -0,0 +1,4 @@
1
+ import { Socket } from 'socket.io-client';
2
+ import { SourceApiListInterface, SourceEnvListInterface } from '../request-types';
3
+ import { SourceMessageCallbackType, SourceStatusCallbackType } from '../types';
4
+ export declare function requestSocket(api: SourceApiListInterface, env: SourceEnvListInterface, onStatus: SourceStatusCallbackType, onMessage: SourceMessageCallbackType): Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap>;
@@ -0,0 +1,18 @@
1
+ import { RequestHttpIntervalEnum, RequestParamsObjType, SourceEnvListInterface } from '../request-types';
2
+ export declare function has<T>(object: T, key: string): boolean;
3
+ export declare function isNumber(value: any): boolean;
4
+ export declare function isObject(value: any): boolean;
5
+ export declare function getEnvUrl(env: SourceEnvListInterface): string;
6
+ export declare function intervalUnitHandle(num: number, unit: RequestHttpIntervalEnum): number;
7
+ export declare function encodeFormData(data: RequestParamsObjType): string;
8
+ export declare function toString(str: any): any;
9
+ /**
10
+ * * 函数过滤器
11
+ * @param data 数据值
12
+ * @param funcStr 函数字符串
13
+ * @param toString 转为字符串
14
+ * @param errorCallBack 错误回调函数
15
+ * @param successCallBack 成功回调函数
16
+ * @returns
17
+ */
18
+ export declare function newFunctionHandle(data: any, funcStr: string, extractData?: boolean, isToString?: boolean, errorCallBack?: (s: any) => void, successCallBack?: (s: any) => void): any;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import SoonSpace, { AnimationOptions, TopologyNodeInfo } from 'soonspacejs';
2
2
  import type { BaseObject3D, TopologyInfo } from 'soonspacejs/types/Library';
3
+ import { PoiNodeData } from '@soonspacejs/plugin-poi-renderer';
3
4
  import SoonFlow from '@soonflow/core';
4
5
  import { Tween } from '@tweenjs/tween.js';
5
6
  import { IMetadata, ITreeData, IPoiData, ITopologyPath, ILoadSceneOptions, TPropertiesMap, TAnimationsMap, IPlayAnimationByIdOptions, TModelVisionsMap, IPresetEffectsOptions, ConstructorOptions } from './types';
@@ -20,6 +21,10 @@ declare class CpsSoonmanagerPlugin {
20
21
  * poi 数据
21
22
  */
22
23
  poiData: IPoiData[] | null;
24
+ /**
25
+ * 数据源
26
+ */
27
+ dataSourceData: any | null;
23
28
  /**
24
29
  * 拓扑路径
25
30
  */
@@ -65,6 +70,11 @@ declare class CpsSoonmanagerPlugin {
65
70
  * @returns
66
71
  */
67
72
  fetchPoiData(): Promise<IPoiData[]>;
73
+ /**
74
+ * 获取数据源数据
75
+ * @returns
76
+ */
77
+ fetchDataSourceData(): Promise<any>;
68
78
  /**
69
79
  * 获取拓扑路径
70
80
  * @returns
@@ -85,6 +95,18 @@ declare class CpsSoonmanagerPlugin {
85
95
  * @returns
86
96
  */
87
97
  fetchModelVisionsData(): Promise<TModelVisionsMap>;
98
+ /**
99
+ * 格式化 Poi 数据完成 Poi Renderer 插件使用
100
+ */
101
+ formatPoiData: (poiData: IPoiData) => PoiNodeData;
102
+ /**
103
+ * 初始化 Poi
104
+ */
105
+ loadPoi(refreshByDataSource: boolean): Promise<void>;
106
+ /**
107
+ * 通过数据源刷新 poi
108
+ */
109
+ refreshPoiByDataSource(): Promise<void>;
88
110
  /**
89
111
  * 根据 id 获取树节点
90
112
  */