@btst/stack 1.6.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 (85) hide show
  1. package/dist/api/index.cjs +7 -1
  2. package/dist/api/index.d.cts +2 -2
  3. package/dist/api/index.d.mts +2 -2
  4. package/dist/api/index.d.ts +2 -2
  5. package/dist/api/index.mjs +7 -1
  6. package/dist/client/index.cjs +6 -2
  7. package/dist/client/index.d.cts +2 -1
  8. package/dist/client/index.d.mts +2 -1
  9. package/dist/client/index.d.ts +2 -1
  10. package/dist/client/index.mjs +6 -2
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/packages/better-stack/src/plugins/open-api/api/generator.cjs +300 -0
  15. package/dist/packages/better-stack/src/plugins/open-api/api/generator.mjs +284 -0
  16. package/dist/packages/better-stack/src/plugins/open-api/api/plugin.cjs +115 -0
  17. package/dist/packages/better-stack/src/plugins/open-api/api/plugin.mjs +113 -0
  18. package/dist/packages/better-stack/src/plugins/open-api/db.cjs +7 -0
  19. package/dist/packages/better-stack/src/plugins/open-api/db.mjs +5 -0
  20. package/dist/packages/better-stack/src/plugins/open-api/logo.cjs +8 -0
  21. package/dist/packages/better-stack/src/plugins/open-api/logo.mjs +6 -0
  22. package/dist/packages/better-stack/src/plugins/route-docs/client/components/loading/docs-skeleton.cjs +43 -0
  23. package/dist/packages/better-stack/src/plugins/route-docs/client/components/loading/docs-skeleton.mjs +41 -0
  24. package/dist/packages/better-stack/src/plugins/route-docs/client/components/pages/docs-page.cjs +794 -0
  25. package/dist/packages/better-stack/src/plugins/route-docs/client/components/pages/docs-page.mjs +788 -0
  26. package/dist/packages/better-stack/src/plugins/route-docs/client/plugin.cjs +111 -0
  27. package/dist/packages/better-stack/src/plugins/route-docs/client/plugin.mjs +106 -0
  28. package/dist/packages/better-stack/src/plugins/route-docs/generator.cjs +244 -0
  29. package/dist/packages/better-stack/src/plugins/route-docs/generator.mjs +227 -0
  30. package/dist/packages/ui/src/components/sheet.cjs +25 -0
  31. package/dist/packages/ui/src/components/sheet.mjs +24 -1
  32. package/dist/plugins/api/index.d.cts +2 -2
  33. package/dist/plugins/api/index.d.mts +2 -2
  34. package/dist/plugins/api/index.d.ts +2 -2
  35. package/dist/plugins/blog/api/index.d.cts +1 -1
  36. package/dist/plugins/blog/api/index.d.mts +1 -1
  37. package/dist/plugins/blog/api/index.d.ts +1 -1
  38. package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
  39. package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
  40. package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
  41. package/dist/plugins/blog/client/index.d.cts +1 -1
  42. package/dist/plugins/blog/client/index.d.mts +1 -1
  43. package/dist/plugins/blog/client/index.d.ts +1 -1
  44. package/dist/plugins/blog/query-keys.d.cts +2 -2
  45. package/dist/plugins/blog/query-keys.d.mts +2 -2
  46. package/dist/plugins/blog/query-keys.d.ts +2 -2
  47. package/dist/plugins/client/index.d.cts +2 -2
  48. package/dist/plugins/client/index.d.mts +2 -2
  49. package/dist/plugins/client/index.d.ts +2 -2
  50. package/dist/plugins/open-api/api/index.cjs +9 -0
  51. package/dist/plugins/open-api/api/index.d.cts +95 -0
  52. package/dist/plugins/open-api/api/index.d.mts +95 -0
  53. package/dist/plugins/open-api/api/index.d.ts +95 -0
  54. package/dist/plugins/open-api/api/index.mjs +2 -0
  55. package/dist/plugins/route-docs/client/index.cjs +10 -0
  56. package/dist/plugins/route-docs/client/index.d.cts +126 -0
  57. package/dist/plugins/route-docs/client/index.d.mts +126 -0
  58. package/dist/plugins/route-docs/client/index.d.ts +126 -0
  59. package/dist/plugins/route-docs/client/index.mjs +1 -0
  60. package/dist/plugins/route-docs/client.css +3 -0
  61. package/dist/plugins/route-docs/style.css +19 -0
  62. package/dist/shared/{stack.ByOugz9d.d.cts → stack.u9iYV6vt.d.cts} +28 -3
  63. package/dist/shared/{stack.ByOugz9d.d.mts → stack.u9iYV6vt.d.mts} +28 -3
  64. package/dist/shared/{stack.ByOugz9d.d.ts → stack.u9iYV6vt.d.ts} +28 -3
  65. package/package.json +28 -1
  66. package/src/api/index.ts +14 -2
  67. package/src/client/index.ts +11 -4
  68. package/src/plugins/open-api/api/generator.ts +433 -0
  69. package/src/plugins/open-api/api/index.ts +8 -0
  70. package/src/plugins/open-api/api/plugin.ts +243 -0
  71. package/src/plugins/open-api/db.ts +7 -0
  72. package/src/plugins/open-api/logo.ts +7 -0
  73. package/src/plugins/route-docs/client/components/loading/docs-skeleton.tsx +82 -0
  74. package/src/plugins/route-docs/client/components/loading/index.tsx +1 -0
  75. package/src/plugins/route-docs/client/components/pages/docs-page.tsx +1240 -0
  76. package/src/plugins/route-docs/client/index.ts +7 -0
  77. package/src/plugins/route-docs/client/plugin.tsx +187 -0
  78. package/src/plugins/route-docs/client.css +3 -0
  79. package/src/plugins/route-docs/generator.ts +385 -0
  80. package/src/plugins/route-docs/index.ts +12 -0
  81. package/src/plugins/route-docs/style.css +19 -0
  82. package/src/types.ts +34 -2
  83. package/dist/shared/{stack.CcI4sYJP.d.mts → stack.DLhzx1-D.d.cts} +1 -1
  84. package/dist/shared/{stack.CcI4sYJP.d.ts → stack.DLhzx1-D.d.mts} +1 -1
  85. 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.cjs';
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,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.mjs';
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,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
+ */
@@ -2,6 +2,28 @@ import { Route, createRouter } from '@btst/yar';
2
2
  import { Adapter, DbPlugin, DatabaseDefinition } from '@btst/db';
3
3
  import { Endpoint, Router } from 'better-call';
4
4
 
5
+ /**
6
+ * Context passed to backend plugins during route creation
7
+ * Provides access to all registered plugins for introspection (used by openAPI plugin)
8
+ */
9
+ interface BetterStackContext {
10
+ /** All registered backend plugins */
11
+ plugins: Record<string, BackendPlugin<any>>;
12
+ /** The API base path (e.g., "/api/data") */
13
+ basePath: string;
14
+ /** The database adapter */
15
+ adapter: Adapter;
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
+ }
5
27
  /**
6
28
  * Backend plugin definition
7
29
  * Defines API routes and data access for a feature
@@ -20,8 +42,9 @@ interface BackendPlugin<TRoutes extends Record<string, Endpoint> = Record<string
20
42
  *
21
43
  * @param adapter - Better DB adapter instance with methods:
22
44
  * create, update, updateMany, delete, deleteMany, findOne, findMany, count
45
+ * @param context - Optional context with access to all plugins (for introspection)
23
46
  */
24
- routes: (adapter: Adapter) => TRoutes;
47
+ routes: (adapter: Adapter, context?: BetterStackContext) => TRoutes;
25
48
  dbPlugin: DbPlugin;
26
49
  }
27
50
  /**
@@ -37,8 +60,10 @@ interface ClientPlugin<TOverrides = Record<string, never>, TRoutes extends Recor
37
60
  /**
38
61
  * Define routes (pages) for this plugin
39
62
  * Returns yar routes that will be composed into the router
63
+ *
64
+ * @param context - Optional context with access to all plugins (for introspection)
40
65
  */
41
- routes: () => TRoutes;
66
+ routes: (context?: ClientStackContext) => TRoutes;
42
67
  /**
43
68
  * Optional sitemap generator for this plugin. Should return absolute URLs.
44
69
  * Implementations can call their own API endpoints to include dynamic routes.
@@ -129,4 +154,4 @@ type SitemapEntry = {
129
154
  };
130
155
  type Sitemap = Array<SitemapEntry>;
131
156
 
132
- export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, Sitemap as S, PluginRoutes as a, ClientLibConfig as b, ClientLib as c, PrefixedPluginRoutes as d, BackendLibConfig as e, BackendLib as f };
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 };
@@ -2,6 +2,28 @@ import { Route, createRouter } from '@btst/yar';
2
2
  import { Adapter, DbPlugin, DatabaseDefinition } from '@btst/db';
3
3
  import { Endpoint, Router } from 'better-call';
4
4
 
5
+ /**
6
+ * Context passed to backend plugins during route creation
7
+ * Provides access to all registered plugins for introspection (used by openAPI plugin)
8
+ */
9
+ interface BetterStackContext {
10
+ /** All registered backend plugins */
11
+ plugins: Record<string, BackendPlugin<any>>;
12
+ /** The API base path (e.g., "/api/data") */
13
+ basePath: string;
14
+ /** The database adapter */
15
+ adapter: Adapter;
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
+ }
5
27
  /**
6
28
  * Backend plugin definition
7
29
  * Defines API routes and data access for a feature
@@ -20,8 +42,9 @@ interface BackendPlugin<TRoutes extends Record<string, Endpoint> = Record<string
20
42
  *
21
43
  * @param adapter - Better DB adapter instance with methods:
22
44
  * create, update, updateMany, delete, deleteMany, findOne, findMany, count
45
+ * @param context - Optional context with access to all plugins (for introspection)
23
46
  */
24
- routes: (adapter: Adapter) => TRoutes;
47
+ routes: (adapter: Adapter, context?: BetterStackContext) => TRoutes;
25
48
  dbPlugin: DbPlugin;
26
49
  }
27
50
  /**
@@ -37,8 +60,10 @@ interface ClientPlugin<TOverrides = Record<string, never>, TRoutes extends Recor
37
60
  /**
38
61
  * Define routes (pages) for this plugin
39
62
  * Returns yar routes that will be composed into the router
63
+ *
64
+ * @param context - Optional context with access to all plugins (for introspection)
40
65
  */
41
- routes: () => TRoutes;
66
+ routes: (context?: ClientStackContext) => TRoutes;
42
67
  /**
43
68
  * Optional sitemap generator for this plugin. Should return absolute URLs.
44
69
  * Implementations can call their own API endpoints to include dynamic routes.
@@ -129,4 +154,4 @@ type SitemapEntry = {
129
154
  };
130
155
  type Sitemap = Array<SitemapEntry>;
131
156
 
132
- export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, Sitemap as S, PluginRoutes as a, ClientLibConfig as b, ClientLib as c, PrefixedPluginRoutes as d, BackendLibConfig as e, BackendLib as f };
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 };
@@ -2,6 +2,28 @@ import { Route, createRouter } from '@btst/yar';
2
2
  import { Adapter, DbPlugin, DatabaseDefinition } from '@btst/db';
3
3
  import { Endpoint, Router } from 'better-call';
4
4
 
5
+ /**
6
+ * Context passed to backend plugins during route creation
7
+ * Provides access to all registered plugins for introspection (used by openAPI plugin)
8
+ */
9
+ interface BetterStackContext {
10
+ /** All registered backend plugins */
11
+ plugins: Record<string, BackendPlugin<any>>;
12
+ /** The API base path (e.g., "/api/data") */
13
+ basePath: string;
14
+ /** The database adapter */
15
+ adapter: Adapter;
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
+ }
5
27
  /**
6
28
  * Backend plugin definition
7
29
  * Defines API routes and data access for a feature
@@ -20,8 +42,9 @@ interface BackendPlugin<TRoutes extends Record<string, Endpoint> = Record<string
20
42
  *
21
43
  * @param adapter - Better DB adapter instance with methods:
22
44
  * create, update, updateMany, delete, deleteMany, findOne, findMany, count
45
+ * @param context - Optional context with access to all plugins (for introspection)
23
46
  */
24
- routes: (adapter: Adapter) => TRoutes;
47
+ routes: (adapter: Adapter, context?: BetterStackContext) => TRoutes;
25
48
  dbPlugin: DbPlugin;
26
49
  }
27
50
  /**
@@ -37,8 +60,10 @@ interface ClientPlugin<TOverrides = Record<string, never>, TRoutes extends Recor
37
60
  /**
38
61
  * Define routes (pages) for this plugin
39
62
  * Returns yar routes that will be composed into the router
63
+ *
64
+ * @param context - Optional context with access to all plugins (for introspection)
40
65
  */
41
- routes: () => TRoutes;
66
+ routes: (context?: ClientStackContext) => TRoutes;
42
67
  /**
43
68
  * Optional sitemap generator for this plugin. Should return absolute URLs.
44
69
  * Implementations can call their own API endpoints to include dynamic routes.
@@ -129,4 +154,4 @@ type SitemapEntry = {
129
154
  };
130
155
  type Sitemap = Array<SitemapEntry>;
131
156
 
132
- export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, Sitemap as S, PluginRoutes as a, ClientLibConfig as b, ClientLib as c, PrefixedPluginRoutes as d, BackendLibConfig as e, BackendLib as f };
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.6.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",
@@ -247,6 +247,27 @@
247
247
  }
248
248
  },
249
249
  "./plugins/form-builder/css": "./dist/plugins/form-builder/style.css",
250
+ "./plugins/open-api/api": {
251
+ "import": {
252
+ "types": "./dist/plugins/open-api/api/index.d.ts",
253
+ "default": "./dist/plugins/open-api/api/index.mjs"
254
+ },
255
+ "require": {
256
+ "types": "./dist/plugins/open-api/api/index.d.cts",
257
+ "default": "./dist/plugins/open-api/api/index.cjs"
258
+ }
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",
250
271
  "./dist/*": "./dist/*",
251
272
  "./ui/css": "./dist/ui/components.css",
252
273
  "./package.json": "./package.json"
@@ -312,6 +333,12 @@
312
333
  ],
313
334
  "plugins/form-builder/client/hooks": [
314
335
  "./dist/plugins/form-builder/client/hooks/index.d.ts"
336
+ ],
337
+ "plugins/open-api/api": [
338
+ "./dist/plugins/open-api/api/index.d.ts"
339
+ ],
340
+ "plugins/route-docs/client": [
341
+ "./dist/plugins/route-docs/client/index.d.ts"
315
342
  ]
316
343
  }
317
344
  },
package/src/api/index.ts CHANGED
@@ -3,6 +3,7 @@ import type {
3
3
  BackendLibConfig,
4
4
  BackendLib,
5
5
  PrefixedPluginRoutes,
6
+ BetterStackContext,
6
7
  } from "../types";
7
8
  import { defineDb } from "@btst/db";
8
9
 
@@ -45,9 +46,19 @@ export function betterStack<
45
46
  betterDbSchema = betterDbSchema.use(plugin.dbPlugin);
46
47
  }
47
48
 
49
+ // Create the adapter instance once
50
+ const adapterInstance = adapter(betterDbSchema);
51
+
52
+ // Create context for plugins that need access to all plugins (e.g., openAPI)
53
+ const context: BetterStackContext = {
54
+ plugins,
55
+ basePath,
56
+ adapter: adapterInstance,
57
+ };
58
+
48
59
  for (const [pluginKey, plugin] of Object.entries(plugins)) {
49
- // Pass the adapter directly to plugin routes
50
- const pluginRoutes = plugin.routes(adapter(betterDbSchema));
60
+ // Pass both adapter and context to plugin routes
61
+ const pluginRoutes = plugin.routes(adapterInstance, context);
51
62
 
52
63
  // Prefix route keys with plugin name to avoid collisions
53
64
  for (const [routeKey, endpoint] of Object.entries(pluginRoutes)) {
@@ -72,4 +83,5 @@ export type {
72
83
  BackendPlugin,
73
84
  BackendLibConfig,
74
85
  BackendLib,
86
+ BetterStackContext,
75
87
  } from "../types";