@farm.js/core 0.1.0-beta.18 → 0.1.0-beta.19

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 (49) hide show
  1. package/dist/agent-runtime.cjs.map +1 -1
  2. package/dist/agent-runtime.mjs +1 -1
  3. package/dist/{chunk-TWOCKYU7.mjs → chunk-5VHPEW6N.mjs} +2 -2
  4. package/dist/{chunk-ZCTTYTRZ.mjs → chunk-7BX7NEA7.mjs} +2 -2
  5. package/dist/{chunk-PWLQWGXD.mjs → chunk-JUQB43GK.mjs} +14 -5
  6. package/dist/chunk-JUQB43GK.mjs.map +1 -0
  7. package/dist/{chunk-XFYFRBX5.mjs → chunk-MFH7BNPY.mjs} +2 -2
  8. package/dist/{chunk-XFYFRBX5.mjs.map → chunk-MFH7BNPY.mjs.map} +1 -1
  9. package/dist/{chunk-6OKRBYDC.mjs → chunk-UNDUIGWC.mjs} +33 -15
  10. package/dist/chunk-UNDUIGWC.mjs.map +1 -0
  11. package/dist/{chunk-SBLHLAE3.mjs → chunk-ZYDQS2TT.mjs} +88 -5
  12. package/dist/chunk-ZYDQS2TT.mjs.map +1 -0
  13. package/dist/{chunk-DGJPXXVL.mjs → chunk-ZYHIM7O7.mjs} +6 -6
  14. package/dist/{devtools-NVNCOYRJ.mjs → devtools-4RDGBT72.mjs} +3 -3
  15. package/dist/docs.cjs.map +1 -1
  16. package/dist/docs.mjs +3 -3
  17. package/dist/index.cjs +136 -20
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.mjs +9 -7
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/integrations.cjs +82 -4
  22. package/dist/integrations.cjs.map +1 -1
  23. package/dist/integrations.mjs +3 -1
  24. package/dist/internal/build-runtime.cjs +134 -20
  25. package/dist/internal/build-runtime.cjs.map +1 -1
  26. package/dist/internal/build-runtime.mjs +7 -7
  27. package/dist/internal/config-runtime.cjs +75 -4
  28. package/dist/internal/config-runtime.cjs.map +1 -1
  29. package/dist/internal/config-runtime.mjs +2 -2
  30. package/dist/plugin.cjs +62 -15
  31. package/dist/plugin.cjs.map +1 -1
  32. package/dist/plugin.mjs +4 -4
  33. package/dist/server.cjs +138 -20
  34. package/dist/server.cjs.map +1 -1
  35. package/dist/server.mjs +5 -5
  36. package/dist/version.cjs +1 -1
  37. package/dist/version.cjs.map +1 -1
  38. package/dist/version.mjs +1 -1
  39. package/dist/vite.cjs +25 -3
  40. package/dist/vite.cjs.map +1 -1
  41. package/dist/vite.mjs +3 -3
  42. package/package.json +1 -1
  43. package/dist/chunk-6OKRBYDC.mjs.map +0 -1
  44. package/dist/chunk-PWLQWGXD.mjs.map +0 -1
  45. package/dist/chunk-SBLHLAE3.mjs.map +0 -1
  46. /package/dist/{chunk-TWOCKYU7.mjs.map → chunk-5VHPEW6N.mjs.map} +0 -0
  47. /package/dist/{chunk-ZCTTYTRZ.mjs.map → chunk-7BX7NEA7.mjs.map} +0 -0
  48. /package/dist/{chunk-DGJPXXVL.mjs.map → chunk-ZYHIM7O7.mjs.map} +0 -0
  49. /package/dist/{devtools-NVNCOYRJ.mjs.map → devtools-4RDGBT72.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-VCANOYFI.mjs";
10
10
  import {
11
11
  build
12
- } from "./chunk-DGJPXXVL.mjs";
12
+ } from "./chunk-ZYHIM7O7.mjs";
13
13
  import "./chunk-4S3ORGFA.mjs";
14
14
  import "./chunk-SL6HTIOK.mjs";
15
15
  import {
@@ -30,7 +30,7 @@ import {
30
30
  isFarmDocsRequest,
31
31
  loadFarmDocsPage,
32
32
  resolveFarmDocsContentDir
33
- } from "./chunk-TWOCKYU7.mjs";
33
+ } from "./chunk-5VHPEW6N.mjs";
34
34
  import "./chunk-V7RBCSDJ.mjs";
35
35
  import {
36
36
  UnsupportedRateLimitStorageError,
@@ -74,7 +74,7 @@ import {
74
74
  resolveDeployConfig,
75
75
  resolveDeployOutputPath,
76
76
  resolveMigrationsConfig
77
- } from "./chunk-ZCTTYTRZ.mjs";
77
+ } from "./chunk-7BX7NEA7.mjs";
78
78
  import {
79
79
  defineConfig,
80
80
  defineFarmConfig
@@ -83,7 +83,7 @@ import {
83
83
  FarmRuntimeShutdownError,
84
84
  PluginManager,
85
85
  definePlugin
86
- } from "./chunk-6OKRBYDC.mjs";
86
+ } from "./chunk-UNDUIGWC.mjs";
87
87
  import {
88
88
  env,
89
89
  getEnv,
@@ -150,7 +150,7 @@ import {
150
150
  parseRouteRenderingDirective,
151
151
  resolveRouteRenderingConfig,
152
152
  resolveRouteRenderingConfigFromFile
153
- } from "./chunk-PWLQWGXD.mjs";
153
+ } from "./chunk-JUQB43GK.mjs";
154
154
  import {
155
155
  APITypeGenerator
156
156
  } from "./chunk-LGHEOHBU.mjs";
@@ -276,6 +276,7 @@ import {
276
276
  defineIntegration,
277
277
  defineIntegrationSchema,
278
278
  dispatchIntegrationRequest,
279
+ getFarmIntegrationPluginOwner,
279
280
  getFarmIntegrationPluginServerRuntime,
280
281
  getIntegrationDocumentNavigationMatchers,
281
282
  getIntegrationProviders,
@@ -289,7 +290,7 @@ import {
289
290
  matchIntegrationRoute,
290
291
  matchRegisteredIntegrationRoute,
291
292
  resolveIntegrationPlugins
292
- } from "./chunk-SBLHLAE3.mjs";
293
+ } from "./chunk-ZYDQS2TT.mjs";
293
294
  import {
294
295
  createFarmStorage,
295
296
  createStorageClient,
@@ -402,7 +403,7 @@ import {
402
403
  getCurrentRequest
403
404
  } from "./chunk-RHIFZZUI.mjs";
404
405
  import "./chunk-LM2YNO4U.mjs";
405
- import "./chunk-XFYFRBX5.mjs";
406
+ import "./chunk-MFH7BNPY.mjs";
406
407
  import {
407
408
  SPARouter,
408
409
  getRouter,
@@ -889,6 +890,7 @@ export {
889
890
  getFarmDeploymentMismatch,
890
891
  getFarmDocsDocumentNavigationMatchers,
891
892
  getFarmDocsRouteTypeEntries,
893
+ getFarmIntegrationPluginOwner,
892
894
  getFarmIntegrationPluginServerRuntime,
893
895
  getFarmLayerAliases,
894
896
  getFarmPresetRuntime,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/provider.tsx","../src/hmr.ts","../src/openapi/scalar-component.tsx","../src/openapi/docs-route.tsx"],"sourcesContent":["import React, { createContext, useContext, type ReactNode } from \"react\";\nimport type { FarmConfig } from \"./types\";\n\ninterface FarmContextValue {\n config: FarmConfig;\n basePath: string;\n}\n\nconst FarmContext = createContext<FarmContextValue | null>(null);\n\ninterface FarmProviderProps {\n children: ReactNode;\n config: FarmConfig;\n}\n\n/**\n * Farm.js context provider for client-side components\n */\nexport function FarmProvider({ children, config }: FarmProviderProps) {\n const value: FarmContextValue = {\n config,\n basePath: config.basePath || \"/\",\n };\n\n return <FarmContext.Provider value={value}>{children}</FarmContext.Provider>;\n}\n\n/**\n * Hook to access Farm.js configuration and utilities\n */\nexport function useFarm(): FarmContextValue {\n const context = useContext(FarmContext);\n\n if (!context) {\n throw new Error(\"useFarm must be used within a FarmProvider\");\n }\n\n return context;\n}\n\n/**\n * Hook to get the current base path\n */\nexport function useBasePath(): string {\n const { basePath } = useFarm();\n return basePath;\n}\n","import type { ViteDevServer, ModuleNode } from \"vite\";\nimport { logger } from \"./utils\";\n\nexport class HMRManager {\n private server: ViteDevServer;\n\n constructor(server: ViteDevServer) {\n this.server = server;\n }\n\n /**\n * Send HMR update to client\n */\n async send(payload: any) {\n this.server.ws.send(payload);\n }\n\n /**\n * Trigger full page reload\n */\n async reloadPage() {\n this.server.ws.send({\n type: \"full-reload\",\n path: \"*\",\n });\n }\n\n /**\n * Handle file change and trigger HMR\n */\n async handleFileChange(file: string) {\n const module = await this.server.moduleGraph.getModuleByUrl(file);\n\n if (!module) {\n return;\n }\n\n // Invalidate module\n this.server.moduleGraph.invalidateModule(module);\n\n // Get affected modules\n const affectedModules = this.getAffectedModules(module);\n\n if (affectedModules.size === 0) {\n return;\n }\n\n if (file.includes(\"/app/\") && (file.endsWith(\"page.tsx\") || file.endsWith(\"page.ts\"))) {\n await this.reloadPage();\n return;\n }\n\n if (file.includes(\"/app/\") && (file.endsWith(\"layout.tsx\") || file.endsWith(\"layout.ts\"))) {\n await this.reloadPage();\n return;\n }\n // Send update for other files\n this.send({\n type: \"update\",\n updates: Array.from(affectedModules).map((m) => ({\n type: m.type === \"css\" ? \"css-update\" : \"js-update\",\n path: m.url,\n acceptedPath: m.url,\n timestamp: Date.now(),\n })),\n });\n }\n\n /**\n * Get all affected modules in the dependency graph\n */\n private getAffectedModules(module: ModuleNode): Set<ModuleNode> {\n const affected = new Set<ModuleNode>();\n const seen = new Set<ModuleNode>();\n\n const traverse = (mod: ModuleNode) => {\n if (seen.has(mod)) return;\n seen.add(mod);\n affected.add(mod);\n\n // Traverse importers\n for (const importer of mod.importers) {\n if (!importer.isSelfAccepting) {\n traverse(importer);\n }\n }\n };\n\n traverse(module);\n return affected;\n }\n\n /**\n * Handle custom HMR events from client\n */\n onClientMessage(event: string, callback: (data: any) => void) {\n // Vite handles this via ws.on\n }\n}\n\n/**\n * Create HMR client code for injection\n */\nexport function createHMRClientCode(): string {\n return `\n// Farm.js HMR Client\nif (import.meta.hot) {\n // Accept HMR updates for this module\n import.meta.hot.accept((newModule) => {\n if (newModule) {\n // Module updated, trigger re-render\n window.location.reload();\n }\n });\n\n // Listen for custom Farm.js events\n import.meta.hot.on('farm:route-update', (data) => {\n console.log('Route updated:', data.path);\n window.location.reload();\n });\n\n // Handle CSS updates\n import.meta.hot.on('vite:beforeUpdate', () => {\n console.log('[Farm.js] HMR update incoming...');\n });\n\n import.meta.hot.on('vite:afterUpdate', () => {\n console.log('[Farm.js] HMR update applied ✓');\n });\n\n // Handle errors\n import.meta.hot.on('vite:error', (err) => {\n console.error('[Farm.js] HMR error:', err);\n });\n}\n`;\n}\n","import React from \"react\";\n\ninterface ScalarAPIDocumentationProps {\n spec: any;\n config?: {\n theme?: \"default\" | \"purple\" | \"blue\" | \"green\" | \"red\" | \"yellow\";\n layout?: \"modern\" | \"classic\";\n showSidebar?: boolean;\n hideDownloadButton?: boolean;\n hideTryItPanel?: boolean;\n };\n}\n\nexport function ScalarAPIDocumentation({ spec, config = {} }: ScalarAPIDocumentationProps) {\n const [isLoaded, setIsLoaded] = React.useState(false);\n\n React.useEffect(() => {\n // Dynamically import Scalar components\n const loadScalar = async () => {\n try {\n // Load Scalar CSS\n const cssLink = document.createElement(\"link\");\n cssLink.rel = \"stylesheet\";\n cssLink.href = \"https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest/dist/style.css\";\n document.head.appendChild(cssLink);\n\n // Load Scalar JS\n const script = document.createElement(\"script\");\n script.src =\n \"https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest/dist/browser/standalone.js\";\n script.onload = () => setIsLoaded(true);\n document.head.appendChild(script);\n } catch (error) {\n console.error(\"Failed to load Scalar:\", error);\n }\n };\n\n loadScalar();\n }, []);\n\n React.useEffect(() => {\n if (isLoaded && window.ScalarApiReference) {\n // Initialize Scalar\n const container = document.getElementById(\"scalar-api-reference\");\n if (container) {\n window.ScalarApiReference({\n spec,\n theme: config.theme || \"default\",\n layout: config.layout || \"modern\",\n showSidebar: config.showSidebar !== false,\n hideDownloadButton: config.hideDownloadButton || false,\n hideTryItPanel: config.hideTryItPanel || false,\n });\n }\n }\n }, [isLoaded, spec, config]);\n\n return (\n <div className=\"scalar-container\">\n <div id=\"scalar-api-reference\" style={{ height: \"100vh\", width: \"100%\" }} />\n </div>\n );\n}\n\n// Extend window type for Scalar\ndeclare global {\n interface Window {\n ScalarApiReference: (config: any) => void;\n }\n}\n","import React from \"react\";\nimport { ScalarAPIDocumentation } from \"./scalar-component\";\n\ninterface DocsRouteProps {\n spec: any;\n config?: any;\n}\n\nexport function DocsRoute({ spec, config }: DocsRouteProps) {\n return (\n <html lang=\"en\">\n <head>\n <meta charSet=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <link rel=\"icon\" href=\"data:,\" />\n <title>{config?.title || \"API Documentation\"}</title>\n <style>{`\n body {\n margin: 0;\n padding: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;\n }\n .scalar-container {\n height: 100vh;\n width: 100%;\n }\n `}</style>\n </head>\n <body>\n <ScalarAPIDocumentation spec={spec} config={config} />\n </body>\n </html>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAgB,iBAAAA,gBAAe,kBAAkC;AAwBxD;AAhBT,IAAM,cAAcC,eAAuC,IAAI;AAUxD,SAAS,aAAa,EAAE,UAAU,OAAO,GAAsB;AACpE,QAAM,QAA0B;AAAA,IAC9B;AAAA,IACA,UAAU,OAAO,YAAY;AAAA,EAC/B;AAEA,SAAO,oBAAC,YAAY,UAAZ,EAAqB,OAAe,UAAS;AACvD;AAPgB;;;ACfT,IAAM,cAAN,MAAM,YAAW;AAAA,EAGtB,YAAY,QAAuB;AACjC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA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GAAG,CAAC,UAAU,MAAM,MAAM,CAAC;AAE3B,SACE,gBAAAD,KAAC,SAAI,WAAU,oBACb,0BAAAA,KAAC,SAAI,IAAG,wBAAuB,OAAO,EAAE,QAAQ,SAAS,OAAO,OAAO,GAAG,GAC5E;AAEJ;AAjDgB;;;ACFV,SACE,OAAAE,MADF;AAHC,SAAS,UAAU,EAAE,MAAM,OAAO,GAAmB;AAC1D,SACE,qBAAC,UAAK,MAAK,MACT;AAAA,yBAAC,UACC;AAAA,sBAAAA,KAAC,UAAK,SAAQ,SAAQ;AAAA,MACtB,gBAAAA,KAAC,UAAK,MAAK,YAAW,SAAQ,uCAAsC;AAAA,MACpE,gBAAAA,KAAC,UAAK,KAAI,QAAO,MAAK,UAAS;AAAA,MAC/B,gBAAAA,KAAC,WAAO,kBAAQ,SAAS,qBAAoB;AAAA,MAC7C,gBAAAA,KAAC,WAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAUN;AAAA,OACJ;AAAA,IACA,gBAAAA,KAAC,UACC,0BAAAA,KAAC,0BAAuB,MAAY,QAAgB,GACtD;AAAA,KACF;AAEJ;AAzBgB;","names":["createContext","createContext","React","jsx","React","jsx"]}
1
+ {"version":3,"sources":["../src/provider.tsx","../src/hmr.ts","../src/openapi/scalar-component.tsx","../src/openapi/docs-route.tsx"],"sourcesContent":["import React, { createContext, useContext, type ReactNode } from \"react\";\nimport type { FarmConfig } from \"./types\";\n\ninterface FarmContextValue {\n config: FarmConfig;\n basePath: string;\n}\n\nconst FarmContext = createContext<FarmContextValue | null>(null);\n\ninterface FarmProviderProps {\n children: ReactNode;\n config: FarmConfig;\n}\n\n/**\n * Farm.js context provider for client-side components\n */\nexport function FarmProvider({ children, config }: FarmProviderProps) {\n const value: FarmContextValue = {\n config,\n basePath: config.basePath || \"/\",\n };\n\n return <FarmContext.Provider value={value}>{children}</FarmContext.Provider>;\n}\n\n/**\n * Hook to access Farm.js configuration and utilities\n */\nexport function useFarm(): FarmContextValue {\n const context = useContext(FarmContext);\n\n if (!context) {\n throw new Error(\"useFarm must be used within a FarmProvider\");\n }\n\n return context;\n}\n\n/**\n * Hook to get the current base path\n */\nexport function useBasePath(): string {\n const { basePath } = useFarm();\n return basePath;\n}\n","import type { ViteDevServer, ModuleNode } from \"vite\";\nimport { logger } from \"./utils\";\n\nexport class HMRManager {\n private server: ViteDevServer;\n\n constructor(server: ViteDevServer) {\n this.server = server;\n }\n\n /**\n * Send HMR update to client\n */\n async send(payload: any) {\n this.server.ws.send(payload);\n }\n\n /**\n * Trigger full page reload\n */\n async reloadPage() {\n this.server.ws.send({\n type: \"full-reload\",\n path: \"*\",\n });\n }\n\n /**\n * Handle file change and trigger HMR\n */\n async handleFileChange(file: string) {\n const module = await this.server.moduleGraph.getModuleByUrl(file);\n\n if (!module) {\n return;\n }\n\n // Invalidate module\n this.server.moduleGraph.invalidateModule(module);\n\n // Get affected modules\n const affectedModules = this.getAffectedModules(module);\n\n if (affectedModules.size === 0) {\n return;\n }\n\n if (file.includes(\"/app/\") && (file.endsWith(\"page.tsx\") || file.endsWith(\"page.ts\"))) {\n await this.reloadPage();\n return;\n }\n\n if (file.includes(\"/app/\") && (file.endsWith(\"layout.tsx\") || file.endsWith(\"layout.ts\"))) {\n await this.reloadPage();\n return;\n }\n // Send update for other files\n this.send({\n type: \"update\",\n updates: Array.from(affectedModules).map((m) => ({\n type: m.type === \"css\" ? \"css-update\" : \"js-update\",\n path: m.url,\n acceptedPath: m.url,\n timestamp: Date.now(),\n })),\n });\n }\n\n /**\n * Get all affected modules in the dependency graph\n */\n private getAffectedModules(module: ModuleNode): Set<ModuleNode> {\n const affected = new Set<ModuleNode>();\n const seen = new Set<ModuleNode>();\n\n const traverse = (mod: ModuleNode) => {\n if (seen.has(mod)) return;\n seen.add(mod);\n affected.add(mod);\n\n // Traverse importers\n for (const importer of mod.importers) {\n if (!importer.isSelfAccepting) {\n traverse(importer);\n }\n }\n };\n\n traverse(module);\n return affected;\n }\n\n /**\n * Handle custom HMR events from client\n */\n onClientMessage(event: string, callback: (data: any) => void) {\n // Vite handles this via ws.on\n }\n}\n\n/**\n * Create HMR client code for injection\n */\nexport function createHMRClientCode(): string {\n return `\n// Farm.js HMR Client\nif (import.meta.hot) {\n // Accept HMR updates for this module\n import.meta.hot.accept((newModule) => {\n if (newModule) {\n // Module updated, trigger re-render\n window.location.reload();\n }\n });\n\n // Listen for custom Farm.js events\n import.meta.hot.on('farm:route-update', (data) => {\n console.log('Route updated:', data.path);\n window.location.reload();\n });\n\n // Handle CSS updates\n import.meta.hot.on('vite:beforeUpdate', () => {\n console.log('[Farm.js] HMR update incoming...');\n });\n\n import.meta.hot.on('vite:afterUpdate', () => {\n console.log('[Farm.js] HMR update applied ✓');\n });\n\n // Handle errors\n import.meta.hot.on('vite:error', (err) => {\n console.error('[Farm.js] HMR error:', err);\n });\n}\n`;\n}\n","import React from \"react\";\n\ninterface ScalarAPIDocumentationProps {\n spec: any;\n config?: {\n theme?: \"default\" | \"purple\" | \"blue\" | \"green\" | \"red\" | \"yellow\";\n layout?: \"modern\" | \"classic\";\n showSidebar?: boolean;\n hideDownloadButton?: boolean;\n hideTryItPanel?: boolean;\n };\n}\n\nexport function ScalarAPIDocumentation({ spec, config = {} }: ScalarAPIDocumentationProps) {\n const [isLoaded, setIsLoaded] = React.useState(false);\n\n React.useEffect(() => {\n // Dynamically import Scalar components\n const loadScalar = async () => {\n try {\n // Load Scalar CSS\n const cssLink = document.createElement(\"link\");\n cssLink.rel = \"stylesheet\";\n cssLink.href = \"https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest/dist/style.css\";\n document.head.appendChild(cssLink);\n\n // Load Scalar JS\n const script = document.createElement(\"script\");\n script.src =\n \"https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest/dist/browser/standalone.js\";\n script.onload = () => setIsLoaded(true);\n document.head.appendChild(script);\n } catch (error) {\n console.error(\"Failed to load Scalar:\", error);\n }\n };\n\n loadScalar();\n }, []);\n\n React.useEffect(() => {\n if (isLoaded && window.ScalarApiReference) {\n // Initialize Scalar\n const container = document.getElementById(\"scalar-api-reference\");\n if (container) {\n window.ScalarApiReference({\n spec,\n theme: config.theme || \"default\",\n layout: config.layout || \"modern\",\n showSidebar: config.showSidebar !== false,\n hideDownloadButton: config.hideDownloadButton || false,\n hideTryItPanel: config.hideTryItPanel || false,\n });\n }\n }\n }, [isLoaded, spec, config]);\n\n return (\n <div className=\"scalar-container\">\n <div id=\"scalar-api-reference\" style={{ height: \"100vh\", width: \"100%\" }} />\n </div>\n );\n}\n\n// Extend window type for Scalar\ndeclare global {\n interface Window {\n ScalarApiReference: (config: any) => void;\n }\n}\n","import React from \"react\";\nimport { ScalarAPIDocumentation } from \"./scalar-component\";\n\ninterface DocsRouteProps {\n spec: any;\n config?: any;\n}\n\nexport function DocsRoute({ spec, config }: DocsRouteProps) {\n return (\n <html lang=\"en\">\n <head>\n <meta charSet=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <link rel=\"icon\" href=\"data:,\" />\n <title>{config?.title || \"API Documentation\"}</title>\n <style>{`\n body {\n margin: 0;\n padding: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;\n }\n .scalar-container {\n height: 100vh;\n width: 100%;\n }\n `}</style>\n </head>\n <body>\n <ScalarAPIDocumentation spec={spec} config={config} />\n </body>\n </html>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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WAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAUN;AAAA,OACJ;AAAA,IACA,gBAAAA,KAAC,UACC,0BAAAA,KAAC,0BAAuB,MAAY,QAAgB,GACtD;AAAA,KACF;AAEJ;AAzBgB;","names":["createContext","createContext","React","jsx","React","jsx"]}
@@ -638,6 +638,7 @@ __export(integrations_exports, {
638
638
  defineIntegrationAPIOperation: () => defineIntegrationAPIOperation,
639
639
  defineIntegrationSchema: () => defineIntegrationSchema,
640
640
  dispatchIntegrationRequest: () => dispatchIntegrationRequest,
641
+ getFarmIntegrationPluginOwner: () => getFarmIntegrationPluginOwner,
641
642
  getFarmIntegrationPluginServerRuntime: () => getFarmIntegrationPluginServerRuntime,
642
643
  getIntegrationDocumentNavigationMatchers: () => getIntegrationDocumentNavigationMatchers,
643
644
  getIntegrationProviders: () => getIntegrationProviders,
@@ -861,6 +862,15 @@ var api = {
861
862
  }
862
863
  };
863
864
 
865
+ // src/plugin-integration-context.ts
866
+ var FARM_PLUGIN_INTEGRATION_CONTEXT = /* @__PURE__ */ Symbol.for("@farm.js/core/plugin-integration-context");
867
+ function setFarmPluginIntegrationContext(plugin, integration) {
868
+ Object.defineProperty(plugin, FARM_PLUGIN_INTEGRATION_CONTEXT, {
869
+ value: integration
870
+ });
871
+ }
872
+ __name(setFarmPluginIntegrationContext, "setFarmPluginIntegrationContext");
873
+
864
874
  // src/request-context.ts
865
875
  var REQUEST_CONTEXT_STORE_KEY = /* @__PURE__ */ Symbol.for("farm.requestContextStore");
866
876
  function getRequestContextStore() {
@@ -1268,11 +1278,17 @@ __name(defineIntegrationSchema, "defineIntegrationSchema");
1268
1278
  var FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME = /* @__PURE__ */ Symbol.for(
1269
1279
  "@farm.js/core/integration-plugin-server-runtime"
1270
1280
  );
1281
+ var FARM_INTEGRATION_PLUGIN_OWNER = /* @__PURE__ */ Symbol.for("@farm.js/core/integration-plugin-owner");
1271
1282
  function getFarmIntegrationPluginServerRuntime(plugin) {
1272
1283
  const value = plugin[FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME];
1273
1284
  return typeof value === "boolean" ? value : void 0;
1274
1285
  }
1275
1286
  __name(getFarmIntegrationPluginServerRuntime, "getFarmIntegrationPluginServerRuntime");
1287
+ function getFarmIntegrationPluginOwner(plugin) {
1288
+ const value = plugin[FARM_INTEGRATION_PLUGIN_OWNER];
1289
+ return value && typeof value === "object" ? value : void 0;
1290
+ }
1291
+ __name(getFarmIntegrationPluginOwner, "getFarmIntegrationPluginOwner");
1276
1292
  function defineTypedIntegrationRoute(method, path, input) {
1277
1293
  return {
1278
1294
  path,
@@ -1432,14 +1448,75 @@ function resolveIntegrationPlugins(integrations) {
1432
1448
  if (!integration || !isFarmIntegration(integration)) {
1433
1449
  continue;
1434
1450
  }
1435
- plugins.push(createIntegrationPlugin(key, integration));
1436
- if (integration.plugins?.length) {
1437
- plugins.push(...integration.plugins);
1438
- }
1451
+ const owner = createIntegrationPluginOwner(key, integration, "lifecycle");
1452
+ plugins.push(withIntegrationPluginOwner(createIntegrationPlugin(key, integration), owner));
1453
+ plugins.push(...resolveIntegrationPluginContributions(key, integration));
1439
1454
  }
1440
1455
  return plugins;
1441
1456
  }
1442
1457
  __name(resolveIntegrationPlugins, "resolveIntegrationPlugins");
1458
+ function resolveIntegrationPluginContributions(key, integration) {
1459
+ const contributions = integration.plugins;
1460
+ if (!contributions) return [];
1461
+ if (!Array.isArray(contributions)) {
1462
+ throw new TypeError(`Integration "${key}" plugins must be an array`);
1463
+ }
1464
+ const names = /* @__PURE__ */ new Set();
1465
+ return contributions.map((plugin, index) => {
1466
+ if (!plugin || typeof plugin !== "object" || typeof plugin.name !== "string") {
1467
+ throw new TypeError(`Integration "${key}" plugin at index ${index} is invalid`);
1468
+ }
1469
+ const name = plugin.name.trim();
1470
+ if (!name) {
1471
+ throw new TypeError(`Integration "${key}" plugin at index ${index} requires a name`);
1472
+ }
1473
+ if (names.has(name)) {
1474
+ throw new Error(`Integration "${key}" contributes duplicate plugin name "${name}"`);
1475
+ }
1476
+ names.add(name);
1477
+ return withIntegrationPluginOwner(
1478
+ plugin,
1479
+ createIntegrationPluginOwner(key, integration, "contribution"),
1480
+ createIntegrationPluginContext(key, integration)
1481
+ );
1482
+ });
1483
+ }
1484
+ __name(resolveIntegrationPluginContributions, "resolveIntegrationPluginContributions");
1485
+ function createIntegrationPluginOwner(key, integration, source) {
1486
+ return Object.freeze({
1487
+ key,
1488
+ category: integration.category,
1489
+ type: integration.type,
1490
+ source,
1491
+ serverRuntime: integration.serverRuntime !== false
1492
+ });
1493
+ }
1494
+ __name(createIntegrationPluginOwner, "createIntegrationPluginOwner");
1495
+ function createIntegrationPluginContext(key, integration) {
1496
+ return Object.freeze({
1497
+ key,
1498
+ category: integration.category,
1499
+ type: integration.type,
1500
+ instance: integration.instance,
1501
+ serverRuntime: integration.serverRuntime !== false
1502
+ });
1503
+ }
1504
+ __name(createIntegrationPluginContext, "createIntegrationPluginContext");
1505
+ function withIntegrationPluginOwner(plugin, owner, integration) {
1506
+ const descriptors = Object.getOwnPropertyDescriptors(plugin);
1507
+ Reflect.deleteProperty(descriptors, FARM_INTEGRATION_PLUGIN_OWNER);
1508
+ Reflect.deleteProperty(descriptors, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME);
1509
+ const ownedPlugin = Object.create(Object.getPrototypeOf(plugin), descriptors);
1510
+ Object.defineProperty(ownedPlugin, FARM_INTEGRATION_PLUGIN_OWNER, { value: owner });
1511
+ Object.defineProperty(ownedPlugin, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME, {
1512
+ value: owner.serverRuntime
1513
+ });
1514
+ if (integration) {
1515
+ setFarmPluginIntegrationContext(ownedPlugin, integration);
1516
+ }
1517
+ return ownedPlugin;
1518
+ }
1519
+ __name(withIntegrationPluginOwner, "withIntegrationPluginOwner");
1443
1520
  function getIntegrationProviders(integrations) {
1444
1521
  if (!integrations) {
1445
1522
  return [];
@@ -3084,6 +3161,7 @@ __name(normalizeMatcher, "normalizeMatcher");
3084
3161
  defineIntegrationAPIOperation,
3085
3162
  defineIntegrationSchema,
3086
3163
  dispatchIntegrationRequest,
3164
+ getFarmIntegrationPluginOwner,
3087
3165
  getFarmIntegrationPluginServerRuntime,
3088
3166
  getIntegrationDocumentNavigationMatchers,
3089
3167
  getIntegrationProviders,