khotan-data 0.0.1 → 0.1.1
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/AGENTS.md +54 -0
- package/README.md +117 -1
- package/dist/cli.js +2869 -0
- package/dist/factory.cjs +3303 -0
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.cts +662 -0
- package/dist/factory.d.ts +662 -0
- package/dist/factory.js +3292 -0
- package/dist/factory.js.map +1 -0
- package/dist/plug-client.cjs +99 -0
- package/dist/plug-client.cjs.map +1 -0
- package/dist/plug-client.d.cts +71 -0
- package/dist/plug-client.d.ts +71 -0
- package/dist/plug-client.js +96 -0
- package/dist/plug-client.js.map +1 -0
- package/dist/templates/agent-skill.md +73 -0
- package/dist/templates/agents.md +41 -0
- package/dist/templates/cache.example.ts +11 -0
- package/dist/templates/cache.ts +58 -0
- package/dist/templates/catch.example.ts +36 -0
- package/dist/templates/catch.ts +119 -0
- package/dist/templates/config-page.tsx +20 -0
- package/dist/templates/debug-index-page.tsx +101 -0
- package/dist/templates/debug-page.tsx +48 -0
- package/dist/templates/graph-page.tsx +11 -0
- package/dist/templates/hub.tsx +450 -0
- package/dist/templates/inflow.example.ts +61 -0
- package/dist/templates/inflow.ts +98 -0
- package/dist/templates/khotan-config.ts +49 -0
- package/dist/templates/khotan-route.ts +13 -0
- package/dist/templates/logs-page.tsx +9 -0
- package/dist/templates/logs.tsx +20 -0
- package/dist/templates/mapping-browser.tsx +761 -0
- package/dist/templates/mappings-page.tsx +9 -0
- package/dist/templates/outflow.example.ts +52 -0
- package/dist/templates/outflow.ts +90 -0
- package/dist/templates/pass.example.ts +51 -0
- package/dist/templates/pass.ts +134 -0
- package/dist/templates/plug-debugger.tsx +1185 -0
- package/dist/templates/plug.example.ts +93 -0
- package/dist/templates/plug.ts +806 -0
- package/dist/templates/relay.example.ts +71 -0
- package/dist/templates/relay.ts +104 -0
- package/dist/templates/runs-table.tsx +592 -0
- package/dist/templates/schema.ts +505 -0
- package/dist/templates/skill-dashboard.md +144 -0
- package/dist/templates/skill-plug.md +216 -0
- package/dist/templates/skill-setup.md +161 -0
- package/dist/templates/skill-webhook.md +196 -0
- package/dist/templates/topology-canvas.tsx +1406 -0
- package/dist/templates/var-panel.tsx +276 -0
- package/dist/templates/webhook-events-table.tsx +241 -0
- package/dist/templates/wire-panel.tsx +216 -0
- package/dist/templates/wire.ts +155 -0
- package/package.json +46 -5
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Example: Typed Endpoints with defineContract + Plug
|
|
3
|
+
// Generated by khotan CLI · https://github.com/khotan-data
|
|
4
|
+
//
|
|
5
|
+
// This file demonstrates how to define a typed API contract and create a
|
|
6
|
+
// type-safe client using createPlugClient. Delete or rename it as needed.
|
|
7
|
+
// ============================================================================
|
|
8
|
+
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { defineContract, createPlugClient } from "khotan-data/plug";
|
|
11
|
+
import { plug, bearer } from "./plug";
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// 1. Define your API contract
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
const ProductSchema = z.object({
|
|
18
|
+
id: z.string(),
|
|
19
|
+
name: z.string(),
|
|
20
|
+
price: z.number(),
|
|
21
|
+
createdAt: z.string(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const ErrorSchema = z.object({
|
|
25
|
+
error: z.string(),
|
|
26
|
+
message: z.string(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const apiContract = defineContract({
|
|
30
|
+
listProducts: {
|
|
31
|
+
method: "GET",
|
|
32
|
+
path: "/products",
|
|
33
|
+
query: z.object({
|
|
34
|
+
page: z.number().optional(),
|
|
35
|
+
limit: z.number().optional(),
|
|
36
|
+
}),
|
|
37
|
+
responses: {
|
|
38
|
+
200: z.object({
|
|
39
|
+
data: z.array(ProductSchema),
|
|
40
|
+
total: z.number(),
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
getProduct: {
|
|
45
|
+
method: "GET",
|
|
46
|
+
path: "/products/:id",
|
|
47
|
+
responses: {
|
|
48
|
+
200: ProductSchema,
|
|
49
|
+
404: ErrorSchema,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
createProduct: {
|
|
53
|
+
method: "POST",
|
|
54
|
+
path: "/products",
|
|
55
|
+
body: z.object({
|
|
56
|
+
name: z.string(),
|
|
57
|
+
price: z.number(),
|
|
58
|
+
}),
|
|
59
|
+
responses: {
|
|
60
|
+
201: ProductSchema,
|
|
61
|
+
400: ErrorSchema,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// 2. Create a typed client from contract + Plug instance
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
const api = plug({
|
|
71
|
+
baseUrl: "https://api.example.com",
|
|
72
|
+
auth: bearer(process.env.API_TOKEN!),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export const client = createPlugClient(apiContract, api);
|
|
76
|
+
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// 3. Usage — fully typed, validated, with IDE autocomplete
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
// GET /products?page=1&limit=10
|
|
82
|
+
// const products = await client.listProducts({ query: { page: 1, limit: 10 } });
|
|
83
|
+
// products.body.data — typed as { id, name, price, createdAt }[]
|
|
84
|
+
|
|
85
|
+
// GET /products/:id
|
|
86
|
+
// const product = await client.getProduct({ params: { id: "abc" } });
|
|
87
|
+
// if (product.status === 200) product.body.name — typed as string
|
|
88
|
+
// if (product.status === 404) product.body.error — typed as string
|
|
89
|
+
|
|
90
|
+
// POST /products
|
|
91
|
+
// const created = await client.createProduct({
|
|
92
|
+
// body: { name: "Widget", price: 9.99 },
|
|
93
|
+
// });
|