@donkeylabs/cli 0.1.1 → 0.4.0
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/package.json +2 -2
- package/src/client/base.ts +481 -0
- package/src/commands/generate.ts +242 -41
- package/templates/starter/src/index.ts +19 -30
- package/templates/starter/src/routes/health/handlers/ping.ts +22 -0
- package/templates/starter/src/routes/health/index.ts +16 -2
- package/templates/sveltekit-app/bun.lock +4 -4
- package/templates/sveltekit-app/donkeylabs.config.ts +1 -0
- package/templates/sveltekit-app/package.json +3 -3
- package/templates/sveltekit-app/src/lib/api.ts +230 -56
- package/templates/sveltekit-app/src/routes/+page.server.ts +2 -2
- package/templates/sveltekit-app/src/routes/+page.svelte +235 -96
- package/templates/sveltekit-app/src/server/index.ts +25 -117
- package/templates/sveltekit-app/src/server/routes/cache/handlers/delete.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/cache/handlers/get.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/cache/handlers/keys.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/cache/handlers/set.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/cache/index.ts +46 -0
- package/templates/sveltekit-app/src/server/routes/counter/handlers/decrement.ts +17 -0
- package/templates/sveltekit-app/src/server/routes/counter/handlers/get.ts +17 -0
- package/templates/sveltekit-app/src/server/routes/counter/handlers/increment.ts +17 -0
- package/templates/sveltekit-app/src/server/routes/counter/handlers/reset.ts +17 -0
- package/templates/sveltekit-app/src/server/routes/counter/index.ts +39 -0
- package/templates/sveltekit-app/src/server/routes/cron/handlers/list.ts +17 -0
- package/templates/sveltekit-app/src/server/routes/cron/index.ts +24 -0
- package/templates/sveltekit-app/src/server/routes/events/handlers/emit.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/events/index.ts +19 -0
- package/templates/sveltekit-app/src/server/routes/index.ts +8 -0
- package/templates/sveltekit-app/src/server/routes/jobs/handlers/enqueue.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/jobs/handlers/stats.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/jobs/index.ts +28 -0
- package/templates/sveltekit-app/src/server/routes/ratelimit/handlers/check.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/ratelimit/handlers/reset.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/ratelimit/index.ts +29 -0
- package/templates/sveltekit-app/src/server/routes/sse/handlers/broadcast.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/sse/handlers/clients.ts +15 -0
- package/templates/sveltekit-app/src/server/routes/sse/index.ts +28 -0
- package/templates/sveltekit-app/{svelte.config.js → svelte.config.ts} +3 -2
- package/templates/starter/CLAUDE.md +0 -144
- package/templates/starter/src/client.test.ts +0 -7
- package/templates/starter/src/db.ts +0 -9
- package/templates/starter/src/routes/health/ping/index.ts +0 -13
- package/templates/starter/src/routes/health/ping/models/model.ts +0 -23
- package/templates/starter/src/routes/health/ping/schema.ts +0 -14
- package/templates/starter/src/routes/health/ping/tests/integ.test.ts +0 -20
- package/templates/starter/src/routes/health/ping/tests/unit.test.ts +0 -21
- package/templates/starter/src/test-ctx.ts +0 -24
|
@@ -1,73 +1,247 @@
|
|
|
1
|
-
// Auto-generated by donkeylabs
|
|
1
|
+
// Auto-generated by @donkeylabs/server
|
|
2
2
|
// DO NOT EDIT MANUALLY
|
|
3
3
|
|
|
4
4
|
import { UnifiedApiClientBase, type ClientOptions } from "@donkeylabs/adapter-sveltekit/client";
|
|
5
5
|
|
|
6
|
+
// Utility type that forces TypeScript to expand types on hover
|
|
7
|
+
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Handler interface for implementing route handlers in model classes.
|
|
11
|
+
* @example
|
|
12
|
+
* class CounterModel implements Handler<Routes.Counter.get> {
|
|
13
|
+
* handle(input: Routes.Counter.get.Input): Routes.Counter.get.Output {
|
|
14
|
+
* return { count: 0 };
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export interface Handler<T extends { Input: any; Output: any }> {
|
|
19
|
+
handle(input: T["Input"]): T["Output"] | Promise<T["Output"]>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Re-export server context for model classes
|
|
23
|
+
export { type ServerContext as AppContext } from "@donkeylabs/server";
|
|
24
|
+
|
|
25
|
+
// ============================================
|
|
26
|
+
// Route Types
|
|
27
|
+
// ============================================
|
|
28
|
+
|
|
29
|
+
export namespace Routes {
|
|
30
|
+
export namespace Counter {
|
|
31
|
+
export namespace get {
|
|
32
|
+
export type Input = Expand<Record<string, never>>;
|
|
33
|
+
export type Output = Expand<{
|
|
34
|
+
count: number;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export namespace increment {
|
|
39
|
+
export type Input = Expand<Record<string, never>>;
|
|
40
|
+
export type Output = Expand<{
|
|
41
|
+
count: number;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export namespace decrement {
|
|
46
|
+
export type Input = Expand<Record<string, never>>;
|
|
47
|
+
export type Output = Expand<{
|
|
48
|
+
count: number;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export namespace reset {
|
|
53
|
+
export type Input = Expand<Record<string, never>>;
|
|
54
|
+
export type Output = Expand<{
|
|
55
|
+
count: number;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export namespace Cache {
|
|
61
|
+
export namespace set {
|
|
62
|
+
export type Input = Expand<{
|
|
63
|
+
key: string;
|
|
64
|
+
value: any;
|
|
65
|
+
ttl?: number;
|
|
66
|
+
}>;
|
|
67
|
+
export type Output = Expand<{
|
|
68
|
+
success: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export namespace get {
|
|
73
|
+
export type Input = Expand<{
|
|
74
|
+
key: string;
|
|
75
|
+
}>;
|
|
76
|
+
export type Output = Expand<{
|
|
77
|
+
value?: any;
|
|
78
|
+
exists: boolean;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export namespace delete {
|
|
83
|
+
export type Input = Expand<{
|
|
84
|
+
key: string;
|
|
85
|
+
}>;
|
|
86
|
+
export type Output = Expand<{
|
|
87
|
+
success: boolean;
|
|
88
|
+
}>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export namespace keys {
|
|
92
|
+
export type Input = Expand<Record<string, never>>;
|
|
93
|
+
export type Output = Expand<{
|
|
94
|
+
keys: string[];
|
|
95
|
+
}>;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export namespace Jobs {
|
|
100
|
+
export namespace enqueue {
|
|
101
|
+
export type Input = Expand<{
|
|
102
|
+
name: string;
|
|
103
|
+
data: any;
|
|
104
|
+
delay?: number;
|
|
105
|
+
}>;
|
|
106
|
+
export type Output = Expand<{
|
|
107
|
+
jobId: string;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export namespace stats {
|
|
112
|
+
export type Input = Expand<Record<string, never>>;
|
|
113
|
+
export type Output = Expand<{
|
|
114
|
+
pending: number;
|
|
115
|
+
running: number;
|
|
116
|
+
completed: number;
|
|
117
|
+
}>;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export namespace Cron {
|
|
122
|
+
export namespace list {
|
|
123
|
+
export type Input = Expand<Record<string, never>>;
|
|
124
|
+
export type Output = Expand<{
|
|
125
|
+
tasks: {
|
|
126
|
+
id: string;
|
|
127
|
+
name: string;
|
|
128
|
+
expression: string;
|
|
129
|
+
enabled: boolean;
|
|
130
|
+
lastRun?: string;
|
|
131
|
+
nextRun?: string;
|
|
132
|
+
}[];
|
|
133
|
+
}>;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export namespace Ratelimit {
|
|
138
|
+
export namespace check {
|
|
139
|
+
export type Input = Expand<{
|
|
140
|
+
key: string;
|
|
141
|
+
limit: number;
|
|
142
|
+
window: number;
|
|
143
|
+
}>;
|
|
144
|
+
export type Output = Expand<{
|
|
145
|
+
allowed: boolean;
|
|
146
|
+
remaining: number;
|
|
147
|
+
resetAt: Date;
|
|
148
|
+
}>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export namespace reset {
|
|
152
|
+
export type Input = Expand<{
|
|
153
|
+
key: string;
|
|
154
|
+
}>;
|
|
155
|
+
export type Output = Expand<{
|
|
156
|
+
success: boolean;
|
|
157
|
+
}>;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export namespace Events {
|
|
162
|
+
export namespace emit {
|
|
163
|
+
export type Input = Expand<{
|
|
164
|
+
event: string;
|
|
165
|
+
data: any;
|
|
166
|
+
}>;
|
|
167
|
+
export type Output = Expand<{
|
|
168
|
+
success: boolean;
|
|
169
|
+
}>;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export namespace Sse {
|
|
174
|
+
export namespace broadcast {
|
|
175
|
+
export type Input = Expand<{
|
|
176
|
+
channel: string;
|
|
177
|
+
event: string;
|
|
178
|
+
data: any;
|
|
179
|
+
}>;
|
|
180
|
+
export type Output = Expand<{
|
|
181
|
+
success: boolean;
|
|
182
|
+
recipients: number;
|
|
183
|
+
}>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export namespace clients {
|
|
187
|
+
export type Input = Expand<Record<string, never>>;
|
|
188
|
+
export type Output = Expand<{
|
|
189
|
+
total: number;
|
|
190
|
+
byChannel: number;
|
|
191
|
+
}>;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ============================================
|
|
197
|
+
// API Client
|
|
198
|
+
// ============================================
|
|
199
|
+
|
|
6
200
|
export class ApiClient extends UnifiedApiClientBase {
|
|
7
201
|
constructor(options?: ClientOptions) {
|
|
8
202
|
super(options);
|
|
9
203
|
}
|
|
10
204
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
205
|
+
counter = {
|
|
206
|
+
get: (input: Routes.Counter.get.Input): Promise<Routes.Counter.get.Output> => this.request("api.counter.get", input),
|
|
207
|
+
increment: (input: Routes.Counter.increment.Input): Promise<Routes.Counter.increment.Output> => this.request("api.counter.increment", input),
|
|
208
|
+
decrement: (input: Routes.Counter.decrement.Input): Promise<Routes.Counter.decrement.Output> => this.request("api.counter.decrement", input),
|
|
209
|
+
reset: (input: Routes.Counter.reset.Input): Promise<Routes.Counter.reset.Output> => this.request("api.counter.reset", input)
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
cache = {
|
|
213
|
+
set: (input: Routes.Cache.set.Input): Promise<Routes.Cache.set.Output> => this.request("api.cache.set", input),
|
|
214
|
+
get: (input: Routes.Cache.get.Input): Promise<Routes.Cache.get.Output> => this.request("api.cache.get", input),
|
|
215
|
+
delete: (input: Routes.Cache.delete.Input): Promise<Routes.Cache.delete.Output> => this.request("api.cache.delete", input),
|
|
216
|
+
keys: (input: Routes.Cache.keys.Input): Promise<Routes.Cache.keys.Output> => this.request("api.cache.keys", input)
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
jobs = {
|
|
220
|
+
enqueue: (input: Routes.Jobs.enqueue.Input): Promise<Routes.Jobs.enqueue.Output> => this.request("api.jobs.enqueue", input),
|
|
221
|
+
stats: (input: Routes.Jobs.stats.Input): Promise<Routes.Jobs.stats.Output> => this.request("api.jobs.stats", input)
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
cron = {
|
|
225
|
+
list: (input: Routes.Cron.list.Input): Promise<Routes.Cron.list.Output> => this.request("api.cron.list", input)
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
ratelimit = {
|
|
229
|
+
check: (input: Routes.Ratelimit.check.Input): Promise<Routes.Ratelimit.check.Output> => this.request("api.ratelimit.check", input),
|
|
230
|
+
reset: (input: Routes.Ratelimit.reset.Input): Promise<Routes.Ratelimit.reset.Output> => this.request("api.ratelimit.reset", input)
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
events = {
|
|
234
|
+
emit: (input: Routes.Events.emit.Input): Promise<Routes.Events.emit.Output> => this.request("api.events.emit", input)
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
sse = {
|
|
238
|
+
broadcast: (input: Routes.Sse.broadcast.Input): Promise<Routes.Sse.broadcast.Output> => this.request("api.sse.broadcast", input),
|
|
239
|
+
clients: (input: Routes.Sse.clients.Input): Promise<Routes.Sse.clients.Output> => this.request("api.sse.clients", input)
|
|
42
240
|
};
|
|
43
241
|
}
|
|
44
242
|
|
|
45
243
|
/**
|
|
46
244
|
* Create an API client instance
|
|
47
|
-
*
|
|
48
|
-
* @param options.locals - Pass SvelteKit locals for SSR direct calls (no HTTP overhead)
|
|
49
|
-
* @param options.baseUrl - Override the base URL for HTTP calls
|
|
50
|
-
*
|
|
51
|
-
* @example SSR usage in +page.server.ts:
|
|
52
|
-
* ```ts
|
|
53
|
-
* export const load = async ({ locals }) => {
|
|
54
|
-
* const api = createApi({ locals });
|
|
55
|
-
* const data = await api.myRoute.get({}); // Direct call, no HTTP!
|
|
56
|
-
* return { data };
|
|
57
|
-
* };
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @example Browser usage in +page.svelte:
|
|
61
|
-
* ```svelte
|
|
62
|
-
* <script>
|
|
63
|
-
* import { createApi } from '$lib/api';
|
|
64
|
-
* const api = createApi(); // HTTP calls
|
|
65
|
-
* let data = $state(null);
|
|
66
|
-
* async function load() {
|
|
67
|
-
* data = await api.myRoute.get({});
|
|
68
|
-
* }
|
|
69
|
-
* </script>
|
|
70
|
-
* ```
|
|
71
245
|
*/
|
|
72
246
|
export function createApi(options?: ClientOptions) {
|
|
73
247
|
return new ApiClient(options);
|
|
@@ -4,11 +4,11 @@ import { createApi } from '$lib/api';
|
|
|
4
4
|
|
|
5
5
|
export const load: PageServerLoad = async ({ locals }) => {
|
|
6
6
|
// Create API client with locals for direct SSR calls (no HTTP!)
|
|
7
|
-
const
|
|
7
|
+
const client = createApi({ locals });
|
|
8
8
|
|
|
9
9
|
try {
|
|
10
10
|
// Direct service call through typed client
|
|
11
|
-
const result = await
|
|
11
|
+
const result = await client.counter.get({});
|
|
12
12
|
return {
|
|
13
13
|
count: result.count,
|
|
14
14
|
loadedAt: new Date().toISOString(),
|