@kevisual/api 0.0.11 → 0.0.12
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 +1 -1
- package/query/query-proxy/index.ts +18 -11
package/package.json
CHANGED
|
@@ -51,15 +51,15 @@ export type RouterViewData = {
|
|
|
51
51
|
export class QueryProxy {
|
|
52
52
|
router: QueryRouterServer;
|
|
53
53
|
token?: string;
|
|
54
|
-
|
|
54
|
+
routerViewItems: RouterViewItem[];
|
|
55
55
|
views: RouterViewQuery[];
|
|
56
56
|
emitter: EventEmitter;
|
|
57
|
-
constructor(opts?: {
|
|
57
|
+
constructor(opts?: { router?: QueryRouterServer, token?: string, routerViewData?: RouterViewData }) {
|
|
58
58
|
this.router = opts?.router || new QueryRouterServer();
|
|
59
59
|
this.token = opts?.token || this.getDefulatToken();
|
|
60
|
-
this.
|
|
61
|
-
this.views = opts?.
|
|
62
|
-
this.
|
|
60
|
+
this.routerViewItems = opts?.routerViewData?.data?.items || [];
|
|
61
|
+
this.views = opts?.routerViewData?.views || [];
|
|
62
|
+
this.initRouterViewQuery();
|
|
63
63
|
this.emitter = new EventEmitter();
|
|
64
64
|
}
|
|
65
65
|
getDefulatToken() {
|
|
@@ -71,14 +71,18 @@ export class QueryProxy {
|
|
|
71
71
|
return undefined;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
async
|
|
75
|
-
this.
|
|
74
|
+
async initRouterViewQuery() {
|
|
75
|
+
this.routerViewItems = this.routerViewItems?.map(item => {
|
|
76
76
|
if (item.type === 'api' && item.api?.url) {
|
|
77
77
|
const url = item.api.url;
|
|
78
|
+
if (item?.api?.query) return item;
|
|
78
79
|
item['api'] = { url: url, query: new Query({ url: url }) };
|
|
79
80
|
}
|
|
80
81
|
if (item.type === 'worker' && item.worker?.url) {
|
|
81
82
|
let viewItem = item as RouterViewWorker;
|
|
83
|
+
if (item.worker.worker) {
|
|
84
|
+
return item;
|
|
85
|
+
}
|
|
82
86
|
let worker: Worker | SharedWorker | ServiceWorker | undefined = undefined;
|
|
83
87
|
if (item.worker.type === 'SharedWorker') {
|
|
84
88
|
worker = new SharedWorker(item.worker.url);
|
|
@@ -99,6 +103,9 @@ export class QueryProxy {
|
|
|
99
103
|
viewItem['worker']['worker'] = worker;
|
|
100
104
|
}
|
|
101
105
|
if (item.type === 'context' && item.context?.key) {
|
|
106
|
+
if (item.context?.router) {
|
|
107
|
+
return item;
|
|
108
|
+
}
|
|
102
109
|
// @ts-ignore
|
|
103
110
|
const context = globalThis['context'] || {}
|
|
104
111
|
const router = context[item.context.key] as QueryRouterServer;
|
|
@@ -114,13 +121,13 @@ export class QueryProxy {
|
|
|
114
121
|
* 初始化路由
|
|
115
122
|
* @returns
|
|
116
123
|
*/
|
|
117
|
-
async init(
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
124
|
+
async init() {
|
|
125
|
+
const routerViewItems = this.routerViewItems || [];
|
|
126
|
+
if (routerViewItems.length === 0) {
|
|
120
127
|
await this.initApi();
|
|
121
128
|
return;
|
|
122
129
|
}
|
|
123
|
-
for (const item of
|
|
130
|
+
for (const item of routerViewItems) {
|
|
124
131
|
switch (item.type) {
|
|
125
132
|
case 'api':
|
|
126
133
|
this.initApi(item);
|