@questpie/elysia 0.0.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/src/server.ts ADDED
@@ -0,0 +1,93 @@
1
+ import { Elysia } from "elysia";
2
+ import { createFetchHandler, type Questpie } from "questpie";
3
+
4
+ /**
5
+ * Context stored in Elysia decorator
6
+ */
7
+ export type QuestpieContext = {
8
+ cms: Questpie<any>;
9
+ cmsContext: Awaited<ReturnType<Questpie<any>["createContext"]>>;
10
+ user: any;
11
+ };
12
+
13
+ /**
14
+ * Elysia adapter configuration
15
+ */
16
+ export type ElysiaAdapterConfig = {
17
+ /**
18
+ * Base path for CMS routes
19
+ * Use '/cms' for server-only apps or '/api/cms' for fullstack apps.
20
+ * @default '/cms'
21
+ */
22
+ basePath?: string;
23
+ };
24
+
25
+ /**
26
+ * Create Elysia app with QUESTPIE CMS integration
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { Elysia } from 'elysia'
31
+ * import { questpieElysia } from '@questpie/elysia'
32
+ * import { cms } from './cms'
33
+ *
34
+ * const app = new Elysia()
35
+ * .use(questpieElysia(cms))
36
+ *
37
+ * export default app
38
+ * export type App = typeof app
39
+ * ```
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * // With custom config
44
+ * const app = new Elysia()
45
+ * .use(questpieElysia(cms, {
46
+ * basePath: '/cms-api',
47
+ * cors: {
48
+ * origin: 'https://example.com',
49
+ * credentials: true
50
+ * }
51
+ * }))
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * // Client usage with Eden Treaty
57
+ * import { treaty } from '@elysiajs/eden'
58
+ * import type { App } from './server'
59
+ *
60
+ * const client = treaty<App>('localhost:3000')
61
+ *
62
+ * // Fully type-safe!
63
+ * const posts = await client.cms.posts.get()
64
+ * const post = await client.cms.posts({ id: '123' }).get()
65
+ * const newPost = await client.cms.posts.post({ title: 'Hello' })
66
+ * ```
67
+ */
68
+ export function questpieElysia(
69
+ cms: Questpie<any>,
70
+ config: ElysiaAdapterConfig = {},
71
+ ) {
72
+ const basePath = config.basePath || "/cms";
73
+ const handler = createFetchHandler(cms, {
74
+ basePath,
75
+ accessMode: "user",
76
+ });
77
+
78
+ const app = new Elysia({ prefix: basePath, name: "questpie-cms" }).all(
79
+ "/*",
80
+ async ({ request }) => {
81
+ const response = await handler(request);
82
+ return (
83
+ response ??
84
+ new Response(JSON.stringify({ error: "Not found" }), {
85
+ status: 404,
86
+ headers: { "Content-Type": "application/json" },
87
+ })
88
+ );
89
+ },
90
+ );
91
+
92
+ return app;
93
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "@questpie/typescript-config/bun.json",
3
+ "include": ["src/**/*"],
4
+ "exclude": ["node_modules", "dist"]
5
+ }