@donkeylabs/cli 0.4.3 → 0.4.4
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
CHANGED
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"vite": "^7.2.6"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@donkeylabs/cli": "^0.4.
|
|
28
|
-
"@donkeylabs/adapter-sveltekit": "^0.4.
|
|
29
|
-
"@donkeylabs/server": "^0.4.
|
|
27
|
+
"@donkeylabs/cli": "^0.4.4",
|
|
28
|
+
"@donkeylabs/adapter-sveltekit": "^0.4.4",
|
|
29
|
+
"@donkeylabs/server": "^0.4.4",
|
|
30
30
|
"bits-ui": "^2.15.4",
|
|
31
31
|
"clsx": "^2.1.1",
|
|
32
32
|
"kysely": "^0.27.6",
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Demo Router - Showcases @donkeylabs/server core features
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - Cache: In-memory caching with TTL
|
|
7
|
-
* - SSE: Server-sent events broadcasting
|
|
8
|
-
* - Jobs: Background job queue
|
|
9
|
-
* - Events: Pub/sub event system
|
|
10
|
-
* - Rate Limiting: Request throttling
|
|
11
|
-
* - Cron: Scheduled tasks
|
|
4
|
+
* Routes delegate to the demo plugin service which handles
|
|
5
|
+
* the core service integrations with proper types.
|
|
12
6
|
*/
|
|
13
7
|
|
|
14
8
|
import { createRouter, defineRoute } from "@donkeylabs/server";
|
|
@@ -24,7 +18,7 @@ demo.route("counter.get").typed(
|
|
|
24
18
|
defineRoute({
|
|
25
19
|
output: z.object({ count: z.number() }),
|
|
26
20
|
handle: async (_, ctx) => {
|
|
27
|
-
return { count: ctx.plugins.demo.
|
|
21
|
+
return { count: ctx.plugins.demo.getCounter() };
|
|
28
22
|
},
|
|
29
23
|
})
|
|
30
24
|
);
|
|
@@ -51,14 +45,13 @@ demo.route("counter.reset").typed(
|
|
|
51
45
|
defineRoute({
|
|
52
46
|
output: z.object({ count: z.number() }),
|
|
53
47
|
handle: async (_, ctx) => {
|
|
54
|
-
ctx.plugins.demo.reset();
|
|
55
|
-
return { count: 0 };
|
|
48
|
+
return { count: ctx.plugins.demo.reset() };
|
|
56
49
|
},
|
|
57
50
|
})
|
|
58
51
|
);
|
|
59
52
|
|
|
60
53
|
// =============================================================================
|
|
61
|
-
// CACHE - In-memory caching
|
|
54
|
+
// CACHE - In-memory caching (via plugin service)
|
|
62
55
|
// =============================================================================
|
|
63
56
|
|
|
64
57
|
demo.route("cache.set").typed(
|
|
@@ -70,8 +63,7 @@ demo.route("cache.set").typed(
|
|
|
70
63
|
}),
|
|
71
64
|
output: z.object({ success: z.boolean() }),
|
|
72
65
|
handle: async (input, ctx) => {
|
|
73
|
-
ctx.
|
|
74
|
-
return { success: true };
|
|
66
|
+
return ctx.plugins.demo.cacheSet(input.key, input.value, input.ttl);
|
|
75
67
|
},
|
|
76
68
|
})
|
|
77
69
|
);
|
|
@@ -81,8 +73,7 @@ demo.route("cache.get").typed(
|
|
|
81
73
|
input: z.object({ key: z.string() }),
|
|
82
74
|
output: z.object({ value: z.any().optional(), exists: z.boolean() }),
|
|
83
75
|
handle: async (input, ctx) => {
|
|
84
|
-
|
|
85
|
-
return { value, exists: value !== undefined };
|
|
76
|
+
return ctx.plugins.demo.cacheGet(input.key);
|
|
86
77
|
},
|
|
87
78
|
})
|
|
88
79
|
);
|
|
@@ -92,23 +83,22 @@ demo.route("cache.delete").typed(
|
|
|
92
83
|
input: z.object({ key: z.string() }),
|
|
93
84
|
output: z.object({ success: z.boolean() }),
|
|
94
85
|
handle: async (input, ctx) => {
|
|
95
|
-
ctx.
|
|
96
|
-
return { success: true };
|
|
86
|
+
return ctx.plugins.demo.cacheDelete(input.key);
|
|
97
87
|
},
|
|
98
88
|
})
|
|
99
89
|
);
|
|
100
90
|
|
|
101
91
|
demo.route("cache.keys").typed(
|
|
102
92
|
defineRoute({
|
|
103
|
-
output: z.object({ keys: z.array(z.string()) }),
|
|
93
|
+
output: z.object({ keys: z.array(z.string()), size: z.number() }),
|
|
104
94
|
handle: async (_, ctx) => {
|
|
105
|
-
return
|
|
95
|
+
return ctx.plugins.demo.cacheKeys();
|
|
106
96
|
},
|
|
107
97
|
})
|
|
108
98
|
);
|
|
109
99
|
|
|
110
100
|
// =============================================================================
|
|
111
|
-
// SSE - Server-Sent Events
|
|
101
|
+
// SSE - Server-Sent Events (via plugin service)
|
|
112
102
|
// =============================================================================
|
|
113
103
|
|
|
114
104
|
demo.route("sse.broadcast").typed(
|
|
@@ -118,10 +108,11 @@ demo.route("sse.broadcast").typed(
|
|
|
118
108
|
event: z.string().default("manual"),
|
|
119
109
|
data: z.any(),
|
|
120
110
|
}),
|
|
121
|
-
output: z.object({ success: z.boolean()
|
|
111
|
+
output: z.object({ success: z.boolean() }),
|
|
122
112
|
handle: async (input, ctx) => {
|
|
123
|
-
const
|
|
124
|
-
|
|
113
|
+
const channel = input.channel ?? "events";
|
|
114
|
+
const event = input.event ?? "manual";
|
|
115
|
+
return ctx.plugins.demo.broadcast(channel, event, input.data);
|
|
125
116
|
},
|
|
126
117
|
})
|
|
127
118
|
);
|
|
@@ -130,14 +121,13 @@ demo.route("sse.clients").typed(
|
|
|
130
121
|
defineRoute({
|
|
131
122
|
output: z.object({ total: z.number(), byChannel: z.number() }),
|
|
132
123
|
handle: async (_, ctx) => {
|
|
133
|
-
|
|
134
|
-
return { total: stats.totalClients, byChannel: stats.clientsByChannel.events || 0 };
|
|
124
|
+
return ctx.plugins.demo.getSSEClients();
|
|
135
125
|
},
|
|
136
126
|
})
|
|
137
127
|
);
|
|
138
128
|
|
|
139
129
|
// =============================================================================
|
|
140
|
-
// JOBS - Background job queue
|
|
130
|
+
// JOBS - Background job queue (via plugin service)
|
|
141
131
|
// =============================================================================
|
|
142
132
|
|
|
143
133
|
demo.route("jobs.enqueue").typed(
|
|
@@ -147,10 +137,10 @@ demo.route("jobs.enqueue").typed(
|
|
|
147
137
|
data: z.record(z.any()).optional(),
|
|
148
138
|
delay: z.number().optional(),
|
|
149
139
|
}),
|
|
150
|
-
output: z.object({
|
|
140
|
+
output: z.object({ jobId: z.string() }),
|
|
151
141
|
handle: async (input, ctx) => {
|
|
152
|
-
const
|
|
153
|
-
return
|
|
142
|
+
const name = input.name ?? "demo-job";
|
|
143
|
+
return ctx.plugins.demo.enqueueJob(name, input.data || {}, input.delay);
|
|
154
144
|
},
|
|
155
145
|
})
|
|
156
146
|
);
|
|
@@ -161,22 +151,15 @@ demo.route("jobs.stats").typed(
|
|
|
161
151
|
pending: z.number(),
|
|
162
152
|
running: z.number(),
|
|
163
153
|
completed: z.number(),
|
|
164
|
-
failed: z.number(),
|
|
165
154
|
}),
|
|
166
155
|
handle: async (_, ctx) => {
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
pending: stats.pending,
|
|
170
|
-
running: stats.processing,
|
|
171
|
-
completed: stats.completed,
|
|
172
|
-
failed: stats.failed,
|
|
173
|
-
};
|
|
156
|
+
return ctx.plugins.demo.getJobStats();
|
|
174
157
|
},
|
|
175
158
|
})
|
|
176
159
|
);
|
|
177
160
|
|
|
178
161
|
// =============================================================================
|
|
179
|
-
// EVENTS - Pub/sub system
|
|
162
|
+
// EVENTS - Pub/sub system (via plugin service)
|
|
180
163
|
// =============================================================================
|
|
181
164
|
|
|
182
165
|
demo.route("events.emit").typed(
|
|
@@ -187,14 +170,13 @@ demo.route("events.emit").typed(
|
|
|
187
170
|
}),
|
|
188
171
|
output: z.object({ success: z.boolean() }),
|
|
189
172
|
handle: async (input, ctx) => {
|
|
190
|
-
|
|
191
|
-
return { success: true };
|
|
173
|
+
return ctx.plugins.demo.emitEvent(input.event, input.data || {});
|
|
192
174
|
},
|
|
193
175
|
})
|
|
194
176
|
);
|
|
195
177
|
|
|
196
178
|
// =============================================================================
|
|
197
|
-
// RATE LIMITING
|
|
179
|
+
// RATE LIMITING (via plugin service)
|
|
198
180
|
// =============================================================================
|
|
199
181
|
|
|
200
182
|
demo.route("ratelimit.check").typed(
|
|
@@ -207,15 +189,13 @@ demo.route("ratelimit.check").typed(
|
|
|
207
189
|
output: z.object({
|
|
208
190
|
allowed: z.boolean(),
|
|
209
191
|
remaining: z.number(),
|
|
210
|
-
|
|
192
|
+
limit: z.number(),
|
|
193
|
+
resetAt: z.date(),
|
|
211
194
|
}),
|
|
212
195
|
handle: async (input, ctx) => {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
remaining: result.remaining,
|
|
217
|
-
resetAt: new Date(result.resetAt).toISOString(),
|
|
218
|
-
};
|
|
196
|
+
const limit = input.limit ?? 10;
|
|
197
|
+
const window = input.window ?? 60;
|
|
198
|
+
return ctx.plugins.demo.checkRateLimit(input.key, limit, window * 1000);
|
|
219
199
|
},
|
|
220
200
|
})
|
|
221
201
|
);
|
|
@@ -225,14 +205,13 @@ demo.route("ratelimit.reset").typed(
|
|
|
225
205
|
input: z.object({ key: z.string() }),
|
|
226
206
|
output: z.object({ success: z.boolean() }),
|
|
227
207
|
handle: async (input, ctx) => {
|
|
228
|
-
ctx.
|
|
229
|
-
return { success: true };
|
|
208
|
+
return ctx.plugins.demo.resetRateLimit(input.key);
|
|
230
209
|
},
|
|
231
210
|
})
|
|
232
211
|
);
|
|
233
212
|
|
|
234
213
|
// =============================================================================
|
|
235
|
-
// CRON - Scheduled tasks info
|
|
214
|
+
// CRON - Scheduled tasks info (via plugin service)
|
|
236
215
|
// =============================================================================
|
|
237
216
|
|
|
238
217
|
demo.route("cron.list").typed(
|
|
@@ -250,17 +229,7 @@ demo.route("cron.list").typed(
|
|
|
250
229
|
),
|
|
251
230
|
}),
|
|
252
231
|
handle: async (_, ctx) => {
|
|
253
|
-
|
|
254
|
-
return {
|
|
255
|
-
tasks: jobs.map((j, i) => ({
|
|
256
|
-
id: `cron-${i}`,
|
|
257
|
-
name: j.name,
|
|
258
|
-
expression: j.schedule,
|
|
259
|
-
enabled: true,
|
|
260
|
-
lastRun: j.lastRun?.toISOString(),
|
|
261
|
-
nextRun: j.nextRun?.toISOString(),
|
|
262
|
-
})),
|
|
263
|
-
};
|
|
232
|
+
return { tasks: ctx.plugins.demo.getCronTasks() };
|
|
264
233
|
},
|
|
265
234
|
})
|
|
266
235
|
);
|