@btst/stack 1.7.0 → 1.8.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.
Files changed (67) hide show
  1. package/dist/api/index.d.cts +2 -2
  2. package/dist/api/index.d.mts +2 -2
  3. package/dist/api/index.d.ts +2 -2
  4. package/dist/client/index.cjs +6 -2
  5. package/dist/client/index.d.cts +2 -1
  6. package/dist/client/index.d.mts +2 -1
  7. package/dist/client/index.d.ts +2 -1
  8. package/dist/client/index.mjs +6 -2
  9. package/dist/index.d.cts +1 -1
  10. package/dist/index.d.mts +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/packages/better-stack/src/plugins/route-docs/client/components/loading/docs-skeleton.cjs +43 -0
  13. package/dist/packages/better-stack/src/plugins/route-docs/client/components/loading/docs-skeleton.mjs +41 -0
  14. package/dist/packages/better-stack/src/plugins/route-docs/client/components/pages/docs-page.cjs +794 -0
  15. package/dist/packages/better-stack/src/plugins/route-docs/client/components/pages/docs-page.mjs +788 -0
  16. package/dist/packages/better-stack/src/plugins/route-docs/client/plugin.cjs +111 -0
  17. package/dist/packages/better-stack/src/plugins/route-docs/client/plugin.mjs +106 -0
  18. package/dist/packages/better-stack/src/plugins/route-docs/generator.cjs +244 -0
  19. package/dist/packages/better-stack/src/plugins/route-docs/generator.mjs +227 -0
  20. package/dist/packages/ui/src/components/sheet.cjs +25 -0
  21. package/dist/packages/ui/src/components/sheet.mjs +24 -1
  22. package/dist/plugins/api/index.d.cts +2 -2
  23. package/dist/plugins/api/index.d.mts +2 -2
  24. package/dist/plugins/api/index.d.ts +2 -2
  25. package/dist/plugins/blog/api/index.d.cts +1 -1
  26. package/dist/plugins/blog/api/index.d.mts +1 -1
  27. package/dist/plugins/blog/api/index.d.ts +1 -1
  28. package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
  29. package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
  30. package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
  31. package/dist/plugins/blog/client/index.d.cts +1 -1
  32. package/dist/plugins/blog/client/index.d.mts +1 -1
  33. package/dist/plugins/blog/client/index.d.ts +1 -1
  34. package/dist/plugins/blog/query-keys.d.cts +2 -2
  35. package/dist/plugins/blog/query-keys.d.mts +2 -2
  36. package/dist/plugins/blog/query-keys.d.ts +2 -2
  37. package/dist/plugins/client/index.d.cts +2 -2
  38. package/dist/plugins/client/index.d.mts +2 -2
  39. package/dist/plugins/client/index.d.ts +2 -2
  40. package/dist/plugins/open-api/api/index.d.cts +1 -1
  41. package/dist/plugins/open-api/api/index.d.mts +1 -1
  42. package/dist/plugins/open-api/api/index.d.ts +1 -1
  43. package/dist/plugins/route-docs/client/index.cjs +10 -0
  44. package/dist/plugins/route-docs/client/index.d.cts +126 -0
  45. package/dist/plugins/route-docs/client/index.d.mts +126 -0
  46. package/dist/plugins/route-docs/client/index.d.ts +126 -0
  47. package/dist/plugins/route-docs/client/index.mjs +1 -0
  48. package/dist/plugins/route-docs/client.css +3 -0
  49. package/dist/plugins/route-docs/style.css +19 -0
  50. package/dist/shared/{stack.CSce37mX.d.cts → stack.u9iYV6vt.d.cts} +14 -2
  51. package/dist/shared/{stack.CSce37mX.d.mts → stack.u9iYV6vt.d.mts} +14 -2
  52. package/dist/shared/{stack.CSce37mX.d.ts → stack.u9iYV6vt.d.ts} +14 -2
  53. package/package.json +15 -1
  54. package/src/client/index.ts +11 -4
  55. package/src/plugins/route-docs/client/components/loading/docs-skeleton.tsx +82 -0
  56. package/src/plugins/route-docs/client/components/loading/index.tsx +1 -0
  57. package/src/plugins/route-docs/client/components/pages/docs-page.tsx +1240 -0
  58. package/src/plugins/route-docs/client/index.ts +7 -0
  59. package/src/plugins/route-docs/client/plugin.tsx +187 -0
  60. package/src/plugins/route-docs/client.css +3 -0
  61. package/src/plugins/route-docs/generator.ts +385 -0
  62. package/src/plugins/route-docs/index.ts +12 -0
  63. package/src/plugins/route-docs/style.css +19 -0
  64. package/src/types.ts +19 -1
  65. package/dist/shared/{stack.CcI4sYJP.d.mts → stack.DLhzx1-D.d.cts} +1 -1
  66. package/dist/shared/{stack.CcI4sYJP.d.ts → stack.DLhzx1-D.d.mts} +1 -1
  67. package/dist/shared/{stack.CcI4sYJP.d.cts → stack.DLhzx1-D.d.ts} +1 -1
@@ -0,0 +1,126 @@
1
+ import * as _btst_stack_plugins_client from '@btst/stack/plugins/client';
2
+ import * as react from 'react';
3
+ import * as _btst_yar from '@btst/yar';
4
+ import { QueryClient } from '@tanstack/react-query';
5
+ import { S as SitemapEntry, b as ClientStackContext } from '../../../shared/stack.u9iYV6vt.js';
6
+ import '@btst/db';
7
+ import 'better-call';
8
+
9
+ /**
10
+ * Represents a documented route parameter
11
+ */
12
+ interface RouteParameter {
13
+ name: string;
14
+ type: string;
15
+ required: boolean;
16
+ description?: string;
17
+ schema?: Record<string, any>;
18
+ }
19
+ /**
20
+ * Sitemap entry with plugin source
21
+ */
22
+ interface PluginSitemapEntry extends SitemapEntry {
23
+ pluginKey: string;
24
+ }
25
+ /**
26
+ * Represents a documented route
27
+ */
28
+ interface DocumentedRoute {
29
+ /** Route key from the plugin */
30
+ key: string;
31
+ /** The route path pattern (e.g., "/users/:id") */
32
+ path: string;
33
+ /** Path parameters extracted from the path */
34
+ pathParams: RouteParameter[];
35
+ /** Query parameters from the route's query schema */
36
+ queryParams: RouteParameter[];
37
+ /** Route metadata */
38
+ meta?: {
39
+ title?: string;
40
+ description?: string;
41
+ tags?: string[];
42
+ [key: string]: any;
43
+ };
44
+ }
45
+ /**
46
+ * Represents a plugin's documented routes
47
+ */
48
+ interface DocumentedPlugin {
49
+ /** Plugin key */
50
+ key: string;
51
+ /** Plugin name */
52
+ name: string;
53
+ /** Routes from this plugin */
54
+ routes: DocumentedRoute[];
55
+ /** Sitemap entries from this plugin */
56
+ sitemapEntries: PluginSitemapEntry[];
57
+ }
58
+ /**
59
+ * The complete route documentation schema
60
+ */
61
+ interface RouteDocsSchema {
62
+ /** All documented plugins */
63
+ plugins: DocumentedPlugin[];
64
+ /** Generation timestamp */
65
+ generatedAt: string;
66
+ /** All sitemap entries aggregated */
67
+ allSitemapEntries: PluginSitemapEntry[];
68
+ }
69
+
70
+ /**
71
+ * Query key for route docs schema
72
+ */
73
+ declare const ROUTE_DOCS_QUERY_KEY: readonly ["route-docs", "schema"];
74
+ /**
75
+ * Get the stored client stack context
76
+ * Used by the docs page component to generate schema on client-side navigation
77
+ */
78
+ declare function getStoredContext(): ClientStackContext | null;
79
+ /**
80
+ * Generate the route docs schema from the stored context
81
+ * This can be called from both server and client
82
+ */
83
+ declare function generateSchema(): Promise<RouteDocsSchema>;
84
+ /**
85
+ * Configuration for Route Docs client plugin
86
+ */
87
+ interface RouteDocsClientConfig {
88
+ /** React Query client for SSR prefetching */
89
+ queryClient: QueryClient;
90
+ /** Title for the documentation page */
91
+ title?: string;
92
+ /** Description for the documentation page */
93
+ description?: string;
94
+ /** Site base path for constructing URLs (e.g., "/pages") */
95
+ siteBasePath: string;
96
+ }
97
+ /**
98
+ * Route Docs client plugin
99
+ * Provides a route that displays documentation for all client routes
100
+ */
101
+ declare const routeDocsClientPlugin: (config: RouteDocsClientConfig) => _btst_stack_plugins_client.ClientPlugin<Record<string, never>, {
102
+ docs: {
103
+ (inputCtx_0?: _btst_yar.InputContext<"/route-docs", _btst_yar.RouteOptions> | undefined): {
104
+ PageComponent?: react.ComponentType<unknown> | undefined;
105
+ LoadingComponent?: react.ComponentType<unknown> | undefined;
106
+ ErrorComponent?: react.ComponentType<unknown> | undefined;
107
+ loader?: (() => Promise<void>) | undefined;
108
+ meta?: (() => ({
109
+ title: string;
110
+ name?: undefined;
111
+ content?: undefined;
112
+ } | {
113
+ name: string;
114
+ content: string;
115
+ title?: undefined;
116
+ })[]) | undefined;
117
+ extra?: (() => any) | undefined;
118
+ };
119
+ options: _btst_yar.RouteOptions | undefined;
120
+ path: "/route-docs";
121
+ meta: _btst_yar.RouteMeta | undefined;
122
+ };
123
+ }>;
124
+
125
+ export { ROUTE_DOCS_QUERY_KEY, generateSchema, getStoredContext, routeDocsClientPlugin };
126
+ export type { RouteDocsClientConfig };
@@ -0,0 +1 @@
1
+ export { ROUTE_DOCS_QUERY_KEY, generateSchema, getStoredContext, routeDocsClientPlugin } from '../../../packages/better-stack/src/plugins/route-docs/client/plugin.mjs';
@@ -0,0 +1,3 @@
1
+ /* Route Docs Plugin Client CSS */
2
+ /* No custom styles needed - uses shadcn/ui components and Tailwind */
3
+
@@ -0,0 +1,19 @@
1
+ @import "./client.css";
2
+
3
+ /*
4
+ * Route Docs Plugin CSS - Includes Tailwind class scanning
5
+ *
6
+ * When consumed from npm, Tailwind v4 will automatically scan this package's
7
+ * source files for Tailwind classes. Consumers only need:
8
+ * @import "@btst/stack/plugins/route-docs/css";
9
+ */
10
+
11
+ /* Scan this package's source files for Tailwind classes */
12
+ @source "../../../src/**/*.{ts,tsx}";
13
+
14
+ /* Scan UI package components (when installed as npm package the UI package will be in this dir) */
15
+ @source "../../packages/ui/src";
16
+
17
+ /*
18
+ * alternatively consumer can use @source "../node_modules/@btst/stack/src/**\/*.{ts,tsx}";
19
+ */
@@ -14,6 +14,16 @@ interface BetterStackContext {
14
14
  /** The database adapter */
15
15
  adapter: Adapter;
16
16
  }
17
+ /**
18
+ * Context passed to client plugins during route creation
19
+ * Provides access to all registered plugins for introspection (used by routeDocs plugin)
20
+ */
21
+ interface ClientStackContext<TPlugins extends Record<string, ClientPlugin<any, any>> = Record<string, ClientPlugin<any, any>>> {
22
+ /** All registered client plugins */
23
+ plugins: TPlugins;
24
+ /** The base path for the client (e.g., "/app") */
25
+ basePath?: string;
26
+ }
17
27
  /**
18
28
  * Backend plugin definition
19
29
  * Defines API routes and data access for a feature
@@ -50,8 +60,10 @@ interface ClientPlugin<TOverrides = Record<string, never>, TRoutes extends Recor
50
60
  /**
51
61
  * Define routes (pages) for this plugin
52
62
  * Returns yar routes that will be composed into the router
63
+ *
64
+ * @param context - Optional context with access to all plugins (for introspection)
53
65
  */
54
- routes: () => TRoutes;
66
+ routes: (context?: ClientStackContext) => TRoutes;
55
67
  /**
56
68
  * Optional sitemap generator for this plugin. Should return absolute URLs.
57
69
  * Implementations can call their own API endpoints to include dynamic routes.
@@ -142,4 +154,4 @@ type SitemapEntry = {
142
154
  };
143
155
  type Sitemap = Array<SitemapEntry>;
144
156
 
145
- export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, Sitemap as S, BetterStackContext as a, PluginRoutes as b, ClientLibConfig as c, ClientLib as d, PrefixedPluginRoutes as e, BackendLibConfig as f, BackendLib as g };
157
+ export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, SitemapEntry as S, BetterStackContext as a, ClientStackContext as b, Sitemap as c, PluginRoutes as d, ClientLibConfig as e, ClientLib as f, PrefixedPluginRoutes as g, BackendLibConfig as h, BackendLib as i };
@@ -14,6 +14,16 @@ interface BetterStackContext {
14
14
  /** The database adapter */
15
15
  adapter: Adapter;
16
16
  }
17
+ /**
18
+ * Context passed to client plugins during route creation
19
+ * Provides access to all registered plugins for introspection (used by routeDocs plugin)
20
+ */
21
+ interface ClientStackContext<TPlugins extends Record<string, ClientPlugin<any, any>> = Record<string, ClientPlugin<any, any>>> {
22
+ /** All registered client plugins */
23
+ plugins: TPlugins;
24
+ /** The base path for the client (e.g., "/app") */
25
+ basePath?: string;
26
+ }
17
27
  /**
18
28
  * Backend plugin definition
19
29
  * Defines API routes and data access for a feature
@@ -50,8 +60,10 @@ interface ClientPlugin<TOverrides = Record<string, never>, TRoutes extends Recor
50
60
  /**
51
61
  * Define routes (pages) for this plugin
52
62
  * Returns yar routes that will be composed into the router
63
+ *
64
+ * @param context - Optional context with access to all plugins (for introspection)
53
65
  */
54
- routes: () => TRoutes;
66
+ routes: (context?: ClientStackContext) => TRoutes;
55
67
  /**
56
68
  * Optional sitemap generator for this plugin. Should return absolute URLs.
57
69
  * Implementations can call their own API endpoints to include dynamic routes.
@@ -142,4 +154,4 @@ type SitemapEntry = {
142
154
  };
143
155
  type Sitemap = Array<SitemapEntry>;
144
156
 
145
- export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, Sitemap as S, BetterStackContext as a, PluginRoutes as b, ClientLibConfig as c, ClientLib as d, PrefixedPluginRoutes as e, BackendLibConfig as f, BackendLib as g };
157
+ export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, SitemapEntry as S, BetterStackContext as a, ClientStackContext as b, Sitemap as c, PluginRoutes as d, ClientLibConfig as e, ClientLib as f, PrefixedPluginRoutes as g, BackendLibConfig as h, BackendLib as i };
@@ -14,6 +14,16 @@ interface BetterStackContext {
14
14
  /** The database adapter */
15
15
  adapter: Adapter;
16
16
  }
17
+ /**
18
+ * Context passed to client plugins during route creation
19
+ * Provides access to all registered plugins for introspection (used by routeDocs plugin)
20
+ */
21
+ interface ClientStackContext<TPlugins extends Record<string, ClientPlugin<any, any>> = Record<string, ClientPlugin<any, any>>> {
22
+ /** All registered client plugins */
23
+ plugins: TPlugins;
24
+ /** The base path for the client (e.g., "/app") */
25
+ basePath?: string;
26
+ }
17
27
  /**
18
28
  * Backend plugin definition
19
29
  * Defines API routes and data access for a feature
@@ -50,8 +60,10 @@ interface ClientPlugin<TOverrides = Record<string, never>, TRoutes extends Recor
50
60
  /**
51
61
  * Define routes (pages) for this plugin
52
62
  * Returns yar routes that will be composed into the router
63
+ *
64
+ * @param context - Optional context with access to all plugins (for introspection)
53
65
  */
54
- routes: () => TRoutes;
66
+ routes: (context?: ClientStackContext) => TRoutes;
55
67
  /**
56
68
  * Optional sitemap generator for this plugin. Should return absolute URLs.
57
69
  * Implementations can call their own API endpoints to include dynamic routes.
@@ -142,4 +154,4 @@ type SitemapEntry = {
142
154
  };
143
155
  type Sitemap = Array<SitemapEntry>;
144
156
 
145
- export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, Sitemap as S, BetterStackContext as a, PluginRoutes as b, ClientLibConfig as c, ClientLib as d, PrefixedPluginRoutes as e, BackendLibConfig as f, BackendLib as g };
157
+ export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, SitemapEntry as S, BetterStackContext as a, ClientStackContext as b, Sitemap as c, PluginRoutes as d, ClientLibConfig as e, ClientLib as f, PrefixedPluginRoutes as g, BackendLibConfig as h, BackendLib as i };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btst/stack",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "A composable, plugin-based library for building full-stack applications.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -257,6 +257,17 @@
257
257
  "default": "./dist/plugins/open-api/api/index.cjs"
258
258
  }
259
259
  },
260
+ "./plugins/route-docs/client": {
261
+ "import": {
262
+ "types": "./dist/plugins/route-docs/client/index.d.ts",
263
+ "default": "./dist/plugins/route-docs/client/index.mjs"
264
+ },
265
+ "require": {
266
+ "types": "./dist/plugins/route-docs/client/index.d.cts",
267
+ "default": "./dist/plugins/route-docs/client/index.cjs"
268
+ }
269
+ },
270
+ "./plugins/route-docs/css": "./dist/plugins/route-docs/style.css",
260
271
  "./dist/*": "./dist/*",
261
272
  "./ui/css": "./dist/ui/components.css",
262
273
  "./package.json": "./package.json"
@@ -325,6 +336,9 @@
325
336
  ],
326
337
  "plugins/open-api/api": [
327
338
  "./dist/plugins/open-api/api/index.d.ts"
339
+ ],
340
+ "plugins/route-docs/client": [
341
+ "./dist/plugins/route-docs/client/index.d.ts"
328
342
  ]
329
343
  }
330
344
  },
@@ -4,10 +4,11 @@ import type {
4
4
  ClientLibConfig,
5
5
  ClientLib,
6
6
  ClientPlugin,
7
+ ClientStackContext,
7
8
  PluginRoutes,
8
9
  Sitemap,
9
10
  } from "../types";
10
- export type { ClientPlugin } from "../types";
11
+ export type { ClientPlugin, ClientStackContext } from "../types";
11
12
 
12
13
  /**
13
14
  * Creates the client library with plugin support
@@ -60,15 +61,21 @@ export function createStackClient<
60
61
  TPlugins extends Record<string, ClientPlugin<any, any>>,
61
62
  TRoutes extends PluginRoutes<TPlugins> = PluginRoutes<TPlugins>,
62
63
  >(config: ClientLibConfig<TPlugins>): ClientLib<TRoutes> {
63
- const { plugins } = config;
64
+ const { plugins, basePath } = config;
64
65
 
65
66
  // Collect all routes from all plugins
66
67
  // We build this with type assertions to preserve literal keys
67
68
  const allRoutes = {} as TRoutes;
68
69
 
70
+ // Create the context object to pass to plugin routes
71
+ const clientStackContext: ClientStackContext<TPlugins> = {
72
+ plugins,
73
+ basePath,
74
+ };
75
+
69
76
  for (const [pluginKey, plugin] of Object.entries(plugins)) {
70
- // Add routes
71
- const pluginRoutes = plugin.routes();
77
+ // Add routes - pass the context for plugins that need introspection (e.g., routeDocs)
78
+ const pluginRoutes = plugin.routes(clientStackContext);
72
79
  Object.assign(allRoutes, pluginRoutes);
73
80
  }
74
81
 
@@ -0,0 +1,82 @@
1
+ "use client";
2
+
3
+ import { Skeleton } from "@workspace/ui/components/skeleton";
4
+ import { ScrollArea } from "@workspace/ui/components/scroll-area";
5
+ import { Card, CardContent } from "@workspace/ui/components/card";
6
+
7
+ export function DocsPageSkeleton() {
8
+ return (
9
+ <div className="flex min-h-screen bg-background">
10
+ {/* Desktop Sidebar skeleton */}
11
+ <aside className="hidden md:block w-72 border-r bg-card shrink-0">
12
+ <div className="p-4 border-b">
13
+ <Skeleton className="h-4 w-16" />
14
+ </div>
15
+ <ScrollArea className="h-[calc(100vh-57px)]">
16
+ <div className="p-3 space-y-4">
17
+ {/* Plugin groups */}
18
+ {[1, 2, 3].map((i) => (
19
+ <div key={i} className="space-y-2">
20
+ <Skeleton className="h-8 w-full" />
21
+ <div className="ml-2 space-y-1">
22
+ {[1, 2, 3].map((j) => (
23
+ <Skeleton key={j} className="h-7 w-full" />
24
+ ))}
25
+ </div>
26
+ </div>
27
+ ))}
28
+ </div>
29
+ </ScrollArea>
30
+ </aside>
31
+
32
+ {/* Mobile header skeleton */}
33
+ <div className="md:hidden fixed top-0 left-0 right-0 z-40 bg-card border-b">
34
+ <div className="flex items-center justify-between p-4">
35
+ <Skeleton className="h-4 w-24" />
36
+ <Skeleton className="h-8 w-20" />
37
+ </div>
38
+ </div>
39
+
40
+ {/* Main content skeleton */}
41
+ <main className="flex-1 overflow-auto pt-16 md:pt-0">
42
+ <div className="max-w-4xl mx-auto p-4 sm:p-6 lg:p-8 space-y-4 sm:space-y-6">
43
+ {/* Title */}
44
+ <div className="space-y-2">
45
+ <Skeleton className="h-8 sm:h-9 w-48 sm:w-64" />
46
+ <Skeleton className="h-4 sm:h-5 w-72 sm:w-96" />
47
+ </div>
48
+
49
+ {/* Separator */}
50
+ <div className="h-px bg-border" />
51
+
52
+ {/* Badges */}
53
+ <div className="flex gap-2">
54
+ <Skeleton className="h-6 w-24" />
55
+ <Skeleton className="h-6 w-20" />
56
+ </div>
57
+
58
+ {/* Routes card */}
59
+ <Card>
60
+ <div className="p-4 sm:p-6">
61
+ <Skeleton className="h-6 w-32 mb-4" />
62
+ </div>
63
+ <CardContent className="pt-0 space-y-4">
64
+ {/* Desktop table skeleton */}
65
+ <div className="hidden md:block space-y-2">
66
+ {[1, 2, 3, 4].map((i) => (
67
+ <Skeleton key={i} className="h-12 w-full" />
68
+ ))}
69
+ </div>
70
+ {/* Mobile cards skeleton */}
71
+ <div className="md:hidden space-y-3">
72
+ {[1, 2, 3].map((i) => (
73
+ <Skeleton key={i} className="h-28 w-full rounded-lg" />
74
+ ))}
75
+ </div>
76
+ </CardContent>
77
+ </Card>
78
+ </div>
79
+ </main>
80
+ </div>
81
+ );
82
+ }
@@ -0,0 +1 @@
1
+ export { DocsPageSkeleton } from "./docs-skeleton";