refactor: migrate from Rollup to Bun for build configuration
feat: update adapter to use globalThis for origin resolution fix: remove unused ClientQuery export from query.ts chore: update tsconfig to include test files and set rootDir feat: add create-query functionality for dynamic API generation feat: implement QueryApi with enhanced type inference from JSON Schema test: add comprehensive API tests for QueryApi functionality test: create demo routes and schemas for testing purposes docs: add type inference demo for QueryApi usage
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { App } from '@kevisual/router';
|
||||
|
||||
const app = new App({
|
||||
io: true,
|
||||
});
|
||||
const app = new App({});
|
||||
|
||||
app
|
||||
.route({
|
||||
@@ -17,8 +15,3 @@ app
|
||||
app.listen(4000, () => {
|
||||
console.log('Server is running at http://localhost:4000');
|
||||
});
|
||||
|
||||
app.io.addListener('subscribe', async ({ data, end, ws }) => {
|
||||
console.log('A user connected', data);
|
||||
ws.send('Hello World');
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// console.log('Hello World');
|
||||
import { adapter, Query } from '@abearxiong/query';
|
||||
import { QueryWs } from '@abearxiong/query/ws';
|
||||
import { adapter, Query } from '@kevisual/query';
|
||||
import { QueryWs } from '@kevisual/query/ws';
|
||||
|
||||
window.onload = async () => {
|
||||
// const res = await adapter({
|
||||
|
||||
67
demo/type-inference-demo.ts
Normal file
67
demo/type-inference-demo.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { QueryApi } from "../src/query-api";
|
||||
|
||||
const api = new QueryApi();
|
||||
|
||||
// 示例 1: args 的 value 是 string 类型
|
||||
api.post(
|
||||
{
|
||||
path: "/users",
|
||||
metadata: {
|
||||
args: {
|
||||
name: "John",
|
||||
email: "john@example.com"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
pos: "someValue", // ✅ TypeScript 会推断 pos 应该是 string 类型
|
||||
other: "data"
|
||||
}
|
||||
);
|
||||
|
||||
// 示例 2: args 的 value 是 number 类型
|
||||
api.post(
|
||||
{
|
||||
path: "/products",
|
||||
metadata: {
|
||||
args: {
|
||||
id: 123,
|
||||
price: 99.99
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
pos: 456, // ✅ TypeScript 会推断 pos 应该是 number 类型
|
||||
other: "data"
|
||||
}
|
||||
);
|
||||
|
||||
// 示例 3: args 的 value 是混合类型
|
||||
api.post(
|
||||
{
|
||||
path: "/orders",
|
||||
metadata: {
|
||||
args: {
|
||||
orderId: 123,
|
||||
status: "pending",
|
||||
total: 99.99
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
pos: "status", // ✅ TypeScript 会推断 pos 可以是 string 或 number
|
||||
// pos: 999, // 这也是合法的
|
||||
other: "data"
|
||||
}
|
||||
);
|
||||
|
||||
// 示例 4: 没有 metadata 或 args
|
||||
api.post(
|
||||
{
|
||||
path: "/test"
|
||||
},
|
||||
{
|
||||
pos: undefined, // ✅ pos 类型为 never,只能是 undefined
|
||||
other: "data"
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user