@kevisual/api 0.0.49 → 0.0.50
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/dist/query-proxy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryClient
|
|
1
|
+
import { QueryClient } from '@kevisual/query';
|
|
2
2
|
import { QueryRouterServer, Route } from '@kevisual/router/browser';
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
import { QueryRouterServer as QueryRouterServer$1, App } from '@kevisual/router';
|
|
@@ -60,7 +60,7 @@ type RouterViewWorker = {
|
|
|
60
60
|
};
|
|
61
61
|
} & RouteViewBase;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* 去掉不需要保存的服务器的数据
|
|
64
64
|
* @param item
|
|
65
65
|
* @returns
|
|
66
66
|
*/
|
|
@@ -113,7 +113,7 @@ declare const pickRouterViewData: (item: RouterViewItem) => {
|
|
|
113
113
|
enabled?: boolean;
|
|
114
114
|
};
|
|
115
115
|
/**
|
|
116
|
-
* 注入 js 的url地址,使用importScripts加载
|
|
116
|
+
* 注入 js 的url地址,使用 importScripts 加载
|
|
117
117
|
*/
|
|
118
118
|
type RouteViewPage = {
|
|
119
119
|
type: 'page';
|
|
@@ -126,6 +126,9 @@ type RouterViewQuery = {
|
|
|
126
126
|
query: string;
|
|
127
127
|
title: string;
|
|
128
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* 后端存储结构
|
|
131
|
+
*/
|
|
129
132
|
type RouterViewData = {
|
|
130
133
|
data: {
|
|
131
134
|
items: RouterViewItem[];
|
|
@@ -145,9 +148,9 @@ declare class QueryProxy {
|
|
|
145
148
|
token?: string;
|
|
146
149
|
routerViewData?: RouterViewData;
|
|
147
150
|
});
|
|
148
|
-
getDefulatToken
|
|
151
|
+
private getDefulatToken;
|
|
149
152
|
initRouterViewQuery(): void;
|
|
150
|
-
initRouterView
|
|
153
|
+
private initRouterView;
|
|
151
154
|
/**
|
|
152
155
|
* 初始化路由
|
|
153
156
|
* main
|
|
@@ -162,10 +165,10 @@ declare class QueryProxy {
|
|
|
162
165
|
initApi(item?: RouterViewApi): Promise<void>;
|
|
163
166
|
initContext(item?: RouterViewContext): Promise<void>;
|
|
164
167
|
generateId(): string;
|
|
165
|
-
callWorker
|
|
166
|
-
initWorker
|
|
167
|
-
initPage
|
|
168
|
-
getQueryByViewId
|
|
168
|
+
private callWorker;
|
|
169
|
+
private initWorker;
|
|
170
|
+
private initPage;
|
|
171
|
+
private getQueryByViewId;
|
|
169
172
|
/**
|
|
170
173
|
* 列出路由
|
|
171
174
|
* @param filter
|
|
@@ -197,6 +200,7 @@ type RouterItem = {
|
|
|
197
200
|
middleware?: string[];
|
|
198
201
|
metadata?: Record<string, any>;
|
|
199
202
|
};
|
|
203
|
+
declare const createViewData: (routerViewData: RouterViewItem | RouterViewItem[], data?: RouterViewData) => RouterViewData;
|
|
200
204
|
|
|
201
205
|
declare const initApi: (opts: {
|
|
202
206
|
item?: RouterViewApi;
|
|
@@ -211,5 +215,5 @@ declare const initApi: (opts: {
|
|
|
211
215
|
message: string;
|
|
212
216
|
}>;
|
|
213
217
|
|
|
214
|
-
export { QueryProxy, RouteTypeList, initApi, pickRouterViewData };
|
|
218
|
+
export { QueryProxy, RouteTypeList, createViewData, initApi, pickRouterViewData };
|
|
215
219
|
export type { RouteViewPage, RouterItem, RouterViewApi, RouterViewContext, RouterViewData, RouterViewItem, RouterViewItemInfo, RouterViewQuery, RouterViewWorker };
|
package/dist/query-proxy.js
CHANGED
|
@@ -8839,6 +8839,7 @@ var initApi = async (opts) => {
|
|
|
8839
8839
|
let metadata = r.metadata || {};
|
|
8840
8840
|
metadata.viewItem = item;
|
|
8841
8841
|
metadata.url = query.url;
|
|
8842
|
+
metadata.source = "query-proxy-api";
|
|
8842
8843
|
router.route({
|
|
8843
8844
|
path: r.path,
|
|
8844
8845
|
key: r.key || "",
|
|
@@ -10307,6 +10308,7 @@ class QueryProxy {
|
|
|
10307
10308
|
console.debug(`注册路由: [${r.path}] ${r?.key}`, "Context");
|
|
10308
10309
|
let metadata = r.metadata || {};
|
|
10309
10310
|
metadata.viewItem = item;
|
|
10311
|
+
metadata.source = "query-proxy-context";
|
|
10310
10312
|
this.router.route({
|
|
10311
10313
|
path: r.path,
|
|
10312
10314
|
key: r.key || "",
|
|
@@ -10399,6 +10401,7 @@ class QueryProxy {
|
|
|
10399
10401
|
console.debug(`注册路由: [${r.path}] ${r?.key}`, "API");
|
|
10400
10402
|
let metadata = r.metadata || {};
|
|
10401
10403
|
metadata.viewItem = item;
|
|
10404
|
+
metadata.source = "query-proxy-worker";
|
|
10402
10405
|
this.router.route({
|
|
10403
10406
|
path: r.path,
|
|
10404
10407
|
key: r.key || "",
|
|
@@ -10504,13 +10507,24 @@ class QueryProxy {
|
|
|
10504
10507
|
item.response = res;
|
|
10505
10508
|
return item;
|
|
10506
10509
|
}
|
|
10507
|
-
item.response = { code: 500, message: "无法处理的路由类型" };
|
|
10510
|
+
item.response = { code: 500, message: "无法处理的路由类型", data: item };
|
|
10508
10511
|
return item;
|
|
10509
10512
|
}
|
|
10510
10513
|
}
|
|
10514
|
+
var createViewData = (routerViewData, data) => {
|
|
10515
|
+
return {
|
|
10516
|
+
views: [],
|
|
10517
|
+
viewId: undefined,
|
|
10518
|
+
data: {
|
|
10519
|
+
items: Array.isArray(routerViewData) ? routerViewData : [routerViewData]
|
|
10520
|
+
},
|
|
10521
|
+
...data
|
|
10522
|
+
};
|
|
10523
|
+
};
|
|
10511
10524
|
export {
|
|
10512
10525
|
pickRouterViewData,
|
|
10513
10526
|
initApi,
|
|
10527
|
+
createViewData,
|
|
10514
10528
|
RouteTypeList,
|
|
10515
10529
|
QueryProxy
|
|
10516
10530
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "mod.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"ws": "npm:@kevisual/ws"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@kevisual/context": "^0.0.
|
|
39
|
+
"@kevisual/context": "^0.0.6",
|
|
40
40
|
"@kevisual/js-filter": "^0.0.5",
|
|
41
41
|
"@kevisual/load": "^0.0.6",
|
|
42
42
|
"es-toolkit": "^1.44.0",
|
|
@@ -62,7 +62,7 @@ export type RouterViewWorker = {
|
|
|
62
62
|
} & RouteViewBase;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* 去掉不需要保存的服务器的数据
|
|
66
66
|
* @param item
|
|
67
67
|
* @returns
|
|
68
68
|
*/
|
|
@@ -86,7 +86,7 @@ export const pickRouterViewData = (item: RouterViewItem) => {
|
|
|
86
86
|
return rest
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
-
* 注入 js 的url地址,使用importScripts加载
|
|
89
|
+
* 注入 js 的url地址,使用 importScripts 加载
|
|
90
90
|
*/
|
|
91
91
|
export type RouteViewPage = {
|
|
92
92
|
type: 'page',
|
|
@@ -100,6 +100,9 @@ export type RouterViewQuery = {
|
|
|
100
100
|
query: string,
|
|
101
101
|
title: string
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* 后端存储结构
|
|
105
|
+
*/
|
|
103
106
|
export type RouterViewData = {
|
|
104
107
|
data: { items: RouterViewItem[]; }
|
|
105
108
|
views: RouterViewQuery[];
|
|
@@ -121,7 +124,7 @@ export class QueryProxy {
|
|
|
121
124
|
this.initRouterViewQuery();
|
|
122
125
|
this.emitter = new EventEmitter();
|
|
123
126
|
}
|
|
124
|
-
getDefulatToken() {
|
|
127
|
+
private getDefulatToken() {
|
|
125
128
|
try {
|
|
126
129
|
if (typeof window !== 'undefined' && typeof window.localStorage !== 'undefined') {
|
|
127
130
|
return localStorage.getItem('token') || undefined;
|
|
@@ -139,7 +142,7 @@ export class QueryProxy {
|
|
|
139
142
|
});
|
|
140
143
|
}
|
|
141
144
|
|
|
142
|
-
initRouterView(item: RouterViewItem) {
|
|
145
|
+
private initRouterView(item: RouterViewItem) {
|
|
143
146
|
if (item.type === 'api' && item.api?.url) {
|
|
144
147
|
const url = item.api.url;
|
|
145
148
|
if (item?.api?.query) return item;
|
|
@@ -253,6 +256,7 @@ export class QueryProxy {
|
|
|
253
256
|
console.debug(`注册路由: [${r.path}] ${r?.key}`, 'Context');
|
|
254
257
|
let metadata = r.metadata || {};
|
|
255
258
|
metadata.viewItem = item;
|
|
259
|
+
metadata.source = 'query-proxy-context';
|
|
256
260
|
this.router.route({
|
|
257
261
|
path: r.path,
|
|
258
262
|
key: r.key || '',
|
|
@@ -268,7 +272,7 @@ export class QueryProxy {
|
|
|
268
272
|
generateId() {
|
|
269
273
|
return 'route_' + Math.random().toString(36).substring(2, 9);
|
|
270
274
|
}
|
|
271
|
-
async callWorker(msg: any, viewItem: RouterViewWorker['worker']): Promise<Result> {
|
|
275
|
+
private async callWorker(msg: any, viewItem: RouterViewWorker['worker']): Promise<Result> {
|
|
272
276
|
const that = this;
|
|
273
277
|
const requestId = this.generateId();
|
|
274
278
|
const worker = viewItem?.worker;
|
|
@@ -296,7 +300,7 @@ export class QueryProxy {
|
|
|
296
300
|
});
|
|
297
301
|
});
|
|
298
302
|
}
|
|
299
|
-
async initWorker(item?: RouterViewWorker, initRoutes: boolean = true) {
|
|
303
|
+
private async initWorker(item?: RouterViewWorker, initRoutes: boolean = true) {
|
|
300
304
|
const that = this;
|
|
301
305
|
if (!item?.worker?.url) {
|
|
302
306
|
console.warn('Worker URL not provided');
|
|
@@ -347,6 +351,7 @@ export class QueryProxy {
|
|
|
347
351
|
console.debug(`注册路由: [${r.path}] ${r?.key}`, 'API');
|
|
348
352
|
let metadata = r.metadata || {};
|
|
349
353
|
metadata.viewItem = item;
|
|
354
|
+
metadata.source = 'query-proxy-worker';
|
|
350
355
|
this.router.route({
|
|
351
356
|
path: r.path,
|
|
352
357
|
key: r.key || '',
|
|
@@ -364,7 +369,7 @@ export class QueryProxy {
|
|
|
364
369
|
}
|
|
365
370
|
}
|
|
366
371
|
}
|
|
367
|
-
async initPage(item?: RouteViewPage) {
|
|
372
|
+
private async initPage(item?: RouteViewPage) {
|
|
368
373
|
if (!item?.page?.url) {
|
|
369
374
|
console.warn('Page地址未提供');
|
|
370
375
|
return;
|
|
@@ -381,7 +386,7 @@ export class QueryProxy {
|
|
|
381
386
|
return;
|
|
382
387
|
}
|
|
383
388
|
}
|
|
384
|
-
getQueryByViewId(viewId: string): string | undefined {
|
|
389
|
+
private getQueryByViewId(viewId: string): string | undefined {
|
|
385
390
|
const view = this.views.find(v => v.id === viewId);
|
|
386
391
|
if (view) {
|
|
387
392
|
return view.query;
|
|
@@ -465,7 +470,7 @@ export class QueryProxy {
|
|
|
465
470
|
item.response = res;
|
|
466
471
|
return item;
|
|
467
472
|
}
|
|
468
|
-
item.response = { code: 500, message: '无法处理的路由类型' };
|
|
473
|
+
item.response = { code: 500, message: '无法处理的路由类型', data: item };
|
|
469
474
|
return item;
|
|
470
475
|
}
|
|
471
476
|
}
|
|
@@ -477,4 +482,15 @@ export type RouterItem = {
|
|
|
477
482
|
description?: string;
|
|
478
483
|
middleware?: string[];
|
|
479
484
|
metadata?: Record<string, any>;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export const createViewData = (routerViewData: RouterViewItem | RouterViewItem[], data?: RouterViewData): RouterViewData => {
|
|
488
|
+
return {
|
|
489
|
+
views: [],
|
|
490
|
+
viewId: undefined,
|
|
491
|
+
data: {
|
|
492
|
+
items: Array.isArray(routerViewData) ? routerViewData : [routerViewData],
|
|
493
|
+
},
|
|
494
|
+
...data
|
|
495
|
+
}
|
|
480
496
|
}
|