kyro-connect 0.1.4 → 0.1.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.
package/README.md CHANGED
@@ -36,7 +36,13 @@ const api = createClient<AppRouter>({
36
36
 
37
37
  ### `createClient(options)`
38
38
 
39
- Creates a proxy-based client for your Kyro CMS tRPC endpoint.
39
+ Creates a proxy-based client for your Kyro CMS tRPC endpoint. Each property access builds a procedure path, and calling it triggers the request.
40
+
41
+ All three calling patterns are supported and interchangeable:
42
+
43
+ - `api["posts"].find(input)` — direct call
44
+ - `api["posts"].find.query(input)` — explicit query
45
+ - `api["posts"].create.mutate(input)` — explicit mutation (for writes)
40
46
 
41
47
  ```ts
42
48
  const api = createClient<AppRouter>({
@@ -52,12 +58,27 @@ const api = createClient<AppRouter>({
52
58
  | `apiKey` | `string` | — | API key for authenticated requests |
53
59
  | `fetch` | `typeof globalThis.fetch` | `globalThis.fetch` | Custom fetch implementation |
54
60
 
61
+ #### Using environment variables
62
+
63
+ ```ts
64
+ const api = createClient<AppRouter>({
65
+ url: process.env.KYRO_API_URL!,
66
+ apiKey: process.env.KYRO_API_KEY!,
67
+ });
68
+ ```
69
+
55
70
  #### Query procedures (GET)
56
71
 
72
+ All three patterns work:
73
+
57
74
  ```ts
75
+ // Direct call
58
76
  const { docs } = await api["posts"].find({ page: 1, limit: 10 });
59
77
  // docs: Post[]
60
78
 
79
+ // Explicit .query()
80
+ const { docs } = await api["posts"].find.query({ page: 1, limit: 10 });
81
+
61
82
  const post = await api["posts"].findByID({ id: "abc123" });
62
83
  // post: Post
63
84
 
@@ -70,11 +91,17 @@ const { totalDocs } = await api["posts"].count({
70
91
  #### Mutation procedures (POST)
71
92
 
72
93
  ```ts
94
+ // Direct call (creates/updates/deletes are auto-detected as POST)
73
95
  const { doc } = await api["posts"].create({
74
96
  data: { title: "Hello", slug: "hello" },
75
97
  });
76
98
  // doc: Post
77
99
 
100
+ // Explicit .mutate()
101
+ const { doc } = await api["posts"].create.mutate({
102
+ data: { title: "Hello", slug: "hello" },
103
+ });
104
+
78
105
  const { doc } = await api["posts"].update({
79
106
  id: "abc",
80
107
  data: { title: "Updated" },
@@ -96,6 +123,14 @@ await api["_globals_site-settings"].update({
96
123
  });
97
124
  ```
98
125
 
126
+ #### Collections with hyphens in slug
127
+
128
+ Use bracket notation:
129
+
130
+ ```ts
131
+ const data = await api["my-collection"].find({ page: 1 });
132
+ ```
133
+
99
134
  ---
100
135
 
101
136
  ## Codegen
@@ -119,21 +154,13 @@ Running codegen produces `kyro.generated.d.ts` containing:
119
154
  - **Output types** — typed outputs for every procedure (`PostsFindOutput`, etc.)
120
155
  - **AppRouter** — mapped type linking all collection/global procedures to their input/output types
121
156
 
122
- ### Slugs with hyphens
123
-
124
- Use bracket notation when accessing collections with hyphens in their slug:
125
-
126
- ```ts
127
- const data = await api["my-collection"].find({ page: 1 });
128
- ```
129
-
130
157
  ### Without codegen
131
158
 
132
159
  The client works without types — everything is `any`:
133
160
 
134
161
  ```ts
135
162
  const api = createClient({ url: "...", apiKey: "..." });
136
- const posts = await api.posts.find({ page: 1 });
163
+ const posts = await api["posts"].find({ page: 1 });
137
164
  // posts: any
138
165
  ```
139
166
 
@@ -143,6 +170,8 @@ const posts = await api.posts.find({ page: 1 });
143
170
 
144
171
  ### Request format
145
172
 
173
+ The client communicates with the Kyro tRPC endpoint. Each procedure call maps to an HTTP request:
174
+
146
175
  | Procedure type | HTTP method | URL | Body |
147
176
  |---|---|---|---|
148
177
  | `find`, `findByID`, `count` | GET | `/api/trpc/{slug}.{proc}?input={json}` | — |
@@ -169,7 +198,6 @@ try {
169
198
  if (err instanceof KyroConnectError) {
170
199
  console.error(err.message); // Server error message
171
200
  console.error(err.status); // HTTP status code
172
- console.error(err.code); // tRPC error code
173
201
  }
174
202
  }
175
203
  ```
package/dist/index.d.cts CHANGED
@@ -3,10 +3,11 @@ interface ClientOptions {
3
3
  apiKey?: string;
4
4
  fetch?: typeof globalThis.fetch;
5
5
  }
6
- type ProcedureClient<I, O> = {
6
+ interface ProcedureClient<I, O> {
7
+ (input: I): Promise<O>;
7
8
  query: (input: I) => Promise<O>;
8
9
  mutate: (input: I) => Promise<O>;
9
- };
10
+ }
10
11
  type RouterClient<T> = {
11
12
  [K in keyof T]: T[K] extends {
12
13
  input: infer I;
package/dist/index.d.ts CHANGED
@@ -3,10 +3,11 @@ interface ClientOptions {
3
3
  apiKey?: string;
4
4
  fetch?: typeof globalThis.fetch;
5
5
  }
6
- type ProcedureClient<I, O> = {
6
+ interface ProcedureClient<I, O> {
7
+ (input: I): Promise<O>;
7
8
  query: (input: I) => Promise<O>;
8
9
  mutate: (input: I) => Promise<O>;
9
- };
10
+ }
10
11
  type RouterClient<T> = {
11
12
  [K in keyof T]: T[K] extends {
12
13
  input: infer I;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kyro-connect",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Universal SDK for Kyro CMS. Type-safe client + codegen for any platform.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",