@kevisual/router 0.2.4 → 0.2.6

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,72 @@
1
+ export declare const api: {
2
+ "app_domain_manager": {
3
+ /**
4
+ * 获取域名信息,可以通过id或者domain进行查询
5
+ *
6
+ * @param data - Request parameters
7
+ * @param data.data - {object}
8
+ */
9
+ "get": {
10
+ "path": "app_domain_manager",
11
+ "key": "get",
12
+ "description": "获取域名信息,可以通过id或者domain进行查询",
13
+ "metadata": {
14
+ "args": {
15
+ "data": {
16
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
17
+ "type": "object",
18
+ "properties": {
19
+ "id": {
20
+ "type": "string"
21
+ },
22
+ "domain": {
23
+ "type": "string"
24
+ }
25
+ },
26
+ "additionalProperties": false,
27
+ "required": ["id",]
28
+ }
29
+ },
30
+ "viewItem": {
31
+ "api": {
32
+ "url": "/api/router"
33
+ },
34
+ "type": "api",
35
+ "title": "路由"
36
+ },
37
+ "url": "/api/router",
38
+ "source": "query-proxy-api"
39
+ }
40
+ },
41
+ "delete": {
42
+ "path": "app_domain_manager",
43
+ "key": "delete",
44
+ "description": "删除域名",
45
+ "metadata": {
46
+ "args": {
47
+ "domainId": {
48
+ "type": "string",
49
+ "optional": true
50
+ }
51
+ }
52
+ }
53
+ }
54
+ },
55
+ "user_manager": {
56
+ "getUser": {
57
+ "path": "user_manager",
58
+ "key": "getUser",
59
+ "description": "获取用户信息",
60
+ "metadata": {
61
+ "args": {
62
+ "userId": {
63
+ "type": "string"
64
+ },
65
+ "includeProfile": {
66
+ "type": "boolean"
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
@@ -0,0 +1 @@
1
+ export const api = {}
File without changes
package/src/test/mini.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Mini } from "../route.ts";
2
-
2
+ import { parse, } from '../commander.ts'
3
3
  const app = new Mini();
4
4
 
5
5
  app.route({
6
6
  path: 'main',
7
- id: 'abc',
7
+ rid: 'abc',
8
8
  description: '这是一个测试的 main 路由'
9
9
  }).define(async (ctx) => {
10
10
  ctx.body = {
@@ -12,5 +12,13 @@ app.route({
12
12
  }
13
13
  }).addTo(app)
14
14
 
15
+ app.route({
16
+ path: 'good',
17
+ description: '这是一个测试的 good 路由'
18
+ }).define(async (ctx) => {
19
+ ctx.body = { content: 'good' }
20
+ console.log('good')
21
+ }).addTo(app)
22
+ // app.wait()
15
23
 
16
- app.wait()
24
+ await parse({ app })
@@ -12,4 +12,4 @@ router.route({
12
12
  }).define(async (ctx) => {
13
13
  const argA: string = ctx.args.a;
14
14
  ctx.body = '1';
15
- })
15
+ }).addTo(router);
@@ -1,5 +1,6 @@
1
1
  import z from "zod";
2
2
  import { App } from "../index.ts";
3
+ import { api as a2 } from './api.js';
3
4
 
4
5
  const app = new App();
5
6
  const api = {
@@ -78,7 +79,7 @@ type API = typeof api;
78
79
 
79
80
  // 类型推断生效:payload 根据 metadata.args 自动推断
80
81
  // get 的 args.data 是 type:"object",所以 payload 需要 { data: object }
81
- app.runAction(api.app_domain_manager.get, { data: { id: "1" } })
82
+ app.runAction(a2.app_domain_manager.get, { data: { idd: "1" }, })
82
83
 
83
84
  // delete 的 args 是 { domainId: { type: "string" } },所以 payload 需要 { domainId: string }
84
85
  app.runAction(api.app_domain_manager.delete, { domainId: "d1" })
@@ -18,5 +18,5 @@ app
18
18
  app.listen(2233, () => {
19
19
  console.log('Server is running on http://localhost:2233');
20
20
  });
21
-
21
+ // TODO:有问题, deno,bun 不兼容sendFile,piepStream
22
22
  app.onServerRequest(proxyRoute);
package/src/test/ws.ts CHANGED
@@ -7,6 +7,7 @@ app
7
7
  .route('demo', '03')
8
8
  .define(async (ctx) => {
9
9
  ctx.body = '03';
10
+ ctx.res.end
10
11
  return ctx;
11
12
  })
12
13
  .addTo(app);
@@ -99,7 +99,7 @@ export const listenProcess = async ({ app, mockProcess, params = {}, timeout = 1
99
99
  */
100
100
  if (!msg.path && !msg.id) {
101
101
  const route = app.routes.find(r => r.path !== 'router')
102
- msg.id = route?.id
102
+ msg.id = route?.rid
103
103
  }
104
104
  // 执行主要逻辑
105
105
  const result = await app.run(msg, ctx);
@@ -1,14 +0,0 @@
1
- import { App } from '@/app.ts';
2
- import { QueryUtil } from '@/router-define.ts';
3
- const v = QueryUtil.create({
4
- a: {
5
- path: 'a',
6
- key: 'b',
7
- },
8
- });
9
- const app = new App();
10
- app.route(v.get('a'));
11
-
12
- v.chain('a').define<{ f: () => {} }>(async (ctx) => {
13
- // ctx.f = 'sdf';
14
- });
@@ -1,18 +0,0 @@
1
- // import { Server } from 'node:http';
2
- import { ServerNode } from '../server/server.ts'
3
-
4
- const server = new ServerNode({
5
- path: '/',
6
- handle: async (data, ctx) => {
7
- console.log('ctx', ctx.req.url)
8
- console.log('Received data:', data);
9
-
10
- ctx.res.writeHead(200, { 'Content-Type': 'application/json' });
11
- return JSON.stringify({ code: 200, message: 'Success', data });
12
- }
13
- });
14
-
15
- server.listen(51015, '0.0.0.0', () => {
16
- console.log('Server is listening on http://localhost:3000');
17
- });
18
-
@@ -1,14 +0,0 @@
1
- import { toJSONSchema, fromJSONSchema } from "@/route.ts";
2
- import { z } from "zod";
3
- const schema = z.object({
4
- name: z.string(),
5
- age: z.number(),
6
-
7
- });
8
- // console.log("schema", schema);
9
- const jsonSchema = toJSONSchema(schema);
10
- console.log("jsonSchema", jsonSchema);
11
-
12
- const newSchema = fromJSONSchema<true>(jsonSchema, { mergeObject: true });
13
- console.log("newSchema shape", Object.keys(newSchema.shape));
14
- console.log('check', newSchema.safeParse({ name: "Alice", age: "30" })?.success);