forked from alibaba/lowcode-datasource
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-source.ts
More file actions
79 lines (66 loc) · 1.98 KB
/
data-source.ts
File metadata and controls
79 lines (66 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { RequestHandlersMap } from './data-source-handlers';
import {
IDataSourceRuntimeContext,
RuntimeDataSource,
} from './data-source-runtime';
export type DataSourceOptions<TParams = Record<string, unknown>> = {
[key: string]: unknown;
uri?: string;
params?: TParams;
method?: string;
isCors?: boolean;
timeout?: number;
headers?: Record<string, string>;
isSync?: boolean;
};
/** 数据源的状态 */
export enum RuntimeDataSourceStatus {
/** 初始状态,尚未加载 */
Initial = 'init',
/** 正在加载 */
Loading = 'loading',
/** 已加载(无错误) */
Loaded = 'loaded',
/** 加载出错了 */
Error = 'error',
}
/**
* 运行时的数据源(对外暴露的接口)
* @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#Jwgj5
*/
export interface IRuntimeDataSource<TParams = unknown, TResultData = unknown> {
/** 当前状态(initial/loading/loaded/error) */
readonly status: RuntimeDataSourceStatus;
/** 加载成功时的数据 */
readonly data?: TResultData;
/** 加载出错的时候的错误信息 */
readonly error?: Error;
/** 当前是否正在加载中 */
readonly isLoading?: boolean;
/**
* 加载数据 (无论是否曾经加载过)
* 注意:若提供 params,则会和默认配置的参数做浅合并;否则会使用默认配置的参数。
*/
load(params?: TParams): Promise<TResultData | void>;
}
/**
* DataSourceEngineFactory
* 用来定义 engine 的工厂函数类型
*/
export interface IRuntimeDataSourceEngineFactory {
create(
dataSource: RuntimeDataSource,
context: IDataSourceRuntimeContext,
extraConfig?: {
requestHandlersMap: RequestHandlersMap;
[key: string]: any;
},
): IDataSourceEngine;
}
// create 返回的 DataSourceEngine 定义
export interface IDataSourceEngine {
/** 数据源, key 是数据源的 ID */
dataSourceMap: Record<string, IRuntimeDataSource>;
/** 重新加载所有的数据源 */
reloadDataSource(): Promise<void>;
}