@vistagenic/vista 0.2.16 → 0.3.2

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 (153) hide show
  1. package/bin/vista.js +184 -177
  2. package/dist/ai/agent.d.ts +37 -0
  3. package/dist/ai/agent.js +385 -0
  4. package/dist/ai/embeddings.d.ts +11 -0
  5. package/dist/ai/embeddings.js +71 -0
  6. package/dist/ai/index.d.ts +10 -0
  7. package/dist/ai/index.js +26 -0
  8. package/dist/ai/memory.d.ts +16 -0
  9. package/dist/ai/memory.js +39 -0
  10. package/dist/ai/observability.d.ts +21 -0
  11. package/dist/ai/observability.js +69 -0
  12. package/dist/ai/providers/anthropic.d.ts +2 -0
  13. package/dist/ai/providers/anthropic.js +190 -0
  14. package/dist/ai/providers/base.d.ts +7 -0
  15. package/dist/ai/providers/base.js +85 -0
  16. package/dist/ai/providers/gemini.d.ts +2 -0
  17. package/dist/ai/providers/gemini.js +194 -0
  18. package/dist/ai/providers/index.d.ts +5 -0
  19. package/dist/ai/providers/index.js +21 -0
  20. package/dist/ai/providers/mock.d.ts +8 -0
  21. package/dist/ai/providers/mock.js +77 -0
  22. package/dist/ai/providers/openai.d.ts +2 -0
  23. package/dist/ai/providers/openai.js +211 -0
  24. package/dist/ai/rag.d.ts +35 -0
  25. package/dist/ai/rag.js +110 -0
  26. package/dist/ai/react/index.d.ts +1 -0
  27. package/dist/ai/react/index.js +17 -0
  28. package/dist/ai/react/react-server.d.ts +1 -0
  29. package/dist/ai/react/react-server.js +17 -0
  30. package/dist/ai/react/use-agent.d.ts +23 -0
  31. package/dist/ai/react/use-agent.js +138 -0
  32. package/dist/ai/stream.d.ts +24 -0
  33. package/dist/ai/stream.js +109 -0
  34. package/dist/ai/tool.d.ts +11 -0
  35. package/dist/ai/tool.js +47 -0
  36. package/dist/ai/types.d.ts +117 -0
  37. package/dist/ai/types.js +5 -0
  38. package/dist/auth/core.d.ts +140 -0
  39. package/dist/auth/core.js +165 -0
  40. package/dist/auth/index.d.ts +20 -8
  41. package/dist/auth/index.js +369 -16
  42. package/dist/auth/react-server.d.ts +1 -0
  43. package/dist/auth/react-server.js +10 -0
  44. package/dist/auth/react.d.ts +18 -0
  45. package/dist/auth/react.js +71 -0
  46. package/dist/bin/build-rsc.js +602 -604
  47. package/dist/bin/build.js +389 -388
  48. package/dist/bin/deploy-output.d.ts +2 -7
  49. package/dist/bin/deploy-output.js +3 -76
  50. package/dist/bin/deploy.d.ts +7 -0
  51. package/dist/bin/deploy.js +102 -0
  52. package/dist/bin/dev-error-overlay-snippet.js +778 -552
  53. package/dist/bin/devtools-indicator-snippet.js +387 -387
  54. package/dist/bin/generate.js +510 -248
  55. package/dist/build/manifest.d.ts +169 -139
  56. package/dist/build/manifest.js +423 -367
  57. package/dist/build/rsc/client-manifest.d.ts +62 -52
  58. package/dist/build/rsc/client-manifest.js +295 -193
  59. package/dist/build/rsc/client-reference-plugin.d.ts +37 -37
  60. package/dist/build/rsc/client-reference-plugin.js +160 -160
  61. package/dist/build/rsc/native-scanner.d.ts +135 -123
  62. package/dist/build/rsc/native-scanner.js +203 -170
  63. package/dist/build/rsc/react-client-reference-manifest.d.ts +28 -22
  64. package/dist/build/rsc/react-client-reference-manifest.js +240 -219
  65. package/dist/build/rsc/rsc-renderer.d.ts +99 -99
  66. package/dist/build/rsc/rsc-renderer.js +263 -263
  67. package/dist/build/rsc/server-component-loader.d.ts +19 -19
  68. package/dist/build/rsc/server-component-loader.js +91 -91
  69. package/dist/build/rsc/server-manifest.d.ts +17 -0
  70. package/dist/build/rsc/server-manifest.js +20 -0
  71. package/dist/build/standalone.js +337 -334
  72. package/dist/build/webpack/plugins/vista-flight-plugin.js +5 -5
  73. package/dist/client/dynamic.react-server.d.ts +2 -0
  74. package/dist/client/dynamic.react-server.js +23 -0
  75. package/dist/client/link.react-server.d.ts +2 -0
  76. package/dist/client/link.react-server.js +11 -0
  77. package/dist/client/navigation.react-server.d.ts +1 -0
  78. package/dist/client/navigation.react-server.js +17 -0
  79. package/dist/client/router.react-server.d.ts +1 -0
  80. package/dist/client/router.react-server.js +17 -0
  81. package/dist/client/rsc-router.react-server.d.ts +1 -0
  82. package/dist/client/rsc-router.react-server.js +17 -0
  83. package/dist/client/script.react-server.d.ts +2 -0
  84. package/dist/client/script.react-server.js +23 -0
  85. package/dist/components/client-island.d.ts +34 -34
  86. package/dist/components/client-island.js +75 -75
  87. package/dist/config.d.ts +17 -0
  88. package/dist/config.js +60 -1
  89. package/dist/deploy/adapters/cloudflare.d.ts +2 -0
  90. package/dist/deploy/adapters/cloudflare.js +124 -0
  91. package/dist/deploy/adapters/docker.d.ts +2 -0
  92. package/dist/deploy/adapters/docker.js +112 -0
  93. package/dist/deploy/adapters/index.d.ts +15 -0
  94. package/dist/deploy/adapters/index.js +24 -0
  95. package/dist/deploy/adapters/netlify.d.ts +2 -0
  96. package/dist/deploy/adapters/netlify.js +115 -0
  97. package/dist/deploy/adapters/render.d.ts +2 -0
  98. package/dist/deploy/adapters/render.js +95 -0
  99. package/dist/deploy/adapters/vercel.d.ts +7 -0
  100. package/dist/deploy/adapters/vercel.js +164 -0
  101. package/dist/deploy/cli-runner.d.ts +8 -0
  102. package/dist/deploy/cli-runner.js +58 -0
  103. package/dist/deploy/detect.d.ts +6 -0
  104. package/dist/deploy/detect.js +77 -0
  105. package/dist/deploy/index.d.ts +24 -0
  106. package/dist/deploy/index.js +112 -0
  107. package/dist/deploy/preflight.d.ts +8 -0
  108. package/dist/deploy/preflight.js +80 -0
  109. package/dist/deploy/types.d.ts +48 -0
  110. package/dist/deploy/types.js +2 -0
  111. package/dist/deploy/utils.d.ts +18 -0
  112. package/dist/deploy/utils.js +70 -0
  113. package/dist/dev-error.d.ts +14 -0
  114. package/dist/dev-error.js +1763 -705
  115. package/dist/index.d.ts +23 -21
  116. package/dist/index.js +61 -57
  117. package/dist/server/cookie-parse.d.ts +4 -0
  118. package/dist/server/cookie-parse.js +14 -0
  119. package/dist/server/engine.js +7 -26
  120. package/dist/server/index.d.ts +109 -102
  121. package/dist/server/index.js +315 -286
  122. package/dist/server/middleware-runner.d.ts +125 -57
  123. package/dist/server/middleware-runner.js +615 -218
  124. package/dist/server/middleware-security.d.ts +36 -0
  125. package/dist/server/middleware-security.js +183 -0
  126. package/dist/server/module-compile-hook.js +695 -662
  127. package/dist/server/route-handler-registry.d.ts +65 -0
  128. package/dist/server/route-handler-registry.js +195 -0
  129. package/dist/server/route-patterns.d.ts +67 -0
  130. package/dist/server/route-patterns.js +186 -0
  131. package/dist/server/rsc-engine.js +75 -92
  132. package/dist/server/rsc-module-system.d.ts +33 -33
  133. package/dist/server/rsc-module-system.js +87 -87
  134. package/dist/server/rsc-upstream.js +892 -888
  135. package/dist/server/static-generator.js +10 -10
  136. package/dist/server/typed-api-runtime.d.ts +18 -0
  137. package/dist/server/typed-api-runtime.js +635 -507
  138. package/dist/server/vista-import-map.js +134 -123
  139. package/dist/stack/index.d.ts +34 -32
  140. package/dist/stack/index.js +49 -45
  141. package/dist/stack/server/caller.d.ts +13 -0
  142. package/dist/stack/server/caller.js +42 -0
  143. package/dist/stack/server/executor.d.ts +40 -36
  144. package/dist/stack/server/executor.js +222 -174
  145. package/dist/stack/server/index.d.ts +11 -10
  146. package/dist/stack/server/index.js +24 -23
  147. package/dist/stack/server/procedure.d.ts +20 -18
  148. package/dist/stack/server/procedure.js +66 -58
  149. package/dist/stack/server/types.d.ts +113 -100
  150. package/dist/theme/react-server.d.ts +10 -0
  151. package/dist/theme/react-server.js +16 -0
  152. package/package.json +28 -3
  153. package/LICENSE +0 -21
@@ -1,57 +1,125 @@
1
- /**
2
- * Vista Middleware Runner
3
- *
4
- * Shared middleware execution logic used by both the standard SSR engine
5
- * and the RSC engine. Discovers `middleware.ts` / `.tsx` / `.js` at the
6
- * project root, constructs a NextRequest-like object from the Express
7
- * request, invokes the user middleware, and returns a disposition that
8
- * the caller can act on.
9
- */
10
- import type { Request } from 'express';
11
- export interface MiddlewareResult {
12
- /** 'redirect' send Location header and status */
13
- kind: 'redirect' | 'rewrite' | 'next' | 'short-circuit' | 'skip';
14
- /** HTTP status (e.g. 307 for redirect, 403 for short-circuit) */
15
- status?: number;
16
- /** Redirect target URL or rewrite path */
17
- location?: string;
18
- /** Extra response headers the middleware set (forwarded to client) */
19
- responseHeaders?: Map<string, string>;
20
- }
21
- /** The NextRequest-like object we hand to middleware. */
22
- export interface VistaMiddlewareRequest {
23
- url: string;
24
- method: string;
25
- headers: Map<string, string | string[] | undefined>;
26
- nextUrl: {
27
- pathname: string;
28
- searchParams: URLSearchParams;
29
- href: string;
30
- origin: string;
31
- };
32
- cookies: {
33
- get: (name: string) => {
34
- name: string;
35
- value: string;
36
- } | undefined;
37
- getAll: () => Array<{
38
- name: string;
39
- value: any;
40
- }>;
41
- has: (name: string) => boolean;
42
- };
43
- }
44
- /**
45
- * Run user-defined middleware for the given request.
46
- *
47
- * @param req Express request
48
- * @param cwd Project root (where middleware.ts lives)
49
- * @param isDev Whether we're in dev mode (busts require cache)
50
- */
51
- export declare function runMiddleware(req: Request, cwd: string, isDev: boolean): Promise<MiddlewareResult>;
52
- /**
53
- * Apply a MiddlewareResult to the Express request/response.
54
- * Returns `true` if the response was finalized (caller should `return`),
55
- * `false` if the request should continue to the next handler.
56
- */
57
- export declare function applyMiddlewareResult(result: MiddlewareResult, req: Request, res: import('express').Response): boolean;
1
+ /**
2
+ * Vista Middleware Runner
3
+ *
4
+ * Built-in middleware system for Vista.js.
5
+ * Supports:
6
+ * 1. Global middleware (top-level middleware.ts / middleware.js at cwd or src/)
7
+ * 2. Route-specific middleware (co-located in app/ directory segments, e.g. app/api/auth/middleware.ts)
8
+ * 3. Exported middleware from route files (e.g. export const middleware = ... in page.tsx or route.ts)
9
+ * 4. Middleware signature: middleware({ request, next }) matching Issue #7 Part 5
10
+ * 5. Middleware chaining and clearly defined execution order:
11
+ * Global -> Segment middlewares (shallowest to deepest) -> Route-level middleware -> Handler
12
+ * 6. Request modification (headers, URL rewrites) and Response modification / short-circuiting
13
+ */
14
+ import type { Request, Response as ExpressResponse } from 'express';
15
+ export interface MiddlewareResult {
16
+ /** 'redirect' send Location header and status; 'short-circuit' — send custom status/body; 'rewrite' rewrite URL; 'next' — continue; 'skip' — no middleware matched */
17
+ kind: 'redirect' | 'rewrite' | 'next' | 'short-circuit' | 'skip';
18
+ /** HTTP status (e.g. 307 for redirect, 401/403 for short-circuit) */
19
+ status?: number;
20
+ /** Redirect target URL or rewrite path */
21
+ location?: string;
22
+ /** Extra response headers the middleware set (forwarded to client) */
23
+ responseHeaders?: Map<string, string>;
24
+ /** Extra request headers modified by middleware (forwarded to downstream handlers) */
25
+ requestHeaders?: Map<string, string>;
26
+ /** Response body when short-circuiting */
27
+ body?: string | Buffer | null;
28
+ }
29
+ /** The Request-like object handed to middleware. */
30
+ export interface VistaMiddlewareRequest {
31
+ url: string;
32
+ method: string;
33
+ path: string;
34
+ headers: Headers;
35
+ nextUrl: {
36
+ pathname: string;
37
+ searchParams: URLSearchParams;
38
+ href: string;
39
+ origin: string;
40
+ };
41
+ cookies: {
42
+ get: (name: string) => {
43
+ name: string;
44
+ value: string;
45
+ } | undefined;
46
+ getAll: () => Array<{
47
+ name: string;
48
+ value: any;
49
+ }>;
50
+ has: (name: string) => boolean;
51
+ };
52
+ [key: string]: any;
53
+ }
54
+ export type NextFunction = (options?: {
55
+ request?: {
56
+ headers?: Headers | Record<string, string>;
57
+ };
58
+ }) => Promise<Response>;
59
+ export interface VistaMiddlewareContext {
60
+ request: VistaMiddlewareRequest;
61
+ next: NextFunction;
62
+ url?: string;
63
+ method?: string;
64
+ headers?: Headers;
65
+ nextUrl?: VistaMiddlewareRequest['nextUrl'];
66
+ cookies?: VistaMiddlewareRequest['cookies'];
67
+ [key: string]: any;
68
+ }
69
+ export type MiddlewareFunction = (contextOrRequest: VistaMiddlewareContext | VistaMiddlewareRequest, nextFn?: NextFunction) => Promise<Response | MiddlewareResult | void> | Response | MiddlewareResult | void;
70
+ export type MiddlewareMatcher = string | {
71
+ source: string;
72
+ missing?: Array<{
73
+ type: 'header' | 'cookie' | 'query';
74
+ key: string;
75
+ value?: string;
76
+ }>;
77
+ has?: Array<{
78
+ type: 'header' | 'cookie' | 'query';
79
+ key: string;
80
+ value?: string;
81
+ }>;
82
+ };
83
+ export interface MiddlewareConfig {
84
+ matcher?: MiddlewareMatcher | MiddlewareMatcher[];
85
+ allowedRedirectHosts?: string[];
86
+ }
87
+ export interface MiddlewareModule {
88
+ default?: MiddlewareFunction;
89
+ middleware?: MiddlewareFunction;
90
+ config?: MiddlewareConfig;
91
+ [key: string]: any;
92
+ }
93
+ export declare function clearMiddlewareCaches(): void;
94
+ /**
95
+ * Discover top-level global middleware.
96
+ * Checks `<cwd>/middleware.*` then `<cwd>/src/middleware.*`.
97
+ */
98
+ export declare function discoverGlobalMiddleware(cwd: string, bustCache: boolean): string | null;
99
+ /**
100
+ * Discover route-specific middleware files along the path hierarchy.
101
+ * Returns file paths from shallowest segment to deepest segment.
102
+ */
103
+ export declare function discoverRouteMiddlewares(cwd: string, pathname: string, bustCache: boolean): string[];
104
+ export declare function patternToRegExp(pattern: string): RegExp;
105
+ export declare function shouldRunMiddleware(middlewareModule: MiddlewareModule, pathname: string, request?: VistaMiddlewareRequest): boolean;
106
+ export declare function buildNextRequest(req: Request): VistaMiddlewareRequest;
107
+ /**
108
+ * Run user-defined middleware chain (global + route-specific) for the given request.
109
+ *
110
+ * Execution Order:
111
+ * 1. Global middleware (cwd/middleware.ts or cwd/src/middleware.ts)
112
+ * 2. Route segment middlewares (from shallowest to deepest in app/)
113
+ * 3. Route file middleware (exported `middleware` from page.tsx/route.ts)
114
+ * 4. Downstream handler (Page component or API route handler)
115
+ *
116
+ * Returns a `MiddlewareResult` indicating whether the request was redirected,
117
+ * short-circuited with a response, rewritten, or continued to the next handler.
118
+ */
119
+ export declare function runMiddleware(req: Request, cwd: string, isDev?: boolean): Promise<MiddlewareResult>;
120
+ /**
121
+ * Apply a MiddlewareResult to the Express request/response.
122
+ * Returns `true` if the response was finalized (caller should `return`),
123
+ * `false` if the request should continue to the next handler.
124
+ */
125
+ export declare function applyMiddlewareResult(result: MiddlewareResult, req: Request, res: ExpressResponse): boolean;