@donkeylabs/cli 2.0.19 → 2.0.20
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 +1 -1
- package/templates/starter/donkeylabs.config.ts +1 -0
- package/templates/starter/package.json +7 -0
- package/templates/starter/src/index.ts +9 -0
- package/templates/starter/src/routes/health/handlers/ping.ts +35 -0
- package/templates/sveltekit-app/src/server/routes/counter/handlers/decrement.ts +19 -0
- package/templates/sveltekit-app/src/server/routes/counter/handlers/get.ts +19 -0
- package/templates/sveltekit-app/src/server/routes/counter/handlers/increment.ts +19 -0
- package/templates/sveltekit-app/src/server/routes/counter/index.ts +11 -0
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ServerContext } from "@donkeylabs/server";
|
|
2
|
+
|
|
3
|
+
type AppContext = ServerContext;
|
|
4
|
+
|
|
5
|
+
interface Handler<TInput = any, TOutput = any> {
|
|
6
|
+
handle(input: TInput): TOutput | Promise<TOutput>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type PingInput = {
|
|
10
|
+
name: string;
|
|
11
|
+
cool: number;
|
|
12
|
+
echo?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type PingOutput = {
|
|
16
|
+
status: "ok";
|
|
17
|
+
timestamp: string;
|
|
18
|
+
echo?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class PingHandler implements Handler {
|
|
22
|
+
ctx: AppContext;
|
|
23
|
+
|
|
24
|
+
constructor(ctx: AppContext) {
|
|
25
|
+
this.ctx = ctx;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async handle(input: PingInput): Promise<PingOutput> {
|
|
29
|
+
return {
|
|
30
|
+
status: "ok",
|
|
31
|
+
timestamp: new Date().toISOString(),
|
|
32
|
+
echo: input.echo,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ServerContext } from "@donkeylabs/server";
|
|
2
|
+
|
|
3
|
+
type AppContext = ServerContext;
|
|
4
|
+
|
|
5
|
+
interface Handler<TInput = any, TOutput = any> {
|
|
6
|
+
handle(input: TInput): TOutput | Promise<TOutput>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class CounterDecrementHandler implements Handler {
|
|
10
|
+
ctx: AppContext;
|
|
11
|
+
|
|
12
|
+
constructor(ctx: AppContext) {
|
|
13
|
+
this.ctx = ctx;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async handle(): Promise<{ count: number }> {
|
|
17
|
+
return { count: -1 };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ServerContext } from "@donkeylabs/server";
|
|
2
|
+
|
|
3
|
+
type AppContext = ServerContext;
|
|
4
|
+
|
|
5
|
+
interface Handler<TInput = any, TOutput = any> {
|
|
6
|
+
handle(input: TInput): TOutput | Promise<TOutput>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class CounterGetHandler implements Handler {
|
|
10
|
+
ctx: AppContext;
|
|
11
|
+
|
|
12
|
+
constructor(ctx: AppContext) {
|
|
13
|
+
this.ctx = ctx;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async handle(): Promise<{ count: number }> {
|
|
17
|
+
return { count: 0 };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ServerContext } from "@donkeylabs/server";
|
|
2
|
+
|
|
3
|
+
type AppContext = ServerContext;
|
|
4
|
+
|
|
5
|
+
interface Handler<TInput = any, TOutput = any> {
|
|
6
|
+
handle(input: TInput): TOutput | Promise<TOutput>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class CounterIncrementHandler implements Handler {
|
|
10
|
+
ctx: AppContext;
|
|
11
|
+
|
|
12
|
+
constructor(ctx: AppContext) {
|
|
13
|
+
this.ctx = ctx;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async handle(): Promise<{ count: number }> {
|
|
17
|
+
return { count: 1 };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRouter } from "@donkeylabs/server";
|
|
2
|
+
import { CounterGetHandler } from "./handlers/get";
|
|
3
|
+
import { CounterIncrementHandler } from "./handlers/increment";
|
|
4
|
+
import { CounterDecrementHandler } from "./handlers/decrement";
|
|
5
|
+
|
|
6
|
+
export const counterRouter = createRouter("counter")
|
|
7
|
+
.route("counter.get").typed({ handle: CounterGetHandler })
|
|
8
|
+
.route("counter.increment").typed({ handle: CounterIncrementHandler })
|
|
9
|
+
.route("counter.decrement").typed({ handle: CounterDecrementHandler });
|
|
10
|
+
|
|
11
|
+
export default counterRouter;
|