@kevisual/api 0.0.46 → 0.0.47

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,215 @@
1
+ import { QueryClient, Result } from '@kevisual/query';
2
+ import { QueryRouterServer, Route } from '@kevisual/router/browser';
3
+ import { EventEmitter } from 'eventemitter3';
4
+ import { QueryRouterServer as QueryRouterServer$1, App } from '@kevisual/router';
5
+
6
+ declare const RouteTypeList: readonly ["api", "context", "worker", "page"];
7
+ type RouterViewItemInfo = RouterViewApi | RouterViewContext | RouterViewWorker | RouteViewPage;
8
+ type RouterViewItem<T = {}> = RouterViewItemInfo & T;
9
+ type RouteViewBase = {
10
+ /**
11
+ * _id 用于纯本地存储标识
12
+ */
13
+ _id?: string;
14
+ id?: string;
15
+ title?: string;
16
+ description?: string;
17
+ enabled?: boolean;
18
+ /**
19
+ * 响应数据
20
+ */
21
+ response?: any;
22
+ /**
23
+ * 默认动作配置
24
+ */
25
+ action?: {
26
+ path?: string;
27
+ key?: string;
28
+ id?: string;
29
+ payload?: any;
30
+ [key: string]: any;
31
+ };
32
+ };
33
+ type RouterViewApi = {
34
+ type: 'api';
35
+ api: {
36
+ url: string;
37
+ query?: QueryClient;
38
+ };
39
+ } & RouteViewBase;
40
+ type RouterViewContext = {
41
+ type: 'context';
42
+ context: {
43
+ key: string;
44
+ router?: QueryRouterServer;
45
+ };
46
+ } & RouteViewBase;
47
+ type RouterViewWorker = {
48
+ type: 'worker';
49
+ worker: {
50
+ type: 'Worker' | 'SharedWorker' | 'serviceWorker';
51
+ url: string;
52
+ worker?: Worker | SharedWorker | ServiceWorker;
53
+ /**
54
+ * worker选项
55
+ * default: { type: 'module' }
56
+ */
57
+ workerOptions?: {
58
+ type: 'module' | 'classic';
59
+ };
60
+ };
61
+ } & RouteViewBase;
62
+ /**
63
+ * 去掉不需要保存都服务器的数据
64
+ * @param item
65
+ * @returns
66
+ */
67
+ declare const pickRouterViewData: (item: RouterViewItem) => {
68
+ type: "api";
69
+ api: {
70
+ url: string;
71
+ query?: QueryClient;
72
+ };
73
+ id?: string;
74
+ title?: string;
75
+ description?: string;
76
+ enabled?: boolean;
77
+ } | {
78
+ type: "context";
79
+ context: {
80
+ key: string;
81
+ router?: QueryRouterServer;
82
+ };
83
+ id?: string;
84
+ title?: string;
85
+ description?: string;
86
+ enabled?: boolean;
87
+ } | {
88
+ type: "worker";
89
+ worker: {
90
+ type: "Worker" | "SharedWorker" | "serviceWorker";
91
+ url: string;
92
+ worker?: Worker | SharedWorker | ServiceWorker;
93
+ /**
94
+ * worker选项
95
+ * default: { type: 'module' }
96
+ */
97
+ workerOptions?: {
98
+ type: "module" | "classic";
99
+ };
100
+ };
101
+ id?: string;
102
+ title?: string;
103
+ description?: string;
104
+ enabled?: boolean;
105
+ } | {
106
+ type: "page";
107
+ page: {
108
+ url: string;
109
+ };
110
+ id?: string;
111
+ title?: string;
112
+ description?: string;
113
+ enabled?: boolean;
114
+ };
115
+ /**
116
+ * 注入 js 的url地址,使用importScripts加载
117
+ */
118
+ type RouteViewPage = {
119
+ type: 'page';
120
+ page: {
121
+ url: string;
122
+ };
123
+ } & RouteViewBase;
124
+ type RouterViewQuery = {
125
+ id: string;
126
+ query: string;
127
+ title: string;
128
+ };
129
+ type RouterViewData = {
130
+ data: {
131
+ items: RouterViewItem[];
132
+ };
133
+ views: RouterViewQuery[];
134
+ viewId?: string;
135
+ [key: string]: any;
136
+ };
137
+ declare class QueryProxy {
138
+ router: QueryRouterServer;
139
+ token?: string;
140
+ routerViewItems: RouterViewItem[];
141
+ views: RouterViewQuery[];
142
+ emitter: EventEmitter;
143
+ constructor(opts?: {
144
+ router?: QueryRouterServer;
145
+ token?: string;
146
+ routerViewData?: RouterViewData;
147
+ });
148
+ getDefulatToken(): string;
149
+ initRouterViewQuery(): void;
150
+ initRouterView(item: RouterViewItem): RouterViewItem<{}>;
151
+ /**
152
+ * 初始化路由
153
+ * main
154
+ * @returns
155
+ */
156
+ init(): Promise<void>;
157
+ /**
158
+ * 监听初始化完成
159
+ * @returns
160
+ */
161
+ listenInitComplete(): Promise<boolean>;
162
+ initApi(item?: RouterViewApi): Promise<void>;
163
+ initContext(item?: RouterViewContext): Promise<void>;
164
+ generateId(): string;
165
+ callWorker(msg: any, viewItem: RouterViewWorker['worker']): Promise<Result>;
166
+ initWorker(item?: RouterViewWorker, initRoutes?: boolean): Promise<void>;
167
+ initPage(item?: RouteViewPage): Promise<void>;
168
+ getQueryByViewId(viewId: string): string | undefined;
169
+ /**
170
+ * 列出路由
171
+ * @param filter
172
+ * @param query WHERE metadata.tags CONTAINS 'premium'
173
+ * @returns
174
+ */
175
+ listRoutes(filterFn?: (item: Route) => boolean, opts?: {
176
+ viewId?: string;
177
+ query?: string;
178
+ }): Promise<any>;
179
+ getViewQuery(viewId: string): Promise<string>;
180
+ /**
181
+ * 运行路由
182
+ * @param msg
183
+ * @returns
184
+ */
185
+ run(msg: {
186
+ id?: string;
187
+ path?: string;
188
+ key?: string;
189
+ }): Promise<any>;
190
+ runByRouteView(routeView: RouterViewItem): Promise<RouterViewItem<{}>>;
191
+ }
192
+ type RouterItem = {
193
+ id?: string;
194
+ path?: string;
195
+ key?: string;
196
+ description?: string;
197
+ middleware?: string[];
198
+ metadata?: Record<string, any>;
199
+ };
200
+
201
+ declare const initApi: (opts: {
202
+ item?: RouterViewApi;
203
+ router: QueryRouterServer$1 | App;
204
+ token?: string;
205
+ /**
206
+ * WHERE path = 'auth' OR path = 'router' OR path = 'call'
207
+ */
208
+ exclude?: string;
209
+ }) => Promise<{
210
+ code: any;
211
+ message: string;
212
+ }>;
213
+
214
+ export { QueryProxy, RouteTypeList, initApi, pickRouterViewData };
215
+ export type { RouteViewPage, RouterItem, RouterViewApi, RouterViewContext, RouterViewData, RouterViewItem, RouterViewItemInfo, RouterViewQuery, RouterViewWorker };